X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Data.cpp;h=82cc259187f241baf8d61af17ecd4be53b79251a;hb=f7a976b98d8cadadcb54a61e42ddb66e00759689;hp=0ae7a75aa3f3caf3e507ac2a8b57d2e725593744;hpb=4b116f1c2ff374e8c5cc5afe2b64eb1fe2a8abd3;p=modules%2Fshaper.git diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 0ae7a75aa..82cc25918 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: Model_Data.hxx // Created: 21 Mar 2014 // Author: Mikhail PONIKAROV @@ -13,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +29,9 @@ #include #include +#include +#include +#include #include @@ -33,7 +39,7 @@ // TDataStd_Name - name of the object // TDataStd_Integer - state of the object execution -Model_Data::Model_Data() +Model_Data::Model_Data() : mySendAttributeUpdated(true) { } @@ -64,8 +70,9 @@ void Model_Data::setName(const std::string& theName) } } -void Model_Data::addAttribute(const std::string& theID, const std::string theAttrType) +AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType) { + AttributePtr aResult; TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1); ModelAPI_Attribute* anAttr = 0; if (theAttrType == ModelAPI_AttributeDocRef::type()) { @@ -88,6 +95,8 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt anAttr = new Model_AttributeRefAttr(anAttrLab); } else if (theAttrType == ModelAPI_AttributeRefList::type()) { anAttr = new Model_AttributeRefList(anAttrLab); + } else if (theAttrType == ModelAPI_AttributeIntArray::type()) { + anAttr = new Model_AttributeIntArray(anAttrLab); } // create also GeomData attributes here because only here the OCAF strucure is known else if (theAttrType == GeomData_Point::type()) { @@ -98,12 +107,14 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt anAttr = new GeomData_Point2D(anAttrLab); } if (anAttr) { - myAttrs[theID] = std::shared_ptr(anAttr); + aResult = std::shared_ptr(anAttr); + myAttrs[theID] = aResult; anAttr->setObject(myObject); anAttr->setID(theID); } else { Events_Error::send("Can not create unknown type of attribute " + theAttrType); } + return aResult; } // macro for gthe generic returning of the attribute by the ID @@ -128,6 +139,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist); +GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray); std::shared_ptr Model_Data::attribute(const std::string& theID) { @@ -195,12 +207,17 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr) if (theAttr->isArgument()) { static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent); - if (myObject) { + if (mySendAttributeUpdated && myObject) { myObject->attributeChanged(theAttr->id()); } } } +void Model_Data::blockSendAttributeUpdated(const bool theBlock) +{ + mySendAttributeUpdated = !theBlock; +} + void Model_Data::erase() { if (!myLab.IsNull()) @@ -265,7 +282,6 @@ void Model_Data::referencesToObjects( std::shared_ptr aRef = std::dynamic_pointer_cast< ModelAPI_AttributeReference>(anAttr->second); aReferenced.push_back(aRef->value()); - theRefs.push_back(std::pair >(anAttr->first, aReferenced)); } else if (aType == ModelAPI_AttributeRefAttr::type()) { // reference to attribute or object std::shared_ptr aRef = std::dynamic_pointer_cast< ModelAPI_AttributeRefAttr>(anAttr->second); @@ -291,3 +307,36 @@ 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); + } + Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(); // no relocation, empty map + anAttrIter.Value()->Paste(aTargetAttr, aRelocTable); + } + // 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); + // make initialized the initialized attributes + std::map >::iterator aMyIter = myAttrs.begin(); + for(; aMyIter != myAttrs.end(); aMyIter++) { + if (aMyIter->second->isInitialized()) { + theTarget->attribute(aMyIter->first)->setInitialized(); + } + } +}