Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI.cxx
1 //  SMESH StdMeshersGUI : GUI for plugged-in meshers
2 //
3 //  Copyright (C) 2003  CEA
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
20 //
21 //
22 //
23 //  File   : StdMeshersGUI.cxx
24 //  Author : Julia DOROVSKIKH
25 //  Module : SMESH
26 //  $Header$
27
28 using namespace std;
29
30 #include <SALOMEconfig.h>
31 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
32
33 #include "SMESHGUI.h"
34 #include "SMESHGUI_Hypotheses.h"
35
36 #include "StdMeshersGUI_LocalLengthDlg.h"
37 #include "StdMeshersGUI_NbSegmentsDlg.h"
38 #include "StdMeshersGUI_MaxElementAreaDlg.h"
39 #include "StdMeshersGUI_MaxElementVolumeDlg.h"
40
41 #include "QAD_Desktop.h"
42 #include "QAD_ResourceMgr.h"
43
44 #include <qobject.h>
45
46 //=============================================================================
47 /*! class HypothesisCreator
48  *
49  */
50 //=============================================================================
51 class StdMeshersGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
52 {
53  public:
54   StdMeshersGUI_HypothesisCreator (const QString& aHypType,
55                                    const QString& aServerLibName,
56                                    SMESHGUI* aSMESHGUI)
57     : myHypType(aHypType),
58     myServerLibName(aServerLibName),
59     mySMESHGUI(aSMESHGUI) {}
60
61   virtual void CreateHypothesis (const bool isAlgo, QWidget* parent = 0);
62   virtual void EditHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp);
63
64  private:
65   QString   myHypType;
66   QString   myServerLibName;
67   SMESHGUI* mySMESHGUI;
68 };
69
70 //=============================================================================
71 /*! HypothesisCreator::CreateHypothesis
72  *
73  */
74 //=============================================================================
75 void StdMeshersGUI_HypothesisCreator::CreateHypothesis
76                                       (bool isAlgo, QWidget* parent)
77 {
78   MESSAGE("StdMeshersGUI_HypothesisCreator::CreateHypothesis");
79
80   // Get default name for hypothesis/algorithm creation
81   char* sHypType = (char*)myHypType.latin1();
82   HypothesisData* aHypData = mySMESHGUI->GetHypothesisData(sHypType);
83   QString aHypName;
84   if (aHypData)
85     aHypName = aHypData->Label;
86   else
87     aHypName = myHypType;
88
89   // Create hypothesis/algorithm
90   if (isAlgo)
91   {
92     mySMESHGUI->CreateHypothesis(myHypType, aHypName, isAlgo);
93   }
94   else
95   {
96     // Show Dialog for hypothesis creation
97     if      (myHypType == "LocalLength")
98       StdMeshersGUI_LocalLengthDlg *aDlg = new StdMeshersGUI_LocalLengthDlg(myHypType, parent, "");
99     else if (myHypType == "NumberOfSegments")
100       StdMeshersGUI_NbSegmentsDlg *aDlg = new StdMeshersGUI_NbSegmentsDlg(myHypType, parent, "");
101     else if (myHypType == "MaxElementArea")
102       StdMeshersGUI_MaxElementAreaDlg *aDlg = new StdMeshersGUI_MaxElementAreaDlg(myHypType, parent, "");
103     else if (myHypType == "MaxElementVolume")
104       StdMeshersGUI_MaxElementVolumeDlg *aDlg = new StdMeshersGUI_MaxElementVolumeDlg(myHypType, parent, "");
105     else if (myHypType == "LengthFromEdges")
106       mySMESHGUI->CreateHypothesis(myHypType, aHypName, isAlgo); // without GUI
107     else if (myHypType == "NotConformAllowed")
108       mySMESHGUI->CreateHypothesis(myHypType, aHypName, isAlgo); // without GUI
109     else ;
110   }
111 }
112
113 //=============================================================================
114 /*! HypothesisCreator::EditHypothesis
115  *
116  */
117 //=============================================================================
118 void StdMeshersGUI_HypothesisCreator::EditHypothesis
119                                       (SMESH::SMESH_Hypothesis_ptr theHyp)
120 {
121   MESSAGE("StdMeshersGUI_HypothesisCreator::EditHypothesis");
122
123   Standard_Boolean res = Standard_True;
124   SALOMEDS::Study::ListOfSObject_var listSOmesh =
125     mySMESHGUI->GetMeshesUsingAlgoOrHypothesis(theHyp);
126   QString Name = theHyp->GetName();
127   if (Name.compare("LocalLength") == 0)
128   {
129     StdMeshers::StdMeshers_LocalLength_var LL =
130       StdMeshers::StdMeshers_LocalLength::_narrow(theHyp);
131     double beforeLength = LL->GetLength() ;
132     double Length = mySMESHGUI->Parameter(res, 
133                                           beforeLength,
134                                           QObject::tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"), 
135                                           QObject::tr("SMESH_VALUE"), 
136                                           1.0E-5, 1E6, 6);
137     if (res && Length != beforeLength)
138     {
139       LL->SetLength(Length);
140       for (int i=0; i<listSOmesh->length(); i++)
141       {
142         mySMESHGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i], false);
143       }
144     }
145   }
146   else if (Name.compare("NumberOfSegments") == 0)
147   {
148     StdMeshers::StdMeshers_NumberOfSegments_var NOS =
149       StdMeshers::StdMeshers_NumberOfSegments::_narrow(theHyp);
150     int beforeNbSeg = NOS->GetNumberOfSegments() ;
151     int NbSeg = mySMESHGUI->Parameter(res,
152                                       beforeNbSeg, 
153                                       QObject::tr("SMESH_NB_SEGMENTS_HYPOTHESIS"), 
154                                       QObject::tr("SMESH_VALUE"), 
155                                       1, 1000000);
156     if (res && NbSeg != beforeNbSeg)
157     {
158       NOS->SetNumberOfSegments(NbSeg);
159       for (int i=0; i<listSOmesh->length(); i++)
160       {
161         SALOMEDS::SObject_var SO = listSOmesh[i] ;
162         mySMESHGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i], false);
163       }
164     }
165   }
166   else if (Name.compare("MaxElementArea") == 0)
167   {
168     StdMeshers::StdMeshers_MaxElementArea_var MEA =
169       StdMeshers::StdMeshers_MaxElementArea::_narrow(theHyp);
170     double beforeMaxArea = MEA->GetMaxElementArea();
171     double MaxArea = mySMESHGUI->Parameter(res,
172                                            beforeMaxArea,
173                                            QObject::tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"), 
174                                            QObject::tr("SMESH_VALUE"), 
175                                            1.0E-5, 1E6, 6);
176     if (res && MaxArea != beforeMaxArea)
177     {
178       MEA->SetMaxElementArea(MaxArea);
179       for (int i=0; i<listSOmesh->length(); i++)
180       {
181         mySMESHGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i], false);
182       }
183     }
184   }
185   else if (Name.compare("MaxElementVolume") == 0)
186   {
187     StdMeshers::StdMeshers_MaxElementVolume_var MEV =
188       StdMeshers::StdMeshers_MaxElementVolume::_narrow(theHyp);
189     double beforeMaxVolume = MEV->GetMaxElementVolume() ;
190     double MaxVolume = mySMESHGUI->Parameter(res, 
191                                              beforeMaxVolume,
192                                              QObject::tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"), 
193                                              QObject::tr("SMESH_VALUE"), 
194                                              1.0E-5, 1E6, 6);
195     if (res && MaxVolume != beforeMaxVolume)
196     {
197       MEV->SetMaxElementVolume(MaxVolume);
198       for (int i=0; i<listSOmesh->length(); i++)
199       {
200         mySMESHGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i], false);
201       }
202     }
203   }
204 //  else if (Name.compare("Regular_1D") == 0)
205 //  {}
206 //  else if (Name.compare("MEFISTO_2D") == 0)
207 //  {}
208   else
209   {}
210 }
211
212 //=============================================================================
213 /*! GetHypothesisCreator
214  *
215  */
216 //=============================================================================
217 extern "C"
218 {
219   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator
220     (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI)
221     {
222       return new StdMeshersGUI_HypothesisCreator
223         (aHypType, aServerLibName, aSMESHGUI);
224     }
225 }