1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_SketcherReentrantMgr.h"
4 #include "PartSet_Module.h"
5 #include "PartSet_SketcherMgr.h"
6 #include "PartSet_WidgetPoint2d.h"
8 #include "ModelAPI_Session.h"
9 #include "ModelAPI_AttributeString.h"
10 #include "ModelAPI_AttributeRefAttr.h"
12 #include "GeomDataAPI_Point2D.h"
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"
26 #include <SketchPlugin_Feature.h>
27 #include <SketchPlugin_Line.h>
28 #include <SketchPlugin_MacroArc.h>
29 #include <SketchPlugin_MacroCircle.h>
30 #include <SketchPlugin_Point.h>
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>
39 #include <QToolButton>
41 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
42 : QObject(theWorkshop),
43 myWorkshop(theWorkshop),
44 myRestartingMode(RM_None),
45 myIsFlagsBlocked(false),
46 myIsInternalEditOperation(false),
47 myIsValueChangedBlocked(false),
48 myInternalActiveWidget(0),
49 myNoMoreWidgetsAttribute("")
53 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
57 ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
59 ModuleBase_ModelWidget* aWidget = 0;
63 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
65 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
66 if (aPanel) { // check for case when the operation is started but property panel is not filled
67 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
68 if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
69 aWidget = myInternalActiveWidget;
75 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
77 return myIsInternalEditOperation;
80 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
82 if (myIsInternalEditOperation) {
83 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
84 (myWorkshop->currentOperation());
86 FeaturePtr aFeature = aFOperation->feature();
87 QString anError = myWorkshop->module()->getFeatureError(aFeature);
88 // stop started internal edit operation as soon as the operation becomes invalid
89 // it is especially important for the sketch tangent arc feature
90 if (!anError.isEmpty()) {
91 aFOperation->setEditOperation(false);
92 //workshop()->operationMgr()->updateApplyOfOperations();
93 myIsInternalEditOperation = false;
94 updateAcceptAllAction();
100 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
102 bool aProcessed = false;
106 aProcessed = myIsInternalEditOperation;
112 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
117 if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
118 ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
119 myWorkshop->currentOperation());
120 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
121 copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
126 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
134 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
135 QMouseEvent* theEvent)
137 bool aProcessed = false;
141 if (myIsInternalEditOperation) {
142 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
143 (myWorkshop->currentOperation());
144 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
147 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
148 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
150 FeaturePtr aCurrentFeature = aFOperation->feature();
151 bool isLineFeature = false, isArcFeature = false;
152 std::string anAttributeOnStart;
153 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
154 anAttributeOnStart = SketchPlugin_Line::START_ID();
155 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
157 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
158 anAttributeOnStart = SketchPlugin_MacroArc::TANGENT_POINT_ID();
159 isArcFeature = anActiveWidget->attributeID() == anAttributeOnStart;
161 bool aCanBeActivatedByMove = isLineFeature || isArcFeature;
162 if (aCanBeActivatedByMove) {
163 /// before restarting of operation we need to clear selection, as it may take part in
164 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
165 /// by mouse release when the operation was restarted.
166 workshop()->selector()->clearSelection();
168 myPreviousFeature = aFOperation->feature();
170 myPreviousFeature = FeaturePtr();
172 anActiveWidget = module()->activeWidget();
173 aCurrentFeature = anActiveWidget->feature();
175 if (anActiveWidget->attributeID() == anAttributeOnStart) {
176 // it was not deactivated by preselection processing
177 aPanel->activateNextWidget(anActiveWidget);
180 // processing mouse move in active widget of restarted operation
181 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
182 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
184 aProcessor->mouseMoved(theWnd, theEvent);
191 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
192 QMouseEvent* /* theEvent*/)
194 return isActiveMgr() && myIsInternalEditOperation;
197 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWnd,
198 QMouseEvent* theEvent)
200 bool aProcessed = false;
204 if (myIsInternalEditOperation) {
205 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
206 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
208 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
209 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
211 // block of viewer update
212 // we need to block update content of the viewer because of Sketch Point feature
213 // in activate() the value of the point is initialized and it can be displayed
214 // but the default value is [0, 0]. So, we block update viewer contentent until
215 // onMouseRelease happens, which correct the point position
216 ModuleBase_Tools::blockUpdateViewer(true);
218 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
219 (myWorkshop->currentOperation());
220 myPreviousFeature = aFOperation->feature();
222 /// selection should be obtained from workshop before ask if the operation can be started as
223 /// the canStartOperation method performs commit/abort of previous operation.
224 /// Sometimes commit/abort
225 /// may cause selection clear(Sketch operation) as a result
226 /// it will be lost and is not used for preselection.
227 ModuleBase_ISelection* aSelection = myWorkshop->selection();
228 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
229 aSelection->getSelected(ModuleBase_ISelection::AllControls);
232 myPreviousFeature = FeaturePtr();
235 // fill the first widget by the mouse event point
236 // if the active widget is not the first, it means that the restarted operation is filled by
237 // the current preselection.
238 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
239 module()->activeWidget());
240 //PartSet_WidgetPoint2D* aPoint2DWdg =
241 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
242 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
243 aPanel->findFirstAcceptingValueWidget());
244 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
245 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
246 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
247 if (!aPreSelected.empty())
248 aSelectedPrs = aPreSelected.front();
249 aMouseProcessor->setPreSelection(aSelectedPrs, theWnd, theEvent);
250 //aPoint2DWdg->mouseReleased(theWnd, theEvent);
251 //if (!aPreSelected.empty())
252 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
254 // unblock viewer update
255 ModuleBase_Tools::blockUpdateViewer(false);
262 void PartSet_SketcherReentrantMgr::onWidgetActivated()
266 if (!myIsInternalEditOperation)
269 PartSet_Module* aModule = module();
270 ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
271 ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
272 if (aFirstWidget != aPanel->activeWidget()) {
273 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
275 aWSelector->activateSelectionAndFilters(true);
279 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
284 // we should avoid processing of the signal about no more widgets attributes and
285 // do this after the restart operaion is finished if it was called
286 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
287 // if it should be called after restart
288 if (myIsFlagsBlocked) {
289 myNoMoreWidgetsAttribute = thePreviousAttributeID;
293 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
294 (myWorkshop->currentOperation());
295 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
298 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
299 bool isStarted = false;
300 if (!module()->sketchMgr()->sketchSolverError()) {
301 if (myRestartingMode != RM_Forbided) {
302 myRestartingMode = RM_LastFeatureUsed;
303 isStarted = startInternalEdit(thePreviousAttributeID);
307 aFOperation->commit();
311 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
318 // empty previous attribute means that the Apply/Ok button has focus and the enter
319 // should not lead to start edition mode of the previous operation
320 if (thePreviousAttributeID.empty())
323 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
324 (myWorkshop->currentOperation());
325 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
328 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
330 if (!isSketchSolverError) {
331 myRestartingMode = RM_EmptyFeatureUsed;
332 isDone = startInternalEdit(thePreviousAttributeID);
338 void PartSet_SketcherReentrantMgr::onVertexSelected()
343 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
344 std::string anOperationId = anOperation->id().toStdString();
345 if (anOperationId == SketchPlugin_Line::ID() ||
346 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
347 /// If last line finished on vertex the lines creation sequence has to be break
348 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
349 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
350 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
351 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
352 bool aFoundWidget = false;
353 bool aFoundObligatory = false;
354 for (; anIt != aLast && !aFoundObligatory; anIt++) {
356 aFoundWidget = *anIt == anActiveWidget;
358 aFoundObligatory = (*anIt)->isObligatory();
360 if (!aFoundObligatory)
361 myRestartingMode = RM_Forbided;
365 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
367 // blocked flag in order to avoid circling when storeValue will be applied in
368 // this method to cached widget
369 if (myIsValueChangedBlocked)
372 if (isInternalEditActive()) {
373 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
374 if (!aWidget->isModifiedInEdit())
379 void PartSet_SketcherReentrantMgr::onBeforeStopped()
381 if (!isActiveMgr() || !myIsInternalEditOperation)
384 beforeStopInternalEdit();
387 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
389 return !isActiveMgr() || myRestartingMode == RM_None;
392 void PartSet_SketcherReentrantMgr::appendCreatedObjects(const std::set<ObjectPtr>& theObjects)
394 if (!myIsFlagsBlocked) // we need to collect objects only when launch operation is called
397 for (std::set<ObjectPtr>::const_iterator anIt = theObjects.begin();
398 anIt != theObjects.end(); ++anIt) {
399 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
400 if (myCreatedFeatures.find(aFeature) != myCreatedFeatures.end())
401 myCreatedFeatures.insert(aFeature);
405 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
407 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
409 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
411 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
412 if (anActive) { // the manager is not active when the current operation is a usual Edit
413 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
414 (myWorkshop->currentOperation());
415 if (aFOperation->isEditOperation())
416 anActive = myIsInternalEditOperation;
422 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
425 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
426 /// event comes two times, so we should not start another internal edit operation
427 /// the Apply button becomes disabled becase the second additional internal feature is created
428 if (myIsInternalEditOperation)
431 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
432 (myWorkshop->currentOperation());
434 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
435 aFOperation->setEditOperation(true/*, false*/);
436 createInternalFeature();
438 myIsInternalEditOperation = true;
439 updateAcceptAllAction();
442 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
443 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
445 // activate selection filters of the first widget in the viewer
448 // activate the last active widget in the Property Panel
449 if (!thePreviousAttributeID.empty()) {
450 ModuleBase_Operation* anEditOperation = module()->currentOperation();
451 if (anEditOperation) {
452 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
453 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
454 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
455 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
456 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
457 /// workaround for the same attributes used in different stacked widgets(attribute types)
458 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
460 aPreviousAttributeWidget = aWidgets[i];
463 // If the current widget is a selector, do nothing, it processes the mouse press
464 if (aPreviousAttributeWidget) {
465 if (!aPreviousAttributeWidget->isViewerSelector()) {
466 aPreviousAttributeWidget->focusTo();
467 aPreviousAttributeWidget->selectContent();
470 // in case of shape multi selector, the widget does not lose focus by filling
471 // like it is in shape selector. So, if enter is pressed, the multi shape selector
472 // control should be deactivated. The focus is moved to Apply button and there
473 // should not be active control visualized in property panel
474 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
475 aPanel->activateWidget(NULL, false);
477 // if there is no the next widget to be automatically activated,
478 // the Ok button in property
479 // panel should accept the focus(example is parallel constraint on sketch lines)
480 QToolButton* anOkBtn =
481 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
483 anOkBtn->setFocus(Qt::TabFocusReason);
490 module()->sketchMgr()->clearClickedFlags();
495 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
497 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
498 (myWorkshop->currentOperation());
500 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
501 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
504 deleteInternalFeature();
507 void PartSet_SketcherReentrantMgr::restartOperation()
509 if (myIsInternalEditOperation) {
510 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
511 myWorkshop->currentOperation());
513 // obtain widgets(attributes) which content should be applied to attributes of new feature
514 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
515 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
516 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
517 QList<ModuleBase_ModelWidget*> aValueWidgets;
518 for (int i = 0, aSize = aWidgets.size(); i < aSize; i++) {
519 ModuleBase_ModelWidget* aWidget = aWidgets[i];
520 if (!aWidget->isModifiedInEdit()) {
521 aValueWidgets.append(aWidget);
522 // the widget is cashed to fill feature of new operation by the current widget value
523 // we set empty parent to the widget in order to remove it ourselves. Reason: restart
524 // operation will clear property panel and delete all widgets. This widget should be
525 // removed only after applying value of the widget to new created feature.
526 aWidget->setParent(0);
530 myNoMoreWidgetsAttribute = "";
531 myIsFlagsBlocked = true;
532 module()->launchOperation(aFOperation->id());
533 myIsFlagsBlocked = false;
535 // we should avoid processing of the signal about no more widgets attributes and
536 // do this after the restart operaion is finished if it was called
537 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
538 // if it should be called after restart
539 if (!myNoMoreWidgetsAttribute.empty()) {
540 onNoMoreWidgets(myNoMoreWidgetsAttribute);
541 myNoMoreWidgetsAttribute = "";
544 // filling new feature by the previous value of active widget
545 // (e.g. circle_type in macro Circle)
546 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
547 myWorkshop->currentOperation());
548 myIsValueChangedBlocked = true; // flag to avoid onAfterValuesChangedInPropertyPanel slot
549 for (int i = 0, aSize = aValueWidgets.size(); i < aSize; i++) {
550 ModuleBase_ModelWidget* aWidget = aValueWidgets[i];
551 aWidget->setEditingMode(false);
552 aWidget->setFeature(aFOperation->feature());
553 aWidget->storeValue();
554 // we must delete this widget
557 myIsValueChangedBlocked = false;
562 void PartSet_SketcherReentrantMgr::createInternalFeature()
564 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
565 (myWorkshop->currentOperation());
567 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
568 FeaturePtr anOperationFeature = aFOperation->feature();
570 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
571 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
573 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
575 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
576 (aFOperation->propertyPanel());
578 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
579 myInternalWidget->setVisible(false);
581 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
583 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
584 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
586 aFactory.createWidget(anInternalPage);
587 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
589 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
590 bool isStoreValue = !aFOperation->isEditOperation() &&
591 !aWidget->getDefaultValue().empty() &&
592 !aWidget->isComputedDefault();
593 aWidget->setFeature(myInternalFeature, isStoreValue);
594 if (!isStoreValue && isFeatureChanged)
595 aWidget->restoreValue();
598 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
601 myInternalActiveWidget = aFirstWidget;
605 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
607 if (myInternalActiveWidget) {
608 ModuleBase_WidgetSelector* aWSelector =
609 dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
611 aWSelector->activateSelectionAndFilters(false);
612 myInternalActiveWidget = 0;
614 delete myInternalWidget;
615 myInternalWidget = 0;
617 QObjectPtrList anObjects;
618 anObjects.append(myInternalFeature);
619 workshop()->deleteFeatures(anObjects);
620 myInternalFeature = FeaturePtr();
623 void PartSet_SketcherReentrantMgr::resetFlags()
625 if (!myIsFlagsBlocked) {
626 myIsInternalEditOperation = false;
627 updateAcceptAllAction();
628 myRestartingMode = RM_None;
629 myCreatedFeatures.clear();
633 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
634 const FeaturePtr& theNewFeature,
635 const CompositeFeaturePtr& theSketch,
636 const bool isTemporary)
638 bool aChanged = false;
639 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
640 !theSourceFeature->data()->isValid())
643 std::string aFeatureKind = theSourceFeature->getKind();
644 if (aFeatureKind == SketchPlugin_Line::ID()) {
645 // Initialize new line with first point equal to end of previous
646 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
647 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
648 aSFData->attribute(SketchPlugin_Line::END_ID()));
649 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
650 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
651 aNFData->attribute(SketchPlugin_Line::START_ID()));
652 aNPoint->setValue(aSPoint->x(), aSPoint->y());
653 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
655 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
656 aSFData->attribute(SketchPlugin_Line::END_ID()));
657 aNPoint->setValue(aSPoint->x(), aSPoint->y());
659 else if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
661 std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
662 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
663 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
664 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
665 //ModuleBase_Tools::flushUpdated(theNewFeature);
668 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
670 std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
671 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
672 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
673 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
675 //// if the arc is tangent, set coincidence to end point of the previous arc
676 //std::string anArcType = aSourceFeatureTypeAttr->value();
677 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
678 // // get the last point of the previuos arc feature(geom point 2d)
679 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
680 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
681 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
682 // aSData->attribute(SketchPlugin_Arc::END_ID()));
683 // // get point attribute on the current feature
684 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
685 // SketchPlugin_Arc::TANGENT_POINT_ID());
686 // aTangentPointAttr->setAttr(aSPointAttr);
688 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
689 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
690 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
691 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
694 //ModuleBase_Tools::flushUpdated(theNewFeature);
700 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
701 const CompositeFeaturePtr& /*theSketch*/) const
703 bool aTangentArc = false;
704 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
706 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
707 FeaturePtr aFeature = aFOperation->feature();
708 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
709 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
710 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
711 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
717 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
719 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
721 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
724 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
726 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
727 return aConnector->workshop();
730 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
732 return dynamic_cast<PartSet_Module*>(myWorkshop->module());