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"
11 #include "ModelAPI_EventReentrantMessage.h"
13 #include "GeomDataAPI_Point2D.h"
15 #include <ModuleBase_IPropertyPanel.h>
16 #include <ModuleBase_OperationFeature.h>
17 #include <ModuleBase_ModelWidget.h>
18 #include <ModuleBase_ViewerPrs.h>
19 #include <ModuleBase_WidgetSelector.h>
20 #include <ModuleBase_PageWidget.h>
21 #include <ModuleBase_PageBase.h>
22 #include <ModuleBase_WidgetFactory.h>
23 #include <ModuleBase_OperationDescription.h>
24 #include "ModuleBase_ToolBox.h"
25 #include "ModuleBase_ISelection.h"
27 #include <SketchPlugin_Feature.h>
28 #include <SketchPlugin_Line.h>
29 #include <SketchPlugin_MacroArc.h>
30 #include <SketchPlugin_MacroCircle.h>
31 #include <SketchPlugin_Point.h>
32 #include <SketchPlugin_Trim.h>
34 #include <XGUI_Workshop.h>
35 #include <XGUI_ModuleConnector.h>
36 #include <XGUI_OperationMgr.h>
37 #include <XGUI_PropertyPanel.h>
38 #include <XGUI_ErrorMgr.h>
39 #include <XGUI_SelectionMgr.h>
41 #include <QToolButton>
43 //#define DEBUG_RESTART
45 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
46 : QObject(theWorkshop),
47 myWorkshop(theWorkshop),
48 myRestartingMode(RM_None),
49 myIsFlagsBlocked(false),
50 myIsInternalEditOperation(false),
51 myInternalActiveWidget(0),
52 myNoMoreWidgetsAttribute("")
56 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
60 ModuleBase_ModelWidget* PartSet_SketcherReentrantMgr::internalActiveWidget() const
62 ModuleBase_ModelWidget* aWidget = 0;
66 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
68 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
69 if (aPanel) { // check for case when the operation is started but property panel is not filled
70 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
71 if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector()))
72 aWidget = myInternalActiveWidget;
78 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
80 return myIsInternalEditOperation;
83 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
85 if (myIsInternalEditOperation) {
86 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
87 (myWorkshop->currentOperation());
89 FeaturePtr aFeature = aFOperation->feature();
90 QString anError = myWorkshop->module()->getFeatureError(aFeature);
91 // stop started internal edit operation as soon as the operation becomes invalid
92 // it is especially important for the sketch tangent arc feature
93 if (!anError.isEmpty()) {
94 aFOperation->setEditOperation(false);
95 //workshop()->operationMgr()->updateApplyOfOperations();
96 myIsInternalEditOperation = false;
97 updateAcceptAllAction();
103 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
105 bool aProcessed = false;
109 aProcessed = myIsInternalEditOperation;
115 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
120 if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
121 ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
122 myWorkshop->currentOperation());
123 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
124 if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
125 copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
130 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
138 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
139 QMouseEvent* theEvent)
141 bool aProcessed = false;
145 if (myIsInternalEditOperation) {
146 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
147 (myWorkshop->currentOperation());
148 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
151 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
152 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
154 FeaturePtr aCurrentFeature = aFOperation->feature();
155 bool isLineFeature = false, isReentrantArcFeature = false;
156 std::string anAttributeOnStart;
157 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
158 anAttributeOnStart = SketchPlugin_Line::START_ID();
159 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
161 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
162 isReentrantArcFeature = true;
164 bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature;
165 if (aCanBeActivatedByMove) {
166 /// before restarting of operation we need to clear selection, as it may take part in
167 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
168 /// by mouse release when the operation was restarted.
169 workshop()->selector()->clearSelection();
171 myPreviousFeature = aFOperation->feature();
173 myPreviousFeature = FeaturePtr();
175 anActiveWidget = module()->activeWidget();
176 aCurrentFeature = anActiveWidget->feature();
178 if (anActiveWidget->attributeID() == anAttributeOnStart) {
179 // it was not deactivated by preselection processing
180 aPanel->activateNextWidget(anActiveWidget);
183 // processing mouse move in active widget of restarted operation
184 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
185 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
187 aProcessor->mouseMoved(theWnd, theEvent);
194 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
195 QMouseEvent* /* theEvent*/)
197 return isActiveMgr() && myIsInternalEditOperation;
200 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
201 QMouseEvent* theEvent)
203 bool aProcessed = false;
207 if (myIsInternalEditOperation) {
208 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
209 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
211 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
212 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
214 // block of viewer update
215 // we need to block update content of the viewer because of Sketch Point feature
216 // in activate() the value of the point is initialized and it can be displayed
217 // but the default value is [0, 0]. So, we block update viewer contentent until
218 // onMouseRelease happens, which correct the point position
219 ModuleBase_Tools::blockUpdateViewer(true);
221 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
222 (myWorkshop->currentOperation());
223 myPreviousFeature = aFOperation->feature();
225 /// selection should be obtained from workshop before ask if the operation can be started as
226 /// the canStartOperation method performs commit/abort of previous operation.
227 /// Sometimes commit/abort
228 /// may cause selection clear(Sketch operation) as a result
229 /// it will be lost and is not used for preselection.
230 ModuleBase_ISelection* aSelection = myWorkshop->selection();
231 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
232 aSelection->getSelected(ModuleBase_ISelection::AllControls);
234 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
235 module()->sketchMgr()->activeSketch());
236 if (!aPreSelected.empty())
237 module()->getGeomSelection(aPreSelected.first(), mySelectedObject, mySelectedAttribute);
240 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
241 mySelectedObject = ObjectPtr();
242 mySelectedAttribute = AttributePtr();
244 myPreviousFeature = FeaturePtr();
247 // fill the first widget by the mouse event point
248 // if the active widget is not the first, it means that the restarted operation is filled by
249 // the current preselection.
250 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
251 module()->activeWidget());
252 //PartSet_WidgetPoint2D* aPoint2DWdg =
253 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
254 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
255 aPanel->findFirstAcceptingValueWidget());
256 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
257 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
258 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
259 if (!aPreSelected.empty())
260 aSelectedPrs = aPreSelected.front();
261 if (aSelectedPrs.get() && aSelectedPrs->object().get()
262 && !aSelectedPrs->object()->data()->isValid()) {
263 // the selected object was removed diring restart, e.g. presentable macro feature
264 // there are created objects to replace the object depending on created feature kind
265 aSelectedPrs = generatePreSelection();
267 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
268 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
269 //if (!aPreSelected.empty())
270 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
272 // unblock viewer update
273 ModuleBase_Tools::blockUpdateViewer(false);
279 //******************************************************
280 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
281 const std::shared_ptr<Events_Message>& theMessage)
283 ReentrantMessagePtr aReentrantMessage =
284 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
285 if (!aReentrantMessage.get())
288 // if feature has already filled the selected object, we should not overwrite it
289 if (!aReentrantMessage->selectedObject().get())
290 aReentrantMessage->setSelectedObject(mySelectedObject);
292 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
293 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
296 void PartSet_SketcherReentrantMgr::onWidgetActivated()
300 if (!myIsInternalEditOperation)
303 PartSet_Module* aModule = module();
304 ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
305 ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
306 if (aFirstWidget != aPanel->activeWidget()) {
307 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
309 aWSelector->activateSelectionAndFilters(true);
313 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
316 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
322 // we should avoid processing of the signal about no more widgets attributes and
323 // do this after the restart operaion is finished if it was called
324 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
325 // if it should be called after restart
326 if (myIsFlagsBlocked) {
327 myNoMoreWidgetsAttribute = thePreviousAttributeID;
331 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
332 (myWorkshop->currentOperation());
333 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
336 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
337 bool isStarted = false;
338 if (!module()->sketchMgr()->sketchSolverError()) {
339 if (myRestartingMode != RM_Forbided) {
340 myRestartingMode = RM_LastFeatureUsed;
341 isStarted = startInternalEdit(thePreviousAttributeID);
345 aFOperation->commit();
349 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
356 // empty previous attribute means that the Apply/Ok button has focus and the enter
357 // should not lead to start edition mode of the previous operation
358 if (thePreviousAttributeID.empty())
361 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
362 (myWorkshop->currentOperation());
363 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
366 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
368 if (!isSketchSolverError) {
369 myRestartingMode = RM_EmptyFeatureUsed;
370 isDone = startInternalEdit(thePreviousAttributeID);
376 void PartSet_SketcherReentrantMgr::onVertexSelected()
381 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
382 std::string anOperationId = anOperation->id().toStdString();
383 if (anOperationId == SketchPlugin_Line::ID() ||
384 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
385 /// If last line finished on vertex the lines creation sequence has to be break
386 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
387 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
388 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
389 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
390 bool aFoundWidget = false;
391 bool aFoundObligatory = false;
392 for (; anIt != aLast && !aFoundObligatory; anIt++) {
394 aFoundWidget = *anIt == anActiveWidget;
396 aFoundObligatory = (*anIt)->isObligatory();
398 if (!aFoundObligatory)
399 myRestartingMode = RM_Forbided;
403 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
406 if (isInternalEditActive()) {
407 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
408 (myWorkshop->currentOperation());
409 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
410 if (!aWidget->isModifiedInEdit().empty())
415 void PartSet_SketcherReentrantMgr::onBeforeStopped()
417 if (!isActiveMgr() || !myIsInternalEditOperation)
420 beforeStopInternalEdit();
423 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
425 return !isActiveMgr() || myRestartingMode == RM_None;
428 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
430 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
432 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
434 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
435 if (anActive) { // the manager is not active when the current operation is a usual Edit
436 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
437 (myWorkshop->currentOperation());
438 if (aFOperation->isEditOperation())
439 anActive = myIsInternalEditOperation;
445 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
448 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
452 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
453 /// event comes two times, so we should not start another internal edit operation
454 /// the Apply button becomes disabled becase the second additional internal feature is created
455 if (myIsInternalEditOperation)
458 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
459 (myWorkshop->currentOperation());
461 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
462 aFOperation->setEditOperation(true/*, false*/);
463 createInternalFeature();
465 myIsInternalEditOperation = true;
466 updateAcceptAllAction();
469 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
470 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
472 // activate selection filters of the first widget in the viewer
475 // activate the last active widget in the Property Panel
476 if (!thePreviousAttributeID.empty()) {
477 ModuleBase_Operation* anEditOperation = module()->currentOperation();
478 if (anEditOperation) {
479 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
480 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
481 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
482 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
483 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
484 /// workaround for the same attributes used in different stacked widgets(attribute types)
485 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
487 aPreviousAttributeWidget = aWidgets[i];
490 // If the current widget is a selector, do nothing, it processes the mouse press
491 if (aPreviousAttributeWidget) {
492 if (!aPreviousAttributeWidget->isViewerSelector()) {
493 aPreviousAttributeWidget->focusTo();
494 aPreviousAttributeWidget->selectContent();
497 // in case of shape multi selector, the widget does not lose focus by filling
498 // like it is in shape selector. So, if enter is pressed, the multi shape selector
499 // control should be deactivated. The focus is moved to Apply button and there
500 // should not be active control visualized in property panel
501 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
502 aPanel->activateWidget(NULL, false);
504 // if there is no the next widget to be automatically activated,
505 // the Ok button in property
506 // panel should accept the focus(example is parallel constraint on sketch lines)
507 QToolButton* anOkBtn =
508 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
510 anOkBtn->setFocus(Qt::TabFocusReason);
517 module()->sketchMgr()->clearClickedFlags();
522 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
524 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
525 (myWorkshop->currentOperation());
527 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
528 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
531 deleteInternalFeature();
534 void PartSet_SketcherReentrantMgr::restartOperation()
537 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
540 if (myIsInternalEditOperation) {
541 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
542 myWorkshop->currentOperation());
544 ModuleBase_ISelection* aSelection = myWorkshop->selection();
545 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
546 aSelection->getSelected(ModuleBase_ISelection::AllControls);
548 if (myInternalFeature.get())
549 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
550 module()->sketchMgr()->activeSketch());
552 myNoMoreWidgetsAttribute = "";
553 myIsFlagsBlocked = true;
554 /// launch has 'false' parameter to do not start new operation if the previous operation
555 /// is not committed. It is important for Line Sketch feature as it uses the previous
556 /// created feature parameter(to build coincidence), but by abort the previous is removed
557 module()->launchOperation(aFOperation->id(), true);
558 myIsFlagsBlocked = false;
561 // we should avoid processing of the signal about no more widgets attributes and
562 // do this after the restart operaion is finished if it was called
563 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
564 // if it should be called after restart
565 if (!myNoMoreWidgetsAttribute.empty()) {
566 onNoMoreWidgets(myNoMoreWidgetsAttribute);
567 myNoMoreWidgetsAttribute = "";
573 void PartSet_SketcherReentrantMgr::createInternalFeature()
575 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
576 (myWorkshop->currentOperation());
578 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
579 FeaturePtr anOperationFeature = aFOperation->feature();
581 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
582 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
585 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
586 << myInternalFeature->data()->name() << std::endl;
589 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
591 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
592 (aFOperation->propertyPanel());
594 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
595 myInternalWidget->setVisible(false);
597 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
599 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
600 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
602 aFactory.createWidget(anInternalPage);
603 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
605 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
606 bool isStoreValue = !aFOperation->isEditOperation() &&
607 !aWidget->getDefaultValue().empty() &&
608 !aWidget->isComputedDefault();
609 aWidget->setFeature(myInternalFeature, isStoreValue);
610 if (!isStoreValue && isFeatureChanged)
611 aWidget->restoreValue();
614 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
617 myInternalActiveWidget = aFirstWidget;
621 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
624 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
625 << myInternalFeature->data()->name() << std::endl;
627 if (myInternalActiveWidget) {
628 ModuleBase_WidgetSelector* aWSelector =
629 dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
631 aWSelector->activateSelectionAndFilters(false);
632 myInternalActiveWidget = 0;
634 delete myInternalWidget;
635 myInternalWidget = 0;
637 QObjectPtrList anObjects;
638 anObjects.append(myInternalFeature);
639 workshop()->deleteFeatures(anObjects);
640 myInternalFeature = FeaturePtr();
643 void PartSet_SketcherReentrantMgr::resetFlags()
645 if (!myIsFlagsBlocked) {
646 myIsInternalEditOperation = false;
647 updateAcceptAllAction();
648 myRestartingMode = RM_None;
649 myReentrantMessage = std::shared_ptr<Events_Message>();
653 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
654 const FeaturePtr& theNewFeature,
655 const CompositeFeaturePtr& theSketch,
656 const bool /*isTemporary*/)
658 bool aChanged = false;
659 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
660 !theSourceFeature->data()->isValid())
664 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
665 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
669 std::string aFeatureKind = theSourceFeature->getKind();
670 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
671 // Initialize new line with first point equal to end of previous
672 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
673 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
674 aSFData->attribute(SketchPlugin_Line::END_ID()));
675 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
676 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
677 aNFData->attribute(SketchPlugin_Line::START_ID()));
678 aNPoint->setValue(aSPoint->x(), aSPoint->y());
679 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
681 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
682 aSFData->attribute(SketchPlugin_Line::END_ID()));
683 aNPoint->setValue(aSPoint->x(), aSPoint->y());
685 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
687 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
688 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
689 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
690 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
691 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
692 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
695 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
697 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
698 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
699 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
700 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
701 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
702 //// if the arc is tangent, set coincidence to end point of the previous arc
703 //std::string anArcType = aSourceFeatureTypeAttr->value();
704 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
705 // // get the last point of the previuos arc feature(geom point 2d)
706 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
707 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
708 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
709 // aSData->attribute(SketchPlugin_Arc::END_ID()));
710 // // get point attribute on the current feature
711 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
712 // SketchPlugin_Arc::TANGENT_POINT_ID());
713 // aTangentPointAttr->setAttr(aSPointAttr);
715 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
716 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
717 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
718 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
721 //ModuleBase_Tools::flushUpdated(theNewFeature);
724 else if (aFeatureKind == SketchPlugin_Trim::ID()) {
725 /*std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
726 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
727 theSourceFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
728 std::shared_ptr<ModelAPI_AttributeReference> aNRefSelectedAttr =
729 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
730 theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
731 aNRefSelectedAttr->setValue(aRefSelectedAttr->value());*/
733 /*std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
734 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
735 theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
736 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
737 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
738 theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
739 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());*/
741 /*std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
742 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
743 theSourceFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
744 std::shared_ptr<GeomDataAPI_Point2D> aNPointSelectedAttr =
745 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
746 theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
747 aNPointSelectedAttr->setValue(aPointSelectedAttr->x(), aPointSelectedAttr->y());
749 /*std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
750 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
751 theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
752 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
753 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
754 theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
755 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
762 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
763 const CompositeFeaturePtr& /*theSketch*/) const
765 bool aTangentArc = false;
766 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
768 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
769 FeaturePtr aFeature = aFOperation->feature();
770 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
771 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
772 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
773 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
779 std::shared_ptr<ModuleBase_ViewerPrs> PartSet_SketcherReentrantMgr::generatePreSelection()
781 std::shared_ptr<ModuleBase_ViewerPrs> aPrs;
786 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
788 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
790 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
793 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
795 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
796 return aConnector->workshop();
799 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
801 return dynamic_cast<PartSet_Module*>(myWorkshop->module());