X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelectionList.cpp;h=3b67df9eb0a9063e23a7874fde696432fdaa9857;hb=2e39226506e4b82f6ae5dcc26e776571801b1555;hp=0643a520bb91a23e620d37c64fefe8413ba3da90;hpb=7821a0fabd7304b201ca2d2dcb21d88ed86ec9ba;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 0643a520b..3b67df9eb 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -13,11 +13,24 @@ #include #include +#include +#include +#include +#include + using namespace std; void Model_AttributeSelectionList::append( const ResultPtr& theContext, const std::shared_ptr& theSubShape) { + // do not use the degenerated edge as a shape, a list is not incremented in this case + if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) { + const TopoDS_Shape& aSubShape = theSubShape->impl(); + if (aSubShape.ShapeType() == TopAbs_EDGE && BRep_Tool::Degenerated(TopoDS::Edge(aSubShape))) { + return; + } + } + int aNewTag = mySize->Get() + 1; TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); @@ -26,6 +39,7 @@ void Model_AttributeSelectionList::append( if (owner()) { aNewAttr->setObject(owner()); } + aNewAttr->setID(id()); mySize->Set(aNewTag); aNewAttr->setValue(theContext, theSubShape); owner()->data()->sendAttributeUpdated(this); @@ -42,21 +56,7 @@ void Model_AttributeSelectionList::append(std::string theNamingName) aNewAttr->setObject(owner()); } mySize->Set(aNewTag); - TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)selectionType(); - string aTypeName; - switch(aType) { - case TopAbs_VERTEX: aTypeName = "VERT"; break; - case TopAbs_EDGE: aTypeName = "EDGE"; break; - case TopAbs_WIRE: aTypeName = "WIRE"; break; - case TopAbs_FACE: aTypeName = "FACE"; break; - case TopAbs_SHELL: aTypeName = "SHEL"; break; - case TopAbs_SOLID: aTypeName = "SOLD"; break; - case TopAbs_COMPOUND: aTypeName = "COMP"; break; - case TopAbs_COMPSOLID: aTypeName = "COMS"; break; - default: - return; // invalid case => empty new attribute - }; - aNewAttr->selectSubShape(aTypeName, theNamingName); + aNewAttr->selectSubShape(selectionType(), theNamingName); owner()->data()->sendAttributeUpdated(this); } @@ -65,14 +65,14 @@ int Model_AttributeSelectionList::size() return mySize->Get(); } -int Model_AttributeSelectionList::selectionType() +const std::string Model_AttributeSelectionList::selectionType() const { - return (int) mySelectionType->Get(); + return TCollection_AsciiString(mySelectionType->Get()).ToCString(); } -void Model_AttributeSelectionList::setSelectionType(int theType) +void Model_AttributeSelectionList::setSelectionType(const std::string& theType) { - mySelectionType->Set((double) theType); + mySelectionType->Set(theType.c_str()); } std::shared_ptr @@ -102,13 +102,21 @@ void Model_AttributeSelectionList::clear() } } +bool Model_AttributeSelectionList::isInitialized() +{ + if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo + return false; + } + return ModelAPI_AttributeSelectionList::isInitialized(); +} + Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) { myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True; if (!myIsInitialized) { mySize = TDataStd_Integer::Set(theLabel, 0); - mySelectionType = TDataStd_Real::Set(theLabel, 0); + mySelectionType = TDataStd_Comment::Set(theLabel, ""); } else { // recollect mySubs - theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType); + theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType); } }