Salome HOME
Copyright update 2022
[modules/med.git] / src / MEDCalc / gui / dialogs / DlgChangeUnderlyingMesh.cxx
1 // Copyright (C) 2015-2022  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 "DlgChangeUnderlyingMesh.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
31 DlgChangeUnderlyingMesh::DlgChangeUnderlyingMesh(SALOME_AppStudyEditor * studyEditor,
32              QDialog * parent)
33   : GenericDialog(parent)
34 {
35   ui.setupUi(this->getPanel());
36   _meshId=-1;
37   _studyEditor = studyEditor;
38   connect(this->ui.btnSelectMesh, SIGNAL(clicked()), this, SLOT(OnSelectMesh()));
39   this->setWindowTitle("Remplacement du maillage support");
40 }
41
42 /** This reset the dialog for a new selection */
43 void DlgChangeUnderlyingMesh::setFieldId(int fieldId) {
44   _fieldId = fieldId;
45   _meshId=-1;
46   this->ui.txtMesh->setText(QString(""));
47 }
48 int DlgChangeUnderlyingMesh::getFieldId() {
49   return _fieldId;
50 }
51
52 int DlgChangeUnderlyingMesh::getMeshId() {
53   return _meshId;
54 }
55
56 void DlgChangeUnderlyingMesh::accept() {
57   if ( _meshId == -1 ) {
58     QMessageBox::warning(this,
59        tr("Data verification"),
60        tr("You must select a mesh in the explorer and clic the button Mesh"));
61   }
62   else {
63     GenericDialog::accept();
64     emit inputValidated();
65   }
66 }
67
68 void DlgChangeUnderlyingMesh::OnSelectMesh() {
69   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
70   if ( listOfSObject->size() > 0 ) {
71     SALOMEDS::SObject_var soMesh = listOfSObject->at(0);
72     std::string name(_studyEditor->getName(soMesh));
73     if (soMesh->_is_nil() || name == "MEDCalc")
74       return;
75     SALOMEDS::GenericAttribute_var anAttr;
76     SALOMEDS::AttributeParameter_var aParam;
77     if ( soMesh->FindAttribute(anAttr,"AttributeParameter") ) {
78       aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
79       if (! aParam->IsSet(MESH_ID, PT_INTEGER))
80         return;
81     }
82     _meshId = aParam->GetInt(MESH_ID);
83     const char * meshname = _studyEditor->getName(soMesh);
84     this->ui.txtMesh->setText(QString(meshname));
85   }
86
87 }