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