Salome HOME
merge V7_7_BR
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupOpDlg.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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 #include "SMESH_TypeFilter.hxx"
34
35 #include <LightApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <QtxColorButton.h>
38 #include <SALOMEDSClient_SObject.hxx>
39 #include <SALOME_ListIO.hxx>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SVTK_Selection.h>
46 #include <SVTK_ViewWindow.h>
47
48 // Qt includes
49 #include <QButtonGroup>
50 #include <QCheckBox>
51 #include <QComboBox>
52 #include <QGridLayout>
53 #include <QGroupBox>
54 #include <QHBoxLayout>
55 #include <QKeyEvent>
56 #include <QLabel>
57 #include <QLineEdit>
58 #include <QListWidget>
59 #include <QPushButton>
60 #include <QVBoxLayout>
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     myIsApplyAndClose( false )
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("RESULT"), 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(reject()));
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(reject()));
228   connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT(onOpenView()));
229   connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT(onCloseView()));
230
231   // set selection mode
232   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
233     aViewWindow->SetSelectionMode(ActorSelection);
234   mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
235 }
236
237 /*!
238   \brief Validate list of groups used for operation. Checks whether they corresponds 
239   to the same face and have one type
240   \param theListGrp input list of groups 
241   \return TRUE if groups are valid, FALSE otherwise
242 */
243 bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theListGrp )
244 {
245   if ( theListGrp.isEmpty() )
246   {
247     SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
248                                   tr("INCORRECT_ARGUMENTS") );
249     return false;
250   }
251
252   int aMeshId = -1, aGrpType = -1;
253   QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter;
254   for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter )
255   {
256     SMESH::SMESH_GroupBase_var aGrp = *anIter;
257     if ( CORBA::is_nil( aGrp ) )
258       continue; // nonsence
259
260     SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh();
261     if ( CORBA::is_nil( aMesh ) )
262       continue;
263
264     // mesh id
265     int aCurrId = aMesh->GetId();
266     if ( aMeshId == -1 )
267       aMeshId = aCurrId;
268     else 
269     {
270       if ( aMeshId != aCurrId )
271       {
272         aMeshId = -1; // different meshes
273         break;
274       }
275     }
276
277     // group type
278     int aCurrType = aGrp->GetType();
279     if ( aGrpType == -1 )
280       aGrpType = aCurrType;
281     else 
282     {
283       if ( aGrpType != aCurrType )
284       {
285         aGrpType = -1; // different types
286         break;
287       }
288     }
289
290   }
291
292   if ( aMeshId == -1 )
293   {
294     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
295                                  tr("DIFF_MESHES"));
296     return false;
297   }
298
299   if ( aGrpType == -1 ) 
300   {
301     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
302                                  tr("DIFF_TYPES"));
303     return false;
304   }
305
306   return true;
307 }
308
309 /*!
310   \brief SLOT called when "Ok" button pressed performs operation and closes dialog box
311 */
312 void SMESHGUI_GroupOpDlg::onOk()
313 {
314   SUIT_OverrideCursor oc;
315   setIsApplyAndClose( true );
316   if ( onApply() )
317     reject();
318   setIsApplyAndClose( false );
319 }
320
321 /*!
322   \brief SLOT called when dialog is closed
323 */
324 void SMESHGUI_GroupOpDlg::reject()
325 {
326   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
327     aViewWindow->SetSelectionMode(ActorSelection);
328   disconnect( mySelectionMgr, 0, this, 0 );
329   disconnect( mySMESHGUI, 0, this, 0 );
330   mySMESHGUI->ResetState();
331   mySelectionMgr->clearFilters();
332   reset();
333   QDialog::reject();
334 }
335
336 //=================================================================================
337 // function : onOpenView()
338 // purpose  :
339 //=================================================================================
340 void SMESHGUI_GroupOpDlg::onOpenView()
341 {
342   if ( mySelector ) {
343     SMESH::SetPointRepresentation(false);
344   }
345   else {
346     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
347     mySMESHGUI->EmitSignalDeactivateDialog();
348     setEnabled(true);
349   }
350 }
351
352 //=================================================================================
353 // function : onCloseView()
354 // purpose  :
355 //=================================================================================
356 void SMESHGUI_GroupOpDlg::onCloseView()
357 {
358   onDeactivate();
359   mySelector = 0;
360 }
361
362 /*!
363   \brief SLOT called when "Help" button pressed shows "Help" page
364 */
365 void SMESHGUI_GroupOpDlg::onHelp()
366 {
367   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
368   if (app) 
369     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
370   else {
371     QString platform;
372 #ifdef WIN32
373     platform = "winapplication";
374 #else
375     platform = "application";
376 #endif
377     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
378                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
379                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
380                                                                  platform)).
381                              arg(myHelpFileName));
382   }
383 }
384
385 /*!
386   \brief Gets list of currently selected groups from selection manager
387   \param theOutList out list of groups
388   \param theOutNames out list of group of group names
389   \return TRUE if operation theOutList is not empty, FALSE otherwise
390 */
391 bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList<SMESH::SMESH_GroupBase_var>& theOutList, 
392                                              QStringList& theOutNames )
393 {
394   theOutList.clear();
395
396   theOutList.clear();
397   theOutNames.clear();
398
399   SALOME_ListIO aListIO;
400   mySelectionMgr->selectedObjects( aListIO );
401   SALOME_ListIteratorOfListIO anIter ( aListIO );
402   for ( ; anIter.More(); anIter.Next()) 
403   {
404     SMESH::SMESH_GroupBase_var aGroup =
405       SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
406     if ( !aGroup->_is_nil()) 
407     {
408       theOutList.append( aGroup );
409       theOutNames.append( aGroup->GetName() );
410     }
411   }
412
413   return theOutList.count() > 0;
414 }
415
416 /*!
417   \brief Converts QT-list of group to the list acceptable by IDL interface
418   \param theIn input list
419   \return list acceptable by IDL interface
420 */
421 SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert( 
422   const QList<SMESH::SMESH_GroupBase_var>& theIn )
423 {
424   SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
425   aList->length( theIn.count() );
426
427   QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = theIn.begin();
428   for ( int i = 0; anIter != theIn.end(); ++anIter, ++i )
429     aList[ i ] = *anIter;
430
431   return aList._retn();
432 }
433
434 /*!
435   \brief Get color to be assigned to group
436   \return color to be assigned to group
437 */
438 SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
439 {
440   QColor aQColor = myColorBtn->color();
441
442   SALOMEDS::Color aColor;
443   aColor.R = (float)aQColor.red() / 255.0;
444   aColor.G = (float)aQColor.green() / 255.0;
445   aColor.B = (float)aQColor.blue() / 255.0;
446
447   return aColor;
448 }
449
450 /*!
451   \brief SLOT, called when selection is changed. Current implementation does 
452    nothing. The method should be redefined in derived classes to update 
453    corresponding GUI controls
454 */
455 void SMESHGUI_GroupOpDlg::onSelectionDone()
456 {
457 }
458
459 /*!
460   \brief Calls onSelectionDone() and setVisible() method of base class
461   \param visible the visible state of the dialog 
462 */
463 void SMESHGUI_GroupOpDlg::setVisible( bool visible )
464 {
465   if ( visible )
466   {
467     onSelectionDone();
468     resize( minimumSizeHint().width(), sizeHint().height() );
469   }
470   QDialog::setVisible( visible );
471 }
472
473 /*!
474   \brief SLOT called when dialog must be deativated
475 */
476 void SMESHGUI_GroupOpDlg::onDeactivate()
477 {
478   setEnabled(false);
479   mySelectionMgr->clearFilters();
480 }
481
482 /*!
483   \brief Event filter updates selection mode and selection filter. This virtual method 
484   is redefined from the base class it is called when dialog obtains input focus
485 */
486 void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
487 {
488   mySMESHGUI->EmitSignalDeactivateDialog();
489   setEnabled(true);
490   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
491   if ( aViewWindow ) {
492     aViewWindow->SetSelectionMode(ActorSelection);
493     if (!mySelector)
494       mySelector = aViewWindow->GetSelector();
495   }
496   mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
497 }
498
499 /*!
500   \brief Resets state of the dialog, initializes its fields with default value, etc. 
501   Usually called by onApply() slot to reinitialize dialog  fields. This virtual method 
502   should be redefined in derived class to update its own fileds
503 */
504 void SMESHGUI_GroupOpDlg::reset()
505 {
506   myNameEdit->setText("");
507   myNameEdit->setFocus();
508 }
509
510 /*!
511   \brief Gets name of group to be created
512   \return name of group to be created
513   \sa setName()
514 */
515 QString SMESHGUI_GroupOpDlg::getName() const
516 {
517   return myNameEdit->text();
518 }
519
520 /*!
521   \brief Sets name of group to be created
522   \param theName name of group to be created
523   \sa getName()
524 */
525 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
526 {
527   myNameEdit->setText( theName );
528 }
529
530 /*!
531   \brief Provides reaction on ï¿½F1� button pressing
532   \param e  key press event
533 */
534 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
535 {
536   QDialog::keyPressEvent( e );
537   if ( e->isAccepted() )
538     return;
539
540   if ( e->key() == Qt::Key_F1 ) {
541     e->accept();
542     onHelp();
543   }
544 }
545
546 /*!
547   \brief This virtual slot does nothing and should be redefined in derived classes
548   \return return false;
549 */
550 bool SMESHGUI_GroupOpDlg::onApply()
551 {
552   return false;
553 }
554
555 /*!
556   \brief Set value of the flag indicating that the dialog is
557   accepted by Apply & Close button
558   \param theFlag value of the flag
559   \sa isApplyAndClose()
560 */
561 void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
562 {
563   myIsApplyAndClose = theFlag;
564 }
565
566 /*!
567   \brief Get value of the flag indicating that the dialog is
568   accepted by Apply & Close button
569   \return value of the flag
570   \sa setApplyAndClose()
571 */
572 bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
573 {
574   return myIsApplyAndClose;
575 }
576
577 // === === === === === === === === === === === === === === === === === === === === === 
578
579 /*!
580   \brief Constructor
581   \param theModule module
582 */
583 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
584 : SMESHGUI_GroupOpDlg( theModule )
585 {
586   setWindowTitle(tr("UNION_OF_GROUPS"));
587   setHelpFileName( "using_operations_on_groups_page.html#union_anchor" );
588
589   QGroupBox* anArgGrp = getArgGrp();
590   myListWg = new QListWidget( anArgGrp );
591
592   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
593   aLay->addWidget( myListWg );
594 }
595
596 /*!
597   \brief Destructor
598 */
599 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
600 {
601 }
602
603 /*!
604   \brief This virtual method redefined from the base class resets state 
605   of the dialog, initializes its fields with default value, etc. 
606 */
607 void SMESHGUI_UnionGroupsDlg::reset()
608 {
609   SMESHGUI_GroupOpDlg::reset();
610   myListWg->clear();
611   myGroups.clear();
612 }
613
614 /*!
615   \brief SLOT called when apply button is pressed performs operation
616   \return TRUE if operation has been completed successfully, FALSE otherwise
617 */
618 bool SMESHGUI_UnionGroupsDlg::onApply()
619 {
620   if ( getSMESHGUI()->isActiveStudyLocked())
621     return false;
622
623   // Verify validity of group name
624   if ( getName() == "" ) 
625   {
626     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
627                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
628     return false;
629   }
630
631   if ( !isValid( myGroups ) )
632     return false;
633
634   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
635   QString aName = getName();
636   
637   bool aRes = false;
638   QStringList anEntryList;
639   try
640   {
641     SMESH::ListOfGroups_var aList = convert( myGroups );
642     SMESH::SMESH_Group_var aNewGrp = 
643       aMesh->UnionListOfGroups( aList, aName.toLatin1().constData() );
644     if ( !CORBA::is_nil( aNewGrp ) )
645     {
646       aNewGrp->SetColor(  getColor() );
647       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
648         anEntryList.append( aSObject->GetID().c_str() );
649       aRes = true;
650     }
651   }
652   catch( ... )
653   {
654     aRes = false;
655   }
656
657   if ( aRes ) 
658   {
659     SMESHGUI::Modified();
660     getSMESHGUI()->updateObjBrowser(true);
661     reset();
662     if( LightApp_Application* anApp =
663         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
664       anApp->browseObjects( anEntryList, isApplyAndClose() );
665     return true;
666   } 
667   else 
668   {
669     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
670                               tr("SMESH_OPERATION_FAILED"));
671     return false;
672   }
673 }
674
675 /*!
676   \brief SLOT, called when selection is changed, updates corresponding GUI controls
677 */
678 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
679 {
680   QStringList aNames;
681   getSelectedGroups( myGroups, aNames );
682   myListWg->clear();
683   myListWg->addItems( aNames );
684 }
685
686 // === === === === === === === === === === === === === === === === === === === === === 
687
688 /*!
689   \brief Constructor
690   \param theModule module
691 */
692 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
693 : SMESHGUI_GroupOpDlg( theModule )
694 {
695   setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
696   setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
697
698   QGroupBox* anArgGrp = getArgGrp();
699   myListWg = new QListWidget( anArgGrp );
700
701   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
702   aLay->addWidget( myListWg );
703 }
704
705 /*!
706   \brief Destructor
707 */
708 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
709 {
710 }
711
712 /*!
713   \brief This virtual method redefined from the base class resets state 
714   of the dialog, initializes its fields with default value, etc. 
715 */
716 void SMESHGUI_IntersectGroupsDlg::reset()
717 {
718   SMESHGUI_GroupOpDlg::reset();
719   myListWg->clear();
720   myGroups.clear();
721 }
722
723 /*!
724   \brief SLOT called when apply button is pressed performs operation
725   \return TRUE if operation has been completed successfully, FALSE otherwise
726 */
727 bool SMESHGUI_IntersectGroupsDlg::onApply()
728 {
729   if ( getSMESHGUI()->isActiveStudyLocked())
730     return false;
731
732   // Verify validity of group name
733   if ( getName() == "" ) 
734   {
735     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
736                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
737     return false;
738   }
739
740   if ( !isValid( myGroups ) )
741     return false;
742
743   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
744   QString aName = getName();
745   
746   bool aRes = false;
747   QStringList anEntryList;
748   try
749   {
750     SMESH::ListOfGroups_var aList = convert( myGroups );
751     SMESH::SMESH_Group_var aNewGrp = 
752       aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() );
753     if ( !CORBA::is_nil( aNewGrp ) )
754     {
755       aNewGrp->SetColor(  getColor() );
756       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
757         anEntryList.append( aSObject->GetID().c_str() );
758       aRes = true;
759     }
760   }
761   catch( ... )
762   {
763     aRes = false;
764   }
765
766   if ( aRes ) 
767   {
768     SMESHGUI::Modified();
769     getSMESHGUI()->updateObjBrowser(true);
770     reset();
771     if( LightApp_Application* anApp =
772         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
773       anApp->browseObjects( anEntryList, isApplyAndClose() );
774     return true;
775   } 
776   else 
777   {
778     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
779                               tr("SMESH_OPERATION_FAILED"));
780     return false;
781   }
782 }
783
784 /*!
785   \brief SLOT, called when selection is changed, updates corresponding GUI controls
786 */
787 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
788 {
789   QStringList aNames;
790   getSelectedGroups( myGroups, aNames );
791   myListWg->clear();
792   myListWg->addItems( aNames );
793 }
794
795 // === === === === === === === === === === === === === === === === === === === === === 
796
797 /*!
798   \brief Constructor
799   \param theModule module
800 */
801 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
802 : SMESHGUI_GroupOpDlg( theModule )
803 {
804   setWindowTitle(tr("CUT_OF_GROUPS"));
805   setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
806
807   QGroupBox* anArgGrp = getArgGrp();
808
809   QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
810   
811   // frame 1
812   QFrame* aFrame1 = new QFrame( anArgGrp );
813   QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
814   aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
815   myBtn1 = new QPushButton( aFrame1 );
816   myBtn1->setIcon(aPix);
817   myListWg1 = new QListWidget( aFrame1 );
818
819   QGridLayout* aLay1 = new QGridLayout( aFrame1 );
820   aLay1->setSpacing( SPACING );
821   aLay1->addWidget( aLbl1, 0, 0 );
822   aLay1->addWidget( myBtn1, 0, 1 );
823   aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
824   //QSpacerItem* aHSpacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
825   //aLay1->addItem( aHSpacer1, 0, 2 );
826
827
828   // frame 2
829   QFrame* aFrame2 = new QFrame( anArgGrp );
830   QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
831   aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
832   myBtn2 = new QPushButton( aFrame2 );
833   myBtn2->setIcon(aPix);
834   myListWg2 = new QListWidget( aFrame2 );
835
836   QGridLayout* aLay2 = new QGridLayout( aFrame2 );
837   aLay2->setSpacing( SPACING );
838   aLay2->addWidget( aLbl2, 0, 0 );
839   aLay2->addWidget( myBtn2, 0, 1 );
840   aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
841   //QSpacerItem* aHSpacer2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
842   //aLay2->addItem( aHSpacer2, 0, 2 );
843
844   // create button group 
845
846   QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
847   aGrp->addButton( myBtn1, 0 );
848   aGrp->addButton( myBtn2, 1 );
849   myBtn1->setCheckable( true );
850   myBtn2->setCheckable( true );
851   aGrp->setExclusive( true );
852   myBtn1->setChecked( true );
853   
854   // fill layout
855   QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
856   aLay->setSpacing( SPACING );
857   aLay->addWidget( aFrame1 );
858   aLay->addWidget( aFrame2 );
859 }
860
861 /*!
862   \brief Destructor
863 */
864 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
865 {
866 }
867
868 /*!
869   \brief This virtual method redefined from the base class resets state 
870   of the dialog, initializes its fields with default value, etc. 
871 */
872 void SMESHGUI_CutGroupsDlg::reset()
873 {
874   SMESHGUI_GroupOpDlg::reset();
875
876   myListWg1->clear();
877   myGroups1.clear();
878
879   myListWg2->clear();
880   myGroups2.clear();
881 }
882
883 /*!
884   \brief SLOT called when apply button is pressed performs operation
885   \return TRUE if operation has been completed successfully, FALSE otherwise
886 */
887 bool SMESHGUI_CutGroupsDlg::onApply()
888 {
889   if ( getSMESHGUI()->isActiveStudyLocked())
890     return false;
891
892   // Verify validity of group name
893   if ( getName() == "" ) 
894   {
895     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
896                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
897     return false;
898   }
899
900   if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
901   {
902     SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
903                                   SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
904     return false;
905   }
906
907   QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
908   QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
909   for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
910     aGroups.append( *anIter );
911
912   if ( !isValid( aGroups ) )
913     return false;
914
915   SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
916   QString aName = getName();
917   
918   bool aRes = false;
919   QStringList anEntryList;
920   try
921   {
922     SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
923     SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
924     SMESH::SMESH_Group_var aNewGrp = 
925       aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() );
926     if ( !CORBA::is_nil( aNewGrp ) )
927     {
928       aNewGrp->SetColor(  getColor() );
929       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
930         anEntryList.append( aSObject->GetID().c_str() );
931       aRes = true;
932     }
933   }
934   catch( ... )
935   {
936     aRes = false;
937   }
938
939   if ( aRes ) 
940   {
941     SMESHGUI::Modified();
942     getSMESHGUI()->updateObjBrowser(true);
943     reset();
944     if( LightApp_Application* anApp =
945         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
946       anApp->browseObjects( anEntryList, isApplyAndClose() );
947     return true;
948   } 
949   else 
950   {
951     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
952                               tr("SMESH_OPERATION_FAILED"));
953     return false;
954   }
955 }
956
957 /*!
958   \brief SLOT, called when selection is changed, updates corresponding GUI controls
959 */
960 void SMESHGUI_CutGroupsDlg::onSelectionDone()
961 {
962   QStringList aNames;
963   if ( myBtn2->isChecked() )
964   {
965     getSelectedGroups( myGroups2, aNames );
966     myListWg2->clear();
967     myListWg2->addItems( aNames );
968   }
969   else 
970   {
971     getSelectedGroups( myGroups1, aNames );
972     myListWg1->clear();
973     myListWg1->addItems( aNames );
974   }
975 }
976
977 // === === === === === === === === === === === === === === === === === === === === === 
978
979 /*!
980   \brief Constructor
981   \param theModule module
982 */
983 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
984   : SMESHGUI_GroupOpDlg( theModule )
985 {
986   setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
987   setHelpFileName( "group_of_underlying_elements_page.html" );
988
989   QGroupBox* anArgGrp = getArgGrp();
990
991   QLabel* aTypeLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
992
993   myTypeCombo = new QComboBox( anArgGrp );
994   QStringList anItems;
995   {
996     anItems.append( tr( "MESH_NODE" ) );
997     anItems.append( tr( "SMESH_EDGE" ) );
998     anItems.append( tr( "SMESH_FACE" ) );
999     anItems.append( tr( "SMESH_VOLUME" ) );
1000     anItems.append( tr( "SMESH_ELEM0D" ) );
1001     anItems.append( tr( "SMESH_BALL" ) );
1002   }
1003   myTypeCombo->addItems( anItems );
1004   myTypeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1005
1006   QLabel* aNbNoLbl = new QLabel( tr( "NUMBER_OF_COMMON_NODES" ), anArgGrp );
1007
1008   myNbNoCombo = new QComboBox( anArgGrp );
1009   anItems.clear();
1010   {
1011     anItems.append( tr( "ALL" ) );
1012     anItems.append( tr( "MAIN" ) );
1013     anItems.append( tr( "AT_LEAST_ONE" ) );
1014     anItems.append( tr( "MAJORITY" ) );
1015   }
1016   myNbNoCombo->addItems( anItems );
1017   myNbNoCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1018
1019   myListWg = new QListWidget( anArgGrp );
1020
1021   myUnderlOnlyChk = new QCheckBox( tr("UNDERLYING_ENTITIES_ONLY"), anArgGrp );
1022   myUnderlOnlyChk->setChecked( false );
1023
1024   // layout
1025   QGridLayout* aLay = new QGridLayout( anArgGrp );
1026   aLay->setSpacing( SPACING );
1027   aLay->addWidget( aTypeLbl,        0, 0 );
1028   aLay->addWidget( myTypeCombo,     0, 1 );
1029   aLay->addWidget( aNbNoLbl,        1, 0 );
1030   aLay->addWidget( myNbNoCombo,     1, 1 );
1031   aLay->addWidget( myListWg,        2, 0, 1, 2 );
1032   aLay->addWidget( myUnderlOnlyChk, 3, 0 );
1033 }
1034
1035 /*!
1036   \brief Destructor
1037 */
1038 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
1039 {
1040 }
1041
1042 /*!
1043   \brief This virtual method redefined from the base class resets state 
1044   of the dialog, initializes its fields with default value, etc. 
1045 */
1046 void SMESHGUI_DimGroupDlg::reset()
1047 {
1048   SMESHGUI_GroupOpDlg::reset();
1049   myListWg->clear();
1050   myGroups.clear();
1051 }
1052
1053 /*!
1054   \brief Gets elements type
1055   \return elements type
1056   \sa setElementType()
1057 */
1058 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
1059 {
1060   return (SMESH::ElementType)( myTypeCombo->currentIndex() + 1 );
1061 }
1062
1063 /*!
1064   \brief Sets elements type
1065   \param theElemType elements type
1066   \sa getElementType()
1067 */
1068 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
1069 {
1070   myTypeCombo->setCurrentIndex( theElemType - 1 );
1071 }
1072
1073 /*!
1074   \brief SLOT called when apply button is pressed performs operation
1075   \return TRUE if operation has been completed successfully, FALSE otherwise
1076 */
1077 bool SMESHGUI_DimGroupDlg::onApply()
1078 {
1079   if ( getSMESHGUI()->isActiveStudyLocked())
1080     return false;
1081
1082   // Verify validity of group name
1083   if ( getName() == "" ) 
1084   {
1085     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
1086                                  SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
1087     return false;
1088   }
1089
1090   if ( !isValid( myGroups ) )
1091     return false;
1092
1093   SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
1094   QString aName = getName();
1095   
1096   bool aRes = false;
1097   QStringList anEntryList;
1098   try
1099   {
1100     SMESH::ListOfIDSources_var aList = new SMESH::ListOfIDSources();
1101     aList->length( myGroups.count() );
1102     QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = myGroups.begin();
1103     for ( int i = 0; anIter != myGroups.end(); ++anIter, ++i )
1104       aList[ i ] = SMESH::SMESH_IDSource::_narrow( *anIter );
1105
1106     SMESH::ElementType anElemType = getElementType();
1107     SMESH::NB_COMMON_NODES_ENUM aNbCoNodes =
1108       (SMESH::NB_COMMON_NODES_ENUM) myNbNoCombo->currentIndex();
1109
1110     SMESH::SMESH_Group_var aNewGrp =
1111       aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData(),
1112                              aNbCoNodes, myUnderlOnlyChk->isChecked() );
1113     if ( !CORBA::is_nil( aNewGrp ) )
1114     {
1115       aNewGrp->SetColor(  getColor() );
1116       if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
1117         anEntryList.append( aSObject->GetID().c_str() );
1118       aRes = true;
1119     }
1120   }
1121   catch( ... )
1122   {
1123     aRes = false;
1124   }
1125
1126   if ( aRes ) 
1127   {
1128     SMESHGUI::Modified();
1129     getSMESHGUI()->updateObjBrowser(true);
1130     reset();
1131     if( LightApp_Application* anApp =
1132         dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1133       anApp->browseObjects( anEntryList, isApplyAndClose() );
1134     return true;
1135   } 
1136   else 
1137   {
1138     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
1139                               tr("SMESH_OPERATION_FAILED"));
1140     return false;
1141   }
1142 }
1143
1144 /*!
1145   \brief SLOT, called when selection is changed, updates corresponding GUI controls
1146 */
1147 void SMESHGUI_DimGroupDlg::onSelectionDone()
1148 {
1149   QStringList aNames;
1150   getSelectedGroups( myGroups, aNames );
1151   myListWg->clear();
1152   myListWg->addItems( aNames );
1153 }