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