]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
3540797e9868cc43171031a4410ef722b0bf6f3b
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "PartSet_Module.h"
4 #include "PartSet_WidgetSketchLabel.h"
5 #include "PartSet_Validators.h"
6 #include "PartSet_Tools.h"
7 #include "PartSet_WidgetPoint2d.h"
8 #include "PartSet_WidgetPoint2dDistance.h"
9 #include "PartSet_WidgetShapeSelector.h"
10 #include "PartSet_WidgetPoint2dAngle.h"
11 #include "PartSet_WidgetMultiSelector.h"
12 #include "PartSet_WidgetEditor.h"
13 #include "PartSet_WidgetFileSelector.h"
14 #include "PartSet_WidgetSketchCreator.h"
15 #include "PartSet_SketcherMgr.h"
16 #include "PartSet_MenuMgr.h"
17 #include "PartSet_CustomPrs.h"
18 #include "PartSet_IconFactory.h"
19
20 #include "PartSet_Filters.h"
21 #include "PartSet_FilterInfinite.h"
22
23 #include <PartSetPlugin_Remove.h>
24 #include <PartSetPlugin_Part.h>
25 #include <PartSetPlugin_Duplicate.h>
26
27 #include <ModuleBase_Operation.h>
28 #include <ModuleBase_OperationAction.h>
29 #include <ModuleBase_IViewer.h>
30 #include <ModuleBase_IViewWindow.h>
31 #include <ModuleBase_IPropertyPanel.h>
32 #include <ModuleBase_WidgetEditor.h>
33 #include <ModuleBase_WidgetValidated.h>
34 #include <ModuleBase_FilterFactory.h>
35 #include <ModuleBase_Tools.h>
36 #include <ModuleBase_OperationFeature.h>
37
38 #include <GeomValidators_ShapeType.h>
39 #include <GeomValidators_Finite.h>
40 #include <GeomValidators_Face.h>
41 #include <GeomValidators_ConstructionComposite.h>
42 #include <GeomValidators_ZeroOffset.h>
43 #include <GeomValidators_BooleanArguments.h>
44 #include <GeomValidators_Different.h>
45
46
47 #include <ModelAPI_Object.h>
48 #include <ModelAPI_Events.h>
49 #include <ModelAPI_Validator.h>
50 #include <ModelAPI_Data.h>
51 #include <ModelAPI_Session.h>
52 #include <ModelAPI_ShapeValidator.h>
53 #include <ModelAPI_ResultBody.h>
54
55 #include <GeomDataAPI_Point2D.h>
56 #include <GeomDataAPI_Point.h>
57 #include <GeomDataAPI_Dir.h>
58
59 #include <XGUI_Displayer.h>
60 #include <XGUI_Workshop.h>
61 #include <XGUI_OperationMgr.h>
62 #include <XGUI_PropertyPanel.h>
63 #include <XGUI_ModuleConnector.h>
64 #include <XGUI_ContextMenuMgr.h>
65 #include <XGUI_Tools.h>
66 #include <XGUI_ObjectsBrowser.h>
67 #include <XGUI_SelectionMgr.h>
68 #include <XGUI_DataModel.h>
69
70 #include <SketchPlugin_Feature.h>
71 #include <SketchPlugin_Sketch.h>
72 #include <SketchPlugin_Line.h>
73 #include <SketchPlugin_Arc.h>
74 #include <SketchPlugin_Circle.h>
75 #include <SketchPlugin_Point.h>
76 #include <SketchPlugin_ConstraintAngle.h>
77 #include <SketchPlugin_ConstraintLength.h>
78 #include <SketchPlugin_ConstraintDistance.h>
79 #include <SketchPlugin_ConstraintParallel.h>
80 #include <SketchPlugin_ConstraintPerpendicular.h>
81 #include <SketchPlugin_ConstraintRadius.h>
82
83 #include <SketcherPrs_SymbolPrs.h>
84 #include <SketcherPrs_Tools.h>
85
86 #include <Events_Loop.h>
87 #include <Config_PropManager.h>
88 #include <Config_Keywords.h>
89
90 #include <StdSelect_TypeOfFace.hxx>
91 #include <TopoDS_Vertex.hxx>
92 #include <TopoDS.hxx>
93 #include <TopoDS_Shape.hxx>
94 #include <BRep_Tool.hxx>
95 #include <AIS_Dimension.hxx>
96
97 #include <QObject>
98 #include <QMouseEvent>
99 #include <QString>
100 #include <QTimer>
101 #include <QApplication>
102 #include <QMessageBox>
103 #include <QMainWindow>
104 #include <QLineEdit>
105
106 #include <GeomAlgoAPI_FaceBuilder.h>
107 #include <GeomDataAPI_Dir.h>
108
109 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
110
111 #ifdef _DEBUG
112 #include <QDebug>
113 #endif
114
115 /*!Create and return new instance of XGUI_Module*/
116 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
117 {
118   return new PartSet_Module(theWshop);
119 }
120
121 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
122   : ModuleBase_IModule(theWshop),
123   myRestartingMode(RM_None), myVisualLayerId(0)
124 {
125   new PartSet_IconFactory();
126
127   mySketchMgr = new PartSet_SketcherMgr(this);
128   myDataModel = new PartSet_DocumentDataModel(this);
129
130   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
131   XGUI_Workshop* aWorkshop = aConnector->workshop();
132
133   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
134   connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
135   connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
136           this, SLOT(onOperationActivatedByPreselection()));
137
138   ModuleBase_IViewer* aViewer = theWshop->viewer();
139   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
140           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
141   connect(aViewer, SIGNAL(viewTransformed(int)),
142           SLOT(onViewTransformed(int)));
143   connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
144           SLOT(onViewCreated(ModuleBase_IViewWindow*)));
145
146   myMenuMgr = new PartSet_MenuMgr(this);
147   myCustomPrs = new PartSet_CustomPrs(theWshop);
148
149   Events_Loop* aLoop = Events_Loop::loop();
150   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
151
152   mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
153   mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
154 }
155
156 PartSet_Module::~PartSet_Module()
157 {
158   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
159   for (; aIt.More(); aIt.Next()) {
160     Handle(SelectMgr_Filter) aFilter = aIt.Value();
161     if (!aFilter.IsNull())
162       aFilter.Nullify();
163   }
164   delete myCustomPrs;
165 }
166
167 void PartSet_Module::activateSelectionFilters()
168 {
169   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
170   for (; aIt.More(); aIt.Next()) {
171     Handle(SelectMgr_Filter) aFilter = aIt.Value();
172     if (!aFilter.IsNull())
173       myWorkshop->viewer()->addSelectionFilter(aFilter);
174   }
175 }
176
177 void PartSet_Module::deactivateSelectionFilters()
178 {
179   SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
180   for (; aIt.More(); aIt.Next()) {
181     Handle(SelectMgr_Filter) aFilter = aIt.Value();
182     if (!aFilter.IsNull())
183       myWorkshop->viewer()->removeSelectionFilter(aFilter);
184   }
185 }
186
187 void PartSet_Module::registerValidators()
188 {
189   //Registering of validators
190   SessionPtr aMgr = ModelAPI_Session::get();
191   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
192   aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
193   aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
194   aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
195   aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
196   aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
197   aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
198   aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
199   aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
200   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
201   aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
202   aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
203
204   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
205   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
206
207   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
208
209   aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
210   aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
211
212   aFactory->registerValidator("GeomValidators_Finite", new GeomValidators_Finite);
213
214   aFactory->registerValidator("GeomValidators_ConstructionComposite",
215                               new GeomValidators_ConstructionComposite);
216
217   aFactory->registerValidator("GeomValidators_ZeroOffset",
218                               new GeomValidators_ZeroOffset);
219
220   aFactory->registerValidator("GeomValidators_BooleanArguments",
221                               new GeomValidators_BooleanArguments);
222
223   aFactory->registerValidator("PartSet_SketchEntityValidator",
224                               new PartSet_SketchEntityValidator);
225
226   aFactory->registerValidator("PartSet_SameTypeAttr",
227                               new PartSet_SameTypeAttrValidator);
228
229   aFactory->registerValidator("GeomValidators_Different",
230                               new GeomValidators_Different);
231 }
232
233 void PartSet_Module::registerFilters()
234 {
235   //Registering of selection filters
236   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
237   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
238 }
239
240 void PartSet_Module::registerProperties()
241 {
242   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
243                                    PLANE_SIZE);
244   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
245                                    Config_Prop::Integer, SKETCH_WIDTH);
246 }
247
248 void PartSet_Module::onOperationCommitted(ModuleBase_Operation* theOperation) 
249 {
250   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
251     mySketchMgr->commitNestedSketch(theOperation);
252   }
253
254   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
255   if (!aFOperation || aFOperation->isEditOperation())
256     return;
257   // the selection is cleared after commit the create operation
258   // in order to do not use the same selected objects in the restarted operation
259   // for common behaviour, the selection is cleared even if the operation is not restarted
260   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
261   XGUI_Workshop* aWorkshop = aConnector->workshop();
262   aWorkshop->selector()->clearSelection();
263
264   /// Restart sketcher operations automatically
265   FeaturePtr aFeature = aFOperation->feature();
266   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
267             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
268   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
269                      myRestartingMode == RM_EmptyFeatureUsed)) {
270     myLastOperationId = aFOperation->id();
271     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature() : FeaturePtr();
272     
273     launchOperation(myLastOperationId);
274   }
275   breakOperationSequence();
276 }
277
278 void PartSet_Module::breakOperationSequence()
279 {
280   myLastOperationId = "";
281   myLastFeature = FeaturePtr();
282   myRestartingMode = RM_None;
283 }
284
285 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
286 {
287   breakOperationSequence();
288 }
289
290 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
291 {
292   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
293     mySketchMgr->startSketch(theOperation);
294   }
295   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
296     mySketchMgr->startNestedSketch(theOperation);
297   }
298
299   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
300   if (aFOperation)
301     myCustomPrs->activate(aFOperation->feature(), true);
302 }
303
304 void PartSet_Module::onOperationResumed(ModuleBase_Operation* theOperation)
305 {
306   ModuleBase_IModule::onOperationResumed(theOperation);
307
308   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
309   if (aFOperation)
310     myCustomPrs->activate(aFOperation->feature(), true);
311 }
312
313 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
314 {
315   bool isModified = myCustomPrs->deactivate(false);
316
317   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
318     mySketchMgr->stopSketch(theOperation);
319   }
320   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
321     mySketchMgr->stopNestedSketch(theOperation);
322   }
323
324   if (isModified) {
325     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
326     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
327     aDisplayer->updateViewer();
328   }
329 }
330
331 ModuleBase_Operation* PartSet_Module::currentOperation() const
332 {
333   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
334   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
335   return anOpMgr->currentOperation();
336 }
337
338 bool PartSet_Module::canUndo() const
339 {
340   bool aCanUndo = false;
341   SessionPtr aMgr = ModelAPI_Session::get();
342   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
343     aCanUndo = !aMgr->isOperation();
344     if (!aCanUndo) // check the enable state additionally by sketch manager
345       aCanUndo = aMgr->canUndo();
346   }
347   return aCanUndo;
348 }
349
350 bool PartSet_Module::canRedo() const
351 {
352   bool aCanRedo = false;
353   SessionPtr aMgr = ModelAPI_Session::get();
354   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
355     aCanRedo = !aMgr->isOperation();
356     if (!aCanRedo) // check the enable state additionally by sketch manager
357       aCanRedo = aMgr->canRedo();
358   }
359   return aCanRedo;
360 }
361
362 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
363 {
364   bool aValid = true;
365   if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
366     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
367     if (aFeature) {
368       // part features are removed in the PartSet module only.
369       if (aFeature->getKind() == PartSetPlugin_Part::ID())
370         aValid = false;
371     }
372   }
373   return aValid;
374 }
375
376 bool PartSet_Module::canCommitOperation() const
377 {
378   return mySketchMgr->canCommitOperation();
379 }
380
381 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
382 {
383   // the sketch manager put the restriction to the objects erase
384   return mySketchMgr->canEraseObject(theObject);
385 }
386
387 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
388 {
389   // the sketch manager put the restriction to the objects display
390   return mySketchMgr->canDisplayObject(theObject);
391 }
392
393 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
394 {
395   bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
396
397   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
398   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
399        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
400   if (isSketchOp || isNestedOp) {
401     // in active sketch operation it is possible to activate operation object in selection
402     // in the edit operation, e.g. points of the line can be moved when the line is edited
403     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
404     aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
405   }
406   return aCanActivate;
407 }
408
409 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
410 {
411   return myMenuMgr->addViewerMenu(theMenu, theStdActions);
412 }
413
414 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
415 {
416   myMenuMgr->updateViewerMenu(theStdActions);
417 }
418
419
420 void PartSet_Module::activeSelectionModes(QIntList& theModes)
421 {
422   theModes.clear();
423   if (mySketchMgr->activeSketch().get())
424     PartSet_SketcherMgr::sketchSelectionModes(theModes);
425 }
426
427 bool PartSet_Module::isMouseOverWindow()
428 {
429   return mySketchMgr->isMouseOverWindow();
430 }
431
432 void PartSet_Module::closeDocument()
433 {
434   clearViewer();
435 }
436
437 void PartSet_Module::clearViewer()
438 {
439   myCustomPrs->clearPrs();
440 }
441
442 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
443 {
444   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
445   if (!aFOperation)
446     return;
447
448   ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
449   if (PartSet_SketcherMgr::isSketchOperation(aFOperation) &&  (aFOperation->isEditOperation())) {
450     // we have to manually activate the sketch label in edit mode
451       aPanel->activateWidget(aPanel->modelWidgets().first());
452       return;
453   }
454
455   // Restart last operation type 
456   if ((aFOperation->id() == myLastOperationId) && myLastFeature) {
457     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
458     if (aFOperation->id().toStdString() == SketchPlugin_Line::ID()) {
459       // Initialise new line with first point equal to end of previous
460       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
461       if (aPnt2dWgt) {
462         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
463         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
464           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
465         if (aPoint) {
466           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
467           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), aFOperation->feature(), 
468             aWgt->attributeID(), aPoint->x(), aPoint->y());
469           aPanel->activateNextWidget(aPnt2dWgt);
470         }
471       }
472     }
473   }
474 }
475
476
477 void PartSet_Module::onSelectionChanged()
478 {
479   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
480   if (!aOperation)
481     return;
482
483   bool isSketcherOp = false;
484   // An edit operation is enable only if the current opeation is the sketch operation
485   if (mySketchMgr->activeSketch()) {
486     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
487       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
488   }
489   if (isSketcherOp) {
490     // Editing of constraints can be done on selection
491     ModuleBase_ISelection* aSelect = myWorkshop->selection();
492     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
493     if (aSelected.size() == 1) {
494       ModuleBase_ViewerPrs aPrs = aSelected.first();
495       ObjectPtr aObject = aPrs.object();
496       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
497       if (aFeature) {
498         std::string aId = aFeature->getKind();
499         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
500             (aId == SketchPlugin_ConstraintLength::ID()) || 
501             (aId == SketchPlugin_ConstraintDistance::ID()) ||
502             (aId == SketchPlugin_ConstraintAngle::ID())) {
503           editFeature(aFeature);
504         }
505       }
506     }
507   } 
508 }
509
510 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
511 {
512   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
513   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
514   anOpMgr->onKeyReleased(theEvent);
515 }
516
517 void PartSet_Module::onEnterReleased()
518 {
519   myRestartingMode = RM_EmptyFeatureUsed;
520 }
521
522 void PartSet_Module::onOperationActivatedByPreselection()
523 {
524   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
525   if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
526     // Set final definitions if they are necessary
527     //propertyPanelDefined(aOperation);
528
529     /// Commit sketcher operations automatically
530     anOperation->commit();
531   }
532 }
533
534 void PartSet_Module::onNoMoreWidgets()
535 {
536   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
537   if (anOperation) {
538     if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
539       if (myRestartingMode != RM_Forbided)
540         myRestartingMode = RM_LastFeatureUsed;
541       XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
542       XGUI_Workshop* aWorkshop = aConnector->workshop();
543       XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
544       // do nothing if the feature can not be applyed
545       if (anOpMgr->isApplyEnabled())
546         anOperation->commit();
547     }
548   }
549 }
550
551 void PartSet_Module::onVertexSelected()
552 {
553   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
554   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
555     /// If last line finished on vertex the lines creation sequence has to be break
556     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
557     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
558     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
559     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
560     bool aFoundWidget = false;
561     bool aFoundObligatory = false;
562     for (; anIt != aLast && !aFoundObligatory; anIt++) {
563       if (!aFoundWidget)
564         aFoundWidget = *anIt == anActiveWidget;
565       else
566         aFoundObligatory = (*anIt)->isObligatory();
567     }
568     if (!aFoundObligatory)
569       myRestartingMode = RM_Forbided;
570   }
571 }
572
573 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
574                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
575 {
576   ModuleBase_IWorkshop* aWorkshop = workshop();
577   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
578   XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
579   ModuleBase_ModelWidget* aWgt = NULL;
580   if (theType == "sketch-start-label") {
581     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
582       theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
583     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
584       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
585     connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
586       mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
587     aWgt = aLabelWgt;
588   } else if (theType == "sketch-2dpoint_selector") {
589     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
590                                                                  theWidgetApi, theParentId);
591     aPointWgt->setSketch(mySketchMgr->activeSketch());
592     connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
593     aWgt = aPointWgt;
594   } else if (theType == "point2ddistance") {
595     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
596                                                         aWorkshop, theWidgetApi, theParentId);
597     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
598     aWgt = aDistanceWgt;
599   } else if(theType == "point2dangle") {
600     PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
601                                                            aWorkshop, theWidgetApi, theParentId);
602     anAngleWgt->setSketch(mySketchMgr->activeSketch());
603     aWgt = anAngleWgt;
604   } else if (theType == "sketch_shape_selector") {
605     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
606       new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
607     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
608     aWgt = aShapeSelectorWgt;
609   } else if (theType == "sketch_multi_selector") {
610     PartSet_WidgetMultiSelector* aShapeSelectorWgt =
611       new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
612     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
613     aWgt = aShapeSelectorWgt;
614   } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
615     aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
616   } else if (theType == "export_file_selector") {
617     aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
618   } else if (theType == "sketch_launcher") {
619     aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
620   }
621   return aWgt;
622 }
623
624
625 bool PartSet_Module::deleteObjects()
626 {
627   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
628   XGUI_Workshop* aWorkshop = aConnector->workshop();
629   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
630
631   //SessionPtr aMgr = ModelAPI_Session::get();
632   // 1. check whether the delete should be processed in the module
633   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
634   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
635        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
636   if (isSketchOp || isNestedOp) {
637     // 2. find selected presentations
638     // selected objects should be collected before the current operation abort because
639     // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
640     ModuleBase_ISelection* aSel = workshop()->selection();
641     QObjectPtrList aSelectedObj = aSel->selectedPresentations();
642     // if there are no selected objects in the viewer, that means that the selection in another
643     // place cased this method. It is necessary to return the false value to understande in above
644     // method that delete is not processed
645     if (aSelectedObj.count() == 0)
646       return false;
647
648     // avoid delete of the objects, which are not belong to the current sketch
649     // in order to do not delete results of other sketches
650     QObjectPtrList aSketchObjects;
651     QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
652     for ( ; anIt != aLast; anIt++) {
653       ObjectPtr anObject = *anIt;
654       if (mySketchMgr->isObjectOfSketch(anObject)) {
655         // sketch feature should be used in this list because workshop deletes features only
656         // results are skipped
657         FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
658         aSketchObjects.append(aSketchFeature);
659       }
660     }
661     // if the selection contains only local selected presentations from other sketches,
662     // the Delete operation should not be done at all
663     if (aSketchObjects.size() == 0)
664       return true;
665
666     // 3. start operation
667     QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
668     ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
669
670     // the active nested sketch operation should be aborted unconditionally
671     // the Delete action should be additionally granted for the Sketch operation
672     // in order to do not abort/commit it
673     if (!anOpMgr->canStartOperation(anOpAction->id(), isSketchOp/*granted*/))
674       return true; // the objects are processed but can not be deleted
675
676     anOpMgr->startOperation(anOpAction);
677
678     // 4. delete features
679     // sketch feature should be skipped, only sub-features can be removed
680     // when sketch operation is active
681     aWorkshop->deleteFeatures(aSketchObjects);
682     // 5. stop operation
683     anOpMgr->commitOperation();
684   }
685   else {
686     bool isPartRemoved = false;
687     // Delete part with help of PartSet plugin
688     // TODO: the deleted objects has to be processed by multiselection
689     QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
690     if (aObjects.size() == 1) {
691       ObjectPtr aObj = aObjects.first();
692       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
693       if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
694         // Remove feature should be created in the document of the part results
695         ResultPtr aPartResult = aFeature->firstResult();
696         if (aPartResult.get()) {
697           std::shared_ptr<ModelAPI_ResultPart> aPart =
698                        std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
699           DocumentPtr aPartDoc = aPart->partDoc();
700           if (aPartDoc.get()) {
701             ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
702                                               (PartSetPlugin_Remove::ID().c_str(), this);
703             if (!anOpMgr->canStartOperation(anOpAction->id()))
704               return true; // the objects are processed but can not be deleted
705
706             anOpMgr->startOperation(anOpAction);
707
708             FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
709             aFeature->execute();
710
711             anOpMgr->commitOperation();
712             isPartRemoved = true;
713           }
714         }
715       }
716     }
717     return isPartRemoved;
718   }
719   return true;
720 }
721
722 void PartSet_Module::onFeatureTriggered()
723 {
724   QAction* aCmd = dynamic_cast<QAction*>(sender());
725   if (aCmd->isCheckable() && aCmd->isChecked()) {
726     // 1. check whether the delete should be processed in the module
727     ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
728     bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
729     if (isNestedOp) {
730       // in case if in the viewer nothing is displayed, the create operation should not be
731       // comitted even if all values of the feature are initialized
732       if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
733         // the action information should be saved before the operation is aborted
734         // because this abort leads to update command status, which unchecks this action
735         anOperation->abort();
736         launchOperation(aCmd->data().toString());
737       }
738     }
739   }
740   ModuleBase_IModule::onFeatureTriggered();
741 }
742
743 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) 
744 {
745   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
746   if (!anAIS.IsNull()) {
747     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
748     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
749     if (!aDim.IsNull()) {
750       aCtx->SetZLayer(aDim, myVisualLayerId);
751     } else {
752       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
753       if (!aCons.IsNull())
754         aCtx->SetZLayer(aCons, myVisualLayerId);
755     }
756   }
757 }
758
759 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
760 {
761   // this is obsolete
762   // it should be recomputed in order to disappear in the viewer if the corresponded object
763   // is erased
764   //if (myCustomPrs->isActive())
765   //  myCustomPrs->redisplay(theObject, false);
766 }
767
768 void PartSet_Module::onViewTransformed(int theTrsfType)
769 {
770   // Set length of arrows constant in pixel size
771   // if the operation is panning or rotate or panglobal then do nothing
772   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
773     return;
774
775   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
776   //Handle(V3d_View) aView = aViewer->activeView();
777
778   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
779   XGUI_Workshop* aWorkshop = aConnector->workshop();
780   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
781   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
782
783   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
784   Handle(V3d_View) aView;
785   double aScale = 0;
786   for (aV3dViewer->InitDefinedViews(); 
787        aV3dViewer->MoreDefinedViews(); 
788        aV3dViewer->NextDefinedViews()) {
789     Handle(V3d_View) aV = aV3dViewer->DefinedView();
790     double aS = aV->Scale();
791     if (aS > aScale) {
792       aScale = aS;
793       aView = aV;
794     }
795   }
796   if (aView.IsNull())
797     return;
798   double aLen = aView->Convert(20);
799
800   double aPrevLen = SketcherPrs_Tools::getArrowSize();
801   SketcherPrs_Tools::setArrowSize(aLen);
802   const double aPrevScale = aViewer->Scale(aViewer->activeView());
803   const double aCurScale = aViewer->activeView()->Camera()->Scale();
804   aViewer->SetScale(aViewer->activeView(), aCurScale);
805   SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
806   bool isModified = false;
807   QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
808   foreach (AISObjectPtr aAIS, aPrsList) {
809     Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
810
811     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
812     if (!aDim.IsNull()) {
813       aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
814       aContext->Redisplay(aDim, false);
815       isModified = true;
816     }
817   }
818   if (isModified)
819     aDisplayer->updateViewer();
820 }
821
822 bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
823 {
824   bool isRedisplayed = false;
825   if (myCustomPrs->isActive())
826     isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
827
828   return isRedisplayed;
829 }
830
831 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
832 {
833   XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
834   if (aOB) {
835     QLineEdit* aLabel = aOB->activeDocLabel();
836     QPalette aPalet = aLabel->palette();
837     aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
838     aLabel->setPalette(aPalet);
839     aOB->treeView()->setExpandsOnDoubleClick(false);
840 #ifdef ModuleDataModel
841     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), 
842       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
843     connect(aOB, SIGNAL(headerMouseDblClicked(const QModelIndex&)), 
844       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
845     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), 
846       myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
847 #endif
848   }
849 }
850
851 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
852 {
853   ObjectPtr anObject;
854   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
855   if (aOperation) {
856     /// If last line finished on vertex the lines creation sequence has to be break
857     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
858     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
859     // if there is an active widget, find the presented object in it
860     if (!anActiveWidget)
861       anActiveWidget = aPanel->preselectionWidget();
862     
863     ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
864                                                                            (anActiveWidget);
865     if (aWidgetValidated)
866       anObject = aWidgetValidated->findPresentedObject(theAIS);
867   }
868   return anObject;
869 }
870
871 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
872 {
873   QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
874   int aSelected = aObjects.size();
875   SessionPtr aMgr = ModelAPI_Session::get();
876   if (aSelected == 1) {
877     bool hasResult = false;
878     bool hasFeature = false;
879     bool hasParameter = false;
880     bool hasSubFeature = false;
881     ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
882
883     ObjectPtr aObject = aObjects.first();
884     if (aObject) {
885       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
886       FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
887       bool isPart = aPart.get() || 
888         (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
889       if (isPart) {
890         DocumentPtr aPartDoc;
891         if (!aPart.get()) {
892           aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
893         }
894         if (aPart.get()) // this may be null is Part feature is disabled
895           aPartDoc = aPart->partDoc();
896         if (aMgr->activeDocument() == aPartDoc)
897           theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
898         else
899           theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
900       } else if (aObject->document() == aMgr->activeDocument()) {
901         if (hasParameter || hasFeature)
902           theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
903       }
904
905       ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
906       if( aResult.get() )
907       {
908         theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
909       }
910     } else {  // If feature is 0 the it means that selected root object (document)
911       if (aMgr->activeDocument() != aMgr->moduleDocument())
912         theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
913     }
914   } else if (aSelected == 0) {
915     // if there is no selection then it means that upper label is selected
916     QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
917     if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
918       if (aMgr->activeDocument() != aMgr->moduleDocument())
919         theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
920   }
921   bool aCanDeactivate = (myWorkshop->currentOperation() == 0);
922   myMenuMgr->action("ACTIVATE_PARTSET_CMD")->setEnabled(aCanDeactivate);
923   myMenuMgr->action("DEACTIVATE_PART_CMD")->setEnabled(aCanDeactivate);
924   myMenuMgr->action("ACTIVATE_PART_CMD")->setEnabled(aCanDeactivate);
925 }
926
927 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
928 {
929   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
930     // Do not change activation of parts if an operation active
931     static QStringList aAllowActivationList;
932     if (aAllowActivationList.isEmpty())
933       aAllowActivationList << 
934       QString(PartSetPlugin_Part::ID().c_str()) << 
935       QString(PartSetPlugin_Duplicate::ID().c_str()) <<
936       QString(PartSetPlugin_Remove::ID().c_str());
937     if (myWorkshop->currentOperation() && 
938       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
939       return;
940     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
941     XGUI_Workshop* aWorkshop = aConnector->workshop();
942     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
943     QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
944     QPalette aPalet = aLabel->palette();
945
946     SessionPtr aMgr = ModelAPI_Session::get();
947     DocumentPtr aActiveDoc = aMgr->activeDocument();
948 #ifdef ModuleDataModel
949     QModelIndex aOldIndex = myDataModel->activePartTree();
950     DocumentPtr aDoc = aMgr->moduleDocument();
951     if (aActiveDoc == aDoc) {
952       if (aOldIndex.isValid())
953         aTreeView->setExpanded(aOldIndex, false);
954       myDataModel->deactivatePart();
955       aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
956     } else {
957       std::string aGrpName = ModelAPI_ResultPart::group();
958       for (int i = 0; i < aDoc->size(aGrpName); i++) {
959         ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
960         if (aPart->partDoc() == aActiveDoc) {
961           QModelIndex aIndex = myDataModel->partIndex(aPart);
962           if (myDataModel->activatePart(aIndex)) {
963             if (aOldIndex.isValid())
964               aTreeView->setExpanded(aOldIndex, false);
965             aTreeView->setExpanded(myDataModel->activePartTree(), true);
966             aPalet.setColor(QPalette::Text, Qt::black);
967           }
968           break;
969         }
970       }
971     }
972 #else
973     // Problem with MPV: At first time on creation it doesn't work because Part feature
974     // creation event will be sent after
975     if (aActivePartIndex.isValid())
976       aTreeView->setExpanded(aActivePartIndex, false);
977     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
978     aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
979     if (aActivePartIndex.isValid())
980       aTreeView->setExpanded(aActivePartIndex, true);
981 #endif
982     aLabel->setPalette(aPalet);
983     aWorkshop->updateCommandStatus();
984
985     // Update displayed objects in order to update active color
986     XGUI_Displayer* aDisplayer = aWorkshop->displayer();
987     QObjectPtrList aObjects = aDisplayer->displayedObjects();
988     foreach(ObjectPtr aObj, aObjects)
989       aDisplayer->redisplay(aObj, false);
990     aDisplayer->updateViewer();
991   }
992 }
993
994 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
995 {
996   if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
997     return;
998   SessionPtr aMgr = ModelAPI_Session::get();
999   if (!theIndex.isValid()) {
1000     aMgr->setActiveDocument(aMgr->moduleDocument());
1001     return;
1002   }
1003   if (theIndex.column() != 0) // Use only first column
1004     return;
1005   ObjectPtr aObj = myDataModel->object(theIndex);
1006   ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1007   if (!aPart.get()) { // Probably this is Feature
1008     FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1009     if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1010       aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1011     }
1012   }
1013   if (aPart.get()) { // if this is a part
1014     if (aPart->partDoc() == aMgr->activeDocument()) {
1015       aMgr->setActiveDocument(aMgr->moduleDocument());
1016     } else {
1017       aPart->activate();
1018     }
1019   }
1020 }
1021
1022
1023 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1024 {
1025   // z layer is created for all started operations in order to visualize operation AIS presentation
1026   // over the object
1027   Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
1028   if (myVisualLayerId == 0) {
1029     if (myVisualLayerId == 0)
1030       aViewer->AddZLayer(myVisualLayerId);
1031   } else {
1032     TColStd_SequenceOfInteger aZList;
1033     aViewer->GetAllZLayers(aZList);
1034     bool aFound = false;
1035     for (int i = 1; i <= aZList.Length(); i++) {
1036       if (aZList(i) == myVisualLayerId) {
1037         aFound = true;
1038         break;
1039       }
1040     }
1041     if (!aFound)
1042       aViewer->AddZLayer(myVisualLayerId);
1043   }
1044 }