Salome HOME
Portation on new based dialog
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_CreateHypothesesOp.cxx
1 /**
2 *  SALOME SMESHGUI
3 *
4 *  Copyright (C) 2005  CEA/DEN, EDF R&D
5 *
6 *
7 *
8 *  File   : SMESHGUI_CreateHypothesesOp.cxx
9 *  Author : Sergey LITONIN
10 *  Module : SALOME
11 */
12
13 #include "SMESHGUI_CreateHypothesesOp.h"
14
15 #include "SMESHGUI_CreateHypothesesDlg.h"
16 #include "SMESHGUI_HypothesesUtils.h"
17 #include "SMESHGUI_Hypotheses.h"
18 #include "SMESHGUI.h"
19
20 #include "SALOME_ListIteratorOfListIO.hxx"
21
22 #include <qstring.h>
23 #include <qstringlist.h>
24
25 /*!
26  * \brief Constructor
27   * \param theIsAlgo - If TRUE when operation is used for creation of gypotheses
28 *
29 * Constructor does nothing
30 */
31 SMESHGUI_CreateHypothesesOp::SMESHGUI_CreateHypothesesOp( const bool theIsAlgo )
32 : SMESHGUI_Operation(),
33   myIsAlgo( theIsAlgo ),
34   myDlg( 0 )
35 {
36 }
37
38 /*!
39  * \brief Destructor
40 */
41 SMESHGUI_CreateHypothesesOp::~SMESHGUI_CreateHypothesesOp()
42 {
43 }
44
45 /*!
46  * \brief Start operation
47 *
48 * Virtual method redefined from the base class initializes and shows dialog
49 */
50 void SMESHGUI_CreateHypothesesOp::startOperation()
51 {
52   if ( myDlg == 0 )
53     myDlg = new SMESHGUI_CreateHypothesesDlg( myIsAlgo );
54
55   SMESHGUI_Operation::startOperation();
56
57   QStringList aHypList, aPluginNames, aLabels, anIconIds;
58     
59   aHypList = SMESH::GetAvailableHypotheses( myIsAlgo );
60   for ( int i = 0, n = aHypList.count(); i < n; ++i )
61   {
62     HypothesisData* aHypData = SMESH::GetHypothesisData( aHypList[i] );
63     if ( aHypData )
64     {
65       aPluginNames.append( aHypData->PluginName );
66       aLabels.append( aHypData->Label );
67       anIconIds.append( aHypData->IconId );
68     }
69     else
70     {
71       aPluginNames.append( "" );
72       aLabels.append( "" );
73       anIconIds.append( "" );
74     }
75   }
76
77   myDlg->init( aHypList, aPluginNames, aLabels, anIconIds );
78   myDlg->show();
79 }
80
81 /*!
82  * \brief Gets dialog
83   * \return Pointer to the dialog used by this operation
84 *
85 * This pointer is used by base operation for its different purposes
86 */
87 SalomeApp_Dialog* SMESHGUI_CreateHypothesesOp::dlg() const
88 {
89   return myDlg;
90 }
91
92 /*!
93  * \brief onApply
94   * \return TRUE if hypothesis or algorithm is created successfully, FALSE otherwise
95 *
96 * Virtual slot redefined from base class is called when "Apply" button clicked and
97 * creates hypothesis or algorithm
98 */
99 bool SMESHGUI_CreateHypothesesOp::onApply()
100 {
101   if ( isStudyLocked() )
102     return false;
103     
104   QString aHypType = myDlg->hypName();
105   if ( aHypType == "" )
106     return false;
107
108   char* sHypType = ( char* )aHypType.latin1();
109
110   HypothesisData* aHypData = SMESH::GetHypothesisData( sHypType );
111   if ( !aHypData )
112     return false;
113     
114   QString aClientLibName = aHypData->ClientLibName;
115
116   if ( aClientLibName == "" )
117   {
118     // Call hypothesis creation server method ( without GUI )
119     QString aHypName = aHypData->Label;
120     SMESH::CreateHypothesis( sHypType, aHypName, myIsAlgo );
121   }
122   else
123   {
124     // Get hypotheses creator client ( GUI )
125     SMESHGUI_GenericHypothesisCreator* aCreator =
126       SMESH::GetHypothesisCreator( sHypType );
127
128     // Create hypothesis/algorithm
129     aCreator->CreateHypothesis( myIsAlgo, dlg() );
130   }
131
132   return true;
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151