]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx
Salome HOME
Improve compilation procedure:
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ConvToQuadOp.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 /**
21 *  SMESH SMESHGUI
22 *
23 *  Copyright (C) 2005  CEA/DEN, EDF R&D
24 *
25 *
26 *
27 *  File   : SMESHGUI_ConvToQuadOp.h
28 *  Module : SMESHGUI
29 */
30
31 #include "SMESHGUI_ConvToQuadOp.h"
32 #include "SMESHGUI_ConvToQuadDlg.h"
33
34 #include "SMESHGUI.h"
35 #include "SMESHGUI_Utils.h"
36
37 #include "SMESH_TypeFilter.hxx"
38
39 #include "SalomeApp_Tools.h"
40
41 #include "SUIT_MessageBox.h"
42
43 #include "LightApp_UpdateFlags.h"
44        
45 //================================================================================
46 /*!
47  * \brief Constructor
48  *
49  * Initialize operation
50 */
51 //================================================================================
52 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
53   : SMESHGUI_SelectionOp(), 
54     myDlg( 0 )
55 {
56 }
57
58 //================================================================================
59 /*!
60  * \brief Destructor
61 */
62 //================================================================================
63 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
64 {
65   if ( myDlg )
66     delete myDlg;
67 }
68
69 //================================================================================
70 /*!
71  * \brief Gets dialog of this operation
72   * \retval LightApp_Dialog* - pointer to dialog of this operation
73 */
74 //================================================================================
75 LightApp_Dialog* SMESHGUI_ConvToQuadOp::dlg() const
76 {
77   return myDlg;
78 }
79
80 //================================================================================
81 /*!
82  * \brief Creates dialog if necessary and shows it
83  *
84  * Virtual method redefined from base class called when operation is started creates
85  * dialog if necessary and shows it, activates selection
86  */
87 //================================================================================
88 void SMESHGUI_ConvToQuadOp::startOperation()
89 {
90   if( !myDlg )
91   {
92     myDlg = new SMESHGUI_ConvToQuadDlg( );
93   }
94   SMESHGUI_SelectionOp::startOperation();
95
96   myDlg->SetMediumNdsOnGeom( false );
97   myDlg->activateObject( 0 );
98   myDlg->show();
99
100   selectionDone();
101 }
102
103 //================================================================================
104 /*!
105  * \brief Updates dialog's look and feel
106  *
107  * Virtual method redefined from the base class updates dialog's look and feel
108  */
109 //================================================================================
110 void SMESHGUI_ConvToQuadOp::selectionDone()
111 {
112   if ( !dlg()->isShown() )
113     return;
114
115   SMESHGUI_SelectionOp::selectionDone();
116   try
117   {
118     QString anMeshEntry = myDlg->selectedObject( 0 );
119     _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.latin1() );
120     if ( !pMesh ) return;
121
122     SMESH::SMESH_Mesh_var mesh =
123     SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );  
124
125     GEOM::GEOM_Object_var mainGeom;
126     mainGeom = mesh->GetShapeToMesh();
127
128     if( mesh->_is_nil() || 
129         ( !mesh->NbEdgesOfOrder(SMESH::ORDER_LINEAR) && 
130           !mesh->NbFacesOfOrder(SMESH::ORDER_LINEAR) &&
131           !mesh->NbVolumesOfOrder(SMESH::ORDER_LINEAR) ) )
132     {
133       myDlg->setButtonEnabled( false, QtxDialog::OK | QtxDialog::Apply );
134       myDlg->SetEnabledCheck( false );
135     }
136     else if( mainGeom->_is_nil() && myDlg->IsEnabledCheck() )
137       myDlg->SetEnabledCheck( false );
138     else 
139     {
140       myDlg->setButtonEnabled( true, QtxDialog::OK | QtxDialog::Apply );
141       myDlg->SetEnabledCheck( true );
142     }
143   }
144   catch ( const SALOME::SALOME_Exception& S_ex )
145   {
146     SalomeApp_Tools::QtCatchCorbaException( S_ex );
147   }
148   catch ( ... )
149   {
150   }
151 }
152
153 //================================================================================
154 /*!
155  * \brief Creates selection filter
156   * \param theId - identifier of current selection widget
157   * \retval SUIT_SelectionFilter* - pointer to the created filter or null
158  *
159  * Creates selection filter in accordance with identifier of current selection widget
160  */
161 //================================================================================
162 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
163 {
164   if ( theId == 0 )
165     return new SMESH_TypeFilter( MESH );
166   else
167     return 0;
168 }
169
170 //================================================================================
171 /*!
172  * \brief Edits mesh
173  *
174  * Virtual slot redefined from the base class called when "Apply" button is clicked
175  */
176 //================================================================================
177 bool SMESHGUI_ConvToQuadOp::onApply()
178 {
179
180   QString aMess;
181
182   QString anMeshEntry = myDlg->selectedObject( 0 );
183   _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.latin1() );
184   if ( !pMesh )
185   {
186     dlg()->show();
187     SUIT_MessageBox::warn1( myDlg,
188         tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED"), tr( "SMESH_BUT_OK" ) );
189    
190     return false;
191   }
192
193   SMESH::SMESH_Mesh_var mesh =
194   SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );  
195
196   if( CORBA::is_nil(mesh) )
197   {
198     SUIT_MessageBox::warn1( myDlg,
199         tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL"), tr( "SMESH_BUT_OK" ) );
200
201     return false;
202   } 
203
204   bool aResult = false;
205
206   try
207   {
208     bool aParam = true;
209     if( myDlg->IsEnabledCheck() )
210       aParam = myDlg->IsMediumNdsOnGeom();
211
212     SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
213     aEditor->ConvertToQuadratic( aParam );
214     aResult = true; 
215   }
216   catch ( const SALOME::SALOME_Exception& S_ex )
217   {
218     SalomeApp_Tools::QtCatchCorbaException( S_ex );
219     aResult = false;
220   }
221   catch ( ... )
222   {
223     aResult = false;
224   }
225   if(aResult)
226   {
227     update( UF_ObjBrowser | UF_Model );
228     myDlg->setButtonEnabled( false, QtxDialog::Apply );
229   }
230   return aResult;
231 }
232