]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_SubShapeDlg.cxx
Salome HOME
d46c3635311e5383347b11fa5f7333671d568c76
[modules/geom.git] / src / EntityGUI / EntityGUI_SubShapeDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
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 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : EntityGUI_SubShapeDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26
27 #include "EntityGUI_SubShapeDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32
33 #include <OCCViewer_ViewModel.h>
34 #include <SVTK_ViewModel.h>
35 #include <SalomeApp_Study.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SALOME_ListIteratorOfListIO.hxx>
39
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_ViewManager.h>
44 #include <SUIT_ViewWindow.h>
45
46 #include <TopExp.hxx>
47 #include <TopExp_Explorer.hxx>
48 #include <TopoDS_Iterator.hxx>
49 #include <TopTools_MapOfShape.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51
52 #include <TColStd_IndexedMapOfInteger.hxx>
53
54 #include <QMessageBox>
55
56 #include <GEOMImpl_Types.hxx>
57
58 //=================================================================================
59 // class    : EntityGUI_SubShapeDlg
60 // purpose  : Constructs a EntityGUI_SubShapeDlg which is a child of 'parent', with the
61 //            name 'name' and widget flags set to 'f'.
62 //            The dialog will by default be modeless, unless you set 'modal' to
63 //            TRUE to construct a modal dialog.
64 //=================================================================================
65 EntityGUI_SubShapeDlg::EntityGUI_SubShapeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
66                                               bool modal, Qt::WindowFlags fl)
67   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
68 {
69   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SUBSHAPE")));
70   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
71
72   setWindowTitle(tr("GEOM_SUBSHAPE_TITLE"));
73
74   /***************************************************************/
75   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUB_SHAPE"));
76   mainFrame()->RadioButton1->setIcon(image0);
77   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
78   mainFrame()->RadioButton2->close();
79   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
80   mainFrame()->RadioButton3->close();
81
82   GroupPoints = new DlgRef_1Sel1List1Check3Btn(centralWidget());
83
84   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
85   GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
86   GroupPoints->TextLabel2->setText(tr("GEOM_SUBSHAPE_TYPE"));
87   GroupPoints->CheckButton1->setText(tr("GEOM_SUBSHAPE_SELECT"));
88   GroupPoints->PushButton1->setIcon(image1);
89   GroupPoints->PushButton2->setText(tr("SHOW_ONLY_SELECTED"));
90   GroupPoints->PushButton3->setText(tr("HIDE_SELECTED"));
91   GroupPoints->PushButton4->setText(tr("SHOW_ALL_SUB_SHAPES"));
92   GroupPoints->LineEdit1->setReadOnly(true);
93
94   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
95   layout->setMargin(0); layout->setSpacing(6);
96   layout->addWidget(GroupPoints);
97   /***************************************************************/
98
99   setIsOptimizedBrowsing(true);
100
101   setHelpFileName("create_explode_page.html");
102
103   mainFrame()->GroupBoxName->hide();
104
105   Init();
106 }
107
108 //=================================================================================
109 // function : ~EntityGUI_SubShapeDlg()
110 // purpose  : Destroys the object and frees any allocated resources
111 //=================================================================================
112 EntityGUI_SubShapeDlg::~EntityGUI_SubShapeDlg()
113 {
114 }
115
116 //=================================================================================
117 // function : Init()
118 // purpose  :
119 //=================================================================================
120 void EntityGUI_SubShapeDlg::Init()
121 {
122   /* init variables */
123   myEditCurrentArgument = GroupPoints->LineEdit1;
124   myObject = GEOM::GEOM_Object::_nil();
125
126   myWithShape = true;
127
128   /* type for sub shape selection */
129   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
130   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
131   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
132   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
133   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
134   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
135   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
136   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
137   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
138
139   if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
140       != OCCViewer_Viewer::Type())
141     GroupPoints->CheckButton1->setEnabled(false);
142
143   /* signals and slots connections */
144   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
145
146   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
147   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
148
149   connect(GroupPoints->PushButton1,  SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
150   connect(GroupPoints->LineEdit1,    SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151
152   connect(GroupPoints->ComboBox1,    SIGNAL(activated(int)),    this, SLOT(ComboTextChanged()));
153   connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(SubShapeToggled()));
154
155   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
156   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
157   connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
158
159   connect(myGeomGUI->getApp()->selectionMgr(),
160           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
161
162   updateButtonState();
163   resize(100,100);
164   SelectionIntoArgument();
165 }
166
167 //=================================================================================
168 // function : enterEvent()
169 // purpose  :
170 //=================================================================================
171 void EntityGUI_SubShapeDlg::enterEvent(QEvent*)
172 {
173   if (!mainFrame()->GroupConstructors->isEnabled())
174     ActivateThisDialog();
175 }
176
177 //=================================================================================
178 // function : ActivateThisDialog()
179 // purpose  :
180 //=================================================================================
181 void EntityGUI_SubShapeDlg::ActivateThisDialog()
182 {
183   GEOMBase_Skeleton::ActivateThisDialog();
184   connect(myGeomGUI->getApp()->selectionMgr(),
185            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
186   SubShapeToggled();
187   updateButtonState();
188 }
189
190 //=================================================================================
191 //function : closeEvent
192 //purpose  : remove temporary geom object
193 //=================================================================================
194 void EntityGUI_SubShapeDlg::closeEvent(QCloseEvent* e)
195 {
196   erasePreview(true);
197   GEOMBase_Skeleton::closeEvent(e);
198 }
199
200 //=================================================================================
201 // function : ClickOnOk()
202 // purpose  :
203 //=================================================================================
204 void EntityGUI_SubShapeDlg::ClickOnOk()
205 {
206   setIsApplyAndClose(true);
207
208   SUIT_Session::session()->activeApplication()->putInfo("");
209
210   /* Explode all sub shapes */
211   bool isOk = true;
212   if (isAllSubShapes()) {
213     /* More than 30 subshapes : ask confirmation */
214     unsigned int nb = NumberOfSubShapes(myShape, shapeType());
215     if (nb > 30) {
216       const QString caption = tr("GEOM_CONFIRM");
217       const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
218       const QString button0 = tr("GEOM_BUT_EXPLODE");
219       const QString button1 = tr("GEOM_BUT_CANCEL");
220
221       if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
222         isOk = false;  /* aborted */
223     }
224   }
225
226   if (isOk)
227     isOk = onAccept();
228
229   if (isOk)
230     ClickOnCancel();
231 }
232
233 //=================================================================================
234 // function : ClickOnApply()
235 // purpose  :
236 //=================================================================================
237 bool EntityGUI_SubShapeDlg::ClickOnApply()
238 {
239   SUIT_Session::session()->activeApplication()->putInfo("");
240
241   /* Explode all sub shapes */
242   if (isAllSubShapes()) {
243     /* More than 30 subshapes : ask confirmation */
244     unsigned int nb = NumberOfSubShapes(myShape, shapeType());
245     if (nb > 30) {
246       const QString caption = tr("GEOM_CONFIRM");
247       const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
248       const QString button0 = tr("GEOM_BUT_EXPLODE");
249       const QString button1 = tr("GEOM_BUT_CANCEL");
250
251       if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
252         return false;  /* aborted */
253     }
254   }
255
256   bool isOk = onAccept();
257
258   // restore selection, corresponding to current selection mode
259   SubShapeToggled();
260
261   return isOk;
262 }
263
264 //=================================================================================
265 // function : SelectionIntoArgument()
266 // purpose  : Called when selection has changed or other case
267 //=================================================================================
268 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
269 {
270   if (!isAllSubShapes())
271     return;
272
273   ResetStateOfDialog();
274
275   QString aString = ""; /* name of selection */
276
277   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
278   SALOME_ListIO aSelList;
279   aSelMgr->selectedObjects(aSelList);
280
281   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
282   if (nbSel != 1)
283     return;
284
285   Handle(SALOME_InteractiveObject) IO = aSelList.First();
286   if (!IO->hasEntry()) {
287     SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
288     updateButtonState();
289     return;
290   }
291
292   TopoDS_Shape S = GEOMBase::GetTopoFromSelection(aSelList);
293   if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX) {
294     myObject = GEOM::GEOM_Object::_nil();
295     updateButtonState();
296     return;
297   }
298
299   myObject = GEOMBase::ConvertIOinGEOMObject(IO);
300   if (myObject->_is_nil()) {
301     updateButtonState();
302     return;
303   }
304
305   myShape = S;
306   GroupPoints->LineEdit1->setText(aString);
307
308   int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
309   int count = GroupPoints->ComboBox1->count();
310
311   if (myWithShape)
312     count = count - 1;
313
314   int i = 0;
315   // Solving PAL5590
316   if (myShape.ShapeType() == TopAbs_COMPOUND) {
317     unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
318     if (nb > 0)
319       i++;
320   }
321   while (i <= myShape.ShapeType()) {
322     GroupPoints->ComboBox1->removeItem(0);
323     i++;
324   }
325
326   if (myShape.ShapeType() == TopAbs_COMPOUND) {
327     if (myWithShape == false) {
328       GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
329       myWithShape = true;
330     }
331   }
332   else {
333     if (myWithShape == true) {
334       GroupPoints->ComboBox1->removeItem(GroupPoints->ComboBox1->count() - 1);
335       myWithShape = false;
336     }
337   }
338
339   int count1 = GroupPoints->ComboBox1->count();
340   if (myWithShape)
341     count1 = count1 - 1;
342
343   if (SelectedShapeType > myShape.ShapeType()) {
344     if (SelectedShapeType == 8) {
345       if (myShape.ShapeType() != TopAbs_COMPOUND) {
346         GroupPoints->ComboBox1->setCurrentIndex(0);
347         ComboTextChanged();
348       }
349     }
350     else
351       GroupPoints->ComboBox1->setCurrentIndex(count1 - count + SelectedShapeType);
352   }
353   else {
354     GroupPoints->ComboBox1->setCurrentIndex(0);
355     ComboTextChanged();
356   }
357
358   updateButtonState();
359 }
360
361 //=================================================================================
362 // function : SetEditCurrentArgument()
363 // purpose  :
364 //=================================================================================
365 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
366 {
367   GroupPoints->LineEdit1->setFocus();
368   myEditCurrentArgument = GroupPoints->LineEdit1;
369
370   GroupPoints->CheckButton1->setChecked(false);
371   SubShapeToggled();
372   SelectionIntoArgument();
373 }
374
375 //=================================================================================
376 // function : LineEditReturnPressed()
377 // purpose  :
378 //=================================================================================
379 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
380 {
381   QLineEdit* send = (QLineEdit*)sender();
382   if (send == GroupPoints->LineEdit1)
383     SetEditCurrentArgument();
384   else
385     return;
386
387   GEOMBase_Skeleton::LineEditReturnPressed();
388 }
389
390 //=================================================================================
391 // function : ResetStateOfDialog()
392 // purpose  : Completely reset the state of method including local context
393 //=================================================================================
394 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
395 {
396   myObject = GEOM::GEOM_Object::_nil();
397   myShape.Nullify();
398   myEditCurrentArgument->setText("");
399
400   int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
401   int count = GroupPoints->ComboBox1->count();
402   if (myWithShape)
403     count = count - 1;
404
405   /* type for sub shape selection */
406   GroupPoints->ComboBox1->clear();
407   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
408   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
409   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
410   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
411   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
412   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
413   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
414   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
415   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
416
417   myWithShape = true;
418
419   GroupPoints->ComboBox1->setCurrentIndex(8 - count + SelectedShapeType);
420
421   // to avoid recursion: SelectionIntoArgument->ResetStateOfDialog->ComboTextChanged->SubShapeToggled->activateSelection->(currentSelectionChanged)->SelectionIntoArgument
422   //ComboTextChanged();
423
424   updateButtonState();
425 }
426
427 //=================================================================================
428 // function : SubShapeToggled()
429 // purpose  : Allow user selection of all or only selected sub shapes
430 //          : Called when 'CheckButton1' state change
431 //=================================================================================
432 void EntityGUI_SubShapeDlg::SubShapeToggled()
433 {
434   GroupPoints->PushButton2->setEnabled(!isAllSubShapes());
435   GroupPoints->PushButton3->setEnabled(!isAllSubShapes());
436   GroupPoints->PushButton4->setEnabled(!isAllSubShapes());
437
438   activateSelection();
439 }
440
441 //=================================================================================
442 // function : ComboTextChanged()
443 // purpose  :
444 //=================================================================================
445 void EntityGUI_SubShapeDlg::ComboTextChanged()
446 {
447   /* Select sub shapes mode not checked */
448   updateButtonState();
449   SubShapeToggled();
450 }
451
452 //=================================================================================
453 // function : NumberOfSubShapes()
454 // purpose  :
455 //=================================================================================
456 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes(const TopoDS_Shape& S,
457                                                       const int shapeType) const
458 {
459   if (S.IsNull())
460     return 0;
461
462   unsigned int index = 0;
463   TopTools_MapOfShape M;
464
465   if (S.ShapeType() == TopAbs_COMPOUND &&
466        (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
467          TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
468          TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
469     TopoDS_Iterator It(S, Standard_True, Standard_True);
470     for (; It.More(); It.Next()) {
471       if (M.Add(It.Value())) {
472         if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
473              TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
474           index++;
475         }
476       }
477     }
478   }
479   else {
480     TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
481     for (; Exp.More(); Exp.Next()) {
482       if (M.Add(Exp.Current())) {
483         index++;
484       }
485     }
486   }
487
488   M.Clear();
489   return index;
490 }
491
492 //=================================================================================
493 // function : updateButtonState
494 // purpose  :
495 //=================================================================================
496 void EntityGUI_SubShapeDlg::updateButtonState()
497 {
498   if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
499        myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND) {
500     GroupPoints->CheckButton1->setChecked(false);
501     GroupPoints->CheckButton1->setEnabled(false);
502   }
503   else
504     GroupPoints->CheckButton1->setEnabled(true);
505 }
506
507 //=================================================================================
508 // function : isAllSubShapes
509 // purpose  :
510 //=================================================================================
511 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
512 {
513   return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
514 }
515
516 //=================================================================================
517 // function : shapeType
518 // purpose  :
519 //=================================================================================
520 int EntityGUI_SubShapeDlg::shapeType() const
521 {
522   int type = GroupPoints->ComboBox1->currentIndex();
523
524   if (myObject->_is_nil())
525     return type;
526
527   // Solving PAL5590
528   type += myShape.ShapeType() + 1;
529   if (myShape.ShapeType() == TopAbs_COMPOUND &&
530        NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
531     type--;
532   }
533
534   return type;
535 }
536
537 //=================================================================================
538 // function : showOnlySelected
539 // purpose  :
540 //=================================================================================
541 void EntityGUI_SubShapeDlg::showOnlySelected()
542 {
543   if (CORBA::is_nil(myObject) || isAllSubShapes())
544     return;
545
546   QPushButton* send = (QPushButton*)sender();
547   if (send == GroupPoints->PushButton4) {
548     activateSelection();
549     return;
550   }
551
552   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
553   SALOME_ListIO aSelList;
554   aSelMgr->selectedObjects(aSelList);
555
556   GEOM_Displayer* aDisplayer = getDisplayer();
557
558   if (send == GroupPoints->PushButton3) {
559     aDisplayer->Erase(aSelList, false, true);
560   }
561   else {
562     aDisplayer->EraseAll();
563     aDisplayer->Display(aSelList, true);
564   }
565 }
566
567 //=================================================================================
568 // function : getSelectedSubshapes
569 // purpose  :
570 //=================================================================================
571 int EntityGUI_SubShapeDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
572 {
573   theMapIndex.Clear();
574
575   SalomeApp_Application* app = myGeomGUI->getApp();
576   if (!app || myObject->_is_nil())
577     return 0;
578
579   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
580   SALOME_ListIO aSelList;
581   aSelMgr->selectedObjects(aSelList);
582
583   // try to find out and process the global selection
584   // (of not published objects and of published sub-shapes)
585   {
586     SALOME_ListIteratorOfListIO anIter (aSelList);
587     for (int i = 0; anIter.More(); anIter.Next(), i++)
588     {
589       Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
590       QString anEntry = anIObj->getEntry();
591       QString str = "_";
592       int index = anEntry.lastIndexOf(str);
593       if (index > 0) // selection among special preview
594       {
595         anEntry.remove(0, index+1);
596         int anIndex = anEntry.toInt();
597         if (anIndex)
598           theMapIndex.Add(anIndex);
599       }
600       else // selection among published shapes
601       {
602         SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
603         if (!appStudy) return 0;
604         _PTR(Study) aStudy = appStudy->studyDS();
605
606         _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
607         GEOM::GEOM_Object_var aGeomObj =
608           GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
609         TopoDS_Shape aShape;
610         if (GEOMBase::GetShape(aGeomObj, aShape)) {
611           if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == (TopAbs_ShapeEnum)shapeType()) {
612             TopTools_IndexedMapOfShape aMainMap;
613             TopExp::MapShapes(myShape, aMainMap);
614
615             TopExp_Explorer anExp (aShape, (TopAbs_ShapeEnum)shapeType());
616             for (; anExp.More(); anExp.Next()) {
617               TopoDS_Shape aSubShape = anExp.Current();
618               int anIndex = aMainMap.FindIndex(aSubShape);
619               if (anIndex >= 0) {
620                 theMapIndex.Add(anIndex);
621               }
622             }
623           }
624         }
625       }
626     } // for aSelList
627   }
628
629   return theMapIndex.Extent();
630 }
631
632 //=================================================================================
633 // function : activateSelection
634 // purpose  : Activate selection in accordance with myEditCurrentArgument
635 //=================================================================================
636 void EntityGUI_SubShapeDlg::activateSelection()
637 {
638   erasePreview(false);
639
640   // local selection
641   if (!myObject->_is_nil() && !isAllSubShapes())
642   {
643     GEOM_Displayer* aDisplayer = getDisplayer();
644     aDisplayer->Erase(myObject, false, false);
645
646     int prevDisplayMode = aDisplayer->SetDisplayMode(0);
647
648     SUIT_ViewWindow* aViewWindow = 0;
649     SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
650     if (activeStudy)
651       aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
652     if (aViewWindow == 0) return;
653
654     SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
655     if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
656         aViewManager->getType() != SVTK_Viewer::Type())
657       return;
658
659     SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
660     SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
661     if (aView == 0) return;
662
663     //TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
664
665     TopTools_IndexedMapOfShape aSubShapesMap;
666     TopExp::MapShapes(myShape, aSubShapesMap);
667     CORBA::String_var aMainEntry = myObject->GetStudyEntry();
668     QString anEntryBase = aMainEntry.in();
669
670     TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
671     for (; anExp.More(); anExp.Next())
672     {
673       TopoDS_Shape aSubShape = anExp.Current();
674       int index = aSubShapesMap.FindIndex(aSubShape);
675       QString anEntry = anEntryBase + QString("_%1").arg(index);
676
677       SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
678       if (aPrs) {
679         displayPreview(aPrs, true, false); // append, do not update
680       }
681     }
682     aDisplayer->UpdateViewer();
683     aDisplayer->SetDisplayMode(prevDisplayMode);
684   }
685
686   globalSelection(GEOM_ALLSHAPES);
687 }
688
689 //=================================================================================
690 // function : createOperation
691 // purpose  :
692 //=================================================================================
693 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
694 {
695   return getGeomEngine()->GetIShapesOperations(getStudyId());
696 }
697
698 //=================================================================================
699 // function : isValid
700 // purpose  :
701 //=================================================================================
702 bool EntityGUI_SubShapeDlg::isValid (QString& msg)
703 {
704   bool isOk = false;
705
706   if (myObject->_is_nil()) {
707     updateButtonState();
708     return isOk;
709   }
710
711   if (isAllSubShapes())
712     isOk = true;
713   else {
714     TColStd_IndexedMapOfInteger aMapIndex;
715     int nbSel = getSelectedSubshapes(aMapIndex);
716     isOk = nbSel > 0;
717
718     if (!isOk)
719       msg += tr("NO_SUBSHAPES_SELECTED");
720   }
721
722   return isOk;
723 }
724
725 //=================================================================================
726 // function : execute
727 // purpose  :
728 //=================================================================================
729 bool EntityGUI_SubShapeDlg::execute (ObjectList& objects)
730 {
731   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
732
733   if (!isAllSubShapes()) {
734     // manual selection
735     TColStd_IndexedMapOfInteger aMapIndex;
736     int nbSel = getSelectedSubshapes(aMapIndex);
737
738     if (nbSel > 0) {
739       int i;
740
741       GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
742       anArray->length(nbSel);
743
744       for (i = 1; i <= nbSel; i++)
745         anArray[i - 1] = aMapIndex.FindKey(i);
746
747       GEOM::ListOfGO_var aList = anOper->MakeSubShapes(myObject, anArray);
748       int n = aList->length();
749       for (i = 0; i < n; i++)
750         objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
751     }
752   }
753   else {
754     GEOM::ListOfGO_var aList = anOper->ExtractSubShapes(myObject, shapeType(), true);
755     if (!aList->length())
756       return false;
757     for (int i = 0, n = aList->length(); i < n; i++)
758       objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
759   }
760
761   return objects.size();
762 }
763
764 //================================================================
765 // Function : getFather
766 // Purpose  : Get father object for object to be added in study
767 //            (called with addInStudy method)
768 //================================================================
769 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather(GEOM::GEOM_Object_ptr)
770 {
771   return myObject;
772 }
773
774 //================================================================
775 // Function : getNewObjectName
776 // Purpose  :
777 //================================================================
778 QString EntityGUI_SubShapeDlg::getNewObjectName() const
779 {
780   return QString::null;
781 }