From 9072f330373ef9198093c9d3d2164bf54614b36c Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 27 Apr 2017 15:31:28 +0300 Subject: [PATCH] Set of fixes to avoid crashes on invalid document from issue #2147 opening. --- src/BuildPlugin/BuildPlugin_Validators.cpp | 6 +++++- src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp | 5 ++++- src/Model/Model_Document.cpp | 3 +++ src/ModelHighAPI/ModelHighAPI_Services.cpp | 7 +++++++ src/ModelHighAPI/ModelHighAPI_Services.h | 8 ++++++++ src/PythonAPI/model/services/__init__.py | 1 + src/PythonAddons/macros/box/feature.py | 3 ++- 7 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index fc93bc7df..f82862cbb 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -184,6 +184,10 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptrvalue(anIndex); GeomShapePtr aShape = aSelection->value(); if(!aShape.get()) { + if (!aSelection->context()) { + theError = "Objects are not selected."; + return false; + } aShape = aSelection->context()->shape(); } for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { @@ -193,7 +197,7 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptrsize() && aValid; i++) { std::shared_ptr aSelAttribute = aCurSelList->value(i); ResultPtr aResult = aSelAttribute->context(); - if (isPartSetDocument) // PartSet document: Result Part is valid + if (!aResult) { + theError = "Invalid selection."; + return false; + } if (isPartSetDocument) // PartSet document: Result Part is valid aValid = aResult->groupName() == ModelAPI_ResultPart::group(); else { // Part document: Result CompSolid is valid aValid = aResult->groupName() == ModelAPI_ResultBody::group(); diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 10d4605f2..f73b93a74 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -590,6 +590,8 @@ bool Model_Document::finishOperation() Events_Loop::loop()->send(aFinishMsg); } + // for open of document with primitive box inside (finish transaction in initAttributes) + bool aWasActivatedFlushes = aLoop->activateFlushes(true); while(aLoop->hasGrouppedEvent(kCreatedEvent) || aLoop->hasGrouppedEvent(kUpdatedEvent) || aLoop->hasGrouppedEvent(kRedispEvent) || aLoop->hasGrouppedEvent(kDeletedEvent)) { aLoop->flush(kCreatedEvent); @@ -597,6 +599,7 @@ bool Model_Document::finishOperation() aLoop->flush(kRedispEvent); aLoop->flush(kDeletedEvent); } + aLoop->activateFlushes(aWasActivatedFlushes); // to avoid "updated" message appearance by updater //aLoop->clear(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); diff --git a/src/ModelHighAPI/ModelHighAPI_Services.cpp b/src/ModelHighAPI/ModelHighAPI_Services.cpp index db14a4601..5e0635579 100644 --- a/src/ModelHighAPI/ModelHighAPI_Services.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Services.cpp @@ -102,6 +102,13 @@ void apply() aSession->startOperation(); } +void updateFeatures() +{ + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); +} + //-------------------------------------------------------------------------------------- void undo() { diff --git a/src/ModelHighAPI/ModelHighAPI_Services.h b/src/ModelHighAPI/ModelHighAPI_Services.h index b02e778e9..03a244cbc 100644 --- a/src/ModelHighAPI/ModelHighAPI_Services.h +++ b/src/ModelHighAPI/ModelHighAPI_Services.h @@ -75,6 +75,14 @@ void end(); MODELHIGHAPI_EXPORT void apply(); +/** Executes features, created or updated before. + * + * This method flushes creation and update events in order to make all + * features up to date. + */ +MODELHIGHAPI_EXPORT +void updateFeatures(); + /// Roll-back the data structure to the previous control point. MODELHIGHAPI_EXPORT void undo(); diff --git a/src/PythonAPI/model/services/__init__.py b/src/PythonAPI/model/services/__init__.py index cf9636106..8c15e89ec 100644 --- a/src/PythonAPI/model/services/__init__.py +++ b/src/PythonAPI/model/services/__init__.py @@ -5,6 +5,7 @@ from ModelHighAPI import moduleDocument, activeDocument from ModelHighAPI import defaultPlane, standardPlane from ModelHighAPI import begin, end from ModelHighAPI import apply as do +from ModelHighAPI import updateFeatures from ModelHighAPI import undo, redo from ModelHighAPI import reset from ModelHighAPI import ModelHighAPI_Selection as selection diff --git a/src/PythonAddons/macros/box/feature.py b/src/PythonAddons/macros/box/feature.py index 8c580cdc8..8b9e486e1 100644 --- a/src/PythonAddons/macros/box/feature.py +++ b/src/PythonAddons/macros/box/feature.py @@ -82,7 +82,8 @@ class BoxFeature(model.Feature): self.base.setPerpendicular(line[0], line[3]) # execute sketch - model.do() + mypart.setCurrentFeature(self.base.feature(), False) + model.updateFeatures() # Creating the extrusion (the box) at default size # A box result -- 2.39.2