1 // Copyright (C) 2016-2019 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 case 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 soObj = listOfSObject->at(0);
91 std::string name(_studyEditor->getName(soObj));
92 if (soObj->_is_nil() || name == "MEDCalc")
95 int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID);
96 if (fieldId < 0) { // is it a field series?
97 int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID);
98 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
99 // managed by the MED module, and we stop this function process.
100 if ( fieldSeriesId < 0)
102 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
103 if (fieldHandlerList->length() < 0)
105 // For a field series, get the first real field entry:
106 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
107 fieldId = fieldHandler.id;
112 // _GBO_ : the dialog should not be modal, so that we can choose a
113 // mesh in the browser. Then we have to emit a signal from the
114 // dialog.accept, connected to a slot of the DatasourceControler
115 _dlgChangeUnderlyingMesh->setFieldId(fieldId);
116 Qt::WindowFlags flags = _dlgChangeUnderlyingMesh->windowFlags();
117 _dlgChangeUnderlyingMesh->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
118 _dlgChangeUnderlyingMesh->open();
123 ProcessingController::OnChangeUnderlyingMeshInputValidated()
125 STDLOG("Change Underlying Mesh");
126 int meshId = _dlgChangeUnderlyingMesh->getMeshId();
127 STDLOG("meshId = " << ToString(meshId));
128 int fieldId = _dlgChangeUnderlyingMesh->getFieldId();
130 ProcessingEvent* event = new ProcessingEvent();
131 event->eventtype = ProcessingEvent::EVENT_CHANGE_UNDERLYING_MESH;
132 event->fieldId = fieldId;
133 event->meshId = meshId;
134 emit processingSignal(event); // --> WorkspaceController::processProcessingEvent()
136 // Tag the item to prevent double import
137 //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
141 ProcessingController::OnInterpolateField()
143 // Get the selected objects in the study (SObject). In case of a
144 // multiple selection, we consider only the first item. At least one
145 // item must be selected.
146 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
147 if ( listOfSObject->size() > 0 ) {
148 SALOMEDS::SObject_var soObj = listOfSObject->at(0);
149 std::string name(_studyEditor->getName(soObj));
150 if (soObj->_is_nil() || name == "MEDCalc")
153 int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID);
154 if (fieldId < 0) { // is it a field series?
155 int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID);
156 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
157 // managed by the MED module, and we stop this function process.
158 if ( fieldSeriesId < 0)
160 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
161 if (fieldHandlerList->length() < 0)
163 // For a field series, get the first real field entry:
164 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
165 fieldId = fieldHandler.id;
170 // _GBO_ : the dialog should not be modal, so that we can choose a
171 // mesh in the browser. Then we have to emit a signal from the
172 // dialog.accept, connected to a slot of the DatasourceControler
173 _dlgInterpolateField->setFieldId(fieldId);
174 Qt::WindowFlags flags = _dlgInterpolateField->windowFlags();
175 _dlgInterpolateField->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
176 _dlgInterpolateField->open();
181 ProcessingController::OnInterpolateFieldInputValidated()
183 STDLOG("Interpolate Field");
184 MEDCALC::InterpolationParameters params;
185 params.precision = _dlgInterpolateField->getPrecision();
186 STDLOG("precision = " << params.precision);
187 params.defaultValue = _dlgInterpolateField->getDefaultValue();
188 STDLOG("defaultValue = " << params.defaultValue);
189 params.reverse = _dlgInterpolateField->getReverse();
190 STDLOG("reverse = " << params.reverse);
191 params.intersectionType = _dlgInterpolateField->getIntersectionType().c_str();
192 STDLOG("intersectionType = " << params.intersectionType);
193 params.method = _dlgInterpolateField->getMethod().c_str();
194 STDLOG("method = " << params.method);
195 params.nature = _dlgInterpolateField->getFieldNature().c_str();
196 STDLOG("nature = " << params.nature);
198 int meshId = _dlgInterpolateField->getMeshId();
199 STDLOG("meshId = " << ToString(meshId));
200 int fieldId = _dlgInterpolateField->getFieldId();
202 ProcessingEvent* event = new ProcessingEvent();
203 event->eventtype = ProcessingEvent::EVENT_INTERPOLATE_FIELD;
204 event->fieldId = fieldId;
205 event->meshId = meshId;
206 event->interpParams = params;
207 emit processingSignal(event); // --> WorkspaceController::processProcessingEvent()
209 // // Tag the item to prevent double import
210 // //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);