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,OBJECT_ID);
90 // _GBO_ : the dialog should not be modal, so that we can choose a
91 // mesh in the browser. Then we have to emit a signal from the
92 // dialog.accept, connected to a slot of the DatasourceControler
93 _dlgChangeUnderlyingMesh->setFieldId(fieldId);
94 Qt::WindowFlags flags = _dlgChangeUnderlyingMesh->windowFlags();
95 _dlgChangeUnderlyingMesh->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
96 _dlgChangeUnderlyingMesh->open();
101 ProcessingController::OnChangeUnderlyingMeshInputValidated()
103 int meshId = _dlgChangeUnderlyingMesh->getMeshId();
104 STDLOG("meshId = " << ToString(meshId));
105 int fieldId = _dlgChangeUnderlyingMesh->getFieldId();
106 MEDCALC::FieldHandler* fieldHandler =
107 MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
109 // We don't modify the original field but create first a duplicate
110 MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler);
111 MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId);
113 // Request once more the duplicate to update the meta-data on this
115 duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id);
118 // WARN: the following is a temporary code for test purpose
119 // Automatically add in ws
120 ProcessingEvent* event = new ProcessingEvent();
121 event->eventtype = ProcessingEvent::EVENT_IMPORT_OBJECT;
122 XmedDataObject* dataObject = new XmedDataObject();
123 dataObject->setFieldHandler(*duplicate);
124 event->objectdata = dataObject;
125 emit processingSignal(event);
126 // Note that this signal is processed by the WorkspaceController
128 // Tag the item to prevent double import
129 //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
133 ProcessingController::OnInterpolateField()
135 // We need a studyEditor updated on the active study
136 _studyEditor->updateActiveStudy();
138 // Get the selected objects in the study (SObject). In case of a
139 // multiple selection, we consider only the first item. At least one
140 // item must be selected.
141 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
142 if ( listOfSObject->size() > 0 ) {
143 SALOMEDS::SObject_var soField = listOfSObject->at(0);
144 int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
145 // _GBO_ : the dialog should not be modal, so that we can choose a
146 // mesh in the browser. Then we have to emit a signal from the
147 // dialog.accept, connected to a slot of the DatasourceControler
148 _dlgInterpolateField->setFieldId(fieldId);
149 Qt::WindowFlags flags = _dlgInterpolateField->windowFlags();
150 _dlgInterpolateField->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
151 _dlgInterpolateField->open();
156 ProcessingController::OnInterpolateFieldInputValidated()
158 MEDCALC::InterpolationParameters params;
159 params.precision = _dlgInterpolateField->getPrecision();
160 STDLOG("precision = " << params.precision);
161 params.defaultValue = _dlgInterpolateField->getDefaultValue();
162 STDLOG("defaultValue = " << params.defaultValue);
163 params.reverse = _dlgInterpolateField->getReverse();
164 STDLOG("reverse = " << params.reverse);
165 params.intersectionType = _dlgInterpolateField->getIntersectionType().c_str();
166 STDLOG("intersectionType = " << params.intersectionType);
167 params.method = _dlgInterpolateField->getMethod().c_str();
168 STDLOG("method = " << params.method);
169 params.nature = _dlgInterpolateField->getFieldNature().c_str();
170 STDLOG("nature = " << params.nature);
172 int meshId = _dlgInterpolateField->getMeshId();
173 STDLOG("meshId = " << ToString(meshId));
174 int fieldId = _dlgInterpolateField->getFieldId();
175 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
177 // We don't modify the original field but create first a duplicate
178 // MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler);
179 //MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId);
180 MEDCALC::FieldHandler* result = NULL;
182 result = MEDFactoryClient::getDataManager()->interpolateField(fieldId, meshId, params);
185 STDLOG("Unable to process field interpolation; please check interpolation parameters");
186 QMessageBox::critical(_salomeModule->getApp()->desktop(),
187 tr("Operation failed"),
188 tr("Unable to process field interpolation; please check interpolation parameters"));
192 // Request once more the duplicate to update the meta-data on this
194 // duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id);
197 // WARN: the following is a temporary code for test purpose
198 // Automatically add in ws
199 ProcessingEvent* event = new ProcessingEvent();
200 event->eventtype = ProcessingEvent::EVENT_IMPORT_OBJECT;
201 XmedDataObject* dataObject = new XmedDataObject();
202 dataObject->setFieldHandler(*result);
203 event->objectdata = dataObject;
204 emit processingSignal(event);
205 // Note that this signal is processed by the WorkspaceController
207 // // Tag the item to prevent double import
208 // //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);