1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_GroupOpDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_GroupOpDlg.h"
30 #include "QAD_Desktop.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SALOME_Selection.h"
35 #include "SMESH_TypeFilter.hxx"
39 #include <qpushbutton.h>
40 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qmessagebox.h>
50 Class : SMESHGUI_GroupOpDlg
51 Description : Perform boolean operations on groups
54 //=======================================================================
55 // name : SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg
56 // Purpose : Constructor
57 //=======================================================================
58 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( QWidget* theParent,
59 SALOME_Selection* theSelection,
61 : QDialog( theParent, "SMESHGUI_GroupOpDlg", false,
62 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
66 if ( myMode == UNION ) setCaption( tr( "UNION_OF_TWO_GROUPS" ) );
67 else if ( myMode == INTERSECT ) setCaption( tr( "INTERSECTION_OF_TWO_GROUPS" ) );
68 else setCaption( tr( "CUT_OF_TWO_GROUPS" ) );
70 QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
72 QFrame* aMainFrame = createMainFrame ( this );
73 QFrame* aBtnFrame = createButtonFrame( this );
75 aDlgLay->addWidget( aMainFrame );
76 aDlgLay->addWidget( aBtnFrame );
78 aDlgLay->setStretchFactor( aMainFrame, 1 );
83 //=======================================================================
84 // name : SMESHGUI_GroupOpDlg::createMainFrame
85 // Purpose : Create frame containing dialog's input fields
86 //=======================================================================
87 QFrame* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent )
89 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, theParent );
90 aMainGrp->setFrameStyle( QFrame::NoFrame );
91 aMainGrp->setInsideMargin( 0 );
93 QGroupBox* aNameGrp = new QGroupBox( 1, Qt::Vertical, tr( "NAME" ), aMainGrp );
94 new QLabel( tr( "RESULT_NAME" ), aNameGrp );
95 myNameEdit = new QLineEdit( aNameGrp );
97 QGroupBox* anArgGrp = new QGroupBox( 3, Qt::Horizontal, tr( "ARGUMENTS" ), aMainGrp );
99 new QLabel( myMode == CUT ? tr( "MAIN_OBJECT" ) :tr( "OBJECT_1" ), anArgGrp );
100 myBtn1 = new QPushButton( anArgGrp );
101 myEdit1 = new QLineEdit( anArgGrp );
103 new QLabel( myMode == CUT ? tr( "TOOL_OBJECT" ) :tr( "OBJECT_2" ), anArgGrp );
104 myBtn2 = new QPushButton( anArgGrp );
105 myEdit2 = new QLineEdit( anArgGrp );
107 myEdit1->setReadOnly( true );
108 myEdit2->setReadOnly( true );
110 QPixmap aPix( QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr( "ICON_SELECT" ) ) );
111 myBtn1->setPixmap( aPix );
112 myBtn2->setPixmap( aPix );
117 //=======================================================================
118 // name : SMESHGUI_GroupOpDlg::createButtonFrame
119 // Purpose : Create frame containing buttons
120 //=======================================================================
121 QFrame* SMESHGUI_GroupOpDlg::createButtonFrame( QWidget* theParent )
123 QFrame* aFrame = new QFrame( theParent );
124 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
126 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame );
127 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), aFrame );
128 myCloseBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aFrame );
130 QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
132 QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
134 aLay->addWidget( myOkBtn );
135 aLay->addWidget( myApplyBtn );
136 aLay->addItem( aSpacer);
137 aLay->addWidget( myCloseBtn );
139 // connect signals and slots
140 connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) );
141 connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ;
142 connect( myApplyBtn, SIGNAL( clicked() ), SLOT( onApply() ) );
147 //=======================================================================
148 // name : SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg
149 // Purpose : Destructor
150 //=======================================================================
151 SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg()
155 //=======================================================================
156 // name : SMESHGUI_GroupOpDlg::Init
157 // Purpose : Init dialog fields, connect signals and slots, show dialog
158 //=======================================================================
159 void SMESHGUI_GroupOpDlg::Init( SALOME_Selection* theSelection )
161 mySelection = theSelection;
162 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
163 aSMESHGUI->SetActiveDialogBox( ( QDialog* )this ) ;
166 myGroup1 = SMESH::SMESH_GroupBase::_nil();
167 myGroup2 = SMESH::SMESH_GroupBase::_nil();
169 // selection and SMESHGUI
170 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
171 connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
172 connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( ClickOnClose() ) );
174 connect( myBtn1, SIGNAL( clicked() ), this, SLOT( onFocusChanged() ) );
175 connect( myBtn2, SIGNAL( clicked() ), this, SLOT( onFocusChanged() ) );
178 aSMESHGUI->DefineDlgPosition( this, x, y );
182 // set selection mode
183 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection, true );
184 mySelection->AddFilter( new SMESH_TypeFilter( GROUP ) );
189 //=======================================================================
190 // name : SMESHGUI_GroupOpDlg::isValid
191 // Purpose : Verify validity of input data
192 //=======================================================================
193 bool SMESHGUI_GroupOpDlg::isValid()
195 // Verify validity of group name
196 if ( myNameEdit->text() == "" )
198 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
199 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "EMPTY_NAME" ), QMessageBox::Ok );
203 // Verufy wheter arguments speciffiyed
204 if ( myGroup1->_is_nil() || myGroup2->_is_nil() )
206 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
207 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "INCORRECT_ARGUMENTS" ), QMessageBox::Ok );
211 // Verify whether arguments belongs to same mesh
212 SMESH::SMESH_Mesh_ptr aMesh1 = myGroup1->GetMesh();
213 SMESH::SMESH_Mesh_ptr aMesh2 = myGroup2->GetMesh();
215 int aMeshId1 = !aMesh1->_is_nil() ? aMesh1->GetId() : -1;
216 int aMeshId2 = !aMesh2->_is_nil() ? aMesh2->GetId() : -1;
218 if ( aMeshId1 != aMeshId2 || aMeshId1 == -1 )
220 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
221 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "DIFF_MESHES" ), QMessageBox::Ok );
225 // Verify whether groups have same types of entities
226 if ( myGroup1->GetType() != myGroup2->GetType() )
228 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
229 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "DIFF_TYPES" ), QMessageBox::Ok );
237 //=======================================================================
238 // name : SMESHGUI_GroupOpDlg::onApply
239 // Purpose : SLOT called when "Apply" button pressed.
240 //=======================================================================
241 bool SMESHGUI_GroupOpDlg::onApply()
243 if ( !isValid() || SMESHGUI::GetSMESHGUI()->ActiveStudyLocked() )
246 SMESH::SMESH_Mesh_ptr aMesh = myGroup1->GetMesh();
247 QString aName = myNameEdit->text();
248 SMESH::SMESH_Group_ptr aNewGrp = SMESH::SMESH_Group::_nil();
250 if ( myMode == UNION ) aNewGrp = aMesh->UnionGroups( myGroup1, myGroup2, aName.latin1() );
251 else if ( myMode == INTERSECT ) aNewGrp = aMesh->IntersectGroups( myGroup1, myGroup2, aName.latin1() );
252 else aNewGrp = aMesh->CutGroups( myGroup1, myGroup2, aName.latin1() );
254 if ( !aNewGrp->_is_nil() )
256 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->updateObjBrowser( true );
262 QMessageBox::critical( SMESHGUI::GetSMESHGUI()->GetDesktop(),
263 tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ), "OK" );
268 //=======================================================================
269 // name : SMESHGUI_GroupOpDlg::onOk
270 // Purpose : SLOT called when "Ok" button pressed.
271 //=======================================================================
272 void SMESHGUI_GroupOpDlg::onOk()
278 //=======================================================================
279 // name : SMESHGUI_GroupOpDlg::onClose
280 // Purpose : SLOT called when "Close" button pressed. Close dialog
281 //=======================================================================
282 void SMESHGUI_GroupOpDlg::onClose()
284 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
285 disconnect( mySelection, 0, this, 0 );
286 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
287 SMESHGUI::GetSMESHGUI()->ResetState();
288 mySelection->ClearFilters();
292 //=======================================================================
293 // name : SMESHGUI_GroupOpDlg::onSelectionDone
294 // Purpose : SLOT called when selection changed
295 //=======================================================================
296 void SMESHGUI_GroupOpDlg::onSelectionDone()
298 if ( myFocusWg == myEdit1 )
299 myGroup1 = SMESH::SMESH_GroupBase::_nil();
301 myGroup2 = SMESH::SMESH_GroupBase::_nil();
303 myFocusWg->setText( "" );
305 if ( mySelection->IObjectCount() == 1 )
307 SMESH::SMESH_GroupBase_var aGroup =
308 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>( mySelection->firstIObject() );
310 if ( !aGroup->_is_nil() )
312 myFocusWg->setText( aGroup->GetName() );
314 if ( myFocusWg == myEdit1 )
322 //=======================================================================
323 // name : SMESHGUI_GroupOpDlg::onDeactivate
324 // Purpose : SLOT called when dialog must be deativated
325 //=======================================================================
326 void SMESHGUI_GroupOpDlg::onDeactivate()
329 mySelection->ClearFilters();
332 //=======================================================================
333 // name : SMESHGUI_GroupOpDlg::enterEvent
334 // Purpose : Event filter
335 //=======================================================================
336 void SMESHGUI_GroupOpDlg::enterEvent( QEvent* )
338 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ;
340 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection, true );
341 mySelection->AddFilter( new SMESH_TypeFilter( GROUP ) );
345 //=================================================================================
346 // function : closeEvent()
348 //=================================================================================
349 void SMESHGUI_GroupOpDlg::closeEvent( QCloseEvent* )
354 //=======================================================================
355 // name : SMESHGUI_GroupOpDlg::onFocusChanged
356 // Purpose : SLOT. Called when "Select" button pressed.
357 //=======================================================================
358 void SMESHGUI_GroupOpDlg::onFocusChanged()
360 const QObject* aSender = sender();
361 myFocusWg = aSender == myBtn1 ? myEdit1 : myEdit2;
365 //=======================================================================
366 // name : SMESHGUI_GroupOpDlg::reset
367 // Purpose : Rest state of dialog
368 //=======================================================================
369 void SMESHGUI_GroupOpDlg::reset()
371 myNameEdit->setText( "" );
372 myEdit1->setText( "" );
373 myEdit2->setText( "" );
375 myNameEdit->setFocus();