X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Data.cpp;h=a47d95c2fa49b1db4321432f53b7515651e303f6;hb=524d88b5c908ef4995ddd2b3975a4333a6db558d;hp=10d11678d642420f5bde838baabe2072dce78114;hpb=3c987a8d1b88765224e3ac1388afb91eae17e4d3;p=modules%2Fshaper.git diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 10d11678d..a47d95c2f 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -35,6 +35,9 @@ #include #include #include +#include +#include + #include #include #include @@ -43,26 +46,22 @@ #include #include #include -#include #include #include +#include #include #include +#include #include #include #include #include #include -#include #include -#include -#include -#include #include -#include #include @@ -78,7 +77,7 @@ static const int kFlagDisplayed = 1; static const int kFlagDeleted = 2; // TDataStd_Integer - 0 if the name of the object is generated automatically, // otherwise the name is defined by user -Standard_GUID kUSER_DEFINED_NAME("9c694d18-a83c-4a56-bc9b-8020628a8244"); +static const Standard_GUID kUSER_DEFINED_NAME("9c694d18-a83c-4a56-bc9b-8020628a8244"); // invalid data const static std::shared_ptr kInvalid(new Model_Data()); @@ -86,6 +85,9 @@ const static std::shared_ptr kInvalid(new Model_Data()); static const Standard_GUID kGroupAttributeGroupID("df64ea4c-fc42-4bf8-ad7e-08f7a54bf1b8"); static const Standard_GUID kGroupAttributeID("ebdcb22a-e045-455b-9a7f-cfd38d68e185"); +// id of attribute to store the version of the feature +static const Standard_GUID kVERSION_ID("61cdb78a-1ba7-4942-976f-63bea7f4a2b1"); + Model_Data::Model_Data() : mySendAttributeUpdated(true), myWasChangedButBlocked(false) { @@ -159,6 +161,24 @@ bool Model_Data::hasUserDefinedName() const return shapeLab().IsAttribute(kUSER_DEFINED_NAME); } +std::string Model_Data::version() +{ + Handle(TDataStd_Name) aVersionAttr; + std::string aVersion; + if (shapeLab().FindAttribute(kVERSION_ID, aVersionAttr)) + aVersion = TCollection_AsciiString(aVersionAttr->Get()).ToCString(); + return aVersion; +} + +void Model_Data::setVersion(const std::string& theVersion) +{ + Handle(TDataStd_Name) aVersionAttr; + std::string aVersion; + if (!shapeLab().FindAttribute(kVERSION_ID, aVersionAttr)) + aVersionAttr = TDataStd_Name::Set(shapeLab(), kVERSION_ID, TCollection_ExtendedString()); + aVersionAttr->Set(theVersion.c_str()); +} + AttributePtr Model_Data::addAttribute( const std::string& theID, const std::string theAttrType, const int theIndex) { @@ -220,7 +240,10 @@ AttributePtr Model_Data::addAttribute( } anAttribute->myIsInitialized = anAllInitialized; anAttr = anAttribute; + } else if (theAttrType == GeomData_Point2DArray::typeId()) { + anAttr = new GeomData_Point2DArray(anAttrLab); } + if (anAttr) { aResult = std::shared_ptr(anAttr); myAttrs[theID] = std::pair(aResult, anAttrIndex); @@ -434,7 +457,8 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr) } } else { // trim: need to redisplay or set color in the python script - if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color")) { + if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color" || + theAttr->id() == "Transparency" || theAttr->id() == "Deflection")) { static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent); } @@ -797,37 +821,10 @@ void Model_Data::referencesToObjects( } } -/// makes copy of all attributes on the given label and all sub-labels -static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) { - TDF_AttributeIterator anAttrIter(theSource); - for(; anAttrIter.More(); anAttrIter.Next()) { - Handle(TDF_Attribute) aTargetAttr; - if (!theDestination.FindAttribute(anAttrIter.Value()->ID(), aTargetAttr)) { - // create a new attribute if not yet exists in the destination - aTargetAttr = anAttrIter.Value()->NewEmpty(); - theDestination.AddAttribute(aTargetAttr); - } - // no special relocation, empty map, but self-relocation is on: copy references w/o changes - Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(Standard_True); - anAttrIter.Value()->Paste(aTargetAttr, aRelocTable); - // an exception: if a source reference refers itself, a copy must also refer itself - if (aTargetAttr->ID() == TDF_Reference::GetID()) { - Handle(TDF_Reference) aTargetRef = Handle(TDF_Reference)::DownCast(aTargetAttr); - if (aTargetRef->Get().IsEqual(anAttrIter.Value()->Label())) - aTargetRef->Set(aTargetRef->Label()); - } - } - // copy the sub-labels content - TDF_ChildIterator aSubLabsIter(theSource); - for(; aSubLabsIter.More(); aSubLabsIter.Next()) { - copyAttrs(aSubLabsIter.Value(), theDestination.FindChild(aSubLabsIter.Value().Tag())); - } -} - void Model_Data::copyTo(std::shared_ptr theTarget) { TDF_Label aTargetRoot = std::dynamic_pointer_cast(theTarget)->label(); - copyAttrs(myLab, aTargetRoot); + Model_Tools::copyAttrs(myLab, aTargetRoot); // reinitialize Model_Attributes by TDF_Attributes set std::shared_ptr aTData = std::dynamic_pointer_cast(theTarget); aTData->myAttrs.clear();