Salome HOME
fix conflict: ctest requires SUBDIRS, not ADD_SUBDIRECTORY directives
[modules/med.git] / src / MEDCalc / gui / dialogs / DlgInterpolateField.cxx
1 #include "DlgInterpolateField.hxx"
2 #include "DatasourceConstants.hxx"
3
4 #include <QString>
5 #include <QMessageBox>
6 #include <QDoubleValidator>
7
8 DlgInterpolateField::DlgInterpolateField(SALOME_AppStudyEditor * studyEditor,
9              QDialog * parent)
10   : GenericDialog(parent)
11 {
12   ui.setupUi(this->getPanel());
13   _meshId=-1;
14   _studyEditor = studyEditor;
15
16   QDoubleValidator* precisionValidator = new QDoubleValidator(1e-15, 1e-1, 1, this);
17   precisionValidator->setNotation(QDoubleValidator::ScientificNotation);
18   this->ui.lineEditPrecision->setValidator(precisionValidator);
19   this->ui.lineEditPrecision->setText("1e-12");
20
21   QDoubleValidator* defaultValueValidator = new QDoubleValidator(this);
22   this->ui.lineEditDefaultValue->setValidator(defaultValueValidator);
23   this->ui.lineEditDefaultValue->setText("0");
24
25   QStringList intersectionTypes;
26   intersectionTypes << "Triangulation" << "Convex" << "Geometric2D" << "PointLocator" << "Barycentric" << "BarycentricGeo2D";
27   this->ui.comboBoxIntersType->addItems(intersectionTypes);
28
29   QStringList methods;
30   methods << "P0P0" << "P0P1" << "P1P0" << "P1P1" << "P2P0";
31   this->ui.comboBoxMethod->addItems(methods);
32
33   QStringList natures;
34   natures << "NoNature" << "ConservativeVolumic" << "Integral" << "IntegralGlobConstraint" << "RevIntegral";
35   this->ui.comboBoxNature->addItems(natures);
36
37   connect(this->ui.btnSelectMesh, SIGNAL(clicked()), this, SLOT(OnSelectMesh()));
38   this->setWindowTitle("Field interpolation");
39   this->getPanel()->adjustSize();
40   this->adjustSize();
41 }
42
43 /** This reset the dialog for a new selection */
44 void DlgInterpolateField::setFieldId(int fieldId) {
45   _fieldId = fieldId;
46   _meshId=-1;
47   this->ui.txtMesh->setText(QString(""));
48 }
49 int DlgInterpolateField::getFieldId() {
50   return _fieldId;
51 }
52
53 int DlgInterpolateField::getMeshId() {
54   return _meshId;
55 }
56
57 double DlgInterpolateField::getPrecision() {
58   return this->ui.lineEditPrecision->text().toDouble();
59 }
60
61 double DlgInterpolateField::getDefaultValue() {
62   return this->ui.lineEditDefaultValue->text().toDouble();
63 }
64
65 bool DlgInterpolateField::getReverse() {
66   return this->ui.checkBoxReverse->isChecked();
67 }
68
69 std::string DlgInterpolateField::getIntersectionType() {
70   return this->ui.comboBoxIntersType->currentText().toStdString();
71 }
72
73 std::string DlgInterpolateField::getMethod() {
74   return this->ui.comboBoxMethod->currentText().toStdString();
75 }
76
77 std::string DlgInterpolateField::getFieldNature() {
78   return this->ui.comboBoxNature->currentText().toStdString();
79 }
80
81 void DlgInterpolateField::accept() {
82   if ( _meshId == -1 ) {
83     QMessageBox::warning(this,
84        tr("Data verification"),
85        tr("You must select a mesh in the explorer and clic the button Mesh"));
86   }
87   else {
88     GenericDialog::accept();
89     emit inputValidated();
90   }
91 }
92
93 void DlgInterpolateField::OnSelectMesh() {
94   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
95   if ( listOfSObject->size() > 0 ) {
96     SALOMEDS::SObject_var soMesh = listOfSObject->at(0);
97     // _GBO_ TODO: we should test here if it is a mesh (attribute in
98     // the sobject)
99     _meshId = _studyEditor->getParameterInt(soMesh,OBJECT_ID);
100     const char * meshname = _studyEditor->getName(soMesh);
101     this->ui.txtMesh->setText(QString(meshname));
102   }
103
104 }