Salome HOME
7c318ba2309b19bae6fb4dd3526c70900217e97b
[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 <SALOMEDS_SObject.hxx>
24 #include <SALOMEDS_Study.hxx>
25 #include CORBA_CLIENT_HEADER(SALOMEDS)
26 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
27
28 #include <QString>
29 #include <QMessageBox>
30 #include <QDoubleValidator>
31
32 DlgInterpolateField::DlgInterpolateField(SALOME_AppStudyEditor * studyEditor,
33              QDialog * parent)
34   : GenericDialog(parent)
35 {
36   ui.setupUi(this->getPanel());
37   _meshId=-1;
38   _studyEditor = studyEditor;
39
40   QDoubleValidator* precisionValidator = new QDoubleValidator(1e-15, 1e-1, 1, this);
41   precisionValidator->setNotation(QDoubleValidator::ScientificNotation);
42   this->ui.lineEditPrecision->setValidator(precisionValidator);
43   this->ui.lineEditPrecision->setText("1e-12");
44
45   QDoubleValidator* defaultValueValidator = new QDoubleValidator(this);
46   this->ui.lineEditDefaultValue->setValidator(defaultValueValidator);
47   this->ui.lineEditDefaultValue->setText("0");
48
49   QStringList intersectionTypes;
50   intersectionTypes << "Triangulation" << "Convex" << "Geometric2D" << "PointLocator" << "Barycentric" << "BarycentricGeo2D";
51   this->ui.comboBoxIntersType->addItems(intersectionTypes);
52
53   QStringList methods;
54   methods << "P0P0" << "P0P1" << "P1P0" << "P1P1" << "P2P0";
55   this->ui.comboBoxMethod->addItems(methods);
56
57   QStringList natures;
58   natures << "NoNature" << "IntensiveMaximum" << "ExtensiveMaximum" << "ExtensiveConservation" << "IntensiveConservation";
59   this->ui.comboBoxNature->addItems(natures);
60
61   connect(this->ui.btnSelectMesh, SIGNAL(clicked()), this, SLOT(OnSelectMesh()));
62   this->setWindowTitle("Field interpolation");
63   this->getPanel()->adjustSize();
64   this->adjustSize();
65 }
66
67 /** This reset the dialog for a new selection */
68 void DlgInterpolateField::setFieldId(int fieldId) {
69   _fieldId = fieldId;
70   _meshId=-1;
71   this->ui.txtMesh->setText(QString(""));
72 }
73 int DlgInterpolateField::getFieldId() {
74   return _fieldId;
75 }
76
77 int DlgInterpolateField::getMeshId() {
78   return _meshId;
79 }
80
81 double DlgInterpolateField::getPrecision() {
82   return this->ui.lineEditPrecision->text().toDouble();
83 }
84
85 double DlgInterpolateField::getDefaultValue() {
86   return this->ui.lineEditDefaultValue->text().toDouble();
87 }
88
89 bool DlgInterpolateField::getReverse() {
90   return this->ui.checkBoxReverse->isChecked();
91 }
92
93 std::string DlgInterpolateField::getIntersectionType() {
94   return this->ui.comboBoxIntersType->currentText().toStdString();
95 }
96
97 std::string DlgInterpolateField::getMethod() {
98   return this->ui.comboBoxMethod->currentText().toStdString();
99 }
100
101 std::string DlgInterpolateField::getFieldNature() {
102   return this->ui.comboBoxNature->currentText().toStdString();
103 }
104
105 void DlgInterpolateField::accept() {
106   if ( _meshId == -1 ) {
107     QMessageBox::warning(this,
108        tr("Data verification"),
109        tr("You must select a mesh in the explorer and clic the button Mesh"));
110   }
111   else {
112     GenericDialog::accept();
113     emit inputValidated();
114   }
115 }
116
117 void DlgInterpolateField::OnSelectMesh() {
118   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
119   if ( listOfSObject->size() > 0 ) {
120     SALOMEDS::SObject_var soMesh = listOfSObject->at(0);
121     std::string name(_studyEditor->getName(soMesh));
122     if (soMesh->_is_nil() || name == "MEDCalc")
123       return;
124     SALOMEDS::GenericAttribute_var anAttr;
125     SALOMEDS::AttributeParameter_var aParam;
126     if ( soMesh->FindAttribute(anAttr,"AttributeParameter") ) {
127       aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
128       if (! aParam->IsSet(MESH_ID, PT_INTEGER))
129         return;
130     }
131     _meshId = aParam->GetInt(MESH_ID);
132     const char * meshname = _studyEditor->getName(soMesh);
133     this->ui.txtMesh->setText(QString(meshname));
134   }
135
136 }