NorMIT-nav  22.09
An IGT application
cxApplicationsParser.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxApplicationsParser.h"
13 
14 #include <iostream>
15 #include <QApplication>
16 #include <QByteArray>
17 #include <QDir>
18 #include "cxXmlOptionItem.h"
19 
20 #include "cxSettings.h"
21 #include "cxDataLocations.h"
22 #include "cxWorkflowStateMachine.h"
23 #include "cxDataLocations.h"
24 #include "cxConfig.h"
25 
26 #include "cxTrackingServiceProxy.h"
28 #include "cxSpaceProviderImpl.h"
29 #include "cxVideoServiceProxy.h"
30 #include "cxProfile.h"
31 
32 namespace cx
33 {
34 
36 {
37  Desktop desktop;
38 
39  QStringList standardToolbars;
40  standardToolbars << "Workflow" << "Navigation" << "Tools" << "Screenshot" << "Desktop";
41 
42 
43  //-----------------------------------------------------
44  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
45  QStringList toolbars;
46  toolbars << standardToolbars << "Data" << "Help";
47  this->addToolbarsToDesktop(desktop, toolbars);
48  desktop.addPreset("active_mesh_widget", Qt::LeftDockWidgetArea, true);
49  desktop.addPreset("volume_properties_widget", Qt::LeftDockWidgetArea, true);
50  desktop.addPreset("slice_properties_widget", Qt::LeftDockWidgetArea, true);
51  desktop.addPreset("dicom_widget", Qt::LeftDockWidgetArea, true);
52  desktop.addPreset("export_data_widget", Qt::LeftDockWidgetArea, true);
53  desktop.addPreset("import_widget", Qt::LeftDockWidgetArea, true);//The last one added becomes the active widget
54  desktop.addPreset("console_widget", Qt::LeftDockWidgetArea, false);
55  desktop.addPreset("help_widget", Qt::RightDockWidgetArea, false);
56  mWorkflowDefaultDesktops["PatientDataUid"] = desktop;
57  //-----------------------------------------------------
58 
59  //-----------------------------------------------------
60  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
61  toolbars.clear();
62  toolbars << standardToolbars << "RegistrationHistory" << "Help";
63  this->addToolbarsToDesktop(desktop, toolbars);
64  desktop.addPreset("console_widget", Qt::LeftDockWidgetArea, true);
65  desktop.addPreset("org_custusx_registration_gui_widget", Qt::LeftDockWidgetArea, true);
66  desktop.addPreset("registration_history_widget", Qt::LeftDockWidgetArea, false);
67  mWorkflowDefaultDesktops["RegistrationUid"] = desktop;
68  //-----------------------------------------------------
69 
70  //-----------------------------------------------------
71  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
72  toolbars.clear();
73  toolbars << standardToolbars << "Camera3DViews" << "Sampler" << "Help";
74  this->addToolbarsToDesktop(desktop, toolbars);
75  desktop.addPreset("active_mesh_widget", Qt::LeftDockWidgetArea, true);
76  desktop.addPreset("volume_properties_widget", Qt::LeftDockWidgetArea, true);
77  desktop.addPreset("slice_properties_widget", Qt::LeftDockWidgetArea, true);
78  desktop.addPreset("console_widget", Qt::LeftDockWidgetArea, false);
79  mWorkflowDefaultDesktops["PreOpPlanningUid"] = desktop;
80  //-----------------------------------------------------
81 
82  //-----------------------------------------------------
83  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
84  toolbars.clear();
85  toolbars << standardToolbars << "InteractorStyle" << "ToolOffset" << "Help";
86  this->addToolbarsToDesktop(desktop, toolbars);
87  mWorkflowDefaultDesktops["NavigationUid"] = desktop;
88  //-----------------------------------------------------
89 
90  //-----------------------------------------------------
91  desktop = Desktop("LAYOUT_US_Acquisition", QByteArray::fromBase64(""));
92  toolbars.clear();
93  toolbars << standardToolbars << "Help";
94  this->addToolbarsToDesktop(desktop, toolbars);
95  desktop.addPreset("igt_link_widget", Qt::LeftDockWidgetArea, true);
96  desktop.addPreset("us_reconstruction", Qt::LeftDockWidgetArea, true);
97  desktop.addPreset("org_custusx_acquisition_widgets_acquisition", Qt::LeftDockWidgetArea, true);
98  mWorkflowDefaultDesktops["IntraOpImagingUid"] = desktop;
99  //-----------------------------------------------------
100 
101  //-----------------------------------------------------
102  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
103  toolbars.clear();
104  toolbars << standardToolbars << "Sampler" << "Help";
105  this->addToolbarsToDesktop(desktop, toolbars);
106  desktop.addPreset("active_mesh_widget", Qt::LeftDockWidgetArea, true);
107  desktop.addPreset("volume_properties_widget", Qt::LeftDockWidgetArea, true);
108  desktop.addPreset("slice_properties_widget", Qt::LeftDockWidgetArea, true);
109  desktop.addPreset("metric_widget", Qt::LeftDockWidgetArea, true);
110  desktop.addPreset("console_widget", Qt::LeftDockWidgetArea, false);
111  desktop.addPreset("playback_widget", Qt::BottomDockWidgetArea, false);
112  mWorkflowDefaultDesktops["PostOpControllUid"] = desktop;
113  //-----------------------------------------------------
114 }
115 
116 void ApplicationsParser::addToolbarsToDesktop(Desktop& desktop, QStringList toolbars)
117 {
118  for (int i=0; i<toolbars.size(); ++i)
119  {
120  desktop.addPreset(toolbars[i]+"ToolBar", Qt::TopToolBarArea);
121  }
122 }
123 
124 void ApplicationsParser::addDefaultDesktops(QString workflowStateUid, QString layoutUid, QString mainwindowstate)
125 {
126  mWorkflowDefaultDesktops[workflowStateUid] = Desktop(layoutUid,
127  QByteArray::fromBase64(mainwindowstate.toLatin1()));
128 }
129 
131 {
132  //TODO use applicationName!!!
133  if (!mWorkflowDefaultDesktops.count(workflowName))
134  return mWorkflowDefaultDesktops["DEFAULT"];
135  return mWorkflowDefaultDesktops[workflowName];
136 }
137 
139 {
140  Desktop retval;
141  XmlOptionFile file = this->getSettings();
142  QDomElement workflowElement = file.descend(workflowName).getElement();
143  QDomElement desktopElement;
144  if (workflowElement.namedItem("custom").isNull())
145  {
146  return this->getDefaultDesktop(workflowName);
147  }
148  else
149  {
150  desktopElement = workflowElement.namedItem("custom").toElement();
151  }
152  retval.mMainWindowState = QByteArray::fromBase64(desktopElement.attribute("mainwindowstate").toLatin1());
153  retval.mLayoutUid = desktopElement.attribute("layoutuid");
154  retval.mSecondaryLayoutUid = desktopElement.attribute("secondarylayoutuid");
155 
156  return retval;
157 }
158 
159 void ApplicationsParser::setDesktop(QString workflowName, Desktop desktop)
160 {
161  XmlOptionFile file = this->getSettings();
162  QDomElement desktopElement = file.descend(workflowName).descend("custom").getElement();
163  // QDomElement desktopElement =
164  // mXmlFile.descend(applicationName).descend("workflows").descend(workflowName).descend("custom").getElement();
165  desktopElement.setAttribute("mainwindowstate", QString(desktop.mMainWindowState.toBase64()));
166  desktopElement.setAttribute("layoutuid", desktop.mLayoutUid);
167  desktopElement.setAttribute("secondarylayoutuid", desktop.mSecondaryLayoutUid);
168  file.save();
169 }
170 
171 XmlOptionFile ApplicationsParser::getSettings()
172 {
173  XmlOptionFile retval = ProfileManager::getInstance()->activeProfile()->getXmlSettings();
174  retval = retval.descend("workflows");
175  return retval;
176 }
177 
178 void ApplicationsParser::resetDesktop(QString workflowName)
179 {
180  XmlOptionFile file = this->getSettings();
181 
182  QDomElement workflowElement = file.descend(workflowName).getElement();
183  workflowElement.removeChild(workflowElement.namedItem("custom"));
184  file.save();
185 }
186 
187 
188 } //namespace cx
cxWorkflowStateMachine.h
cx::XmlOptionFile
Helper class for xml files used to store ssc/cx data.
Definition: cxXmlOptionItem.h:78
cx::Desktop::addPreset
void addPreset(QString name, int pos, bool tabbed=true)
Definition: cxStateService.cpp:33
cxApplicationsParser.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::XmlOptionFile::save
void save()
save entire document.
Definition: cxXmlOptionItem.cpp:396
cx::ApplicationsParser::setDesktop
void setDesktop(QString workflowName, Desktop desktop)
Definition: cxApplicationsParser.cpp:159
cxXmlOptionItem.h
cx::XmlOptionFile::descend
XmlOptionFile descend(QString element) const
step one level down in the xml tree
Definition: cxXmlOptionItem.cpp:271
cx::ApplicationsParser::getDesktop
Desktop getDesktop(QString workflowName)
Definition: cxApplicationsParser.cpp:138
cx::ApplicationsParser::ApplicationsParser
ApplicationsParser()
Definition: cxApplicationsParser.cpp:35
cxProfile.h
cx::Desktop::mMainWindowState
QByteArray mMainWindowState
Definition: cxStateService.h:51
cxPatientModelServiceProxy.h
cxSpaceProviderImpl.h
cx::XmlOptionFile::getElement
QDomElement getElement()
return the current element
Definition: cxXmlOptionItem.cpp:365
cxSettings.h
cx::ApplicationsParser::resetDesktop
void resetDesktop(QString workflowName)
Definition: cxApplicationsParser.cpp:178
cxDataLocations.h
cx::Desktop::mLayoutUid
QString mLayoutUid
Definition: cxStateService.h:49
cxTrackingServiceProxy.h
cx::ProfileManager::getInstance
static ProfileManager * getInstance(QString defaultProfile=QString("Laboratory"))
returns the only instance of this class
Definition: cxProfile.cpp:167
cx::ProfileManager::activeProfile
ProfilePtr activeProfile()
Definition: cxProfile.cpp:285
cx::ApplicationsParser::getDefaultDesktop
Desktop getDefaultDesktop(QString workflowName)
Definition: cxApplicationsParser.cpp:130
cxVideoServiceProxy.h
cx::Desktop
Data class for CustusX desktop.
Definition: cxStateService.h:43
cx::Desktop::mSecondaryLayoutUid
QString mSecondaryLayoutUid
Definition: cxStateService.h:50