Salome HOME
fix PAL8469. Updating the global mesh icon when local hypotheses are edited
[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 "QAD_Desktop.h"
41 #include "QAD_ResourceMgr.h"
42
43 #include <qobject.h>
44
45 #include "utilities.h"
46
47 using namespace std;
48
49 //=============================================================================
50 /*! class HypothesisCreator
51  *
52  */
53 //=============================================================================
54 class StdMeshersGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator
55 {
56  public:
57   StdMeshersGUI_HypothesisCreator (const QString& aHypType,
58                                    const QString& aServerLibName,
59                                    SMESHGUI* aSMESHGUI)
60     : myHypType(aHypType),
61     myServerLibName(aServerLibName),
62     mySMESHGUI(aSMESHGUI) {}
63
64   virtual void CreateHypothesis (const bool isAlgo, QWidget* parent = 0);
65   virtual void EditHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp);
66
67  private:
68   QString   myHypType;
69   QString   myServerLibName;
70   SMESHGUI* mySMESHGUI;
71 };
72
73 //=============================================================================
74 /*! HypothesisCreator::CreateHypothesis
75  *
76  */
77 //=============================================================================
78 void StdMeshersGUI_HypothesisCreator::CreateHypothesis
79                                       (bool isAlgo, QWidget* parent)
80 {
81   MESSAGE("StdMeshersGUI_HypothesisCreator::CreateHypothesis");
82
83   // Get default name for hypothesis/algorithm creation
84   char* sHypType = (char*)myHypType.latin1();
85   HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
86   QString aHypName;
87   if (aHypData)
88     aHypName = aHypData->Label;
89   else
90     aHypName = myHypType;
91
92   // Create hypothesis/algorithm
93   if (isAlgo)
94   {
95     SMESH::CreateHypothesis(myHypType, aHypName, isAlgo);
96   }
97   else
98   {
99     if ( StdMeshersGUI_Parameters::HasParameters( myHypType ))
100     // Show Dialog for hypothesis creation
101       StdMeshersGUI_CreateStdHypothesisDlg *aDlg =
102         new StdMeshersGUI_CreateStdHypothesisDlg(myHypType, parent, "");
103     else
104       SMESH::CreateHypothesis(myHypType, aHypName, isAlgo); // without GUI
105   }
106 }
107
108 //=============================================================================
109 /*! HypothesisCreator::EditHypothesis
110  *
111  */
112 //=============================================================================
113 void StdMeshersGUI_HypothesisCreator::EditHypothesis
114                                       (SMESH::SMESH_Hypothesis_ptr theHyp)
115 {
116   MESSAGE("StdMeshersGUI_HypothesisCreator::EditHypothesis");
117
118   SALOMEDS::Study::ListOfSObject_var listSOmesh =
119     SMESH::GetMeshesUsingAlgoOrHypothesis(theHyp);
120   
121   list<SMESHGUI_aParameterPtr> paramList;
122   StdMeshersGUI_Parameters::GetParameters( theHyp, paramList );
123
124   bool modified = false;
125   if ( SMESHGUI_aParameterDlg::Parameters( paramList, QObject::tr("SMESH_VALUE")) )
126     modified = StdMeshersGUI_Parameters::SetParameters( theHyp, paramList );
127
128   if ( modified ) {
129     //set new Attribute Comment for hypothesis which parameters were modified
130     QString aParams = "";
131     StdMeshersGUI_Parameters::GetParameters( theHyp, paramList, aParams );
132     SALOMEDS::SObject_var SHyp = SMESH::FindSObject(theHyp);
133     if (!SHyp->_is_nil()) 
134       if (!aParams.isEmpty()) {
135         SMESH::SetValue(SHyp, aParams);
136         //mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
137       }    
138         
139     if ( listSOmesh->length() > 0 ) {
140       SALOMEDS::SObject_var submSO = listSOmesh[0];
141       SMESH::SMESH_Mesh_var aMesh =
142         SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(submSO);
143       SMESH::SMESH_subMesh_var aSubMesh =
144         SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(submSO);
145       if ( !aSubMesh->_is_nil() )
146         aMesh = aSubMesh->GetFather();
147       SALOMEDS::SObject_var meshSO = SMESH::FindSObject( aMesh );
148       SMESH::ModifiedMesh( meshSO, false);
149     }
150   }
151 }
152
153 //=============================================================================
154 /*! GetHypothesisCreator
155  *
156  */
157 //=============================================================================
158 extern "C"
159 {
160   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator
161     (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI)
162     {
163       return new StdMeshersGUI_HypothesisCreator
164         (aHypType, aServerLibName, aSMESHGUI);
165     }
166 }