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 <QMessageBox>
37 static const int OPTIONS_VIEW_MODE_ID = 943;
38 static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
39 static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
40 static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
41 static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
43 PresentationController::PresentationController(MEDModule* salomeModule)
45 STDLOG("Creating a PresentationController");
46 _salomeModule = salomeModule;
47 _studyEditor = _salomeModule->getStudyEditor();
50 PresentationController::~PresentationController()
52 STDLOG("Deleting the PresentationController");
56 PresentationController::createActions()
58 STDLOG("Creating PresentationController actions");
59 int toolbarId = _salomeModule->createTool("View Mode", "PresentationToolbar");
61 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
64 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
65 ag->setText("View mode");
66 ag->setUsesDropDown(true);
68 QString label = tr("LAB_VIEW_MODE_REPLACE");
69 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
70 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
71 a->setCheckable(true);
75 label = tr("LAB_VIEW_MODE_OVERLAP");
76 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
77 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
78 a->setCheckable(true);
81 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
82 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
83 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
84 a->setCheckable(true);
87 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
88 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
89 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
90 a->setCheckable(true);
93 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, toolbarId);
96 label = tr("LAB_PRESENTATION_SCALAR_MAP");
97 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
98 QString icon = tr("ICO_PRESENTATION_SCALAR_MAP");
100 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeScalarMap()),icon,tooltip);
101 _salomeModule->createTool(actionId, toolbarId);
102 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
103 _salomeModule->createMenu(actionId, presentationMenuId);
105 label = tr("LAB_PRESENTATION_CONTOUR");
106 tooltip = tr("TIP_PRESENTATION_CONTOUR");
107 icon = tr("ICO_PRESENTATION_CONTOUR");
108 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeContour()),icon,tooltip);
109 _salomeModule->createTool(actionId, toolbarId);
110 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
111 _salomeModule->createMenu(actionId, presentationMenuId);
113 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
114 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
115 icon = tr("ICO_PRESENTATION_VECTOR_FIELD");
116 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeVectorField()),icon,tooltip);
117 _salomeModule->createTool(actionId, toolbarId);
118 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
119 _salomeModule->createMenu(actionId, presentationMenuId);
121 label = tr("LAB_PRESENTATION_SLICES");
122 tooltip = tr("TIP_PRESENTATION_SLICES");
123 icon = tr("ICO_PRESENTATION_SLICES");
124 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeSlices()),icon,tooltip);
125 _salomeModule->createTool(actionId, toolbarId);
126 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
127 _salomeModule->createMenu(actionId, presentationMenuId);
129 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
130 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
131 icon = tr("ICO_PRESENTATION_DEFLECTION_SHAPE");
132 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeDeflectionShape()),icon,tooltip);
133 _salomeModule->createTool(actionId, toolbarId);
134 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
135 _salomeModule->createMenu(actionId, presentationMenuId);
137 label = tr("LAB_PRESENTATION_POINT_SPRITE");
138 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
139 icon = tr("ICO_PRESENTATION_POINT_SPRITE");
140 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizePointSprite()),icon,tooltip);
141 _salomeModule->createTool(actionId, toolbarId);
142 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
143 _salomeModule->createMenu(actionId, presentationMenuId);
146 MEDCALC::MEDPresentationViewMode
147 PresentationController::getSelectedViewMode()
149 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
150 return MEDCALC::VIEW_MODE_REPLACE;
152 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
153 return MEDCALC::VIEW_MODE_OVERLAP;
155 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
156 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
158 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
159 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
164 PresentationController::visualize(PresentationEvent::EventType eventType)
166 // We need a _studyEditor updated on the active study
167 _studyEditor->updateActiveStudy();
169 // Get the selected objects in the study (SObject)
170 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
172 // For each object, emit a signal to the workspace to request a
173 // visualisation using the tui command (so that the user can see how
174 // to make a view of an object from the tui console).
175 for (int i=0; i<listOfSObject->size(); i++) {
176 SALOMEDS::SObject_var soField = listOfSObject->at(i);
177 int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
178 // If fieldId equals -1, then it means that it is not a field
179 // managed by the MED module, and we stop this function process.
183 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
184 if (! fieldHandler) {
185 QMessageBox::warning(_salomeModule->getApp()->desktop(),
186 tr("Operation not allowed"),
187 tr("No field is defined"));
191 PresentationEvent* event = new PresentationEvent();
192 event->eventtype = eventType;
193 XmedDataObject* dataObject = new XmedDataObject();
194 dataObject->setFieldHandler(*fieldHandler);
195 event->objectdata = dataObject;
196 emit presentationSignal(event);
201 PresentationController::OnVisualizeScalarMap()
203 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
207 PresentationController::OnVisualizeContour()
209 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
213 PresentationController::OnVisualizeVectorField()
215 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
219 PresentationController::OnVisualizeSlices()
221 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
225 PresentationController::OnVisualizeDeflectionShape()
227 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
231 PresentationController::OnVisualizePointSprite()
233 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
237 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
239 if (presentationId < 0) {
240 std::cerr << "Unknown presentation\n";
244 std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name");
245 std::string icon = std::string("ICO_") + name;
246 name = tr(name.c_str()).toStdString();
247 std::string label = tr(icon.c_str()).toStdString();
249 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
250 _PTR(Study) studyDS = study->studyDS();
252 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str());
254 // update Object browser
255 _salomeModule->getApp()->updateObjectBrowser(true);
259 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
261 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
262 this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);