Salome HOME
Merge branch 'V8_4_BR'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SplitBiQuad.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_SplitBiQuad.h
25 // Author : Open CASCADE S.A.S.
26 //
27
28 #include "SMESHGUI_SplitBiQuad.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESH_LogicalFilter.hxx"
33 #include "SMESH_TypeFilter.hxx"
34
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
37
38 #include <LightApp_UpdateFlags.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_OverrideCursor.h>
41 #include <SalomeApp_Tools.h>
42
43 #include <QStringList>
44 #include <QGridLayout>
45
46 //================================================================================
47 /*!
48  * \brief Dialog constructor
49  */
50 //================================================================================
51
52 SMESHGUI_SplitBiQuadDlg::SMESHGUI_SplitBiQuadDlg()
53   : SMESHGUI_Dialog( 0, /*modal=*/false, /*allowResize=*/true )
54 {
55   setWindowTitle( tr( "CAPTION" ) );
56   setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
57   createObject( tr( "MESH" ), mainFrame(), 0 );
58
59   QGridLayout* aLay = new QGridLayout( mainFrame() );
60   aLay->setMargin( 5 );
61   aLay->setSpacing( 5 );
62
63   aLay->addWidget( objectWg( 0,  Label ),   0, 0 );
64   //aLay->addWidget( objectWg( 0,  Btn ),     0, 1 );
65   aLay->addWidget( objectWg( 0,  Control ), 0, 1 );
66   objectWg( 0,  Btn )->hide();
67 }
68
69 //================================================================================
70 /*!
71  * \brief Dialog destructor
72  */
73 //================================================================================
74
75 SMESHGUI_SplitBiQuadDlg::~SMESHGUI_SplitBiQuadDlg()
76 {
77 }
78
79 //================================================================================
80 /*!
81  * \brief SMESHGUI_SplitBiQuadOp constructor
82  */
83 //================================================================================
84
85 SMESHGUI_SplitBiQuadOp::SMESHGUI_SplitBiQuadOp()
86   : SMESHGUI_SelectionOp(), myDlg( 0 )
87 {
88 }
89
90 //================================================================================
91 /*!
92  * \brief SMESHGUI_SplitBiQuadOp destructor
93  */
94 //================================================================================
95
96 SMESHGUI_SplitBiQuadOp::~SMESHGUI_SplitBiQuadOp()
97 {
98   if ( myDlg ) delete myDlg;
99 }
100
101 //================================================================================
102 /*!
103  * \brief Gets dialog of this operation
104   * \retval LightApp_Dialog* - pointer to dialog of this operation
105 */
106 //================================================================================
107
108 LightApp_Dialog* SMESHGUI_SplitBiQuadOp::dlg() const
109 {
110   return myDlg;
111 }
112
113 //================================================================================
114 /*!
115  * \brief Creates dialog if necessary and shows it
116  *
117  * Virtual method redefined from base class called when operation is started creates
118  * dialog if necessary and shows it, activates selection
119  */
120 //================================================================================
121
122 void SMESHGUI_SplitBiQuadOp::startOperation()
123 {
124   if( !myDlg )
125   {
126     myDlg = new SMESHGUI_SplitBiQuadDlg();
127   }
128   myHelpFileName = "split_biquad_to_linear.html";
129
130   SMESHGUI_SelectionOp::startOperation();
131
132   myDlg->activateObject( 0 );
133   myDlg->show();
134
135   selectionDone();
136 }
137
138 //================================================================================
139 /*!
140  * \brief Updates dialog's look and feel
141  *
142  * Virtual method redefined from the base class updates dialog's look and feel
143  */
144 //================================================================================
145
146 // void SMESHGUI_SplitBiQuadOp::selectionDone()
147 // {
148 //   if ( !dlg()->isVisible() )
149 //     return;
150
151 //   SMESHGUI_SelectionOp::selectionDone();
152 // }
153
154 //================================================================================
155 /*!
156  * \brief Creates selection filter
157   * \param theId - identifier of current selection widget
158   * \retval SUIT_SelectionFilter* - pointer to the created filter or null
159  *
160  * Creates selection filter in accordance with identifier of current selection widget
161  */
162 //================================================================================
163
164 SUIT_SelectionFilter* SMESHGUI_SplitBiQuadOp::createFilter( const int theId ) const
165 {
166   if ( theId != 0 )
167     return 0;
168
169   QList<SUIT_SelectionFilter*> filters;
170   filters << new SMESH_TypeFilter( SMESH::IDSOURCE_FACE );
171   filters << new SMESH_TypeFilter( SMESH::IDSOURCE_VOLUME );
172   return new SMESH_LogicalFilter( filters,
173                                   SMESH_LogicalFilter::LO_OR,
174                                   /*takeOwnership=*/true );
175 }
176
177 //================================================================================
178 /*!
179  * \brief Edits mesh
180  *
181  * Virtual slot redefined from the base class called when "Apply" button is clicked
182  */
183 //================================================================================
184
185 bool SMESHGUI_SplitBiQuadOp::onApply()
186 {
187   SUIT_OverrideCursor aWaitCursor;
188
189   LightApp_Dialog::SelectedObjects selection;
190   myDlg->objectSelection( selection );
191   if ( selection.empty() || selection[0].empty() )
192   {
193     SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
194     return false;
195   }
196   QStringList& entries = selection[0];
197
198   SMESH::SMESH_Mesh_var mesh;
199   SMESH::ListOfIDSources_var idSource = new SMESH::ListOfIDSources();
200   idSource->length( entries.count() );
201
202   int nbObj = 0;
203   for ( int i = 0; i < entries.count() ; ++i )
204   {
205     _PTR(SObject) pObj = studyDS()->FindObjectID( entries[i].toLatin1().data() );
206     SMESH::SMESH_IDSource_var obj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
207     if( !CORBA::is_nil( obj ))
208     {
209       idSource[ nbObj++ ] = obj;
210       SMESH::SMESH_Mesh_var m = obj->GetMesh();
211       if ( !mesh->_is_nil() && mesh->GetId() != m->GetId() )
212       {
213         SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), tr("DIFFERENT_MESHES") );
214         return false;
215       }
216       mesh = m;
217     }
218   }
219   if ( CORBA::is_nil( mesh ))
220   {
221     SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
222     return false;
223   }
224   if ( nbObj == 0 )
225   {
226     SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
227     return false;
228   }
229   idSource->length( nbObj );
230
231   bool aResult = false;
232
233   try
234   {
235     SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
236     aResult = true;
237     aEditor->SplitBiQuadraticIntoLinear( idSource );
238   }
239   catch ( const SALOME::SALOME_Exception& S_ex )
240   {
241     SalomeApp_Tools::QtCatchCorbaException( S_ex );
242     aResult = false;
243   }
244   catch ( ... )
245   {
246     aResult = false;
247   }
248   if( aResult )
249   {
250     SMESHGUI::Modified();
251     update( UF_ObjBrowser | UF_Model | UF_Viewer );
252     selectionDone();
253   }
254   return aResult;
255 }