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