Salome HOME
Updated copyright comment
[modules/med.git] / src / MEDCalc / gui / ProcessingController.cxx
1 // Copyright (C) 2016-2024  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ProcessingController.hxx"
21 #include <MEDCalcConstants.hxx>
22
23 #include <SALOMEDS_SObject.hxx>
24 #include <SALOMEDS_Study.hxx>
25 #include CORBA_CLIENT_HEADER(SALOMEDS)
26 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
27
28 #include "MEDFactoryClient.hxx"
29 #include "MEDModule.hxx"
30 #include "Basics_Utils.hxx"
31
32 #include <SUIT_Desktop.h>
33 #include <QMessageBox>
34
35 ProcessingController::ProcessingController(MEDModule* salomeModule)
36 {
37   STDLOG("Creating a ProcessingController");
38   _salomeModule = salomeModule;
39   _studyEditor = _salomeModule->getStudyEditor();
40
41   _dlgChangeUnderlyingMesh = new DlgChangeUnderlyingMesh(_studyEditor);
42   connect(_dlgChangeUnderlyingMesh,SIGNAL(inputValidated()),
43           this, SLOT(OnChangeUnderlyingMeshInputValidated()));
44
45   _dlgInterpolateField = new DlgInterpolateField(_studyEditor);
46   connect(_dlgInterpolateField,SIGNAL(inputValidated()),
47           this, SLOT(OnInterpolateFieldInputValidated()));
48 }
49
50 ProcessingController::~ProcessingController()
51 {
52   STDLOG("Deleting the ProcessingController");
53 }
54
55 void
56 ProcessingController::createActions()
57 {
58   STDLOG("Creating ProcessingController actions");
59
60   int processingToolbarId = _salomeModule->createTool("Processing", "ProcessingToolbar");
61   int processingMenuId = _salomeModule->createMenu(tr("MENU_PROCESSING"), -1, -1, 12);
62
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");
68   int actionId;
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);
73
74   label   = tr("LAB_PROCESSING_INTERPOLATE_FIELD");
75   icon = tr("ICO_PROCESSING_INTERPOLATE_FIELD");
76   actionId = _salomeModule->createStandardAction(label, this, SLOT(OnInterpolateField()),
77                                                  icon, label, FIELDSOp::OpProcessingInterpolation);
78   _salomeModule->createTool(actionId, processingToolbarId);
79   _salomeModule->action(actionId)->setIconVisibleInMenu(true);
80   _salomeModule->createMenu(actionId, processingMenuId);
81 }
82
83 void
84 ProcessingController::OnChangeUnderlyingMesh()
85 {
86   // Get the selected objects in the study (SObject). In case of a
87   // multiple selection, we consider only the first item. At least one
88   // item must be selected.
89   SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
90   if ( listOfSObject->size() > 0 ) {
91     SALOMEDS::SObject_var soObj = listOfSObject->at(0);
92     std::string name(_studyEditor->getName(soObj));
93     if (soObj->_is_nil() || name == "MEDCalc")
94       return;
95
96     int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID);
97     if (fieldId < 0) { // is it a field series?
98       int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID);
99       // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
100       // managed by the MED module, and we stop this function process.
101       if ( fieldSeriesId < 0)
102         return;
103       MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
104       /* todo: always false!
105       if (fieldHandlerList->length() < 0)
106         return;
107       */
108       // For a field series, get the first real field entry:
109       MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
110       fieldId = fieldHandler.id;
111       if (fieldId < 0)
112         return;
113     }
114
115     // _GBO_ : the dialog should not be modal, so that we can choose a
116     // mesh in the browser. Then we have to emit a signal from the
117     // dialog.accept, connected to a slot of the DatasourceControler
118     _dlgChangeUnderlyingMesh->setFieldId(fieldId);
119     Qt::WindowFlags flags = _dlgChangeUnderlyingMesh->windowFlags();
120     _dlgChangeUnderlyingMesh->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
121     _dlgChangeUnderlyingMesh->open();
122   }
123 }
124
125 void
126 ProcessingController::OnChangeUnderlyingMeshInputValidated()
127 {
128   STDLOG("Change Underlying Mesh");
129   int meshId = _dlgChangeUnderlyingMesh->getMeshId();
130   STDLOG("meshId = " << ToString(meshId));
131   int fieldId = _dlgChangeUnderlyingMesh->getFieldId();
132
133   ProcessingEvent* event = new ProcessingEvent();
134   event->eventtype = ProcessingEvent::EVENT_CHANGE_UNDERLYING_MESH;
135   event->fieldId = fieldId;
136   event->meshId = meshId;
137   emit processingSignal(event); // --> WorkspaceController::processProcessingEvent()
138
139   // Tag the item to prevent double import
140   //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
141 }
142
143 void
144 ProcessingController::OnInterpolateField()
145 {
146   // Get the selected objects in the study (SObject). In case of a
147   // multiple selection, we consider only the first item. At least one
148   // item must be selected.
149   SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
150   if ( listOfSObject->size() > 0 ) {
151     SALOMEDS::SObject_var soObj = listOfSObject->at(0);
152     std::string name(_studyEditor->getName(soObj));
153     if (soObj->_is_nil() || name == "MEDCalc")
154       return;
155
156     int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID);
157     if (fieldId < 0) { // is it a field series?
158       int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID);
159       // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
160       // managed by the MED module, and we stop this function process.
161       if ( fieldSeriesId < 0)
162         return;
163       MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
164       /* todo: always false!
165       if (fieldHandlerList->length() < 0)
166         return;
167       */
168       // For a field series, get the first real field entry:
169       MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
170       fieldId = fieldHandler.id;
171       if (fieldId < 0)
172         return;
173     }
174
175     // _GBO_ : the dialog should not be modal, so that we can choose a
176     // mesh in the browser. Then we have to emit a signal from the
177     // dialog.accept, connected to a slot of the DatasourceControler
178     _dlgInterpolateField->setFieldId(fieldId);
179     Qt::WindowFlags flags = _dlgInterpolateField->windowFlags();
180     _dlgInterpolateField->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
181     _dlgInterpolateField->open();
182   }
183 }
184
185 void
186 ProcessingController::OnInterpolateFieldInputValidated()
187 {
188   STDLOG("Interpolate Field");
189   MEDCALC::InterpolationParameters params;
190   params.precision = _dlgInterpolateField->getPrecision();
191   STDLOG("precision = " << params.precision);
192   params.defaultValue = _dlgInterpolateField->getDefaultValue();
193   STDLOG("defaultValue = " << params.defaultValue);
194   params.reverse = _dlgInterpolateField->getReverse();
195   STDLOG("reverse = " << params.reverse);
196   params.intersectionType = _dlgInterpolateField->getIntersectionType().c_str();
197   STDLOG("intersectionType = " << params.intersectionType);
198   params.method = _dlgInterpolateField->getMethod().c_str();
199   STDLOG("method = " << params.method);
200   params.nature = _dlgInterpolateField->getFieldNature().c_str();
201   STDLOG("nature = " << params.nature);
202
203   int meshId = _dlgInterpolateField->getMeshId();
204   STDLOG("meshId = " << ToString(meshId));
205   int fieldId = _dlgInterpolateField->getFieldId();
206
207   ProcessingEvent* event = new ProcessingEvent();
208   event->eventtype = ProcessingEvent::EVENT_INTERPOLATE_FIELD;
209   event->fieldId = fieldId;
210   event->meshId = meshId;
211   event->interpParams = params;
212   emit processingSignal(event); // --> WorkspaceController::processProcessingEvent()
213
214   // // Tag the item to prevent double import
215   // //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
216 }