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