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