1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 // File : SMESHGUI_GroupOp.cxx
23 // Author : Sergey LITONIN
26 #include <SMESHGUI_GroupOp.h>
27 #include <SMESHGUI_GroupOpDlg.h>
28 #include <SMESH_TypeFilter.hxx>
31 #include <SalomeApp_SelectionMgr.h>
32 #include <SalomeApp_UpdateFlags.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_Desktop.h>
36 #include <SALOMEDS_SObject.hxx>
38 #include <SALOMEconfig.h>
39 #include CORBA_SERVER_HEADER(SMESH_Group)
43 Class : SMESHGUI_GroupOp
44 Description : Perform boolean operations on groups
47 //=======================================================================
48 // name : SMESHGUI_GroupOp
50 //=======================================================================
51 SMESHGUI_GroupOp::SMESHGUI_GroupOp( const int mode )
52 : SMESHGUI_SelectionOp(),
58 //=======================================================================
59 // name : ~SMESHGUI_GroupOp
61 //=======================================================================
62 SMESHGUI_GroupOp::~SMESHGUI_GroupOp()
68 //=======================================================================
71 //=======================================================================
72 SalomeApp_Dialog* SMESHGUI_GroupOp::dlg() const
77 //=======================================================================
80 //=======================================================================
81 bool SMESHGUI_GroupOp::onApply()
83 if( !myDlg || !isValid() || getSMESHGUI()->isActiveStudyLocked() )
86 QStringList selGroup[2];
87 for( int i=1; i<=2; i++ )
88 myDlg->selectedObject( i, selGroup[i-1] );
90 _PTR(SObject) pGroup1 = studyDS()->FindObjectID( selGroup[0].first() ),
91 pGroup2 = studyDS()->FindObjectID( selGroup[1].first() );
92 SMESH::SMESH_GroupBase_var aGroup1 = SMESH::SMESH_GroupBase::_narrow( _CAST(SObject,pGroup1)->GetObject() ),
93 aGroup2 = SMESH::SMESH_GroupBase::_narrow( _CAST(SObject,pGroup2)->GetObject() );
95 SMESH::SMESH_Mesh_ptr aMesh = aGroup1->GetMesh();
96 QString aName = myDlg->name();
97 SMESH::SMESH_Group_ptr aNewGrp = SMESH::SMESH_Group::_nil();
100 aNewGrp = aMesh->UnionGroups( aGroup1, aGroup2, aName.latin1() );
102 else if( myMode == INTERSECT )
103 aNewGrp = aMesh->IntersectGroups( aGroup1, aGroup2, aName.latin1() );
106 aNewGrp = aMesh->CutGroups( aGroup1, aGroup2, aName.latin1() );
108 if (!aNewGrp->_is_nil())
110 update( UF_Model | UF_ObjBrowser );
116 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr("SMESH_ERROR"),
117 tr("SMESH_OPERATION_FAILED"), tr( "SMESH_BUT_OK" ) );
122 //=======================================================================
123 // name : startOperation
125 //=======================================================================
126 void SMESHGUI_GroupOp::startOperation()
130 myDlg = new SMESHGUI_GroupOpDlg( getSMESHGUI(), myMode );
131 connect( myDlg, SIGNAL( nameChanged( const QString& ) ), this, SLOT( onNameChanged( const QString& ) ) );
134 SMESHGUI_SelectionOp::startOperation();
139 //=======================================================================
140 // name : startOperation
142 //=======================================================================
143 SUIT_SelectionFilter* SMESHGUI_GroupOp::createFilter( const int ) const
145 return new SMESH_TypeFilter( GROUP );
148 //=======================================================================
149 // name : startOperation
151 //=======================================================================
152 void SMESHGUI_GroupOp::initDialog()
154 SMESHGUI_SelectionOp::initDialog();
157 myDlg->setName( QString::null );
162 //=======================================================================
163 // name : updateDialog
165 //=======================================================================
166 void SMESHGUI_GroupOp::selectionDone()
168 SMESHGUI_SelectionOp::selectionDone();
172 //=======================================================================
173 // name : updateDialog
175 //=======================================================================
176 void SMESHGUI_GroupOp::updateDialog()
181 bool isEnabled = !myDlg->name().isEmpty() && myDlg->hasSelection( 1 ) && myDlg->hasSelection( 2 );
182 myDlg->setButtonEnabled( isEnabled, QtxDialog::OK | QtxDialog::Apply );
185 //=======================================================================
187 // Purpose : Verify validity of input data
188 //=======================================================================
189 bool SMESHGUI_GroupOp::isValid() const
194 // Verify validity of group name
195 if( myDlg->name().isEmpty() )
197 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
198 tr("EMPTY_NAME"), tr( "SMESH_BUT_OK" ) );
202 QStringList selGroup[2];
203 for( int i=1; i<=2; i++ )
204 myDlg->selectedObject( i, selGroup[i-1] );
206 _PTR(SObject) pGroup1 = studyDS()->FindObjectID( selGroup[0].first() ),
207 pGroup2 = studyDS()->FindObjectID( selGroup[1].first() );
208 SMESH::SMESH_GroupBase_var aGroup1 = SMESH::SMESH_GroupBase::_narrow( _CAST(SObject,pGroup1)->GetObject() ),
209 aGroup2 = SMESH::SMESH_GroupBase::_narrow( _CAST(SObject,pGroup2)->GetObject() );
211 // Verufy wheter arguments speciffiyed
212 if( aGroup1->_is_nil() || aGroup2->_is_nil())
214 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
215 tr("INCORRECT_ARGUMENTS"), tr( "SMESH_BUT_OK" ) );
219 // Verify whether arguments belongs to same mesh
220 SMESH::SMESH_Mesh_ptr aMesh1 = aGroup1->GetMesh();
221 SMESH::SMESH_Mesh_ptr aMesh2 = aGroup2->GetMesh();
223 int aMeshId1 = !aMesh1->_is_nil() ? aMesh1->GetId() : -1;
224 int aMeshId2 = !aMesh2->_is_nil() ? aMesh2->GetId() : -1;
226 if (aMeshId1 != aMeshId2 || aMeshId1 == -1) {
227 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
228 tr("DIFF_MESHES"), tr( "SMESH_BUT_OK" ) );
232 // Verify whether groups have same types of entities
233 if( aGroup1->GetType() != aGroup2->GetType() ) {
234 SUIT_MessageBox::warn1( SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
235 tr("DIFF_TYPES"), tr( "SMESH_BUT_OK" ) );
242 //=======================================================================
243 // name : onNameChanged
245 //=======================================================================
246 void SMESHGUI_GroupOp::onNameChanged( const QString& )