Salome HOME
Merge from V5_1_main 14/05/2010
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupOpDlg.cxx
1 //  Copyright (C) 2007-2010  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 // Qt includes
49 #include <QHBoxLayout>
50 #include <QVBoxLayout>
51 #include <QGridLayout>
52 #include <QPushButton>
53 #include <QGroupBox>
54 #include <QLabel>
55 #include <QLineEdit>
56 #include <QKeyEvent>
57 #include <QListWidget>
58 #include <QButtonGroup>
59 #include <SALOME_ListIteratorOfListIO.hxx>
60 #include <QComboBox>
61 #include <QtxColorButton.h>
62
63 #define SPACING 6
64 #define MARGIN  11
65
66 /*!
67  *  Class       : SMESHGUI_GroupOpDlg
68  *  Description : Perform boolean operations on groups
69  */
70
71 /*!
72   \brief Constructor
73   \param theModule pointer on module instance
74 */
75 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule )
76   : QDialog( SMESH::GetDesktop( theModule ) ),
77     mySMESHGUI( theModule ),
78     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
79 {
80   setModal(false);
81
82   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
83
84   QVBoxLayout* aDlgLay = new QVBoxLayout (this);
85   aDlgLay->setMargin(MARGIN);
86   aDlgLay->setSpacing(SPACING);
87
88   QWidget* aMainFrame = createMainFrame  (this);
89   QWidget* aBtnFrame  = createButtonFrame(this);
90
91   aDlgLay->addWidget(aMainFrame);
92   aDlgLay->addWidget(aBtnFrame);
93
94   Init();
95 }
96
97 /*!
98   \brief Creates frame containing dialog's input fields
99   \param theParent parent widget
100   \return pointer on created widget
101 */
102 QWidget* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent )
103 {
104   QWidget* aMainGrp = new QWidget(theParent);
105   QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
106   aLay->setMargin(0);
107   aLay->setSpacing(SPACING);
108   
109   // ------------------------------------------------------
110   QGroupBox* aNameGrp = new QGroupBox(tr("NAME"), aMainGrp);
111   QHBoxLayout* aNameGrpLayout = new QHBoxLayout(aNameGrp);
112   aNameGrpLayout->setMargin(MARGIN);
113   aNameGrpLayout->setSpacing(SPACING);
114
115   QLabel* aNameLab = new QLabel(tr("RESULT_NAME"), aNameGrp);
116   myNameEdit = new QLineEdit(aNameGrp);
117
118   aNameGrpLayout->addWidget(aNameLab);
119   aNameGrpLayout->addWidget(myNameEdit);
120
121   // ------------------------------------------------------
122   myArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp);
123
124
125   // ------------------------------------------------------
126   
127   QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
128   QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
129   aColorBoxLayout->setMargin(MARGIN);
130   aColorBoxLayout->setSpacing(SPACING);
131
132   QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
133   myColorBtn = new QtxColorButton(aColorBox);
134   myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding, 
135                              myColorBtn->sizePolicy().verticalPolicy() );
136
137   aColorBoxLayout->addWidget(aColorLab);
138   aColorBoxLayout->addWidget(myColorBtn);
139
140   // ------------------------------------------------------
141   aLay->addWidget( aNameGrp );
142   aLay->addWidget( myArgGrp );
143   aLay->addWidget( aColorBox );
144
145   return aMainGrp;
146 }
147
148 /*!
149   \brief Gets pointer on arguments group box
150   \return pointer on arguments group box
151 */
152 QGroupBox* SMESHGUI_GroupOpDlg::getArgGrp() const
153 {
154   return myArgGrp;
155 }
156
157 /*!
158   \brief Sets help file name
159   \param theFName help file name
160 */
161 void SMESHGUI_GroupOpDlg::setHelpFileName( const QString& theFName )
162 {
163   myHelpFileName = theFName;
164 }
165
166 /*!
167   \brief Gets pointer to the module instance
168   \return pointer to the module instance
169 */
170 SMESHGUI* SMESHGUI_GroupOpDlg::getSMESHGUI() const
171 {
172   return mySMESHGUI;
173 }
174
175 /*!
176   \brief Create frame containing buttons
177   \param theParent parent widget
178   \return pointer to the created frame
179 */
180 QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
181 {
182   QGroupBox* aFrame = new QGroupBox(theParent);
183
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);
188
189   QHBoxLayout* aLay = new QHBoxLayout(aFrame);
190   aLay->setMargin(MARGIN);
191   aLay->setSpacing(SPACING);
192
193   aLay->addWidget(myOkBtn);
194   aLay->addSpacing(10);
195   aLay->addWidget(myApplyBtn);
196   aLay->addSpacing(10);
197   aLay->addStretch();
198   aLay->addWidget(myCloseBtn);
199   aLay->addWidget(myHelpBtn);
200
201   // connect signals and slots
202   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
203   connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
204   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
205   connect(myHelpBtn,  SIGNAL(clicked()), SLOT(onHelp()));
206
207   return aFrame;
208 }
209
210 /*!
211   \brief Destructor
212 */
213 SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg()
214 {
215 }
216
217 /*!
218   \brief Init dialog fields, connect signals and slots, show dialog
219 */
220 void SMESHGUI_GroupOpDlg::Init()
221 {
222   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
223   
224   // selection and SMESHGUI
225   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
226   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
227   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(ClickOnClose()));
228
229   // set selection mode
230   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
231     aViewWindow->SetSelectionMode(ActorSelection);
232   mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
233 }
234
235 /*!
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
240 */
241 bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theListGrp )
242 {
243   if ( theListGrp.isEmpty() )
244   {
245     SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
246                                   tr("INCORRECT_ARGUMENTS") );
247     return false;
248   }
249
250   int aMeshId = -1, aGrpType = -1;
251   QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter;
252   for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter )
253   {
254     SMESH::SMESH_GroupBase_var aGrp = *anIter;
255     if ( CORBA::is_nil( aGrp ) )
256       continue; // nonsence
257
258     SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh();
259     if ( CORBA::is_nil( aMesh ) )
260       continue;
261
262     // mesh id
263     int aCurrId = aMesh->GetId();
264     if ( aMeshId == -1 )
265       aMeshId = aCurrId;
266     else 
267     {
268       if ( aMeshId != aCurrId )
269       {
270         aMeshId = -1; // different meshes
271         break;
272       }
273     }
274
275     // group type
276     int aCurrType = aGrp->GetType();
277     if ( aGrpType == -1 )
278       aGrpType = aCurrType;
279     else 
280     {
281       if ( aGrpType != aCurrType )
282       {
283         aGrpType = -1; // different types
284         break;
285       }
286     }
287
288   }
289
290   if ( aMeshId == -1 )
291   {
292     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
293                                  tr("DIFF_MESHES"));
294     return false;
295   }
296
297   if ( aGrpType == -1 ) 
298   {
299     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
300                                  tr("DIFF_TYPES"));
301     return false;
302   }
303
304   return true;
305 }
306
307 /*!
308   \brief SLOT called when "Ok" button pressed performs operation and closes dialog box
309 */
310 void SMESHGUI_GroupOpDlg::onOk()
311 {
312   if ( onApply() )
313     onClose();
314 }
315
316 /*!
317   \brief SLOT called when "Close" button pressed closes dialog
318 */
319 void SMESHGUI_GroupOpDlg::onClose()
320 {
321   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
322     aViewWindow->SetSelectionMode(ActorSelection);
323   disconnect( mySelectionMgr, 0, this, 0 );
324   disconnect( mySMESHGUI, 0, this, 0 );
325   mySMESHGUI->ResetState();
326   mySelectionMgr->clearFilters();
327   reset();
328   reject();
329 }
330
331 /*!
332   \brief SLOT called when "Help" button pressed shows "Help" page
333 */
334 void SMESHGUI_GroupOpDlg::onHelp()
335 {
336   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
337   if (app) 
338     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
339   else {
340     QString platform;
341 #ifdef WIN32
342     platform = "winapplication";
343 #else
344     platform = "application";
345 #endif
346     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
347                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
348                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
349                                                                  platform)).
350                              arg(myHelpFileName));
351   }
352 }
353
354 /*!
355   \brief Gets list of currently selected groups from selection manager
356   \param theOutList out list of groups
357   \param theOutNames out list of group of group names
358   \return TRUE if operation theOutList is not empty, FALSE otherwise
359 */
360 bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList<SMESH::SMESH_GroupBase_var>& theOutList, 
361                                              QStringList& theOutNames )
362 {
363   theOutList.clear();
364
365   theOutList.clear();
366   theOutNames.clear();
367
368   SALOME_ListIO aListIO;
369   mySelectionMgr->selectedObjects( aListIO );
370   SALOME_ListIteratorOfListIO anIter ( aListIO );
371   for ( ; anIter.More(); anIter.Next()) 
372   {
373     SMESH::SMESH_GroupBase_var aGroup =
374       SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
375     if ( !aGroup->_is_nil()) 
376     {
377       theOutList.append( aGroup );
378       theOutNames.append( aGroup->GetName() );
379     }
380   }
381
382   return theOutList.count() > 0;
383 }
384
385 /*!
386   \brief Converts QT-list of group to the list acceptable by IDL interface
387   \param theIn input list
388   \return list acceptable by IDL interface
389 */
390 SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert( 
391   const QList<SMESH::SMESH_GroupBase_var>& theIn )
392 {
393   SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
394   aList->length( theIn.count() );
395
396   QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = theIn.begin();
397   for ( int i = 0; anIter != theIn.end(); ++anIter, ++i )
398     aList[ i ] = *anIter;
399
400   return aList._retn();
401 }
402
403 /*!
404   \brief Get color to be assigned to group
405   \return color to be assigned to group
406 */
407 SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
408 {
409   QColor aQColor = myColorBtn->color();
410
411   SALOMEDS::Color aColor;
412   aColor.R = (float)aQColor.red() / 255.0;
413   aColor.G = (float)aQColor.green() / 255.0;
414   aColor.B = (float)aQColor.blue() / 255.0;
415
416   return aColor;
417 }
418
419 /*!
420   \brief SLOT, called when selection is changed. Current implementation does 
421    nothing. The method should be redefined in derived classes to update 
422    corresponding GUI controls
423 */
424 void SMESHGUI_GroupOpDlg::onSelectionDone()
425 {
426 }
427
428 /*!
429   \brief Calls onSelectionDone() and setVisible() method of base class
430   \param visible the visible state of the dialog 
431 */
432 void SMESHGUI_GroupOpDlg::setVisible( bool visible )
433 {
434   if ( visible )
435   {
436     onSelectionDone();
437     resize( minimumSizeHint().width(), sizeHint().height() );
438   }
439   QDialog::setVisible( visible );
440 }
441
442 /*!
443   \brief SLOT called when dialog must be deativated
444 */
445 void SMESHGUI_GroupOpDlg::onDeactivate()
446 {
447   setEnabled(false);
448   mySelectionMgr->clearFilters();
449 }
450
451 /*!
452   \brief Event filter updates selection mode and selection filter. This virtual method 
453   is redefined from the base class it is called when dialog obtains input focus
454 */
455 void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
456 {
457   mySMESHGUI->EmitSignalDeactivateDialog();
458   setEnabled(true);
459   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
460     aViewWindow->SetSelectionMode(ActorSelection);
461   mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
462 }
463
464 /*!
465   \brief Provides reaction on close event, closes the dialog box
466 */
467 void SMESHGUI_GroupOpDlg::closeEvent(QCloseEvent*)
468 {
469   onClose();
470 }
471
472 /*!
473   \brief Resets state of the dialog, initializes its fields with default value, etc. 
474   Usually called by onApply() slot to reinitialize dialog  fields. This virtual method 
475   should be redefined in derived class to update its own fileds
476 */
477 void SMESHGUI_GroupOpDlg::reset()
478 {
479   myNameEdit->setText("");
480   myNameEdit->setFocus();
481 }
482
483 /*!
484   \brief Gets name of group to be created
485   \return name of group to be created
486   \sa setName()
487 */
488 QString SMESHGUI_GroupOpDlg::getName() const
489 {
490   return myNameEdit->text();
491 }
492
493 /*!
494   \brief Sets name of group to be created
495   \param theName name of group to be created
496   \sa getName()
497 */
498 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
499 {
500   myNameEdit->setText( theName );
501 }
502
503 /*!
504   \brief Provides reaction on \93F1\94 button pressing
505   \param e  key press event
506 */
507 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
508 {
509   QDialog::keyPressEvent( e );
510   if ( e->isAccepted() )
511     return;
512
513   if ( e->key() == Qt::Key_F1 ) {
514     e->accept();
515     onHelp();
516   }
517 }
518
519 /*!
520   \brief This virtual slot does nothing and should be redefined in derived classes
521   \return return false;
522 */
523 bool SMESHGUI_GroupOpDlg::onApply()
524 {
525   return false;
526 }
527
528 // === === === === === === === === === === === === === === === === === === === === === 
529
530 /*!
531   \brief Constructor
532   \param theModule module
533 */
534 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
535 : SMESHGUI_GroupOpDlg( theModule )
536 {
537   setWindowTitle(tr("UNION_OF_GROUPS"));
538   setHelpFileName( "using_operations_on_groups_page.html#union_anchor" );
539
540   QGroupBox* anArgGrp = getArgGrp();
541   myListWg = new QListWidget( anArgGrp );
542
543   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
544   aLay->addWidget( myListWg );
545 }
546
547 /*!
548   \brief Destructor
549 */
550 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
551 {
552 }
553
554 /*!
555   \brief This virtual method redefined from the base class resets state 
556   of the dialog, initializes its fields with default value, etc. 
557 */
558 void SMESHGUI_UnionGroupsDlg::reset()
559 {
560   SMESHGUI_GroupOpDlg::reset();
561   myListWg->clear();
562   myGroups.clear();
563 }
564
565 /*!
566   \brief SLOT called when apply button is pressed performs operation
567   \return TRUE if operation has been completed successfully, FALSE otherwise
568 */
569 bool SMESHGUI_UnionGroupsDlg::onApply()
570 {
571   if ( getSMESHGUI()->isActiveStudyLocked())
572     return false;
573
574   // Verify validity of group name
575   if ( getName() == "" ) 
576   {
577     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
578                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
579     return false;
580   }
581
582   if ( !isValid( myGroups ) )
583     return false;
584
585   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
586   QString aName = getName();
587   
588   bool aRes = false;
589   try
590   {
591     SMESH::ListOfGroups_var aList = convert( myGroups );
592     SMESH::SMESH_Group_var aNewGrp = 
593       aMesh->UnionListOfGroups( aList, aName.toLatin1().constData() );
594     if ( !CORBA::is_nil( aNewGrp ) )
595     {
596       aNewGrp->SetColor(  getColor() );
597       aRes = true;
598     }
599   }
600   catch( ... )
601   {
602     aRes = false;
603   }
604
605   if ( aRes ) 
606   {
607     getSMESHGUI()->updateObjBrowser(true);
608     reset();
609     return true;
610   } 
611   else 
612   {
613     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
614                               tr("SMESH_OPERATION_FAILED"));
615     return false;
616   }
617 }
618
619 /*!
620   \brief SLOT, called when selection is changed, updates corresponding GUI controls
621 */
622 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
623 {
624   QStringList aNames;
625   getSelectedGroups( myGroups, aNames );
626   myListWg->clear();
627   myListWg->addItems( aNames );
628 }
629
630 // === === === === === === === === === === === === === === === === === === === === === 
631
632 /*!
633   \brief Constructor
634   \param theModule module
635 */
636 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
637 : SMESHGUI_GroupOpDlg( theModule )
638 {
639   setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
640   setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
641
642   QGroupBox* anArgGrp = getArgGrp();
643   myListWg = new QListWidget( anArgGrp );
644
645   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
646   aLay->addWidget( myListWg );
647 }
648
649 /*!
650   \brief Destructor
651 */
652 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
653 {
654 }
655
656 /*!
657   \brief This virtual method redefined from the base class resets state 
658   of the dialog, initializes its fields with default value, etc. 
659 */
660 void SMESHGUI_IntersectGroupsDlg::reset()
661 {
662   SMESHGUI_GroupOpDlg::reset();
663   myListWg->clear();
664   myGroups.clear();
665 }
666
667 /*!
668   \brief SLOT called when apply button is pressed performs operation
669   \return TRUE if operation has been completed successfully, FALSE otherwise
670 */
671 bool SMESHGUI_IntersectGroupsDlg::onApply()
672 {
673   if ( getSMESHGUI()->isActiveStudyLocked())
674     return false;
675
676   // Verify validity of group name
677   if ( getName() == "" ) 
678   {
679     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
680                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
681     return false;
682   }
683
684   if ( !isValid( myGroups ) )
685     return false;
686
687   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
688   QString aName = getName();
689   
690   bool aRes = false;
691   try
692   {
693     SMESH::ListOfGroups_var aList = convert( myGroups );
694     SMESH::SMESH_Group_var aNewGrp = 
695       aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() );
696     if ( !CORBA::is_nil( aNewGrp ) )
697     {
698       aNewGrp->SetColor(  getColor() );
699       aRes = true;
700     }
701   }
702   catch( ... )
703   {
704     aRes = false;
705   }
706
707   if ( aRes ) 
708   {
709     getSMESHGUI()->updateObjBrowser(true);
710     reset();
711     return true;
712   } 
713   else 
714   {
715     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
716                               tr("SMESH_OPERATION_FAILED"));
717     return false;
718   }
719 }
720
721 /*!
722   \brief SLOT, called when selection is changed, updates corresponding GUI controls
723 */
724 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
725 {
726   QStringList aNames;
727   getSelectedGroups( myGroups, aNames );
728   myListWg->clear();
729   myListWg->addItems( aNames );
730 }
731
732 // === === === === === === === === === === === === === === === === === === === === === 
733
734 /*!
735   \brief Constructor
736   \param theModule module
737 */
738 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
739 : SMESHGUI_GroupOpDlg( theModule )
740 {
741   setWindowTitle(tr("CUT_OF_GROUPS"));
742   setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
743
744   QGroupBox* anArgGrp = getArgGrp();
745
746   QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
747   
748   // frame 1
749   QFrame* aFrame1 = new QFrame( anArgGrp );
750   QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
751   aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
752   myBtn1 = new QPushButton( aFrame1 );
753   myBtn1->setIcon(aPix);
754   myListWg1 = new QListWidget( aFrame1 );
755
756   QGridLayout* aLay1 = new QGridLayout( aFrame1 );
757   aLay1->setSpacing( SPACING );
758   aLay1->addWidget( aLbl1, 0, 0 );
759   aLay1->addWidget( myBtn1, 0, 1 );
760   aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
761   //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
762   //aLay1->addItem( aHSpacer1, 0, 2 );
763
764
765   // frame 2
766   QFrame* aFrame2 = new QFrame( anArgGrp );
767   QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
768   aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
769   myBtn2 = new QPushButton( aFrame2 );
770   myBtn2->setIcon(aPix);
771   myListWg2 = new QListWidget( aFrame2 );
772
773   QGridLayout* aLay2 = new QGridLayout( aFrame2 );
774   aLay2->setSpacing( SPACING );
775   aLay2->addWidget( aLbl2, 0, 0 );
776   aLay2->addWidget( myBtn2, 0, 1 );
777   aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
778   //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
779   //aLay2->addItem( aHSpacer2, 0, 2 );
780
781   // create button group 
782
783   QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
784   aGrp->addButton( myBtn1, 0 );
785   aGrp->addButton( myBtn2, 1 );
786   myBtn1->setCheckable( true );
787   myBtn2->setCheckable( true );
788   aGrp->setExclusive( true );
789   myBtn1->setChecked( true );
790   
791   // fill layout
792   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
793   aLay->setSpacing( SPACING );
794   aLay->addWidget( aFrame1 );
795   aLay->addWidget( aFrame2 );
796 }
797
798 /*!
799   \brief Destructor
800 */
801 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
802 {
803 }
804
805 /*!
806   \brief This virtual method redefined from the base class resets state 
807   of the dialog, initializes its fields with default value, etc. 
808 */
809 void SMESHGUI_CutGroupsDlg::reset()
810 {
811   SMESHGUI_GroupOpDlg::reset();
812
813   myListWg1->clear();
814   myGroups1.clear();
815
816   myListWg2->clear();
817   myGroups2.clear();
818 }
819
820 /*!
821   \brief SLOT called when apply button is pressed performs operation
822   \return TRUE if operation has been completed successfully, FALSE otherwise
823 */
824 bool SMESHGUI_CutGroupsDlg::onApply()
825 {
826   if ( getSMESHGUI()->isActiveStudyLocked())
827     return false;
828
829   // Verify validity of group name
830   if ( getName() == "" ) 
831   {
832     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
833                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
834     return false;
835   }
836
837   if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
838   {
839     SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
840                                   SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
841     return false;
842   }
843
844   QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
845   QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
846   for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
847     aGroups.append( *anIter );
848
849   if ( !isValid( aGroups ) )
850     return false;
851
852   SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
853   QString aName = getName();
854   
855   bool aRes = false;
856   try
857   {
858     SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
859     SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
860     SMESH::SMESH_Group_var aNewGrp = 
861       aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() );
862     if ( !CORBA::is_nil( aNewGrp ) )
863     {
864       aNewGrp->SetColor(  getColor() );
865       aRes = true;
866     }
867   }
868   catch( ... )
869   {
870     aRes = false;
871   }
872
873   if ( aRes ) 
874   {
875     getSMESHGUI()->updateObjBrowser(true);
876     reset();
877     return true;
878   } 
879   else 
880   {
881     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
882                               tr("SMESH_OPERATION_FAILED"));
883     return false;
884   }
885 }
886
887 /*!
888   \brief SLOT, called when selection is changed, updates corresponding GUI controls
889 */
890 void SMESHGUI_CutGroupsDlg::onSelectionDone()
891 {
892   QStringList aNames;
893   if ( myBtn2->isChecked() )
894   {
895     getSelectedGroups( myGroups2, aNames );
896     myListWg2->clear();
897     myListWg2->addItems( aNames );
898   }
899   else 
900   {
901     getSelectedGroups( myGroups1, aNames );
902     myListWg1->clear();
903     myListWg1->addItems( aNames );
904   }
905 }
906
907 // === === === === === === === === === === === === === === === === === === === === === 
908
909 /*!
910   \brief Constructor
911   \param theModule module
912 */
913 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
914 : SMESHGUI_GroupOpDlg( theModule )
915 {
916   setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
917   setHelpFileName( "creating_groups_page.html#gui_create_dim_group" );
918
919   QGroupBox* anArgGrp = getArgGrp();
920
921   QLabel* aLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
922   
923   myCombo = new QComboBox( anArgGrp );
924   static QStringList anItems;
925   if ( anItems.isEmpty() )
926   {
927     anItems.append( tr( "NODE" ) );
928     anItems.append( tr( "EDGE" ) );
929     anItems.append( tr( "FACE" ) );
930     anItems.append( tr( "VOLUME" ) );
931   }
932   myCombo->addItems( anItems );
933   myCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
934   
935   myListWg = new QListWidget( anArgGrp );
936
937   // layout
938   QGridLayout* aLay = new QGridLayout( anArgGrp );
939   aLay->setSpacing( SPACING );
940   aLay->addWidget( aLbl, 0, 0 );
941   aLay->addWidget( myCombo, 0, 1 );
942   aLay->addWidget( myListWg, 1, 0, 1, 2 );
943 }
944
945 /*!
946   \brief Destructor
947 */
948 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
949 {
950 }
951
952 /*!
953   \brief This virtual method redefined from the base class resets state 
954   of the dialog, initializes its fields with default value, etc. 
955 */
956 void SMESHGUI_DimGroupDlg::reset()
957 {
958   SMESHGUI_GroupOpDlg::reset();
959   myListWg->clear();
960   myGroups.clear();
961 }
962
963 /*!
964   \brief Gets elements type
965   \return elements type
966   \sa setElementType()
967 */
968 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
969 {
970   return (SMESH::ElementType)( myCombo->currentIndex() + 1 );
971 }
972
973 /*!
974   \brief Sets elements type
975   \param theElemType elements type
976   \sa getElementType()
977 */
978 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
979 {
980   myCombo->setCurrentIndex( theElemType - 1 );
981 }
982
983 /*!
984   \brief SLOT called when apply button is pressed performs operation
985   \return TRUE if operation has been completed successfully, FALSE otherwise
986 */
987 bool SMESHGUI_DimGroupDlg::onApply()
988 {
989   if ( getSMESHGUI()->isActiveStudyLocked())
990     return false;
991
992   // Verify validity of group name
993   if ( getName() == "" ) 
994   {
995     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
996                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
997     return false;
998   }
999
1000   if ( !isValid( myGroups ) )
1001     return false;
1002
1003   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1004   QString aName = getName();
1005   
1006   bool aRes = false;
1007   try
1008   {
1009     SMESH::ListOfGroups_var aList = convert( myGroups );
1010     SMESH::ElementType anElemType = getElementType();
1011     SMESH::SMESH_Group_var aNewGrp = 
1012       aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData() );
1013     if ( !CORBA::is_nil( aNewGrp ) )
1014     {
1015       aNewGrp->SetColor(  getColor() );
1016       aRes = true;
1017     }
1018   }
1019   catch( ... )
1020   {
1021     aRes = false;
1022   }
1023
1024   if ( aRes ) 
1025   {
1026     getSMESHGUI()->updateObjBrowser(true);
1027     reset();
1028     return true;
1029   } 
1030   else 
1031   {
1032     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1033                               tr("SMESH_OPERATION_FAILED"));
1034     return false;
1035   }
1036 }
1037
1038 /*!
1039   \brief SLOT, called when selection is changed, updates corresponding GUI controls
1040 */
1041 void SMESHGUI_DimGroupDlg::onSelectionDone()
1042 {
1043   QStringList aNames;
1044   getSelectedGroups( myGroups, aNames );
1045   myListWg->clear();
1046   myListWg->addItems( aNames );
1047 }
1048
1049