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