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 <SALOMEDS_SObject.hxx>
24 #include <SALOMEDS_Study.hxx>
25 #include CORBA_CLIENT_HEADER(SALOMEDS)
26 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
28 #include "MEDFactoryClient.hxx"
29 #include "MEDModule.hxx"
30 #include "Basics_Utils.hxx"
32 #include <SUIT_Desktop.h>
33 #include <QMessageBox>
35 ProcessingController::ProcessingController(MEDModule* salomeModule)
37 STDLOG("Creating a ProcessingController");
38 _salomeModule = salomeModule;
39 _studyEditor = _salomeModule->getStudyEditor();
41 _dlgChangeUnderlyingMesh = new DlgChangeUnderlyingMesh(_studyEditor);
42 connect(_dlgChangeUnderlyingMesh,SIGNAL(inputValidated()),
43 this, SLOT(OnChangeUnderlyingMeshInputValidated()));
45 _dlgInterpolateField = new DlgInterpolateField(_studyEditor);
46 connect(_dlgInterpolateField,SIGNAL(inputValidated()),
47 this, SLOT(OnInterpolateFieldInputValidated()));
50 ProcessingController::~ProcessingController()
52 STDLOG("Deleting the ProcessingController");
56 ProcessingController::createActions()
58 STDLOG("Creating ProcessingController actions");
60 int processingToolbarId = _salomeModule->createTool("Processing", "ProcessingToolbar");
61 int processingMenuId = _salomeModule->createMenu(tr("MENU_PROCESSING"), -1, -1, 12);
63 // Change underlying mesh (note that this action creates a new field in
64 // the workspace that corresponds to a copy of the selected field
65 // modified by the change of the underlying mesh.
66 QString label = tr("LAB_PROCESSING_CHANGE_MESH");
67 QString icon = tr("ICO_PROCESSING_CHANGE_MESH");
69 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnChangeUnderlyingMesh()),icon,label);
70 _salomeModule->createTool(actionId, processingToolbarId);
71 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
72 _salomeModule->createMenu(actionId, processingMenuId);
74 label = tr("LAB_PROCESSING_INTERPOLATE_FIELD");
75 icon = tr("ICO_PROCESSING_INTERPOLATE_FIELD");
76 actionId = _salomeModule->createStandardAction(label,this, SLOT(OnInterpolateField()),icon,label);
77 _salomeModule->createTool(actionId, processingToolbarId);
78 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
79 _salomeModule->createMenu(actionId, processingMenuId);
83 ProcessingController::OnChangeUnderlyingMesh()
85 // Get the selected objects in the study (SObject). In cas of a
86 // multiple selection, we consider only the first item. At least one
87 // item must be selected.
88 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
89 if ( listOfSObject->size() > 0 ) {
90 SALOMEDS::SObject_var soField = listOfSObject->at(0);
91 std::string name(_studyEditor->getName(soField));
92 if (soField->_is_nil() || name == "MEDCalc")
94 SALOMEDS::GenericAttribute_var anAttr;
95 SALOMEDS::AttributeParameter_var aParam;
96 if ( soField->FindAttribute(anAttr,"AttributeParameter") ) {
97 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
98 if (! aParam->IsSet(FIELD_SERIES_ID, PT_INTEGER))
101 int fieldId = aParam->GetInt(FIELD_SERIES_ID);
102 // _GBO_ : the dialog should not be modal, so that we can choose a
103 // mesh in the browser. Then we have to emit a signal from the
104 // dialog.accept, connected to a slot of the DatasourceControler
105 _dlgChangeUnderlyingMesh->setFieldId(fieldId);
106 Qt::WindowFlags flags = _dlgChangeUnderlyingMesh->windowFlags();
107 _dlgChangeUnderlyingMesh->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
108 _dlgChangeUnderlyingMesh->open();
113 ProcessingController::OnChangeUnderlyingMeshInputValidated()
115 int meshId = _dlgChangeUnderlyingMesh->getMeshId();
116 STDLOG("meshId = " << ToString(meshId));
117 int fieldId = _dlgChangeUnderlyingMesh->getFieldId();
118 MEDCALC::FieldHandler* fieldHandler =
119 MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
121 // We don't modify the original field but create first a duplicate
122 MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler);
123 MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId);
125 // Request once more the duplicate to update the meta-data on this
127 duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id);
130 // WARN: the following is a temporary code for test purpose
131 // Automatically add in ws
132 ProcessingEvent* event = new ProcessingEvent();
133 event->eventtype = ProcessingEvent::EVENT_IMPORT_OBJECT;
134 XmedDataObject* dataObject = new XmedDataObject();
135 dataObject->setFieldHandler(*duplicate);
136 event->objectdata = dataObject;
137 emit processingSignal(event);
138 // Note that this signal is processed by the WorkspaceController
140 // Tag the item to prevent double import
141 //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
145 ProcessingController::OnInterpolateField()
147 // Get the selected objects in the study (SObject). In case of a
148 // multiple selection, we consider only the first item. At least one
149 // item must be selected.
150 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
151 if ( listOfSObject->size() > 0 ) {
152 SALOMEDS::SObject_var soField = listOfSObject->at(0);
153 std::string name(_studyEditor->getName(soField));
154 if (soField->_is_nil() || name == "MEDCalc")
156 SALOMEDS::GenericAttribute_var anAttr;
157 SALOMEDS::AttributeParameter_var aParam;
158 if ( soField->FindAttribute(anAttr,"AttributeParameter") ) {
159 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
160 if (! aParam->IsSet(FIELD_SERIES_ID, PT_INTEGER))
163 int fieldId = aParam->GetInt(FIELD_SERIES_ID);
164 // _GBO_ : the dialog should not be modal, so that we can choose a
165 // mesh in the browser. Then we have to emit a signal from the
166 // dialog.accept, connected to a slot of the DatasourceControler
167 _dlgInterpolateField->setFieldId(fieldId);
168 Qt::WindowFlags flags = _dlgInterpolateField->windowFlags();
169 _dlgInterpolateField->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
170 _dlgInterpolateField->open();
175 ProcessingController::OnInterpolateFieldInputValidated()
177 MEDCALC::InterpolationParameters params;
178 params.precision = _dlgInterpolateField->getPrecision();
179 STDLOG("precision = " << params.precision);
180 params.defaultValue = _dlgInterpolateField->getDefaultValue();
181 STDLOG("defaultValue = " << params.defaultValue);
182 params.reverse = _dlgInterpolateField->getReverse();
183 STDLOG("reverse = " << params.reverse);
184 params.intersectionType = _dlgInterpolateField->getIntersectionType().c_str();
185 STDLOG("intersectionType = " << params.intersectionType);
186 params.method = _dlgInterpolateField->getMethod().c_str();
187 STDLOG("method = " << params.method);
188 params.nature = _dlgInterpolateField->getFieldNature().c_str();
189 STDLOG("nature = " << params.nature);
191 int meshId = _dlgInterpolateField->getMeshId();
192 STDLOG("meshId = " << ToString(meshId));
193 int fieldId = _dlgInterpolateField->getFieldId();
194 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
196 // We don't modify the original field but create first a duplicate
197 // MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler);
198 //MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId);
199 MEDCALC::FieldHandler* result = NULL;
201 result = MEDFactoryClient::getDataManager()->interpolateField(fieldId, meshId, params);
204 STDLOG("Unable to process field interpolation; please check interpolation parameters");
205 QMessageBox::critical(_salomeModule->getApp()->desktop(),
206 tr("Operation failed"),
207 tr("Unable to process field interpolation; please check interpolation parameters"));
211 // Request once more the duplicate to update the meta-data on this
213 // duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id);
216 // WARN: the following is a temporary code for test purpose
217 // Automatically add in ws
218 ProcessingEvent* event = new ProcessingEvent();
219 event->eventtype = ProcessingEvent::EVENT_IMPORT_OBJECT;
220 XmedDataObject* dataObject = new XmedDataObject();
221 dataObject->setFieldHandler(*result);
222 event->objectdata = dataObject;
223 emit processingSignal(event);
224 // Note that this signal is processed by the WorkspaceController
226 // // Tag the item to prevent double import
227 // //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);