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