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