NorMIT-nav  18.04-rc6
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 "cxEnumConverter.h"
19 #include "cxXmlOptionItem.h"
20 
21 #include "cxSettings.h"
22 #include "cxDataLocations.h"
23 #include "cxWorkflowStateMachine.h"
24 #include "cxDataLocations.h"
25 #include "cxConfig.h"
26 
27 #include "cxTrackingServiceProxy.h"
29 #include "cxSpaceProviderImpl.h"
30 #include "cxVideoServiceProxy.h"
31 #include "cxProfile.h"
32 
33 namespace cx
34 {
35 
37 {
38  // mXmlFile = profile()->getXmlSettings().descend("applications");
39 
40  QString fullState =
41  "AAAA/wAAAAD9AAAAAgAAAAAAAAGEAAADlvwCAAAACvsAAAAiAEMAbwBuAHQAZQB4AHQARABvAGMAawBXAGkAZABnAGUAdAEAAAMgAAAAWgAAAAAAAAAA+wAAADIASQBtAGEAZwBlAFAAcgBvAHAAZQByAHQAaQBlAHMARABvAGMAawBXAGkAZABnAGUAdAEAAAM0AAAAuwAAAAAAAAAA/AAAAEEAAAI7AAACAwEAAB36AAAAAAEAAAAV+wAAAEAAVgBvAGwAdQBtAGUAUAByAG8AcABlAHIAdABpAGUAcwBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AQAAAAD/////AAABGQD////7AAAAPABNAGUAcwBoAFAAcgBvAHAAZQByAHQAaQBlAHMAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAEAAAAA/////wAAAP4A////+wAAADoAUABvAGkAbgB0AFMAYQBtAHAAbABpAG4AZwBXAGkAZABnAG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QAAAAAAP////8AAAFMAP////sAAABGAFMAZQBnAG0AZQBuAHQAYQB0AGkAbwBuAE0AZQB0AGgAbwBkAHMAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAAPEA////+wAAAEYAUgBlAGcAaQBzAHQAcgBhAHQAaQBvAG4ATQBlAHQAaABvAGQAcwBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AAAAAAD/////AAABYgD////7AAAAPgBJAG0AYQBnAGUAUAByAG8AcABlAHIAdABpAGUAcwBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AQAAAAD/////AAAA8AD////7AAAAFABEAG8AYwBrAFcAaQBkAGcAZQB0AAAAAAAAAAGBAAABSgD////7AAAALABNAGUAdAByAGkAYwBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AAAAAAD/////AAAAZgD////7AAAALABFAHIAYQBzAGUAcgBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AAAAAAD/////AAAA2wD////7AAAAMABUAHIAYQBjAGsAUABhAGQAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAAHQA////+wAAADYAVwBpAHIAZQBQAGgAYQBuAHQAbwBtAFcAaQBkAGcAZQB0AEQAbwBjAGsAVwBpAGQAZwBlAHQAAAAAAP////8AAADyAP////wAAAKCAAABVQAAAL4BAAAd+gAAAAEBAAAAAvsAAAAuAEMAbwBuAHMAbwBsAGUAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAEAAAAA/////wAAAFQA////+wAAAC4AQgByAG8AdwBzAGUAcgBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AQAAAAAAAAFvAAAAiAD////8AAADKAAAAMsAAAAAAP////oAAAAAAQAAAAH7AAAAQABUAHIAYQBuAHMAZgBlAHIARgB1AG4AYwB0AGkAbwBuAFcAaQBkAGcAZQB0AEQAb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EAcgEAAAME/////wAAAAAAAAAAAAAAIgBTAGMAcgBlAGUAbgBzAGgAbwB0AFQAbwBvAGwAQgBhAHIBAAADWf////8AAAAAAAAAAAAAABwARABlAHMAawB0AG8AcABUAG8AbwBsAEIAYQByAQAAA4r/////AAAAAAAAAAAAAAAsAEkAbgB0AGUAcgBhAGMAdABvAHIAUwB0AHkAbABlAFQAbwBvAGwAQgBhAHIAAAAD3/////8AAAAAAAAAAAAAABYASABlAGwAcABUAG8AbwBsAEIAYQByAQAAA98AAAF4AAAAAAAAAAA=";
42 
43  // this->addDefaultDesktops(
44  // "PatientDataUid",
45  // "LAYOUT_3D_ACS",
46  // "");
47 
48  Desktop desktop;
49 
50  QStringList standardToolbars;
51  standardToolbars << "Workflow" << "Navigation" << "Tools" << "Screenshot" << "Desktop";
52 
53 
54  //-----------------------------------------------------
55  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
56  QStringList toolbars;
57  toolbars << standardToolbars << "Data" << "Help";
58  this->addToolbarsToDesktop(desktop, toolbars);
59  desktop.addPreset("active_mesh_widget", Qt::LeftDockWidgetArea, true);
60  desktop.addPreset("volume_properties_widget", Qt::LeftDockWidgetArea, true);
61  desktop.addPreset("slice_properties_widget", Qt::LeftDockWidgetArea, true);
62  desktop.addPreset("dicom_widget", Qt::LeftDockWidgetArea, true);
63  desktop.addPreset("console_widget", Qt::LeftDockWidgetArea, false);
64  desktop.addPreset("help_widget", Qt::RightDockWidgetArea, false);
65  mWorkflowDefaultDesktops["PatientDataUid"] = desktop;
66  //-----------------------------------------------------
67 
68  //-----------------------------------------------------
69  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
70  toolbars.clear();
71  toolbars << standardToolbars << "RegistrationHistory" << "Help";
72  this->addToolbarsToDesktop(desktop, toolbars);
73  desktop.addPreset("console_widget", Qt::LeftDockWidgetArea, true);
74  desktop.addPreset("org_custusx_registration_gui_widget", Qt::LeftDockWidgetArea, true);
75  desktop.addPreset("registration_history_widget", Qt::LeftDockWidgetArea, false);
76  mWorkflowDefaultDesktops["RegistrationUid"] = desktop;
77  //-----------------------------------------------------
78 
79  //-----------------------------------------------------
80  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
81  toolbars.clear();
82  toolbars << standardToolbars << "Camera3DViews" << "Sampler" << "Help";
83  this->addToolbarsToDesktop(desktop, toolbars);
84  desktop.addPreset("active_mesh_widget", Qt::LeftDockWidgetArea, true);
85  desktop.addPreset("volume_properties_widget", Qt::LeftDockWidgetArea, true);
86  desktop.addPreset("slice_properties_widget", Qt::LeftDockWidgetArea, true);
87  desktop.addPreset("console_widget", Qt::LeftDockWidgetArea, false);
88  mWorkflowDefaultDesktops["PreOpPlanningUid"] = desktop;
89  //-----------------------------------------------------
90 
91  //-----------------------------------------------------
92  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
93  toolbars.clear();
94  toolbars << standardToolbars << "InteractorStyle" << "ToolOffset" << "Help";
95  this->addToolbarsToDesktop(desktop, toolbars);
96  mWorkflowDefaultDesktops["NavigationUid"] = desktop;
97  //-----------------------------------------------------
98 
99  //-----------------------------------------------------
100  desktop = Desktop("LAYOUT_US_Acquisition", QByteArray::fromBase64(""));
101  toolbars.clear();
102  toolbars << standardToolbars << "Help";
103  this->addToolbarsToDesktop(desktop, toolbars);
104  desktop.addPreset("igt_link_widget", Qt::LeftDockWidgetArea, true);
105  desktop.addPreset("us_reconstruction", Qt::LeftDockWidgetArea, true);
106  desktop.addPreset("org_custusx_acquisition_widgets_acquisition", Qt::LeftDockWidgetArea, true);
107  mWorkflowDefaultDesktops["IntraOpImagingUid"] = desktop;
108  //-----------------------------------------------------
109 
110  //-----------------------------------------------------
111  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
112  toolbars.clear();
113  toolbars << standardToolbars << "Sampler" << "Help";
114  this->addToolbarsToDesktop(desktop, toolbars);
115  desktop.addPreset("active_mesh_widget", Qt::LeftDockWidgetArea, true);
116  desktop.addPreset("volume_properties_widget", Qt::LeftDockWidgetArea, true);
117  desktop.addPreset("slice_properties_widget", Qt::LeftDockWidgetArea, true);
118  desktop.addPreset("metric_widget", Qt::LeftDockWidgetArea, true);
119  desktop.addPreset("console_widget", Qt::LeftDockWidgetArea, false);
120  desktop.addPreset("playback_widget", Qt::BottomDockWidgetArea, false);
121  mWorkflowDefaultDesktops["PostOpControllUid"] = desktop;
122  //-----------------------------------------------------
123 }
124 
125 void ApplicationsParser::addToolbarsToDesktop(Desktop& desktop, QStringList toolbars)
126 {
127  for (int i=0; i<toolbars.size(); ++i)
128  {
129  desktop.addPreset(toolbars[i]+"ToolBar", Qt::TopToolBarArea);
130  }
131 }
132 
133 void ApplicationsParser::addDefaultDesktops(QString workflowStateUid, QString layoutUid, QString mainwindowstate)
134 {
135  mWorkflowDefaultDesktops[workflowStateUid] = Desktop(layoutUid,
136  QByteArray::fromBase64(mainwindowstate.toLatin1()));
137 }
138 
140 {
141  //TODO use applicationName!!!
142  if (!mWorkflowDefaultDesktops.count(workflowName))
143  return mWorkflowDefaultDesktops["DEFAULT"];
144  return mWorkflowDefaultDesktops[workflowName];
145 }
146 
148 {
149  Desktop retval;
150  XmlOptionFile file = this->getSettings();
151  QDomElement workflowElement = file.descend(workflowName).getElement();
152  QDomElement desktopElement;
153  if (workflowElement.namedItem("custom").isNull())
154  {
155  return this->getDefaultDesktop(workflowName);
156  }
157  else
158  {
159  desktopElement = workflowElement.namedItem("custom").toElement();
160  }
161  retval.mMainWindowState = QByteArray::fromBase64(desktopElement.attribute("mainwindowstate").toLatin1());
162  retval.mLayoutUid = desktopElement.attribute("layoutuid");
163  retval.mSecondaryLayoutUid = desktopElement.attribute("secondarylayoutuid");
164 
165  return retval;
166 }
167 
168 void ApplicationsParser::setDesktop(QString workflowName, Desktop desktop)
169 {
170  XmlOptionFile file = this->getSettings();
171  QDomElement desktopElement = file.descend(workflowName).descend("custom").getElement();
172  // QDomElement desktopElement =
173  // mXmlFile.descend(applicationName).descend("workflows").descend(workflowName).descend("custom").getElement();
174  desktopElement.setAttribute("mainwindowstate", QString(desktop.mMainWindowState.toBase64()));
175  desktopElement.setAttribute("layoutuid", desktop.mLayoutUid);
176  desktopElement.setAttribute("secondarylayoutuid", desktop.mSecondaryLayoutUid);
177  file.save();
178 }
179 
180 XmlOptionFile ApplicationsParser::getSettings()
181 {
182  XmlOptionFile retval = ProfileManager::getInstance()->activeProfile()->getXmlSettings();
183  retval = retval.descend("workflows");
184  return retval;
185 }
186 
187 void ApplicationsParser::resetDesktop(QString workflowName)
188 {
189  XmlOptionFile file = this->getSettings();
190 
191  QDomElement workflowElement = file.descend(workflowName).getElement();
192  workflowElement.removeChild(workflowElement.namedItem("custom"));
193  file.save();
194 }
195 
196 
197 } //namespace cx
ProfilePtr activeProfile()
Definition: cxProfile.cpp:285
void setDesktop(QString workflowName, Desktop desktop)
static ProfileManager * getInstance(QString defaultProfile=QString("Laboratory"))
returns the only instance of this class
Definition: cxProfile.cpp:167
QDomElement getElement()
return the current element
void resetDesktop(QString workflowName)
QByteArray mMainWindowState
Data class for CustusX desktop.
QString mLayoutUid
void save()
save entire document.
QString mSecondaryLayoutUid
Desktop getDefaultDesktop(QString workflowName)
void addPreset(QString name, int pos, bool tabbed=true)
Helper class for xml files used to store ssc/cx data.
Desktop getDesktop(QString workflowName)
XmlOptionFile descend(QString element) const
step one level down in the xml tree
Namespace for all CustusX production code.