Salome HOME
8af09b3fab92f07e1a87d68dd96f8ba3cc7f26e3
[modules/shaper.git] / src / PartSet / PartSet_SketcherReentrantMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "PartSet_SketcherReentrantMgr.h"
4 #include "PartSet_Module.h"
5 #include "PartSet_SketcherMgr.h"
6 #include "PartSet_WidgetPoint2d.h"
7
8 #include "ModelAPI_Session.h"
9 #include "ModelAPI_AttributeString.h"
10 #include "ModelAPI_AttributeRefAttr.h"
11 #include "ModelAPI_EventReentrantMessage.h"
12
13 #include "GeomDataAPI_Point2D.h"
14
15 #include <ModuleBase_IPropertyPanel.h>
16 #include <ModuleBase_OperationFeature.h>
17 #include <ModuleBase_ModelWidget.h>
18 #include <ModuleBase_ViewerPrs.h>
19 #include <ModuleBase_WidgetSelector.h>
20 #include <ModuleBase_PageWidget.h>
21 #include <ModuleBase_PageBase.h>
22 #include <ModuleBase_WidgetFactory.h>
23 #include <ModuleBase_OperationDescription.h>
24 #include "ModuleBase_ToolBox.h"
25 #include "ModuleBase_ISelection.h"
26
27 #include <SketchPlugin_Feature.h>
28 #include <SketchPlugin_Line.h>
29 #include <SketchPlugin_MacroArc.h>
30 #include <SketchPlugin_MacroCircle.h>
31 #include <SketchPlugin_Point.h>
32 #include <SketchPlugin_Trim.h>
33
34 #include <XGUI_Workshop.h>
35 #include <XGUI_ModuleConnector.h>
36 #include <XGUI_OperationMgr.h>
37 #include <XGUI_PropertyPanel.h>
38 #include <XGUI_ErrorMgr.h>
39 #include <XGUI_SelectionMgr.h>
40
41 #include <QToolButton>
42
43 //#define DEBUG_RESTART
44
45 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
46 : QObject(theWorkshop),
47   myWorkshop(theWorkshop),
48   myRestartingMode(RM_None),
49   myIsFlagsBlocked(false),
50   myIsInternalEditOperation(false),
51   myInternalActiveWidget(0),
52   myNoMoreWidgetsAttribute("")
53 {
54 }
55
56 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
57 {
58 }
59
60 ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
61 {
62   ModuleBase_ModelWidget* aWidget = 0;
63   if (!isActiveMgr())
64     return aWidget;
65
66   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
67   if (anOperation) {
68     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
69     if (aPanel) { // check for case when the operation is started but property panel is not filled
70       ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
71       if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
72         aWidget = myInternalActiveWidget;
73     }
74   }
75   return aWidget;
76 }
77
78 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
79 {
80   return myIsInternalEditOperation;
81 }
82
83 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
84 {
85   if  (myIsInternalEditOperation) {
86     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
87                                                          (myWorkshop->currentOperation());
88     if (aFOperation) {
89       FeaturePtr aFeature = aFOperation->feature();
90       QString anError = myWorkshop->module()->getFeatureError(aFeature);
91       // stop started internal edit operation as soon as the operation becomes invalid
92       // it is especially important for the sketch tangent arc feature
93       if (!anError.isEmpty()) {
94         aFOperation->setEditOperation(false);
95         //workshop()->operationMgr()->updateApplyOfOperations();
96         myIsInternalEditOperation = false;
97         updateAcceptAllAction();
98       }
99     }
100   }
101 }
102
103 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
104 {
105   bool aProcessed = false;
106   if (!isActiveMgr())
107     return aProcessed;
108
109   aProcessed = myIsInternalEditOperation;
110   resetFlags();
111
112   return aProcessed;
113 }
114
115 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
116 {
117   if (!isActiveMgr())
118     return;
119
120   if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
121     ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
122                                                                 myWorkshop->currentOperation());
123     CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
124     if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
125       copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
126   }
127   resetFlags();
128 }
129
130 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
131 {
132   if (!isActiveMgr())
133     return;
134
135   resetFlags();
136 }
137
138 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
139                                                       QMouseEvent* theEvent)
140 {
141   bool aProcessed = false;
142   if (!isActiveMgr())
143     return aProcessed;
144
145   if  (myIsInternalEditOperation) {
146     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
147                                                          (myWorkshop->currentOperation());
148     FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
149                                                                      : FeaturePtr();
150     if (aLastFeature) {
151       ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
152       ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
153
154       FeaturePtr aCurrentFeature = aFOperation->feature();
155       bool isLineFeature = false, isArcFeature = false;
156       std::string anAttributeOnStart;
157       if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
158         anAttributeOnStart = SketchPlugin_Line::START_ID();
159         isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
160       }
161       else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
162         anAttributeOnStart = SketchPlugin_MacroArc::TANGENT_POINT_ID();
163         isArcFeature = anActiveWidget->attributeID() == anAttributeOnStart;
164       }
165       bool aCanBeActivatedByMove = isLineFeature || isArcFeature;
166       if (aCanBeActivatedByMove) {
167         /// before restarting of operation we need to clear selection, as it may take part in
168         /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
169         /// by mouse release when the operation was restarted.
170         workshop()->selector()->clearSelection();
171
172         myPreviousFeature = aFOperation->feature();
173         restartOperation();
174         myPreviousFeature = FeaturePtr();
175
176         anActiveWidget = module()->activeWidget();
177         aCurrentFeature = anActiveWidget->feature();
178         aProcessed = true;
179         if (anActiveWidget->attributeID() == anAttributeOnStart) {
180           // it was not deactivated by preselection processing
181           aPanel->activateNextWidget(anActiveWidget);
182         }
183       } else {
184         // processing mouse move in active widget of restarted operation
185         ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
186         PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
187         if (aProcessor)
188           aProcessor->mouseMoved(theWnd, theEvent);
189       }
190     }
191   }
192   return aProcessed;
193 }
194
195 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
196                                                         QMouseEvent* /* theEvent*/)
197 {
198   return isActiveMgr() && myIsInternalEditOperation;
199 }
200
201 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
202                                                         QMouseEvent* theEvent)
203 {
204   bool aProcessed = false;
205   if (!isActiveMgr())
206     return aProcessed;
207
208   if (myIsInternalEditOperation) {
209     ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
210     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
211
212     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
213     if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
214
215       // block of viewer update
216       // we need to block update content of the viewer because of Sketch Point feature
217       // in activate() the value of the point is initialized and it can be displayed
218       // but the default value is [0, 0]. So, we block update viewer contentent until
219       // onMouseRelease happens, which correct the point position
220       ModuleBase_Tools::blockUpdateViewer(true);
221
222       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
223                                                            (myWorkshop->currentOperation());
224       myPreviousFeature = aFOperation->feature();
225
226       /// selection should be obtained from workshop before ask if the operation can be started as
227       /// the canStartOperation method performs commit/abort of previous operation.
228       /// Sometimes commit/abort
229       /// may cause selection clear(Sketch operation) as a result
230       /// it will be lost and is not used for preselection.
231       ModuleBase_ISelection* aSelection = myWorkshop->selection();
232       QList<ModuleBase_ViewerPrsPtr> aPreSelected =
233         aSelection->getSelected(ModuleBase_ISelection::AllControls);
234
235       myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
236                                                      module()->sketchMgr()->activeSketch());
237       if (!aPreSelected.empty())
238         module()->getGeomSelection(aPreSelected.first(), mySelectedObject, mySelectedAttribute);
239
240       restartOperation();
241       myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
242       mySelectedObject = ObjectPtr();
243       mySelectedAttribute = AttributePtr();
244
245       myPreviousFeature = FeaturePtr();
246       aProcessed = true;
247
248       // fill the first widget by the mouse event point
249       // if the active widget is not the first, it means that the restarted operation is filled by
250       // the current preselection.
251       PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
252                                                                        module()->activeWidget());
253       //PartSet_WidgetPoint2D* aPoint2DWdg =
254       //  dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
255       PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
256                                                         aPanel->findFirstAcceptingValueWidget());
257       //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
258       if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
259         std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
260         if (!aPreSelected.empty())
261           aSelectedPrs = aPreSelected.front();
262         if (aSelectedPrs.get() && aSelectedPrs->object().get()
263             && !aSelectedPrs->object()->data()->isValid()) {
264           // the selected object was removed diring restart, e.g. presentable macro feature
265           // there are created objects to replace the object depending on created feature kind
266           aSelectedPrs = generatePreSelection();
267         }
268         aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
269         //aPoint2DWdg->mouseReleased(theWindow, theEvent);
270         //if (!aPreSelected.empty())
271         //  aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
272       }
273       // unblock viewer update
274       ModuleBase_Tools::blockUpdateViewer(false);
275     }
276   }
277   return aProcessed;
278 }
279
280 //******************************************************
281 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
282                                        const std::shared_ptr<Events_Message>& theMessage)
283 {
284   ReentrantMessagePtr aReentrantMessage =
285                       std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
286   if (!aReentrantMessage.get())
287     return;
288
289   aReentrantMessage->setSelectedObject(mySelectedObject);
290   aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
291   aReentrantMessage->setClickedPoint(myClickedSketchPoint);
292 }
293
294 void PartSet_SketcherReentrantMgr::onWidgetActivated()
295 {
296   if (!isActiveMgr())
297     return;
298   if (!myIsInternalEditOperation)
299     return;
300
301   PartSet_Module* aModule = module();
302   ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
303   ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
304   if (aFirstWidget != aPanel->activeWidget()) {
305     ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
306     if (aWSelector)
307       aWSelector->activateSelectionAndFilters(true);
308   }
309 }
310
311 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
312 {
313 #ifdef DEBUG_RESTART
314   std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
315 #endif
316
317   if (!isActiveMgr())
318     return;
319
320   // we should avoid processing of the signal about no more widgets attributes and
321   // do this after the restart operaion is finished if it was called
322   // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
323   // if it should be called after restart
324   if (myIsFlagsBlocked) {
325     myNoMoreWidgetsAttribute = thePreviousAttributeID;
326     return;
327   }
328
329   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
330                                                        (myWorkshop->currentOperation());
331   if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
332     return;
333
334   if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
335     bool isStarted = false;
336     if (!module()->sketchMgr()->sketchSolverError()) {
337       if (myRestartingMode != RM_Forbided) {
338         myRestartingMode = RM_LastFeatureUsed;
339         isStarted = startInternalEdit(thePreviousAttributeID);
340       }
341     }
342     if (!isStarted)
343       aFOperation->commit();
344   }
345 }
346
347 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
348 {
349   bool isDone = false;
350
351   if (!isActiveMgr())
352     return isDone;
353
354   // empty previous attribute means that the Apply/Ok button has focus and the enter
355   // should not lead to start edition mode of the previous operation
356   if (thePreviousAttributeID.empty())
357     return isDone;
358
359   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
360                                                        (myWorkshop->currentOperation());
361   if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
362     return isDone;
363
364   bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
365
366   if (!isSketchSolverError) {
367     myRestartingMode = RM_EmptyFeatureUsed;
368     isDone = startInternalEdit(thePreviousAttributeID);
369   }
370
371   return isDone;
372 }
373
374 void PartSet_SketcherReentrantMgr::onVertexSelected()
375 {
376   if (!isActiveMgr())
377     return;
378
379   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
380   std::string anOperationId = anOperation->id().toStdString();
381   if (anOperationId == SketchPlugin_Line::ID() ||
382       isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
383     /// If last line finished on vertex the lines creation sequence has to be break
384     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
385     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
386     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
387     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
388     bool aFoundWidget = false;
389     bool aFoundObligatory = false;
390     for (; anIt != aLast && !aFoundObligatory; anIt++) {
391       if (!aFoundWidget)
392         aFoundWidget = *anIt == anActiveWidget;
393       else
394         aFoundObligatory = (*anIt)->isObligatory();
395     }
396     if (!aFoundObligatory)
397       myRestartingMode = RM_Forbided;
398   }
399 }
400
401 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
402 {
403
404   if (isInternalEditActive()) {
405     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
406                                                        (myWorkshop->currentOperation());
407     ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
408     if (!aWidget->isModifiedInEdit().empty())
409       restartOperation();
410   }
411 }
412
413 void PartSet_SketcherReentrantMgr::onBeforeStopped()
414 {
415   if (!isActiveMgr() || !myIsInternalEditOperation)
416     return;
417
418   beforeStopInternalEdit();
419 }
420
421 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
422 {
423   return !isActiveMgr() || myRestartingMode == RM_None;
424 }
425
426 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
427 {
428   ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
429
430   bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
431   if (!anActive) {
432     anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
433     if (anActive) { // the manager is not active when the current operation is a usual Edit
434       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
435                                                        (myWorkshop->currentOperation());
436       if (aFOperation->isEditOperation())
437         anActive = myIsInternalEditOperation;
438     }
439   }
440   return anActive;
441 }
442
443 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
444 {
445 #ifdef DEBUG_RESTART
446   std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
447 #endif
448
449   bool isDone = false;
450   /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
451   /// event comes two times, so we should not start another internal edit operation
452   /// the Apply button becomes disabled becase the second additional internal feature is created
453   if (myIsInternalEditOperation)
454     return true;
455
456   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
457                                                      (myWorkshop->currentOperation());
458
459   if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
460     aFOperation->setEditOperation(true/*, false*/);
461     createInternalFeature();
462
463     myIsInternalEditOperation = true;
464     updateAcceptAllAction();
465
466     isDone = true;
467     connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
468     connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
469
470     // activate selection filters of the first widget in the viewer
471     onWidgetActivated();
472
473     // activate the last active widget in the Property Panel
474     if (!thePreviousAttributeID.empty()) {
475       ModuleBase_Operation* anEditOperation = module()->currentOperation();
476       if (anEditOperation) {
477         ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
478         ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
479         QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
480         for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
481           if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
482           /// workaround for the same attributes used in different stacked widgets(attribute types)
483           if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
484             continue;
485             aPreviousAttributeWidget = aWidgets[i];
486           }
487         }
488         // If the current widget is a selector, do nothing, it processes the mouse press
489         if (aPreviousAttributeWidget) {
490           if (!aPreviousAttributeWidget->isViewerSelector()) {
491             aPreviousAttributeWidget->focusTo();
492             aPreviousAttributeWidget->selectContent();
493           }
494           else {
495             // in case of shape multi selector, the widget does not lose focus by filling
496             // like it is in shape selector. So, if enter is pressed, the multi shape selector
497             // control should be deactivated. The focus is moved to Apply button and there
498             // should not be active control visualized in property panel
499             if (aPreviousAttributeWidget == aPanel->activeWidget()) {
500               aPanel->activateWidget(NULL, false);
501             }
502             // if there is no the next widget to be automatically activated,
503             // the Ok button in property
504             // panel should accept the focus(example is parallel constraint on sketch lines)
505             QToolButton* anOkBtn =
506               dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
507             if (anOkBtn)
508               anOkBtn->setFocus(Qt::TabFocusReason);
509           }
510         }
511       }
512     }
513   }
514   if (isDone)
515     module()->sketchMgr()->clearClickedFlags();
516
517   return isDone;
518 }
519
520 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
521 {
522   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
523                                                       (myWorkshop->currentOperation());
524   if (aFOperation) {
525     disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
526     disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
527   }
528
529   deleteInternalFeature();
530 }
531
532 void PartSet_SketcherReentrantMgr::restartOperation()
533 {
534 #ifdef DEBUG_RESTART
535   std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
536 #endif
537
538   if (myIsInternalEditOperation) {
539     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
540                                                                   myWorkshop->currentOperation());
541     if (aFOperation) {
542       ModuleBase_ISelection* aSelection = myWorkshop->selection();
543       QList<ModuleBase_ViewerPrsPtr> aPreSelected =
544         aSelection->getSelected(ModuleBase_ISelection::AllControls);
545
546
547
548       if (myInternalFeature.get())
549         copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
550                                   module()->sketchMgr()->activeSketch());
551
552       myNoMoreWidgetsAttribute = "";
553       myIsFlagsBlocked = true;
554       module()->launchOperation(aFOperation->id());
555       myIsFlagsBlocked = false;
556       resetFlags();
557
558       // we should avoid processing of the signal about no more widgets attributes and
559       // do this after the restart operaion is finished if it was called
560       // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
561       // if it should be called after restart
562       if (!myNoMoreWidgetsAttribute.empty()) {
563         onNoMoreWidgets(myNoMoreWidgetsAttribute);
564         myNoMoreWidgetsAttribute = "";
565       }
566     }
567   }
568 }
569
570 void PartSet_SketcherReentrantMgr::createInternalFeature()
571 {
572   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
573                                                      (myWorkshop->currentOperation());
574
575   if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
576     FeaturePtr anOperationFeature = aFOperation->feature();
577
578     CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
579     myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
580
581 #ifdef DEBUG_RESTART
582     std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
583               << myInternalFeature->data()->name() << std::endl;
584 #endif
585
586     bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
587                                                      aSketch, false);
588     XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
589                                                   (aFOperation->propertyPanel());
590
591     myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
592     myInternalWidget->setVisible(false);
593
594     ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
595
596     QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
597     ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
598
599     aFactory.createWidget(anInternalPage);
600     QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
601
602     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
603       bool isStoreValue = !aFOperation->isEditOperation() &&
604                           !aWidget->getDefaultValue().empty() &&
605                           !aWidget->isComputedDefault();
606       aWidget->setFeature(myInternalFeature, isStoreValue);
607       if (!isStoreValue && isFeatureChanged)
608         aWidget->restoreValue();
609     }
610
611     ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
612                                                                                         (aWidgets);
613     if (aFirstWidget)
614       myInternalActiveWidget = aFirstWidget;
615   }
616 }
617
618 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
619 {
620 #ifdef DEBUG_RESTART
621   std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
622             << myInternalFeature->data()->name() << std::endl;
623 #endif
624   if (myInternalActiveWidget) {
625     ModuleBase_WidgetSelector* aWSelector =
626       dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
627     if (aWSelector)
628       aWSelector->activateSelectionAndFilters(false);
629     myInternalActiveWidget = 0;
630   }
631   delete myInternalWidget;
632   myInternalWidget = 0;
633
634   QObjectPtrList anObjects;
635   anObjects.append(myInternalFeature);
636   workshop()->deleteFeatures(anObjects);
637   myInternalFeature = FeaturePtr();
638 }
639
640 void PartSet_SketcherReentrantMgr::resetFlags()
641 {
642   if (!myIsFlagsBlocked) {
643     myIsInternalEditOperation = false;
644     updateAcceptAllAction();
645     myRestartingMode = RM_None;
646     myReentrantMessage = std::shared_ptr<Events_Message>();
647   }
648 }
649
650 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
651                                                              const FeaturePtr& theNewFeature,
652                                                              const CompositeFeaturePtr& theSketch,
653                                                              const bool /*isTemporary*/)
654 {
655   bool aChanged = false;
656   if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
657       !theSourceFeature->data()->isValid())
658     return aChanged;
659
660 #ifdef DEBUG_RESTART
661   std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
662             << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
663             << "'" << std::endl;
664 #endif
665
666   std::string aFeatureKind = theSourceFeature->getKind();
667   /*if (aFeatureKind == SketchPlugin_Line::ID()) {
668     // Initialize new line with first point equal to end of previous
669     std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
670     std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
671                                                  aSFData->attribute(SketchPlugin_Line::END_ID()));
672     std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
673     std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
674                                                  aNFData->attribute(SketchPlugin_Line::START_ID()));
675     aNPoint->setValue(aSPoint->x(), aSPoint->y());
676     PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
677
678     aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
679                                                  aSFData->attribute(SketchPlugin_Line::END_ID()));
680     aNPoint->setValue(aSPoint->x(), aSPoint->y());
681   }
682   else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
683     // set circle type
684     /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
685     AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
686     AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
687     if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
688       aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
689     //ModuleBase_Tools::flushUpdated(theNewFeature);
690     aChanged = true;*/
691   }
692   else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
693     // set arc type
694     std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
695     AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
696     AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
697     if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
698       aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
699     //// if the arc is tangent, set coincidence to end point of the previous arc
700     //std::string anArcType = aSourceFeatureTypeAttr->value();
701     //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
702     //  // get the last point of the previuos arc feature(geom point 2d)
703     //  std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
704     //  std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
705     //                                  std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
706     //                                  aSData->attribute(SketchPlugin_Arc::END_ID()));
707     //  // get point attribute on the current feature
708     //  AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
709     //                                                SketchPlugin_Arc::TANGENT_POINT_ID());
710     //  aTangentPointAttr->setAttr(aSPointAttr);
711
712     //  std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
713     //                                std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
714     //                                theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
715     //  aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
716
717     //}
718     //ModuleBase_Tools::flushUpdated(theNewFeature);
719     aChanged = true;
720   }
721   else if (aFeatureKind == SketchPlugin_Trim::ID()) {
722     /*std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
723                             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
724                             theSourceFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
725     std::shared_ptr<ModelAPI_AttributeReference> aNRefSelectedAttr =
726                             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
727                             theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
728     aNRefSelectedAttr->setValue(aRefSelectedAttr->value());*/
729
730     std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
731                             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
732                             theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
733     std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
734                             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
735                             theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
736     aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
737
738     /*std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
739                             std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
740                             theSourceFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
741     std::shared_ptr<GeomDataAPI_Point2D> aNPointSelectedAttr =
742                             std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
743                             theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
744     aNPointSelectedAttr->setValue(aPointSelectedAttr->x(), aPointSelectedAttr->y());
745     */
746     std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
747                             std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
748                             theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
749     std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
750                             std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
751                             theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
752     aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
753
754     aChanged = true;
755   }
756   return aChanged;
757 }
758
759 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
760                                                  const CompositeFeaturePtr& /*theSketch*/) const
761 {
762   bool aTangentArc = false;
763   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
764                                                                         (theOperation);
765   if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
766     FeaturePtr aFeature = aFOperation->feature();
767     if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
768       AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
769       std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
770       aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
771     }
772   }
773   return aTangentArc;
774 }
775
776 std::shared_ptr<ModuleBase_ViewerPrs> PartSet_SketcherReentrantMgr::generatePreSelection()
777 {
778   std::shared_ptr<ModuleBase_ViewerPrs> aPrs;
779
780   return aPrs;
781 }
782
783 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
784 {
785   CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
786   if (aSketch.get())
787     workshop()->errorMgr()->updateAcceptAllAction(aSketch);
788 }
789
790 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
791 {
792   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
793   return aConnector->workshop();
794 }
795
796 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
797 {
798   return dynamic_cast<PartSet_Module*>(myWorkshop->module());
799 }