From 93f0f178b042dba3a741970a383bae997fcdb9bb Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 24 Oct 2018 16:59:16 +0300 Subject: [PATCH] Fix for issue #2718: Fatal error when open study with box rotated, translated and mirrored --- src/Model/Model_AttributeSelection.cpp | 8 ++++---- src/Model/Model_Objects.cpp | 13 ++++++++----- src/Model/Model_ResultPart.cpp | 13 ++++++++++++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 0e95d42a5..6b008ce7c 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -954,17 +954,17 @@ void Model_AttributeSelection::selectSubShape( CenterType aCenterType = theType[0] == 'v' || theType[0] == 'V' ? // only for vertex-type centerTypeByName(aSubShapeName) : NOT_CENTER; std::string aType = aCenterType == NOT_CENTER ? theType : "EDGE"; // search for edge now - TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(GeomAPI_Shape::shapeTypeByStr(theType)); static const GeomShapePtr anEmptyShape; // first iteration is selection by name without center prefix, second - in case of problem, // try with initial name for(int aUseCenter = 1; aUseCenter >= 0; aUseCenter--) { - std::string aSubShapeName = theSubShapeName; if (aUseCenter == 0 && aCenterType != NOT_CENTER) { + aSubShapeName = theSubShapeName; aCenterType = NOT_CENTER; aType = theType; } else if (aUseCenter != 1) continue; + TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(GeomAPI_Shape::shapeTypeByStr(aType)); std::shared_ptr aDoc = std::dynamic_pointer_cast(owner()->document()); @@ -1036,7 +1036,6 @@ void Model_AttributeSelection::selectSubShape( } } } - aSubShapeName = theSubShapeName; } // invalid TDF_Label aSelLab = selectionLabel(); @@ -1473,7 +1472,8 @@ void Model_AttributeSelection::updateInHistory() // to avoid detection of part changes by local selection only AttributeSelectionPtr aSel = std::dynamic_pointer_cast(*aRef); - if (aSel.get() && !aSel->value()->isSame(aSel->context()->shape())) + if (aSel.get() && aSel->value().get() && + !aSel->value()->isSame(aSel->context()->shape())) continue; FeaturePtr aRefFeat = std::dynamic_pointer_cast((*aRef)->owner()); diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index e6116ebbe..100ec495f 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -1872,11 +1872,14 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set& t if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) { aNewBody = createBody(theFeature->data(), aResIndex); } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) { - std::shared_ptr aNewP = createPart(theFeature->data(), aResIndex); - theFeature->setResult(aNewP, aResIndex); - if (!aNewP->partDoc().get()) - // create the part result: it is better to restore the previous result if it is possible - theFeature->execute(); + if (aResIndex <= theFeature->results().size()) { // to avoid crash if previous execute + // for index = 0 erases result + std::shared_ptr aNewP = createPart(theFeature->data(), aResIndex); + theFeature->setResult(aNewP, aResIndex); + if (!aNewP->partDoc().get()) + // create the part result: it is better to restore the previous result if it is possible + theFeature->execute(); + } } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) { ResultConstructionPtr aConstr = createConstruction(theFeature->data(), aResIndex); if (!aConstr->updateShape()) diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 255f5e380..c4f6f309e 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -169,6 +169,8 @@ std::shared_ptr Model_ResultPart::shape() { std::shared_ptr aResult(new GeomAPI_Shape); if (myShape.IsNull()) { // shape is not produced yet, create it + SessionPtr aMgr = ModelAPI_Session::get(); + bool aToSendUpdate = aMgr->isOperation(); // inside of operation may send an update evnet if (myTrsf.get()) { // get shape of the base result and apply the transformation ResultPtr anOrigResult = baseRef(); std::shared_ptr anOrigShape = anOrigResult->shape(); @@ -180,6 +182,10 @@ std::shared_ptr Model_ResultPart::shape() aResult->setImpl(new TopoDS_Shape(aShape)); } } + if (!myShape.IsNull() && aToSendUpdate) { + static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); + ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent); + } return aResult; } else { DocumentPtr aDoc = Model_ResultPart::partDoc(); @@ -205,9 +211,14 @@ std::shared_ptr Model_ResultPart::shape() } } } + if (!myShape.IsNull() && aToSendUpdate) { + static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); + ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent); + } } - if (!myShape.IsNull()) + if (!myShape.IsNull()) { aResult->setImpl(new TopoDS_Shape(myShape)); + } return aResult; } -- 2.39.2