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, isArcFeature = 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 anAttributeOnStart = SketchPlugin_MacroArc::TANGENT_POINT_ID();
163 isArcFeature = anActiveWidget->attributeID() == anAttributeOnStart;
165 bool aCanBeActivatedByMove = isLineFeature || isArcFeature;
166 if (aCanBeActivatedByMove) {
167 /// before restarting of operation we need to clear selection, as it may take part in
168 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
169 /// by mouse release when the operation was restarted.
170 workshop()->selector()->clearSelection();
172 myPreviousFeature = aFOperation->feature();
174 myPreviousFeature = FeaturePtr();
176 anActiveWidget = module()->activeWidget();
177 aCurrentFeature = anActiveWidget->feature();
179 if (anActiveWidget->attributeID() == anAttributeOnStart) {
180 // it was not deactivated by preselection processing
181 aPanel->activateNextWidget(anActiveWidget);
184 // processing mouse move in active widget of restarted operation
185 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
186 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
188 aProcessor->mouseMoved(theWnd, theEvent);
195 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
196 QMouseEvent* /* theEvent*/)
198 return isActiveMgr() && myIsInternalEditOperation;
201 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
202 QMouseEvent* theEvent)
204 bool aProcessed = false;
208 if (myIsInternalEditOperation) {
209 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
210 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
212 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
213 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
215 // block of viewer update
216 // we need to block update content of the viewer because of Sketch Point feature
217 // in activate() the value of the point is initialized and it can be displayed
218 // but the default value is [0, 0]. So, we block update viewer contentent until
219 // onMouseRelease happens, which correct the point position
220 ModuleBase_Tools::blockUpdateViewer(true);
222 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
223 (myWorkshop->currentOperation());
224 myPreviousFeature = aFOperation->feature();
226 /// selection should be obtained from workshop before ask if the operation can be started as
227 /// the canStartOperation method performs commit/abort of previous operation.
228 /// Sometimes commit/abort
229 /// may cause selection clear(Sketch operation) as a result
230 /// it will be lost and is not used for preselection.
231 ModuleBase_ISelection* aSelection = myWorkshop->selection();
232 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
233 aSelection->getSelected(ModuleBase_ISelection::AllControls);
235 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
236 module()->sketchMgr()->activeSketch());
237 if (!aPreSelected.empty())
238 module()->getGeomSelection(aPreSelected.first(), mySelectedObject, mySelectedAttribute);
241 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
242 mySelectedObject = ObjectPtr();
243 mySelectedAttribute = AttributePtr();
245 myPreviousFeature = FeaturePtr();
248 // fill the first widget by the mouse event point
249 // if the active widget is not the first, it means that the restarted operation is filled by
250 // the current preselection.
251 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
252 module()->activeWidget());
253 //PartSet_WidgetPoint2D* aPoint2DWdg =
254 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
255 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
256 aPanel->findFirstAcceptingValueWidget());
257 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
258 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
259 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
260 if (!aPreSelected.empty())
261 aSelectedPrs = aPreSelected.front();
262 if (aSelectedPrs.get() && aSelectedPrs->object().get()
263 && !aSelectedPrs->object()->data()->isValid()) {
264 // the selected object was removed diring restart, e.g. presentable macro feature
265 // there are created objects to replace the object depending on created feature kind
266 aSelectedPrs = generatePreSelection();
268 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
269 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
270 //if (!aPreSelected.empty())
271 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
273 // unblock viewer update
274 ModuleBase_Tools::blockUpdateViewer(false);
280 //******************************************************
281 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
282 const std::shared_ptr<Events_Message>& theMessage)
284 ReentrantMessagePtr aReentrantMessage =
285 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
286 if (!aReentrantMessage.get())
289 // if feature has already filled the selected object, we should not overwrite it
290 if (!aReentrantMessage->selectedObject().get())
291 aReentrantMessage->setSelectedObject(mySelectedObject);
293 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
294 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
297 void PartSet_SketcherReentrantMgr::onWidgetActivated()
301 if (!myIsInternalEditOperation)
304 PartSet_Module* aModule = module();
305 ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
306 ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
307 if (aFirstWidget != aPanel->activeWidget()) {
308 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
310 aWSelector->activateSelectionAndFilters(true);
314 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
317 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
323 // we should avoid processing of the signal about no more widgets attributes and
324 // do this after the restart operaion is finished if it was called
325 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
326 // if it should be called after restart
327 if (myIsFlagsBlocked) {
328 myNoMoreWidgetsAttribute = thePreviousAttributeID;
332 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
333 (myWorkshop->currentOperation());
334 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
337 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
338 bool isStarted = false;
339 if (!module()->sketchMgr()->sketchSolverError()) {
340 if (myRestartingMode != RM_Forbided) {
341 myRestartingMode = RM_LastFeatureUsed;
342 isStarted = startInternalEdit(thePreviousAttributeID);
346 aFOperation->commit();
350 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
357 // empty previous attribute means that the Apply/Ok button has focus and the enter
358 // should not lead to start edition mode of the previous operation
359 if (thePreviousAttributeID.empty())
362 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
363 (myWorkshop->currentOperation());
364 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
367 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
369 if (!isSketchSolverError) {
370 myRestartingMode = RM_EmptyFeatureUsed;
371 isDone = startInternalEdit(thePreviousAttributeID);
377 void PartSet_SketcherReentrantMgr::onVertexSelected()
382 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
383 std::string anOperationId = anOperation->id().toStdString();
384 if (anOperationId == SketchPlugin_Line::ID() ||
385 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
386 /// If last line finished on vertex the lines creation sequence has to be break
387 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
388 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
389 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
390 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
391 bool aFoundWidget = false;
392 bool aFoundObligatory = false;
393 for (; anIt != aLast && !aFoundObligatory; anIt++) {
395 aFoundWidget = *anIt == anActiveWidget;
397 aFoundObligatory = (*anIt)->isObligatory();
399 if (!aFoundObligatory)
400 myRestartingMode = RM_Forbided;
404 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
407 if (isInternalEditActive()) {
408 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
409 (myWorkshop->currentOperation());
410 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
411 if (!aWidget->isModifiedInEdit().empty())
416 void PartSet_SketcherReentrantMgr::onBeforeStopped()
418 if (!isActiveMgr() || !myIsInternalEditOperation)
421 beforeStopInternalEdit();
424 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
426 return !isActiveMgr() || myRestartingMode == RM_None;
429 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
431 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
433 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
435 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
436 if (anActive) { // the manager is not active when the current operation is a usual Edit
437 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
438 (myWorkshop->currentOperation());
439 if (aFOperation->isEditOperation())
440 anActive = myIsInternalEditOperation;
446 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
449 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
453 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
454 /// event comes two times, so we should not start another internal edit operation
455 /// the Apply button becomes disabled becase the second additional internal feature is created
456 if (myIsInternalEditOperation)
459 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
460 (myWorkshop->currentOperation());
462 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
463 aFOperation->setEditOperation(true/*, false*/);
464 createInternalFeature();
466 myIsInternalEditOperation = true;
467 updateAcceptAllAction();
470 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
471 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
473 // activate selection filters of the first widget in the viewer
476 // activate the last active widget in the Property Panel
477 if (!thePreviousAttributeID.empty()) {
478 ModuleBase_Operation* anEditOperation = module()->currentOperation();
479 if (anEditOperation) {
480 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
481 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
482 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
483 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
484 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
485 /// workaround for the same attributes used in different stacked widgets(attribute types)
486 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
488 aPreviousAttributeWidget = aWidgets[i];
491 // If the current widget is a selector, do nothing, it processes the mouse press
492 if (aPreviousAttributeWidget) {
493 if (!aPreviousAttributeWidget->isViewerSelector()) {
494 aPreviousAttributeWidget->focusTo();
495 aPreviousAttributeWidget->selectContent();
498 // in case of shape multi selector, the widget does not lose focus by filling
499 // like it is in shape selector. So, if enter is pressed, the multi shape selector
500 // control should be deactivated. The focus is moved to Apply button and there
501 // should not be active control visualized in property panel
502 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
503 aPanel->activateWidget(NULL, false);
505 // if there is no the next widget to be automatically activated,
506 // the Ok button in property
507 // panel should accept the focus(example is parallel constraint on sketch lines)
508 QToolButton* anOkBtn =
509 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
511 anOkBtn->setFocus(Qt::TabFocusReason);
518 module()->sketchMgr()->clearClickedFlags();
523 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
525 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
526 (myWorkshop->currentOperation());
528 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
529 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
532 deleteInternalFeature();
535 void PartSet_SketcherReentrantMgr::restartOperation()
538 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
541 if (myIsInternalEditOperation) {
542 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
543 myWorkshop->currentOperation());
545 ModuleBase_ISelection* aSelection = myWorkshop->selection();
546 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
547 aSelection->getSelected(ModuleBase_ISelection::AllControls);
549 if (myInternalFeature.get())
550 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
551 module()->sketchMgr()->activeSketch());
553 myNoMoreWidgetsAttribute = "";
554 myIsFlagsBlocked = true;
555 /// launch has 'false' parameter to do not start new operation if the previous operation
556 /// is not committed. It is important for Line Sketch feature as it uses the previous
557 /// created feature parameter(to build coincidence), but by abort the previous is removed
558 module()->launchOperation(aFOperation->id(), true);
559 myIsFlagsBlocked = false;
562 // we should avoid processing of the signal about no more widgets attributes and
563 // do this after the restart operaion is finished if it was called
564 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
565 // if it should be called after restart
566 if (!myNoMoreWidgetsAttribute.empty()) {
567 onNoMoreWidgets(myNoMoreWidgetsAttribute);
568 myNoMoreWidgetsAttribute = "";
574 void PartSet_SketcherReentrantMgr::createInternalFeature()
576 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
577 (myWorkshop->currentOperation());
579 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
580 FeaturePtr anOperationFeature = aFOperation->feature();
582 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
583 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
586 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
587 << myInternalFeature->data()->name() << std::endl;
590 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
592 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
593 (aFOperation->propertyPanel());
595 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
596 myInternalWidget->setVisible(false);
598 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
600 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
601 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
603 aFactory.createWidget(anInternalPage);
604 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
606 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
607 bool isStoreValue = !aFOperation->isEditOperation() &&
608 !aWidget->getDefaultValue().empty() &&
609 !aWidget->isComputedDefault();
610 aWidget->setFeature(myInternalFeature, isStoreValue);
611 if (!isStoreValue && isFeatureChanged)
612 aWidget->restoreValue();
615 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
618 myInternalActiveWidget = aFirstWidget;
622 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
625 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
626 << myInternalFeature->data()->name() << std::endl;
628 if (myInternalActiveWidget) {
629 ModuleBase_WidgetSelector* aWSelector =
630 dynamic_cast<ModuleBase_WidgetSelector*>(myInternalActiveWidget);
632 aWSelector->activateSelectionAndFilters(false);
633 myInternalActiveWidget = 0;
635 delete myInternalWidget;
636 myInternalWidget = 0;
638 QObjectPtrList anObjects;
639 anObjects.append(myInternalFeature);
640 workshop()->deleteFeatures(anObjects);
641 myInternalFeature = FeaturePtr();
644 void PartSet_SketcherReentrantMgr::resetFlags()
646 if (!myIsFlagsBlocked) {
647 myIsInternalEditOperation = false;
648 updateAcceptAllAction();
649 myRestartingMode = RM_None;
650 myReentrantMessage = std::shared_ptr<Events_Message>();
654 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
655 const FeaturePtr& theNewFeature,
656 const CompositeFeaturePtr& theSketch,
657 const bool /*isTemporary*/)
659 bool aChanged = false;
660 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
661 !theSourceFeature->data()->isValid())
665 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
666 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
670 std::string aFeatureKind = theSourceFeature->getKind();
671 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
672 // Initialize new line with first point equal to end of previous
673 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
674 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
675 aSFData->attribute(SketchPlugin_Line::END_ID()));
676 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
677 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
678 aNFData->attribute(SketchPlugin_Line::START_ID()));
679 aNPoint->setValue(aSPoint->x(), aSPoint->y());
680 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
682 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
683 aSFData->attribute(SketchPlugin_Line::END_ID()));
684 aNPoint->setValue(aSPoint->x(), aSPoint->y());
686 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
688 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
689 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
690 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
691 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
692 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
693 //ModuleBase_Tools::flushUpdated(theNewFeature);
696 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
698 std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
699 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
700 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
701 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
702 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
703 //// if the arc is tangent, set coincidence to end point of the previous arc
704 //std::string anArcType = aSourceFeatureTypeAttr->value();
705 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
706 // // get the last point of the previuos arc feature(geom point 2d)
707 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
708 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
709 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
710 // aSData->attribute(SketchPlugin_Arc::END_ID()));
711 // // get point attribute on the current feature
712 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
713 // SketchPlugin_Arc::TANGENT_POINT_ID());
714 // aTangentPointAttr->setAttr(aSPointAttr);
716 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
717 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
718 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
719 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
722 //ModuleBase_Tools::flushUpdated(theNewFeature);
725 else if (aFeatureKind == SketchPlugin_Trim::ID()) {
726 /*std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
727 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
728 theSourceFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
729 std::shared_ptr<ModelAPI_AttributeReference> aNRefSelectedAttr =
730 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
731 theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
732 aNRefSelectedAttr->setValue(aRefSelectedAttr->value());*/
734 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
735 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
736 theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
737 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
738 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
739 theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
740 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
742 /*std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
743 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
744 theSourceFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
745 std::shared_ptr<GeomDataAPI_Point2D> aNPointSelectedAttr =
746 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
747 theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
748 aNPointSelectedAttr->setValue(aPointSelectedAttr->x(), aPointSelectedAttr->y());
750 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
751 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
752 theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
753 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
754 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
755 theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
756 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
763 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
764 const CompositeFeaturePtr& /*theSketch*/) const
766 bool aTangentArc = false;
767 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
769 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
770 FeaturePtr aFeature = aFOperation->feature();
771 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
772 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
773 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
774 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
780 std::shared_ptr<ModuleBase_ViewerPrs> PartSet_SketcherReentrantMgr::generatePreSelection()
782 std::shared_ptr<ModuleBase_ViewerPrs> aPrs;
787 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
789 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
791 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
794 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
796 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
797 return aConnector->workshop();
800 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
802 return dynamic_cast<PartSet_Module*>(myWorkshop->module());