]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_SubShapeDlg.cxx
Salome HOME
IMP 0021069: Hide selected in explode function
[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   if (ClickOnApply())
207     ClickOnCancel();
208 }
209
210 //=================================================================================
211 // function : ClickOnApply()
212 // purpose  :
213 //=================================================================================
214 bool EntityGUI_SubShapeDlg::ClickOnApply()
215 {
216   SUIT_Session::session()->activeApplication()->putInfo("");
217
218   /* Explode all sub shapes */
219   if (isAllSubShapes()) {
220     /* More than 30 subshapes : ask confirmation */
221     unsigned int nb = NumberOfSubShapes(myShape, shapeType());
222     if (nb > 30) {
223       const QString caption = tr("GEOM_CONFIRM");
224       const QString text = tr("GEOM_CONFIRM_INFO").arg(nb);
225       const QString button0 = tr("GEOM_BUT_EXPLODE");
226       const QString button1 = tr("GEOM_BUT_CANCEL");
227
228       if (QMessageBox::warning(this, caption, text, button0, button1) != 0)
229         return false;  /* aborted */
230     }
231   }
232
233   bool isOk = onAccept();
234
235   // restore selection, corresponding to current selection mode
236   SubShapeToggled();
237
238   return isOk;
239 }
240
241 //=================================================================================
242 // function : SelectionIntoArgument()
243 // purpose  : Called when selection has changed or other case
244 //=================================================================================
245 void EntityGUI_SubShapeDlg::SelectionIntoArgument()
246 {
247   if (!isAllSubShapes())
248     return;
249
250   ResetStateOfDialog();
251
252   QString aString = ""; /* name of selection */
253
254   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
255   SALOME_ListIO aSelList;
256   aSelMgr->selectedObjects(aSelList);
257
258   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
259   if (nbSel != 1)
260     return;
261
262   Handle(SALOME_InteractiveObject) IO = aSelList.First();
263   if (!IO->hasEntry()) {
264     SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
265     updateButtonState();
266     return;
267   }
268
269   TopoDS_Shape S = GEOMBase::GetTopoFromSelection(aSelList);
270   if (S.IsNull() || S.ShapeType() == TopAbs_VERTEX) {
271     myObject = GEOM::GEOM_Object::_nil();
272     updateButtonState();
273     return;
274   }
275
276   myObject = GEOMBase::ConvertIOinGEOMObject(IO);
277   if (myObject->_is_nil()) {
278     updateButtonState();
279     return;
280   }
281
282   myShape = S;
283   GroupPoints->LineEdit1->setText(aString);
284
285   int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
286   int count = GroupPoints->ComboBox1->count();
287
288   if (myWithShape)
289     count = count - 1;
290
291   int i = 0;
292   // Solving PAL5590
293   if (myShape.ShapeType() == TopAbs_COMPOUND) {
294     unsigned int nb = NumberOfSubShapes(myShape, TopAbs_COMPOUND);
295     if (nb > 0)
296       i++;
297   }
298   while (i <= myShape.ShapeType()) {
299     GroupPoints->ComboBox1->removeItem(0);
300     i++;
301   }
302
303   if (myShape.ShapeType() == TopAbs_COMPOUND) {
304     if (myWithShape == false) {
305       GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
306       myWithShape = true;
307     }
308   }
309   else {
310     if (myWithShape == true) {
311       GroupPoints->ComboBox1->removeItem(GroupPoints->ComboBox1->count() - 1);
312       myWithShape = false;
313     }
314   }
315
316   int count1 = GroupPoints->ComboBox1->count();
317   if (myWithShape)
318     count1 = count1 - 1;
319
320   if (SelectedShapeType > myShape.ShapeType()) {
321     if (SelectedShapeType == 8) {
322       if (myShape.ShapeType() != TopAbs_COMPOUND) {
323         GroupPoints->ComboBox1->setCurrentIndex(0);
324         ComboTextChanged();
325       }
326     }
327     else
328       GroupPoints->ComboBox1->setCurrentIndex(count1 - count + SelectedShapeType);
329   }
330   else {
331     GroupPoints->ComboBox1->setCurrentIndex(0);
332     ComboTextChanged();
333   }
334
335   updateButtonState();
336 }
337
338 //=================================================================================
339 // function : SetEditCurrentArgument()
340 // purpose  :
341 //=================================================================================
342 void EntityGUI_SubShapeDlg::SetEditCurrentArgument()
343 {
344   GroupPoints->LineEdit1->setFocus();
345   myEditCurrentArgument = GroupPoints->LineEdit1;
346
347   GroupPoints->CheckButton1->setChecked(false);
348   SubShapeToggled();
349   SelectionIntoArgument();
350 }
351
352 //=================================================================================
353 // function : LineEditReturnPressed()
354 // purpose  :
355 //=================================================================================
356 void EntityGUI_SubShapeDlg::LineEditReturnPressed()
357 {
358   QLineEdit* send = (QLineEdit*)sender();
359   if (send == GroupPoints->LineEdit1)
360     SetEditCurrentArgument();
361   else
362     return;
363
364   GEOMBase_Skeleton::LineEditReturnPressed();
365 }
366
367 //=================================================================================
368 // function : ResetStateOfDialog()
369 // purpose  : Completely reset the state of method including local context
370 //=================================================================================
371 void EntityGUI_SubShapeDlg::ResetStateOfDialog()
372 {
373   myObject = GEOM::GEOM_Object::_nil();
374   myShape.Nullify();
375   myEditCurrentArgument->setText("");
376
377   int SelectedShapeType = GroupPoints->ComboBox1->currentIndex();
378   int count = GroupPoints->ComboBox1->count();
379   if (myWithShape)
380     count = count - 1;
381
382   /* type for sub shape selection */
383   GroupPoints->ComboBox1->clear();
384   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compound");
385   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Compsolid");
386   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Solid");
387   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shell");
388   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Face");
389   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Wire");
390   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Edge");
391   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Vertex");
392   GroupPoints->ComboBox1->insertItem(GroupPoints->ComboBox1->count(), "Shape");
393
394   myWithShape = true;
395
396   GroupPoints->ComboBox1->setCurrentIndex(8 - count + SelectedShapeType);
397   ComboTextChanged();
398
399   updateButtonState();
400 }
401
402 //=================================================================================
403 // function : SubShapeToggled()
404 // purpose  : Allow user selection of all or only selected sub shapes
405 //          : Called when 'CheckButton1' state change
406 //=================================================================================
407 void EntityGUI_SubShapeDlg::SubShapeToggled()
408 {
409   activateSelection();
410 }
411
412 //=================================================================================
413 // function : ComboTextChanged()
414 // purpose  :
415 //=================================================================================
416 void EntityGUI_SubShapeDlg::ComboTextChanged()
417 {
418   /* Select sub shapes mode not checked */
419   updateButtonState();
420   SubShapeToggled();
421 }
422
423 //=================================================================================
424 // function : NumberOfSubShapes()
425 // purpose  :
426 //=================================================================================
427 unsigned int EntityGUI_SubShapeDlg::NumberOfSubShapes(const TopoDS_Shape& S,
428                                                        const int shapeType) const
429 {
430   if (S.IsNull())
431     return 0;
432
433   unsigned int index = 0;
434   TopTools_MapOfShape M;
435
436   if (S.ShapeType() == TopAbs_COMPOUND &&
437        (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
438          TopAbs_ShapeEnum(shapeType) == TopAbs_COMPSOLID ||
439          TopAbs_ShapeEnum(shapeType) == TopAbs_COMPOUND)) {
440     TopoDS_Iterator It(S, Standard_True, Standard_True);
441     for (; It.More(); It.Next()) {
442       if (M.Add(It.Value())) {
443         if (TopAbs_ShapeEnum(shapeType) == TopAbs_SHAPE ||
444              TopAbs_ShapeEnum(shapeType) == It.Value().ShapeType()) {
445           index++;
446         }
447       }
448     }
449   }
450   else {
451     TopExp_Explorer Exp (S, TopAbs_ShapeEnum(shapeType));
452     for (; Exp.More(); Exp.Next()) {
453       if (M.Add(Exp.Current())) {
454         index++;
455       }
456     }
457   }
458
459   M.Clear();
460   return index;
461 }
462
463 //=================================================================================
464 // function : updateButtonState
465 // purpose  :
466 //=================================================================================
467 void EntityGUI_SubShapeDlg::updateButtonState()
468 {
469   if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() != OCCViewer_Viewer::Type() ||
470        myObject->_is_nil() || shapeType() == TopAbs_SHAPE || shapeType() == TopAbs_COMPOUND) {
471     GroupPoints->CheckButton1->setChecked(false);
472     GroupPoints->CheckButton1->setEnabled(false);
473   }
474   else
475     GroupPoints->CheckButton1->setEnabled(true);
476 }
477
478 //=================================================================================
479 // function : isAllSubShapes
480 // purpose  :
481 //=================================================================================
482 bool EntityGUI_SubShapeDlg::isAllSubShapes() const
483 {
484   return !GroupPoints->CheckButton1->isChecked() || !GroupPoints->CheckButton1->isEnabled();
485 }
486
487 //=================================================================================
488 // function : shapeType
489 // purpose  :
490 //=================================================================================
491 int EntityGUI_SubShapeDlg::shapeType() const
492 {
493   int type = GroupPoints->ComboBox1->currentIndex();
494
495   if (myObject->_is_nil())
496     return type;
497
498   // Solving PAL5590
499   type += myShape.ShapeType() + 1;
500   if (myShape.ShapeType() == TopAbs_COMPOUND &&
501        NumberOfSubShapes(myShape, TopAbs_COMPOUND) > 0) {
502     type--;
503   }
504
505   return type;
506 }
507
508 //=================================================================================
509 // function : showOnlySelected
510 // purpose  :
511 //=================================================================================
512 void EntityGUI_SubShapeDlg::showOnlySelected()
513 {
514   if (CORBA::is_nil(myObject) || isAllSubShapes())
515     return;
516
517   QPushButton* send = (QPushButton*)sender();
518   if (send == GroupPoints->PushButton4) {
519     activateSelection();
520     return;
521   }
522
523   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
524   SALOME_ListIO aSelList;
525   aSelMgr->selectedObjects(aSelList);
526
527   GEOM_Displayer* aDisplayer = getDisplayer();
528
529   if (send == GroupPoints->PushButton3) {
530     aDisplayer->Erase(aSelList, false, true);
531   }
532   else {
533     aDisplayer->EraseAll();
534     aDisplayer->Display(aSelList, true);
535   }
536 }
537
538 //=================================================================================
539 // function : getSelectedSubshapes
540 // purpose  :
541 //=================================================================================
542 int EntityGUI_SubShapeDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
543 {
544   theMapIndex.Clear();
545
546   SalomeApp_Application* app = myGeomGUI->getApp();
547   if (!app || myObject->_is_nil())
548     return 0;
549
550   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
551   SALOME_ListIO aSelList;
552   aSelMgr->selectedObjects(aSelList);
553
554   // try to find out and process the global selection
555   // (of not published objects and of published sub-shapes)
556   {
557     SALOME_ListIteratorOfListIO anIter (aSelList);
558     for (int i = 0; anIter.More(); anIter.Next(), i++)
559     {
560       Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
561       QString anEntry = anIObj->getEntry();
562       QString str = "_";
563       int index = anEntry.lastIndexOf(str);
564       if (index > 0) // selection among special preview
565       {
566         anEntry.remove(0, index+1);
567         int anIndex = anEntry.toInt();
568         if (anIndex)
569           theMapIndex.Add(anIndex);
570       }
571       else // selection among published shapes
572       {
573         SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
574         if (!appStudy) return 0;
575         _PTR(Study) aStudy = appStudy->studyDS();
576
577         _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
578         GEOM::GEOM_Object_var aGeomObj =
579           GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
580         TopoDS_Shape aShape;
581         if (GEOMBase::GetShape(aGeomObj, aShape)) {
582           if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == (TopAbs_ShapeEnum)shapeType()) {
583             TopTools_IndexedMapOfShape aMainMap;
584             TopExp::MapShapes(myShape, aMainMap);
585
586             TopExp_Explorer anExp (aShape, (TopAbs_ShapeEnum)shapeType());
587             for (; anExp.More(); anExp.Next()) {
588               TopoDS_Shape aSubShape = anExp.Current();
589               int anIndex = aMainMap.FindIndex(aSubShape);
590               if (anIndex >= 0) {
591                 theMapIndex.Add(anIndex);
592               }
593             }
594           }
595         }
596       }
597     } // for aSelList
598   }
599
600   return theMapIndex.Extent();
601 }
602
603 //=================================================================================
604 // function : activateSelection
605 // purpose  : Activate selection in accordance with myEditCurrentArgument
606 //=================================================================================
607 void EntityGUI_SubShapeDlg::activateSelection()
608 {
609   erasePreview(false);
610
611   // local selection
612   if (!myObject->_is_nil() && !isAllSubShapes())
613   {
614     GEOM_Displayer* aDisplayer = getDisplayer();
615     int prevDisplayMode = aDisplayer->SetDisplayMode(0);
616
617     SUIT_ViewWindow* aViewWindow = 0;
618     SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
619     if (activeStudy)
620       aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
621     if (aViewWindow == 0) return;
622
623     SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
624     if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
625         aViewManager->getType() != SVTK_Viewer::Type())
626       return;
627
628     SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
629     SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
630     if (aView == 0) return;
631
632     //TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
633
634     TopTools_IndexedMapOfShape aSubShapesMap;
635     TopExp::MapShapes(myShape, aSubShapesMap);
636     CORBA::String_var aMainEntry = myObject->GetStudyEntry();
637     QString anEntryBase = aMainEntry.in();
638
639     TopExp_Explorer anExp (myShape, (TopAbs_ShapeEnum)shapeType());
640     for (; anExp.More(); anExp.Next())
641     {
642       TopoDS_Shape aSubShape = anExp.Current();
643       int index = aSubShapesMap.FindIndex(aSubShape);
644       QString anEntry = anEntryBase + QString("_%1").arg(index);
645
646       SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
647       if (aPrs) {
648         displayPreview(aPrs, true, false); // append, do not update
649       }
650     }
651     aDisplayer->UpdateViewer();
652     aDisplayer->SetDisplayMode(prevDisplayMode);
653   }
654
655   globalSelection(GEOM_ALLSHAPES);
656 }
657
658 //=================================================================================
659 // function : createOperation
660 // purpose  :
661 //=================================================================================
662 GEOM::GEOM_IOperations_ptr EntityGUI_SubShapeDlg::createOperation()
663 {
664   return getGeomEngine()->GetIShapesOperations(getStudyId());
665 }
666
667 //=================================================================================
668 // function : isValid
669 // purpose  :
670 //=================================================================================
671 bool EntityGUI_SubShapeDlg::isValid (QString& msg)
672 {
673   bool isOk = false;
674
675   if (myObject->_is_nil()) {
676     updateButtonState();
677     return isOk;
678   }
679
680   if (isAllSubShapes())
681     isOk = true;
682   else {
683     TColStd_IndexedMapOfInteger aMapIndex;
684     int nbSel = getSelectedSubshapes(aMapIndex);
685     isOk = nbSel > 0;
686
687     if (!isOk)
688       msg += tr("NO_SUBSHAPES_SELECTED");
689   }
690
691   return isOk;
692 }
693
694 //=================================================================================
695 // function : execute
696 // purpose  :
697 //=================================================================================
698 bool EntityGUI_SubShapeDlg::execute (ObjectList& objects)
699 {
700   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
701   GEOM::ListOfGO_var aList = anOper->ExtractSubShapes(myObject, shapeType(), true);
702
703   if (!aList->length())
704     return false;
705
706   // Throw away sub-shapes not selected by user if not in preview mode
707   // and manual selection is active
708   if (!isAllSubShapes()) {
709     TColStd_IndexedMapOfInteger aMapIndex;
710     int nbSel = getSelectedSubshapes(aMapIndex);
711
712     if (nbSel > 0) {
713       GEOM::GEOM_ILocalOperations_var aLocOp =
714         getGeomEngine()->GetILocalOperations(getStudyId());
715
716       for (int i = 0, n = aList->length(); i < n; i++)
717         if (aMapIndex.Contains(aLocOp->GetSubShapeIndex(myObject, aList[i])))
718           objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
719         else
720           aList[i]->UnRegister();
721     }
722   }
723   else
724     for (int i = 0, n = aList->length(); i < n; i++)
725       objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
726
727   return objects.size();
728 }
729
730 //================================================================
731 // Function : getFather
732 // Purpose  : Get father object for object to be added in study
733 //            (called with addInStudy method)
734 //================================================================
735 GEOM::GEOM_Object_ptr EntityGUI_SubShapeDlg::getFather(GEOM::GEOM_Object_ptr)
736 {
737   return myObject;
738 }
739
740 //================================================================
741 // Function : getNewObjectName
742 // Purpose  :
743 //================================================================
744 QString EntityGUI_SubShapeDlg::getNewObjectName() const
745 {
746   return QString::null;
747 }