1 // Copyright (C) 2007-2013 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(reject()));
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(reject()));
233 // set selection mode
234 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
235 aViewWindow->SetSelectionMode(ActorSelection);
236 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::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 dialog is closed
325 void SMESHGUI_GroupOpDlg::reject()
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 (SMESH::GROUP));
471 \brief Resets state of the dialog, initializes its fields with default value, etc.
472 Usually called by onApply() slot to reinitialize dialog fields. This virtual method
473 should be redefined in derived class to update its own fileds
475 void SMESHGUI_GroupOpDlg::reset()
477 myNameEdit->setText("");
478 myNameEdit->setFocus();
482 \brief Gets name of group to be created
483 \return name of group to be created
486 QString SMESHGUI_GroupOpDlg::getName() const
488 return myNameEdit->text();
492 \brief Sets name of group to be created
493 \param theName name of group to be created
496 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
498 myNameEdit->setText( theName );
502 \brief Provides reaction on
\93F1
\94 button pressing
503 \param e key press event
505 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
507 QDialog::keyPressEvent( e );
508 if ( e->isAccepted() )
511 if ( e->key() == Qt::Key_F1 ) {
518 \brief This virtual slot does nothing and should be redefined in derived classes
519 \return return false;
521 bool SMESHGUI_GroupOpDlg::onApply()
527 \brief Set value of the flag indicating that the dialog is
528 accepted by Apply & Close button
529 \param theFlag value of the flag
530 \sa isApplyAndClose()
532 void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
534 myIsApplyAndClose = theFlag;
538 \brief Get value of the flag indicating that the dialog is
539 accepted by Apply & Close button
540 \return value of the flag
541 \sa setApplyAndClose()
543 bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
545 return myIsApplyAndClose;
548 // === === === === === === === === === === === === === === === === === === === === ===
552 \param theModule module
554 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
555 : SMESHGUI_GroupOpDlg( theModule )
557 setWindowTitle(tr("UNION_OF_GROUPS"));
558 setHelpFileName( "using_operations_on_groups_page.html#union_anchor" );
560 QGroupBox* anArgGrp = getArgGrp();
561 myListWg = new QListWidget( anArgGrp );
563 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
564 aLay->addWidget( myListWg );
570 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
575 \brief This virtual method redefined from the base class resets state
576 of the dialog, initializes its fields with default value, etc.
578 void SMESHGUI_UnionGroupsDlg::reset()
580 SMESHGUI_GroupOpDlg::reset();
586 \brief SLOT called when apply button is pressed performs operation
587 \return TRUE if operation has been completed successfully, FALSE otherwise
589 bool SMESHGUI_UnionGroupsDlg::onApply()
591 if ( getSMESHGUI()->isActiveStudyLocked())
594 // Verify validity of group name
595 if ( getName() == "" )
597 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
598 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
602 if ( !isValid( myGroups ) )
605 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
606 QString aName = getName();
609 QStringList anEntryList;
612 SMESH::ListOfGroups_var aList = convert( myGroups );
613 SMESH::SMESH_Group_var aNewGrp =
614 aMesh->UnionListOfGroups( aList, aName.toLatin1().constData() );
615 if ( !CORBA::is_nil( aNewGrp ) )
617 aNewGrp->SetColor( getColor() );
618 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
619 anEntryList.append( aSObject->GetID().c_str() );
630 SMESHGUI::Modified();
631 getSMESHGUI()->updateObjBrowser(true);
633 if( LightApp_Application* anApp =
634 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
635 anApp->browseObjects( anEntryList, isApplyAndClose() );
640 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
641 tr("SMESH_OPERATION_FAILED"));
647 \brief SLOT, called when selection is changed, updates corresponding GUI controls
649 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
652 getSelectedGroups( myGroups, aNames );
654 myListWg->addItems( aNames );
657 // === === === === === === === === === === === === === === === === === === === === ===
661 \param theModule module
663 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
664 : SMESHGUI_GroupOpDlg( theModule )
666 setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
667 setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
669 QGroupBox* anArgGrp = getArgGrp();
670 myListWg = new QListWidget( anArgGrp );
672 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
673 aLay->addWidget( myListWg );
679 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
684 \brief This virtual method redefined from the base class resets state
685 of the dialog, initializes its fields with default value, etc.
687 void SMESHGUI_IntersectGroupsDlg::reset()
689 SMESHGUI_GroupOpDlg::reset();
695 \brief SLOT called when apply button is pressed performs operation
696 \return TRUE if operation has been completed successfully, FALSE otherwise
698 bool SMESHGUI_IntersectGroupsDlg::onApply()
700 if ( getSMESHGUI()->isActiveStudyLocked())
703 // Verify validity of group name
704 if ( getName() == "" )
706 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
707 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
711 if ( !isValid( myGroups ) )
714 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
715 QString aName = getName();
718 QStringList anEntryList;
721 SMESH::ListOfGroups_var aList = convert( myGroups );
722 SMESH::SMESH_Group_var aNewGrp =
723 aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() );
724 if ( !CORBA::is_nil( aNewGrp ) )
726 aNewGrp->SetColor( getColor() );
727 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
728 anEntryList.append( aSObject->GetID().c_str() );
739 SMESHGUI::Modified();
740 getSMESHGUI()->updateObjBrowser(true);
742 if( LightApp_Application* anApp =
743 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
744 anApp->browseObjects( anEntryList, isApplyAndClose() );
749 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
750 tr("SMESH_OPERATION_FAILED"));
756 \brief SLOT, called when selection is changed, updates corresponding GUI controls
758 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
761 getSelectedGroups( myGroups, aNames );
763 myListWg->addItems( aNames );
766 // === === === === === === === === === === === === === === === === === === === === ===
770 \param theModule module
772 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
773 : SMESHGUI_GroupOpDlg( theModule )
775 setWindowTitle(tr("CUT_OF_GROUPS"));
776 setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
778 QGroupBox* anArgGrp = getArgGrp();
780 QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
783 QFrame* aFrame1 = new QFrame( anArgGrp );
784 QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
785 aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
786 myBtn1 = new QPushButton( aFrame1 );
787 myBtn1->setIcon(aPix);
788 myListWg1 = new QListWidget( aFrame1 );
790 QGridLayout* aLay1 = new QGridLayout( aFrame1 );
791 aLay1->setSpacing( SPACING );
792 aLay1->addWidget( aLbl1, 0, 0 );
793 aLay1->addWidget( myBtn1, 0, 1 );
794 aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
795 //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
796 //aLay1->addItem( aHSpacer1, 0, 2 );
800 QFrame* aFrame2 = new QFrame( anArgGrp );
801 QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
802 aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
803 myBtn2 = new QPushButton( aFrame2 );
804 myBtn2->setIcon(aPix);
805 myListWg2 = new QListWidget( aFrame2 );
807 QGridLayout* aLay2 = new QGridLayout( aFrame2 );
808 aLay2->setSpacing( SPACING );
809 aLay2->addWidget( aLbl2, 0, 0 );
810 aLay2->addWidget( myBtn2, 0, 1 );
811 aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
812 //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
813 //aLay2->addItem( aHSpacer2, 0, 2 );
815 // create button group
817 QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
818 aGrp->addButton( myBtn1, 0 );
819 aGrp->addButton( myBtn2, 1 );
820 myBtn1->setCheckable( true );
821 myBtn2->setCheckable( true );
822 aGrp->setExclusive( true );
823 myBtn1->setChecked( true );
826 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
827 aLay->setSpacing( SPACING );
828 aLay->addWidget( aFrame1 );
829 aLay->addWidget( aFrame2 );
835 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
840 \brief This virtual method redefined from the base class resets state
841 of the dialog, initializes its fields with default value, etc.
843 void SMESHGUI_CutGroupsDlg::reset()
845 SMESHGUI_GroupOpDlg::reset();
855 \brief SLOT called when apply button is pressed performs operation
856 \return TRUE if operation has been completed successfully, FALSE otherwise
858 bool SMESHGUI_CutGroupsDlg::onApply()
860 if ( getSMESHGUI()->isActiveStudyLocked())
863 // Verify validity of group name
864 if ( getName() == "" )
866 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
867 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
871 if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
873 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
874 SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
878 QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
879 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
880 for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
881 aGroups.append( *anIter );
883 if ( !isValid( aGroups ) )
886 SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
887 QString aName = getName();
890 QStringList anEntryList;
893 SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
894 SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
895 SMESH::SMESH_Group_var aNewGrp =
896 aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() );
897 if ( !CORBA::is_nil( aNewGrp ) )
899 aNewGrp->SetColor( getColor() );
900 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
901 anEntryList.append( aSObject->GetID().c_str() );
912 SMESHGUI::Modified();
913 getSMESHGUI()->updateObjBrowser(true);
915 if( LightApp_Application* anApp =
916 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
917 anApp->browseObjects( anEntryList, isApplyAndClose() );
922 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
923 tr("SMESH_OPERATION_FAILED"));
929 \brief SLOT, called when selection is changed, updates corresponding GUI controls
931 void SMESHGUI_CutGroupsDlg::onSelectionDone()
934 if ( myBtn2->isChecked() )
936 getSelectedGroups( myGroups2, aNames );
938 myListWg2->addItems( aNames );
942 getSelectedGroups( myGroups1, aNames );
944 myListWg1->addItems( aNames );
948 // === === === === === === === === === === === === === === === === === === === === ===
952 \param theModule module
954 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
955 : SMESHGUI_GroupOpDlg( theModule )
957 setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
958 setHelpFileName( "group_of_underlying_elements_page.html" );
960 QGroupBox* anArgGrp = getArgGrp();
962 QLabel* aLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
964 myCombo = new QComboBox( anArgGrp );
965 static QStringList anItems;
966 if ( anItems.isEmpty() )
968 anItems.append( tr( "NODE" ) );
969 anItems.append( tr( "EDGE" ) );
970 anItems.append( tr( "FACE" ) );
971 anItems.append( tr( "VOLUME" ) );
973 myCombo->addItems( anItems );
974 myCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
976 myListWg = new QListWidget( anArgGrp );
979 QGridLayout* aLay = new QGridLayout( anArgGrp );
980 aLay->setSpacing( SPACING );
981 aLay->addWidget( aLbl, 0, 0 );
982 aLay->addWidget( myCombo, 0, 1 );
983 aLay->addWidget( myListWg, 1, 0, 1, 2 );
989 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
994 \brief This virtual method redefined from the base class resets state
995 of the dialog, initializes its fields with default value, etc.
997 void SMESHGUI_DimGroupDlg::reset()
999 SMESHGUI_GroupOpDlg::reset();
1005 \brief Gets elements type
1006 \return elements type
1007 \sa setElementType()
1009 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
1011 return (SMESH::ElementType)( myCombo->currentIndex() + 1 );
1015 \brief Sets elements type
1016 \param theElemType elements type
1017 \sa getElementType()
1019 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
1021 myCombo->setCurrentIndex( theElemType - 1 );
1025 \brief SLOT called when apply button is pressed performs operation
1026 \return TRUE if operation has been completed successfully, FALSE otherwise
1028 bool SMESHGUI_DimGroupDlg::onApply()
1030 if ( getSMESHGUI()->isActiveStudyLocked())
1033 // Verify validity of group name
1034 if ( getName() == "" )
1036 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
1037 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
1041 if ( !isValid( myGroups ) )
1044 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1045 QString aName = getName();
1048 QStringList anEntryList;
1051 SMESH::ListOfGroups_var aList = convert( myGroups );
1052 SMESH::ElementType anElemType = getElementType();
1053 SMESH::SMESH_Group_var aNewGrp =
1054 aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData() );
1055 if ( !CORBA::is_nil( aNewGrp ) )
1057 aNewGrp->SetColor( getColor() );
1058 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
1059 anEntryList.append( aSObject->GetID().c_str() );
1070 SMESHGUI::Modified();
1071 getSMESHGUI()->updateObjBrowser(true);
1073 if( LightApp_Application* anApp =
1074 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1075 anApp->browseObjects( anEntryList, isApplyAndClose() );
1080 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1081 tr("SMESH_OPERATION_FAILED"));
1087 \brief SLOT, called when selection is changed, updates corresponding GUI controls
1089 void SMESHGUI_DimGroupDlg::onSelectionDone()
1092 getSelectedGroups( myGroups, aNames );
1094 myListWg->addItems( aNames );