Fraxinus  16.5.0-fx-rc5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxApplicationsParser.h"
34 
35 #include <iostream>
36 #include <QApplication>
37 #include <QByteArray>
38 #include <QDir>
39 #include "cxEnumConverter.h"
40 #include "cxXmlOptionItem.h"
41 
42 #include "cxSettings.h"
43 #include "cxDataLocations.h"
44 #include "cxWorkflowStateMachine.h"
45 #include "cxDataLocations.h"
46 #include "cxConfig.h"
47 
48 #include "cxTrackingServiceProxy.h"
50 #include "cxSpaceProviderImpl.h"
51 #include "cxVideoServiceProxy.h"
52 #include "cxProfile.h"
53 
54 namespace cx
55 {
56 
58 {
59 // mXmlFile = profile()->getXmlSettings().descend("applications");
60 
61  QString fullState =
62  "AAAA/wAAAAD9AAAAAgAAAAAAAAGEAAADlvwCAAAACvsAAAAiAEMAbwBuAHQAZQB4AHQARABvAGMAawBXAGkAZABnAGUAdAEAAAMgAAAAWgAAAAAAAAAA+wAAADIASQBtAGEAZwBlAFAAcgBvAHAAZQByAHQAaQBlAHMARABvAGMAawBXAGkAZABnAGUAdAEAAAM0AAAAuwAAAAAAAAAA/AAAAEEAAAI7AAACAwEAAB36AAAAAAEAAAAV+wAAAEAAVgBvAGwAdQBtAGUAUAByAG8AcABlAHIAdABpAGUAcwBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AQAAAAD/////AAABGQD////7AAAAPABNAGUAcwBoAFAAcgBvAHAAZQByAHQAaQBlAHMAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAEAAAAA/////wAAAP4A////+wAAADoAUABvAGkAbgB0AFMAYQBtAHAAbABpAG4AZwBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AAAAAAD/////AAAAAAAAAAD7AAAAOgBDAGEAbQBlAHIAYQBDAG8AbgB0AHIAbwBsAFcAaQBkAGcAZQB0AEQAbwBjAGsAVwBpAGQAZwBlAHQAAAAAAP////8AAAAAAAAAAPsAAAAuAEkARwBUAEwAaQBuAGsAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAAUEA////+wAAADgAVQBTAEEAYwBxAHUAcwBpAHQAaQBvAG4AVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAANQA////+wAAAEIAVAByAGEAYwBrAGUAZABDAGUAbgB0AGUAcgBsAGkAbgBlAFcAaQBkAGcAZQB0AEQAbwBjAGsAVwBpAGQAZwBlAHQAAAAAAP////8AAADDAP////sAAAA0AE4AYQB2AGkAZwBhAHQAaQBvAG4AVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAAMEA////+wAAADIARgByAGEAbQBlAFQAcgBlAGUAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAAGYA////+wAAADwAVABvAG8AbABQAHIAbwBwAGUAcgB0AGkAZQBzAFcAaQBkAGcAZQB0AEQAbwBjAGsAVwBpAGQAZwBlAHQBAAAAAP////8AAAGEAP////sAAABGAFIAZQBnAGkAcwB0AHIAYQB0AGkAbwBuAEgAaQBzAHQAbwByAHkAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAAQIA////+wAAAEQAQwBhAGwAaQBiAHIAYQB0AGkAbwBuAE0AZQB0AGgAbwBkAHMAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAAZMA////+wAAAEgAVgBpAHMAdQBhAGwAaQB6AGEAdABpAG8AbgBNAGUAdABoAG8AZABzAFcAaQBkAGcAZQB0AEQAbwBjAGsAVwBpAGQAZwBlAHQAAAAAAP////8AAAFMAP////sAAABGAFMAZQBnAG0AZQBuAHQAYQB0AGkAbwBuAE0AZQB0AGgAbwBkAHMAVwBpAGQAZwBlAHQARABvAGMAawBXAGkAZABnAGUAdAAAAAAA/////wAAAPEA////+wAAAEYAUgBlAGcAaQBzAHQAcgBhAHQAaQBvAG4ATQBlAHQAaABvAGQAcwBXAGkAZABnAGUAdABEAG8AYwBrAFcAaQBkAGcAZQB0AAAAAAD/////AAABYgD////7AAAAPgBJAG0AYQBnAGUAUAByAG8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4AAAAAAAAAAA=";
63 
64 // this->addDefaultDesktops(
65 // "PatientDataUid",
66 // "LAYOUT_3D_ACS",
67 // "");
68 
69  Desktop desktop;
70 
71  QStringList standardToolbars;
72  standardToolbars << "Workflow" << "Navigation" << "Tools" << "Screenshot" << "Desktop";
73 
74 
75  //-----------------------------------------------------
76  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
77  QStringList toolbars;
78  toolbars << standardToolbars << "Data" << "Help";
79  this->addToolbarsToDesktop(desktop, toolbars);
80  desktop.addPreset("MeshInfoWidget", Qt::LeftDockWidgetArea, true);
81  desktop.addPreset("VolumePropertiesWidget", Qt::LeftDockWidgetArea, true);
82  desktop.addPreset("SlicePropertiesWidget", Qt::LeftDockWidgetArea, true);
83  desktop.addPreset("DicomWidget", Qt::LeftDockWidgetArea, true);
84  desktop.addPreset("ConsoleWidget", Qt::LeftDockWidgetArea, false);
85  desktop.addPreset("HelpWidget", Qt::RightDockWidgetArea, false);
86  mWorkflowDefaultDesktops["PatientDataUid"] = desktop;
87  //-----------------------------------------------------
88 
89  //-----------------------------------------------------
90  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
91  toolbars.clear();
92  toolbars << standardToolbars << "RegistrationHistory" << "Help";
93  this->addToolbarsToDesktop(desktop, toolbars);
94  desktop.addPreset("ConsoleWidget", Qt::LeftDockWidgetArea, true);
95  desktop.addPreset("org_custusx_registration_gui_widget", Qt::LeftDockWidgetArea, true);
96  desktop.addPreset("RegistrationHistoryWidget", Qt::LeftDockWidgetArea, false);
97  mWorkflowDefaultDesktops["RegistrationUid"] = desktop;
98  //-----------------------------------------------------
99 
100  //-----------------------------------------------------
101  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
102  toolbars.clear();
103  toolbars << standardToolbars << "Camera3DViews" << "Sampler" << "Help";
104  this->addToolbarsToDesktop(desktop, toolbars);
105  desktop.addPreset("MeshInfoWidget", Qt::LeftDockWidgetArea, true);
106  desktop.addPreset("VolumePropertiesWidget", Qt::LeftDockWidgetArea, true);
107  desktop.addPreset("SlicePropertiesWidget", Qt::LeftDockWidgetArea, true);
108  desktop.addPreset("ConsoleWidget", Qt::LeftDockWidgetArea, false);
109  mWorkflowDefaultDesktops["PreOpPlanningUid"] = desktop;
110  //-----------------------------------------------------
111 
112  //-----------------------------------------------------
113  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
114  toolbars.clear();
115  toolbars << standardToolbars << "InteractorStyle" << "ToolOffset" << "Help";
116  this->addToolbarsToDesktop(desktop, toolbars);
117  mWorkflowDefaultDesktops["NavigationUid"] = desktop;
118  //-----------------------------------------------------
119 
120  //-----------------------------------------------------
121  desktop = Desktop("LAYOUT_US_Acquisition", QByteArray::fromBase64(""));
122  toolbars.clear();
123  toolbars << standardToolbars << "Help";
124  this->addToolbarsToDesktop(desktop, toolbars);
125  desktop.addPreset("IGTLinkWidget", Qt::LeftDockWidgetArea, true);
126  desktop.addPreset("USReconstruction", Qt::LeftDockWidgetArea, true);
127  desktop.addPreset("org_custusx_acquisition_widgets_acquisition", Qt::LeftDockWidgetArea, true);
128  mWorkflowDefaultDesktops["IntraOpImagingUid"] = desktop;
129  //-----------------------------------------------------
130 
131  //-----------------------------------------------------
132  desktop = Desktop("LAYOUT_3D_ACS", QByteArray::fromBase64(""));
133  toolbars.clear();
134  toolbars << standardToolbars << "Sampler" << "Help";
135  this->addToolbarsToDesktop(desktop, toolbars);
136  desktop.addPreset("MeshInfoWidget", Qt::LeftDockWidgetArea, true);
137  desktop.addPreset("VolumePropertiesWidget", Qt::LeftDockWidgetArea, true);
138  desktop.addPreset("SlicePropertiesWidget", Qt::LeftDockWidgetArea, true);
139  desktop.addPreset("MetricWidget", Qt::LeftDockWidgetArea, true);
140  desktop.addPreset("ConsoleWidget", Qt::LeftDockWidgetArea, false);
141  desktop.addPreset("PlaybackWidget", Qt::BottomDockWidgetArea, false);
142  mWorkflowDefaultDesktops["PostOpControllUid"] = desktop;
143  //-----------------------------------------------------
144 }
145 
146 void ApplicationsParser::addToolbarsToDesktop(Desktop& desktop, QStringList toolbars)
147 {
148  for (int i=0; i<toolbars.size(); ++i)
149  {
150  desktop.addPreset(toolbars[i]+"ToolBar", Qt::TopToolBarArea);
151  }
152 }
153 
154 void ApplicationsParser::addDefaultDesktops(QString workflowStateUid, QString layoutUid, QString mainwindowstate)
155 {
156  mWorkflowDefaultDesktops[workflowStateUid] = Desktop(layoutUid,
157  QByteArray::fromBase64(mainwindowstate.toLatin1()));
158 }
159 
161 {
162  //TODO use applicationName!!!
163  if (!mWorkflowDefaultDesktops.count(workflowName))
164  return mWorkflowDefaultDesktops["DEFAULT"];
165  return mWorkflowDefaultDesktops[workflowName];
166 }
167 
169 {
170  Desktop retval;
171  XmlOptionFile file = this->getSettings();
172  QDomElement workflowElement = file.descend(workflowName).getElement();
173  QDomElement desktopElement;
174  if (workflowElement.namedItem("custom").isNull())
175  {
176  return this->getDefaultDesktop(workflowName);
177  }
178  else
179  {
180  desktopElement = workflowElement.namedItem("custom").toElement();
181  }
182  retval.mMainWindowState = QByteArray::fromBase64(desktopElement.attribute("mainwindowstate").toLatin1());
183  retval.mLayoutUid = desktopElement.attribute("layoutuid");
184  retval.mSecondaryLayoutUid = desktopElement.attribute("secondarylayoutuid");
185 
186  return retval;
187 }
188 
189 void ApplicationsParser::setDesktop(QString workflowName, Desktop desktop)
190 {
191  XmlOptionFile file = this->getSettings();
192  QDomElement desktopElement = file.descend(workflowName).descend("custom").getElement();
193 // QDomElement desktopElement =
194 // mXmlFile.descend(applicationName).descend("workflows").descend(workflowName).descend("custom").getElement();
195  desktopElement.setAttribute("mainwindowstate", QString(desktop.mMainWindowState.toBase64()));
196  desktopElement.setAttribute("layoutuid", desktop.mLayoutUid);
197  desktopElement.setAttribute("secondarylayoutuid", desktop.mSecondaryLayoutUid);
198  file.save();
199 }
200 
201 XmlOptionFile ApplicationsParser::getSettings()
202 {
203  XmlOptionFile retval = ProfileManager::getInstance()->activeProfile()->getXmlSettings();
204  retval = retval.descend("workflows");
205  return retval;
206 }
207 
208 void ApplicationsParser::resetDesktop(QString workflowName)
209 {
210  XmlOptionFile file = this->getSettings();
211 
212  QDomElement workflowElement = file.descend(workflowName).getElement();
213  workflowElement.removeChild(workflowElement.namedItem("custom"));
214  file.save();
215 }
216 
217 
218 } //namespace cx
ProfilePtr activeProfile()
Definition: cxProfile.cpp:301
void setDesktop(QString workflowName, Desktop desktop)
static ProfileManager * getInstance(QString defaultProfile=QString("Laboratory"))
returns the only instance of this class
Definition: cxProfile.cpp:183
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