1 // Copyright (C) 2007-2012 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.
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_GroupOpDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupOpDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
34 #include <SMESH_TypeFilter.hxx>
36 // SALOME GUI includes
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <SVTK_Selection.h>
45 #include <SVTK_ViewWindow.h>
46 #include <SALOME_ListIO.hxx>
48 // SALOME KERNEL includes
49 #include <SALOMEDSClient_SObject.hxx>
52 #include <QHBoxLayout>
53 #include <QVBoxLayout>
54 #include <QGridLayout>
55 #include <QPushButton>
60 #include <QListWidget>
61 #include <QButtonGroup>
62 #include <SALOME_ListIteratorOfListIO.hxx>
64 #include <QtxColorButton.h>
70 * Class : SMESHGUI_GroupOpDlg
71 * Description : Perform boolean operations on groups
76 \param theModule pointer on module instance
78 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule )
79 : QDialog( SMESH::GetDesktop( theModule ) ),
80 mySMESHGUI( theModule ),
81 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
82 myIsApplyAndClose( false )
86 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
88 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
89 aDlgLay->setMargin(MARGIN);
90 aDlgLay->setSpacing(SPACING);
92 QWidget* aMainFrame = createMainFrame (this);
93 QWidget* aBtnFrame = createButtonFrame(this);
95 aDlgLay->addWidget(aMainFrame);
96 aDlgLay->addWidget(aBtnFrame);
102 \brief Creates frame containing dialog's input fields
103 \param theParent parent widget
104 \return pointer on created widget
106 QWidget* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent )
108 QWidget* aMainGrp = new QWidget(theParent);
109 QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
111 aLay->setSpacing(SPACING);
113 // ------------------------------------------------------
114 QGroupBox* aNameGrp = new QGroupBox(tr("NAME"), aMainGrp);
115 QHBoxLayout* aNameGrpLayout = new QHBoxLayout(aNameGrp);
116 aNameGrpLayout->setMargin(MARGIN);
117 aNameGrpLayout->setSpacing(SPACING);
119 QLabel* aNameLab = new QLabel(tr("RESULT_NAME"), aNameGrp);
120 myNameEdit = new QLineEdit(aNameGrp);
122 aNameGrpLayout->addWidget(aNameLab);
123 aNameGrpLayout->addWidget(myNameEdit);
125 // ------------------------------------------------------
126 myArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp);
129 // ------------------------------------------------------
131 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
132 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
133 aColorBoxLayout->setMargin(MARGIN);
134 aColorBoxLayout->setSpacing(SPACING);
136 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
137 myColorBtn = new QtxColorButton(aColorBox);
138 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
139 myColorBtn->sizePolicy().verticalPolicy() );
141 aColorBoxLayout->addWidget(aColorLab);
142 aColorBoxLayout->addWidget(myColorBtn);
144 // ------------------------------------------------------
145 aLay->addWidget( aNameGrp );
146 aLay->addWidget( myArgGrp );
147 aLay->addWidget( aColorBox );
153 \brief Gets pointer on arguments group box
154 \return pointer on arguments group box
156 QGroupBox* SMESHGUI_GroupOpDlg::getArgGrp() const
162 \brief Sets help file name
163 \param theFName help file name
165 void SMESHGUI_GroupOpDlg::setHelpFileName( const QString& theFName )
167 myHelpFileName = theFName;
171 \brief Gets pointer to the module instance
172 \return pointer to the module instance
174 SMESHGUI* SMESHGUI_GroupOpDlg::getSMESHGUI() const
180 \brief Create frame containing buttons
181 \param theParent parent widget
182 \return pointer to the created frame
184 QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
186 QGroupBox* aFrame = new QGroupBox(theParent);
188 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
189 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
190 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
191 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
193 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
194 aLay->setMargin(MARGIN);
195 aLay->setSpacing(SPACING);
197 aLay->addWidget(myOkBtn);
198 aLay->addSpacing(10);
199 aLay->addWidget(myApplyBtn);
200 aLay->addSpacing(10);
202 aLay->addWidget(myCloseBtn);
203 aLay->addWidget(myHelpBtn);
205 // connect signals and slots
206 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
207 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
208 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
209 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
217 SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg()
222 \brief Init dialog fields, connect signals and slots, show dialog
224 void SMESHGUI_GroupOpDlg::Init()
226 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
228 // selection and SMESHGUI
229 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
230 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
231 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(ClickOnClose()));
233 // set selection mode
234 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
235 aViewWindow->SetSelectionMode(ActorSelection);
236 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
240 \brief Validate list of groups used for operation. Checks whether they corresponds
241 to the same face and have one type
242 \param theListGrp input list of groups
243 \return TRUE if groups are valid, FALSE otherwise
245 bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theListGrp )
247 if ( theListGrp.isEmpty() )
249 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
250 tr("INCORRECT_ARGUMENTS") );
254 int aMeshId = -1, aGrpType = -1;
255 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter;
256 for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter )
258 SMESH::SMESH_GroupBase_var aGrp = *anIter;
259 if ( CORBA::is_nil( aGrp ) )
260 continue; // nonsence
262 SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh();
263 if ( CORBA::is_nil( aMesh ) )
267 int aCurrId = aMesh->GetId();
272 if ( aMeshId != aCurrId )
274 aMeshId = -1; // different meshes
280 int aCurrType = aGrp->GetType();
281 if ( aGrpType == -1 )
282 aGrpType = aCurrType;
285 if ( aGrpType != aCurrType )
287 aGrpType = -1; // different types
296 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
301 if ( aGrpType == -1 )
303 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
312 \brief SLOT called when "Ok" button pressed performs operation and closes dialog box
314 void SMESHGUI_GroupOpDlg::onOk()
316 setIsApplyAndClose( true );
319 setIsApplyAndClose( false );
323 \brief SLOT called when "Close" button pressed closes dialog
325 void SMESHGUI_GroupOpDlg::onClose()
327 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
328 aViewWindow->SetSelectionMode(ActorSelection);
329 disconnect( mySelectionMgr, 0, this, 0 );
330 disconnect( mySMESHGUI, 0, this, 0 );
331 mySMESHGUI->ResetState();
332 mySelectionMgr->clearFilters();
338 \brief SLOT called when "Help" button pressed shows "Help" page
340 void SMESHGUI_GroupOpDlg::onHelp()
342 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
344 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
348 platform = "winapplication";
350 platform = "application";
352 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
353 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
354 arg(app->resourceMgr()->stringValue("ExternalBrowser",
356 arg(myHelpFileName));
361 \brief Gets list of currently selected groups from selection manager
362 \param theOutList out list of groups
363 \param theOutNames out list of group of group names
364 \return TRUE if operation theOutList is not empty, FALSE otherwise
366 bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList<SMESH::SMESH_GroupBase_var>& theOutList,
367 QStringList& theOutNames )
374 SALOME_ListIO aListIO;
375 mySelectionMgr->selectedObjects( aListIO );
376 SALOME_ListIteratorOfListIO anIter ( aListIO );
377 for ( ; anIter.More(); anIter.Next())
379 SMESH::SMESH_GroupBase_var aGroup =
380 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
381 if ( !aGroup->_is_nil())
383 theOutList.append( aGroup );
384 theOutNames.append( aGroup->GetName() );
388 return theOutList.count() > 0;
392 \brief Converts QT-list of group to the list acceptable by IDL interface
393 \param theIn input list
394 \return list acceptable by IDL interface
396 SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert(
397 const QList<SMESH::SMESH_GroupBase_var>& theIn )
399 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
400 aList->length( theIn.count() );
402 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = theIn.begin();
403 for ( int i = 0; anIter != theIn.end(); ++anIter, ++i )
404 aList[ i ] = *anIter;
406 return aList._retn();
410 \brief Get color to be assigned to group
411 \return color to be assigned to group
413 SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
415 QColor aQColor = myColorBtn->color();
417 SALOMEDS::Color aColor;
418 aColor.R = (float)aQColor.red() / 255.0;
419 aColor.G = (float)aQColor.green() / 255.0;
420 aColor.B = (float)aQColor.blue() / 255.0;
426 \brief SLOT, called when selection is changed. Current implementation does
427 nothing. The method should be redefined in derived classes to update
428 corresponding GUI controls
430 void SMESHGUI_GroupOpDlg::onSelectionDone()
435 \brief Calls onSelectionDone() and setVisible() method of base class
436 \param visible the visible state of the dialog
438 void SMESHGUI_GroupOpDlg::setVisible( bool visible )
443 resize( minimumSizeHint().width(), sizeHint().height() );
445 QDialog::setVisible( visible );
449 \brief SLOT called when dialog must be deativated
451 void SMESHGUI_GroupOpDlg::onDeactivate()
454 mySelectionMgr->clearFilters();
458 \brief Event filter updates selection mode and selection filter. This virtual method
459 is redefined from the base class it is called when dialog obtains input focus
461 void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
463 mySMESHGUI->EmitSignalDeactivateDialog();
465 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
466 aViewWindow->SetSelectionMode(ActorSelection);
467 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
471 \brief Provides reaction on close event, closes the dialog box
473 void SMESHGUI_GroupOpDlg::closeEvent(QCloseEvent*)
479 \brief Resets state of the dialog, initializes its fields with default value, etc.
480 Usually called by onApply() slot to reinitialize dialog fields. This virtual method
481 should be redefined in derived class to update its own fileds
483 void SMESHGUI_GroupOpDlg::reset()
485 myNameEdit->setText("");
486 myNameEdit->setFocus();
490 \brief Gets name of group to be created
491 \return name of group to be created
494 QString SMESHGUI_GroupOpDlg::getName() const
496 return myNameEdit->text();
500 \brief Sets name of group to be created
501 \param theName name of group to be created
504 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
506 myNameEdit->setText( theName );
510 \brief Provides reaction on
\93F1
\94 button pressing
511 \param e key press event
513 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
515 QDialog::keyPressEvent( e );
516 if ( e->isAccepted() )
519 if ( e->key() == Qt::Key_F1 ) {
526 \brief This virtual slot does nothing and should be redefined in derived classes
527 \return return false;
529 bool SMESHGUI_GroupOpDlg::onApply()
535 \brief Set value of the flag indicating that the dialog is
536 accepted by Apply & Close button
537 \param theFlag value of the flag
538 \sa isApplyAndClose()
540 void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
542 myIsApplyAndClose = theFlag;
546 \brief Get value of the flag indicating that the dialog is
547 accepted by Apply & Close button
548 \return value of the flag
549 \sa setApplyAndClose()
551 bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
553 return myIsApplyAndClose;
556 // === === === === === === === === === === === === === === === === === === === === ===
560 \param theModule module
562 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
563 : SMESHGUI_GroupOpDlg( theModule )
565 setWindowTitle(tr("UNION_OF_GROUPS"));
566 setHelpFileName( "using_operations_on_groups_page.html#union_anchor" );
568 QGroupBox* anArgGrp = getArgGrp();
569 myListWg = new QListWidget( anArgGrp );
571 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
572 aLay->addWidget( myListWg );
578 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
583 \brief This virtual method redefined from the base class resets state
584 of the dialog, initializes its fields with default value, etc.
586 void SMESHGUI_UnionGroupsDlg::reset()
588 SMESHGUI_GroupOpDlg::reset();
594 \brief SLOT called when apply button is pressed performs operation
595 \return TRUE if operation has been completed successfully, FALSE otherwise
597 bool SMESHGUI_UnionGroupsDlg::onApply()
599 if ( getSMESHGUI()->isActiveStudyLocked())
602 // Verify validity of group name
603 if ( getName() == "" )
605 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
606 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
610 if ( !isValid( myGroups ) )
613 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
614 QString aName = getName();
617 QStringList anEntryList;
620 SMESH::ListOfGroups_var aList = convert( myGroups );
621 SMESH::SMESH_Group_var aNewGrp =
622 aMesh->UnionListOfGroups( aList, aName.toLatin1().constData() );
623 if ( !CORBA::is_nil( aNewGrp ) )
625 aNewGrp->SetColor( getColor() );
626 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
627 anEntryList.append( aSObject->GetID().c_str() );
638 SMESHGUI::Modified();
639 getSMESHGUI()->updateObjBrowser(true);
641 if( LightApp_Application* anApp =
642 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
643 anApp->browseObjects( anEntryList, isApplyAndClose() );
648 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
649 tr("SMESH_OPERATION_FAILED"));
655 \brief SLOT, called when selection is changed, updates corresponding GUI controls
657 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
660 getSelectedGroups( myGroups, aNames );
662 myListWg->addItems( aNames );
665 // === === === === === === === === === === === === === === === === === === === === ===
669 \param theModule module
671 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
672 : SMESHGUI_GroupOpDlg( theModule )
674 setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
675 setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
677 QGroupBox* anArgGrp = getArgGrp();
678 myListWg = new QListWidget( anArgGrp );
680 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
681 aLay->addWidget( myListWg );
687 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
692 \brief This virtual method redefined from the base class resets state
693 of the dialog, initializes its fields with default value, etc.
695 void SMESHGUI_IntersectGroupsDlg::reset()
697 SMESHGUI_GroupOpDlg::reset();
703 \brief SLOT called when apply button is pressed performs operation
704 \return TRUE if operation has been completed successfully, FALSE otherwise
706 bool SMESHGUI_IntersectGroupsDlg::onApply()
708 if ( getSMESHGUI()->isActiveStudyLocked())
711 // Verify validity of group name
712 if ( getName() == "" )
714 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
715 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
719 if ( !isValid( myGroups ) )
722 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
723 QString aName = getName();
726 QStringList anEntryList;
729 SMESH::ListOfGroups_var aList = convert( myGroups );
730 SMESH::SMESH_Group_var aNewGrp =
731 aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() );
732 if ( !CORBA::is_nil( aNewGrp ) )
734 aNewGrp->SetColor( getColor() );
735 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
736 anEntryList.append( aSObject->GetID().c_str() );
747 SMESHGUI::Modified();
748 getSMESHGUI()->updateObjBrowser(true);
750 if( LightApp_Application* anApp =
751 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
752 anApp->browseObjects( anEntryList, isApplyAndClose() );
757 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
758 tr("SMESH_OPERATION_FAILED"));
764 \brief SLOT, called when selection is changed, updates corresponding GUI controls
766 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
769 getSelectedGroups( myGroups, aNames );
771 myListWg->addItems( aNames );
774 // === === === === === === === === === === === === === === === === === === === === ===
778 \param theModule module
780 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
781 : SMESHGUI_GroupOpDlg( theModule )
783 setWindowTitle(tr("CUT_OF_GROUPS"));
784 setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
786 QGroupBox* anArgGrp = getArgGrp();
788 QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
791 QFrame* aFrame1 = new QFrame( anArgGrp );
792 QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
793 aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
794 myBtn1 = new QPushButton( aFrame1 );
795 myBtn1->setIcon(aPix);
796 myListWg1 = new QListWidget( aFrame1 );
798 QGridLayout* aLay1 = new QGridLayout( aFrame1 );
799 aLay1->setSpacing( SPACING );
800 aLay1->addWidget( aLbl1, 0, 0 );
801 aLay1->addWidget( myBtn1, 0, 1 );
802 aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
803 //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
804 //aLay1->addItem( aHSpacer1, 0, 2 );
808 QFrame* aFrame2 = new QFrame( anArgGrp );
809 QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
810 aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
811 myBtn2 = new QPushButton( aFrame2 );
812 myBtn2->setIcon(aPix);
813 myListWg2 = new QListWidget( aFrame2 );
815 QGridLayout* aLay2 = new QGridLayout( aFrame2 );
816 aLay2->setSpacing( SPACING );
817 aLay2->addWidget( aLbl2, 0, 0 );
818 aLay2->addWidget( myBtn2, 0, 1 );
819 aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
820 //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
821 //aLay2->addItem( aHSpacer2, 0, 2 );
823 // create button group
825 QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
826 aGrp->addButton( myBtn1, 0 );
827 aGrp->addButton( myBtn2, 1 );
828 myBtn1->setCheckable( true );
829 myBtn2->setCheckable( true );
830 aGrp->setExclusive( true );
831 myBtn1->setChecked( true );
834 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
835 aLay->setSpacing( SPACING );
836 aLay->addWidget( aFrame1 );
837 aLay->addWidget( aFrame2 );
843 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
848 \brief This virtual method redefined from the base class resets state
849 of the dialog, initializes its fields with default value, etc.
851 void SMESHGUI_CutGroupsDlg::reset()
853 SMESHGUI_GroupOpDlg::reset();
863 \brief SLOT called when apply button is pressed performs operation
864 \return TRUE if operation has been completed successfully, FALSE otherwise
866 bool SMESHGUI_CutGroupsDlg::onApply()
868 if ( getSMESHGUI()->isActiveStudyLocked())
871 // Verify validity of group name
872 if ( getName() == "" )
874 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
875 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
879 if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
881 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
882 SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
886 QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
887 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
888 for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
889 aGroups.append( *anIter );
891 if ( !isValid( aGroups ) )
894 SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
895 QString aName = getName();
898 QStringList anEntryList;
901 SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
902 SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
903 SMESH::SMESH_Group_var aNewGrp =
904 aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() );
905 if ( !CORBA::is_nil( aNewGrp ) )
907 aNewGrp->SetColor( getColor() );
908 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
909 anEntryList.append( aSObject->GetID().c_str() );
920 SMESHGUI::Modified();
921 getSMESHGUI()->updateObjBrowser(true);
923 if( LightApp_Application* anApp =
924 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
925 anApp->browseObjects( anEntryList, isApplyAndClose() );
930 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
931 tr("SMESH_OPERATION_FAILED"));
937 \brief SLOT, called when selection is changed, updates corresponding GUI controls
939 void SMESHGUI_CutGroupsDlg::onSelectionDone()
942 if ( myBtn2->isChecked() )
944 getSelectedGroups( myGroups2, aNames );
946 myListWg2->addItems( aNames );
950 getSelectedGroups( myGroups1, aNames );
952 myListWg1->addItems( aNames );
956 // === === === === === === === === === === === === === === === === === === === === ===
960 \param theModule module
962 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
963 : SMESHGUI_GroupOpDlg( theModule )
965 setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
966 setHelpFileName( "creating_groups_page.html#gui_create_dim_group" );
968 QGroupBox* anArgGrp = getArgGrp();
970 QLabel* aLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
972 myCombo = new QComboBox( anArgGrp );
973 static QStringList anItems;
974 if ( anItems.isEmpty() )
976 anItems.append( tr( "NODE" ) );
977 anItems.append( tr( "EDGE" ) );
978 anItems.append( tr( "FACE" ) );
979 anItems.append( tr( "VOLUME" ) );
981 myCombo->addItems( anItems );
982 myCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
984 myListWg = new QListWidget( anArgGrp );
987 QGridLayout* aLay = new QGridLayout( anArgGrp );
988 aLay->setSpacing( SPACING );
989 aLay->addWidget( aLbl, 0, 0 );
990 aLay->addWidget( myCombo, 0, 1 );
991 aLay->addWidget( myListWg, 1, 0, 1, 2 );
997 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
1002 \brief This virtual method redefined from the base class resets state
1003 of the dialog, initializes its fields with default value, etc.
1005 void SMESHGUI_DimGroupDlg::reset()
1007 SMESHGUI_GroupOpDlg::reset();
1013 \brief Gets elements type
1014 \return elements type
1015 \sa setElementType()
1017 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
1019 return (SMESH::ElementType)( myCombo->currentIndex() + 1 );
1023 \brief Sets elements type
1024 \param theElemType elements type
1025 \sa getElementType()
1027 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
1029 myCombo->setCurrentIndex( theElemType - 1 );
1033 \brief SLOT called when apply button is pressed performs operation
1034 \return TRUE if operation has been completed successfully, FALSE otherwise
1036 bool SMESHGUI_DimGroupDlg::onApply()
1038 if ( getSMESHGUI()->isActiveStudyLocked())
1041 // Verify validity of group name
1042 if ( getName() == "" )
1044 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
1045 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
1049 if ( !isValid( myGroups ) )
1052 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1053 QString aName = getName();
1056 QStringList anEntryList;
1059 SMESH::ListOfGroups_var aList = convert( myGroups );
1060 SMESH::ElementType anElemType = getElementType();
1061 SMESH::SMESH_Group_var aNewGrp =
1062 aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData() );
1063 if ( !CORBA::is_nil( aNewGrp ) )
1065 aNewGrp->SetColor( getColor() );
1066 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
1067 anEntryList.append( aSObject->GetID().c_str() );
1078 SMESHGUI::Modified();
1079 getSMESHGUI()->updateObjBrowser(true);
1081 if( LightApp_Application* anApp =
1082 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1083 anApp->browseObjects( anEntryList, isApplyAndClose() );
1088 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1089 tr("SMESH_OPERATION_FAILED"));
1095 \brief SLOT, called when selection is changed, updates corresponding GUI controls
1097 void SMESHGUI_DimGroupDlg::onSelectionDone()
1100 getSelectedGroups( myGroups, aNames );
1102 myListWg->addItems( aNames );