Salome HOME
NPAL17269: Performance pb. when creating a group with GUI.
[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 //
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 GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
51   :GEOMBase_Skeleton( theGeometryGUI, parent, "GroupGUI_GroupDlg", false,
52                       WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
53    myMode( mode ),
54    myBusy( false )
55 {
56   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
57
58   QPixmap image0     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
59   QPixmap image1     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
60   QPixmap image2     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
61   QPixmap image3     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
62   QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63
64   setCaption( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
65
66   // Shape type button group
67   GroupConstructors->setEnabled( myMode == CreateGroup );
68   GroupConstructors->setTitle( tr( "SHAPE_TYPE" ) );
69   RadioButton1->setPixmap( image0 );
70   RadioButton2->setPixmap( image1 );
71   RadioButton3->setPixmap( image2 );
72   RadioButton4->setPixmap( image3 );
73   RadioButton4->show();
74
75   // Group name
76   GroupBoxName->setTitle( tr( "GROUP_NAME" ) );
77
78   // Main shape and sub-shapes
79   GroupMedium = new QGroupBox( 1, Qt::Vertical, tr( "MAIN_SUB_SHAPES" ), this );
80   GroupMedium->setInsideMargin( 10 );
81   Layout1->addWidget( GroupMedium, 2, 0 );
82
83   QWidget* aFrame = new QWidget( GroupMedium );
84   QGridLayout* aMedLayout = new QGridLayout( aFrame, 4, 4, 0, 6 );
85
86   QLabel* aMainLabel = new QLabel( tr( "MAIN_SHAPE" ), aFrame );
87
88   mySelBtn = new QPushButton( aFrame );
89   mySelBtn->setPixmap( iconSelect );
90   mySelBtn->setEnabled( myMode == CreateGroup );
91
92   myMainName = new QLineEdit( aFrame );
93   myMainName->setReadOnly( true );
94   myMainName->setEnabled( myMode == CreateGroup );
95
96   mySelSubBtn = new QPushButton( tr( "SELECT_SUB_SHAPES" ), aFrame );
97   mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame );
98   myAddBtn    = new QPushButton( tr( "ADD" ), aFrame );
99   myRemBtn    = new QPushButton( tr( "REMOVE" ), aFrame );
100   myIdList    = new QListBox( aFrame );
101
102   myIdList->setSelectionMode( QListBox::Extended );
103   myIdList->setRowMode( QListBox::FitToWidth );
104
105   aMedLayout->addWidget( aMainLabel, 0, 0 );
106   aMedLayout->addWidget( mySelBtn, 0, 1 );
107   aMedLayout->addMultiCellWidget( myMainName, 0, 0, 2, 3 );
108   aMedLayout->addMultiCellWidget( mySelSubBtn, 1, 1, 0, 2 );
109   aMedLayout->addWidget( mySelAllBtn, 1, 3 );
110   aMedLayout->addMultiCellWidget( myIdList, 2, 3, 0, 2 );
111   aMedLayout->addWidget( myAddBtn, 2, 3 );
112   aMedLayout->addWidget( myRemBtn, 3, 3 );
113
114   setHelpFileName("working_with_groups.htm");
115
116   Init();
117 }
118
119 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
120 {
121 }
122
123
124 //=================================================================================
125 // function : Init()
126 // purpose  :
127 //=================================================================================
128 void GroupGUI_GroupDlg::Init()
129 {
130   // san -- TODO: clear selected sub-shapes...
131
132   if ( myMode == CreateGroup ) {
133     initName( tr( "GROUP_PREFIX" ) );
134
135     // Get ready for main shape selection
136     myEditCurrentArgument = myMainName;
137
138     connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
139     connect( mySelBtn,          SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
140   }
141   else if ( myMode == EditGroup && IObjectCount() ) {
142     Standard_Boolean aResult = Standard_False;
143     GEOM::GEOM_Object_var anObj =
144       GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
145
146     if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
147       myGroup = anObj;
148
149       ResultName->setText( GEOMBase::GetName( myGroup ) );
150
151       GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
152       myMainObj = anOp->GetMainShape( myGroup );
153       if ( !CORBA::is_nil( myMainObj ) )
154         myMainName->setText( GEOMBase::GetName( myMainObj ) );
155
156       setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
157
158       GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
159       QListBoxItem* anItem;
160       for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
161         anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) );
162         myIdList->insertItem( anItem );
163       }
164
165       myEditCurrentArgument = 0;
166     }
167   }
168
169   LightApp_SelectionMgr* aSelMgr =
170     ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
171
172   connect( aSelMgr,     SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
173
174   connect( buttonOk   , SIGNAL( clicked() ), this, SLOT( ClickOnOk()    ) );
175   connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
176
177   connect( mySelSubBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
178   connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
179   connect( myAddBtn,    SIGNAL( clicked() ), this, SLOT( add() ) );
180   connect( myRemBtn,    SIGNAL( clicked() ), this, SLOT( remove() ) );
181   connect( myIdList,    SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
182
183   activateSelection();
184 }
185
186 //=================================================================================
187 // function : enterEvent()
188 // purpose  :
189 //=================================================================================
190 void GroupGUI_GroupDlg::enterEvent( QEvent* e )
191 {
192   if ( !buttonCancel->isEnabled() )
193     this->ActivateThisDialog();
194 }
195
196 //=================================================================================
197 // function : ClickOnOk()
198 // purpose  :
199 //=================================================================================
200 void GroupGUI_GroupDlg::ClickOnOk()
201 {
202   if ( ClickOnApply() )
203     ClickOnCancel();
204 }
205
206 //=================================================================================
207 // function : ClickOnApply()
208 // purpose  :
209 //=================================================================================
210 bool GroupGUI_GroupDlg::ClickOnApply()
211 {
212   if ( !onAccept( myMode == CreateGroup, true ) )
213     return false;
214
215   if ( myMode == CreateGroup )
216     {
217       initName();
218       myIdList->clear();
219     }
220   else
221     activateSelection();
222   return true;
223 }
224
225
226 //=================================================================================
227 // function : ActivateThisDialog()
228 // purpose  :
229 //=================================================================================
230 void GroupGUI_GroupDlg::ActivateThisDialog()
231 {
232   GEOMBase_Skeleton::ActivateThisDialog();
233
234   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
235            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
236
237   activateSelection();
238 }
239
240 //=================================================================================
241 // function : LineEditReturnPressed()
242 // purpose  :
243 //=================================================================================
244 void GroupGUI_GroupDlg::LineEditReturnPressed()
245 {
246   QLineEdit* send = ( QLineEdit* )sender();
247
248   if ( send == myMainName && !myEditCurrentArgument ) {
249     myEditCurrentArgument = myMainName;
250     activateSelection();
251   }
252   else
253     GEOMBase_Skeleton::LineEditReturnPressed();
254
255   updateState();
256 }
257
258
259 //=================================================================================
260 // function : SetEditCurrentArgument()
261 // purpose  :
262 //=================================================================================
263 void GroupGUI_GroupDlg::SetEditCurrentArgument()
264 {
265   QPushButton* send = (QPushButton*)sender();
266
267   if ( send == mySelBtn )
268     myEditCurrentArgument = myMainName;
269   else if ( send == mySelSubBtn || send == mySelAllBtn )
270     myEditCurrentArgument = 0;
271
272   activateSelection();
273
274   if ( send == mySelAllBtn )
275     selectAllSubShapes();
276   else
277     updateState();
278 }
279
280
281 //=================================================================================
282 // function : SelectionIntoArgument()
283 // purpose  : Called when selection has changed
284 //=================================================================================
285 void GroupGUI_GroupDlg::SelectionIntoArgument()
286 {
287   if ( myEditCurrentArgument ) {  // Selection of a main shape is active
288     myEditCurrentArgument->setText( "" );
289     myIdList->clear();
290
291     if ( IObjectCount() == 1 ) {
292       Standard_Boolean aResult = Standard_False;
293       GEOM::GEOM_Object_var anObj =
294         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
295
296       if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
297         myMainObj = anObj;
298         myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
299         updateState();
300         return;
301       }
302     }
303
304     myMainObj = GEOM::GEOM_Object::_nil();
305   }
306   else { // an attempt to synchronize list box selection with 3d viewer
307     if ( myBusy )
308       return;
309
310     bool isBlocked = myIdList->signalsBlocked();
311     myIdList->blockSignals( true );
312     myIdList->clearSelection();
313
314     TColStd_IndexedMapOfInteger aMapIndex;
315
316     SALOME_ListIO aSelIOs;
317     SalomeApp_Application* app = myGeomGUI->getApp();
318     if (app) {
319       LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
320       if (aSelMgr) {
321         QMap<QString, TColStd_IndexedMapOfInteger> aMap;
322         aSelMgr->selectedSubOwners(aMap);
323         if (aMap.size() == 1)
324           aMapIndex = aMap.begin().data();
325       }
326     }
327
328     // try to find out and process the object browser selection
329     if ( !aMapIndex.Extent() ) {
330       globalSelection( GEOM_ALLSHAPES );
331
332       GEOM::ListOfGO anObjects;
333       GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
334
335       GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
336       GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
337
338       for (int i = 0; i < anObjects.length(); i++)
339       {
340         GEOM::GEOM_Object_var aGeomObj = anObjects[i];
341         GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
342         TopoDS_Shape aShape;
343         if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
344         {
345           aSubObjects->length(1);
346           aSubObjects[0] = aGeomObj;
347         }
348         else if (aGeomObj->GetType() == GEOM_GROUP)
349           aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
350         else
351           continue;
352
353         for (int i = 0; i < aSubObjects->length(); i++)
354         {
355           TopoDS_Shape aShape;
356           if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
357           {
358             CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
359             if ( anIndex >= 0 )
360               aMapIndex.Add( anIndex );
361           }
362         }
363       }
364
365       if ( !myMainObj->_is_nil() )
366         localSelection( myMainObj, getShapeType() );
367     }
368
369     if (aMapIndex.Extent() >= 1) {
370       QMap<int, int> aMap;
371       for ( int i = 0, n = myIdList->count(); i < n; i++ )
372         aMap.insert( myIdList->item( i )->text().toInt(), i );
373
374       for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
375         if ( aMap.contains( aMapIndex( ii ) ) )
376           myIdList->setSelected( aMap[aMapIndex( ii )], true );
377       }
378     }
379     myIdList->blockSignals( isBlocked );
380   }
381
382   updateState();
383 }
384
385 //=================================================================================
386 // function : ConstructorsClicked()
387 // purpose  : Radio button management
388 //=================================================================================
389 void GroupGUI_GroupDlg::ConstructorsClicked( int constructorId )
390 {
391   myIdList->clear();
392   activateSelection();
393   updateState();
394 }
395
396 //=================================================================================
397 // function : selectAllSubShapes
398 // purpose  : 
399 //=================================================================================
400 void GroupGUI_GroupDlg::selectAllSubShapes()
401 {
402   if ( CORBA::is_nil( myMainObj ) )
403     return;
404
405   GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
406
407   GEOM::ListOfLong_var aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
408   if ( !aShOp->IsDone() )
409     return;
410
411   bool isBlocked = myIdList->signalsBlocked();
412   myIdList->blockSignals( true );
413   myIdList->clear();
414
415   QListBoxItem* anItem;
416   for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
417     CORBA::Long anIndex = aSubShapes[i];
418     if ( anIndex < 0 )
419       continue;
420
421     anItem = new QListBoxText( QString( "%1" ).arg( anIndex ) );
422     myIdList->insertItem( anItem );
423     myIdList->setSelected( anItem, true );
424   }
425
426   myIdList->blockSignals( isBlocked );
427   highlightSubShapes();
428   //updateState(); // already done in highlightSubShapes()
429 }
430
431 //=================================================================================
432 // function : add
433 // purpose  : 
434 //=================================================================================
435 void GroupGUI_GroupDlg::add()
436 {
437   TColStd_MapOfInteger aMap;
438   for ( int i = 0, n = myIdList->count(); i < n; i++ )
439     aMap.Add( myIdList->item( i )->text().toInt() );
440
441   TColStd_IndexedMapOfInteger aMapIndex;
442
443   SALOME_ListIO aSelIOs;
444   SalomeApp_Application* app = myGeomGUI->getApp();
445   if (app) {
446     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
447     if (aSelMgr) {
448       QMap<QString, TColStd_IndexedMapOfInteger> aMap;
449       aSelMgr->selectedSubOwners(aMap);
450       if (aMap.size() == 1)
451         aMapIndex = aMap.begin().data();
452     }
453   }
454
455   // try to find out and process the object browser selection
456   if ( !aMapIndex.Extent() ) {
457     GEOM::ListOfGO anObjects;
458     GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
459
460     GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
461     GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
462
463     for (int i = 0; i < anObjects.length(); i++)
464     {
465       GEOM::GEOM_Object_var aGeomObj = anObjects[i];
466       GEOM::ListOfGO_var aSubObjects  = new GEOM::ListOfGO();
467       TopoDS_Shape aShape;
468       if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) )
469       {
470         aSubObjects->length(1);
471         aSubObjects[0] = aGeomObj;
472       }
473       else if (aGeomObj->GetType() == GEOM_GROUP)
474         aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
475       else
476         break;
477
478       for (int i = 0; i < aSubObjects->length(); i++)
479       {
480         TopoDS_Shape aShape;
481         if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
482         {
483           CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
484           if ( anIndex >= 0 )
485             aMapIndex.Add( anIndex );
486         }
487       }
488     }
489   }
490
491   if ( aMapIndex.Extent() >= 1 ) {
492     QListBoxItem* anItem;
493     bool isBlocked = myIdList->signalsBlocked();
494     myIdList->blockSignals( true );
495
496     for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
497       if ( aMap.Contains( aMapIndex( i ) ) )
498         continue;
499
500       anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
501       myIdList->insertItem( anItem );
502       myIdList->setSelected( anItem, true );
503     }
504
505     myIdList->blockSignals( isBlocked );
506   }
507
508   updateState();
509 }
510
511 //=================================================================================
512 // function : remove
513 // purpose  : 
514 //=================================================================================
515 void GroupGUI_GroupDlg::remove()
516 {
517   bool isBlocked = myIdList->signalsBlocked();
518   myIdList->blockSignals( true );
519
520   for ( int i = myIdList->count() - 1; i >= 0; i-- ) {
521     if ( myIdList->isSelected( i ) )
522       myIdList->removeItem( i );
523   }
524
525   myIdList->blockSignals( isBlocked );
526
527   highlightSubShapes();
528 }
529
530
531 //=================================================================================
532 // function : getConstructorId()
533 // purpose  :
534 //=================================================================================
535 int GroupGUI_GroupDlg::getConstructorId() const
536 {
537   return GroupConstructors->id( GroupConstructors->selected() );
538 }
539
540 //=================================================================================
541 // function : getShapeType()
542 // purpose  :
543 //=================================================================================
544 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
545 {
546   switch ( getConstructorId() ) {
547   case 0:  return TopAbs_VERTEX;
548   case 1:  return TopAbs_EDGE;
549   case 2:  return TopAbs_FACE;
550   case 3:  return TopAbs_SOLID;
551   default: return TopAbs_SHAPE;
552   }
553 }
554
555 //=================================================================================
556 // function : setShapeType()
557 // purpose  :
558 //=================================================================================
559 void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
560 {
561   int anId = 0;
562   switch ( theType ) {
563   case TopAbs_VERTEX: anId = 0; break;
564   case TopAbs_EDGE:   anId = 1; break;
565   case TopAbs_FACE:   anId = 2; break;
566   case TopAbs_SOLID:  anId = 3; break;
567   }
568   GroupConstructors->setButton( anId );
569 }
570
571
572 //=================================================================================
573 // function : activateSelection
574 // purpose  : Activate selection in accordance with myEditCurrentArgument
575 //=================================================================================
576 void GroupGUI_GroupDlg::activateSelection()
577 {
578   globalSelection( GEOM_ALLSHAPES );
579
580   if ( !myMainObj->_is_nil() && !myEditCurrentArgument ) {
581     localSelection( myMainObj, getShapeType() );
582   }
583
584   SelectionIntoArgument();
585 }
586
587 //=================================================================================
588 // function : updateState
589 // purpose  : 
590 //=================================================================================
591 void GroupGUI_GroupDlg::updateState()
592 {
593   bool isAdd = false;
594
595   TColStd_IndexedMapOfInteger aMapIndex;
596
597   SALOME_ListIO aSelIOs;
598   SalomeApp_Application* app = myGeomGUI->getApp();
599   if (app) {
600     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
601     if (aSelMgr) {
602       QMap<QString, TColStd_IndexedMapOfInteger> aMap;
603       aSelMgr->selectedSubOwners(aMap);
604       if (aMap.size() == 1)
605         aMapIndex = aMap.begin().data();
606     }
607   }
608
609   // try to find out and process the object browser selection
610   if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
611     GEOM::ListOfGO anObjects;
612     //GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
613     GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
614
615     GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
616     GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
617
618     isAdd = true;
619
620     for (int i = 0; i < anObjects.length(); i++)
621     {
622       GEOM::GEOM_Object_var aGeomObj = anObjects[i];
623       GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
624       TopoDS_Shape aShape;
625       if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) {
626         aSubObjects->length(1);
627         aSubObjects[0] = aGeomObj;
628       }
629       else if (aGeomObj->GetType() == GEOM_GROUP) {
630         aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
631       }
632       else {
633         aMapIndex.Clear();
634         break;
635       }
636
637       for (int i = 0; i < aSubObjects->length(); i++)
638       {
639         TopoDS_Shape aShape;
640         aSubObjects[i];
641         if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) )
642         {
643           CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
644           if ( anIndex >= 0 )
645             aMapIndex.Add( anIndex );
646           else
647             isAdd = false;
648         }
649         else
650           isAdd = false;
651
652         if ( !isAdd ) {
653           aMapIndex.Clear();
654           break;
655         }
656       }
657
658       if ( !isAdd ) {
659         aMapIndex.Clear();
660         break;
661       }
662     }
663   }
664
665   isAdd = aMapIndex.Extent() > 0;
666
667   myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
668   bool hasSel = false;
669   for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ )
670     hasSel =  myIdList->isSelected( ii );
671   myRemBtn->setEnabled( hasSel );
672   mySelSubBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
673   mySelAllBtn->setEnabled( !CORBA::is_nil( myMainObj ) );
674 }
675
676 //=================================================================================
677 // function : selectionChanged
678 // purpose  :
679 //=================================================================================
680 void GroupGUI_GroupDlg::selectionChanged()
681 {
682   highlightSubShapes();
683 }
684
685 //=================================================================================
686 // function : highlightSubShapes
687 // purpose  :
688 //=================================================================================
689 void GroupGUI_GroupDlg::highlightSubShapes()
690 {
691   if ( CORBA::is_nil( myMainObj ) )
692     return;
693
694   Standard_Boolean isOk;
695   Handle(GEOM_AISShape) aSh =
696     GEOMBase::ConvertIORinGEOMAISShape( GEOMBase::GetIORFromObject( myMainObj ), isOk, true );
697   if ( !isOk || aSh.IsNull() )
698     return;
699
700   TColStd_MapOfInteger anIds;
701
702   myBusy = true;
703
704   int ii = 0, nn = myIdList->count();
705   for ( ; ii < nn; ii++ )
706     if ( myIdList->isSelected( ii ) )
707       anIds.Add( myIdList->item( ii )->text().toInt() );
708
709   SalomeApp_Application* app = myGeomGUI->getApp();
710   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
711   aSelMgr->clearSelected();
712   //if (nn < 3000) aSelMgr->AddOrRemoveIndex(aSh->getIO(), anIds, false);
713   aSelMgr->AddOrRemoveIndex(aSh->getIO(), anIds, false);
714
715   myBusy = false;
716
717   //updateState();
718   if (nn < 3000) {
719     updateState();
720   }
721   else {
722     myAddBtn->setEnabled( true );
723     myRemBtn->setEnabled( true );
724   }
725 }
726
727 //=================================================================================
728 // function : createOperation
729 // purpose  :
730 //=================================================================================
731 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
732 {
733   return getGeomEngine()->GetIGroupOperations( getStudyId() );
734 }
735
736 #define RETURN_WITH_MSG(a, b) \
737   if ( !(a) ) { \
738     theMessage += (b); \
739     return false; \
740   }
741
742 //=================================================================================
743 // function : isValid()
744 // purpose  : Verify validity of input data
745 //=================================================================================
746 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
747 {
748   SalomeApp_Study* study = getStudy();
749   ASSERT(study);
750   RETURN_WITH_MSG  ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
751
752   if ( myMode == CreateGroup ) {
753     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
754   }
755   else {
756     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
757   }
758
759   QString aName (getNewObjectName());
760   RETURN_WITH_MSG  ( !aName.stripWhiteSpace().isEmpty(), tr( "EMPTY_NAME" ) )
761
762   RETURN_WITH_MSG  ( myIdList->count(), tr( "EMPTY_LIST" ) )
763   return true;
764 }
765
766 //=================================================================================
767 // function : execute
768 // purpose  :
769 //=================================================================================
770 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
771 {
772   GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
773
774   GEOM::GEOM_Object_var aGroup;
775   if (myMode == CreateGroup)
776     aGroup = anOp->CreateGroup(myMainObj, getShapeType());
777   else if (myMode == EditGroup)
778     aGroup = myGroup;
779
780   if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOp->IsDone()))
781     return false;
782
783   GEOM::ListOfLong_var aCurrList = anOp->GetObjects(aGroup);
784   if (!anOp->IsDone())
785     return false;
786
787   if (aCurrList->length() > 0)
788   {
789     anOp->DifferenceIDs(aGroup, aCurrList);
790     if (!anOp->IsDone())
791       return false;
792   }
793
794   int ii, nn = myIdList->count();
795   if (nn > 0)
796   {
797     GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
798     aNewList->length(nn);
799     for (ii = 0; ii < nn; ii++) {
800       aNewList[ii] = myIdList->item(ii)->text().toInt();
801     }
802     anOp->UnionIDs(aGroup, aNewList);
803     if (!anOp->IsDone())
804       return false;
805   }
806
807   SalomeApp_Study* study = getStudy();
808   if ( study ) {
809     string IOR = GEOMBase::GetIORFromObject( aGroup );
810     if ( IOR != "" ) {
811       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
812       if ( SO ) {
813         _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
814         aBuilder->SetName( SO, getNewObjectName() );
815       }
816     }
817   }
818
819   objects.push_back( aGroup._retn() );
820
821   return true;
822 }
823
824 //================================================================
825 // Function : getFather
826 // Purpose  : Get father object for object to be added in study
827 //            ( called with addInStudy method )
828 //================================================================
829 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj )
830 {
831   GEOM::GEOM_Object_var aFatherObj;
832   if ( theObj->GetType() == GEOM_GROUP ) {
833     GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
834     aFatherObj = anOp->GetMainShape( theObj );
835   }
836   return aFatherObj._retn();
837 }