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