From: mpv Date: Wed, 31 Oct 2018 17:43:42 +0000 (+0300) Subject: Fix for crash in D:\tmp\clothespin.py : support selection of sub-shapes in Part-results. X-Git-Tag: End2018~221 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8588356f81c947d341405d47403f232f0b98a46f;p=modules%2Fshaper.git Fix for crash in D:\tmp\clothespin.py : support selection of sub-shapes in Part-results. --- diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 0c07f092e..434376735 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -705,51 +705,13 @@ bool Model_AttributeSelection::update() return setInvalidIfFalse(aSelLab, false); // unknown case } -/// integer that contains the tag number of external construction shape naming -static Standard_GUID kEXTERNAL_CONSTRUCTION_TAG("f7d0726f-e848-4d22-9101-def16d0eff2c"); - -void Model_AttributeSelection::storeExternalConstruction( - const ResultConstructionPtr& theConstruction, const GeomShapePtr& theSubShape) -{ - std::string aName = namingName(); - if (aName.empty()) // unknown error - return; - std::shared_ptr aMyDoc = - std::dynamic_pointer_cast(owner()->document()); - TDF_Label anExternalLab = aMyDoc->extConstructionsLabel(); - Handle(TDataStd_Integer) anExtTag; - if (selectionLabel().FindAttribute(kEXTERNAL_CONSTRUCTION_TAG, anExtTag)) { - anExternalLab = anExternalLab.FindChild(anExtTag->Get()); // use existing label - } else { - // search label with the same name - TDF_ChildIDIterator aNamesIter(anExternalLab, TDataStd_Name::GetID()); - for(; aNamesIter.More(); aNamesIter.Next()) { - if (aName == TCollection_AsciiString(Handle(TDataStd_Name)::DownCast( - aNamesIter.Value())->Get()).ToCString()) { - anExternalLab = aNamesIter.Value()->Label(); - break; - } - } - if (aNamesIter.More()) { - } else { - anExternalLab = anExternalLab.NewChild(); // create new label - TDataStd_Integer::Set(selectionLabel(), kEXTERNAL_CONSTRUCTION_TAG, - anExternalLab.Tag()); // store this tag in the data model - } - } - anExternalLab.ForgetAllAttributes(); - TopoDS_Shape aSubShape = theSubShape->impl(); - TNaming_Builder aBuilder(anExternalLab); - aBuilder.Generated(aSubShape); -} - void Model_AttributeSelection::selectBody( const ResultPtr& theContext, const std::shared_ptr& theSubShape) { // perform the selection TopoDS_Shape aContext; - ResultPtr aBody = std::dynamic_pointer_cast(theContext);//myRef.value() + ResultPtr aBody = std::dynamic_pointer_cast(theContext); if (aBody) { aContext = aBody->shape()->impl(); } else { @@ -767,7 +729,9 @@ void Model_AttributeSelection::selectBody( TDF_Label aSelLab = selectionLabel(); TopoDS_Shape aNewSub = theSubShape->impl(); FeaturePtr aFeatureOwner = std::dynamic_pointer_cast(owner()); - if (aFeatureOwner->document() != theContext->document()) { // reference to the sketch face + if (aFeatureOwner->document() != theContext->document() && + theContext->groupName() == ModelAPI_ResultConstruction::group()) {// condition for parts + // reference to the sketch face if (theSubShape->shapeType() == GeomAPI_Shape::FACE || theSubShape->shapeType() == GeomAPI_Shape::WIRE) { // sketch face or sketch face wire ResultConstructionPtr aConstr = @@ -793,7 +757,6 @@ void Model_AttributeSelection::selectBody( if (aFaceIndex >= 0) { TDataStd_Integer::Set(aSelLab, theSubShape->shapeType() == GeomAPI_Shape::FACE ? kEXT_SKETCH_FACE : kEXT_SKETCH_WIRE, aFaceIndex); // store index of the face - //storeExternalConstruction(aConstr, theSubShape); return; } } else if (theSubShape->shapeType() == GeomAPI_Shape::EDGE ||// sketch result edge (full one) @@ -1058,12 +1021,25 @@ void Model_AttributeSelection::selectSubShape( owner()->document()->objectByName(ModelAPI_ResultPart::group(), aPartName); if (aFound.get()) { // found such part, so asking it for the name ResultPartPtr aPart = std::dynamic_pointer_cast(aFound); - aDoc = std::dynamic_pointer_cast(aPart->partDoc()); - aSubShapeName = aSubShapeName.substr(aPartEnd +1); - if (aSubShapeName.empty()) { // the whole Part result + std::string aNameInPart = aSubShapeName.substr(aPartEnd + 1); + if (aNameInPart.empty()) { // whole part setValue(aPart, anEmptyShape); return; } + int anIndex; + std::shared_ptr aSelected = + aPart->shapeInPart(aNameInPart, aType, anIndex); + if (aSelected.get()) { + if (aCenterType != NOT_CENTER) { + if (!aSelected->isEdge()) + continue; + std::shared_ptr aSelectedEdge(new GeomAPI_Edge(aSelected)); + setValueCenter(aPart, aSelectedEdge, aCenterType); + } else + setValue(aPart, aSelected); + TDataStd_Integer::Set(selectionLabel(), anIndex); + return; + } } } } @@ -1319,16 +1295,9 @@ void Model_AttributeSelection::computeValues( { bool aWasWholeContext = theValShape.IsNull(); if (aWasWholeContext) { - //theShapes.Append(theValShape); - //return; theValShape = theOldContext->shape()->impl(); } - //TopoDS_Shape anOldContShape = theOldContext->shape()->impl(); TopoDS_Shape aNewContShape = theNewContext->shape()->impl(); - //if (anOldContShape.IsSame(theValShape)) { // full context shape substituted by new full context - //theShapes.Append(aNewContShape); - //return; - //} // if a new value is unchanged in the new context, do nothing: value is correct TopExp_Explorer aSubExp(aNewContShape, theValShape.ShapeType()); for(; aSubExp.More(); aSubExp.Next()) { @@ -1466,8 +1435,6 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr aModifIter.Label().FindAttribute(TNaming_NamedShape::GetID(), aNewNS); if (aNewNS->Evolution() == TNaming_MODIFY || aNewNS->Evolution() == TNaming_GENERATED) { aResults.insert(aModifierObj); - //TNaming_Iterator aPairIter(aNewNS); - //aResContShapes.Append(aPairIter.NewShape()); aResContShapes.Append(aModifierObj->shape()->impl()); } else if (aNewNS->Evolution() == TNaming_DELETE) { // a shape was deleted => result is empty aResults.insert(ResultPtr()); diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 8759f8d58..98e35767e 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -31,7 +31,6 @@ class Model_AttributeSelectionList; class Model_Document; -class ModelAPI_ResultConstruction; /**\class Model_AttributeSelection * \ingroup DataModel @@ -158,12 +157,6 @@ protected: /// Returns theType type of the center, or NOT_CENTER if it is not. std::shared_ptr internalValue(CenterType& theType); - /// stores the naming structure of external construction (sketch element) in the data - /// tree of this document with name equal to selection-name in external document - void storeExternalConstruction( - const std::shared_ptr& theConstruction, - const std::shared_ptr& theSubShape); - /// Performs the selection for the body result (TNaming selection) virtual void selectBody( const ResultPtr& theContext, const std::shared_ptr& theSubShape);