Salome HOME
Movement of examples to CVS EXAMPLES SAMPLES_SRC.
[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 #include "SALOMEconfig.h"
29 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_Hypotheses.h"
34 #include "SMESHGUI_HypothesesUtils.h"
35
36 #include "SMESHGUI_aParameterDlg.h"
37 #include "StdMeshersGUI_Parameters.h"
38 #include "StdMeshersGUI_CreateStdHypothesisDlg.h"
39
40 #include "SUIT_Desktop.h"
41 #include "SUIT_ResourceMgr.h"
42
43 #include <SalomeApp_Tools.h>
44
45 #include <qobject.h>
46
47 #include "utilities.h"
48
49 using namespace std;
50
51 //=============================================================================
52 /*! class HypothesisCreator
53  *
54  */
55 //=============================================================================
56 class StdMeshersGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
57 {
58  public:
59   StdMeshersGUI_HypothesisCreator (const QString& aHypType,
60                                    const QString& aServerLibName,
61                                    SMESHGUI* aSMESHGUI)
62     : myHypType(aHypType),
63     myServerLibName(aServerLibName),
64     mySMESHGUI(aSMESHGUI) {}
65
66   virtual void CreateHypothesis (const bool isAlgo, QWidget* parent = 0);
67   virtual void EditHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp);
68
69  private:
70   QString   myHypType;
71   QString   myServerLibName;
72   SMESHGUI* mySMESHGUI;
73 };
74
75 //=============================================================================
76 /*! HypothesisCreator::CreateHypothesis
77  *
78  */
79 //=============================================================================
80 void StdMeshersGUI_HypothesisCreator::CreateHypothesis
81                                       (bool isAlgo, QWidget* parent)
82 {
83   MESSAGE("StdMeshersGUI_HypothesisCreator::CreateHypothesis");
84
85   // Get default name for hypothesis/algorithm creation
86   char* sHypType = (char*)myHypType.latin1();
87   HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
88   QString aHypName;
89   if (aHypData)
90     aHypName = aHypData->Label;
91   else
92     aHypName = myHypType;
93
94   // Create hypothesis/algorithm
95   if (isAlgo)
96   {
97     SMESH::CreateHypothesis(myHypType, aHypName, isAlgo);
98   }
99   else
100   {
101     if ( StdMeshersGUI_Parameters::HasParameters( myHypType ))
102     {
103       // Show Dialog for hypothesis creation
104       StdMeshersGUI_CreateStdHypothesisDlg *aDlg =
105           new StdMeshersGUI_CreateStdHypothesisDlg(myHypType, parent, "");
106       /* Move widget on the botton right corner of main widget */
107 //       int x, y ;
108 //       mySMESHGUI->DefineDlgPosition( aDlg, x, y ) ;
109 //       aDlg->move( x, y ) ;
110       aDlg->exec() ; /* displays Dialog */
111     }
112     else
113       SMESH::CreateHypothesis(myHypType, aHypName, isAlgo); // without GUI
114   }
115 }
116
117 //=============================================================================
118 /*! HypothesisCreator::EditHypothesis
119  *
120  */
121 //=============================================================================
122 void StdMeshersGUI_HypothesisCreator::EditHypothesis
123                                       (SMESH::SMESH_Hypothesis_ptr theHyp)
124 {
125   MESSAGE("StdMeshersGUI_HypothesisCreator::EditHypothesis");
126
127   SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis(theHyp);
128
129   list<SMESHGUI_aParameterPtr> paramList;
130   StdMeshersGUI_Parameters::GetParameters( theHyp, paramList );
131
132   bool modified = false;
133   if ( SMESHGUI_aParameterDlg::Parameters( SMESHGUI::GetSMESHGUI(), paramList, QObject::tr("SMESH_VALUE")) )
134   {
135     try
136     {
137       modified = StdMeshersGUI_Parameters::SetParameters( theHyp, paramList );
138     }
139     catch (const SALOME::SALOME_Exception& S_ex)
140     {
141       SalomeApp_Tools::QtCatchCorbaException(S_ex);
142       return;
143     }    
144   }
145
146   if ( modified ) {
147     //set new Attribute Comment for hypothesis which parameters were modified
148     QString aParams = "";
149     StdMeshersGUI_Parameters::GetParameters( theHyp, paramList, aParams );
150     _PTR(SObject) SHyp = SMESH::FindSObject(theHyp);
151     if (SHyp)
152       if (!aParams.isEmpty()) {
153         SMESH::SetValue(SHyp, aParams);
154         //mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
155       }    
156
157     if ( listSOmesh.size() > 0 ) {
158       _PTR(SObject) submSO = listSOmesh[0];
159       SMESH::SMESH_Mesh_var aMesh =
160         SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(submSO);
161       SMESH::SMESH_subMesh_var aSubMesh =
162         SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(submSO);
163       if ( !aSubMesh->_is_nil() )
164         aMesh = aSubMesh->GetFather();
165       _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
166       SMESH::ModifiedMesh( meshSO, false);
167     }
168   }
169 }
170
171 //=============================================================================
172 /*! GetHypothesisCreator
173  *
174  */
175 //=============================================================================
176 extern "C"
177 {
178   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator
179     (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI)
180     {
181       return new StdMeshersGUI_HypothesisCreator
182         (aHypType, aServerLibName, aSMESHGUI);
183     }
184 }