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 "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>
39 #include <QDockWidget>
41 PresentationController::PresentationController(MEDModule* salomeModule)
43 STDLOG("Creating a PresentationController");
44 _salomeModule = salomeModule;
45 _studyEditor = _salomeModule->getStudyEditor();
47 _widgetPresentationParameters = new WidgetPresentationParameters();
49 QMainWindow* parent = salomeModule->getApp()->desktop();
50 QDockWidget *dockWidget = new QDockWidget(parent);
51 dockWidget->setVisible(false);
52 dockWidget->setWindowTitle(tr("TITLE_PRESENTATION_PARAMETERS"));
53 dockWidget->setObjectName(tr("TITLE_PRESENTATION_PARAMETERS"));
54 dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
55 dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
56 dockWidget->setWidget(_widgetPresentationParameters);
57 parent->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
61 PresentationController::~PresentationController()
63 STDLOG("Deleting the PresentationController");
67 PresentationController::_getIconName(const std::string& name)
69 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
73 // Read value from preferences and suffix name to select icon theme
74 int theme = mgr->integerValue("MEDCalc", "icons");
76 return name + "_MODERN";
77 } else if (theme == 1) {
78 return name + "_CLASSIC";
80 return name + "_DEFAULT";
84 PresentationController::createActions()
86 STDLOG("Creating PresentationController actions");
88 int presentationToolbarId = _salomeModule->createTool("View Mode", "PresentationToolbar");
89 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
92 QString label = tr("LAB_PRESENTATION_SCALAR_MAP");
93 QString tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
94 QString icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
96 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeScalarMap()),icon,tooltip);
97 _salomeModule->createTool(actionId, presentationToolbarId);
98 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
99 _salomeModule->createMenu(actionId, presentationMenuId);
101 label = tr("LAB_PRESENTATION_CONTOUR");
102 tooltip = tr("TIP_PRESENTATION_CONTOUR");
103 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
104 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeContour()),icon,tooltip);
105 _salomeModule->createTool(actionId, presentationToolbarId);
106 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
107 _salomeModule->createMenu(actionId, presentationMenuId);
109 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
110 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
111 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
112 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeVectorField()),icon,tooltip);
113 _salomeModule->createTool(actionId, presentationToolbarId);
114 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
115 _salomeModule->createMenu(actionId, presentationMenuId);
117 label = tr("LAB_PRESENTATION_SLICES");
118 tooltip = tr("TIP_PRESENTATION_SLICES");
119 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
120 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeSlices()),icon,tooltip);
121 _salomeModule->createTool(actionId, presentationToolbarId);
122 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
123 _salomeModule->createMenu(actionId, presentationMenuId);
125 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
126 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
127 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
128 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeDeflectionShape()),icon,tooltip);
129 _salomeModule->createTool(actionId, presentationToolbarId);
130 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
131 _salomeModule->createMenu(actionId, presentationMenuId);
133 label = tr("LAB_PRESENTATION_POINT_SPRITE");
134 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
135 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
136 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizePointSprite()),icon,tooltip);
137 _salomeModule->createTool(actionId, presentationToolbarId);
138 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
139 _salomeModule->createMenu(actionId, presentationMenuId);
142 MEDCALC::MEDPresentationViewMode
143 PresentationController::getSelectedViewMode()
145 return _widgetPresentationParameters->getViewMode();
149 PresentationController::visualize(PresentationEvent::EventType eventType)
151 // We need a _studyEditor updated on the active study
152 _studyEditor->updateActiveStudy();
154 // Get the selected objects in the study (SObject)
155 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
157 // For each object, emit a signal to the workspace to request a
158 // visualisation using the tui command (so that the user can see how
159 // to make a view of an object from the tui console).
160 for (int i=0; i<listOfSObject->size(); i++) {
161 SALOMEDS::SObject_var soField = listOfSObject->at(i);
162 int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
163 // If fieldId equals -1, then it means that it is not a field
164 // managed by the MED module, and we stop this function process.
168 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
169 if (! fieldHandler) {
170 QMessageBox::warning(_salomeModule->getApp()->desktop(),
171 tr("Operation not allowed"),
172 tr("No field is defined"));
176 PresentationEvent* event = new PresentationEvent();
177 event->eventtype = eventType;
178 XmedDataObject* dataObject = new XmedDataObject();
179 dataObject->setFieldHandler(*fieldHandler);
180 event->objectdata = dataObject;
181 emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
186 PresentationController::OnVisualizeScalarMap()
188 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
192 PresentationController::OnVisualizeContour()
194 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
198 PresentationController::OnVisualizeVectorField()
200 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
204 PresentationController::OnVisualizeSlices()
206 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
210 PresentationController::OnVisualizeDeflectionShape()
212 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
216 PresentationController::OnVisualizePointSprite()
218 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
222 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
224 if (presentationId < 0) {
225 std::cerr << "Unknown presentation\n";
229 std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name");
230 std::string icon = std::string("ICO_") + name;
231 icon = _getIconName(icon);
232 name = tr(name.c_str()).toStdString();
233 std::string label = tr(icon.c_str()).toStdString();
235 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
236 _PTR(Study) studyDS = study->studyDS();
238 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str());
240 // update Object browser
241 _salomeModule->getApp()->updateObjectBrowser(true);
245 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
247 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
248 this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);