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