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()));
228 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT(onOpenView()));
229 connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT(onCloseView()));
231 // set selection mode
232 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
233 aViewWindow->SetSelectionMode(ActorSelection);
234 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
238 \brief Validate list of groups used for operation. Checks whether they corresponds
239 to the same face and have one type
240 \param theListGrp input list of groups
241 \return TRUE if groups are valid, FALSE otherwise
243 bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theListGrp )
245 if ( theListGrp.isEmpty() )
247 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
248 tr("INCORRECT_ARGUMENTS") );
252 int aMeshId = -1, aGrpType = -1;
253 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter;
254 for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter )
256 SMESH::SMESH_GroupBase_var aGrp = *anIter;
257 if ( CORBA::is_nil( aGrp ) )
258 continue; // nonsence
260 SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh();
261 if ( CORBA::is_nil( aMesh ) )
265 int aCurrId = aMesh->GetId();
270 if ( aMeshId != aCurrId )
272 aMeshId = -1; // different meshes
278 int aCurrType = aGrp->GetType();
279 if ( aGrpType == -1 )
280 aGrpType = aCurrType;
283 if ( aGrpType != aCurrType )
285 aGrpType = -1; // different types
294 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
299 if ( aGrpType == -1 )
301 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
310 \brief SLOT called when "Ok" button pressed performs operation and closes dialog box
312 void SMESHGUI_GroupOpDlg::onOk()
314 SUIT_OverrideCursor oc;
315 setIsApplyAndClose( true );
318 setIsApplyAndClose( false );
322 \brief SLOT called when dialog is closed
324 void SMESHGUI_GroupOpDlg::reject()
326 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
327 aViewWindow->SetSelectionMode(ActorSelection);
328 disconnect( mySelectionMgr, 0, this, 0 );
329 disconnect( mySMESHGUI, 0, this, 0 );
330 mySMESHGUI->ResetState();
331 mySelectionMgr->clearFilters();
336 //=================================================================================
337 // function : onOpenView()
339 //=================================================================================
340 void SMESHGUI_GroupOpDlg::onOpenView()
343 SMESH::SetPointRepresentation(false);
346 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
347 mySMESHGUI->EmitSignalDeactivateDialog();
352 //=================================================================================
353 // function : onCloseView()
355 //=================================================================================
356 void SMESHGUI_GroupOpDlg::onCloseView()
363 \brief SLOT called when "Help" button pressed shows "Help" page
365 void SMESHGUI_GroupOpDlg::onHelp()
367 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
369 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
373 platform = "winapplication";
375 platform = "application";
377 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
378 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
379 arg(app->resourceMgr()->stringValue("ExternalBrowser",
381 arg(myHelpFileName));
386 \brief Gets list of currently selected groups from selection manager
387 \param theOutList out list of groups
388 \param theOutNames out list of group of group names
389 \return TRUE if operation theOutList is not empty, FALSE otherwise
391 bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList<SMESH::SMESH_GroupBase_var>& theOutList,
392 QStringList& theOutNames )
399 SALOME_ListIO aListIO;
400 mySelectionMgr->selectedObjects( aListIO );
401 SALOME_ListIteratorOfListIO anIter ( aListIO );
402 for ( ; anIter.More(); anIter.Next())
404 SMESH::SMESH_GroupBase_var aGroup =
405 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
406 if ( !aGroup->_is_nil())
408 theOutList.append( aGroup );
409 theOutNames.append( aGroup->GetName() );
413 return theOutList.count() > 0;
417 \brief Converts QT-list of group to the list acceptable by IDL interface
418 \param theIn input list
419 \return list acceptable by IDL interface
421 SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert(
422 const QList<SMESH::SMESH_GroupBase_var>& theIn )
424 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
425 aList->length( theIn.count() );
427 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = theIn.begin();
428 for ( int i = 0; anIter != theIn.end(); ++anIter, ++i )
429 aList[ i ] = *anIter;
431 return aList._retn();
435 \brief Get color to be assigned to group
436 \return color to be assigned to group
438 SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
440 QColor aQColor = myColorBtn->color();
442 SALOMEDS::Color aColor;
443 aColor.R = (float)aQColor.red() / 255.0;
444 aColor.G = (float)aQColor.green() / 255.0;
445 aColor.B = (float)aQColor.blue() / 255.0;
451 \brief SLOT, called when selection is changed. Current implementation does
452 nothing. The method should be redefined in derived classes to update
453 corresponding GUI controls
455 void SMESHGUI_GroupOpDlg::onSelectionDone()
460 \brief Calls onSelectionDone() and setVisible() method of base class
461 \param visible the visible state of the dialog
463 void SMESHGUI_GroupOpDlg::setVisible( bool visible )
468 resize( minimumSizeHint().width(), sizeHint().height() );
470 QDialog::setVisible( visible );
474 \brief SLOT called when dialog must be deativated
476 void SMESHGUI_GroupOpDlg::onDeactivate()
479 mySelectionMgr->clearFilters();
483 \brief Event filter updates selection mode and selection filter. This virtual method
484 is redefined from the base class it is called when dialog obtains input focus
486 void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
488 mySMESHGUI->EmitSignalDeactivateDialog();
490 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
492 aViewWindow->SetSelectionMode(ActorSelection);
494 mySelector = aViewWindow->GetSelector();
496 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
500 \brief Resets state of the dialog, initializes its fields with default value, etc.
501 Usually called by onApply() slot to reinitialize dialog fields. This virtual method
502 should be redefined in derived class to update its own fileds
504 void SMESHGUI_GroupOpDlg::reset()
506 myNameEdit->setText("");
507 myNameEdit->setFocus();
511 \brief Gets name of group to be created
512 \return name of group to be created
515 QString SMESHGUI_GroupOpDlg::getName() const
517 return myNameEdit->text();
521 \brief Sets name of group to be created
522 \param theName name of group to be created
525 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
527 myNameEdit->setText( theName );
531 \brief Provides reaction on �F1� button pressing
532 \param e key press event
534 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
536 QDialog::keyPressEvent( e );
537 if ( e->isAccepted() )
540 if ( e->key() == Qt::Key_F1 ) {
547 \brief This virtual slot does nothing and should be redefined in derived classes
548 \return return false;
550 bool SMESHGUI_GroupOpDlg::onApply()
556 \brief Set value of the flag indicating that the dialog is
557 accepted by Apply & Close button
558 \param theFlag value of the flag
559 \sa isApplyAndClose()
561 void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
563 myIsApplyAndClose = theFlag;
567 \brief Get value of the flag indicating that the dialog is
568 accepted by Apply & Close button
569 \return value of the flag
570 \sa setApplyAndClose()
572 bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
574 return myIsApplyAndClose;
577 // === === === === === === === === === === === === === === === === === === === === ===
581 \param theModule module
583 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
584 : SMESHGUI_GroupOpDlg( theModule )
586 setWindowTitle(tr("UNION_OF_GROUPS"));
587 setHelpFileName( "using_operations_on_groups_page.html#union_anchor" );
589 QGroupBox* anArgGrp = getArgGrp();
590 myListWg = new QListWidget( anArgGrp );
592 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
593 aLay->addWidget( myListWg );
599 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
604 \brief This virtual method redefined from the base class resets state
605 of the dialog, initializes its fields with default value, etc.
607 void SMESHGUI_UnionGroupsDlg::reset()
609 SMESHGUI_GroupOpDlg::reset();
615 \brief SLOT called when apply button is pressed performs operation
616 \return TRUE if operation has been completed successfully, FALSE otherwise
618 bool SMESHGUI_UnionGroupsDlg::onApply()
620 if ( getSMESHGUI()->isActiveStudyLocked())
623 // Verify validity of group name
624 if ( getName() == "" )
626 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
627 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
631 if ( !isValid( myGroups ) )
634 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
635 QString aName = getName();
638 QStringList anEntryList;
641 SMESH::ListOfGroups_var aList = convert( myGroups );
642 SMESH::SMESH_Group_var aNewGrp =
643 aMesh->UnionListOfGroups( aList, aName.toLatin1().constData() );
644 if ( !CORBA::is_nil( aNewGrp ) )
646 aNewGrp->SetColor( getColor() );
647 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
648 anEntryList.append( aSObject->GetID().c_str() );
659 SMESHGUI::Modified();
660 getSMESHGUI()->updateObjBrowser(true);
662 if( LightApp_Application* anApp =
663 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
664 anApp->browseObjects( anEntryList, isApplyAndClose() );
669 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
670 tr("SMESH_OPERATION_FAILED"));
676 \brief SLOT, called when selection is changed, updates corresponding GUI controls
678 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
681 getSelectedGroups( myGroups, aNames );
683 myListWg->addItems( aNames );
686 // === === === === === === === === === === === === === === === === === === === === ===
690 \param theModule module
692 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
693 : SMESHGUI_GroupOpDlg( theModule )
695 setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
696 setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
698 QGroupBox* anArgGrp = getArgGrp();
699 myListWg = new QListWidget( anArgGrp );
701 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
702 aLay->addWidget( myListWg );
708 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
713 \brief This virtual method redefined from the base class resets state
714 of the dialog, initializes its fields with default value, etc.
716 void SMESHGUI_IntersectGroupsDlg::reset()
718 SMESHGUI_GroupOpDlg::reset();
724 \brief SLOT called when apply button is pressed performs operation
725 \return TRUE if operation has been completed successfully, FALSE otherwise
727 bool SMESHGUI_IntersectGroupsDlg::onApply()
729 if ( getSMESHGUI()->isActiveStudyLocked())
732 // Verify validity of group name
733 if ( getName() == "" )
735 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
736 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
740 if ( !isValid( myGroups ) )
743 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
744 QString aName = getName();
747 QStringList anEntryList;
750 SMESH::ListOfGroups_var aList = convert( myGroups );
751 SMESH::SMESH_Group_var aNewGrp =
752 aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() );
753 if ( !CORBA::is_nil( aNewGrp ) )
755 aNewGrp->SetColor( getColor() );
756 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
757 anEntryList.append( aSObject->GetID().c_str() );
768 SMESHGUI::Modified();
769 getSMESHGUI()->updateObjBrowser(true);
771 if( LightApp_Application* anApp =
772 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
773 anApp->browseObjects( anEntryList, isApplyAndClose() );
778 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
779 tr("SMESH_OPERATION_FAILED"));
785 \brief SLOT, called when selection is changed, updates corresponding GUI controls
787 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
790 getSelectedGroups( myGroups, aNames );
792 myListWg->addItems( aNames );
795 // === === === === === === === === === === === === === === === === === === === === ===
799 \param theModule module
801 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
802 : SMESHGUI_GroupOpDlg( theModule )
804 setWindowTitle(tr("CUT_OF_GROUPS"));
805 setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
807 QGroupBox* anArgGrp = getArgGrp();
809 QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
812 QFrame* aFrame1 = new QFrame( anArgGrp );
813 QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
814 aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
815 myBtn1 = new QPushButton( aFrame1 );
816 myBtn1->setIcon(aPix);
817 myListWg1 = new QListWidget( aFrame1 );
819 QGridLayout* aLay1 = new QGridLayout( aFrame1 );
820 aLay1->setSpacing( SPACING );
821 aLay1->addWidget( aLbl1, 0, 0 );
822 aLay1->addWidget( myBtn1, 0, 1 );
823 aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
824 //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
825 //aLay1->addItem( aHSpacer1, 0, 2 );
829 QFrame* aFrame2 = new QFrame( anArgGrp );
830 QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
831 aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
832 myBtn2 = new QPushButton( aFrame2 );
833 myBtn2->setIcon(aPix);
834 myListWg2 = new QListWidget( aFrame2 );
836 QGridLayout* aLay2 = new QGridLayout( aFrame2 );
837 aLay2->setSpacing( SPACING );
838 aLay2->addWidget( aLbl2, 0, 0 );
839 aLay2->addWidget( myBtn2, 0, 1 );
840 aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
841 //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
842 //aLay2->addItem( aHSpacer2, 0, 2 );
844 // create button group
846 QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
847 aGrp->addButton( myBtn1, 0 );
848 aGrp->addButton( myBtn2, 1 );
849 myBtn1->setCheckable( true );
850 myBtn2->setCheckable( true );
851 aGrp->setExclusive( true );
852 myBtn1->setChecked( true );
855 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
856 aLay->setSpacing( SPACING );
857 aLay->addWidget( aFrame1 );
858 aLay->addWidget( aFrame2 );
864 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
869 \brief This virtual method redefined from the base class resets state
870 of the dialog, initializes its fields with default value, etc.
872 void SMESHGUI_CutGroupsDlg::reset()
874 SMESHGUI_GroupOpDlg::reset();
884 \brief SLOT called when apply button is pressed performs operation
885 \return TRUE if operation has been completed successfully, FALSE otherwise
887 bool SMESHGUI_CutGroupsDlg::onApply()
889 if ( getSMESHGUI()->isActiveStudyLocked())
892 // Verify validity of group name
893 if ( getName() == "" )
895 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
896 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
900 if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
902 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
903 SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
907 QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
908 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
909 for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
910 aGroups.append( *anIter );
912 if ( !isValid( aGroups ) )
915 SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
916 QString aName = getName();
919 QStringList anEntryList;
922 SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
923 SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
924 SMESH::SMESH_Group_var aNewGrp =
925 aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() );
926 if ( !CORBA::is_nil( aNewGrp ) )
928 aNewGrp->SetColor( getColor() );
929 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
930 anEntryList.append( aSObject->GetID().c_str() );
941 SMESHGUI::Modified();
942 getSMESHGUI()->updateObjBrowser(true);
944 if( LightApp_Application* anApp =
945 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
946 anApp->browseObjects( anEntryList, isApplyAndClose() );
951 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
952 tr("SMESH_OPERATION_FAILED"));
958 \brief SLOT, called when selection is changed, updates corresponding GUI controls
960 void SMESHGUI_CutGroupsDlg::onSelectionDone()
963 if ( myBtn2->isChecked() )
965 getSelectedGroups( myGroups2, aNames );
967 myListWg2->addItems( aNames );
971 getSelectedGroups( myGroups1, aNames );
973 myListWg1->addItems( aNames );
977 // === === === === === === === === === === === === === === === === === === === === ===
981 \param theModule module
983 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
984 : SMESHGUI_GroupOpDlg( theModule )
986 setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
987 setHelpFileName( "group_of_underlying_elements_page.html" );
989 QGroupBox* anArgGrp = getArgGrp();
991 QLabel* aTypeLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
993 myTypeCombo = new QComboBox( anArgGrp );
996 anItems.append( tr( "MESH_NODE" ) );
997 anItems.append( tr( "SMESH_EDGE" ) );
998 anItems.append( tr( "SMESH_FACE" ) );
999 anItems.append( tr( "SMESH_VOLUME" ) );
1000 anItems.append( tr( "SMESH_ELEM0D" ) );
1001 anItems.append( tr( "SMESH_BALL" ) );
1003 myTypeCombo->addItems( anItems );
1004 myTypeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1006 QLabel* aNbNoLbl = new QLabel( tr( "NUMBER_OF_COMMON_NODES" ), anArgGrp );
1008 myNbNoCombo = new QComboBox( anArgGrp );
1011 anItems.append( tr( "ALL" ) );
1012 anItems.append( tr( "MAIN" ) );
1013 anItems.append( tr( "AT_LEAST_ONE" ) );
1014 anItems.append( tr( "MAJORITY" ) );
1016 myNbNoCombo->addItems( anItems );
1017 myNbNoCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1019 myListWg = new QListWidget( anArgGrp );
1021 myUnderlOnlyChk = new QCheckBox( tr("UNDERLYING_ENTITIES_ONLY"), anArgGrp );
1022 myUnderlOnlyChk->setChecked( false );
1025 QGridLayout* aLay = new QGridLayout( anArgGrp );
1026 aLay->setSpacing( SPACING );
1027 aLay->addWidget( aTypeLbl, 0, 0 );
1028 aLay->addWidget( myTypeCombo, 0, 1 );
1029 aLay->addWidget( aNbNoLbl, 1, 0 );
1030 aLay->addWidget( myNbNoCombo, 1, 1 );
1031 aLay->addWidget( myListWg, 2, 0, 1, 2 );
1032 aLay->addWidget( myUnderlOnlyChk, 3, 0 );
1038 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
1043 \brief This virtual method redefined from the base class resets state
1044 of the dialog, initializes its fields with default value, etc.
1046 void SMESHGUI_DimGroupDlg::reset()
1048 SMESHGUI_GroupOpDlg::reset();
1054 \brief Gets elements type
1055 \return elements type
1056 \sa setElementType()
1058 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
1060 return (SMESH::ElementType)( myTypeCombo->currentIndex() + 1 );
1064 \brief Sets elements type
1065 \param theElemType elements type
1066 \sa getElementType()
1068 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
1070 myTypeCombo->setCurrentIndex( theElemType - 1 );
1074 \brief SLOT called when apply button is pressed performs operation
1075 \return TRUE if operation has been completed successfully, FALSE otherwise
1077 bool SMESHGUI_DimGroupDlg::onApply()
1079 if ( getSMESHGUI()->isActiveStudyLocked())
1082 // Verify validity of group name
1083 if ( getName() == "" )
1085 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
1086 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
1090 if ( !isValid( myGroups ) )
1093 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1094 QString aName = getName();
1097 QStringList anEntryList;
1100 SMESH::ListOfIDSources_var aList = new SMESH::ListOfIDSources();
1101 aList->length( myGroups.count() );
1102 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = myGroups.begin();
1103 for ( int i = 0; anIter != myGroups.end(); ++anIter, ++i )
1104 aList[ i ] = SMESH::SMESH_IDSource::_narrow( *anIter );
1106 SMESH::ElementType anElemType = getElementType();
1107 SMESH::NB_COMMON_NODES_ENUM aNbCoNodes =
1108 (SMESH::NB_COMMON_NODES_ENUM) myNbNoCombo->currentIndex();
1110 SMESH::SMESH_Group_var aNewGrp =
1111 aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData(),
1112 aNbCoNodes, myUnderlOnlyChk->isChecked() );
1113 if ( !CORBA::is_nil( aNewGrp ) )
1115 aNewGrp->SetColor( getColor() );
1116 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
1117 anEntryList.append( aSObject->GetID().c_str() );
1128 SMESHGUI::Modified();
1129 getSMESHGUI()->updateObjBrowser(true);
1131 if( LightApp_Application* anApp =
1132 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1133 anApp->browseObjects( anEntryList, isApplyAndClose() );
1138 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1139 tr("SMESH_OPERATION_FAILED"));
1145 \brief SLOT, called when selection is changed, updates corresponding GUI controls
1147 void SMESHGUI_DimGroupDlg::onSelectionDone()
1150 getSelectedGroups( myGroups, aNames );
1152 myListWg->addItems( aNames );