From f68074b0f3e013e10a9d06016ceac84827a5cdc2 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 30 Mar 2017 09:54:37 +0300 Subject: [PATCH 1/1] Issue #2071 Fatal error when Create box --- src/PartSet/PartSet_Module.cpp | 4 +- .../PartSet_OverconstraintListener.cpp | 38 +++++++++++++------ src/PartSet/PartSet_SketcherReentrantMgr.cpp | 13 ++++++- src/PartSet/PartSet_SketcherReentrantMgr.h | 8 ++-- src/PartSet/PartSet_WidgetPoint2d.cpp | 2 +- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 2d4bc1579..edd895a40 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -512,7 +512,7 @@ bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const { bool isEnabledFixed = false; if (theActionId == XGUI_ActionsMgr::AcceptAll && - mySketchReentrantMgr->isInternalEditStarted()) + mySketchReentrantMgr->isInternalEditActive()) isEnabledFixed = true; return isEnabledFixed; } @@ -560,7 +560,7 @@ bool PartSet_Module::isMouseOverWindow() bool PartSet_Module::isSketchNeutralPointActivated() const { bool isNeutralPoint = true; - if (sketchReentranceMgr()->isInternalEditStarted()) + if (sketchReentranceMgr()->isInternalEditActive()) isNeutralPoint = false; if (myIsOperationIsLaunched) isNeutralPoint = false; diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 8dd5af2eb..0e74b0600 100755 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -9,6 +9,7 @@ #include "PartSet_OverconstraintListener.h" #include #include +#include #include "XGUI_ModuleConnector.h" #include "XGUI_Workshop.h" @@ -29,7 +30,7 @@ //#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop) -: myWorkshop(theWorkshop), myIsFullyConstrained(false), myIsNeedUpdateCustomColor(false) +: myWorkshop(theWorkshop), myIsFullyConstrained(false)//, myIsNeedUpdateCustomColor(false) { Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED)); @@ -37,6 +38,8 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED)); + + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); } void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject, @@ -111,24 +114,35 @@ void PartSet_OverconstraintListener::processEvent( myIsFullyConstrained = anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED); if (aPrevFullyConstrained != myIsFullyConstrained) { - myIsNeedUpdateCustomColor = true; + //myIsNeedUpdateCustomColor = true; std::set aModifiedObjects; PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch(); - for (int i = 0; i < aSketch->numberOfSubs(); i++) { - FeaturePtr aFeature = aSketch->subFeature(i); - aModifiedObjects.insert(aFeature); // is necessary to redisplay presentations - std::list aResults = aFeature->results(); - for (std::list::const_iterator aIt = aResults.begin(); - aIt != aResults.end(); ++aIt) { - aModifiedObjects.insert(*aIt); + if (aSketch.get()) { + for (int i = 0; i < aSketch->numberOfSubs(); i++) { + FeaturePtr aFeature = aSketch->subFeature(i); + aModifiedObjects.insert(aFeature); // is necessary to redisplay presentations + std::list aResults = aFeature->results(); + for (std::list::const_iterator aIt = aResults.begin(); + aIt != aResults.end(); ++aIt) { + aModifiedObjects.insert(*aIt); + } } + redisplayObjects(aModifiedObjects); } - redisplayObjects(aModifiedObjects); - myIsNeedUpdateCustomColor = false; + //myIsNeedUpdateCustomColor = false; + } + } + else if (anEventID == Events_Loop::eventByName(EVENT_OBJECT_CREATED)) { + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + PartSet_SketcherReentrantMgr* aReentrantMgr = aModule->sketchReentranceMgr(); + if (aReentrantMgr->isInternalEditActive()) { + std::shared_ptr aUpdMsg = + std::dynamic_pointer_cast(theMessage); + std::set anObjects = aUpdMsg->objects(); + aReentrantMgr->appendCreatedObjects(anObjects); } } - #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER aCurrentInfoStr = getObjectsInfo(myConflictingObjects); qDebug(QString("RESULT: current objects count = %1:%2\n") diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.cpp b/src/PartSet/PartSet_SketcherReentrantMgr.cpp index cab4e9945..488f5660a 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReentrantMgr.cpp @@ -389,9 +389,17 @@ bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection() return !isActiveMgr() || myRestartingMode == RM_None; } -bool PartSet_SketcherReentrantMgr::isInternalEditStarted() const +void PartSet_SketcherReentrantMgr::appendCreatedObjects(const std::set& theObjects) { - return myIsInternalEditOperation; + if (!myIsFlagsBlocked) // we need to collect objects only when launch operation is called + return; + + for (std::set::const_iterator anIt = theObjects.begin(); + anIt != theObjects.end(); ++anIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + if (myCreatedFeatures.find(aFeature) != myCreatedFeatures.end()) + myCreatedFeatures.insert(aFeature); + } } bool PartSet_SketcherReentrantMgr::isActiveMgr() const @@ -618,6 +626,7 @@ void PartSet_SketcherReentrantMgr::resetFlags() myIsInternalEditOperation = false; updateAcceptAllAction(); myRestartingMode = RM_None; + myCreatedFeatures.clear(); } } diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.h b/src/PartSet/PartSet_SketcherReentrantMgr.h index b430c2389..17006c1e4 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.h +++ b/src/PartSet/PartSet_SketcherReentrantMgr.h @@ -101,9 +101,10 @@ public: /// Returns false if the reentrant mode of the operation is not empty. bool canBeCommittedByPreselection(); - /// returns true if an internal edit operation is started - /// \return boolean value - bool isInternalEditStarted() const; + /// Put information about created objects into a cash. It will be processed in + /// restart operation. + /// \param theObjects a list of created objects + void appendCreatedObjects(const std::set& theObjects); private slots: /// SLOT, that is called by a widget activating in the property panel @@ -192,6 +193,7 @@ private: bool myIsValueChangedBlocked; /// blocked flag to avoid circling by value changed FeaturePtr myPreviousFeature; /// feature of the previous operation, which is restarted + std::set myCreatedFeatures; /// list of created features by restart operation FeaturePtr myInternalFeature; QWidget* myInternalWidget; ModuleBase_ModelWidget* myInternalActiveWidget; diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index d82e457a8..0d296dc09 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -689,7 +689,7 @@ void PartSet_WidgetPoint2D::mouseMoved(ModuleBase_IViewWindow* theWindow, QMouse { PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); - if (isEditingMode() || aModule->sketchReentranceMgr()->isInternalEditStarted()) + if (isEditingMode() || aModule->sketchReentranceMgr()->isInternalEditActive()) return; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView()); -- 2.39.2