Salome HOME
PR: synchro V7_main tag mergefrom_V6_main_28Feb13
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupOpDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_GroupOpDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_GroupOpDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33
34 #include <SMESH_TypeFilter.hxx>
35
36 // SALOME GUI includes
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
41
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>
47
48 // SALOME KERNEL includes
49 #include <SALOMEDSClient_SObject.hxx>
50
51 // Qt includes
52 #include <QHBoxLayout>
53 #include <QVBoxLayout>
54 #include <QGridLayout>
55 #include <QPushButton>
56 #include <QGroupBox>
57 #include <QLabel>
58 #include <QLineEdit>
59 #include <QKeyEvent>
60 #include <QListWidget>
61 #include <QButtonGroup>
62 #include <SALOME_ListIteratorOfListIO.hxx>
63 #include <QComboBox>
64 #include <QtxColorButton.h>
65
66 #define SPACING 6
67 #define MARGIN  11
68
69 /*!
70  *  Class       : SMESHGUI_GroupOpDlg
71  *  Description : Perform boolean operations on groups
72  */
73
74 /*!
75   \brief Constructor
76   \param theModule pointer on module instance
77 */
78 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule )
79   : QDialog( SMESH::GetDesktop( theModule ) ),
80     mySMESHGUI( theModule ),
81     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
82     myIsApplyAndClose( false )
83 {
84   setModal(false);
85
86   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
87
88   QVBoxLayout* aDlgLay = new QVBoxLayout (this);
89   aDlgLay->setMargin(MARGIN);
90   aDlgLay->setSpacing(SPACING);
91
92   QWidget* aMainFrame = createMainFrame  (this);
93   QWidget* aBtnFrame  = createButtonFrame(this);
94
95   aDlgLay->addWidget(aMainFrame);
96   aDlgLay->addWidget(aBtnFrame);
97
98   Init();
99 }
100
101 /*!
102   \brief Creates frame containing dialog's input fields
103   \param theParent parent widget
104   \return pointer on created widget
105 */
106 QWidget* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent )
107 {
108   QWidget* aMainGrp = new QWidget(theParent);
109   QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
110   aLay->setMargin(0);
111   aLay->setSpacing(SPACING);
112   
113   // ------------------------------------------------------
114   QGroupBox* aNameGrp = new QGroupBox(tr("NAME"), aMainGrp);
115   QHBoxLayout* aNameGrpLayout = new QHBoxLayout(aNameGrp);
116   aNameGrpLayout->setMargin(MARGIN);
117   aNameGrpLayout->setSpacing(SPACING);
118
119   QLabel* aNameLab = new QLabel(tr("RESULT_NAME"), aNameGrp);
120   myNameEdit = new QLineEdit(aNameGrp);
121
122   aNameGrpLayout->addWidget(aNameLab);
123   aNameGrpLayout->addWidget(myNameEdit);
124
125   // ------------------------------------------------------
126   myArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp);
127
128
129   // ------------------------------------------------------
130   
131   QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
132   QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
133   aColorBoxLayout->setMargin(MARGIN);
134   aColorBoxLayout->setSpacing(SPACING);
135
136   QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
137   myColorBtn = new QtxColorButton(aColorBox);
138   myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding, 
139                              myColorBtn->sizePolicy().verticalPolicy() );
140
141   aColorBoxLayout->addWidget(aColorLab);
142   aColorBoxLayout->addWidget(myColorBtn);
143
144   // ------------------------------------------------------
145   aLay->addWidget( aNameGrp );
146   aLay->addWidget( myArgGrp );
147   aLay->addWidget( aColorBox );
148
149   return aMainGrp;
150 }
151
152 /*!
153   \brief Gets pointer on arguments group box
154   \return pointer on arguments group box
155 */
156 QGroupBox* SMESHGUI_GroupOpDlg::getArgGrp() const
157 {
158   return myArgGrp;
159 }
160
161 /*!
162   \brief Sets help file name
163   \param theFName help file name
164 */
165 void SMESHGUI_GroupOpDlg::setHelpFileName( const QString& theFName )
166 {
167   myHelpFileName = theFName;
168 }
169
170 /*!
171   \brief Gets pointer to the module instance
172   \return pointer to the module instance
173 */
174 SMESHGUI* SMESHGUI_GroupOpDlg::getSMESHGUI() const
175 {
176   return mySMESHGUI;
177 }
178
179 /*!
180   \brief Create frame containing buttons
181   \param theParent parent widget
182   \return pointer to the created frame
183 */
184 QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
185 {
186   QGroupBox* aFrame = new QGroupBox(theParent);
187
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);
192
193   QHBoxLayout* aLay = new QHBoxLayout(aFrame);
194   aLay->setMargin(MARGIN);
195   aLay->setSpacing(SPACING);
196
197   aLay->addWidget(myOkBtn);
198   aLay->addSpacing(10);
199   aLay->addWidget(myApplyBtn);
200   aLay->addSpacing(10);
201   aLay->addStretch();
202   aLay->addWidget(myCloseBtn);
203   aLay->addWidget(myHelpBtn);
204
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()));
210
211   return aFrame;
212 }
213
214 /*!
215   \brief Destructor
216 */
217 SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg()
218 {
219 }
220
221 /*!
222   \brief Init dialog fields, connect signals and slots, show dialog
223 */
224 void SMESHGUI_GroupOpDlg::Init()
225 {
226   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
227   
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()));
232
233   // set selection mode
234   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
235     aViewWindow->SetSelectionMode(ActorSelection);
236   mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
237 }
238
239 /*!
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
244 */
245 bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theListGrp )
246 {
247   if ( theListGrp.isEmpty() )
248   {
249     SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
250                                   tr("INCORRECT_ARGUMENTS") );
251     return false;
252   }
253
254   int aMeshId = -1, aGrpType = -1;
255   QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter;
256   for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter )
257   {
258     SMESH::SMESH_GroupBase_var aGrp = *anIter;
259     if ( CORBA::is_nil( aGrp ) )
260       continue; // nonsence
261
262     SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh();
263     if ( CORBA::is_nil( aMesh ) )
264       continue;
265
266     // mesh id
267     int aCurrId = aMesh->GetId();
268     if ( aMeshId == -1 )
269       aMeshId = aCurrId;
270     else 
271     {
272       if ( aMeshId != aCurrId )
273       {
274         aMeshId = -1; // different meshes
275         break;
276       }
277     }
278
279     // group type
280     int aCurrType = aGrp->GetType();
281     if ( aGrpType == -1 )
282       aGrpType = aCurrType;
283     else 
284     {
285       if ( aGrpType != aCurrType )
286       {
287         aGrpType = -1; // different types
288         break;
289       }
290     }
291
292   }
293
294   if ( aMeshId == -1 )
295   {
296     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
297                                  tr("DIFF_MESHES"));
298     return false;
299   }
300
301   if ( aGrpType == -1 ) 
302   {
303     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
304                                  tr("DIFF_TYPES"));
305     return false;
306   }
307
308   return true;
309 }
310
311 /*!
312   \brief SLOT called when "Ok" button pressed performs operation and closes dialog box
313 */
314 void SMESHGUI_GroupOpDlg::onOk()
315 {
316   setIsApplyAndClose( true );
317   if ( onApply() )
318     reject();
319   setIsApplyAndClose( false );
320 }
321
322 /*!
323   \brief SLOT called when dialog is closed
324 */
325 void SMESHGUI_GroupOpDlg::reject()
326 {
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();
333   reset();
334   QDialog::reject();
335 }
336
337 /*!
338   \brief SLOT called when "Help" button pressed shows "Help" page
339 */
340 void SMESHGUI_GroupOpDlg::onHelp()
341 {
342   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
343   if (app) 
344     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
345   else {
346     QString platform;
347 #ifdef WIN32
348     platform = "winapplication";
349 #else
350     platform = "application";
351 #endif
352     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
353                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
354                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
355                                                                  platform)).
356                              arg(myHelpFileName));
357   }
358 }
359
360 /*!
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
365 */
366 bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList<SMESH::SMESH_GroupBase_var>& theOutList, 
367                                              QStringList& theOutNames )
368 {
369   theOutList.clear();
370
371   theOutList.clear();
372   theOutNames.clear();
373
374   SALOME_ListIO aListIO;
375   mySelectionMgr->selectedObjects( aListIO );
376   SALOME_ListIteratorOfListIO anIter ( aListIO );
377   for ( ; anIter.More(); anIter.Next()) 
378   {
379     SMESH::SMESH_GroupBase_var aGroup =
380       SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
381     if ( !aGroup->_is_nil()) 
382     {
383       theOutList.append( aGroup );
384       theOutNames.append( aGroup->GetName() );
385     }
386   }
387
388   return theOutList.count() > 0;
389 }
390
391 /*!
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
395 */
396 SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert( 
397   const QList<SMESH::SMESH_GroupBase_var>& theIn )
398 {
399   SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
400   aList->length( theIn.count() );
401
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;
405
406   return aList._retn();
407 }
408
409 /*!
410   \brief Get color to be assigned to group
411   \return color to be assigned to group
412 */
413 SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
414 {
415   QColor aQColor = myColorBtn->color();
416
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;
421
422   return aColor;
423 }
424
425 /*!
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
429 */
430 void SMESHGUI_GroupOpDlg::onSelectionDone()
431 {
432 }
433
434 /*!
435   \brief Calls onSelectionDone() and setVisible() method of base class
436   \param visible the visible state of the dialog 
437 */
438 void SMESHGUI_GroupOpDlg::setVisible( bool visible )
439 {
440   if ( visible )
441   {
442     onSelectionDone();
443     resize( minimumSizeHint().width(), sizeHint().height() );
444   }
445   QDialog::setVisible( visible );
446 }
447
448 /*!
449   \brief SLOT called when dialog must be deativated
450 */
451 void SMESHGUI_GroupOpDlg::onDeactivate()
452 {
453   setEnabled(false);
454   mySelectionMgr->clearFilters();
455 }
456
457 /*!
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
460 */
461 void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
462 {
463   mySMESHGUI->EmitSignalDeactivateDialog();
464   setEnabled(true);
465   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
466     aViewWindow->SetSelectionMode(ActorSelection);
467   mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
468 }
469
470 /*!
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
474 */
475 void SMESHGUI_GroupOpDlg::reset()
476 {
477   myNameEdit->setText("");
478   myNameEdit->setFocus();
479 }
480
481 /*!
482   \brief Gets name of group to be created
483   \return name of group to be created
484   \sa setName()
485 */
486 QString SMESHGUI_GroupOpDlg::getName() const
487 {
488   return myNameEdit->text();
489 }
490
491 /*!
492   \brief Sets name of group to be created
493   \param theName name of group to be created
494   \sa getName()
495 */
496 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
497 {
498   myNameEdit->setText( theName );
499 }
500
501 /*!
502   \brief Provides reaction on \93F1\94 button pressing
503   \param e  key press event
504 */
505 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
506 {
507   QDialog::keyPressEvent( e );
508   if ( e->isAccepted() )
509     return;
510
511   if ( e->key() == Qt::Key_F1 ) {
512     e->accept();
513     onHelp();
514   }
515 }
516
517 /*!
518   \brief This virtual slot does nothing and should be redefined in derived classes
519   \return return false;
520 */
521 bool SMESHGUI_GroupOpDlg::onApply()
522 {
523   return false;
524 }
525
526 /*!
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()
531 */
532 void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
533 {
534   myIsApplyAndClose = theFlag;
535 }
536
537 /*!
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()
542 */
543 bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
544 {
545   return myIsApplyAndClose;
546 }
547
548 // === === === === === === === === === === === === === === === === === === === === === 
549
550 /*!
551   \brief Constructor
552   \param theModule module
553 */
554 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
555 : SMESHGUI_GroupOpDlg( theModule )
556 {
557   setWindowTitle(tr("UNION_OF_GROUPS"));
558   setHelpFileName( "using_operations_on_groups_page.html#union_anchor" );
559
560   QGroupBox* anArgGrp = getArgGrp();
561   myListWg = new QListWidget( anArgGrp );
562
563   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
564   aLay->addWidget( myListWg );
565 }
566
567 /*!
568   \brief Destructor
569 */
570 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
571 {
572 }
573
574 /*!
575   \brief This virtual method redefined from the base class resets state 
576   of the dialog, initializes its fields with default value, etc. 
577 */
578 void SMESHGUI_UnionGroupsDlg::reset()
579 {
580   SMESHGUI_GroupOpDlg::reset();
581   myListWg->clear();
582   myGroups.clear();
583 }
584
585 /*!
586   \brief SLOT called when apply button is pressed performs operation
587   \return TRUE if operation has been completed successfully, FALSE otherwise
588 */
589 bool SMESHGUI_UnionGroupsDlg::onApply()
590 {
591   if ( getSMESHGUI()->isActiveStudyLocked())
592     return false;
593
594   // Verify validity of group name
595   if ( getName() == "" ) 
596   {
597     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
598                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
599     return false;
600   }
601
602   if ( !isValid( myGroups ) )
603     return false;
604
605   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
606   QString aName = getName();
607   
608   bool aRes = false;
609   QStringList anEntryList;
610   try
611   {
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 ) )
616     {
617       aNewGrp->SetColor(  getColor() );
618       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
619         anEntryList.append( aSObject->GetID().c_str() );
620       aRes = true;
621     }
622   }
623   catch( ... )
624   {
625     aRes = false;
626   }
627
628   if ( aRes ) 
629   {
630     SMESHGUI::Modified();
631     getSMESHGUI()->updateObjBrowser(true);
632     reset();
633     if( LightApp_Application* anApp =
634         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
635       anApp->browseObjects( anEntryList, isApplyAndClose() );
636     return true;
637   } 
638   else 
639   {
640     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
641                               tr("SMESH_OPERATION_FAILED"));
642     return false;
643   }
644 }
645
646 /*!
647   \brief SLOT, called when selection is changed, updates corresponding GUI controls
648 */
649 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
650 {
651   QStringList aNames;
652   getSelectedGroups( myGroups, aNames );
653   myListWg->clear();
654   myListWg->addItems( aNames );
655 }
656
657 // === === === === === === === === === === === === === === === === === === === === === 
658
659 /*!
660   \brief Constructor
661   \param theModule module
662 */
663 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
664 : SMESHGUI_GroupOpDlg( theModule )
665 {
666   setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
667   setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
668
669   QGroupBox* anArgGrp = getArgGrp();
670   myListWg = new QListWidget( anArgGrp );
671
672   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
673   aLay->addWidget( myListWg );
674 }
675
676 /*!
677   \brief Destructor
678 */
679 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
680 {
681 }
682
683 /*!
684   \brief This virtual method redefined from the base class resets state 
685   of the dialog, initializes its fields with default value, etc. 
686 */
687 void SMESHGUI_IntersectGroupsDlg::reset()
688 {
689   SMESHGUI_GroupOpDlg::reset();
690   myListWg->clear();
691   myGroups.clear();
692 }
693
694 /*!
695   \brief SLOT called when apply button is pressed performs operation
696   \return TRUE if operation has been completed successfully, FALSE otherwise
697 */
698 bool SMESHGUI_IntersectGroupsDlg::onApply()
699 {
700   if ( getSMESHGUI()->isActiveStudyLocked())
701     return false;
702
703   // Verify validity of group name
704   if ( getName() == "" ) 
705   {
706     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
707                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
708     return false;
709   }
710
711   if ( !isValid( myGroups ) )
712     return false;
713
714   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
715   QString aName = getName();
716   
717   bool aRes = false;
718   QStringList anEntryList;
719   try
720   {
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 ) )
725     {
726       aNewGrp->SetColor(  getColor() );
727       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
728         anEntryList.append( aSObject->GetID().c_str() );
729       aRes = true;
730     }
731   }
732   catch( ... )
733   {
734     aRes = false;
735   }
736
737   if ( aRes ) 
738   {
739     SMESHGUI::Modified();
740     getSMESHGUI()->updateObjBrowser(true);
741     reset();
742     if( LightApp_Application* anApp =
743         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
744       anApp->browseObjects( anEntryList, isApplyAndClose() );
745     return true;
746   } 
747   else 
748   {
749     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
750                               tr("SMESH_OPERATION_FAILED"));
751     return false;
752   }
753 }
754
755 /*!
756   \brief SLOT, called when selection is changed, updates corresponding GUI controls
757 */
758 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
759 {
760   QStringList aNames;
761   getSelectedGroups( myGroups, aNames );
762   myListWg->clear();
763   myListWg->addItems( aNames );
764 }
765
766 // === === === === === === === === === === === === === === === === === === === === === 
767
768 /*!
769   \brief Constructor
770   \param theModule module
771 */
772 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
773 : SMESHGUI_GroupOpDlg( theModule )
774 {
775   setWindowTitle(tr("CUT_OF_GROUPS"));
776   setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
777
778   QGroupBox* anArgGrp = getArgGrp();
779
780   QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
781   
782   // frame 1
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 );
789
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 );
797
798
799   // frame 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 );
806
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 );
814
815   // create button group 
816
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 );
824   
825   // fill layout
826   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
827   aLay->setSpacing( SPACING );
828   aLay->addWidget( aFrame1 );
829   aLay->addWidget( aFrame2 );
830 }
831
832 /*!
833   \brief Destructor
834 */
835 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
836 {
837 }
838
839 /*!
840   \brief This virtual method redefined from the base class resets state 
841   of the dialog, initializes its fields with default value, etc. 
842 */
843 void SMESHGUI_CutGroupsDlg::reset()
844 {
845   SMESHGUI_GroupOpDlg::reset();
846
847   myListWg1->clear();
848   myGroups1.clear();
849
850   myListWg2->clear();
851   myGroups2.clear();
852 }
853
854 /*!
855   \brief SLOT called when apply button is pressed performs operation
856   \return TRUE if operation has been completed successfully, FALSE otherwise
857 */
858 bool SMESHGUI_CutGroupsDlg::onApply()
859 {
860   if ( getSMESHGUI()->isActiveStudyLocked())
861     return false;
862
863   // Verify validity of group name
864   if ( getName() == "" ) 
865   {
866     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
867                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
868     return false;
869   }
870
871   if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
872   {
873     SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
874                                   SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
875     return false;
876   }
877
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 );
882
883   if ( !isValid( aGroups ) )
884     return false;
885
886   SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
887   QString aName = getName();
888   
889   bool aRes = false;
890   QStringList anEntryList;
891   try
892   {
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 ) )
898     {
899       aNewGrp->SetColor(  getColor() );
900       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
901         anEntryList.append( aSObject->GetID().c_str() );
902       aRes = true;
903     }
904   }
905   catch( ... )
906   {
907     aRes = false;
908   }
909
910   if ( aRes ) 
911   {
912     SMESHGUI::Modified();
913     getSMESHGUI()->updateObjBrowser(true);
914     reset();
915     if( LightApp_Application* anApp =
916         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
917       anApp->browseObjects( anEntryList, isApplyAndClose() );
918     return true;
919   } 
920   else 
921   {
922     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
923                               tr("SMESH_OPERATION_FAILED"));
924     return false;
925   }
926 }
927
928 /*!
929   \brief SLOT, called when selection is changed, updates corresponding GUI controls
930 */
931 void SMESHGUI_CutGroupsDlg::onSelectionDone()
932 {
933   QStringList aNames;
934   if ( myBtn2->isChecked() )
935   {
936     getSelectedGroups( myGroups2, aNames );
937     myListWg2->clear();
938     myListWg2->addItems( aNames );
939   }
940   else 
941   {
942     getSelectedGroups( myGroups1, aNames );
943     myListWg1->clear();
944     myListWg1->addItems( aNames );
945   }
946 }
947
948 // === === === === === === === === === === === === === === === === === === === === === 
949
950 /*!
951   \brief Constructor
952   \param theModule module
953 */
954 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
955 : SMESHGUI_GroupOpDlg( theModule )
956 {
957   setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
958   setHelpFileName( "group_of_underlying_elements_page.html" );
959
960   QGroupBox* anArgGrp = getArgGrp();
961
962   QLabel* aLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
963   
964   myCombo = new QComboBox( anArgGrp );
965   static QStringList anItems;
966   if ( anItems.isEmpty() )
967   {
968     anItems.append( tr( "NODE" ) );
969     anItems.append( tr( "EDGE" ) );
970     anItems.append( tr( "FACE" ) );
971     anItems.append( tr( "VOLUME" ) );
972   }
973   myCombo->addItems( anItems );
974   myCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
975   
976   myListWg = new QListWidget( anArgGrp );
977
978   // layout
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 );
984 }
985
986 /*!
987   \brief Destructor
988 */
989 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
990 {
991 }
992
993 /*!
994   \brief This virtual method redefined from the base class resets state 
995   of the dialog, initializes its fields with default value, etc. 
996 */
997 void SMESHGUI_DimGroupDlg::reset()
998 {
999   SMESHGUI_GroupOpDlg::reset();
1000   myListWg->clear();
1001   myGroups.clear();
1002 }
1003
1004 /*!
1005   \brief Gets elements type
1006   \return elements type
1007   \sa setElementType()
1008 */
1009 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
1010 {
1011   return (SMESH::ElementType)( myCombo->currentIndex() + 1 );
1012 }
1013
1014 /*!
1015   \brief Sets elements type
1016   \param theElemType elements type
1017   \sa getElementType()
1018 */
1019 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
1020 {
1021   myCombo->setCurrentIndex( theElemType - 1 );
1022 }
1023
1024 /*!
1025   \brief SLOT called when apply button is pressed performs operation
1026   \return TRUE if operation has been completed successfully, FALSE otherwise
1027 */
1028 bool SMESHGUI_DimGroupDlg::onApply()
1029 {
1030   if ( getSMESHGUI()->isActiveStudyLocked())
1031     return false;
1032
1033   // Verify validity of group name
1034   if ( getName() == "" ) 
1035   {
1036     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
1037                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
1038     return false;
1039   }
1040
1041   if ( !isValid( myGroups ) )
1042     return false;
1043
1044   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1045   QString aName = getName();
1046   
1047   bool aRes = false;
1048   QStringList anEntryList;
1049   try
1050   {
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 ) )
1056     {
1057       aNewGrp->SetColor(  getColor() );
1058       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
1059         anEntryList.append( aSObject->GetID().c_str() );
1060       aRes = true;
1061     }
1062   }
1063   catch( ... )
1064   {
1065     aRes = false;
1066   }
1067
1068   if ( aRes ) 
1069   {
1070     SMESHGUI::Modified();
1071     getSMESHGUI()->updateObjBrowser(true);
1072     reset();
1073     if( LightApp_Application* anApp =
1074         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1075       anApp->browseObjects( anEntryList, isApplyAndClose() );
1076     return true;
1077   } 
1078   else 
1079   {
1080     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1081                               tr("SMESH_OPERATION_FAILED"));
1082     return false;
1083   }
1084 }
1085
1086 /*!
1087   \brief SLOT, called when selection is changed, updates corresponding GUI controls
1088 */
1089 void SMESHGUI_DimGroupDlg::onSelectionDone()
1090 {
1091   QStringList aNames;
1092   getSelectedGroups( myGroups, aNames );
1093   myListWg->clear();
1094   myListWg->addItems( aNames );
1095 }
1096
1097