1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Data.hxx
4 // Created: 21 Mar 2014
5 // Author: Mikhail PONIKAROV
7 #include <Model_Data.h>
8 #include <Model_AttributeDocRef.h>
9 #include <Model_AttributeInteger.h>
10 #include <Model_AttributeDouble.h>
11 #include <Model_AttributeReference.h>
12 #include <Model_AttributeRefAttr.h>
13 #include <Model_AttributeRefList.h>
14 #include <Model_AttributeBoolean.h>
15 #include <Model_AttributeString.h>
16 #include <Model_AttributeSelection.h>
17 #include <Model_AttributeSelectionList.h>
18 #include <Model_AttributeIntArray.h>
19 #include <Model_Events.h>
20 #include <Model_Expression.h>
21 #include <ModelAPI_Feature.h>
22 #include <ModelAPI_Result.h>
23 #include <ModelAPI_ResultParameter.h>
24 #include <ModelAPI_Validator.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_ResultPart.h>
27 #include <ModelAPI_ResultCompSolid.h>
28 #include <ModelAPI_Tools.h>
29 #include <Model_Validator.h>
31 #include <GeomDataAPI_Point.h>
32 #include <GeomDataAPI_Point2D.h>
34 #include <GeomData_Point.h>
35 #include <GeomData_Point2D.h>
36 #include <GeomData_Dir.h>
37 #include <Events_Loop.h>
38 #include <Events_Error.h>
40 #include <TDataStd_Name.hxx>
41 #include <TDataStd_AsciiString.hxx>
42 #include <TDataStd_IntegerArray.hxx>
43 #include <TDF_AttributeIterator.hxx>
44 #include <TDF_ChildIterator.hxx>
45 #include <TDF_RelocationTable.hxx>
46 #include <TColStd_HArray1OfByte.hxx>
51 // TDataStd_Name - name of the object
52 // TDataStd_IntegerArray - state of the object execution, transaction ID of update
53 // TDataStd_BooleanArray - array of flags of this data:
54 // 0 - is in history or not
55 static const int kFlagInHistory = 0;
56 // 1 - is displayed or not
57 static const int kFlagDisplayed = 1;
58 // 2 - is deleted (for results) or not
59 static const int kFlagDeleted = 2;
62 const static std::shared_ptr<ModelAPI_Data> kInvalid(new Model_Data());
64 Model_Data::Model_Data() : mySendAttributeUpdated(true), myWasChangedButBlocked(false)
68 void Model_Data::setLabel(TDF_Label theLab)
71 // set or get the default flags
72 if (!myLab.FindAttribute(TDataStd_BooleanArray::GetID(), myFlags)) {
73 // set default values if not found
74 myFlags = TDataStd_BooleanArray::Set(myLab, 0, 2);
75 myFlags->SetValue(kFlagInHistory, Standard_True); // is in history by default is true
76 myFlags->SetValue(kFlagDisplayed, Standard_True); // is displayed by default is true
77 myFlags->SetValue(kFlagDeleted, Standard_False); // is deleted by default is false
78 } else if (myFlags->Length() != 3) { // for old formats support
79 Standard_Boolean aFlag0 = myFlags->Upper() >= 0 ? myFlags->Value(0) : Standard_True;
80 Standard_Boolean aFlag1 = myFlags->Upper() >= 1 ? myFlags->Value(1) : Standard_True;
81 Standard_Boolean aFlag2 = myFlags->Upper() >= 2 ? myFlags->Value(2) : Standard_True;
82 Handle(TColStd_HArray1OfByte) aNewArray = new TColStd_HArray1OfByte(0, 2);
83 myFlags->SetInternalArray(aNewArray);
84 myFlags->SetValue(0, aFlag0);
85 myFlags->SetValue(1, aFlag1);
86 myFlags->SetValue(2, aFlag2);
90 std::string Model_Data::name()
92 Handle(TDataStd_Name) aName;
93 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
94 return std::string(TCollection_AsciiString(aName->Get()).ToCString());
95 return ""; // not defined
98 void Model_Data::setName(const std::string& theName)
100 bool isModified = false;
101 std::string anOldName = name();
102 Handle(TDataStd_Name) aName;
103 if (!myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
104 TDataStd_Name::Set(myLab, theName.c_str());
107 isModified = !aName->Get().IsEqual(theName.c_str());
109 aName->Set(theName.c_str());
111 if (mySendAttributeUpdated && isModified)
112 ModelAPI_ObjectRenamedMessage::send(myObject, anOldName, theName, this);
115 AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
117 AttributePtr aResult;
118 TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
119 ModelAPI_Attribute* anAttr = 0;
120 if (theAttrType == ModelAPI_AttributeDocRef::typeId()) {
121 anAttr = new Model_AttributeDocRef(anAttrLab);
122 } else if (theAttrType == Model_AttributeInteger::typeId()) {
123 Model_AttributeInteger* anAttribute = new Model_AttributeInteger(anAttrLab);
124 // Expression should use the same label to support backward compatibility
125 TDF_Label anExpressionLab = anAttrLab;
126 anAttribute->myExpression.reset(new Model_ExpressionInteger(anExpressionLab));
127 anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression->isInitialized();
128 anAttr = anAttribute;
129 } else if (theAttrType == ModelAPI_AttributeDouble::typeId()) {
130 Model_AttributeDouble* anAttribute = new Model_AttributeDouble(anAttrLab);
131 TDF_Label anExpressionLab = anAttrLab.FindChild(1);
132 anAttribute->myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
133 anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression->isInitialized();
134 anAttr = anAttribute;
135 } else if (theAttrType == Model_AttributeBoolean::typeId()) {
136 anAttr = new Model_AttributeBoolean(anAttrLab);
137 } else if (theAttrType == Model_AttributeString::typeId()) {
138 anAttr = new Model_AttributeString(anAttrLab);
139 } else if (theAttrType == ModelAPI_AttributeReference::typeId()) {
140 anAttr = new Model_AttributeReference(anAttrLab);
141 } else if (theAttrType == ModelAPI_AttributeSelection::typeId()) {
142 anAttr = new Model_AttributeSelection(anAttrLab);
143 } else if (theAttrType == ModelAPI_AttributeSelectionList::typeId()) {
144 anAttr = new Model_AttributeSelectionList(anAttrLab);
145 } else if (theAttrType == ModelAPI_AttributeRefAttr::typeId()) {
146 anAttr = new Model_AttributeRefAttr(anAttrLab);
147 } else if (theAttrType == ModelAPI_AttributeRefList::typeId()) {
148 anAttr = new Model_AttributeRefList(anAttrLab);
149 } else if (theAttrType == ModelAPI_AttributeIntArray::typeId()) {
150 anAttr = new Model_AttributeIntArray(anAttrLab);
152 // create also GeomData attributes here because only here the OCAF structure is known
153 else if (theAttrType == GeomData_Point::typeId()) {
154 GeomData_Point* anAttribute = new GeomData_Point(anAttrLab);
155 for (int aComponent = 0; aComponent < GeomData_Point::NUM_COMPONENTS; ++aComponent) {
156 TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
157 anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
158 anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression[aComponent]->isInitialized();
160 anAttr = anAttribute;
161 } else if (theAttrType == GeomData_Dir::typeId()) {
162 anAttr = new GeomData_Dir(anAttrLab);
163 } else if (theAttrType == GeomData_Point2D::typeId()) {
164 GeomData_Point2D* anAttribute = new GeomData_Point2D(anAttrLab);
165 for (int aComponent = 0; aComponent < GeomData_Point2D::NUM_COMPONENTS; ++aComponent) {
166 TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
167 anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
168 anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression[aComponent]->isInitialized();
170 anAttr = anAttribute;
173 aResult = std::shared_ptr<ModelAPI_Attribute>(anAttr);
174 myAttrs[theID] = aResult;
175 anAttr->setObject(myObject);
176 anAttr->setID(theID);
178 Events_Error::send("Can not create unknown type of attribute " + theAttrType);
183 // macro for gthe generic returning of the attribute by the ID
184 #define GET_ATTRIBUTE_BY_ID(ATTR_TYPE, METHOD_NAME) \
185 std::shared_ptr<ATTR_TYPE> Model_Data::METHOD_NAME(const std::string& theID) { \
186 std::shared_ptr<ATTR_TYPE> aRes; \
187 std::map<std::string, AttributePtr >::iterator aFound = \
188 myAttrs.find(theID); \
189 if (aFound != myAttrs.end()) { \
190 aRes = std::dynamic_pointer_cast<ATTR_TYPE>(aFound->second); \
194 // implement nice getting methods for all ModelAPI attributes
195 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDocRef, document);
196 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDouble, real);
197 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeInteger, integer);
198 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeBoolean, boolean);
199 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeString, string);
200 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeReference, reference);
201 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection);
202 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
203 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
204 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
205 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
207 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
209 std::shared_ptr<ModelAPI_Attribute> aResult;
210 if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
212 return myAttrs[theID];
215 const std::string& Model_Data::id(const std::shared_ptr<ModelAPI_Attribute>& theAttr)
217 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr =
219 for (; anAttr != myAttrs.end(); anAttr++) {
220 if (anAttr->second == theAttr)
221 return anAttr->first;
224 static std::string anEmpty;
228 bool Model_Data::isEqual(const std::shared_ptr<ModelAPI_Data>& theData)
230 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theData);
232 return myLab.IsEqual(aData->myLab) == Standard_True ;
236 bool Model_Data::isValid()
238 return !myLab.IsNull() && myLab.HasAttribute();
241 std::list<std::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const std::string& theType)
243 std::list<std::shared_ptr<ModelAPI_Attribute> > aResult;
244 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
246 for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
247 if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
248 aResult.push_back(anAttrsIter->second);
254 std::list<std::string> Model_Data::attributesIDs(const std::string& theType)
256 std::list<std::string> aResult;
257 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
259 for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
260 if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
261 aResult.push_back(anAttrsIter->first);
267 void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
269 theAttr->setInitialized();
270 if (theAttr->isArgument()) {
271 if (mySendAttributeUpdated) {
273 myObject->attributeChanged(theAttr->id());
274 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
275 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
278 myWasChangedButBlocked = true;
283 void Model_Data::blockSendAttributeUpdated(const bool theBlock)
285 if (mySendAttributeUpdated == theBlock) {
286 mySendAttributeUpdated = !theBlock;
287 if (mySendAttributeUpdated && myWasChangedButBlocked) { // so, now it is ok to send the update signal
288 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
289 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
290 myWasChangedButBlocked = false;
295 void Model_Data::erase()
298 myLab.ForgetAllAttributes();
301 // indexes in the state array
303 STATE_INDEX_STATE = 1, // the state type itself
304 STATE_INDEX_TRANSACTION = 2, // transaction ID
307 /// Returns the label array, initialises it by default values if not exists
308 static Handle(TDataStd_IntegerArray) stateArray(TDF_Label& theLab)
310 Handle(TDataStd_IntegerArray) aStateArray;
311 if (!theLab.FindAttribute(TDataStd_IntegerArray::GetID(), aStateArray)) {
312 aStateArray = TDataStd_IntegerArray::Set(theLab, 1, 2);
313 aStateArray->SetValue(STATE_INDEX_STATE, ModelAPI_StateMustBeUpdated); // default state
314 aStateArray->SetValue(STATE_INDEX_TRANSACTION, 0); // default transaction ID (not existing)
319 void Model_Data::execState(const ModelAPI_ExecState theState)
321 if (theState != ModelAPI_StateNothing) {
322 if (stateArray(myLab)->Value(STATE_INDEX_STATE) != (int)theState) {
323 stateArray(myLab)->SetValue(STATE_INDEX_STATE, (int)theState);
325 // send signal even if the new value corresponds to the one in data model: undo issue 980
326 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED);
327 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent, false);
331 ModelAPI_ExecState Model_Data::execState()
333 return ModelAPI_ExecState(stateArray(myLab)->Value(STATE_INDEX_STATE));
336 int Model_Data::updateID()
338 return stateArray(myLab)->Value(STATE_INDEX_TRANSACTION);
341 void Model_Data::setUpdateID(const int theID)
343 stateArray(myLab)->SetValue(STATE_INDEX_TRANSACTION, theID);
346 void Model_Data::setError(const std::string& theError, bool theSend)
348 execState(ModelAPI_StateExecFailed);
350 Events_Error::send(theError);
352 TDataStd_AsciiString::Set(myLab, theError.c_str());
353 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED);
354 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent, false);
357 void Model_Data::eraseErrorString()
359 myLab.ForgetAttribute(TDataStd_AsciiString::GetID());
362 std::string Model_Data::error() const
364 Handle(TDataStd_AsciiString) anErrorAttr;
365 if (myLab.FindAttribute(TDataStd_AsciiString::GetID(), anErrorAttr)) {
366 return std::string(anErrorAttr->Get().ToCString());
368 return std::string();
371 int Model_Data::featureId() const
373 return myLab.Father().Tag(); // tag of the feature label
376 void Model_Data::eraseBackReferences()
379 std::shared_ptr<ModelAPI_Result> aRes =
380 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
382 aRes->setIsConcealed(false);
385 void Model_Data::removeBackReference(FeaturePtr theFeature, std::string theAttrID)
387 AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
388 removeBackReference(anAttribute);
391 void Model_Data::removeBackReference(AttributePtr theAttr)
393 if (myRefsToMe.find(theAttr) == myRefsToMe.end())
396 myRefsToMe.erase(theAttr);
398 // remove concealment immideately: on deselection it must be posible to reselect in GUI the same
399 FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttr->owner());
400 if (aFeatureOwner.get() &&
401 ModelAPI_Session::get()->validators()->isConcealed(aFeatureOwner->getKind(), theAttr->id())) {
402 updateConcealmentFlag();
406 void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
407 const bool theApplyConcealment)
409 // it is possible to add the same attribute twice: may be last time the owner was not Stable...
410 AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
411 if (myRefsToMe.find(anAttribute) == myRefsToMe.end())
412 myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
414 if (theApplyConcealment && theFeature->isStable() &&
415 ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
416 std::shared_ptr<ModelAPI_Result> aRes =
417 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
418 // the second condition is for history upper than concealment causer, so the feature result may
419 // be displayed and previewed; also for avoiding of quick show/hide on history
421 if (aRes && !theFeature->isDisabled()) {
422 aRes->setIsConcealed(true);
427 void Model_Data::updateConcealmentFlag()
429 std::set<AttributePtr>::iterator aRefsIter = myRefsToMe.begin();
430 for(; aRefsIter != myRefsToMe.end(); aRefsIter++) {
431 if (aRefsIter->get()) {
432 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefsIter)->owner());
433 if (aFeature.get() && !aFeature->isDisabled() && aFeature->isStable()) {
434 if (ModelAPI_Session::get()->validators()->isConcealed(
435 aFeature->getKind(), (*aRefsIter)->id())) {
436 std::shared_ptr<ModelAPI_Result> aRes =
437 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
439 aRes->setIsConcealed(true); // set concealed
446 std::shared_ptr<ModelAPI_Result> aRes =
447 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
449 aRes->setIsConcealed(false);
453 std::set<std::string> set_union(const std::set<std::string>& theLeft,
454 const std::set<std::string>& theRight)
456 std::set<std::string> aResult;
457 aResult.insert(theLeft.begin(), theLeft.end());
458 aResult.insert(theRight.begin(), theRight.end());
462 std::set<std::string> usedParameters(const AttributePointPtr& theAttribute)
464 std::set<std::string> anUsedParameters;
465 for (int aComponent = 0; aComponent < 3; ++aComponent)
466 anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
467 return anUsedParameters;
470 std::set<std::string> usedParameters(const AttributePoint2DPtr& theAttribute)
472 std::set<std::string> anUsedParameters;
473 for (int aComponent = 0; aComponent < 2; ++aComponent)
474 anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
475 return anUsedParameters;
478 std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters,
479 const DocumentPtr& theDocument)
481 std::list<ResultParameterPtr> aResult;
482 std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
483 for (; aParamIt != theParameters.cend(); ++aParamIt) {
484 const std::string& aName = *aParamIt;
486 ResultParameterPtr aParam;
487 if (ModelAPI_Tools::findVariable(aName, aValue, aParam, theDocument))
488 aResult.push_back(aParam);
493 void Model_Data::referencesToObjects(
494 std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs)
496 static Model_ValidatorsFactory* aValidators =
497 static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
498 FeaturePtr aMyFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(myObject);
500 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
501 std::list<ObjectPtr> aReferenced; // not inside of cycle to avoid excess memory management
502 for(; anAttr != myAttrs.end(); anAttr++) {
503 // skip not-case attributes, that really may refer to anything not-used (issue 671)
504 if (aMyFeature.get() && !aValidators->isCase(aMyFeature, anAttr->second->id()))
507 std::string aType = anAttr->second->attributeType();
508 if (aType == ModelAPI_AttributeReference::typeId()) { // reference to object
509 std::shared_ptr<ModelAPI_AttributeReference> aRef = std::dynamic_pointer_cast<
510 ModelAPI_AttributeReference>(anAttr->second);
511 aReferenced.push_back(aRef->value());
512 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { // reference to attribute or object
513 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = std::dynamic_pointer_cast<
514 ModelAPI_AttributeRefAttr>(anAttr->second);
515 aReferenced.push_back(aRef->isObject() ? aRef->object() : aRef->attr()->owner());
516 } else if (aType == ModelAPI_AttributeRefList::typeId()) { // list of references
517 aReferenced = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr->second)->list();
518 } else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute
519 std::shared_ptr<ModelAPI_AttributeSelection> aRef = std::dynamic_pointer_cast<
520 ModelAPI_AttributeSelection>(anAttr->second);
521 aReferenced.push_back(aRef->context());
522 } else if (aType == ModelAPI_AttributeSelectionList::typeId()) { // list of selection attributes
523 std::shared_ptr<ModelAPI_AttributeSelectionList> aRef = std::dynamic_pointer_cast<
524 ModelAPI_AttributeSelectionList>(anAttr->second);
525 for(int a = aRef->size() - 1; a >= 0; a--) {
526 aReferenced.push_back(aRef->value(a)->context());
528 } else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute
529 AttributeIntegerPtr anAttribute =
530 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttr->second);
531 std::set<std::string> anUsedParameters = anAttribute->usedParameters();
532 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
533 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
534 } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute
535 AttributeDoublePtr anAttribute =
536 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr->second);
537 std::set<std::string> anUsedParameters = anAttribute->usedParameters();
538 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
539 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
540 } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute
541 AttributePointPtr anAttribute =
542 std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr->second);
543 std::set<std::string> anUsedParameters = usedParameters(anAttribute);
544 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
545 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
546 } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute
547 AttributePoint2DPtr anAttribute =
548 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->second);
549 std::set<std::string> anUsedParameters = usedParameters(anAttribute);
550 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
551 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
553 continue; // nothing to do, not reference
555 if (!aReferenced.empty()) {
556 theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
562 /// makes copy of all attributes on the given label and all sub-labels
563 static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) {
564 TDF_AttributeIterator anAttrIter(theSource);
565 for(; anAttrIter.More(); anAttrIter.Next()) {
566 Handle(TDF_Attribute) aTargetAttr;
567 if (!theDestination.FindAttribute(anAttrIter.Value()->ID(), aTargetAttr)) {
568 // create a new attribute if not yet exists in the destination
569 aTargetAttr = anAttrIter.Value()->NewEmpty();
570 theDestination.AddAttribute(aTargetAttr);
572 Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(); // no relocation, empty map
573 anAttrIter.Value()->Paste(aTargetAttr, aRelocTable);
575 // copy the sub-labels content
576 TDF_ChildIterator aSubLabsIter(theSource);
577 for(; aSubLabsIter.More(); aSubLabsIter.Next()) {
578 copyAttrs(aSubLabsIter.Value(), theDestination.FindChild(aSubLabsIter.Value().Tag()));
582 void Model_Data::copyTo(std::shared_ptr<ModelAPI_Data> theTarget)
584 TDF_Label aTargetRoot = std::dynamic_pointer_cast<Model_Data>(theTarget)->label();
585 copyAttrs(myLab, aTargetRoot);
586 // make initialized the initialized attributes
587 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aMyIter = myAttrs.begin();
588 for(; aMyIter != myAttrs.end(); aMyIter++) {
589 if (aMyIter->second->isInitialized()) {
590 AttributePtr aTargetAttr = theTarget->attribute(aMyIter->first);
592 aTargetAttr->setInitialized();
597 bool Model_Data::isInHistory()
599 return myFlags->Value(kFlagInHistory) == Standard_True;
602 void Model_Data::setIsInHistory(const bool theFlag)
604 return myFlags->SetValue(kFlagInHistory, theFlag);
607 bool Model_Data::isDeleted()
609 return myFlags->Value(kFlagDeleted) == Standard_True;
612 void Model_Data::setIsDeleted(const bool theFlag)
614 return myFlags->SetValue(kFlagDeleted, theFlag);
617 bool Model_Data::isDisplayed()
619 if (!myObject.get() || !myObject->document().get() || // object is in valid
620 myFlags->Value(kFlagDisplayed) != Standard_True) // or it was not displayed before
622 if (myObject->document()->isActive()) // for active documents it must be ok anyway
624 // any object from the root document except part result may be displayed
625 if (myObject->document() == ModelAPI_Session::get()->moduleDocument() &&
626 myObject->groupName() != ModelAPI_ResultPart::group())
631 void Model_Data::setDisplayed(const bool theDisplay)
633 if (theDisplay != isDisplayed()) {
634 myFlags->SetValue(kFlagDisplayed, theDisplay);
635 static Events_Loop* aLoop = Events_Loop::loop();
636 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
637 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
638 aECreator->sendUpdated(myObject, EVENT_DISP);
642 std::shared_ptr<ModelAPI_Data> Model_Data::invalidPtr()
647 std::shared_ptr<ModelAPI_Data> Model_Data::invalidData()
652 std::shared_ptr<ModelAPI_Object> Model_Data::owner()