1 // Copyright (C) 2007-2021 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"
34 #include <SMESH_ActorUtils.h>
36 #include <LightApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <QtxColorButton.h>
39 #include <SALOMEDSClient_SObject.hxx>
40 #include <SALOME_ListIO.hxx>
41 #include <SUIT_Desktop.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_OverrideCursor.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SVTK_Selection.h>
47 #include <SVTK_ViewWindow.h>
50 #include <QButtonGroup>
53 #include <QGridLayout>
55 #include <QHBoxLayout>
59 #include <QListWidget>
60 #include <QPushButton>
61 #include <QVBoxLayout>
67 * Class : SMESHGUI_GroupOpDlg
68 * Description : Perform boolean operations on groups
73 \param theModule pointer on module instance
75 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule )
76 : QDialog( SMESH::GetDesktop( theModule ) ),
77 mySMESHGUI( theModule ),
78 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
79 myIsApplyAndClose( false )
83 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
85 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
86 aDlgLay->setMargin(MARGIN);
87 aDlgLay->setSpacing(SPACING);
89 QWidget* aMainFrame = createMainFrame (this);
90 QWidget* aBtnFrame = createButtonFrame(this);
92 aDlgLay->addWidget(aMainFrame);
93 aDlgLay->addWidget(aBtnFrame);
99 \brief Creates frame containing dialog's input fields
100 \param theParent parent widget
101 \return pointer on created widget
103 QWidget* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent )
105 QWidget* aMainGrp = new QWidget(theParent);
106 QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
108 aLay->setSpacing(SPACING);
110 // ------------------------------------------------------
111 QGroupBox* aNameGrp = new QGroupBox(tr("RESULT"), aMainGrp);
112 QHBoxLayout* aNameGrpLayout = new QHBoxLayout(aNameGrp);
113 aNameGrpLayout->setMargin(MARGIN);
114 aNameGrpLayout->setSpacing(SPACING);
116 QLabel* aNameLab = new QLabel(tr("RESULT_NAME"), aNameGrp);
117 myNameEdit = new QLineEdit(aNameGrp);
119 aNameGrpLayout->addWidget(aNameLab);
120 aNameGrpLayout->addWidget(myNameEdit);
122 // ------------------------------------------------------
123 myArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp);
126 // ------------------------------------------------------
128 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
129 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
130 aColorBoxLayout->setMargin(MARGIN);
131 aColorBoxLayout->setSpacing(SPACING);
133 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
134 myColorBtn = new QtxColorButton(aColorBox);
135 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
136 myColorBtn->sizePolicy().verticalPolicy() );
138 aColorBoxLayout->addWidget(aColorLab);
139 aColorBoxLayout->addWidget(myColorBtn);
141 // ------------------------------------------------------
142 aLay->addWidget( aNameGrp );
143 aLay->addWidget( myArgGrp );
144 aLay->addWidget( aColorBox );
150 \brief Gets pointer on arguments group box
151 \return pointer on arguments group box
153 QGroupBox* SMESHGUI_GroupOpDlg::getArgGrp() const
159 \brief Sets help file name
160 \param theFName help file name
162 void SMESHGUI_GroupOpDlg::setHelpFileName( const QString& theFName )
164 myHelpFileName = theFName;
168 \brief Gets pointer to the module instance
169 \return pointer to the module instance
171 SMESHGUI* SMESHGUI_GroupOpDlg::getSMESHGUI() const
177 \brief Create frame containing buttons
178 \param theParent parent widget
179 \return pointer to the created frame
181 QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
183 QGroupBox* aFrame = new QGroupBox(theParent);
185 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
186 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
187 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
188 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
190 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
191 aLay->setMargin(MARGIN);
192 aLay->setSpacing(SPACING);
194 aLay->addWidget(myOkBtn);
195 aLay->addSpacing(10);
196 aLay->addWidget(myApplyBtn);
197 aLay->addSpacing(10);
199 aLay->addWidget(myCloseBtn);
200 aLay->addWidget(myHelpBtn);
202 // connect signals and slots
203 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
204 connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
205 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
206 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
214 SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg()
219 \brief Init dialog fields, connect signals and slots, show dialog
221 void SMESHGUI_GroupOpDlg::Init()
223 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
225 // selection and SMESHGUI
226 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
227 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
228 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
229 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT(onOpenView()));
230 connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT(onCloseView()));
232 // set selection mode
233 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
234 aViewWindow->SetSelectionMode(ActorSelection);
235 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
237 setDefaultGroupColor();
241 \brief Validate list of groups used for operation. Checks whether they corresponds
242 to the same face and have one type
243 \param theListGrp input list of groups
244 \return TRUE if groups are valid, FALSE otherwise
246 bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theListGrp )
248 if ( theListGrp.isEmpty() )
250 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
251 tr("INCORRECT_ARGUMENTS") );
255 int aMeshId = -1, aGrpType = -1;
256 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter;
257 for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter )
259 SMESH::SMESH_GroupBase_var aGrp = *anIter;
260 if ( CORBA::is_nil( aGrp ) )
261 continue; // nonsense
263 SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh();
264 if ( CORBA::is_nil( aMesh ) )
268 int aCurrId = aMesh->GetId();
273 if ( aMeshId != aCurrId )
275 aMeshId = -1; // different meshes
281 int aCurrType = aGrp->GetType();
282 if ( aGrpType == -1 )
283 aGrpType = aCurrType;
286 if ( aGrpType != aCurrType )
288 aGrpType = -1; // different types
297 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
302 if ( aGrpType == -1 )
304 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
313 \brief SLOT called when "Ok" button pressed performs operation and closes dialog box
315 void SMESHGUI_GroupOpDlg::onOk()
317 SUIT_OverrideCursor oc;
318 setIsApplyAndClose( true );
321 setIsApplyAndClose( false );
325 \brief SLOT called when dialog is closed
327 void SMESHGUI_GroupOpDlg::reject()
329 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
330 aViewWindow->SetSelectionMode(ActorSelection);
331 disconnect( mySelectionMgr, 0, this, 0 );
332 disconnect( mySMESHGUI, 0, this, 0 );
333 mySMESHGUI->ResetState();
334 mySelectionMgr->clearFilters();
339 //=================================================================================
340 // function : onOpenView()
342 //=================================================================================
343 void SMESHGUI_GroupOpDlg::onOpenView()
346 SMESH::SetPointRepresentation(false);
349 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
350 mySMESHGUI->EmitSignalDeactivateDialog();
355 //=================================================================================
356 // function : onCloseView()
358 //=================================================================================
359 void SMESHGUI_GroupOpDlg::onCloseView()
366 \brief SLOT called when "Help" button pressed shows "Help" page
368 void SMESHGUI_GroupOpDlg::onHelp()
370 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
372 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
376 platform = "winapplication";
378 platform = "application";
380 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
381 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
382 arg(app->resourceMgr()->stringValue("ExternalBrowser",
384 arg(myHelpFileName));
389 \brief Gets list of currently selected groups from selection manager
390 \param theOutList out list of groups
391 \param theOutNames out list of group of group names
392 \return TRUE if operation theOutList is not empty, FALSE otherwise
394 bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList<SMESH::SMESH_GroupBase_var>& theOutList,
395 QStringList& theOutNames )
402 SALOME_ListIO aListIO;
403 mySelectionMgr->selectedObjects( aListIO );
404 SALOME_ListIteratorOfListIO anIter ( aListIO );
405 for ( ; anIter.More(); anIter.Next())
407 SMESH::SMESH_GroupBase_var aGroup =
408 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
409 if ( !aGroup->_is_nil())
411 theOutList.append( aGroup );
412 theOutNames.append( aGroup->GetName() );
416 return theOutList.count() > 0;
420 \brief Converts QT-list of group to the list acceptable by IDL interface
421 \param theIn input list
422 \return list acceptable by IDL interface
424 SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert(
425 const QList<SMESH::SMESH_GroupBase_var>& theIn )
427 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
428 aList->length( theIn.count() );
430 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = theIn.begin();
431 for ( int i = 0; anIter != theIn.end(); ++anIter, ++i )
432 aList[ i ] = *anIter;
434 return aList._retn();
438 \brief Get color to be assigned to group
439 \return color to be assigned to group
441 SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
443 QColor aQColor = myColorBtn->color();
445 SALOMEDS::Color aColor;
446 aColor.R = (float)aQColor.red() / 255.0;
447 aColor.G = (float)aQColor.green() / 255.0;
448 aColor.B = (float)aQColor.blue() / 255.0;
454 \brief Set default color for group
456 void SMESHGUI_GroupOpDlg::setDefaultGroupColor()
458 myColorBtn->setColor( SMESH::GetColor( "SMESH", "default_grp_color", QColor( 255, 170, 0 ) ) );
462 \brief SLOT, called when selection is changed. Current implementation does
463 nothing. The method should be redefined in derived classes to update
464 corresponding GUI controls
466 void SMESHGUI_GroupOpDlg::onSelectionDone()
471 \brief Calls onSelectionDone() and setVisible() method of base class
472 \param visible the visible state of the dialog
474 void SMESHGUI_GroupOpDlg::setVisible( bool visible )
479 resize( minimumSizeHint().width(), sizeHint().height() );
481 QDialog::setVisible( visible );
485 \brief SLOT called when dialog must be deactivated
487 void SMESHGUI_GroupOpDlg::onDeactivate()
490 mySelectionMgr->clearFilters();
494 \brief Event filter updates selection mode and selection filter. This virtual method
495 is redefined from the base class it is called when dialog obtains input focus
497 void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
499 mySMESHGUI->EmitSignalDeactivateDialog();
501 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
503 aViewWindow->SetSelectionMode(ActorSelection);
505 mySelector = aViewWindow->GetSelector();
507 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
511 \brief Resets state of the dialog, initializes its fields with default value, etc.
512 Usually called by onApply() slot to reinitialize dialog fields. This virtual method
513 should be redefined in derived class to update its own fields
515 void SMESHGUI_GroupOpDlg::reset()
517 myNameEdit->setText("");
518 myNameEdit->setFocus();
519 setDefaultGroupColor();
523 \brief Gets name of group to be created
524 \return name of group to be created
527 QString SMESHGUI_GroupOpDlg::getName() const
529 return myNameEdit->text();
533 \brief Sets name of group to be created
534 \param theName name of group to be created
537 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
539 myNameEdit->setText( theName );
543 \brief Provides reaction on �F1� button pressing
544 \param e key press event
546 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
548 QDialog::keyPressEvent( e );
549 if ( e->isAccepted() )
552 if ( e->key() == Qt::Key_F1 ) {
559 \brief This virtual slot does nothing and should be redefined in derived classes
560 \return return false;
562 bool SMESHGUI_GroupOpDlg::onApply()
568 \brief Set value of the flag indicating that the dialog is
569 accepted by Apply & Close button
570 \param theFlag value of the flag
571 \sa isApplyAndClose()
573 void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
575 myIsApplyAndClose = theFlag;
579 \brief Get value of the flag indicating that the dialog is
580 accepted by Apply & Close button
581 \return value of the flag
582 \sa setApplyAndClose()
584 bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
586 return myIsApplyAndClose;
589 // === === === === === === === === === === === === === === === === === === === === ===
593 \param theModule module
595 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
596 : SMESHGUI_GroupOpDlg( theModule )
598 setWindowTitle(tr("UNION_OF_GROUPS"));
599 setHelpFileName( "using_operations_on_groups.html#union-anchor" );
601 QGroupBox* anArgGrp = getArgGrp();
602 myListWg = new QListWidget( anArgGrp );
604 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
605 aLay->addWidget( myListWg );
611 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
616 \brief This virtual method redefined from the base class resets state
617 of the dialog, initializes its fields with default value, etc.
619 void SMESHGUI_UnionGroupsDlg::reset()
621 SMESHGUI_GroupOpDlg::reset();
627 \brief SLOT called when apply button is pressed performs operation
628 \return TRUE if operation has been completed successfully, FALSE otherwise
630 bool SMESHGUI_UnionGroupsDlg::onApply()
632 if ( SMESHGUI::isStudyLocked())
635 // Verify validity of group name
636 if ( getName() == "" )
638 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
639 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
643 if ( !isValid( myGroups ) )
646 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
647 QString aName = getName();
650 QStringList anEntryList;
653 SMESH::ListOfGroups_var aList = convert( myGroups );
654 SMESH::SMESH_Group_var aNewGrp =
655 aMesh->UnionListOfGroups( aList, aName.toUtf8().constData() );
656 if ( !CORBA::is_nil( aNewGrp ) )
658 aNewGrp->SetColor( getColor() );
659 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
660 anEntryList.append( aSObject->GetID().c_str() );
671 SMESHGUI::Modified();
672 getSMESHGUI()->updateObjBrowser(true);
674 if( LightApp_Application* anApp =
675 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
676 anApp->browseObjects( anEntryList, isApplyAndClose() );
681 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
682 tr("SMESH_OPERATION_FAILED"));
688 \brief SLOT, called when selection is changed, updates corresponding GUI controls
690 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
693 getSelectedGroups( myGroups, aNames );
695 myListWg->addItems( aNames );
698 // === === === === === === === === === === === === === === === === === === === === ===
702 \param theModule module
704 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
705 : SMESHGUI_GroupOpDlg( theModule )
707 setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
708 setHelpFileName( "using_operations_on_groups.html#intersection-anchor" );
710 QGroupBox* anArgGrp = getArgGrp();
711 myListWg = new QListWidget( anArgGrp );
713 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
714 aLay->addWidget( myListWg );
720 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
725 \brief This virtual method redefined from the base class resets state
726 of the dialog, initializes its fields with default value, etc.
728 void SMESHGUI_IntersectGroupsDlg::reset()
730 SMESHGUI_GroupOpDlg::reset();
736 \brief SLOT called when apply button is pressed performs operation
737 \return TRUE if operation has been completed successfully, FALSE otherwise
739 bool SMESHGUI_IntersectGroupsDlg::onApply()
741 if ( SMESHGUI::isStudyLocked())
744 // Verify validity of group name
745 if ( getName() == "" )
747 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
748 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
752 if ( !isValid( myGroups ) )
755 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
756 QString aName = getName();
759 QStringList anEntryList;
762 SMESH::ListOfGroups_var aList = convert( myGroups );
763 SMESH::SMESH_Group_var aNewGrp =
764 aMesh->IntersectListOfGroups( aList, aName.toUtf8().constData() );
765 if ( !CORBA::is_nil( aNewGrp ) )
767 aNewGrp->SetColor( getColor() );
768 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
769 anEntryList.append( aSObject->GetID().c_str() );
780 SMESHGUI::Modified();
781 getSMESHGUI()->updateObjBrowser(true);
783 if( LightApp_Application* anApp =
784 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
785 anApp->browseObjects( anEntryList, isApplyAndClose() );
790 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
791 tr("SMESH_OPERATION_FAILED"));
797 \brief SLOT, called when selection is changed, updates corresponding GUI controls
799 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
802 getSelectedGroups( myGroups, aNames );
804 myListWg->addItems( aNames );
807 // === === === === === === === === === === === === === === === === === === === === ===
811 \param theModule module
813 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
814 : SMESHGUI_GroupOpDlg( theModule )
816 setWindowTitle(tr("CUT_OF_GROUPS"));
817 setHelpFileName( "using_operations_on_groups.html#cut-anchor" );
819 QGroupBox* anArgGrp = getArgGrp();
821 QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
824 QFrame* aFrame1 = new QFrame( anArgGrp );
825 QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
826 aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
827 myBtn1 = new QPushButton( aFrame1 );
828 myBtn1->setIcon(aPix);
829 myListWg1 = new QListWidget( aFrame1 );
831 QGridLayout* aLay1 = new QGridLayout( aFrame1 );
832 aLay1->setSpacing( SPACING );
833 aLay1->addWidget( aLbl1, 0, 0 );
834 aLay1->addWidget( myBtn1, 0, 1 );
835 aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
836 //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
837 //aLay1->addItem( aHSpacer1, 0, 2 );
841 QFrame* aFrame2 = new QFrame( anArgGrp );
842 QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
843 aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
844 myBtn2 = new QPushButton( aFrame2 );
845 myBtn2->setIcon(aPix);
846 myListWg2 = new QListWidget( aFrame2 );
848 QGridLayout* aLay2 = new QGridLayout( aFrame2 );
849 aLay2->setSpacing( SPACING );
850 aLay2->addWidget( aLbl2, 0, 0 );
851 aLay2->addWidget( myBtn2, 0, 1 );
852 aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
853 //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
854 //aLay2->addItem( aHSpacer2, 0, 2 );
856 // create button group
858 QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
859 aGrp->addButton( myBtn1, 0 );
860 aGrp->addButton( myBtn2, 1 );
861 myBtn1->setCheckable( true );
862 myBtn2->setCheckable( true );
863 aGrp->setExclusive( true );
864 myBtn1->setChecked( true );
867 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
868 aLay->setSpacing( SPACING );
869 aLay->addWidget( aFrame1 );
870 aLay->addWidget( aFrame2 );
876 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
881 \brief This virtual method redefined from the base class resets state
882 of the dialog, initializes its fields with default value, etc.
884 void SMESHGUI_CutGroupsDlg::reset()
886 SMESHGUI_GroupOpDlg::reset();
896 \brief SLOT called when apply button is pressed performs operation
897 \return TRUE if operation has been completed successfully, FALSE otherwise
899 bool SMESHGUI_CutGroupsDlg::onApply()
901 if ( SMESHGUI::isStudyLocked())
904 // Verify validity of group name
905 if ( getName() == "" )
907 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
908 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
912 if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
914 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
915 SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
919 QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
920 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
921 for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
922 aGroups.append( *anIter );
924 if ( !isValid( aGroups ) )
927 SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
928 QString aName = getName();
931 QStringList anEntryList;
934 SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
935 SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
936 SMESH::SMESH_Group_var aNewGrp =
937 aMesh->CutListOfGroups( aList1, aList2, aName.toUtf8().constData() );
938 if ( !CORBA::is_nil( aNewGrp ) )
940 aNewGrp->SetColor( getColor() );
941 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
942 anEntryList.append( aSObject->GetID().c_str() );
953 SMESHGUI::Modified();
954 getSMESHGUI()->updateObjBrowser(true);
956 if( LightApp_Application* anApp =
957 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
958 anApp->browseObjects( anEntryList, isApplyAndClose() );
963 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
964 tr("SMESH_OPERATION_FAILED"));
970 \brief SLOT, called when selection is changed, updates corresponding GUI controls
972 void SMESHGUI_CutGroupsDlg::onSelectionDone()
975 if ( myBtn2->isChecked() )
977 getSelectedGroups( myGroups2, aNames );
979 myListWg2->addItems( aNames );
983 getSelectedGroups( myGroups1, aNames );
985 myListWg1->addItems( aNames );
989 // === === === === === === === === === === === === === === === === === === === === ===
993 \param theModule module
995 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
996 : SMESHGUI_GroupOpDlg( theModule )
998 setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
999 setHelpFileName( "group_of_underlying_elements.html" );
1001 QGroupBox* anArgGrp = getArgGrp();
1003 QLabel* aTypeLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
1005 myTypeCombo = new QComboBox( anArgGrp );
1006 QStringList anItems;
1008 anItems.append( tr( "MESH_NODE" ) );
1009 anItems.append( tr( "SMESH_EDGE" ) );
1010 anItems.append( tr( "SMESH_FACE" ) );
1011 anItems.append( tr( "SMESH_VOLUME" ) );
1012 anItems.append( tr( "SMESH_ELEM0D" ) );
1013 anItems.append( tr( "SMESH_BALL" ) );
1015 myTypeCombo->addItems( anItems );
1016 myTypeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1018 QLabel* aNbNoLbl = new QLabel( tr( "NUMBER_OF_COMMON_NODES" ), anArgGrp );
1020 myNbNoCombo = new QComboBox( anArgGrp );
1023 anItems.append( tr( "ALL" ) );
1024 anItems.append( tr( "MAIN" ) );
1025 anItems.append( tr( "AT_LEAST_ONE" ) );
1026 anItems.append( tr( "MAJORITY" ) );
1028 myNbNoCombo->addItems( anItems );
1029 myNbNoCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1031 myListWg = new QListWidget( anArgGrp );
1033 myUnderlOnlyChk = new QCheckBox( tr("UNDERLYING_ENTITIES_ONLY"), anArgGrp );
1034 myUnderlOnlyChk->setChecked( false );
1037 QGridLayout* aLay = new QGridLayout( anArgGrp );
1038 aLay->setSpacing( SPACING );
1039 aLay->addWidget( aTypeLbl, 0, 0 );
1040 aLay->addWidget( myTypeCombo, 0, 1 );
1041 aLay->addWidget( aNbNoLbl, 1, 0 );
1042 aLay->addWidget( myNbNoCombo, 1, 1 );
1043 aLay->addWidget( myListWg, 2, 0, 1, 2 );
1044 aLay->addWidget( myUnderlOnlyChk, 3, 0 );
1050 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
1055 \brief This virtual method redefined from the base class resets state
1056 of the dialog, initializes its fields with default value, etc.
1058 void SMESHGUI_DimGroupDlg::reset()
1060 SMESHGUI_GroupOpDlg::reset();
1066 \brief Gets elements type
1067 \return elements type
1068 \sa setElementType()
1070 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
1072 return (SMESH::ElementType)( myTypeCombo->currentIndex() + 1 );
1076 \brief Sets elements type
1077 \param theElemType elements type
1078 \sa getElementType()
1080 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
1082 myTypeCombo->setCurrentIndex( theElemType - 1 );
1086 \brief SLOT called when apply button is pressed performs operation
1087 \return TRUE if operation has been completed successfully, FALSE otherwise
1089 bool SMESHGUI_DimGroupDlg::onApply()
1091 if ( SMESHGUI::isStudyLocked())
1094 // Verify validity of group name
1095 if ( getName() == "" )
1097 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
1098 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
1102 if ( !isValid( myGroups ) )
1105 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1106 QString aName = getName();
1109 QStringList anEntryList;
1112 SMESH::ListOfIDSources_var aList = new SMESH::ListOfIDSources();
1113 aList->length( myGroups.count() );
1114 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = myGroups.begin();
1115 for ( int i = 0; anIter != myGroups.end(); ++anIter, ++i )
1116 aList[ i ] = SMESH::SMESH_IDSource::_narrow( *anIter );
1118 SMESH::ElementType anElemType = getElementType();
1119 SMESH::NB_COMMON_NODES_ENUM aNbCoNodes =
1120 (SMESH::NB_COMMON_NODES_ENUM) myNbNoCombo->currentIndex();
1122 SMESH::SMESH_Group_var aNewGrp =
1123 aMesh->CreateDimGroup( aList, anElemType, aName.toUtf8().constData(),
1124 aNbCoNodes, myUnderlOnlyChk->isChecked() );
1125 if ( !CORBA::is_nil( aNewGrp ) )
1127 aNewGrp->SetColor( getColor() );
1128 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
1129 anEntryList.append( aSObject->GetID().c_str() );
1140 SMESHGUI::Modified();
1141 getSMESHGUI()->updateObjBrowser(true);
1143 if( LightApp_Application* anApp =
1144 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1145 anApp->browseObjects( anEntryList, isApplyAndClose() );
1150 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1151 tr("SMESH_OPERATION_FAILED"));
1157 \brief SLOT, called when selection is changed, updates corresponding GUI controls
1159 void SMESHGUI_DimGroupDlg::onSelectionDone()
1162 getSelectedGroups( myGroups, aNames );
1164 myListWg->addItems( aNames );