Salome HOME
4ef53c6f2ec3b36cfbb94bec799a0d93e348eaee
[modules/med.git] / src / MEDCalc / gui / dialogs / DlgInterpolateField.cxx
1 // Copyright (C) 2015-2016  CEA/DEN, EDF R&D
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 "DlgInterpolateField.hxx"
21 #include <MEDCalcConstants.hxx>
22
23 #include <QString>
24 #include <QMessageBox>
25 #include <QDoubleValidator>
26
27 DlgInterpolateField::DlgInterpolateField(SALOME_AppStudyEditor * studyEditor,
28              QDialog * parent)
29   : GenericDialog(parent)
30 {
31   ui.setupUi(this->getPanel());
32   _meshId=-1;
33   _studyEditor = studyEditor;
34
35   QDoubleValidator* precisionValidator = new QDoubleValidator(1e-15, 1e-1, 1, this);
36   precisionValidator->setNotation(QDoubleValidator::ScientificNotation);
37   this->ui.lineEditPrecision->setValidator(precisionValidator);
38   this->ui.lineEditPrecision->setText("1e-12");
39
40   QDoubleValidator* defaultValueValidator = new QDoubleValidator(this);
41   this->ui.lineEditDefaultValue->setValidator(defaultValueValidator);
42   this->ui.lineEditDefaultValue->setText("0");
43
44   QStringList intersectionTypes;
45   intersectionTypes << "Triangulation" << "Convex" << "Geometric2D" << "PointLocator" << "Barycentric" << "BarycentricGeo2D";
46   this->ui.comboBoxIntersType->addItems(intersectionTypes);
47
48   QStringList methods;
49   methods << "P0P0" << "P0P1" << "P1P0" << "P1P1" << "P2P0";
50   this->ui.comboBoxMethod->addItems(methods);
51
52   QStringList natures;
53   natures << "NoNature" << "IntensiveMaximum" << "ExtensiveMaximum" << "ExtensiveConservation" << "IntensiveConservation";
54   this->ui.comboBoxNature->addItems(natures);
55
56   connect(this->ui.btnSelectMesh, SIGNAL(clicked()), this, SLOT(OnSelectMesh()));
57   this->setWindowTitle("Field interpolation");
58   this->getPanel()->adjustSize();
59   this->adjustSize();
60 }
61
62 /** This reset the dialog for a new selection */
63 void DlgInterpolateField::setFieldId(int fieldId) {
64   _fieldId = fieldId;
65   _meshId=-1;
66   this->ui.txtMesh->setText(QString(""));
67 }
68 int DlgInterpolateField::getFieldId() {
69   return _fieldId;
70 }
71
72 int DlgInterpolateField::getMeshId() {
73   return _meshId;
74 }
75
76 double DlgInterpolateField::getPrecision() {
77   return this->ui.lineEditPrecision->text().toDouble();
78 }
79
80 double DlgInterpolateField::getDefaultValue() {
81   return this->ui.lineEditDefaultValue->text().toDouble();
82 }
83
84 bool DlgInterpolateField::getReverse() {
85   return this->ui.checkBoxReverse->isChecked();
86 }
87
88 std::string DlgInterpolateField::getIntersectionType() {
89   return this->ui.comboBoxIntersType->currentText().toStdString();
90 }
91
92 std::string DlgInterpolateField::getMethod() {
93   return this->ui.comboBoxMethod->currentText().toStdString();
94 }
95
96 std::string DlgInterpolateField::getFieldNature() {
97   return this->ui.comboBoxNature->currentText().toStdString();
98 }
99
100 void DlgInterpolateField::accept() {
101   if ( _meshId == -1 ) {
102     QMessageBox::warning(this,
103        tr("Data verification"),
104        tr("You must select a mesh in the explorer and clic the button Mesh"));
105   }
106   else {
107     GenericDialog::accept();
108     emit inputValidated();
109   }
110 }
111
112 void DlgInterpolateField::OnSelectMesh() {
113   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
114   if ( listOfSObject->size() > 0 ) {
115     SALOMEDS::SObject_var soMesh = listOfSObject->at(0);
116     // _GBO_ TODO: we should test here if it is a mesh (attribute in
117     // the sobject)
118     _meshId = _studyEditor->getParameterInt(soMesh,MESH_ID);
119     const char * meshname = _studyEditor->getName(soMesh);
120     this->ui.txtMesh->setText(QString(meshname));
121   }
122
123 }