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)
48 STDLOG("Creating a PresentationController");
49 _salomeModule = salomeModule;
50 _studyEditor = _salomeModule->getStudyEditor();
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);
179 MEDCALC::MEDPresentationViewMode
180 PresentationController::getSelectedViewMode()
182 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
183 return MEDCALC::VIEW_MODE_REPLACE;
185 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
186 return MEDCALC::VIEW_MODE_OVERLAP;
188 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
189 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
191 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
192 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
195 STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
196 return MEDCALC::VIEW_MODE_REPLACE;
199 MEDCALC::MEDPresentationColorMap
200 PresentationController::getSelectedColorMap()
202 return _widgetPresentationParameters->getColorMap();
206 PresentationController::visualize(PresentationEvent::EventType eventType)
208 // We need a _studyEditor updated on the active study
209 _studyEditor->updateActiveStudy();
211 // Get the selected objects in the study (SObject)
212 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
214 // For each object, emit a signal to the workspace to request a
215 // visualisation using the tui command (so that the user can see how
216 // to make a view of an object from the tui console).
217 for (int i=0; i<listOfSObject->size(); i++) {
218 SALOMEDS::SObject_var soField = listOfSObject->at(i);
219 int fieldId = _studyEditor->getParameterInt(soField,FIELD_ID);
220 // If fieldId equals -1, then it means that it is not a field
221 // managed by the MED module, and we stop this function process.
225 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
226 if (! fieldHandler) {
227 QMessageBox::warning(_salomeModule->getApp()->desktop(),
228 tr("Operation not allowed"),
229 tr("No field is defined"));
233 PresentationEvent* event = new PresentationEvent();
234 event->eventtype = eventType;
235 XmedDataObject* dataObject = new XmedDataObject();
236 dataObject->setFieldHandler(*fieldHandler);
237 event->objectdata = dataObject;
238 emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
243 PresentationController::OnVisualizeScalarMap()
245 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
249 PresentationController::OnVisualizeContour()
251 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
255 PresentationController::OnVisualizeVectorField()
257 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
261 PresentationController::OnVisualizeSlices()
263 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
267 PresentationController::OnVisualizeDeflectionShape()
269 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
273 PresentationController::OnVisualizePointSprite()
275 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
279 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
281 if (presentationId < 0) {
282 std::cerr << "Unknown presentation\n";
286 std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name");
287 std::string icon = std::string("ICO_") + name;
288 icon = _getIconName(icon);
289 name = tr(name.c_str()).toStdString();
290 std::string label = tr(icon.c_str()).toStdString();
292 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
293 _PTR(Study) studyDS = study->studyDS();
295 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str(), presentationId);
297 // update Object browser
298 _salomeModule->getApp()->updateObjectBrowser(true);
302 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
304 if (presentationId < 0) {
305 std::cerr << "Unknown presentation\n";
309 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
310 _PTR(Study) studyDS = study->studyDS();
312 _salomeModule->engine()->unregisterPresentation(_CAST(Study, studyDS)->GetStudy(), presentationId);
314 // update Object browser
315 _salomeModule->getApp()->updateObjectBrowser(true);
319 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
321 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
322 this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
324 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
325 this->updateTreeViewForPresentationRemoval(event->presentationId);
330 PresentationController::showDockWidgets(bool isVisible)
332 STDLOG("Switching PresentationController visibility to: " << isVisible);
333 _dockWidget->setVisible(isVisible);