1 // Copyright (C) 2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PresentationController.hxx"
21 #include <MEDCalcConstants.hxx>
22 #include "MEDModule.hxx"
23 #include "Basics_Utils.hxx"
24 #include "QtxActionGroup.h"
25 #include "QtxActionToolMgr.h"
26 #include "MEDFactoryClient.hxx"
28 #include <SalomeApp_Application.h>
29 #include <SalomeApp_Study.h>
30 #include <SalomeApp_DataObject.h>
32 #include <SALOMEDS_SObject.hxx>
33 #include <SALOMEDS_Study.hxx>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <QMessageBox>
40 static const int OPTIONS_VIEW_MODE_ID = 943;
41 static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
42 static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
43 static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
44 static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
46 PresentationController::PresentationController(MEDModule* salomeModule) :
47 _salomeModule(salomeModule),
48 _studyEditor(salomeModule->getStudyEditor())
50 STDLOG("Creating a PresentationController");
52 _widgetPresentationParameters = new WidgetPresentationParameters();
54 QMainWindow* parent = salomeModule->getApp()->desktop();
55 _dockWidget = new QDockWidget(parent);
56 _dockWidget->setVisible(false);
57 _dockWidget->setWindowTitle(tr("TITLE_PRESENTATION_PARAMETERS"));
58 _dockWidget->setObjectName(tr("TITLE_PRESENTATION_PARAMETERS"));
59 _dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
60 _dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
61 _dockWidget->setWidget(_widgetPresentationParameters);
62 parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget);
63 //_dockWidget->show();
66 PresentationController::~PresentationController()
68 STDLOG("Deleting the PresentationController");
72 PresentationController::_getIconName(const std::string& name)
74 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
78 // Read value from preferences and suffix name to select icon theme
79 int theme = mgr->integerValue("MEDCalc", "icons");
81 return name + "_MODERN";
82 } else if (theme == 1) {
83 return name + "_CLASSIC";
85 return name + "_DEFAULT";
89 PresentationController::createActions()
91 STDLOG("Creating PresentationController actions");
94 int viewModeToolbarId = _salomeModule->createTool("View Mode", "ViewModeToolbar");
95 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
96 ag->setText("View mode");
97 ag->setUsesDropDown(true);
98 QString label = tr("LAB_VIEW_MODE_REPLACE");
99 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
100 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
101 a->setCheckable(true);
105 label = tr("LAB_VIEW_MODE_OVERLAP");
106 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
107 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
108 a->setCheckable(true);
111 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
112 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
113 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
114 a->setCheckable(true);
117 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
118 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
119 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
120 a->setCheckable(true);
123 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, viewModeToolbarId);
126 int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar");
127 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
129 label = tr("LAB_PRESENTATION_SCALAR_MAP");
130 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
131 QString icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
133 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeScalarMap()),icon,tooltip);
134 _salomeModule->createTool(actionId, presentationToolbarId);
135 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
136 _salomeModule->createMenu(actionId, presentationMenuId);
138 label = tr("LAB_PRESENTATION_CONTOUR");
139 tooltip = tr("TIP_PRESENTATION_CONTOUR");
140 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
141 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeContour()),icon,tooltip);
142 _salomeModule->createTool(actionId, presentationToolbarId);
143 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
144 _salomeModule->createMenu(actionId, presentationMenuId);
146 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
147 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
148 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
149 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeVectorField()),icon,tooltip);
150 _salomeModule->createTool(actionId, presentationToolbarId);
151 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
152 _salomeModule->createMenu(actionId, presentationMenuId);
154 label = tr("LAB_PRESENTATION_SLICES");
155 tooltip = tr("TIP_PRESENTATION_SLICES");
156 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
157 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeSlices()),icon,tooltip);
158 _salomeModule->createTool(actionId, presentationToolbarId);
159 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
160 _salomeModule->createMenu(actionId, presentationMenuId);
162 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
163 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
164 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
165 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeDeflectionShape()),icon,tooltip);
166 _salomeModule->createTool(actionId, presentationToolbarId);
167 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
168 _salomeModule->createMenu(actionId, presentationMenuId);
170 label = tr("LAB_PRESENTATION_POINT_SPRITE");
171 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
172 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
173 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizePointSprite()),icon,tooltip);
174 _salomeModule->createTool(actionId, presentationToolbarId);
175 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
176 _salomeModule->createMenu(actionId, presentationMenuId);
178 label = tr("LAB_DELETE_PRESENTATION");
179 tooltip = tr("TIP_DELETE_PRESENTATION");
180 icon = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str());
181 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnDeletePresentation()),icon,tooltip);
182 // _salomeModule->createTool(actionId, presentationToolbarId);
183 // _salomeModule->action(actionId)->setIconVisibleInMenu(true);
184 _salomeModule->createMenu(actionId, presentationMenuId);
188 MEDCALC::MEDPresentationViewMode
189 PresentationController::getSelectedViewMode()
191 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
192 return MEDCALC::VIEW_MODE_REPLACE;
194 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
195 return MEDCALC::VIEW_MODE_OVERLAP;
197 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
198 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
200 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
201 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
204 STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
205 return MEDCALC::VIEW_MODE_REPLACE;
208 MEDCALC::MEDPresentationColorMap
209 PresentationController::getSelectedColorMap()
211 return _widgetPresentationParameters->getColorMap();
215 PresentationController::visualize(PresentationEvent::EventType eventType)
217 // We need a _studyEditor updated on the active study
218 _studyEditor->updateActiveStudy();
220 // Get the selected objects in the study (SObject)
221 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
223 // For each object, emit a signal to the workspace to request a
224 // visualisation using the tui command (so that the user can see how
225 // to make a view of an object from the tui console).
226 for (int i=0; i<listOfSObject->size(); i++) {
227 SALOMEDS::SObject_var soField = listOfSObject->at(i);
230 fieldId = _studyEditor->getParameterInt(soField,FIELD_ID); }
232 if (fieldId < 0) // is it a field serie ?
234 int fieldSeriesId = -1;
236 fieldSeriesId = _studyEditor->getParameterInt(soField,FIELD_SERIES_ID); }
238 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
239 // managed by the MED module, and we stop this function process.
240 if ( fieldSeriesId < 0)
242 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
243 if (fieldHandlerList->length() < 0)
245 // For a field series, get the first real field entry:
246 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
247 fieldId = fieldHandler.id;
250 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
251 if (! fieldHandler) {
252 QMessageBox::warning(_salomeModule->getApp()->desktop(),
253 tr("Operation not allowed"),
254 tr("No field is defined"));
258 PresentationEvent* event = new PresentationEvent();
259 event->eventtype = eventType;
260 XmedDataObject* dataObject = new XmedDataObject();
261 dataObject->setFieldHandler(*fieldHandler);
262 event->objectdata = dataObject;
263 emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
268 PresentationController::OnVisualizeScalarMap()
270 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
274 PresentationController::OnVisualizeContour()
276 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
280 PresentationController::OnVisualizeVectorField()
282 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
286 PresentationController::OnVisualizeSlices()
288 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
292 PresentationController::OnVisualizeDeflectionShape()
294 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
298 PresentationController::OnVisualizePointSprite()
300 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
304 PresentationController::OnDeletePresentation()
306 // We need a _studyEditor updated on the active study
307 _studyEditor->updateActiveStudy();
309 // Get the selected objects in the study (SObject)
310 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
312 // For each object, emit a signal to the workspace to request pres deletion
313 for (int i=0; i<listOfSObject->size(); i++) {
314 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
315 int presId = _studyEditor->getParameterInt(soPres,PRESENTATION_ID);
316 // If fieldId equals -1, then it means that it is not a field
317 // managed by the MED module, and we stop this function process.
321 STDLOG("Requesting deletion of presentation: ")
322 std::ostringstream oss;
324 STDLOG(" - Pres id: " + oss.str());
326 PresentationEvent* event = new PresentationEvent();
327 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
328 XmedDataObject* dataObject = new XmedDataObject();
329 dataObject->setPresentationId(presId);
330 event->objectdata = dataObject;
331 emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
336 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
338 if (presentationId < 0) {
339 std::cerr << "Unknown presentation\n";
343 std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name");
344 std::string icon = std::string("ICO_") + name;
345 icon = _getIconName(icon);
346 name = tr(name.c_str()).toStdString();
347 std::string label = tr(icon.c_str()).toStdString();
349 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
350 _PTR(Study) studyDS = study->studyDS();
352 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str(), presentationId);
354 // update Object browser
355 _salomeModule->getApp()->updateObjectBrowser(true);
359 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
361 if (presentationId < 0) {
362 std::cerr << "Unknown presentation\n";
366 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
367 _PTR(Study) studyDS = study->studyDS();
369 _salomeModule->engine()->unregisterPresentation(_CAST(Study, studyDS)->GetStudy(), presentationId);
371 // update Object browser
372 _salomeModule->getApp()->updateObjectBrowser(true);
376 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
378 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
379 this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
381 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
382 this->updateTreeViewForPresentationRemoval(event->presentationId);
387 PresentationController::showDockWidgets(bool isVisible)
389 STDLOG("Switching PresentationController visibility to: " << isVisible);
390 _dockWidget->setVisible(isVisible);