Salome HOME
Merge from V5_1_main 10/06/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     SMESHGUI::Modified();
608     getSMESHGUI()->updateObjBrowser(true);
609     reset();
610     return true;
611   } 
612   else 
613   {
614     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
615                               tr("SMESH_OPERATION_FAILED"));
616     return false;
617   }
618 }
619
620 /*!
621   \brief SLOT, called when selection is changed, updates corresponding GUI controls
622 */
623 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
624 {
625   QStringList aNames;
626   getSelectedGroups( myGroups, aNames );
627   myListWg->clear();
628   myListWg->addItems( aNames );
629 }
630
631 // === === === === === === === === === === === === === === === === === === === === === 
632
633 /*!
634   \brief Constructor
635   \param theModule module
636 */
637 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
638 : SMESHGUI_GroupOpDlg( theModule )
639 {
640   setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
641   setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
642
643   QGroupBox* anArgGrp = getArgGrp();
644   myListWg = new QListWidget( anArgGrp );
645
646   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
647   aLay->addWidget( myListWg );
648 }
649
650 /*!
651   \brief Destructor
652 */
653 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
654 {
655 }
656
657 /*!
658   \brief This virtual method redefined from the base class resets state 
659   of the dialog, initializes its fields with default value, etc. 
660 */
661 void SMESHGUI_IntersectGroupsDlg::reset()
662 {
663   SMESHGUI_GroupOpDlg::reset();
664   myListWg->clear();
665   myGroups.clear();
666 }
667
668 /*!
669   \brief SLOT called when apply button is pressed performs operation
670   \return TRUE if operation has been completed successfully, FALSE otherwise
671 */
672 bool SMESHGUI_IntersectGroupsDlg::onApply()
673 {
674   if ( getSMESHGUI()->isActiveStudyLocked())
675     return false;
676
677   // Verify validity of group name
678   if ( getName() == "" ) 
679   {
680     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
681                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
682     return false;
683   }
684
685   if ( !isValid( myGroups ) )
686     return false;
687
688   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
689   QString aName = getName();
690   
691   bool aRes = false;
692   try
693   {
694     SMESH::ListOfGroups_var aList = convert( myGroups );
695     SMESH::SMESH_Group_var aNewGrp = 
696       aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() );
697     if ( !CORBA::is_nil( aNewGrp ) )
698     {
699       aNewGrp->SetColor(  getColor() );
700       aRes = true;
701     }
702   }
703   catch( ... )
704   {
705     aRes = false;
706   }
707
708   if ( aRes ) 
709   {
710     SMESHGUI::Modified();
711     getSMESHGUI()->updateObjBrowser(true);
712     reset();
713     return true;
714   } 
715   else 
716   {
717     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
718                               tr("SMESH_OPERATION_FAILED"));
719     return false;
720   }
721 }
722
723 /*!
724   \brief SLOT, called when selection is changed, updates corresponding GUI controls
725 */
726 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
727 {
728   QStringList aNames;
729   getSelectedGroups( myGroups, aNames );
730   myListWg->clear();
731   myListWg->addItems( aNames );
732 }
733
734 // === === === === === === === === === === === === === === === === === === === === === 
735
736 /*!
737   \brief Constructor
738   \param theModule module
739 */
740 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
741 : SMESHGUI_GroupOpDlg( theModule )
742 {
743   setWindowTitle(tr("CUT_OF_GROUPS"));
744   setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
745
746   QGroupBox* anArgGrp = getArgGrp();
747
748   QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
749   
750   // frame 1
751   QFrame* aFrame1 = new QFrame( anArgGrp );
752   QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
753   aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
754   myBtn1 = new QPushButton( aFrame1 );
755   myBtn1->setIcon(aPix);
756   myListWg1 = new QListWidget( aFrame1 );
757
758   QGridLayout* aLay1 = new QGridLayout( aFrame1 );
759   aLay1->setSpacing( SPACING );
760   aLay1->addWidget( aLbl1, 0, 0 );
761   aLay1->addWidget( myBtn1, 0, 1 );
762   aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
763   //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
764   //aLay1->addItem( aHSpacer1, 0, 2 );
765
766
767   // frame 2
768   QFrame* aFrame2 = new QFrame( anArgGrp );
769   QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
770   aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
771   myBtn2 = new QPushButton( aFrame2 );
772   myBtn2->setIcon(aPix);
773   myListWg2 = new QListWidget( aFrame2 );
774
775   QGridLayout* aLay2 = new QGridLayout( aFrame2 );
776   aLay2->setSpacing( SPACING );
777   aLay2->addWidget( aLbl2, 0, 0 );
778   aLay2->addWidget( myBtn2, 0, 1 );
779   aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
780   //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
781   //aLay2->addItem( aHSpacer2, 0, 2 );
782
783   // create button group 
784
785   QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
786   aGrp->addButton( myBtn1, 0 );
787   aGrp->addButton( myBtn2, 1 );
788   myBtn1->setCheckable( true );
789   myBtn2->setCheckable( true );
790   aGrp->setExclusive( true );
791   myBtn1->setChecked( true );
792   
793   // fill layout
794   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
795   aLay->setSpacing( SPACING );
796   aLay->addWidget( aFrame1 );
797   aLay->addWidget( aFrame2 );
798 }
799
800 /*!
801   \brief Destructor
802 */
803 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
804 {
805 }
806
807 /*!
808   \brief This virtual method redefined from the base class resets state 
809   of the dialog, initializes its fields with default value, etc. 
810 */
811 void SMESHGUI_CutGroupsDlg::reset()
812 {
813   SMESHGUI_GroupOpDlg::reset();
814
815   myListWg1->clear();
816   myGroups1.clear();
817
818   myListWg2->clear();
819   myGroups2.clear();
820 }
821
822 /*!
823   \brief SLOT called when apply button is pressed performs operation
824   \return TRUE if operation has been completed successfully, FALSE otherwise
825 */
826 bool SMESHGUI_CutGroupsDlg::onApply()
827 {
828   if ( getSMESHGUI()->isActiveStudyLocked())
829     return false;
830
831   // Verify validity of group name
832   if ( getName() == "" ) 
833   {
834     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
835                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
836     return false;
837   }
838
839   if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
840   {
841     SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
842                                   SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
843     return false;
844   }
845
846   QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
847   QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
848   for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
849     aGroups.append( *anIter );
850
851   if ( !isValid( aGroups ) )
852     return false;
853
854   SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
855   QString aName = getName();
856   
857   bool aRes = false;
858   try
859   {
860     SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
861     SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
862     SMESH::SMESH_Group_var aNewGrp = 
863       aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() );
864     if ( !CORBA::is_nil( aNewGrp ) )
865     {
866       aNewGrp->SetColor(  getColor() );
867       aRes = true;
868     }
869   }
870   catch( ... )
871   {
872     aRes = false;
873   }
874
875   if ( aRes ) 
876   {
877     SMESHGUI::Modified();
878     getSMESHGUI()->updateObjBrowser(true);
879     reset();
880     return true;
881   } 
882   else 
883   {
884     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
885                               tr("SMESH_OPERATION_FAILED"));
886     return false;
887   }
888 }
889
890 /*!
891   \brief SLOT, called when selection is changed, updates corresponding GUI controls
892 */
893 void SMESHGUI_CutGroupsDlg::onSelectionDone()
894 {
895   QStringList aNames;
896   if ( myBtn2->isChecked() )
897   {
898     getSelectedGroups( myGroups2, aNames );
899     myListWg2->clear();
900     myListWg2->addItems( aNames );
901   }
902   else 
903   {
904     getSelectedGroups( myGroups1, aNames );
905     myListWg1->clear();
906     myListWg1->addItems( aNames );
907   }
908 }
909
910 // === === === === === === === === === === === === === === === === === === === === === 
911
912 /*!
913   \brief Constructor
914   \param theModule module
915 */
916 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
917 : SMESHGUI_GroupOpDlg( theModule )
918 {
919   setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
920   setHelpFileName( "creating_groups_page.html#gui_create_dim_group" );
921
922   QGroupBox* anArgGrp = getArgGrp();
923
924   QLabel* aLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
925   
926   myCombo = new QComboBox( anArgGrp );
927   static QStringList anItems;
928   if ( anItems.isEmpty() )
929   {
930     anItems.append( tr( "NODE" ) );
931     anItems.append( tr( "EDGE" ) );
932     anItems.append( tr( "FACE" ) );
933     anItems.append( tr( "VOLUME" ) );
934   }
935   myCombo->addItems( anItems );
936   myCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
937   
938   myListWg = new QListWidget( anArgGrp );
939
940   // layout
941   QGridLayout* aLay = new QGridLayout( anArgGrp );
942   aLay->setSpacing( SPACING );
943   aLay->addWidget( aLbl, 0, 0 );
944   aLay->addWidget( myCombo, 0, 1 );
945   aLay->addWidget( myListWg, 1, 0, 1, 2 );
946 }
947
948 /*!
949   \brief Destructor
950 */
951 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
952 {
953 }
954
955 /*!
956   \brief This virtual method redefined from the base class resets state 
957   of the dialog, initializes its fields with default value, etc. 
958 */
959 void SMESHGUI_DimGroupDlg::reset()
960 {
961   SMESHGUI_GroupOpDlg::reset();
962   myListWg->clear();
963   myGroups.clear();
964 }
965
966 /*!
967   \brief Gets elements type
968   \return elements type
969   \sa setElementType()
970 */
971 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
972 {
973   return (SMESH::ElementType)( myCombo->currentIndex() + 1 );
974 }
975
976 /*!
977   \brief Sets elements type
978   \param theElemType elements type
979   \sa getElementType()
980 */
981 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
982 {
983   myCombo->setCurrentIndex( theElemType - 1 );
984 }
985
986 /*!
987   \brief SLOT called when apply button is pressed performs operation
988   \return TRUE if operation has been completed successfully, FALSE otherwise
989 */
990 bool SMESHGUI_DimGroupDlg::onApply()
991 {
992   if ( getSMESHGUI()->isActiveStudyLocked())
993     return false;
994
995   // Verify validity of group name
996   if ( getName() == "" ) 
997   {
998     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
999                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
1000     return false;
1001   }
1002
1003   if ( !isValid( myGroups ) )
1004     return false;
1005
1006   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1007   QString aName = getName();
1008   
1009   bool aRes = false;
1010   try
1011   {
1012     SMESH::ListOfGroups_var aList = convert( myGroups );
1013     SMESH::ElementType anElemType = getElementType();
1014     SMESH::SMESH_Group_var aNewGrp = 
1015       aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData() );
1016     if ( !CORBA::is_nil( aNewGrp ) )
1017     {
1018       aNewGrp->SetColor(  getColor() );
1019       aRes = true;
1020     }
1021   }
1022   catch( ... )
1023   {
1024     aRes = false;
1025   }
1026
1027   if ( aRes ) 
1028   {
1029     SMESHGUI::Modified();
1030     getSMESHGUI()->updateObjBrowser(true);
1031     reset();
1032     return true;
1033   } 
1034   else 
1035   {
1036     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1037                               tr("SMESH_OPERATION_FAILED"));
1038     return false;
1039   }
1040 }
1041
1042 /*!
1043   \brief SLOT, called when selection is changed, updates corresponding GUI controls
1044 */
1045 void SMESHGUI_DimGroupDlg::onSelectionDone()
1046 {
1047   QStringList aNames;
1048   getSelectedGroups( myGroups, aNames );
1049   myListWg->clear();
1050   myListWg->addItems( aNames );
1051 }
1052
1053