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 "DatasourceConstants.hxx"
22 #include "MEDModule.hxx"
23 #include "Basics_Utils.hxx"
24 #include "QtxActionGroup.h"
25 #include "MEDFactoryClient.hxx"
27 #include <SalomeApp_Application.h>
28 #include <SalomeApp_Study.h>
29 #include <SalomeApp_DataObject.h>
31 #include <SALOMEDS_SObject.hxx>
32 #include <SALOMEDS_Study.hxx>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <QMessageBox>
39 static const int OPTIONS_VIEW_MODE_ID = 943;
40 static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
41 static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
42 static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
43 static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
45 PresentationController::PresentationController(MEDModule* salomeModule)
47 STDLOG("Creating a PresentationController");
48 _salomeModule = salomeModule;
49 _studyEditor = _salomeModule->getStudyEditor();
52 PresentationController::~PresentationController()
54 STDLOG("Deleting the PresentationController");
58 PresentationController::_getIconName(const std::string& name)
60 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
64 // Read value from preferences and suffix name to select icon theme
65 int theme = mgr->integerValue("MEDCalc", "icons");
67 return name + "_MODERN";
68 } else if (theme == 1) {
69 return name + "_CLASSIC";
71 return name + "_DEFAULT";
75 PresentationController::createActions()
77 STDLOG("Creating PresentationController actions");
78 int toolbarId = _salomeModule->createTool("View Mode", "PresentationToolbar");
80 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
83 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
84 ag->setText("View mode");
85 ag->setUsesDropDown(true);
87 QString label = tr("LAB_VIEW_MODE_REPLACE");
88 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
89 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
90 a->setCheckable(true);
94 label = tr("LAB_VIEW_MODE_OVERLAP");
95 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
96 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
97 a->setCheckable(true);
100 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
101 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
102 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
103 a->setCheckable(true);
106 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
107 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
108 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
109 a->setCheckable(true);
112 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, toolbarId);
115 label = tr("LAB_PRESENTATION_SCALAR_MAP");
116 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
117 QString icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
119 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeScalarMap()),icon,tooltip);
120 _salomeModule->createTool(actionId, toolbarId);
121 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
122 _salomeModule->createMenu(actionId, presentationMenuId);
124 label = tr("LAB_PRESENTATION_CONTOUR");
125 tooltip = tr("TIP_PRESENTATION_CONTOUR");
126 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
127 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeContour()),icon,tooltip);
128 _salomeModule->createTool(actionId, toolbarId);
129 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
130 _salomeModule->createMenu(actionId, presentationMenuId);
132 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
133 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
134 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
135 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeVectorField()),icon,tooltip);
136 _salomeModule->createTool(actionId, toolbarId);
137 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
138 _salomeModule->createMenu(actionId, presentationMenuId);
140 label = tr("LAB_PRESENTATION_SLICES");
141 tooltip = tr("TIP_PRESENTATION_SLICES");
142 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
143 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeSlices()),icon,tooltip);
144 _salomeModule->createTool(actionId, toolbarId);
145 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
146 _salomeModule->createMenu(actionId, presentationMenuId);
148 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
149 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
150 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
151 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeDeflectionShape()),icon,tooltip);
152 _salomeModule->createTool(actionId, toolbarId);
153 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
154 _salomeModule->createMenu(actionId, presentationMenuId);
156 label = tr("LAB_PRESENTATION_POINT_SPRITE");
157 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
158 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
159 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizePointSprite()),icon,tooltip);
160 _salomeModule->createTool(actionId, toolbarId);
161 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
162 _salomeModule->createMenu(actionId, presentationMenuId);
165 MEDCALC::MEDPresentationViewMode
166 PresentationController::getSelectedViewMode()
168 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
169 return MEDCALC::VIEW_MODE_REPLACE;
171 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
172 return MEDCALC::VIEW_MODE_OVERLAP;
174 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
175 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
177 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
178 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
183 PresentationController::visualize(PresentationEvent::EventType eventType)
185 // We need a _studyEditor updated on the active study
186 _studyEditor->updateActiveStudy();
188 // Get the selected objects in the study (SObject)
189 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
191 // For each object, emit a signal to the workspace to request a
192 // visualisation using the tui command (so that the user can see how
193 // to make a view of an object from the tui console).
194 for (int i=0; i<listOfSObject->size(); i++) {
195 SALOMEDS::SObject_var soField = listOfSObject->at(i);
196 int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
197 // If fieldId equals -1, then it means that it is not a field
198 // managed by the MED module, and we stop this function process.
202 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
203 if (! fieldHandler) {
204 QMessageBox::warning(_salomeModule->getApp()->desktop(),
205 tr("Operation not allowed"),
206 tr("No field is defined"));
210 PresentationEvent* event = new PresentationEvent();
211 event->eventtype = eventType;
212 XmedDataObject* dataObject = new XmedDataObject();
213 dataObject->setFieldHandler(*fieldHandler);
214 event->objectdata = dataObject;
215 emit presentationSignal(event);
220 PresentationController::OnVisualizeScalarMap()
222 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
226 PresentationController::OnVisualizeContour()
228 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
232 PresentationController::OnVisualizeVectorField()
234 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
238 PresentationController::OnVisualizeSlices()
240 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
244 PresentationController::OnVisualizeDeflectionShape()
246 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
250 PresentationController::OnVisualizePointSprite()
252 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
256 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
258 if (presentationId < 0) {
259 std::cerr << "Unknown presentation\n";
263 std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name");
264 std::string icon = std::string("ICO_") + name;
265 icon = _getIconName(icon);
266 name = tr(name.c_str()).toStdString();
267 std::string label = tr(icon.c_str()).toStdString();
269 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
270 _PTR(Study) studyDS = study->studyDS();
272 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str());
274 // update Object browser
275 _salomeModule->getApp()->updateObjectBrowser(true);
279 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
281 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
282 this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);