1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_SplitBiQuad.h
25 // Author : Open CASCADE S.A.S.
28 #include "SMESHGUI_SplitBiQuad.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESH_LogicalFilter.hxx"
33 #include "SMESH_TypeFilter.hxx"
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
38 #include <LightApp_UpdateFlags.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_OverrideCursor.h>
41 #include <SalomeApp_Tools.h>
43 #include <QStringList>
44 #include <QGridLayout>
46 //================================================================================
48 * \brief Dialog constructor
50 //================================================================================
52 SMESHGUI_SplitBiQuadDlg::SMESHGUI_SplitBiQuadDlg()
53 : SMESHGUI_Dialog( 0, /*modal=*/false, /*allowResize=*/true )
55 setWindowTitle( tr( "CAPTION" ) );
56 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
57 createObject( tr( "MESH" ), mainFrame(), 0 );
59 QGridLayout* aLay = new QGridLayout( mainFrame() );
61 aLay->setSpacing( 5 );
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();
69 //================================================================================
71 * \brief Dialog destructor
73 //================================================================================
75 SMESHGUI_SplitBiQuadDlg::~SMESHGUI_SplitBiQuadDlg()
79 //================================================================================
81 * \brief SMESHGUI_SplitBiQuadOp constructor
83 //================================================================================
85 SMESHGUI_SplitBiQuadOp::SMESHGUI_SplitBiQuadOp()
86 : SMESHGUI_SelectionOp(), myDlg( 0 )
90 //================================================================================
92 * \brief SMESHGUI_SplitBiQuadOp destructor
94 //================================================================================
96 SMESHGUI_SplitBiQuadOp::~SMESHGUI_SplitBiQuadOp()
98 if ( myDlg ) delete myDlg;
101 //================================================================================
103 * \brief Gets dialog of this operation
104 * \retval LightApp_Dialog* - pointer to dialog of this operation
106 //================================================================================
108 LightApp_Dialog* SMESHGUI_SplitBiQuadOp::dlg() const
113 //================================================================================
115 * \brief Creates dialog if necessary and shows it
117 * Virtual method redefined from base class called when operation is started creates
118 * dialog if necessary and shows it, activates selection
120 //================================================================================
122 void SMESHGUI_SplitBiQuadOp::startOperation()
126 myDlg = new SMESHGUI_SplitBiQuadDlg();
128 myHelpFileName = "split_biquad_to_linear.html";
130 SMESHGUI_SelectionOp::startOperation();
132 myDlg->activateObject( 0 );
138 //================================================================================
140 * \brief Updates dialog's look and feel
142 * Virtual method redefined from the base class updates dialog's look and feel
144 //================================================================================
146 // void SMESHGUI_SplitBiQuadOp::selectionDone()
148 // if ( !dlg()->isVisible() )
151 // SMESHGUI_SelectionOp::selectionDone();
154 //================================================================================
156 * \brief Creates selection filter
157 * \param theId - identifier of current selection widget
158 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
160 * Creates selection filter in accordance with identifier of current selection widget
162 //================================================================================
164 SUIT_SelectionFilter* SMESHGUI_SplitBiQuadOp::createFilter( const int theId ) const
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 );
177 //================================================================================
181 * Virtual slot redefined from the base class called when "Apply" button is clicked
183 //================================================================================
185 bool SMESHGUI_SplitBiQuadOp::onApply()
187 SUIT_OverrideCursor aWaitCursor;
189 LightApp_Dialog::SelectedObjects selection;
190 myDlg->objectSelection( selection );
191 if ( selection.empty() || selection[0].empty() )
193 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
196 QStringList& entries = selection[0];
198 SMESH::SMESH_Mesh_var mesh;
199 SMESH::ListOfIDSources_var idSource = new SMESH::ListOfIDSources();
200 idSource->length( entries.count() );
203 for ( int i = 0; i < entries.count() ; ++i )
205 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( entries[i].toUtf8().data() );
206 SMESH::SMESH_IDSource_var obj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
207 if( !CORBA::is_nil( obj ))
209 idSource[ nbObj++ ] = obj;
210 SMESH::SMESH_Mesh_var m = obj->GetMesh();
211 if ( !mesh->_is_nil() && mesh->GetId() != m->GetId() )
213 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), tr("DIFFERENT_MESHES") );
219 if ( CORBA::is_nil( mesh ))
221 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
226 SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
229 idSource->length( nbObj );
231 bool aResult = false;
235 SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
237 aEditor->SplitBiQuadraticIntoLinear( idSource );
239 catch ( const SALOME::SALOME_Exception& S_ex )
241 SalomeApp_Tools::QtCatchCorbaException( S_ex );
250 SMESHGUI::Modified();
251 update( UF_ObjBrowser | UF_Model | UF_Viewer );