Salome HOME
PAL8238
[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     // Show Dialog for hypothesis creation
103       //StdMeshersGUI_CreateStdHypothesisDlg *aDlg =
104         new StdMeshersGUI_CreateStdHypothesisDlg(myHypType, parent, "");
105     else
106       SMESH::CreateHypothesis(myHypType, aHypName, isAlgo); // without GUI
107   }
108 }
109
110 //=============================================================================
111 /*! HypothesisCreator::EditHypothesis
112  *
113  */
114 //=============================================================================
115 void StdMeshersGUI_HypothesisCreator::EditHypothesis
116                                       (SMESH::SMESH_Hypothesis_ptr theHyp)
117 {
118   MESSAGE("StdMeshersGUI_HypothesisCreator::EditHypothesis");
119
120   SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis(theHyp);
121
122   list<SMESHGUI_aParameterPtr> paramList;
123   StdMeshersGUI_Parameters::GetParameters( theHyp, paramList );
124
125   bool modified = false;
126   if ( SMESHGUI_aParameterDlg::Parameters( SMESHGUI::GetSMESHGUI(), paramList, QObject::tr("SMESH_VALUE")) )
127   {
128     try
129     {
130       modified = StdMeshersGUI_Parameters::SetParameters( theHyp, paramList );
131     }
132     catch (const SALOME::SALOME_Exception& S_ex)
133     {
134       SalomeApp_Tools::QtCatchCorbaException(S_ex);
135       return;
136     }    
137   }
138
139   if ( modified ) {
140     //set new Attribute Comment for hypothesis which parameters were modified
141     QString aParams = "";
142     StdMeshersGUI_Parameters::GetParameters( theHyp, paramList, aParams );
143     _PTR(SObject) SHyp = SMESH::FindSObject(theHyp);
144     if (SHyp)
145       if (!aParams.isEmpty()) {
146         SMESH::SetValue(SHyp, aParams);
147         //mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
148       }    
149
150     if ( listSOmesh.size() > 0 ) {
151       _PTR(SObject) submSO = listSOmesh[0];
152       SMESH::SMESH_Mesh_var aMesh =
153         SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(submSO);
154       SMESH::SMESH_subMesh_var aSubMesh =
155         SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(submSO);
156       if ( !aSubMesh->_is_nil() )
157         aMesh = aSubMesh->GetFather();
158       _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
159       SMESH::ModifiedMesh( meshSO, false);
160     }
161   }
162 }
163
164 //=============================================================================
165 /*! GetHypothesisCreator
166  *
167  */
168 //=============================================================================
169 extern "C"
170 {
171   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator
172     (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI)
173     {
174       return new StdMeshersGUI_HypothesisCreator
175         (aHypType, aServerLibName, aSMESHGUI);
176     }
177 }