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 "ProcessingController.hxx"
21 #include <MEDCalcConstants.hxx>
23 #include "MEDFactoryClient.hxx"
24 #include "MEDModule.hxx"
25 #include "Basics_Utils.hxx"
27 #include <SUIT_Desktop.h>
28 #include <QMessageBox>
30 ProcessingController::ProcessingController(MEDModule* salomeModule)
32 STDLOG("Creating a ProcessingController");
33 _salomeModule = salomeModule;
34 _studyEditor = _salomeModule->getStudyEditor();
36 _dlgChangeUnderlyingMesh = new DlgChangeUnderlyingMesh(_studyEditor);
37 connect(_dlgChangeUnderlyingMesh,SIGNAL(inputValidated()),
38 this, SLOT(OnChangeUnderlyingMeshInputValidated()));
40 _dlgInterpolateField = new DlgInterpolateField(_studyEditor);
41 connect(_dlgInterpolateField,SIGNAL(inputValidated()),
42 this, SLOT(OnInterpolateFieldInputValidated()));
45 ProcessingController::~ProcessingController()
47 STDLOG("Deleting the ProcessingController");
51 ProcessingController::createActions()
53 STDLOG("Creating ProcessingController actions");
55 int processingToolbarId = _salomeModule->createTool("Processing", "ProcessingToolbar");
56 int processingMenuId = _salomeModule->createMenu(tr("MENU_PROCESSING"), -1, 1);
58 // Change underlying mesh (note that this action creates a new field in
59 // the workspace that corresponds to a copy of the selected field
60 // modified by the change of the underlying mesh.
61 QString label = tr("LAB_PROCESSING_CHANGE_MESH");
62 QString icon = tr("ICO_PROCESSING_CHANGE_MESH");
64 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnChangeUnderlyingMesh()),icon,label);
65 _salomeModule->createTool(actionId, processingToolbarId);
66 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
67 _salomeModule->createMenu(actionId, processingMenuId);
69 label = tr("LAB_PROCESSING_INTERPOLATE_FIELD");
70 icon = tr("ICO_PROCESSING_INTERPOLATE_FIELD");
71 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnInterpolateField()),icon,label);
72 _salomeModule->createTool(actionId, processingToolbarId);
73 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
74 _salomeModule->createMenu(actionId, processingMenuId);
78 ProcessingController::OnChangeUnderlyingMesh()
80 // We need a studyEditor updated on the active study
81 _studyEditor->updateActiveStudy();
83 // Get the selected objects in the study (SObject). In cas of a
84 // multiple selection, we consider only the first item. At least one
85 // item must be selected.
86 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
87 if ( listOfSObject->size() > 0 ) {
88 SALOMEDS::SObject_var soField = listOfSObject->at(0);
89 //int fieldId = _studyEditor->getParameterInt(soField,FIELD_SERIES_ID);
90 int fieldId = _studyEditor->getParameterInt(soField,FIELD_ID);
91 // _GBO_ : the dialog should not be modal, so that we can choose a
92 // mesh in the browser. Then we have to emit a signal from the
93 // dialog.accept, connected to a slot of the DatasourceControler
94 _dlgChangeUnderlyingMesh->setFieldId(fieldId);
95 Qt::WindowFlags flags = _dlgChangeUnderlyingMesh->windowFlags();
96 _dlgChangeUnderlyingMesh->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
97 _dlgChangeUnderlyingMesh->open();
102 ProcessingController::OnChangeUnderlyingMeshInputValidated()
104 int meshId = _dlgChangeUnderlyingMesh->getMeshId();
105 STDLOG("meshId = " << ToString(meshId));
106 int fieldId = _dlgChangeUnderlyingMesh->getFieldId();
107 MEDCALC::FieldHandler* fieldHandler =
108 MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
110 // We don't modify the original field but create first a duplicate
111 MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler);
112 MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId);
114 // Request once more the duplicate to update the meta-data on this
116 duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id);
119 // WARN: the following is a temporary code for test purpose
120 // Automatically add in ws
121 ProcessingEvent* event = new ProcessingEvent();
122 event->eventtype = ProcessingEvent::EVENT_IMPORT_OBJECT;
123 XmedDataObject* dataObject = new XmedDataObject();
124 dataObject->setFieldHandler(*duplicate);
125 event->objectdata = dataObject;
126 emit processingSignal(event);
127 // Note that this signal is processed by the WorkspaceController
129 // Tag the item to prevent double import
130 //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
134 ProcessingController::OnInterpolateField()
136 // We need a studyEditor updated on the active study
137 _studyEditor->updateActiveStudy();
139 // Get the selected objects in the study (SObject). In case of a
140 // multiple selection, we consider only the first item. At least one
141 // item must be selected.
142 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
143 if ( listOfSObject->size() > 0 ) {
144 SALOMEDS::SObject_var soField = listOfSObject->at(0);
145 int fieldId = _studyEditor->getParameterInt(soField,FIELD_ID);
146 // _GBO_ : the dialog should not be modal, so that we can choose a
147 // mesh in the browser. Then we have to emit a signal from the
148 // dialog.accept, connected to a slot of the DatasourceControler
149 _dlgInterpolateField->setFieldId(fieldId);
150 Qt::WindowFlags flags = _dlgInterpolateField->windowFlags();
151 _dlgInterpolateField->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
152 _dlgInterpolateField->open();
157 ProcessingController::OnInterpolateFieldInputValidated()
159 MEDCALC::InterpolationParameters params;
160 params.precision = _dlgInterpolateField->getPrecision();
161 STDLOG("precision = " << params.precision);
162 params.defaultValue = _dlgInterpolateField->getDefaultValue();
163 STDLOG("defaultValue = " << params.defaultValue);
164 params.reverse = _dlgInterpolateField->getReverse();
165 STDLOG("reverse = " << params.reverse);
166 params.intersectionType = _dlgInterpolateField->getIntersectionType().c_str();
167 STDLOG("intersectionType = " << params.intersectionType);
168 params.method = _dlgInterpolateField->getMethod().c_str();
169 STDLOG("method = " << params.method);
170 params.nature = _dlgInterpolateField->getFieldNature().c_str();
171 STDLOG("nature = " << params.nature);
173 int meshId = _dlgInterpolateField->getMeshId();
174 STDLOG("meshId = " << ToString(meshId));
175 int fieldId = _dlgInterpolateField->getFieldId();
176 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
178 // We don't modify the original field but create first a duplicate
179 // MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler);
180 //MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId);
181 MEDCALC::FieldHandler* result = NULL;
183 result = MEDFactoryClient::getDataManager()->interpolateField(fieldId, meshId, params);
186 STDLOG("Unable to process field interpolation; please check interpolation parameters");
187 QMessageBox::critical(_salomeModule->getApp()->desktop(),
188 tr("Operation failed"),
189 tr("Unable to process field interpolation; please check interpolation parameters"));
193 // Request once more the duplicate to update the meta-data on this
195 // duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id);
198 // WARN: the following is a temporary code for test purpose
199 // Automatically add in ws
200 ProcessingEvent* event = new ProcessingEvent();
201 event->eventtype = ProcessingEvent::EVENT_IMPORT_OBJECT;
202 XmedDataObject* dataObject = new XmedDataObject();
203 dataObject->setFieldHandler(*result);
204 event->objectdata = dataObject;
205 emit processingSignal(event);
206 // Note that this signal is processed by the WorkspaceController
208 // // Tag the item to prevent double import
209 // //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);