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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESHGUI_GroupOpDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_GroupOpDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESH_TypeFilter.hxx"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Desktop.h"
38 #include "SUIT_Session.h"
39 #include "SUIT_MessageBox.h"
41 #include "LightApp_Application.h"
43 #include "LightApp_SelectionMgr.h"
44 #include "SVTK_Selection.h"
45 #include "SVTK_ViewWindow.h"
46 #include "SVTK_Selector.h"
47 #include "SALOME_ListIO.hxx"
52 #include <qpushbutton.h>
53 #include <qgroupbox.h>
56 #include <qlineedit.h>
57 #include <qmessagebox.h>
63 * Class : SMESHGUI_GroupOpDlg
64 * Description : Perform boolean operations on groups
67 //=======================================================================
68 // name : SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg
69 // Purpose : Constructor
70 //=======================================================================
71 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule, const int theMode )
72 : QDialog( SMESH::GetDesktop( theModule ), "SMESHGUI_GroupOpDlg", false,
73 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
74 mySMESHGUI( theModule ),
75 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
79 if (myMode == UNION) {
80 setCaption(tr("UNION_OF_TWO_GROUPS"));
81 myHelpFileName = "/files/using_operations_on_groups.htm#Union";
83 else if (myMode == INTERSECT) {
84 setCaption(tr("INTERSECTION_OF_TWO_GROUPS"));
85 myHelpFileName = "/files/using_operations_on_groups.htm#Intersection";
88 setCaption(tr("CUT_OF_TWO_GROUPS"));
89 myHelpFileName = "/files/using_operations_on_groups.htm#Cut";
92 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
94 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
96 QFrame* aMainFrame = createMainFrame (this);
97 QFrame* aBtnFrame = createButtonFrame(this);
99 aDlgLay->addWidget(aMainFrame);
100 aDlgLay->addWidget(aBtnFrame);
102 aDlgLay->setStretchFactor(aMainFrame, 1);
107 //=======================================================================
108 // name : SMESHGUI_GroupOpDlg::createMainFrame
109 // Purpose : Create frame containing dialog's input fields
110 //=======================================================================
111 QFrame* SMESHGUI_GroupOpDlg::createMainFrame (QWidget* theParent)
113 QGroupBox* aMainGrp = new QGroupBox(1, Qt::Horizontal, theParent);
114 aMainGrp->setFrameStyle(QFrame::NoFrame);
115 aMainGrp->setInsideMargin(0);
117 QGroupBox* aNameGrp = new QGroupBox(1, Qt::Vertical, tr("NAME"), aMainGrp);
118 new QLabel(tr("RESULT_NAME"), aNameGrp);
119 myNameEdit = new QLineEdit(aNameGrp);
121 QGroupBox* anArgGrp = new QGroupBox(3, Qt::Horizontal, tr("ARGUMENTS"), aMainGrp);
123 new QLabel(myMode == CUT ? tr("MAIN_OBJECT") :tr("OBJECT_1"), anArgGrp);
124 myBtn1 = new QPushButton(anArgGrp);
125 myEdit1 = new QLineEdit(anArgGrp);
126 myEdit1->setAlignment( Qt::AlignLeft );
128 new QLabel(myMode == CUT ? tr("TOOL_OBJECT") :tr("OBJECT_2"), anArgGrp);
129 myBtn2 = new QPushButton(anArgGrp);
130 myEdit2 = new QLineEdit(anArgGrp);
131 myEdit2->setAlignment( Qt::AlignLeft );
133 myEdit1->setReadOnly(true);
134 myEdit2->setReadOnly(true);
136 QPixmap aPix (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
137 myBtn1->setPixmap(aPix);
138 myBtn2->setPixmap(aPix);
143 //=======================================================================
144 // name : SMESHGUI_GroupOpDlg::createButtonFrame
145 // Purpose : Create frame containing buttons
146 //=======================================================================
147 QFrame* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
149 QFrame* aFrame = new QFrame(theParent);
150 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
152 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
153 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
154 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
155 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
157 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
159 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
161 aLay->addWidget(myOkBtn);
162 aLay->addWidget(myApplyBtn);
163 aLay->addItem(aSpacer);
164 aLay->addWidget(myCloseBtn);
165 aLay->addWidget(myHelpBtn);
167 // connect signals and slots
168 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
169 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
170 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
171 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
176 //=======================================================================
177 // name : SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg
178 // Purpose : Destructor
179 //=======================================================================
180 SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg()
184 //=======================================================================
185 // name : SMESHGUI_GroupOpDlg::Init
186 // Purpose : Init dialog fields, connect signals and slots, show dialog
187 //=======================================================================
188 void SMESHGUI_GroupOpDlg::Init()
190 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
193 myGroup1 = SMESH::SMESH_GroupBase::_nil();
194 myGroup2 = SMESH::SMESH_GroupBase::_nil();
196 // selection and SMESHGUI
197 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
198 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
199 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(ClickOnClose()));
201 connect(myBtn1, SIGNAL(clicked()), this, SLOT(onFocusChanged()));
202 connect(myBtn2, SIGNAL(clicked()), this, SLOT(onFocusChanged()));
206 // set selection mode
207 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
208 aViewWindow->SetSelectionMode(ActorSelection);
209 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
214 //=======================================================================
215 // name : SMESHGUI_GroupOpDlg::isValid
216 // Purpose : Verify validity of input data
217 //=======================================================================
218 bool SMESHGUI_GroupOpDlg::isValid()
220 // Verify validity of group name
221 if (myNameEdit->text() == "") {
222 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
223 tr("EMPTY_NAME"), QMessageBox::Ok);
227 // Verufy wheter arguments speciffiyed
228 if (myGroup1->_is_nil() || myGroup2->_is_nil()) {
229 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
230 tr("INCORRECT_ARGUMENTS"), QMessageBox::Ok);
234 // Verify whether arguments belongs to same mesh
235 SMESH::SMESH_Mesh_ptr aMesh1 = myGroup1->GetMesh();
236 SMESH::SMESH_Mesh_ptr aMesh2 = myGroup2->GetMesh();
238 int aMeshId1 = !aMesh1->_is_nil() ? aMesh1->GetId() : -1;
239 int aMeshId2 = !aMesh2->_is_nil() ? aMesh2->GetId() : -1;
241 if (aMeshId1 != aMeshId2 || aMeshId1 == -1) {
242 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
243 tr("DIFF_MESHES"), QMessageBox::Ok);
247 // Verify whether groups have same types of entities
248 if (myGroup1->GetType() != myGroup2->GetType()) {
249 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
250 tr("DIFF_TYPES"), QMessageBox::Ok);
257 //=======================================================================
258 // name : SMESHGUI_GroupOpDlg::onApply
259 // Purpose : SLOT called when "Apply" button pressed.
260 //=======================================================================
261 bool SMESHGUI_GroupOpDlg::onApply()
263 if (!isValid() || mySMESHGUI->isActiveStudyLocked())
266 SMESH::SMESH_Mesh_ptr aMesh = myGroup1->GetMesh();
267 QString aName = myNameEdit->text();
268 SMESH::SMESH_Group_ptr aNewGrp = SMESH::SMESH_Group::_nil();
270 if (myMode == UNION) aNewGrp = aMesh->UnionGroups(myGroup1, myGroup2, aName.latin1());
271 else if (myMode == INTERSECT) aNewGrp = aMesh->IntersectGroups(myGroup1, myGroup2, aName.latin1());
272 else aNewGrp = aMesh->CutGroups(myGroup1, myGroup2, aName.latin1());
274 if (!aNewGrp->_is_nil()) {
275 mySMESHGUI->updateObjBrowser(true);
279 QMessageBox::critical(SMESHGUI::desktop(), tr("SMESH_ERROR"),
280 tr("SMESH_OPERATION_FAILED"), "OK");
285 //=======================================================================
286 // name : SMESHGUI_GroupOpDlg::onOk
287 // Purpose : SLOT called when "Ok" button pressed.
288 //=======================================================================
289 void SMESHGUI_GroupOpDlg::onOk()
295 //=======================================================================
296 // name : SMESHGUI_GroupOpDlg::onClose
297 // Purpose : SLOT called when "Close" button pressed. Close dialog
298 //=======================================================================
299 void SMESHGUI_GroupOpDlg::onClose()
301 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
302 aViewWindow->SetSelectionMode(ActorSelection);
303 disconnect(mySelectionMgr, 0, this, 0);
304 disconnect(mySMESHGUI, 0, this, 0);
305 mySMESHGUI->ResetState();
306 mySelectionMgr->clearFilters();
310 //=================================================================================
311 // function : onHelp()
313 //=================================================================================
314 void SMESHGUI_GroupOpDlg::onHelp()
316 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
318 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
320 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
321 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
322 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
323 QObject::tr("BUT_OK"));
327 //=======================================================================
328 // name : SMESHGUI_GroupOpDlg::onSelectionDone
329 // Purpose : SLOT called when selection changed
330 //=======================================================================
331 void SMESHGUI_GroupOpDlg::onSelectionDone()
333 if (myFocusWg == myEdit1)
334 myGroup1 = SMESH::SMESH_GroupBase::_nil();
336 myGroup2 = SMESH::SMESH_GroupBase::_nil();
338 myFocusWg->setText("");
341 mySelectionMgr->selectedObjects(aList);
343 if (aList.Extent() == 1) {
344 SMESH::SMESH_GroupBase_var aGroup =
345 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(aList.First());
347 if (!aGroup->_is_nil())
349 myFocusWg->setText(aGroup->GetName());
350 myFocusWg->setCursorPosition( 0 );
352 if (myFocusWg == myEdit1)
360 //=======================================================================
361 // name : SMESHGUI_GroupOpDlg::onDeactivate
362 // Purpose : SLOT called when dialog must be deativated
363 //=======================================================================
364 void SMESHGUI_GroupOpDlg::onDeactivate()
367 mySelectionMgr->clearFilters();
370 //=======================================================================
371 // name : SMESHGUI_GroupOpDlg::enterEvent
372 // Purpose : Event filter
373 //=======================================================================
374 void SMESHGUI_GroupOpDlg::enterEvent (QEvent*)
376 mySMESHGUI->EmitSignalDeactivateDialog();
378 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
379 aViewWindow->SetSelectionMode(ActorSelection);
380 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
383 //=======================================================================
384 // name : SMESHGUI_GroupOpDlg::closeEvent
386 //=======================================================================
387 void SMESHGUI_GroupOpDlg::closeEvent (QCloseEvent*)
392 //=======================================================================
393 // name : SMESHGUI_GroupOpDlg::onFocusChanged
394 // Purpose : SLOT. Called when "Select" button pressed.
395 //=======================================================================
396 void SMESHGUI_GroupOpDlg::onFocusChanged()
398 const QObject* aSender = sender();
399 myFocusWg = aSender == myBtn1 ? myEdit1 : myEdit2;
403 //=======================================================================
404 // name : SMESHGUI_GroupOpDlg::reset
405 // Purpose : Rest state of dialog
406 //=======================================================================
407 void SMESHGUI_GroupOpDlg::reset()
409 myNameEdit->setText("");
410 myEdit1->setText("");
411 myEdit2->setText("");
413 myNameEdit->setFocus();
416 //=================================================================================
417 // function : keyPressEvent()
419 //=================================================================================
420 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
422 QDialog::keyPressEvent( e );
423 if ( e->isAccepted() )
426 if ( e->key() == Key_F1 )