Salome HOME
Using files from package LightApp instead of SalomeApp
[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     if ( IObjectCount() == 1 ) {
307       Standard_Boolean aResult = Standard_False;
308       GEOM::GEOM_Object_var anObj =
309         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
310       
311       if ( aResult && !anObj->_is_nil() ) {
312         QMap<int, int> aMap;
313         for ( int i = 0, n = myIdList->count(); i < n; i++ )
314           aMap.insert( myIdList->item( i )->text().toInt(), i );
315         
316         TColStd_IndexedMapOfInteger aMapIndex;
317         ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
318         for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
319           if ( aMap.contains( aMapIndex( ii ) ) )
320             myIdList->setSelected( aMap[aMapIndex( ii )], true );
321         }
322       }
323     }
324
325     myIdList->blockSignals( isBlocked );
326   }
327
328   updateState();
329 }
330
331 //=================================================================================
332 // function : ConstructorsClicked()
333 // purpose  : Radio button management
334 //=================================================================================
335 void GroupGUI_GroupDlg::ConstructorsClicked( int constructorId )
336 {
337   myIdList->clear();
338   activateSelection();
339   updateState();
340 }
341
342 //=================================================================================
343 // function : selectAllSubShapes
344 // purpose  : 
345 //=================================================================================
346 void GroupGUI_GroupDlg::selectAllSubShapes()
347 {
348   if ( CORBA::is_nil( myMainObj ) )
349     return;
350
351   GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
352   GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
353
354   GEOM::ListOfGO_var aSubShapes = aShOp->MakeExplode( myMainObj, getShapeType(), false );
355   if ( !aShOp->IsDone() )
356     return;
357
358   bool isBlocked = myIdList->signalsBlocked();
359   myIdList->blockSignals( true );
360   myIdList->clear();
361   
362   QListBoxItem* anItem;
363   for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
364     CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubShapes[i] );
365     if ( anIndex < 0 )
366       continue;
367
368     anItem = new QListBoxText( QString( "%1" ).arg( anIndex ) );
369     myIdList->insertItem( anItem );
370     myIdList->setSelected( anItem, true );
371   }
372
373   myIdList->blockSignals( isBlocked );
374   highlightSubShapes();
375   updateState();
376 }
377
378 //=================================================================================
379 // function : add
380 // purpose  : 
381 //=================================================================================
382 void GroupGUI_GroupDlg::add()
383 {
384   TColStd_MapOfInteger aMap;
385   for ( int i = 0, n = myIdList->count(); i < n; i++ )
386     aMap.Add( myIdList->item( i )->text().toInt() );
387
388   if ( IObjectCount() == 1 ) {
389     Standard_Boolean aResult = Standard_False;
390     GEOM::GEOM_Object_var anObj =
391       GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
392
393     if ( aResult && !anObj->_is_nil() ) {
394       TColStd_IndexedMapOfInteger aMapIndex;
395       ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
396       QListBoxItem* anItem;
397       bool isBlocked = myIdList->signalsBlocked();
398       myIdList->blockSignals( true );
399
400       for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
401         if ( aMap.Contains( aMapIndex( i ) ) )
402           continue;
403
404         anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
405         myIdList->insertItem( anItem );
406         myIdList->setSelected( anItem, true );
407       }
408
409       myIdList->blockSignals( isBlocked );
410     }
411   }
412   updateState();
413 }
414
415 //=================================================================================
416 // function : remove
417 // purpose  : 
418 //=================================================================================
419 void GroupGUI_GroupDlg::remove()
420 {
421   for ( int i = myIdList->count() - 1; i >= 0; i-- ) {
422     if ( myIdList->isSelected( i ) ) 
423       myIdList->removeItem( i );
424   }
425   updateState();
426 }
427
428
429 //=================================================================================
430 // function : getConstructorId()
431 // purpose  :
432 //=================================================================================
433 int GroupGUI_GroupDlg::getConstructorId() const
434 {
435   return GroupConstructors->id( GroupConstructors->selected() );
436 }
437
438 //=================================================================================
439 // function : getShapeType()
440 // purpose  :
441 //=================================================================================
442 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
443 {
444   switch ( getConstructorId() ) {
445   case 0:  return TopAbs_VERTEX;
446   case 1:  return TopAbs_EDGE;
447   case 2:  return TopAbs_FACE;
448   case 3:  return TopAbs_SOLID;
449   default: return TopAbs_SHAPE;
450   }
451 }
452
453 //=================================================================================
454 // function : setShapeType()
455 // purpose  :
456 //=================================================================================
457 void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
458 {
459   int anId = 0;
460   switch ( theType ) {
461   case TopAbs_VERTEX: anId = 0; break;
462   case TopAbs_EDGE:   anId = 1; break;
463   case TopAbs_FACE:   anId = 2; break;
464   case TopAbs_SOLID:  anId = 3; break;
465   }  
466   GroupConstructors->setButton( anId );
467 }
468
469
470 //=================================================================================
471 // function : activateSelection
472 // purpose  : Activate selection in accordance with myEditCurrentArgument
473 //=================================================================================
474 void GroupGUI_GroupDlg::activateSelection()
475 {
476   globalSelection( GEOM_ALLSHAPES );
477
478   if ( !myMainObj->_is_nil() && !myEditCurrentArgument ) {
479     localSelection( myMainObj, getShapeType() );
480   }
481
482   SelectionIntoArgument();
483 }
484
485 //=================================================================================
486 // function : updateState
487 // purpose  : 
488 //=================================================================================
489 void GroupGUI_GroupDlg::updateState()
490 {
491   bool isAdd = false;
492   if ( IObjectCount() == 1 ) {
493     Standard_Boolean aResult = Standard_False;
494     GEOM::GEOM_Object_var anObj =
495       GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
496
497     if ( aResult && !anObj->_is_nil() ) {
498       TColStd_IndexedMapOfInteger aMapIndex;
499       ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
500       isAdd = aMapIndex.Extent() > 0;
501     }
502   }
503   myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
504   bool hasSel = false;
505   for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ )
506     hasSel =  myIdList->isSelected( ii );
507   myRemBtn->setEnabled( hasSel );
508   mySelSubBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
509   mySelAllBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
510 }
511
512 //=================================================================================
513 // function : selectionChanged
514 // purpose  :
515 //=================================================================================
516 void GroupGUI_GroupDlg::selectionChanged()
517 {
518   highlightSubShapes();
519 }
520
521 //=================================================================================
522 // function : highlightSubShapes
523 // purpose  :
524 //=================================================================================
525 void GroupGUI_GroupDlg::highlightSubShapes()
526 {
527   if ( CORBA::is_nil( myMainObj ) )
528     return;
529
530   Standard_Boolean isOk;
531   Handle(GEOM_AISShape) aSh = 
532     GEOMBase::ConvertIORinGEOMAISShape( GEOMBase::GetIORFromObject( myMainObj ), isOk, true );
533   if ( !isOk || aSh.IsNull() )
534     return;
535
536   TColStd_MapOfInteger anIds;
537
538   myBusy = true;
539
540   for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ )
541     if ( myIdList->isSelected( ii ) )
542       anIds.Add( myIdList->item( ii )->text().toInt() );    
543
544   LightApp_SelectionMgr* aSelMgr = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
545   aSelMgr->clearSelected();
546   aSelMgr->AddOrRemoveIndex( aSh->getIO(), anIds, false );
547
548   myBusy = false;
549
550   updateState();
551 }
552
553 //=================================================================================
554 // function : createOperation
555 // purpose  :
556 //=================================================================================
557 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
558 {
559   return getGeomEngine()->GetIGroupOperations( getStudyId() );
560 }
561
562 #define RETURN_WITH_MSG(a, b) \
563   if ( !(a) ) { \
564     theMessage += (b); \
565     return false; \
566   }
567
568 //=================================================================================
569 // function : isValid()
570 // purpose  : Verify validity of input data
571 //=================================================================================
572 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
573 {
574   SalomeApp_Study* study = getStudy();
575   ASSERT(study);
576   RETURN_WITH_MSG  ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
577
578   if ( myMode == CreateGroup ) {
579     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
580   }
581   else {
582     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
583   }
584
585   const char* aName = getNewObjectName();
586   RETURN_WITH_MSG  ( aName && strlen( aName ), tr( "EMPTY_NAME" ) )
587
588   RETURN_WITH_MSG  ( myIdList->count(), tr( "EMPTY_LIST" ) )
589   return true;
590 }
591
592 //=================================================================================
593 // function : execute
594 // purpose  :
595 //=================================================================================
596 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
597 {
598   GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
599   
600   GEOM::GEOM_Object_var aGroup;
601   if ( myMode == CreateGroup ) 
602     aGroup = anOp->CreateGroup( myMainObj, getShapeType() );
603   else if ( myMode == EditGroup )
604     aGroup = myGroup;
605
606   if ( CORBA::is_nil( aGroup ) || ( myMode == CreateGroup && !anOp->IsDone() ) )
607     return false;
608
609   GEOM::ListOfLong_var aCurrList = anOp->GetObjects( aGroup );
610   if ( !anOp->IsDone()  )
611     return false;
612
613   for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
614     anOp->RemoveObject( aGroup, aCurrList[i] );
615     if ( !anOp->IsDone()  )
616       return false;
617   }
618
619   for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ ) {
620     anOp->AddObject( aGroup, myIdList->item( ii )->text().toInt() );    
621     if ( !anOp->IsDone()  )
622       return false;
623   }
624
625   SalomeApp_Study* study = getStudy();
626   if ( study ) {
627     string IOR = GEOMBase::GetIORFromObject( aGroup );
628     if ( IOR != "" ) {
629       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
630       if ( SO ) { 
631         _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
632         aBuilder->SetName( SO, getNewObjectName() );
633       }
634     }
635   }
636
637   objects.push_back( aGroup._retn() );
638
639   return true;
640 }
641
642 //================================================================
643 // Function : getFather
644 // Purpose  : Get father object for object to be added in study
645 //            ( called with addInStudy method )
646 //================================================================
647 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj )
648 {
649   GEOM::GEOM_Object_var aFatherObj;
650   if ( theObj->GetType() == GEOM_GROUP ) {
651     GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
652     aFatherObj = anOp->GetMainShape( theObj );
653   }
654   return aFatherObj._retn();
655 }