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 PresentationController::PresentationController(MEDModule* salomeModule)
42 STDLOG("Creating a PresentationController");
43 _salomeModule = salomeModule;
44 _studyEditor = _salomeModule->getStudyEditor();
46 _widgetPresentationParameters = new WidgetPresentationParameters();
48 QMainWindow* parent = salomeModule->getApp()->desktop();
49 _dockWidget = new QDockWidget(parent);
50 _dockWidget->setVisible(false);
51 _dockWidget->setWindowTitle(tr("TITLE_PRESENTATION_PARAMETERS"));
52 _dockWidget->setObjectName(tr("TITLE_PRESENTATION_PARAMETERS"));
53 _dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
54 _dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
55 _dockWidget->setWidget(_widgetPresentationParameters);
56 parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget);
57 //_dockWidget->show();
60 PresentationController::~PresentationController()
62 STDLOG("Deleting the PresentationController");
66 PresentationController::_getIconName(const std::string& name)
68 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
72 // Read value from preferences and suffix name to select icon theme
73 int theme = mgr->integerValue("MEDCalc", "icons");
75 return name + "_MODERN";
76 } else if (theme == 1) {
77 return name + "_CLASSIC";
79 return name + "_DEFAULT";
83 PresentationController::createActions()
85 STDLOG("Creating PresentationController actions");
87 int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar");
88 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
91 QString label = tr("LAB_PRESENTATION_SCALAR_MAP");
92 QString tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
93 QString icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
95 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeScalarMap()),icon,tooltip);
96 _salomeModule->createTool(actionId, presentationToolbarId);
97 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
98 _salomeModule->createMenu(actionId, presentationMenuId);
100 label = tr("LAB_PRESENTATION_CONTOUR");
101 tooltip = tr("TIP_PRESENTATION_CONTOUR");
102 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
103 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeContour()),icon,tooltip);
104 _salomeModule->createTool(actionId, presentationToolbarId);
105 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
106 _salomeModule->createMenu(actionId, presentationMenuId);
108 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
109 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
110 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
111 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeVectorField()),icon,tooltip);
112 _salomeModule->createTool(actionId, presentationToolbarId);
113 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
114 _salomeModule->createMenu(actionId, presentationMenuId);
116 label = tr("LAB_PRESENTATION_SLICES");
117 tooltip = tr("TIP_PRESENTATION_SLICES");
118 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
119 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeSlices()),icon,tooltip);
120 _salomeModule->createTool(actionId, presentationToolbarId);
121 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
122 _salomeModule->createMenu(actionId, presentationMenuId);
124 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
125 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
126 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
127 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeDeflectionShape()),icon,tooltip);
128 _salomeModule->createTool(actionId, presentationToolbarId);
129 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
130 _salomeModule->createMenu(actionId, presentationMenuId);
132 label = tr("LAB_PRESENTATION_POINT_SPRITE");
133 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
134 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
135 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizePointSprite()),icon,tooltip);
136 _salomeModule->createTool(actionId, presentationToolbarId);
137 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
138 _salomeModule->createMenu(actionId, presentationMenuId);
141 MEDCALC::MEDPresentationViewMode
142 PresentationController::getSelectedViewMode()
144 return _widgetPresentationParameters->getViewMode();
147 MEDCALC::MEDPresentationColorMap
148 PresentationController::getSelectedColorMap()
150 return _widgetPresentationParameters->getColorMap();
154 PresentationController::visualize(PresentationEvent::EventType eventType)
156 // We need a _studyEditor updated on the active study
157 _studyEditor->updateActiveStudy();
159 // Get the selected objects in the study (SObject)
160 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
162 // For each object, emit a signal to the workspace to request a
163 // visualisation using the tui command (so that the user can see how
164 // to make a view of an object from the tui console).
165 for (int i=0; i<listOfSObject->size(); i++) {
166 SALOMEDS::SObject_var soField = listOfSObject->at(i);
167 int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
168 // If fieldId equals -1, then it means that it is not a field
169 // managed by the MED module, and we stop this function process.
173 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
174 if (! fieldHandler) {
175 QMessageBox::warning(_salomeModule->getApp()->desktop(),
176 tr("Operation not allowed"),
177 tr("No field is defined"));
181 PresentationEvent* event = new PresentationEvent();
182 event->eventtype = eventType;
183 XmedDataObject* dataObject = new XmedDataObject();
184 dataObject->setFieldHandler(*fieldHandler);
185 event->objectdata = dataObject;
186 emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
191 PresentationController::OnVisualizeScalarMap()
193 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
197 PresentationController::OnVisualizeContour()
199 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
203 PresentationController::OnVisualizeVectorField()
205 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
209 PresentationController::OnVisualizeSlices()
211 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
215 PresentationController::OnVisualizeDeflectionShape()
217 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
221 PresentationController::OnVisualizePointSprite()
223 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
227 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
229 if (presentationId < 0) {
230 std::cerr << "Unknown presentation\n";
234 std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name");
235 std::string icon = std::string("ICO_") + name;
236 icon = _getIconName(icon);
237 name = tr(name.c_str()).toStdString();
238 std::string label = tr(icon.c_str()).toStdString();
240 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
241 _PTR(Study) studyDS = study->studyDS();
243 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str());
245 // update Object browser
246 _salomeModule->getApp()->updateObjectBrowser(true);
250 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
252 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
253 this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
258 PresentationController::showDockWidgets(bool isVisible)
260 STDLOG("Switching PresentationController visibility to: " << isVisible);
261 _dockWidget->setVisible(isVisible);