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);
115 if (isModified && myObject && myObject->document()) {
116 std::dynamic_pointer_cast<Model_Document>(myObject->document())->
117 changeNamingName(anOldName, theName);
121 AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
123 AttributePtr aResult;
124 TDF_Label anAttrLab = myLab.FindChild(int(myAttrs.size()) + 1);
125 ModelAPI_Attribute* anAttr = 0;
126 if (theAttrType == ModelAPI_AttributeDocRef::typeId()) {
127 anAttr = new Model_AttributeDocRef(anAttrLab);
128 } else if (theAttrType == Model_AttributeInteger::typeId()) {
129 anAttr = new Model_AttributeInteger(anAttrLab);
130 } else if (theAttrType == ModelAPI_AttributeDouble::typeId()) {
131 anAttr = new Model_AttributeDouble(anAttrLab);
132 } else if (theAttrType == Model_AttributeBoolean::typeId()) {
133 anAttr = new Model_AttributeBoolean(anAttrLab);
134 } else if (theAttrType == Model_AttributeString::typeId()) {
135 anAttr = new Model_AttributeString(anAttrLab);
136 } else if (theAttrType == ModelAPI_AttributeReference::typeId()) {
137 anAttr = new Model_AttributeReference(anAttrLab);
138 } else if (theAttrType == ModelAPI_AttributeSelection::typeId()) {
139 anAttr = new Model_AttributeSelection(anAttrLab);
140 } else if (theAttrType == ModelAPI_AttributeSelectionList::typeId()) {
141 anAttr = new Model_AttributeSelectionList(anAttrLab);
142 } else if (theAttrType == ModelAPI_AttributeRefAttr::typeId()) {
143 anAttr = new Model_AttributeRefAttr(anAttrLab);
144 } else if (theAttrType == ModelAPI_AttributeRefList::typeId()) {
145 anAttr = new Model_AttributeRefList(anAttrLab);
146 } else if (theAttrType == ModelAPI_AttributeRefAttrList::typeId()) {
147 anAttr = new Model_AttributeRefAttrList(anAttrLab);
148 } else if (theAttrType == ModelAPI_AttributeIntArray::typeId()) {
149 anAttr = new Model_AttributeIntArray(anAttrLab);
150 } else if (theAttrType == ModelAPI_AttributeDoubleArray::typeId()) {
151 anAttr = new Model_AttributeDoubleArray(anAttrLab);
153 // create also GeomData attributes here because only here the OCAF structure is known
154 else if (theAttrType == GeomData_Point::typeId()) {
155 GeomData_Point* anAttribute = new GeomData_Point();
156 bool anAllInitialized = true;
157 for (int aComponent = 0; aComponent < GeomData_Point::NUM_COMPONENTS; ++aComponent) {
158 TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
159 anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
160 anAllInitialized = anAllInitialized && anAttribute->myExpression[aComponent]->isInitialized();
162 anAttribute->myIsInitialized = anAllInitialized;
163 anAttr = anAttribute;
164 } else if (theAttrType == GeomData_Dir::typeId()) {
165 anAttr = new GeomData_Dir(anAttrLab);
166 } else if (theAttrType == GeomData_Point2D::typeId()) {
167 GeomData_Point2D* anAttribute = new GeomData_Point2D();
168 bool anAllInitialized = true;
169 for (int aComponent = 0; aComponent < GeomData_Point2D::NUM_COMPONENTS; ++aComponent) {
170 TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
171 anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
172 anAllInitialized = anAllInitialized && anAttribute->myExpression[aComponent]->isInitialized();
174 anAttribute->myIsInitialized = anAllInitialized;
175 anAttr = anAttribute;
178 aResult = std::shared_ptr<ModelAPI_Attribute>(anAttr);
179 myAttrs[theID] = aResult;
180 anAttr->setObject(myObject);
181 anAttr->setID(theID);
183 Events_InfoMessage("Model_Data",
184 "Can not create unknown type of attribute %1").arg(theAttrType).send();
189 // macro for the generic returning of the attribute by the ID
190 #define GET_ATTRIBUTE_BY_ID(ATTR_TYPE, METHOD_NAME) \
191 std::shared_ptr<ATTR_TYPE> Model_Data::METHOD_NAME(const std::string& theID) { \
192 std::shared_ptr<ATTR_TYPE> aRes; \
193 std::map<std::string, AttributePtr >::iterator aFound = \
194 myAttrs.find(theID); \
195 if (aFound != myAttrs.end()) { \
196 aRes = std::dynamic_pointer_cast<ATTR_TYPE>(aFound->second); \
200 // implement nice getting methods for all ModelAPI attributes
201 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDocRef, document);
202 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDouble, real);
203 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeInteger, integer);
204 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeBoolean, boolean);
205 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeString, string);
206 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeReference, reference);
207 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection);
208 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
209 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
210 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
211 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttrList, refattrlist);
212 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
213 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDoubleArray, realArray);
215 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
217 std::shared_ptr<ModelAPI_Attribute> aResult;
218 if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
220 return myAttrs[theID];
223 const std::string& Model_Data::id(const std::shared_ptr<ModelAPI_Attribute>& theAttr)
225 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr =
227 for (; anAttr != myAttrs.end(); anAttr++) {
228 if (anAttr->second == theAttr)
229 return anAttr->first;
232 static std::string anEmpty;
236 bool Model_Data::isEqual(const std::shared_ptr<ModelAPI_Data>& theData)
238 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theData);
240 return myLab.IsEqual(aData->myLab) == Standard_True ;
244 bool Model_Data::isValid()
246 return !myLab.IsNull() && myLab.HasAttribute();
249 std::list<std::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const std::string& theType)
251 std::list<std::shared_ptr<ModelAPI_Attribute> > aResult;
252 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
254 for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
255 if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
256 aResult.push_back(anAttrsIter->second);
262 std::list<std::string> Model_Data::attributesIDs(const std::string& theType)
264 std::list<std::string> aResult;
265 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
267 for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
268 if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
269 aResult.push_back(anAttrsIter->first);
275 void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
277 theAttr->setInitialized();
278 if (theAttr->isArgument()) {
279 if (mySendAttributeUpdated) {
281 myObject->attributeChanged(theAttr->id());
282 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
283 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
286 // to avoid too many duplications do not add the same like the last
287 if (myWasChangedButBlocked.empty() || *(myWasChangedButBlocked.rbegin()) != theAttr)
288 myWasChangedButBlocked.push_back(theAttr);
293 void Model_Data::blockSendAttributeUpdated(const bool theBlock, const bool theSendMessage)
295 if (mySendAttributeUpdated == theBlock) {
296 mySendAttributeUpdated = !theBlock;
297 if (mySendAttributeUpdated && !myWasChangedButBlocked.empty()) {
298 // so, now it is ok to send the update signal
299 if (theSendMessage) {
300 // make a copy to avoid iteration on modified list
301 // (may be cleared by attribute changed call)
302 std::list<ModelAPI_Attribute*> aWasChangedButBlocked = myWasChangedButBlocked;
303 myWasChangedButBlocked.clear();
304 std::list<ModelAPI_Attribute*>::iterator aChangedIter = aWasChangedButBlocked.begin();
305 for(; aChangedIter != aWasChangedButBlocked.end(); aChangedIter++) {
306 myObject->attributeChanged((*aChangedIter)->id());
308 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
309 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
311 myWasChangedButBlocked.clear();
317 void Model_Data::erase()
319 if (!myLab.IsNull()) {
320 if (myLab.HasAttribute()) {
321 // remove in order to clear back references in other objects
322 std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
323 referencesToObjects(aRefs);
324 std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator
325 anAttrIter = aRefs.begin();
326 for(; anAttrIter != aRefs.end(); anAttrIter++) {
327 std::list<ObjectPtr>::iterator aReferenced = anAttrIter->second.begin();
328 for(; aReferenced != anAttrIter->second.end(); aReferenced++) {
329 if (aReferenced->get() && (*aReferenced)->data()->isValid()) {
330 std::shared_ptr<Model_Data> aData =
331 std::dynamic_pointer_cast<Model_Data>((*aReferenced)->data());
332 aData->removeBackReference(myAttrs[anAttrIter->first]);
338 myLab.ForgetAllAttributes();
342 // indexes in the state array
344 STATE_INDEX_STATE = 1, // the state type itself
345 STATE_INDEX_TRANSACTION = 2, // transaction ID
348 /// Returns the label array, initialises it by default values if not exists
349 static Handle(TDataStd_IntegerArray) stateArray(TDF_Label& theLab)
351 Handle(TDataStd_IntegerArray) aStateArray;
352 if (!theLab.FindAttribute(TDataStd_IntegerArray::GetID(), aStateArray)) {
353 aStateArray = TDataStd_IntegerArray::Set(theLab, 1, 2);
354 aStateArray->SetValue(STATE_INDEX_STATE, ModelAPI_StateMustBeUpdated); // default state
355 aStateArray->SetValue(STATE_INDEX_TRANSACTION, 0); // default transaction ID (not existing)
360 void Model_Data::execState(const ModelAPI_ExecState theState)
362 if (theState != ModelAPI_StateNothing) {
363 if (stateArray(myLab)->Value(STATE_INDEX_STATE) != (int)theState) {
364 stateArray(myLab)->SetValue(STATE_INDEX_STATE, (int)theState);
369 ModelAPI_ExecState Model_Data::execState()
371 return ModelAPI_ExecState(stateArray(myLab)->Value(STATE_INDEX_STATE));
374 int Model_Data::updateID()
376 return stateArray(myLab)->Value(STATE_INDEX_TRANSACTION);
379 void Model_Data::setUpdateID(const int theID)
381 stateArray(myLab)->SetValue(STATE_INDEX_TRANSACTION, theID);
384 void Model_Data::setError(const std::string& theError, bool theSend)
386 execState(ModelAPI_StateExecFailed);
388 Events_InfoMessage("Model_Data", theError).send();
390 TDataStd_AsciiString::Set(myLab, theError.c_str());
393 void Model_Data::eraseErrorString()
395 myLab.ForgetAttribute(TDataStd_AsciiString::GetID());
398 std::string Model_Data::error() const
400 Handle(TDataStd_AsciiString) anErrorAttr;
401 if (myLab.FindAttribute(TDataStd_AsciiString::GetID(), anErrorAttr)) {
402 return std::string(anErrorAttr->Get().ToCString());
404 return std::string();
407 int Model_Data::featureId() const
409 return myLab.Father().Tag(); // tag of the feature label
412 void Model_Data::eraseBackReferences()
415 std::shared_ptr<ModelAPI_Result> aRes =
416 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
418 aRes->setIsConcealed(false);
421 void Model_Data::removeBackReference(FeaturePtr theFeature, std::string theAttrID)
423 AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
424 removeBackReference(anAttribute);
427 void Model_Data::removeBackReference(AttributePtr theAttr)
429 if (myRefsToMe.find(theAttr) == myRefsToMe.end())
432 myRefsToMe.erase(theAttr);
434 // remove concealment immideately: on deselection it must be posible to reselect in GUI the same
435 FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttr->owner());
436 if (aFeatureOwner.get() &&
437 ModelAPI_Session::get()->validators()->isConcealed(aFeatureOwner->getKind(), theAttr->id())) {
438 updateConcealmentFlag();
442 void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
443 const bool theApplyConcealment)
445 // it is possible to add the same attribute twice: may be last time the owner was not Stable...
446 AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
447 if (myRefsToMe.find(anAttribute) == myRefsToMe.end())
448 myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
450 if (theApplyConcealment && theFeature->isStable() &&
451 ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
452 std::shared_ptr<ModelAPI_Result> aRes =
453 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
454 // the second condition is for history upper than concealment causer, so the feature result may
455 // be displayed and previewed; also for avoiding of quick show/hide on history
457 if (aRes && !theFeature->isDisabled() &&
458 !ModelAPI_Session::get()->validators()->isUnconcealed(aRes, theFeature)) {
459 aRes->setIsConcealed(true);
464 void Model_Data::updateConcealmentFlag()
466 std::set<AttributePtr>::iterator aRefsIter = myRefsToMe.begin();
467 for(; aRefsIter != myRefsToMe.end(); aRefsIter++) {
468 if (aRefsIter->get()) {
469 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefsIter)->owner());
470 if (aFeature.get() && !aFeature->isDisabled() && aFeature->isStable()) {
471 if (ModelAPI_Session::get()->validators()->isConcealed(
472 aFeature->getKind(), (*aRefsIter)->id())) {
473 std::shared_ptr<ModelAPI_Result> aRes =
474 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
476 if (!ModelAPI_Session::get()->validators()->isUnconcealed(aRes, aFeature)) {
477 aRes->setIsConcealed(true); // set concealed
485 std::shared_ptr<ModelAPI_Result> aRes =
486 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
488 aRes->setIsConcealed(false);
492 std::set<std::string> set_union(const std::set<std::string>& theLeft,
493 const std::set<std::string>& theRight)
495 std::set<std::string> aResult;
496 aResult.insert(theLeft.begin(), theLeft.end());
497 aResult.insert(theRight.begin(), theRight.end());
501 std::set<std::string> usedParameters(const AttributePointPtr& theAttribute)
503 std::set<std::string> anUsedParameters;
504 for (int aComponent = 0; aComponent < 3; ++aComponent)
505 anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
506 return anUsedParameters;
509 std::set<std::string> usedParameters(const AttributePoint2DPtr& theAttribute)
511 std::set<std::string> anUsedParameters;
512 for (int aComponent = 0; aComponent < 2; ++aComponent)
513 anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
514 return anUsedParameters;
517 std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters)
519 std::list<ResultParameterPtr> aResult;
520 std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
521 for (; aParamIt != theParameters.cend(); ++aParamIt) {
522 const std::string& aName = *aParamIt;
524 ResultParameterPtr aParam;
525 // theSearcher is not needed here: in expressions
526 // 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 // reinitialize Model_Attributes by TDF_Attributes set
642 std::shared_ptr<Model_Data> aTData = std::dynamic_pointer_cast<Model_Data>(theTarget);
643 aTData->myAttrs.clear();
644 theTarget->owner()->initAttributes(); // reinit feature attributes
647 bool Model_Data::isInHistory()
649 return myFlags->Value(kFlagInHistory) == Standard_True;
652 void Model_Data::setIsInHistory(const bool theFlag)
654 return myFlags->SetValue(kFlagInHistory, theFlag);
657 bool Model_Data::isDeleted()
659 return myFlags->Value(kFlagDeleted) == Standard_True;
662 void Model_Data::setIsDeleted(const bool theFlag)
664 return myFlags->SetValue(kFlagDeleted, theFlag);
667 bool Model_Data::isDisplayed()
669 if (!myObject.get() || !myObject->document().get() || // object is in valid
670 myFlags->Value(kFlagDisplayed) != Standard_True) // or it was not displayed before
672 if (myObject->document()->isActive()) // for active documents it must be ok anyway
674 // any object from the root document except part result may be displayed
675 if (myObject->document() == ModelAPI_Session::get()->moduleDocument() &&
676 myObject->groupName() != ModelAPI_ResultPart::group())
681 void Model_Data::setDisplayed(const bool theDisplay)
683 if (theDisplay != isDisplayed()) {
684 myFlags->SetValue(kFlagDisplayed, theDisplay);
685 static Events_Loop* aLoop = Events_Loop::loop();
686 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
687 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
688 aECreator->sendUpdated(myObject, EVENT_DISP);
692 std::shared_ptr<ModelAPI_Data> Model_Data::invalidPtr()
697 std::shared_ptr<ModelAPI_Data> Model_Data::invalidData()
702 std::shared_ptr<ModelAPI_Object> Model_Data::owner()