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