1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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"
33 #include "SMESH_TypeFilter.hxx"
35 #include <LightApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <QtxColorButton.h>
38 #include <SALOMEDSClient_SObject.hxx>
39 #include <SALOME_ListIO.hxx>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SVTK_Selection.h>
46 #include <SVTK_ViewWindow.h>
49 #include <QButtonGroup>
52 #include <QGridLayout>
54 #include <QHBoxLayout>
58 #include <QListWidget>
59 #include <QPushButton>
60 #include <QVBoxLayout>
66 * Class : SMESHGUI_GroupOpDlg
67 * Description : Perform boolean operations on groups
72 \param theModule pointer on module instance
74 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule )
75 : QDialog( SMESH::GetDesktop( theModule ) ),
76 mySMESHGUI( theModule ),
77 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
78 myIsApplyAndClose( false )
82 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
84 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
85 aDlgLay->setMargin(MARGIN);
86 aDlgLay->setSpacing(SPACING);
88 QWidget* aMainFrame = createMainFrame (this);
89 QWidget* aBtnFrame = createButtonFrame(this);
91 aDlgLay->addWidget(aMainFrame);
92 aDlgLay->addWidget(aBtnFrame);
98 \brief Creates frame containing dialog's input fields
99 \param theParent parent widget
100 \return pointer on created widget
102 QWidget* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent )
104 QWidget* aMainGrp = new QWidget(theParent);
105 QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
107 aLay->setSpacing(SPACING);
109 // ------------------------------------------------------
110 QGroupBox* aNameGrp = new QGroupBox(tr("RESULT"), aMainGrp);
111 QHBoxLayout* aNameGrpLayout = new QHBoxLayout(aNameGrp);
112 aNameGrpLayout->setMargin(MARGIN);
113 aNameGrpLayout->setSpacing(SPACING);
115 QLabel* aNameLab = new QLabel(tr("RESULT_NAME"), aNameGrp);
116 myNameEdit = new QLineEdit(aNameGrp);
118 aNameGrpLayout->addWidget(aNameLab);
119 aNameGrpLayout->addWidget(myNameEdit);
121 // ------------------------------------------------------
122 myArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp);
125 // ------------------------------------------------------
127 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
128 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
129 aColorBoxLayout->setMargin(MARGIN);
130 aColorBoxLayout->setSpacing(SPACING);
132 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
133 myColorBtn = new QtxColorButton(aColorBox);
134 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
135 myColorBtn->sizePolicy().verticalPolicy() );
137 aColorBoxLayout->addWidget(aColorLab);
138 aColorBoxLayout->addWidget(myColorBtn);
140 // ------------------------------------------------------
141 aLay->addWidget( aNameGrp );
142 aLay->addWidget( myArgGrp );
143 aLay->addWidget( aColorBox );
149 \brief Gets pointer on arguments group box
150 \return pointer on arguments group box
152 QGroupBox* SMESHGUI_GroupOpDlg::getArgGrp() const
158 \brief Sets help file name
159 \param theFName help file name
161 void SMESHGUI_GroupOpDlg::setHelpFileName( const QString& theFName )
163 myHelpFileName = theFName;
167 \brief Gets pointer to the module instance
168 \return pointer to the module instance
170 SMESHGUI* SMESHGUI_GroupOpDlg::getSMESHGUI() const
176 \brief Create frame containing buttons
177 \param theParent parent widget
178 \return pointer to the created frame
180 QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
182 QGroupBox* aFrame = new QGroupBox(theParent);
184 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
185 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
186 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
187 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
189 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
190 aLay->setMargin(MARGIN);
191 aLay->setSpacing(SPACING);
193 aLay->addWidget(myOkBtn);
194 aLay->addSpacing(10);
195 aLay->addWidget(myApplyBtn);
196 aLay->addSpacing(10);
198 aLay->addWidget(myCloseBtn);
199 aLay->addWidget(myHelpBtn);
201 // connect signals and slots
202 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
203 connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
204 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
205 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
213 SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg()
218 \brief Init dialog fields, connect signals and slots, show dialog
220 void SMESHGUI_GroupOpDlg::Init()
222 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
224 // selection and SMESHGUI
225 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
226 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
227 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
229 // set selection mode
230 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
231 aViewWindow->SetSelectionMode(ActorSelection);
232 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
236 \brief Validate list of groups used for operation. Checks whether they corresponds
237 to the same face and have one type
238 \param theListGrp input list of groups
239 \return TRUE if groups are valid, FALSE otherwise
241 bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theListGrp )
243 if ( theListGrp.isEmpty() )
245 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
246 tr("INCORRECT_ARGUMENTS") );
250 int aMeshId = -1, aGrpType = -1;
251 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter;
252 for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter )
254 SMESH::SMESH_GroupBase_var aGrp = *anIter;
255 if ( CORBA::is_nil( aGrp ) )
256 continue; // nonsence
258 SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh();
259 if ( CORBA::is_nil( aMesh ) )
263 int aCurrId = aMesh->GetId();
268 if ( aMeshId != aCurrId )
270 aMeshId = -1; // different meshes
276 int aCurrType = aGrp->GetType();
277 if ( aGrpType == -1 )
278 aGrpType = aCurrType;
281 if ( aGrpType != aCurrType )
283 aGrpType = -1; // different types
292 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
297 if ( aGrpType == -1 )
299 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
308 \brief SLOT called when "Ok" button pressed performs operation and closes dialog box
310 void SMESHGUI_GroupOpDlg::onOk()
312 SUIT_OverrideCursor oc;
313 setIsApplyAndClose( true );
316 setIsApplyAndClose( false );
320 \brief SLOT called when dialog is closed
322 void SMESHGUI_GroupOpDlg::reject()
324 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
325 aViewWindow->SetSelectionMode(ActorSelection);
326 disconnect( mySelectionMgr, 0, this, 0 );
327 disconnect( mySMESHGUI, 0, this, 0 );
328 mySMESHGUI->ResetState();
329 mySelectionMgr->clearFilters();
335 \brief SLOT called when "Help" button pressed shows "Help" page
337 void SMESHGUI_GroupOpDlg::onHelp()
339 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
341 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
345 platform = "winapplication";
347 platform = "application";
349 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
350 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
351 arg(app->resourceMgr()->stringValue("ExternalBrowser",
353 arg(myHelpFileName));
358 \brief Gets list of currently selected groups from selection manager
359 \param theOutList out list of groups
360 \param theOutNames out list of group of group names
361 \return TRUE if operation theOutList is not empty, FALSE otherwise
363 bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList<SMESH::SMESH_GroupBase_var>& theOutList,
364 QStringList& theOutNames )
371 SALOME_ListIO aListIO;
372 mySelectionMgr->selectedObjects( aListIO );
373 SALOME_ListIteratorOfListIO anIter ( aListIO );
374 for ( ; anIter.More(); anIter.Next())
376 SMESH::SMESH_GroupBase_var aGroup =
377 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
378 if ( !aGroup->_is_nil())
380 theOutList.append( aGroup );
381 theOutNames.append( aGroup->GetName() );
385 return theOutList.count() > 0;
389 \brief Converts QT-list of group to the list acceptable by IDL interface
390 \param theIn input list
391 \return list acceptable by IDL interface
393 SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert(
394 const QList<SMESH::SMESH_GroupBase_var>& theIn )
396 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
397 aList->length( theIn.count() );
399 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = theIn.begin();
400 for ( int i = 0; anIter != theIn.end(); ++anIter, ++i )
401 aList[ i ] = *anIter;
403 return aList._retn();
407 \brief Get color to be assigned to group
408 \return color to be assigned to group
410 SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
412 QColor aQColor = myColorBtn->color();
414 SALOMEDS::Color aColor;
415 aColor.R = (float)aQColor.red() / 255.0;
416 aColor.G = (float)aQColor.green() / 255.0;
417 aColor.B = (float)aQColor.blue() / 255.0;
423 \brief SLOT, called when selection is changed. Current implementation does
424 nothing. The method should be redefined in derived classes to update
425 corresponding GUI controls
427 void SMESHGUI_GroupOpDlg::onSelectionDone()
432 \brief Calls onSelectionDone() and setVisible() method of base class
433 \param visible the visible state of the dialog
435 void SMESHGUI_GroupOpDlg::setVisible( bool visible )
440 resize( minimumSizeHint().width(), sizeHint().height() );
442 QDialog::setVisible( visible );
446 \brief SLOT called when dialog must be deativated
448 void SMESHGUI_GroupOpDlg::onDeactivate()
451 mySelectionMgr->clearFilters();
455 \brief Event filter updates selection mode and selection filter. This virtual method
456 is redefined from the base class it is called when dialog obtains input focus
458 void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
460 mySMESHGUI->EmitSignalDeactivateDialog();
462 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
463 aViewWindow->SetSelectionMode(ActorSelection);
464 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
468 \brief Resets state of the dialog, initializes its fields with default value, etc.
469 Usually called by onApply() slot to reinitialize dialog fields. This virtual method
470 should be redefined in derived class to update its own fileds
472 void SMESHGUI_GroupOpDlg::reset()
474 myNameEdit->setText("");
475 myNameEdit->setFocus();
479 \brief Gets name of group to be created
480 \return name of group to be created
483 QString SMESHGUI_GroupOpDlg::getName() const
485 return myNameEdit->text();
489 \brief Sets name of group to be created
490 \param theName name of group to be created
493 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
495 myNameEdit->setText( theName );
499 \brief Provides reaction on
\93F1
\94 button pressing
500 \param e key press event
502 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
504 QDialog::keyPressEvent( e );
505 if ( e->isAccepted() )
508 if ( e->key() == Qt::Key_F1 ) {
515 \brief This virtual slot does nothing and should be redefined in derived classes
516 \return return false;
518 bool SMESHGUI_GroupOpDlg::onApply()
524 \brief Set value of the flag indicating that the dialog is
525 accepted by Apply & Close button
526 \param theFlag value of the flag
527 \sa isApplyAndClose()
529 void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
531 myIsApplyAndClose = theFlag;
535 \brief Get value of the flag indicating that the dialog is
536 accepted by Apply & Close button
537 \return value of the flag
538 \sa setApplyAndClose()
540 bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
542 return myIsApplyAndClose;
545 // === === === === === === === === === === === === === === === === === === === === ===
549 \param theModule module
551 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
552 : SMESHGUI_GroupOpDlg( theModule )
554 setWindowTitle(tr("UNION_OF_GROUPS"));
555 setHelpFileName( "using_operations_on_groups_page.html#union_anchor" );
557 QGroupBox* anArgGrp = getArgGrp();
558 myListWg = new QListWidget( anArgGrp );
560 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
561 aLay->addWidget( myListWg );
567 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
572 \brief This virtual method redefined from the base class resets state
573 of the dialog, initializes its fields with default value, etc.
575 void SMESHGUI_UnionGroupsDlg::reset()
577 SMESHGUI_GroupOpDlg::reset();
583 \brief SLOT called when apply button is pressed performs operation
584 \return TRUE if operation has been completed successfully, FALSE otherwise
586 bool SMESHGUI_UnionGroupsDlg::onApply()
588 if ( getSMESHGUI()->isActiveStudyLocked())
591 // Verify validity of group name
592 if ( getName() == "" )
594 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
595 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
599 if ( !isValid( myGroups ) )
602 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
603 QString aName = getName();
606 QStringList anEntryList;
609 SMESH::ListOfGroups_var aList = convert( myGroups );
610 SMESH::SMESH_Group_var aNewGrp =
611 aMesh->UnionListOfGroups( aList, aName.toLatin1().constData() );
612 if ( !CORBA::is_nil( aNewGrp ) )
614 aNewGrp->SetColor( getColor() );
615 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
616 anEntryList.append( aSObject->GetID().c_str() );
627 SMESHGUI::Modified();
628 getSMESHGUI()->updateObjBrowser(true);
630 if( LightApp_Application* anApp =
631 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
632 anApp->browseObjects( anEntryList, isApplyAndClose() );
637 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
638 tr("SMESH_OPERATION_FAILED"));
644 \brief SLOT, called when selection is changed, updates corresponding GUI controls
646 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
649 getSelectedGroups( myGroups, aNames );
651 myListWg->addItems( aNames );
654 // === === === === === === === === === === === === === === === === === === === === ===
658 \param theModule module
660 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
661 : SMESHGUI_GroupOpDlg( theModule )
663 setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
664 setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
666 QGroupBox* anArgGrp = getArgGrp();
667 myListWg = new QListWidget( anArgGrp );
669 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
670 aLay->addWidget( myListWg );
676 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
681 \brief This virtual method redefined from the base class resets state
682 of the dialog, initializes its fields with default value, etc.
684 void SMESHGUI_IntersectGroupsDlg::reset()
686 SMESHGUI_GroupOpDlg::reset();
692 \brief SLOT called when apply button is pressed performs operation
693 \return TRUE if operation has been completed successfully, FALSE otherwise
695 bool SMESHGUI_IntersectGroupsDlg::onApply()
697 if ( getSMESHGUI()->isActiveStudyLocked())
700 // Verify validity of group name
701 if ( getName() == "" )
703 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
704 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
708 if ( !isValid( myGroups ) )
711 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
712 QString aName = getName();
715 QStringList anEntryList;
718 SMESH::ListOfGroups_var aList = convert( myGroups );
719 SMESH::SMESH_Group_var aNewGrp =
720 aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() );
721 if ( !CORBA::is_nil( aNewGrp ) )
723 aNewGrp->SetColor( getColor() );
724 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
725 anEntryList.append( aSObject->GetID().c_str() );
736 SMESHGUI::Modified();
737 getSMESHGUI()->updateObjBrowser(true);
739 if( LightApp_Application* anApp =
740 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
741 anApp->browseObjects( anEntryList, isApplyAndClose() );
746 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
747 tr("SMESH_OPERATION_FAILED"));
753 \brief SLOT, called when selection is changed, updates corresponding GUI controls
755 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
758 getSelectedGroups( myGroups, aNames );
760 myListWg->addItems( aNames );
763 // === === === === === === === === === === === === === === === === === === === === ===
767 \param theModule module
769 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
770 : SMESHGUI_GroupOpDlg( theModule )
772 setWindowTitle(tr("CUT_OF_GROUPS"));
773 setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
775 QGroupBox* anArgGrp = getArgGrp();
777 QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
780 QFrame* aFrame1 = new QFrame( anArgGrp );
781 QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
782 aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
783 myBtn1 = new QPushButton( aFrame1 );
784 myBtn1->setIcon(aPix);
785 myListWg1 = new QListWidget( aFrame1 );
787 QGridLayout* aLay1 = new QGridLayout( aFrame1 );
788 aLay1->setSpacing( SPACING );
789 aLay1->addWidget( aLbl1, 0, 0 );
790 aLay1->addWidget( myBtn1, 0, 1 );
791 aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
792 //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
793 //aLay1->addItem( aHSpacer1, 0, 2 );
797 QFrame* aFrame2 = new QFrame( anArgGrp );
798 QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
799 aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
800 myBtn2 = new QPushButton( aFrame2 );
801 myBtn2->setIcon(aPix);
802 myListWg2 = new QListWidget( aFrame2 );
804 QGridLayout* aLay2 = new QGridLayout( aFrame2 );
805 aLay2->setSpacing( SPACING );
806 aLay2->addWidget( aLbl2, 0, 0 );
807 aLay2->addWidget( myBtn2, 0, 1 );
808 aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
809 //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
810 //aLay2->addItem( aHSpacer2, 0, 2 );
812 // create button group
814 QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
815 aGrp->addButton( myBtn1, 0 );
816 aGrp->addButton( myBtn2, 1 );
817 myBtn1->setCheckable( true );
818 myBtn2->setCheckable( true );
819 aGrp->setExclusive( true );
820 myBtn1->setChecked( true );
823 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
824 aLay->setSpacing( SPACING );
825 aLay->addWidget( aFrame1 );
826 aLay->addWidget( aFrame2 );
832 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
837 \brief This virtual method redefined from the base class resets state
838 of the dialog, initializes its fields with default value, etc.
840 void SMESHGUI_CutGroupsDlg::reset()
842 SMESHGUI_GroupOpDlg::reset();
852 \brief SLOT called when apply button is pressed performs operation
853 \return TRUE if operation has been completed successfully, FALSE otherwise
855 bool SMESHGUI_CutGroupsDlg::onApply()
857 if ( getSMESHGUI()->isActiveStudyLocked())
860 // Verify validity of group name
861 if ( getName() == "" )
863 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
864 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
868 if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
870 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
871 SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
875 QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
876 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
877 for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
878 aGroups.append( *anIter );
880 if ( !isValid( aGroups ) )
883 SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
884 QString aName = getName();
887 QStringList anEntryList;
890 SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
891 SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
892 SMESH::SMESH_Group_var aNewGrp =
893 aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() );
894 if ( !CORBA::is_nil( aNewGrp ) )
896 aNewGrp->SetColor( getColor() );
897 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
898 anEntryList.append( aSObject->GetID().c_str() );
909 SMESHGUI::Modified();
910 getSMESHGUI()->updateObjBrowser(true);
912 if( LightApp_Application* anApp =
913 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
914 anApp->browseObjects( anEntryList, isApplyAndClose() );
919 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
920 tr("SMESH_OPERATION_FAILED"));
926 \brief SLOT, called when selection is changed, updates corresponding GUI controls
928 void SMESHGUI_CutGroupsDlg::onSelectionDone()
931 if ( myBtn2->isChecked() )
933 getSelectedGroups( myGroups2, aNames );
935 myListWg2->addItems( aNames );
939 getSelectedGroups( myGroups1, aNames );
941 myListWg1->addItems( aNames );
945 // === === === === === === === === === === === === === === === === === === === === ===
949 \param theModule module
951 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
952 : SMESHGUI_GroupOpDlg( theModule )
954 setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
955 setHelpFileName( "group_of_underlying_elements_page.html" );
957 QGroupBox* anArgGrp = getArgGrp();
959 QLabel* aTypeLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
961 myTypeCombo = new QComboBox( anArgGrp );
964 anItems.append( tr( "MESH_NODE" ) );
965 anItems.append( tr( "SMESH_EDGE" ) );
966 anItems.append( tr( "SMESH_FACE" ) );
967 anItems.append( tr( "SMESH_VOLUME" ) );
968 anItems.append( tr( "SMESH_ELEM0D" ) );
969 anItems.append( tr( "SMESH_BALL" ) );
971 myTypeCombo->addItems( anItems );
972 myTypeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
974 QLabel* aNbNoLbl = new QLabel( tr( "NUMBER_OF_COMMON_NODES" ), anArgGrp );
976 myNbNoCombo = new QComboBox( anArgGrp );
979 anItems.append( tr( "ALL" ) );
980 anItems.append( tr( "MAIN" ) );
981 anItems.append( tr( "AT_LEAST_ONE" ) );
982 anItems.append( tr( "MAJORITY" ) );
984 myNbNoCombo->addItems( anItems );
985 myNbNoCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
987 myListWg = new QListWidget( anArgGrp );
989 myUnderlOnlyChk = new QCheckBox( tr("UNDERLYING_ENTITIES_ONLY"), anArgGrp );
990 myUnderlOnlyChk->setChecked( false );
993 QGridLayout* aLay = new QGridLayout( anArgGrp );
994 aLay->setSpacing( SPACING );
995 aLay->addWidget( aTypeLbl, 0, 0 );
996 aLay->addWidget( myTypeCombo, 0, 1 );
997 aLay->addWidget( aNbNoLbl, 1, 0 );
998 aLay->addWidget( myNbNoCombo, 1, 1 );
999 aLay->addWidget( myListWg, 2, 0, 1, 2 );
1000 aLay->addWidget( myUnderlOnlyChk, 3, 0 );
1006 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
1011 \brief This virtual method redefined from the base class resets state
1012 of the dialog, initializes its fields with default value, etc.
1014 void SMESHGUI_DimGroupDlg::reset()
1016 SMESHGUI_GroupOpDlg::reset();
1022 \brief Gets elements type
1023 \return elements type
1024 \sa setElementType()
1026 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
1028 return (SMESH::ElementType)( myTypeCombo->currentIndex() + 1 );
1032 \brief Sets elements type
1033 \param theElemType elements type
1034 \sa getElementType()
1036 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
1038 myTypeCombo->setCurrentIndex( theElemType - 1 );
1042 \brief SLOT called when apply button is pressed performs operation
1043 \return TRUE if operation has been completed successfully, FALSE otherwise
1045 bool SMESHGUI_DimGroupDlg::onApply()
1047 if ( getSMESHGUI()->isActiveStudyLocked())
1050 // Verify validity of group name
1051 if ( getName() == "" )
1053 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
1054 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
1058 if ( !isValid( myGroups ) )
1061 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1062 QString aName = getName();
1065 QStringList anEntryList;
1068 SMESH::ListOfIDSources_var aList = new SMESH::ListOfIDSources();
1069 aList->length( myGroups.count() );
1070 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = myGroups.begin();
1071 for ( int i = 0; anIter != myGroups.end(); ++anIter, ++i )
1072 aList[ i ] = SMESH::SMESH_IDSource::_narrow( *anIter );
1074 SMESH::ElementType anElemType = getElementType();
1075 SMESH::NB_COMMON_NODES_ENUM aNbCoNodes =
1076 (SMESH::NB_COMMON_NODES_ENUM) myNbNoCombo->currentIndex();
1078 SMESH::SMESH_Group_var aNewGrp =
1079 aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData(),
1080 aNbCoNodes, myUnderlOnlyChk->isChecked() );
1081 if ( !CORBA::is_nil( aNewGrp ) )
1083 aNewGrp->SetColor( getColor() );
1084 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
1085 anEntryList.append( aSObject->GetID().c_str() );
1096 SMESHGUI::Modified();
1097 getSMESHGUI()->updateObjBrowser(true);
1099 if( LightApp_Application* anApp =
1100 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1101 anApp->browseObjects( anEntryList, isApplyAndClose() );
1106 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1107 tr("SMESH_OPERATION_FAILED"));
1113 \brief SLOT, called when selection is changed, updates corresponding GUI controls
1115 void SMESHGUI_DimGroupDlg::onSelectionDone()
1118 getSelectedGroups( myGroups, aNames );
1120 myListWg->addItems( aNames );