X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelection.cpp;h=232ff61b558ead55e47049e9d23208513d06c975;hb=a83e22046c5fb877969fa8879e42491d4054f198;hp=d85df7d3e99c453da2e0aa40f427d3baa3c80e7e;hpb=6d1d824304c048a69924a836c4e6fa74d301b95e;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index d85df7d3e..232ff61b5 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,7 @@ #include #include #include +#include using namespace std; //#define DEB_NAMING 1 #ifdef DEB_NAMING @@ -122,7 +124,6 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, if (theContext->groupName() == ModelAPI_ResultBody::group()) { // do not select the whole shape for body:it is already must be in the data framework // equal and null selected objects mean the same: object is equal to context, - // TODO: synchronize with GUI later that it must be null always if (theContext->shape().get() && (theContext->shape()->isEqual(theSubShape) || !theSubShape.get())) { aSelLab.ForgetAllAttributes(true); @@ -135,15 +136,30 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, // to sub, so the whole result is selected aSelLab.ForgetAllAttributes(true); TDataStd_UAttribute::Set(aSelLab, kCONSTUCTION_SIMPLE_REF_ID); - // For correct naming selection, put the shape into the naming structure. - // It seems sub-shapes are not needed: only this shape is (and can be ) selected. - TNaming_Builder aBuilder(aSelLab); - aBuilder.Generated(theContext->shape()->impl()); - std::shared_ptr aMyDoc = - std::dynamic_pointer_cast(owner()->document()); - std::string aName = theContext->data()->name(); - aMyDoc->addNamingName(aSelLab, aName); - TDataStd_Name::Set(aSelLab, aName.c_str()); + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(theContext); + if (aConstruction->isInfinite()) { + // For correct naming selection, put the shape into the naming structure. + // It seems sub-shapes are not needed: only this shape is (and can be ) selected. + TNaming_Builder aBuilder(aSelLab); + aBuilder.Generated(theContext->shape()->impl()); + std::shared_ptr aMyDoc = + std::dynamic_pointer_cast(owner()->document()); + std::string aName = theContext->data()->name(); + aMyDoc->addNamingName(aSelLab, aName); + TDataStd_Name::Set(aSelLab, aName.c_str()); + } else { // for sketch the naming is needed in DS + BRep_Builder aCompoundBuilder; + TopoDS_Compound aComp; + aCompoundBuilder.MakeCompound(aComp); + for(int a = 0; a < aConstruction->facesNum(); a++) { + TopoDS_Shape aFace = aConstruction->face(a)->impl(); + aCompoundBuilder.Add(aComp, aFace); + } + std::shared_ptr aShape(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(aComp)); + selectConstruction(theContext, aShape); + } } else { selectConstruction(theContext, theSubShape); } @@ -184,7 +200,6 @@ std::shared_ptr Model_AttributeSelection::value() return aResult; // empty result } if (aSelLab.IsAttribute(kPART_REF_ID)) { - /* TODO: implement used text here ResultPartPtr aPart = std::dynamic_pointer_cast(context()); if (!aPart.get() || !aPart->isActivated()) return std::shared_ptr(); // postponed naming needed @@ -192,11 +207,12 @@ std::shared_ptr Model_AttributeSelection::value() if (selectionLabel().FindAttribute(TDataStd_Integer::GetID(), anIndex)) { return aPart->selectionValue(anIndex->Get()); } + /* Handle(TDataStd_Name) aName; if (!selectionLabel().FindAttribute(TDataStd_Name::GetID(), aName)) { return std::shared_ptr(); // something is wrong } - return aPart->shapeInPart(TCollection_AsciiString(aName).ToCString()); + return aPart->shapeInPart(TCollection_AsciiString(aName->Get()).ToCString()); */ } @@ -301,8 +317,16 @@ TDF_LabelMap& Model_AttributeSelection::scope() std::list > allFeatures = aMyDoc->allFeatures(); std::list >::iterator aFIter = allFeatures.begin(); bool aMePassed = false; - std::shared_ptr aComposite = + CompositeFeaturePtr aComposite = std::dynamic_pointer_cast(owner()); + FeaturePtr aFeature = std::dynamic_pointer_cast(owner()); + CompositeFeaturePtr aCompositeOwner, aCompositeOwnerOwner; + if (aFeature.get()) { + aCompositeOwner = ModelAPI_Tools::compositeOwner(aFeature); + if (aCompositeOwner.get()) { + aCompositeOwnerOwner = ModelAPI_Tools::compositeOwner(aCompositeOwner); + } + } for(; aFIter != allFeatures.end(); aFIter++) { if (*aFIter == owner()) { // the left features are created later (except subs of composite) aMePassed = true; @@ -313,7 +337,11 @@ TDF_LabelMap& Model_AttributeSelection::scope() if (aComposite->isSub(*aFIter)) isInScope = true; } - if (aFIter->get() && (*aFIter)->data()->isValid()) { + // remove the composite-owner of this feature (sketch in extrusion-cut) + if (isInScope && (aCompositeOwner == *aFIter || aCompositeOwnerOwner == *aFIter)) + isInScope = false; + + if (isInScope && aFIter->get() && (*aFIter)->data()->isValid()) { TDF_Label aFeatureLab = std::dynamic_pointer_cast( (*aFIter)->data())->label().Father(); TDF_ChildIDIterator aNSIter(aFeatureLab, TNaming_NamedShape::GetID(), 1); @@ -363,6 +391,21 @@ bool Model_AttributeSelection::update() return setInvalidIfFalse(aSelLab, aContext->shape() && !aContext->shape()->isNull()); } if (aSelLab.IsAttribute(kCONSTUCTION_SIMPLE_REF_ID)) { // it is just reference to construction, not sub-shape + // if there is a sketch, the sketch-naming must be updated + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aContext); + if (!aConstruction->isInfinite()) { + BRep_Builder aCompoundBuilder; + TopoDS_Compound aComp; + aCompoundBuilder.MakeCompound(aComp); + for(int a = 0; a < aConstruction->facesNum(); a++) { + TopoDS_Shape aFace = aConstruction->face(a)->impl(); + aCompoundBuilder.Add(aComp, aFace); + } + std::shared_ptr aShape(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(aComp)); + selectConstruction(aContext, aShape); + } return setInvalidIfFalse(aSelLab, aContext->shape() && !aContext->shape()->isNull()); } @@ -445,7 +488,7 @@ bool Model_AttributeSelection::update() } } } - double aBestFound = 0; // best percentage of found edges + int aBestFound = 0; // best number of found edges (not percentage: issue 1019) int aBestOrient = 0; // for the equal "BestFound" additional parameter is orientation for(int aFaceIndex = 0; aFaceIndex < aConstructionContext->facesNum(); aFaceIndex++) { int aFound = 0, aNotFound = 0, aSameOrientation = 0; @@ -474,12 +517,9 @@ bool Model_AttributeSelection::update() } } if (aFound + aNotFound != 0) { - double aSum = aFound + aNotFound; - // aSameOrientation: if edges are same, take where orientation is better - double aPercentage = double(aFound) / double(aFound + aNotFound); - if (aPercentage > aBestFound || - (aPercentage == aBestFound && aSameOrientation > aBestOrient)) { - aBestFound = aPercentage; + if (aFound > aBestFound || + (aFound == aBestFound && aSameOrientation > aBestOrient)) { + aBestFound = aFound; aBestOrient = aSameOrientation; aNewSelected = aConstructionContext->face(aFaceIndex); } @@ -591,11 +631,9 @@ void Model_AttributeSelection::selectBody( } TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl() : aContext; /// fix for issue 411: result modified shapes must not participate in this selection mechanism - /* FeaturePtr aFeatureOwner = std::dynamic_pointer_cast(owner()); if (aFeatureOwner.get()) aFeatureOwner->eraseResults(); - */ if (!aContext.IsNull()) { aSel.Select(aNewShape, aContext); } @@ -729,7 +767,7 @@ void Model_AttributeSelection::selectConstruction( if (allCurves.Contains(aCurve)) { int anID = aComposite->subFeatureId(a); aRefs->Add(anID); - if (aShapeType != TopAbs_EDGE) { // face nneds the sub-edges on sub-labels + if (aShapeType != TopAbs_EDGE) { // face needs the sub-edges on sub-labels // add edges to sub-label to support naming for edges selection TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); for(; anEdgeExp.More(); anEdgeExp.Next()) { @@ -835,6 +873,24 @@ void Model_AttributeSelection::selectSubShape( { if(theSubShapeName.empty() || theType.empty()) return; + // check this is Part-name: 2 delimiters in the name + std::size_t aPartEnd = theSubShapeName.find('/'); + if (aPartEnd != string::npos && aPartEnd != theSubShapeName.rfind('/')) { + std::string aPartName = theSubShapeName.substr(0, aPartEnd); + ObjectPtr aFound = 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); + string aNameInPart = theSubShapeName.substr(aPartEnd + 1); + int anIndex; + std::shared_ptr aSelected = aPart->shapeInPart(aNameInPart, theType, anIndex); + if (aSelected.get()) { + setValue(aPart, aSelected); + TDataStd_Integer::Set(selectionLabel(), anIndex); + return; + } + } + } + Model_SelectionNaming aSelNaming(selectionLabel()); std::shared_ptr aDoc = std::dynamic_pointer_cast(owner()->document());