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_AttributeDoubleArray.h>
12 #include <Model_AttributeReference.h>
13 #include <Model_AttributeRefAttr.h>
14 #include <Model_AttributeRefList.h>
15 #include <Model_AttributeRefAttrList.h>
16 #include <Model_AttributeBoolean.h>
17 #include <Model_AttributeString.h>
18 #include <Model_AttributeSelection.h>
19 #include <Model_AttributeSelectionList.h>
20 #include <Model_AttributeIntArray.h>
21 #include <Model_Events.h>
22 #include <Model_Expression.h>
23 #include <ModelAPI_Feature.h>
24 #include <ModelAPI_Result.h>
25 #include <ModelAPI_ResultParameter.h>
26 #include <ModelAPI_Validator.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_ResultPart.h>
29 #include <ModelAPI_ResultCompSolid.h>
30 #include <ModelAPI_Tools.h>
31 #include <Model_Validator.h>
33 #include <GeomDataAPI_Point.h>
34 #include <GeomDataAPI_Point2D.h>
36 #include <GeomData_Point.h>
37 #include <GeomData_Point2D.h>
38 #include <GeomData_Dir.h>
39 #include <Events_Loop.h>
40 #include <Events_InfoMessage.h>
42 #include <TDataStd_Name.hxx>
43 #include <TDataStd_AsciiString.hxx>
44 #include <TDataStd_IntegerArray.hxx>
45 #include <TDF_AttributeIterator.hxx>
46 #include <TDF_ChildIterator.hxx>
47 #include <TDF_RelocationTable.hxx>
48 #include <TColStd_HArray1OfByte.hxx>
53 // TDataStd_Name - name of the object
54 // TDataStd_IntegerArray - state of the object execution, transaction ID of update
55 // TDataStd_BooleanArray - array of flags of this data:
56 // 0 - is in history or not
57 static const int kFlagInHistory = 0;
58 // 1 - is displayed or not
59 static const int kFlagDisplayed = 1;
60 // 2 - is deleted (for results) or not
61 static const int kFlagDeleted = 2;
64 const static std::shared_ptr<ModelAPI_Data> kInvalid(new Model_Data());
66 Model_Data::Model_Data() : mySendAttributeUpdated(true), myWasChangedButBlocked(false)
70 void Model_Data::setLabel(TDF_Label theLab)
73 // set or get the default flags
74 if (!myLab.FindAttribute(TDataStd_BooleanArray::GetID(), myFlags)) {
75 // set default values if not found
76 myFlags = TDataStd_BooleanArray::Set(myLab, 0, 2);
77 myFlags->SetValue(kFlagInHistory, Standard_True); // is in history by default is true
78 myFlags->SetValue(kFlagDisplayed, Standard_True); // is displayed by default is true
79 myFlags->SetValue(kFlagDeleted, Standard_False); // is deleted by default is false
80 } else if (myFlags->Length() != 3) { // for old formats support
81 Standard_Boolean aFlag0 = myFlags->Upper() >= 0 ? myFlags->Value(0) : Standard_True;
82 Standard_Boolean aFlag1 = myFlags->Upper() >= 1 ? myFlags->Value(1) : Standard_True;
83 Standard_Boolean aFlag2 = myFlags->Upper() >= 2 ? myFlags->Value(2) : Standard_True;
84 Handle(TColStd_HArray1OfByte) aNewArray = new TColStd_HArray1OfByte(0, 2);
85 myFlags->SetInternalArray(aNewArray);
86 myFlags->SetValue(0, aFlag0);
87 myFlags->SetValue(1, aFlag1);
88 myFlags->SetValue(2, aFlag2);
92 std::string Model_Data::name()
94 Handle(TDataStd_Name) aName;
95 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
96 return std::string(TCollection_AsciiString(aName->Get()).ToCString());
97 return ""; // not defined
100 void Model_Data::setName(const std::string& theName)
102 bool isModified = false;
103 std::string anOldName = name();
104 Handle(TDataStd_Name) aName;
105 if (!myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
106 TDataStd_Name::Set(myLab, theName.c_str());
109 isModified = !aName->Get().IsEqual(theName.c_str());
111 aName->Set(theName.c_str());
113 if (mySendAttributeUpdated && isModified)
114 ModelAPI_ObjectRenamedMessage::send(myObject, anOldName, theName, this);
117 AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
119 AttributePtr aResult;
120 TDF_Label anAttrLab = myLab.FindChild(int(myAttrs.size()) + 1);
121 ModelAPI_Attribute* anAttr = 0;
122 if (theAttrType == ModelAPI_AttributeDocRef::typeId()) {
123 anAttr = new Model_AttributeDocRef(anAttrLab);
124 } else if (theAttrType == Model_AttributeInteger::typeId()) {
125 Model_AttributeInteger* anAttribute = new Model_AttributeInteger();
126 // Expression should use the same label to support backward compatibility
127 TDF_Label anExpressionLab = anAttrLab;
128 anAttribute->myExpression.reset(new Model_ExpressionInteger(anExpressionLab));
129 anAttribute->myIsInitialized = anAttribute->myExpression->isInitialized();
130 anAttr = anAttribute;
131 } else if (theAttrType == ModelAPI_AttributeDouble::typeId()) {
132 Model_AttributeDouble* anAttribute = new Model_AttributeDouble();
133 TDF_Label anExpressionLab = anAttrLab.FindChild(1);
134 anAttribute->myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
135 anAttribute->myIsInitialized = anAttribute->myExpression->isInitialized();
136 anAttr = anAttribute;
137 } else if (theAttrType == Model_AttributeBoolean::typeId()) {
138 anAttr = new Model_AttributeBoolean(anAttrLab);
139 } else if (theAttrType == Model_AttributeString::typeId()) {
140 anAttr = new Model_AttributeString(anAttrLab);
141 } else if (theAttrType == ModelAPI_AttributeReference::typeId()) {
142 anAttr = new Model_AttributeReference(anAttrLab);
143 } else if (theAttrType == ModelAPI_AttributeSelection::typeId()) {
144 anAttr = new Model_AttributeSelection(anAttrLab);
145 } else if (theAttrType == ModelAPI_AttributeSelectionList::typeId()) {
146 anAttr = new Model_AttributeSelectionList(anAttrLab);
147 } else if (theAttrType == ModelAPI_AttributeRefAttr::typeId()) {
148 anAttr = new Model_AttributeRefAttr(anAttrLab);
149 } else if (theAttrType == ModelAPI_AttributeRefList::typeId()) {
150 anAttr = new Model_AttributeRefList(anAttrLab);
151 } else if (theAttrType == ModelAPI_AttributeRefAttrList::typeId()) {
152 anAttr = new Model_AttributeRefAttrList(anAttrLab);
153 } else if (theAttrType == ModelAPI_AttributeIntArray::typeId()) {
154 anAttr = new Model_AttributeIntArray(anAttrLab);
155 } else if (theAttrType == ModelAPI_AttributeDoubleArray::typeId()) {
156 anAttr = new Model_AttributeDoubleArray(anAttrLab);
158 // create also GeomData attributes here because only here the OCAF structure is known
159 else if (theAttrType == GeomData_Point::typeId()) {
160 GeomData_Point* anAttribute = new GeomData_Point();
161 bool anAllInitialized = true;
162 for (int aComponent = 0; aComponent < GeomData_Point::NUM_COMPONENTS; ++aComponent) {
163 TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
164 anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
165 anAllInitialized = anAllInitialized && anAttribute->myExpression[aComponent]->isInitialized();
167 anAttribute->myIsInitialized = anAllInitialized;
168 anAttr = anAttribute;
169 } else if (theAttrType == GeomData_Dir::typeId()) {
170 anAttr = new GeomData_Dir(anAttrLab);
171 } else if (theAttrType == GeomData_Point2D::typeId()) {
172 GeomData_Point2D* anAttribute = new GeomData_Point2D();
173 bool anAllInitialized = true;
174 for (int aComponent = 0; aComponent < GeomData_Point2D::NUM_COMPONENTS; ++aComponent) {
175 TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
176 anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
177 anAllInitialized = anAllInitialized && anAttribute->myExpression[aComponent]->isInitialized();
179 anAttribute->myIsInitialized = anAllInitialized;
180 anAttr = anAttribute;
183 aResult = std::shared_ptr<ModelAPI_Attribute>(anAttr);
184 myAttrs[theID] = aResult;
185 anAttr->setObject(myObject);
186 anAttr->setID(theID);
188 Events_InfoMessage("Model_Data", "Can not create unknown type of attribute %1").arg(theAttrType).send();
193 // macro for the generic returning of the attribute by the ID
194 #define GET_ATTRIBUTE_BY_ID(ATTR_TYPE, METHOD_NAME) \
195 std::shared_ptr<ATTR_TYPE> Model_Data::METHOD_NAME(const std::string& theID) { \
196 std::shared_ptr<ATTR_TYPE> aRes; \
197 std::map<std::string, AttributePtr >::iterator aFound = \
198 myAttrs.find(theID); \
199 if (aFound != myAttrs.end()) { \
200 aRes = std::dynamic_pointer_cast<ATTR_TYPE>(aFound->second); \
204 // implement nice getting methods for all ModelAPI attributes
205 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDocRef, document);
206 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDouble, real);
207 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeInteger, integer);
208 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeBoolean, boolean);
209 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeString, string);
210 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeReference, reference);
211 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection);
212 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
213 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
214 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
215 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttrList, refattrlist);
216 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
217 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDoubleArray, realArray);
219 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
221 std::shared_ptr<ModelAPI_Attribute> aResult;
222 if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
224 return myAttrs[theID];
227 const std::string& Model_Data::id(const std::shared_ptr<ModelAPI_Attribute>& theAttr)
229 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr =
231 for (; anAttr != myAttrs.end(); anAttr++) {
232 if (anAttr->second == theAttr)
233 return anAttr->first;
236 static std::string anEmpty;
240 bool Model_Data::isEqual(const std::shared_ptr<ModelAPI_Data>& theData)
242 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theData);
244 return myLab.IsEqual(aData->myLab) == Standard_True ;
248 bool Model_Data::isValid()
250 return !myLab.IsNull() && myLab.HasAttribute();
253 std::list<std::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const std::string& theType)
255 std::list<std::shared_ptr<ModelAPI_Attribute> > aResult;
256 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
258 for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
259 if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
260 aResult.push_back(anAttrsIter->second);
266 std::list<std::string> Model_Data::attributesIDs(const std::string& theType)
268 std::list<std::string> aResult;
269 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
271 for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
272 if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
273 aResult.push_back(anAttrsIter->first);
279 void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
281 theAttr->setInitialized();
282 if (theAttr->isArgument()) {
283 if (mySendAttributeUpdated) {
285 myObject->attributeChanged(theAttr->id());
286 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
287 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
290 // to avoid too many duplications do not add the same like the last
291 if (myWasChangedButBlocked.empty() || *(myWasChangedButBlocked.rbegin()) != theAttr)
292 myWasChangedButBlocked.push_back(theAttr);
297 void Model_Data::blockSendAttributeUpdated(const bool theBlock, const bool theSendMessage)
299 if (mySendAttributeUpdated == theBlock) {
300 mySendAttributeUpdated = !theBlock;
301 if (mySendAttributeUpdated && !myWasChangedButBlocked.empty()) { // so, now it is ok to send the update signal
302 if (theSendMessage) {
303 // make a copy to avoid iteration on modified list (may be cleared by attribute changed call)
304 std::list<ModelAPI_Attribute*> aWasChangedButBlocked = myWasChangedButBlocked;
305 myWasChangedButBlocked.clear();
306 std::list<ModelAPI_Attribute*>::iterator aChangedIter = aWasChangedButBlocked.begin();
307 for(; aChangedIter != aWasChangedButBlocked.end(); aChangedIter++) {
308 myObject->attributeChanged((*aChangedIter)->id());
310 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
311 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
313 myWasChangedButBlocked.clear();
319 void Model_Data::erase()
321 if (!myLab.IsNull()) {
322 if (myLab.HasAttribute()) {
323 // remove in order to clear back references in other objects
324 std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
325 referencesToObjects(aRefs);
326 std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator anAttrIter = aRefs.begin();
327 for(; anAttrIter != aRefs.end(); anAttrIter++) {
328 std::list<ObjectPtr>::iterator aReferenced = anAttrIter->second.begin();
329 for(; aReferenced != anAttrIter->second.end(); aReferenced++) {
330 if (aReferenced->get() && (*aReferenced)->data()->isValid()) {
331 std::shared_ptr<Model_Data> aData =
332 std::dynamic_pointer_cast<Model_Data>((*aReferenced)->data());
333 aData->removeBackReference(myAttrs[anAttrIter->first]);
339 myLab.ForgetAllAttributes();
343 // indexes in the state array
345 STATE_INDEX_STATE = 1, // the state type itself
346 STATE_INDEX_TRANSACTION = 2, // transaction ID
349 /// Returns the label array, initialises it by default values if not exists
350 static Handle(TDataStd_IntegerArray) stateArray(TDF_Label& theLab)
352 Handle(TDataStd_IntegerArray) aStateArray;
353 if (!theLab.FindAttribute(TDataStd_IntegerArray::GetID(), aStateArray)) {
354 aStateArray = TDataStd_IntegerArray::Set(theLab, 1, 2);
355 aStateArray->SetValue(STATE_INDEX_STATE, ModelAPI_StateMustBeUpdated); // default state
356 aStateArray->SetValue(STATE_INDEX_TRANSACTION, 0); // default transaction ID (not existing)
361 void Model_Data::execState(const ModelAPI_ExecState theState)
363 if (theState != ModelAPI_StateNothing) {
364 if (stateArray(myLab)->Value(STATE_INDEX_STATE) != (int)theState) {
365 stateArray(myLab)->SetValue(STATE_INDEX_STATE, (int)theState);
370 ModelAPI_ExecState Model_Data::execState()
372 return ModelAPI_ExecState(stateArray(myLab)->Value(STATE_INDEX_STATE));
375 int Model_Data::updateID()
377 return stateArray(myLab)->Value(STATE_INDEX_TRANSACTION);
380 void Model_Data::setUpdateID(const int theID)
382 stateArray(myLab)->SetValue(STATE_INDEX_TRANSACTION, theID);
385 void Model_Data::setError(const std::string& theError, bool theSend)
387 execState(ModelAPI_StateExecFailed);
389 Events_InfoMessage("Model_Data", theError).send();
391 TDataStd_AsciiString::Set(myLab, theError.c_str());
394 void Model_Data::eraseErrorString()
396 myLab.ForgetAttribute(TDataStd_AsciiString::GetID());
399 std::string Model_Data::error() const
401 Handle(TDataStd_AsciiString) anErrorAttr;
402 if (myLab.FindAttribute(TDataStd_AsciiString::GetID(), anErrorAttr)) {
403 return std::string(anErrorAttr->Get().ToCString());
405 return std::string();
408 int Model_Data::featureId() const
410 return myLab.Father().Tag(); // tag of the feature label
413 void Model_Data::eraseBackReferences()
416 std::shared_ptr<ModelAPI_Result> aRes =
417 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
419 aRes->setIsConcealed(false);
422 void Model_Data::removeBackReference(FeaturePtr theFeature, std::string theAttrID)
424 AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
425 removeBackReference(anAttribute);
428 void Model_Data::removeBackReference(AttributePtr theAttr)
430 if (myRefsToMe.find(theAttr) == myRefsToMe.end())
433 myRefsToMe.erase(theAttr);
435 // remove concealment immideately: on deselection it must be posible to reselect in GUI the same
436 FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttr->owner());
437 if (aFeatureOwner.get() &&
438 ModelAPI_Session::get()->validators()->isConcealed(aFeatureOwner->getKind(), theAttr->id())) {
439 updateConcealmentFlag();
443 void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
444 const bool theApplyConcealment)
446 // it is possible to add the same attribute twice: may be last time the owner was not Stable...
447 AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
448 if (myRefsToMe.find(anAttribute) == myRefsToMe.end())
449 myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
451 if (theApplyConcealment && theFeature->isStable() &&
452 ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
453 std::shared_ptr<ModelAPI_Result> aRes =
454 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
455 // the second condition is for history upper than concealment causer, so the feature result may
456 // be displayed and previewed; also for avoiding of quick show/hide on history
458 if (aRes && !theFeature->isDisabled() &&
459 !ModelAPI_Session::get()->validators()->isUnconcealed(aRes, theFeature)) {
460 aRes->setIsConcealed(true);
465 void Model_Data::updateConcealmentFlag()
467 std::set<AttributePtr>::iterator aRefsIter = myRefsToMe.begin();
468 for(; aRefsIter != myRefsToMe.end(); aRefsIter++) {
469 if (aRefsIter->get()) {
470 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefsIter)->owner());
471 if (aFeature.get() && !aFeature->isDisabled() && aFeature->isStable()) {
472 if (ModelAPI_Session::get()->validators()->isConcealed(
473 aFeature->getKind(), (*aRefsIter)->id())) {
474 std::shared_ptr<ModelAPI_Result> aRes =
475 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
477 if (!ModelAPI_Session::get()->validators()->isUnconcealed(aRes, aFeature)) {
478 aRes->setIsConcealed(true); // set concealed
486 std::shared_ptr<ModelAPI_Result> aRes =
487 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
489 aRes->setIsConcealed(false);
493 std::set<std::string> set_union(const std::set<std::string>& theLeft,
494 const std::set<std::string>& theRight)
496 std::set<std::string> aResult;
497 aResult.insert(theLeft.begin(), theLeft.end());
498 aResult.insert(theRight.begin(), theRight.end());
502 std::set<std::string> usedParameters(const AttributePointPtr& theAttribute)
504 std::set<std::string> anUsedParameters;
505 for (int aComponent = 0; aComponent < 3; ++aComponent)
506 anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
507 return anUsedParameters;
510 std::set<std::string> usedParameters(const AttributePoint2DPtr& theAttribute)
512 std::set<std::string> anUsedParameters;
513 for (int aComponent = 0; aComponent < 2; ++aComponent)
514 anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
515 return anUsedParameters;
518 std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters)
520 std::list<ResultParameterPtr> aResult;
521 std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
522 for (; aParamIt != theParameters.cend(); ++aParamIt) {
523 const std::string& aName = *aParamIt;
525 ResultParameterPtr aParam;
526 // theSearcher is not needed here: in expressions of features the parameters history is not needed
527 if (ModelAPI_Tools::findVariable(FeaturePtr(), aName, aValue, aParam))
528 aResult.push_back(aParam);
533 void Model_Data::referencesToObjects(
534 std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs)
536 static Model_ValidatorsFactory* aValidators =
537 static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
538 FeaturePtr aMyFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(myObject);
540 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
541 std::list<ObjectPtr> aReferenced; // not inside of cycle to avoid excess memory management
542 for(; anAttr != myAttrs.end(); anAttr++) {
543 // skip not-case attributes, that really may refer to anything not-used (issue 671)
544 if (aMyFeature.get() && !aValidators->isCase(aMyFeature, anAttr->second->id()))
547 std::string aType = anAttr->second->attributeType();
548 if (aType == ModelAPI_AttributeReference::typeId()) { // reference to object
549 std::shared_ptr<ModelAPI_AttributeReference> aRef = std::dynamic_pointer_cast<
550 ModelAPI_AttributeReference>(anAttr->second);
551 aReferenced.push_back(aRef->value());
552 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { // reference to attribute or object
553 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = std::dynamic_pointer_cast<
554 ModelAPI_AttributeRefAttr>(anAttr->second);
555 if (aRef->isObject()) {
556 aReferenced.push_back(aRef->object());
558 AttributePtr anAttr = aRef->attr();
560 aReferenced.push_back(anAttr->owner());
562 } else if (aType == ModelAPI_AttributeRefList::typeId()) { // list of references
563 aReferenced = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr->second)->list();
564 } else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute
565 std::shared_ptr<ModelAPI_AttributeSelection> aRef = std::dynamic_pointer_cast<
566 ModelAPI_AttributeSelection>(anAttr->second);
567 aReferenced.push_back(aRef->context());
568 } else if (aType == ModelAPI_AttributeSelectionList::typeId()) { // list of selection attributes
569 std::shared_ptr<ModelAPI_AttributeSelectionList> aRef = std::dynamic_pointer_cast<
570 ModelAPI_AttributeSelectionList>(anAttr->second);
571 for(int a = aRef->size() - 1; a >= 0; a--) {
572 aReferenced.push_back(aRef->value(a)->context());
574 } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
575 std::shared_ptr<ModelAPI_AttributeRefAttrList> aRefAttr = std::dynamic_pointer_cast<
576 ModelAPI_AttributeRefAttrList>(anAttr->second);
577 std::list<std::pair<ObjectPtr, AttributePtr> > aRefs = aRefAttr->list();
578 std::list<std::pair<ObjectPtr, AttributePtr> >::const_iterator anIt = aRefs.begin(),
580 for (; anIt != aLast; anIt++) {
581 aReferenced.push_back(anIt->first);
583 } else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute
584 AttributeIntegerPtr anAttribute =
585 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttr->second);
586 std::set<std::string> anUsedParameters = anAttribute->usedParameters();
587 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
588 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
589 } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute
590 AttributeDoublePtr anAttribute =
591 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr->second);
592 std::set<std::string> anUsedParameters = anAttribute->usedParameters();
593 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
594 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
595 } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute
596 AttributePointPtr anAttribute =
597 std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr->second);
598 std::set<std::string> anUsedParameters = usedParameters(anAttribute);
599 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
600 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
601 } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute
602 AttributePoint2DPtr anAttribute =
603 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->second);
604 std::set<std::string> anUsedParameters = usedParameters(anAttribute);
605 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
606 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
608 continue; // nothing to do, not reference
610 if (!aReferenced.empty()) {
611 theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
617 /// makes copy of all attributes on the given label and all sub-labels
618 static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) {
619 TDF_AttributeIterator anAttrIter(theSource);
620 for(; anAttrIter.More(); anAttrIter.Next()) {
621 Handle(TDF_Attribute) aTargetAttr;
622 if (!theDestination.FindAttribute(anAttrIter.Value()->ID(), aTargetAttr)) {
623 // create a new attribute if not yet exists in the destination
624 aTargetAttr = anAttrIter.Value()->NewEmpty();
625 theDestination.AddAttribute(aTargetAttr);
627 Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(); // no relocation, empty map
628 anAttrIter.Value()->Paste(aTargetAttr, aRelocTable);
630 // copy the sub-labels content
631 TDF_ChildIterator aSubLabsIter(theSource);
632 for(; aSubLabsIter.More(); aSubLabsIter.Next()) {
633 copyAttrs(aSubLabsIter.Value(), theDestination.FindChild(aSubLabsIter.Value().Tag()));
637 void Model_Data::copyTo(std::shared_ptr<ModelAPI_Data> theTarget)
639 TDF_Label aTargetRoot = std::dynamic_pointer_cast<Model_Data>(theTarget)->label();
640 copyAttrs(myLab, aTargetRoot);
641 // make initialized the initialized attributes
642 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aMyIter = myAttrs.begin();
643 for(; aMyIter != myAttrs.end(); aMyIter++) {
644 if (aMyIter->second->isInitialized()) {
645 AttributePtr aTargetAttr = theTarget->attribute(aMyIter->first);
647 aTargetAttr->setInitialized();
652 bool Model_Data::isInHistory()
654 return myFlags->Value(kFlagInHistory) == Standard_True;
657 void Model_Data::setIsInHistory(const bool theFlag)
659 return myFlags->SetValue(kFlagInHistory, theFlag);
662 bool Model_Data::isDeleted()
664 return myFlags->Value(kFlagDeleted) == Standard_True;
667 void Model_Data::setIsDeleted(const bool theFlag)
669 return myFlags->SetValue(kFlagDeleted, theFlag);
672 bool Model_Data::isDisplayed()
674 if (!myObject.get() || !myObject->document().get() || // object is in valid
675 myFlags->Value(kFlagDisplayed) != Standard_True) // or it was not displayed before
677 if (myObject->document()->isActive()) // for active documents it must be ok anyway
679 // any object from the root document except part result may be displayed
680 if (myObject->document() == ModelAPI_Session::get()->moduleDocument() &&
681 myObject->groupName() != ModelAPI_ResultPart::group())
686 void Model_Data::setDisplayed(const bool theDisplay)
688 if (theDisplay != isDisplayed()) {
689 myFlags->SetValue(kFlagDisplayed, theDisplay);
690 static Events_Loop* aLoop = Events_Loop::loop();
691 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
692 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
693 aECreator->sendUpdated(myObject, EVENT_DISP);
697 std::shared_ptr<ModelAPI_Data> Model_Data::invalidPtr()
702 std::shared_ptr<ModelAPI_Data> Model_Data::invalidData()
707 std::shared_ptr<ModelAPI_Object> Model_Data::owner()