Salome HOME
041774bf4a8183a2f54b4d9a6662aee7118d7ad7
[modules/geom.git] / src / GroupGUI / GroupGUI_GroupDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2004  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GroupGUI_GroupDlg.cxx
25 //  Author : Sergey ANIKIN
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GroupGUI_GroupDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_Study.h"
35 #include "LightApp_SelectionMgr.h"
36
37 #include "GEOMBase.h"
38
39 #include "GEOMImpl_Types.hxx"
40
41 #include <qlabel.h>
42 #include <qlistbox.h>
43 #include <qlineedit.h>
44 #include <qmap.h>
45
46 #include <TColStd_IndexedMapOfInteger.hxx>
47 #include <TColStd_MapOfInteger.hxx>
48
49
50
51
52 GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode, 
53                                      QWidget* parent, 
54                                      const char* name,
55                                      bool modal, 
56                                      WFlags fl)
57   :GEOMBase_Skeleton( parent, "GroupGUI_GroupDlg", false,
58                       WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
59    myMode( mode ), 
60    myBusy( false )
61 {
62   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_VERTEX" ) ) );
63   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_EDGE" ) ) );
64   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_FACE" ) ) );
65   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_SOLID" ) ) );
66   
67   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
68
69   setCaption( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
70
71   // Shape type button group
72   GroupConstructors->setEnabled( myMode == CreateGroup );
73   GroupConstructors->setTitle( tr( "SHAPE_TYPE" ) );
74   RadioButton1->setPixmap( image0 );
75   RadioButton2->setPixmap( image1 );
76   RadioButton3->setPixmap( image2 );
77   RadioButton4->setPixmap( image3 );
78   RadioButton4->show();
79
80   // Group name
81   GroupBoxName->setTitle( tr( "GROUP_NAME" ) );
82
83   // Main shape and sub-shapes
84   GroupMedium = new QGroupBox( 1, Qt::Vertical, tr( "MAIN_SUB_SHAPES" ), this );
85   GroupMedium->setInsideMargin( 10 );
86   Layout1->addWidget( GroupMedium, 2, 0 );
87
88   QWidget* aFrame = new QWidget( GroupMedium );
89   QGridLayout* aMedLayout = new QGridLayout( aFrame, 4, 4, 0, 6 );
90
91   QLabel* aMainLabel = new QLabel( tr( "MAIN_SHAPE" ), aFrame );
92
93   mySelBtn = new QPushButton( aFrame );
94   mySelBtn->setPixmap( iconSelect );
95   mySelBtn->setEnabled( myMode == CreateGroup );
96
97   myMainName = new QLineEdit( aFrame );
98   myMainName->setReadOnly( true );
99   myMainName->setEnabled( myMode == CreateGroup );
100   
101   mySelSubBtn = new QPushButton( tr( "SELECT_SUB_SHAPES" ), aFrame );  
102   mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame );  
103   myAddBtn    = new QPushButton( tr( "ADD" ), aFrame );  
104   myRemBtn    = new QPushButton( tr( "REMOVE" ), aFrame );  
105   myIdList    = new QListBox( aFrame );
106   
107   myIdList->setSelectionMode( QListBox::Extended );
108   myIdList->setRowMode( QListBox::FitToWidth );
109
110   aMedLayout->addWidget( aMainLabel, 0, 0 );
111   aMedLayout->addWidget( mySelBtn, 0, 1 );
112   aMedLayout->addMultiCellWidget( myMainName, 0, 0, 2, 3 );
113   aMedLayout->addMultiCellWidget( mySelSubBtn, 1, 1, 0, 2 );
114   aMedLayout->addWidget( mySelAllBtn, 1, 3 );
115   aMedLayout->addMultiCellWidget( myIdList, 2, 3, 0, 2 );
116   aMedLayout->addWidget( myAddBtn, 2, 3 );
117   aMedLayout->addWidget( myRemBtn, 3, 3 );
118
119   Init();
120 }
121
122 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
123 {
124 }
125
126
127 //=================================================================================
128 // function : Init()
129 // purpose  :
130 //=================================================================================
131 void GroupGUI_GroupDlg::Init()
132 {
133   // san -- TODO: clear selected sub-shapes...
134
135   if ( myMode == CreateGroup ) {
136     initName( tr( "GROUP_PREFIX" ) );
137
138     // Get ready for main shape selection
139     myEditCurrentArgument = myMainName;
140
141     connect( GroupConstructors, SIGNAL( clicked( int ) ),            this, SLOT( ConstructorsClicked( int ) ) );
142     connect( mySelBtn,          SIGNAL( clicked() ),                 this, SLOT(SetEditCurrentArgument()));
143   }
144   else if ( myMode == EditGroup && IObjectCount() ) {
145     Standard_Boolean aResult = Standard_False;
146     GEOM::GEOM_Object_var anObj =
147       GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
148     
149     if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
150       myGroup = anObj;
151
152       ResultName->setText( GEOMBase::GetName( myGroup ) );
153
154       GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
155       myMainObj = anOp->GetMainShape( myGroup );
156       if ( !CORBA::is_nil( myMainObj ) )
157         myMainName->setText( GEOMBase::GetName( myMainObj ) );
158
159       setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
160
161       GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
162       QListBoxItem* anItem;
163       for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
164         anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) );
165         myIdList->insertItem( anItem );
166       }
167
168       myEditCurrentArgument = 0;
169     }
170   }
171
172   connect( buttonOk   , SIGNAL( clicked() ), this, SLOT( ClickOnOk()    ) );
173   connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
174
175   connect( mySelSubBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
176   connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
177   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
178            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
179   connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( selectAllSubShapes() ) );
180   connect( myAddBtn,    SIGNAL( clicked() ), this, SLOT( add() ) );
181   connect( myRemBtn,    SIGNAL( clicked() ), this, SLOT( remove() ) );
182   connect( myIdList,    SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
183
184   activateSelection();
185 }
186
187 //=================================================================================
188 // function : enterEvent()
189 // purpose  :
190 //=================================================================================
191 void GroupGUI_GroupDlg::enterEvent( QEvent* e )
192 {
193   if ( !buttonCancel->isEnabled() )
194     this->ActivateThisDialog();
195 }
196
197 //=================================================================================
198 // function : ClickOnOk()
199 // purpose  :
200 //=================================================================================
201 void GroupGUI_GroupDlg::ClickOnOk()
202 {
203   if ( ClickOnApply() )
204     ClickOnCancel();
205 }
206
207
208 //=================================================================================
209 // function : ClickOnApply()
210 // purpose  :
211 //=================================================================================
212 bool GroupGUI_GroupDlg::ClickOnApply()
213 {
214   if ( !onAccept( myMode == CreateGroup, true ) )
215     return false;
216
217   if ( myMode == CreateGroup )
218     initName();
219   return true;
220 }
221
222
223 //=================================================================================
224 // function : ActivateThisDialog()
225 // purpose  :
226 //=================================================================================
227 void GroupGUI_GroupDlg::ActivateThisDialog()
228 {
229   GEOMBase_Skeleton::ActivateThisDialog();
230
231   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
232            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
233
234   activateSelection();
235 }
236
237 //=================================================================================
238 // function : LineEditReturnPressed()
239 // purpose  :
240 //=================================================================================
241 void GroupGUI_GroupDlg::LineEditReturnPressed()
242 {
243   QLineEdit* send = ( QLineEdit* )sender();
244   
245   if ( send == myMainName && !myEditCurrentArgument ) {
246     myEditCurrentArgument = myMainName;
247     activateSelection();
248   }
249   else
250     GEOMBase_Skeleton::LineEditReturnPressed();
251
252   updateState();
253 }
254
255
256 //=================================================================================
257 // function : SetEditCurrentArgument()
258 // purpose  :
259 //=================================================================================
260 void GroupGUI_GroupDlg::SetEditCurrentArgument()
261 {
262   QPushButton* send = (QPushButton*)sender();
263
264   if ( send == mySelBtn )
265     myEditCurrentArgument = myMainName;
266   else if ( send == mySelSubBtn || send == mySelAllBtn )
267     myEditCurrentArgument = 0;
268
269   activateSelection();
270   updateState();
271 }
272
273
274 //=================================================================================
275 // function : SelectionIntoArgument()
276 // purpose  : Called when selection has changed
277 //=================================================================================
278 void GroupGUI_GroupDlg::SelectionIntoArgument()
279 {
280   if ( myEditCurrentArgument ) {  // Selection of a main shape is active
281     myEditCurrentArgument->setText( "" );
282     
283     if ( IObjectCount() == 1 ) {
284       Standard_Boolean aResult = Standard_False;
285       GEOM::GEOM_Object_var anObj =
286         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
287
288       if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
289         myMainObj = anObj;
290         myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
291         updateState();
292         return;
293       }
294     }
295
296     myMainObj = GEOM::GEOM_Object::_nil();
297   }
298   else {  // an attempt to synchronize list box selection with 3d viewer
299     if ( myBusy )
300       return;
301
302     bool isBlocked = myIdList->signalsBlocked();
303     myIdList->blockSignals( true );
304     myIdList->clearSelection();
305
306     TColStd_IndexedMapOfInteger aMapIndex;
307
308     if ( IObjectCount() == 1 ) {
309       Standard_Boolean aResult = Standard_False;
310       GEOM::GEOM_Object_var anObj =
311         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
312       
313       if ( aResult && !anObj->_is_nil() )
314         ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
315     }
316     
317     if ( !aMapIndex.Extent() ) // try to find out and process the object browser selection
318       {
319         GEOM::ListOfGO anObjects;
320         GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
321         GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
322         for (int i = 0; i < anObjects.length(); i++)
323           {
324             TopoDS_Shape aShape;
325             if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) )
326               {
327                 CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] );
328                 if ( anIndex >= 0 )
329                   aMapIndex.Add( anIndex );
330               }
331           }
332       }
333     
334     if ( aMapIndex.Extent()>=1 )
335     {
336       QMap<int, int> aMap;
337       for ( int i = 0, n = myIdList->count(); i < n; i++ )
338         aMap.insert( myIdList->item( i )->text().toInt(), i );
339       
340       for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ )
341         {
342           if ( aMap.contains( aMapIndex( ii ) ) )
343             myIdList->setSelected( aMap[aMapIndex( ii )], true );
344         }
345     }
346     myIdList->blockSignals( isBlocked );
347   }
348
349   updateState();
350 }
351
352 //=================================================================================
353 // function : ConstructorsClicked()
354 // purpose  : Radio button management
355 //=================================================================================
356 void GroupGUI_GroupDlg::ConstructorsClicked( int constructorId )
357 {
358   myIdList->clear();
359   activateSelection();
360   updateState();
361 }
362
363 //=================================================================================
364 // function : selectAllSubShapes
365 // purpose  : 
366 //=================================================================================
367 void GroupGUI_GroupDlg::selectAllSubShapes()
368 {
369   if ( CORBA::is_nil( myMainObj ) )
370     return;
371
372   GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
373   GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
374
375   GEOM::ListOfGO_var aSubShapes = aShOp->MakeExplode( myMainObj, getShapeType(), false );
376   if ( !aShOp->IsDone() )
377     return;
378
379   bool isBlocked = myIdList->signalsBlocked();
380   myIdList->blockSignals( true );
381   myIdList->clear();
382   
383   QListBoxItem* anItem;
384   for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
385     CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubShapes[i] );
386     if ( anIndex < 0 )
387       continue;
388
389     anItem = new QListBoxText( QString( "%1" ).arg( anIndex ) );
390     myIdList->insertItem( anItem );
391     myIdList->setSelected( anItem, true );
392   }
393
394   myIdList->blockSignals( isBlocked );
395   highlightSubShapes();
396   updateState();
397 }
398
399 //=================================================================================
400 // function : add
401 // purpose  : 
402 //=================================================================================
403 void GroupGUI_GroupDlg::add()
404 {
405   TColStd_MapOfInteger aMap;
406   for ( int i = 0, n = myIdList->count(); i < n; i++ )
407     aMap.Add( myIdList->item( i )->text().toInt() );
408   
409   TColStd_IndexedMapOfInteger aMapIndex;
410   
411   if ( IObjectCount() == 1 ) {
412     Standard_Boolean aResult = Standard_False;
413     GEOM::GEOM_Object_var anObj =
414       GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
415     
416     if ( aResult && !anObj->_is_nil() )
417       ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
418   }
419   
420   if ( !aMapIndex.Extent() ) // try to find out and process the object browser selection
421     {
422       GEOM::ListOfGO anObjects;
423       GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
424       GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
425       for (int i = 0; i < anObjects.length(); i++)
426         {
427           TopoDS_Shape aShape;
428           if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) )
429             {
430               CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] );
431               if ( anIndex >= 0 )
432                 aMapIndex.Add( anIndex );
433             }
434         }
435     }
436   
437   if ( aMapIndex.Extent()>=1 )
438     {
439       QListBoxItem* anItem;
440       bool isBlocked = myIdList->signalsBlocked();
441       myIdList->blockSignals( true );
442
443       for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
444         if ( aMap.Contains( aMapIndex( i ) ) )
445           continue;
446
447         anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
448         myIdList->insertItem( anItem );
449         myIdList->setSelected( anItem, true );
450       }
451
452       myIdList->blockSignals( isBlocked );
453     }
454   
455   updateState();
456 }
457
458 //=================================================================================
459 // function : remove
460 // purpose  : 
461 //=================================================================================
462 void GroupGUI_GroupDlg::remove()
463 {
464   for ( int i = myIdList->count() - 1; i >= 0; i-- ) {
465     if ( myIdList->isSelected( i ) ) 
466       myIdList->removeItem( i );
467   }
468   updateState();
469 }
470
471
472 //=================================================================================
473 // function : getConstructorId()
474 // purpose  :
475 //=================================================================================
476 int GroupGUI_GroupDlg::getConstructorId() const
477 {
478   return GroupConstructors->id( GroupConstructors->selected() );
479 }
480
481 //=================================================================================
482 // function : getShapeType()
483 // purpose  :
484 //=================================================================================
485 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
486 {
487   switch ( getConstructorId() ) {
488   case 0:  return TopAbs_VERTEX;
489   case 1:  return TopAbs_EDGE;
490   case 2:  return TopAbs_FACE;
491   case 3:  return TopAbs_SOLID;
492   default: return TopAbs_SHAPE;
493   }
494 }
495
496 //=================================================================================
497 // function : setShapeType()
498 // purpose  :
499 //=================================================================================
500 void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
501 {
502   int anId = 0;
503   switch ( theType ) {
504   case TopAbs_VERTEX: anId = 0; break;
505   case TopAbs_EDGE:   anId = 1; break;
506   case TopAbs_FACE:   anId = 2; break;
507   case TopAbs_SOLID:  anId = 3; break;
508   }  
509   GroupConstructors->setButton( anId );
510 }
511
512
513 //=================================================================================
514 // function : activateSelection
515 // purpose  : Activate selection in accordance with myEditCurrentArgument
516 //=================================================================================
517 void GroupGUI_GroupDlg::activateSelection()
518 {
519   globalSelection( GEOM_ALLSHAPES );
520
521   if ( !myMainObj->_is_nil() && !myEditCurrentArgument ) {
522     localSelection( myMainObj, getShapeType() );
523   }
524
525   SelectionIntoArgument();
526 }
527
528 //=================================================================================
529 // function : updateState
530 // purpose  : 
531 //=================================================================================
532 void GroupGUI_GroupDlg::updateState()
533 {
534   bool isAdd = false;
535
536   TColStd_IndexedMapOfInteger aMapIndex;
537   
538   if ( IObjectCount() == 1 ) {
539     Standard_Boolean aResult = Standard_False;
540     GEOM::GEOM_Object_var anObj =
541       GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
542
543     if ( aResult && !anObj->_is_nil() )
544       ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
545   }
546   
547   if ( !aMapIndex.Extent() ) // try to find out and process the object browser selection
548     {
549       isAdd = true;
550       GEOM::ListOfGO anObjects;
551       GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
552       GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
553       for (int i = 0; i < anObjects.length(); i++)
554         {
555           TopoDS_Shape aShape;
556           if ( GEOMBase::GetShape(anObjects[i], aShape, getShapeType()) )
557             {
558               CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, anObjects[i] );
559               if ( anIndex >= 0 )
560                 aMapIndex.Add( anIndex );
561               else
562                 isAdd = false;
563             }
564           else
565             isAdd = false;
566           
567           if ( !isAdd )
568             {
569               aMapIndex.Clear();
570               break;
571             }
572         }
573     }
574   
575   isAdd = aMapIndex.Extent() > 0;
576   
577   myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
578   bool hasSel = false;
579   for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ )
580     hasSel =  myIdList->isSelected( ii );
581   myRemBtn->setEnabled( hasSel );
582   mySelSubBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
583   mySelAllBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
584 }
585
586 //=================================================================================
587 // function : selectionChanged
588 // purpose  :
589 //=================================================================================
590 void GroupGUI_GroupDlg::selectionChanged()
591 {
592   highlightSubShapes();
593 }
594
595 //=================================================================================
596 // function : highlightSubShapes
597 // purpose  :
598 //=================================================================================
599 void GroupGUI_GroupDlg::highlightSubShapes()
600 {
601   if ( CORBA::is_nil( myMainObj ) )
602     return;
603
604   Standard_Boolean isOk;
605   Handle(GEOM_AISShape) aSh = 
606     GEOMBase::ConvertIORinGEOMAISShape( GEOMBase::GetIORFromObject( myMainObj ), isOk, true );
607   if ( !isOk || aSh.IsNull() )
608     return;
609
610   TColStd_MapOfInteger anIds;
611
612   myBusy = true;
613
614   for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ )
615     if ( myIdList->isSelected( ii ) )
616       anIds.Add( myIdList->item( ii )->text().toInt() );    
617
618   LightApp_SelectionMgr* aSelMgr = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
619   aSelMgr->clearSelected();
620   aSelMgr->AddOrRemoveIndex( aSh->getIO(), anIds, false );
621
622   myBusy = false;
623
624   updateState();
625 }
626
627 //=================================================================================
628 // function : createOperation
629 // purpose  :
630 //=================================================================================
631 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
632 {
633   return getGeomEngine()->GetIGroupOperations( getStudyId() );
634 }
635
636 #define RETURN_WITH_MSG(a, b) \
637   if ( !(a) ) { \
638     theMessage += (b); \
639     return false; \
640   }
641
642 //=================================================================================
643 // function : isValid()
644 // purpose  : Verify validity of input data
645 //=================================================================================
646 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
647 {
648   SalomeApp_Study* study = getStudy();
649   ASSERT(study);
650   RETURN_WITH_MSG  ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
651
652   if ( myMode == CreateGroup ) {
653     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
654   }
655   else {
656     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
657   }
658
659   const char* aName = getNewObjectName();
660   RETURN_WITH_MSG  ( aName && strlen( aName ), tr( "EMPTY_NAME" ) )
661
662   RETURN_WITH_MSG  ( myIdList->count(), tr( "EMPTY_LIST" ) )
663   return true;
664 }
665
666 //=================================================================================
667 // function : execute
668 // purpose  :
669 //=================================================================================
670 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
671 {
672   GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
673   
674   GEOM::GEOM_Object_var aGroup;
675   if ( myMode == CreateGroup ) 
676     aGroup = anOp->CreateGroup( myMainObj, getShapeType() );
677   else if ( myMode == EditGroup )
678     aGroup = myGroup;
679
680   if ( CORBA::is_nil( aGroup ) || ( myMode == CreateGroup && !anOp->IsDone() ) )
681     return false;
682
683   GEOM::ListOfLong_var aCurrList = anOp->GetObjects( aGroup );
684   if ( !anOp->IsDone()  )
685     return false;
686
687   for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
688     anOp->RemoveObject( aGroup, aCurrList[i] );
689     if ( !anOp->IsDone()  )
690       return false;
691   }
692
693   for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ ) {
694     anOp->AddObject( aGroup, myIdList->item( ii )->text().toInt() );    
695     if ( !anOp->IsDone()  )
696       return false;
697   }
698
699   SalomeApp_Study* study = getStudy();
700   if ( study ) {
701     string IOR = GEOMBase::GetIORFromObject( aGroup );
702     if ( IOR != "" ) {
703       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
704       if ( SO ) { 
705         _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
706         aBuilder->SetName( SO, getNewObjectName() );
707       }
708     }
709   }
710
711   objects.push_back( aGroup._retn() );
712
713   return true;
714 }
715
716 //================================================================
717 // Function : getFather
718 // Purpose  : Get father object for object to be added in study
719 //            ( called with addInStudy method )
720 //================================================================
721 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj )
722 {
723   GEOM::GEOM_Object_var aFatherObj;
724   if ( theObj->GetType() == GEOM_GROUP ) {
725     GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
726     aFatherObj = anOp->GetMainShape( theObj );
727   }
728   return aFatherObj._retn();
729 }