]> SALOME platform Git repositories - modules/geom.git/blob - src/GroupGUI/GroupGUI_GroupDlg.cxx
Salome HOME
*** empty log message ***
[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.com
21 //
22 // File   : GroupGUI_GroupDlg.cxx
23 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
24 //
25
26 #include "GroupGUI_GroupDlg.h"
27
28 #include <SUIT_Desktop.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #include <LightApp_SelectionMgr.h>
34
35 #include <DlgRef.h>
36 #include <GEOMBase.h>
37
38 #include <GEOMImpl_Types.hxx>
39
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TColStd_MapOfInteger.hxx>
42
43 GroupGUI_GroupDlg::GroupGUI_GroupDlg( Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent )
44   : GEOMBase_Skeleton( theGeometryGUI, parent, false ),
45     myMode( mode ),
46     myBusy( false )
47 {
48   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
49
50   QPixmap image0    ( resMgr->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_VERTEX" ) ) );
51   QPixmap image1    ( resMgr->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_EDGE" ) ) );
52   QPixmap image2    ( resMgr->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_FACE" ) ) );
53   QPixmap image3    ( resMgr->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_SOLID" ) ) );
54   QPixmap iconSelect( resMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55
56   setWindowTitle( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
57
58   // Shape type button group
59   mainFrame()->GroupConstructors->setEnabled( myMode == CreateGroup );
60   mainFrame()->GroupConstructors->setTitle( tr( "SHAPE_TYPE" ) );
61   mainFrame()->RadioButton1->setIcon( image0 );
62   mainFrame()->RadioButton2->setIcon( image1 );
63   mainFrame()->RadioButton3->setIcon( image2 );
64   mainFrame()->RadioButton4->setIcon( image3 );
65   mainFrame()->RadioButton4->show();
66
67   // Group name
68   mainFrame()->GroupBoxName->setTitle( tr( "GROUP_NAME" ) );
69
70   // Main shape and sub-shapes
71   myGroupBox = new DlgRef_1Sel1List4Btn( centralWidget() );
72   myGroupBox->GroupBox1->setTitle( tr( "MAIN_SUB_SHAPES" ) );
73   myGroupBox->TextLabel1->setText( tr( "MAIN_SHAPE" ) );
74   myGroupBox->PushButton1->setIcon( iconSelect );
75   myGroupBox->PushButton1->setEnabled( myMode == CreateGroup );
76   myGroupBox->LineEdit1->setReadOnly( true );
77   myGroupBox->LineEdit1->setEnabled( myMode == CreateGroup );
78   myGroupBox->PushButton2->setText( tr( "SELECT_SUB_SHAPES" ) );
79   myGroupBox->PushButton3->setText( tr( "SELECT_ALL" ) );
80   myGroupBox->PushButton4->setText( tr( "ADD" ) );
81   myGroupBox->PushButton5->setText( tr( "REMOVE" ) );
82   myGroupBox->ListView1->setSelectionMode( QAbstractItemView::ExtendedSelection );
83   myGroupBox->ListView1->setFlow( QListView::TopToBottom );
84   myGroupBox->ListView1->setWrapping( true );
85
86   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
87   layout->setMargin( 0 ); layout->setSpacing( 6 );
88   layout->addWidget( myGroupBox );
89
90   setHelpFileName( "working_with_groups.htm" );
91
92   Init();
93 }
94
95 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
96 {
97 }
98
99
100 //=================================================================================
101 // function : Init()
102 // purpose  :
103 //=================================================================================
104 void GroupGUI_GroupDlg::Init()
105 {
106   // san -- TODO: clear selected sub-shapes...
107
108   if ( myMode == CreateGroup ) {
109     initName( tr( "GROUP_PREFIX" ) );
110
111     // Get ready for main shape selection
112     myEditCurrentArgument = myGroupBox->LineEdit1;
113
114     connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
115     connect( myGroupBox->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
116   }
117   else if ( myMode == EditGroup && IObjectCount() ) {
118     Standard_Boolean aResult = Standard_False;
119     GEOM::GEOM_Object_var anObj =
120       GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
121
122     if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
123       myGroup = anObj;
124
125       mainFrame()->ResultName->setText( GEOMBase::GetName( myGroup ) );
126
127       GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
128       myMainObj = anOp->GetMainShape( myGroup );
129       if ( !CORBA::is_nil( myMainObj ) )
130         myGroupBox->LineEdit1->setText( GEOMBase::GetName( myMainObj ) );
131
132       setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
133
134       GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
135       for ( int i = 0, n = aCurrList->length(); i < n; i++ )
136         myGroupBox->ListView1->addItem( new QListWidgetItem( QString( "%1" ).arg( aCurrList[i] ) ) );
137
138       myEditCurrentArgument = 0;
139     }
140   }
141
142   LightApp_SelectionMgr* aSelMgr =
143     ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
144
145   connect( aSelMgr,     SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
146
147   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk()    ) );
148   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
149
150   connect( myGroupBox->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
151   connect( myGroupBox->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
152   connect( myGroupBox->PushButton4, SIGNAL( clicked() ), this, SLOT( add() ) );
153   connect( myGroupBox->PushButton5, SIGNAL( clicked() ), this, SLOT( remove() ) );
154   connect( myGroupBox->ListView1,   SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) );
155
156   activateSelection();
157 }
158
159 //=================================================================================
160 // function : enterEvent()
161 // purpose  :
162 //=================================================================================
163 void GroupGUI_GroupDlg::enterEvent( QEvent* )
164 {
165   if ( !buttonCancel()->isEnabled() )
166     this->ActivateThisDialog();
167 }
168
169 //=================================================================================
170 // function : ClickOnOk()
171 // purpose  :
172 //=================================================================================
173 void GroupGUI_GroupDlg::ClickOnOk()
174 {
175   if ( ClickOnApply() )
176     ClickOnCancel();
177 }
178
179 //=================================================================================
180 // function : ClickOnApply()
181 // purpose  :
182 //=================================================================================
183 bool GroupGUI_GroupDlg::ClickOnApply()
184 {
185   if ( !onAccept( myMode == CreateGroup, true ) )
186     return false;
187
188   if ( myMode == CreateGroup ) {
189     initName();
190     myGroupBox->ListView1->clear();
191   }
192   else {
193     activateSelection();
194   }
195   return true;
196 }
197
198
199 //=================================================================================
200 // function : ActivateThisDialog()
201 // purpose  :
202 //=================================================================================
203 void GroupGUI_GroupDlg::ActivateThisDialog()
204 {
205   GEOMBase_Skeleton::ActivateThisDialog();
206
207   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
208            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
209
210   activateSelection();
211 }
212
213 //=================================================================================
214 // function : LineEditReturnPressed()
215 // purpose  :
216 //=================================================================================
217 void GroupGUI_GroupDlg::LineEditReturnPressed()
218 {
219   QLineEdit* send = ( QLineEdit* )sender();
220
221   if ( send == myGroupBox->LineEdit1 && !myEditCurrentArgument ) {
222     myEditCurrentArgument = myGroupBox->LineEdit1;
223     activateSelection();
224   }
225   else {
226     GEOMBase_Skeleton::LineEditReturnPressed();
227   }
228
229   updateState();
230 }
231
232
233 //=================================================================================
234 // function : SetEditCurrentArgument()
235 // purpose  :
236 //=================================================================================
237 void GroupGUI_GroupDlg::SetEditCurrentArgument()
238 {
239   QPushButton* send = (QPushButton*)sender();
240
241   if ( send == myGroupBox->PushButton1 )
242     myEditCurrentArgument = myGroupBox->LineEdit1;
243   else if ( send == myGroupBox->PushButton2 || send == myGroupBox->PushButton3 )
244     myEditCurrentArgument = 0;
245
246   activateSelection();
247
248   if ( send == myGroupBox->PushButton3 )
249     selectAllSubShapes();
250   else
251     updateState();
252 }
253
254
255 //=================================================================================
256 // function : SelectionIntoArgument()
257 // purpose  : Called when selection has changed
258 //=================================================================================
259 void GroupGUI_GroupDlg::SelectionIntoArgument()
260 {
261   if ( myEditCurrentArgument ) {  // Selection of a main shape is active
262     myEditCurrentArgument->setText( "" );
263     myGroupBox->ListView1->clear();
264
265     if ( IObjectCount() == 1 ) {
266       Standard_Boolean aResult = Standard_False;
267       GEOM::GEOM_Object_var anObj =
268         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
269
270       if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
271         myMainObj = anObj;
272         myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
273         updateState();
274         return;
275       }
276     }
277
278     myMainObj = GEOM::GEOM_Object::_nil();
279   }
280   else { // an attempt to synchronize list box selection with 3d viewer
281     if ( myBusy )
282       return;
283
284     bool isBlocked = myGroupBox->ListView1->signalsBlocked();
285     myGroupBox->ListView1->blockSignals( true );
286     myGroupBox->ListView1->clearSelection();
287
288     TColStd_IndexedMapOfInteger aMapIndex;
289
290     if ( IObjectCount() == 1 ) {
291       Standard_Boolean aResult = Standard_False;
292       GEOM::GEOM_Object_var anObj =
293         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
294
295       if ( aResult && !anObj->_is_nil() )
296         ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->
297           selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
298     }
299
300     // try to find out and process the object browser selection
301     if ( !aMapIndex.Extent() ) {
302       globalSelection( GEOM_ALLSHAPES );
303       
304       GEOM::ListOfGO anObjects;
305       GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
306
307       GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
308       GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
309
310       for (int i = 0; i < anObjects.length(); i++) {
311         GEOM::GEOM_Object_var aGeomObj = anObjects[i];
312         GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
313         TopoDS_Shape aShape;
314         if ( GEOMBase::GetShape( aGeomObj, aShape, getShapeType() ) ) {
315           aSubObjects->length(1);
316           aSubObjects[0] = aGeomObj;
317         }
318         else if (aGeomObj->GetType() == GEOM_GROUP)
319           aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
320         else
321           continue;
322
323         for (int i = 0; i < aSubObjects->length(); i++) {
324           TopoDS_Shape aShape;
325           if ( GEOMBase::GetShape( aSubObjects[i], aShape, getShapeType() ) ) {
326             CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
327             if ( anIndex >= 0 )
328               aMapIndex.Add( anIndex );
329           }
330         }
331       }
332       
333       if ( !myMainObj->_is_nil() )
334         localSelection( myMainObj, getShapeType() );
335     }
336
337     if ( aMapIndex.Extent() >= 1 ) {
338       QMap<int, int> aMap;
339       for ( int i = 0, n = myGroupBox->ListView1->count(); i < n; i++ )
340         aMap.insert( myGroupBox->ListView1->item( i )->text().toInt(), i );
341
342       for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
343         if ( aMap.contains( aMapIndex( ii ) ) )
344           myGroupBox->ListView1->item( aMap[aMapIndex( ii )])->setSelected( true );
345       }
346     }
347     myGroupBox->ListView1->blockSignals( isBlocked );
348   }
349
350   updateState();
351 }
352
353 //=================================================================================
354 // function : ConstructorsClicked()
355 // purpose  : Radio button management
356 //=================================================================================
357 void GroupGUI_GroupDlg::ConstructorsClicked( int )
358 {
359   myGroupBox->ListView1->clear();
360   activateSelection();
361   updateState();
362 }
363
364 //=================================================================================
365 // function : selectAllSubShapes
366 // purpose  : 
367 //=================================================================================
368 void GroupGUI_GroupDlg::selectAllSubShapes()
369 {
370   if ( CORBA::is_nil( myMainObj ) )
371     return;
372
373   GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
374   GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
375
376   GEOM::ListOfGO_var aSubShapes = aShOp->MakeExplode( myMainObj, getShapeType(), false );
377   if ( !aShOp->IsDone() )
378     return;
379
380   bool isBlocked = myGroupBox->ListView1->signalsBlocked();
381   myGroupBox->ListView1->blockSignals( true );
382   myGroupBox->ListView1->clear();
383
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     QListWidgetItem* anItem = new QListWidgetItem( QString( "%1" ).arg( anIndex ) );
390     myGroupBox->ListView1->addItem( anItem );
391     anItem->setSelected( true );
392   }
393
394   myGroupBox->ListView1->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 = myGroupBox->ListView1->count(); i < n; i++ )
407     aMap.Add( myGroupBox->ListView1->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() ) )->
418         selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
419   }
420
421   // try to find out and process the object browser selection
422   if ( !aMapIndex.Extent() ) {
423     GEOM::ListOfGO anObjects;
424     GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
425     
426     GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
427     GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
428     
429     for ( int i = 0; i < anObjects.length(); i++ ) {
430       GEOM::GEOM_Object_var aGeomObj = anObjects[i];
431       GEOM::ListOfGO_var aSubObjects  = new GEOM::ListOfGO();
432       TopoDS_Shape aShape;
433       if ( GEOMBase::GetShape( aGeomObj, aShape, getShapeType() ) ) {
434         aSubObjects->length( 1 );
435         aSubObjects[0] = aGeomObj;
436       }
437       else if ( aGeomObj->GetType() == GEOM_GROUP )
438         aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false );
439       else
440         break;
441         
442       for ( int i = 0; i < aSubObjects->length(); i++ ) {
443         TopoDS_Shape aShape;
444         if ( GEOMBase::GetShape( aSubObjects[i], aShape, getShapeType() ) ) {
445           CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
446           if ( anIndex >= 0 )
447             aMapIndex.Add( anIndex );
448         }
449       }
450     }
451   }
452
453   if ( aMapIndex.Extent() >= 1 ) {
454     bool isBlocked = myGroupBox->ListView1->signalsBlocked();
455     myGroupBox->ListView1->blockSignals( true );
456
457     for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
458       if ( aMap.Contains( aMapIndex( i ) ) )
459         continue;
460
461       QListWidgetItem* anItem = new QListWidgetItem( QString( "%1" ).arg( aMapIndex( i ) ) );
462       myGroupBox->ListView1->addItem( anItem );
463       anItem->setSelected( true );
464     }
465
466     myGroupBox->ListView1->blockSignals( isBlocked );
467   }
468
469   updateState();
470 }
471
472 //=================================================================================
473 // function : remove
474 // purpose  : 
475 //=================================================================================
476 void GroupGUI_GroupDlg::remove()
477 {
478   QListIterator<QListWidgetItem*> it( myGroupBox->ListView1->selectedItems() );
479   while ( it.hasNext() )
480     delete it.next();
481   updateState();
482 }
483
484
485 //=================================================================================
486 // function : getShapeType()
487 // purpose  :
488 //=================================================================================
489 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
490 {
491   switch ( getConstructorId() ) {
492   case 0:  return TopAbs_VERTEX;
493   case 1:  return TopAbs_EDGE;
494   case 2:  return TopAbs_FACE;
495   case 3:  return TopAbs_SOLID;
496   default: return TopAbs_SHAPE;
497   }
498 }
499
500 //=================================================================================
501 // function : setShapeType()
502 // purpose  :
503 //=================================================================================
504 void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
505 {
506   int anId = 0;
507   switch ( theType ) {
508   case TopAbs_VERTEX: anId = 0; break;
509   case TopAbs_EDGE:   anId = 1; break;
510   case TopAbs_FACE:   anId = 2; break;
511   case TopAbs_SOLID:  anId = 3; break;
512   }
513   setConstructorId( anId );
514 }
515
516
517 //=================================================================================
518 // function : activateSelection
519 // purpose  : Activate selection in accordance with myEditCurrentArgument
520 //=================================================================================
521 void GroupGUI_GroupDlg::activateSelection()
522 {
523   globalSelection( GEOM_ALLSHAPES );
524
525   if ( !myMainObj->_is_nil() && !myEditCurrentArgument ) {
526     localSelection( myMainObj, getShapeType() );
527   }
528
529   SelectionIntoArgument();
530 }
531
532 //=================================================================================
533 // function : updateState
534 // purpose  : 
535 //=================================================================================
536 void GroupGUI_GroupDlg::updateState()
537 {
538   bool isAdd = false;
539
540   TColStd_IndexedMapOfInteger aMapIndex;
541
542   if ( IObjectCount() == 1 ) {
543     Standard_Boolean aResult = Standard_False;
544     GEOM::GEOM_Object_var anObj =
545       GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
546
547     if ( aResult && !anObj->_is_nil() )
548       ( (SalomeApp_Application*)(SUIT_Session::session()->activeApplication() ) )->
549         selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
550   }
551
552   // try to find out and process the object browser selection
553   if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
554     GEOM::ListOfGO anObjects;
555     GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), anObjects );
556     
557     GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
558     GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
559
560      isAdd = true;
561      
562      for ( int i = 0; i < anObjects.length(); i++ ) {
563        GEOM::GEOM_Object_var aGeomObj = anObjects[i];
564        GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
565        TopoDS_Shape aShape;
566        if ( GEOMBase::GetShape( aGeomObj, aShape, getShapeType() ) ) {
567          aSubObjects->length( 1 );
568          aSubObjects[0] = aGeomObj;
569        }
570        else if ( aGeomObj->GetType() == GEOM_GROUP )
571          aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false );
572        else {
573          aMapIndex.Clear();
574          break;
575        }
576        
577        for ( int i = 0; i < aSubObjects->length(); i++ ) {
578          TopoDS_Shape aShape;
579          aSubObjects[i];
580          if ( GEOMBase::GetShape( aSubObjects[i], aShape, getShapeType() ) ) {
581            CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
582            if ( anIndex >= 0 )
583              aMapIndex.Add( anIndex );
584            else
585              isAdd = false;
586          }
587          else
588            isAdd = false;
589              
590          if ( !isAdd ) {
591            aMapIndex.Clear();
592            break;
593          }
594        }
595        
596        if ( !isAdd ) {
597          aMapIndex.Clear();
598          break;
599        }
600      }
601   }
602   
603   isAdd = aMapIndex.Extent() > 0;
604
605   myGroupBox->PushButton4->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
606   bool hasSel = myGroupBox->ListView1->selectedItems().count() > 0;
607   myGroupBox->PushButton5->setEnabled( hasSel );
608   myGroupBox->PushButton2->setEnabled( !CORBA::is_nil( myMainObj ) );
609   myGroupBox->PushButton3->setEnabled( !CORBA::is_nil( myMainObj ) );
610 }
611
612 //=================================================================================
613 // function : selectionChanged
614 // purpose  :
615 //=================================================================================
616 void GroupGUI_GroupDlg::selectionChanged()
617 {
618   highlightSubShapes();
619 }
620
621 //=================================================================================
622 // function : highlightSubShapes
623 // purpose  :
624 //=================================================================================
625 void GroupGUI_GroupDlg::highlightSubShapes()
626 {
627   if ( CORBA::is_nil( myMainObj ) )
628     return;
629
630   Standard_Boolean isOk;
631   char* objIOR = GEOMBase::GetIORFromObject( myMainObj );
632   Handle(GEOM_AISShape) aSh =
633     GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true );
634   free( objIOR );
635   if ( !isOk || aSh.IsNull() )
636     return;
637
638   TColStd_MapOfInteger anIds;
639
640   myBusy = true;
641
642   for ( int ii = 0, nn = myGroupBox->ListView1->count(); ii < nn; ii++ )
643     if ( myGroupBox->ListView1->item( ii )->isSelected() )
644       anIds.Add( myGroupBox->ListView1->item( ii )->text().toInt() );
645
646   LightApp_SelectionMgr* aSelMgr =
647     ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
648   aSelMgr->clearSelected();
649   aSelMgr->AddOrRemoveIndex( aSh->getIO(), anIds, false );
650
651   myBusy = false;
652
653   updateState();
654 }
655
656 //=================================================================================
657 // function : createOperation
658 // purpose  :
659 //=================================================================================
660 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
661 {
662   return getGeomEngine()->GetIGroupOperations( getStudyId() );
663 }
664
665 #define RETURN_WITH_MSG(a, b) \
666   if ( !(a) ) { \
667     theMessage += (b); \
668     return false; \
669   }
670
671 //=================================================================================
672 // function : isValid()
673 // purpose  : Verify validity of input data
674 //=================================================================================
675 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
676 {
677   SalomeApp_Study* study = getStudy();
678   ASSERT(study);
679   RETURN_WITH_MSG  ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
680
681   if ( myMode == CreateGroup ) {
682     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
683   }
684   else {
685     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
686   }
687
688   QString aName( getNewObjectName() );
689   RETURN_WITH_MSG  ( !aName.trimmed().isEmpty(), tr( "EMPTY_NAME" ) )
690
691   RETURN_WITH_MSG  ( myGroupBox->ListView1->count(), tr( "EMPTY_LIST" ) )
692   return true;
693 }
694
695 //=================================================================================
696 // function : execute
697 // purpose  :
698 //=================================================================================
699 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
700 {
701   GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
702
703   GEOM::GEOM_Object_var aGroup;
704   if ( myMode == CreateGroup )
705     aGroup = anOp->CreateGroup( myMainObj, getShapeType() );
706   else if ( myMode == EditGroup )
707     aGroup = myGroup;
708
709   if ( CORBA::is_nil( aGroup ) || ( myMode == CreateGroup && !anOp->IsDone() ) )
710     return false;
711
712   GEOM::ListOfLong_var aCurrList = anOp->GetObjects( aGroup );
713   if ( !anOp->IsDone()  )
714     return false;
715
716   for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
717     anOp->RemoveObject( aGroup, aCurrList[i] );
718     if ( !anOp->IsDone()  )
719       return false;
720   }
721
722   for ( int ii = 0, nn = myGroupBox->ListView1->count(); ii < nn; ii++ ) {
723     anOp->AddObject( aGroup, myGroupBox->ListView1->item( ii )->text().toInt() );
724     if ( !anOp->IsDone()  )
725       return false;
726   }
727
728   SalomeApp_Study* study = getStudy();
729   if ( study ) {
730     char* objIOR = GEOMBase::GetIORFromObject( aGroup );
731     string IOR( objIOR );
732     free( objIOR );
733     if ( IOR != "" ) {
734       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
735       if ( SO ) {
736         _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
737         aBuilder->SetName( SO, getNewObjectName() );
738       }
739     }
740   }
741
742   objects.push_back( aGroup._retn() );
743
744   return true;
745 }
746
747 //================================================================
748 // Function : getFather
749 // Purpose  : Get father object for object to be added in study
750 //            ( called with addInStudy method )
751 //================================================================
752 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj )
753 {
754   GEOM::GEOM_Object_var aFatherObj;
755   if ( theObj->GetType() == GEOM_GROUP ) {
756     GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
757     aFatherObj = anOp->GetMainShape( theObj );
758   }
759   return aFatherObj._retn();
760 }
761