Salome HOME
Crossed cursor correction: it stayed in the application if the feature is aborted.
[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       FeaturePtr aPrevFeature = aFOperation->feature();
462       aFOperation->commit();
463       module()->launchOperation(aFOperation->id());
464       myIsFlagsBlocked = false;
465       resetFlags();
466       // we should avoid processing of the signal about no more widgets attributes and 
467       // do this after the restart operaion is finished if it was called
468       // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
469       // if it should be called after restart
470       if (!myNoMoreWidgetsAttribute.empty()) {
471         onNoMoreWidgets(myNoMoreWidgetsAttribute);
472         myNoMoreWidgetsAttribute = "";
473       }
474     }
475   }
476 }
477
478 void PartSet_SketcherReetntrantMgr::createInternalFeature()
479 {
480   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
481                                                      (myWorkshop->currentOperation());
482
483   if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
484     FeaturePtr anOperationFeature = aFOperation->feature();
485
486     CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
487     myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
488
489     bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
490                                                      aSketch, false);
491     XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
492                                                   (aFOperation->propertyPanel());
493
494     myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
495     myInternalWidget->setVisible(false);
496
497     ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
498
499     QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
500     ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
501
502     aFactory.createWidget(anInternalPage);
503     QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
504
505     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
506       bool isStoreValue = !aFOperation->isEditOperation() &&
507                           !aWidget->getDefaultValue().empty() &&
508                           !aWidget->isComputedDefault();
509       aWidget->setFeature(myInternalFeature, isStoreValue);
510       if (!isStoreValue && isFeatureChanged)
511         aWidget->restoreValue();
512     }
513
514     ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
515                                                                                         (aWidgets);
516     if (aFirstWidget)
517       myInternalActiveWidget = aFirstWidget;
518   }
519 }
520
521 void PartSet_SketcherReetntrantMgr::deleteInternalFeature()
522 {
523   if (myInternalActiveWidget) {
524     ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
525     if (aWSelector)
526       aWSelector->activateSelectionAndFilters(false);
527     myInternalActiveWidget = 0;
528   }
529   delete myInternalWidget;
530   myInternalWidget = 0;
531
532   QObjectPtrList anObjects;
533   anObjects.append(myInternalFeature);
534   workshop()->deleteFeatures(anObjects);
535   myInternalFeature = FeaturePtr();
536 }
537
538 void PartSet_SketcherReetntrantMgr::resetFlags()
539 {
540   if (!myIsFlagsBlocked) {
541     myIsInternalEditOperation = false;
542     updateAcceptAllAction();
543     myRestartingMode = RM_None;
544   }
545 }
546
547 bool PartSet_SketcherReetntrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
548                                                              const FeaturePtr& theNewFeature,
549                                                              const CompositeFeaturePtr& theSketch,
550                                                              const bool isTemporary)
551 {
552   bool aChanged = false;
553   if (!theSourceFeature.get())
554     return aChanged;
555
556   std::string aFeatureKind = theSourceFeature->getKind();
557   if (aFeatureKind == SketchPlugin_Line::ID()) {
558     // Initialize new line with first point equal to end of previous
559     std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
560     std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
561                                                  aSFData->attribute(SketchPlugin_Line::END_ID()));
562     std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
563     std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
564                                                  aNFData->attribute(SketchPlugin_Line::START_ID()));
565     aNPoint->setValue(aSPoint->x(), aSPoint->y());
566     PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
567
568     aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
569                                                  aSFData->attribute(SketchPlugin_Line::END_ID()));
570     aNPoint->setValue(aSPoint->x(), aSPoint->y());
571   }
572   else if (aFeatureKind == SketchPlugin_Circle::ID()) {
573     // set circle type
574     std::string aTypeAttributeId = SketchPlugin_Circle::CIRCLE_TYPE();
575     AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
576     AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
577     aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
578     //ModuleBase_Tools::flushUpdated(theNewFeature);
579     aChanged = true;
580   }
581   else if (aFeatureKind == SketchPlugin_Arc::ID()) {
582     // set arc type
583     std::string aTypeAttributeId = SketchPlugin_Arc::ARC_TYPE();
584     AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
585     AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
586     aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
587
588     // if the arc is tangent, set coincidence to end point of the previous arc
589     std::string anArcType = aSourceFeatureTypeAttr->value();
590     if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
591       // get the last point of the previuos arc feature(geom point 2d)
592       std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
593       std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr = 
594                                       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
595                                       aSData->attribute(SketchPlugin_Arc::END_ID()));
596       // get point attribute on the current feature
597       AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
598                                                     SketchPlugin_Arc::TANGENT_POINT_ID());
599       aTangentPointAttr->setAttr(aSPointAttr);
600
601       std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr = 
602                                     std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
603                                     theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
604       aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
605
606     }
607     //ModuleBase_Tools::flushUpdated(theNewFeature);
608     aChanged = true;
609   }
610   return aChanged;
611 }
612
613 bool PartSet_SketcherReetntrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
614                                                  const CompositeFeaturePtr& /*theSketch*/) const
615 {
616   bool aTangentArc = false;
617   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
618                                                                         (theOperation);
619   if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
620     FeaturePtr aFeature = aFOperation->feature();
621     if (aFeature.get() && aFeature->getKind() == SketchPlugin_Arc::ID()) {
622       AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_Arc::ARC_TYPE());
623       std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
624       aTangentArc = anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT();
625     }
626   }
627   return aTangentArc;
628 }
629
630 void PartSet_SketcherReetntrantMgr::updateAcceptAllAction()
631 {
632   CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
633   if (aSketch.get())
634     workshop()->errorMgr()->updateAcceptAllAction(aSketch);
635 }
636
637 XGUI_Workshop* PartSet_SketcherReetntrantMgr::workshop() const
638 {
639   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
640   return aConnector->workshop();
641 }
642
643 PartSet_Module* PartSet_SketcherReetntrantMgr::module() const
644 {
645   return dynamic_cast<PartSet_Module*>(myWorkshop->module());
646 }
647