1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include <Model_Data.h>
21 #include <Model_AttributeDocRef.h>
22 #include <Model_AttributeInteger.h>
23 #include <Model_AttributeDouble.h>
24 #include <Model_AttributeDoubleArray.h>
25 #include <Model_AttributeReference.h>
26 #include <Model_AttributeRefAttr.h>
27 #include <Model_AttributeRefList.h>
28 #include <Model_AttributeRefAttrList.h>
29 #include <Model_AttributeBoolean.h>
30 #include <Model_AttributeString.h>
31 #include <Model_AttributeStringArray.h>
32 #include <Model_AttributeSelection.h>
33 #include <Model_AttributeSelectionList.h>
34 #include <Model_AttributeIntArray.h>
35 #include <Model_AttributeTables.h>
36 #include <Model_Events.h>
37 #include <Model_Expression.h>
38 #include <ModelAPI_Feature.h>
39 #include <ModelAPI_Result.h>
40 #include <ModelAPI_ResultParameter.h>
41 #include <ModelAPI_Validator.h>
42 #include <ModelAPI_Session.h>
43 #include <ModelAPI_ResultPart.h>
44 #include <ModelAPI_ResultCompSolid.h>
45 #include <ModelAPI_Tools.h>
46 #include <Model_Validator.h>
48 #include <GeomDataAPI_Point.h>
49 #include <GeomDataAPI_Point2D.h>
51 #include <GeomData_Point.h>
52 #include <GeomData_Point2D.h>
53 #include <GeomData_Dir.h>
54 #include <Events_Loop.h>
55 #include <Events_InfoMessage.h>
57 #include <TDataStd_Name.hxx>
58 #include <TDataStd_AsciiString.hxx>
59 #include <TDataStd_IntegerArray.hxx>
60 #include <TDF_AttributeIterator.hxx>
61 #include <TDF_ChildIterator.hxx>
62 #include <TDF_RelocationTable.hxx>
63 #include <TColStd_HArray1OfByte.hxx>
68 // TDataStd_Name - name of the object
69 // TDataStd_IntegerArray - state of the object execution, transaction ID of update
70 // TDataStd_BooleanArray - array of flags of this data:
71 // 0 - is in history or not
72 static const int kFlagInHistory = 0;
73 // 1 - is displayed or not
74 static const int kFlagDisplayed = 1;
75 // 2 - is deleted (for results) or not
76 static const int kFlagDeleted = 2;
79 const static std::shared_ptr<ModelAPI_Data> kInvalid(new Model_Data());
81 Model_Data::Model_Data() : mySendAttributeUpdated(true), myWasChangedButBlocked(false)
85 void Model_Data::setLabel(TDF_Label theLab)
88 // set or get the default flags
89 if (!myLab.FindAttribute(TDataStd_BooleanArray::GetID(), myFlags)) {
90 // set default values if not found
91 myFlags = TDataStd_BooleanArray::Set(myLab, 0, 2);
92 myFlags->SetValue(kFlagInHistory, Standard_True); // is in history by default is true
93 myFlags->SetValue(kFlagDisplayed, Standard_True); // is displayed by default is true
94 myFlags->SetValue(kFlagDeleted, Standard_False); // is deleted by default is false
95 } else if (myFlags->Length() != 3) { // for old formats support
96 Standard_Boolean aFlag0 = myFlags->Upper() >= 0 ? myFlags->Value(0) : Standard_True;
97 Standard_Boolean aFlag1 = myFlags->Upper() >= 1 ? myFlags->Value(1) : Standard_True;
98 Standard_Boolean aFlag2 = myFlags->Upper() >= 2 ? myFlags->Value(2) : Standard_True;
99 Handle(TColStd_HArray1OfByte) aNewArray = new TColStd_HArray1OfByte(0, 2);
100 myFlags->SetInternalArray(aNewArray);
101 myFlags->SetValue(0, aFlag0);
102 myFlags->SetValue(1, aFlag1);
103 myFlags->SetValue(2, aFlag2);
107 std::string Model_Data::name()
109 Handle(TDataStd_Name) aName;
110 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
112 myObject->myName = TCollection_AsciiString(aName->Get()).ToCString();
114 return std::string(TCollection_AsciiString(aName->Get()).ToCString());
116 return ""; // not defined
119 void Model_Data::setName(const std::string& theName)
121 bool isModified = false;
122 std::string anOldName = name();
123 Handle(TDataStd_Name) aName;
124 if (!myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
125 TDataStd_Name::Set(myLab, theName.c_str());
128 isModified = !aName->Get().IsEqual(theName.c_str());
130 aName->Set(theName.c_str());
132 if (mySendAttributeUpdated && isModified)
133 ModelAPI_ObjectRenamedMessage::send(myObject, anOldName, theName, this);
134 if (isModified && myObject && myObject->document()) {
135 std::dynamic_pointer_cast<Model_Document>(myObject->document())->
136 changeNamingName(anOldName, theName);
139 myObject->myName = theName;
143 AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
145 AttributePtr aResult;
146 TDF_Label anAttrLab = myLab.FindChild(int(myAttrs.size()) + 1);
147 ModelAPI_Attribute* anAttr = 0;
148 if (theAttrType == ModelAPI_AttributeDocRef::typeId()) {
149 anAttr = new Model_AttributeDocRef(anAttrLab);
150 } else if (theAttrType == Model_AttributeInteger::typeId()) {
151 anAttr = new Model_AttributeInteger(anAttrLab);
152 } else if (theAttrType == ModelAPI_AttributeDouble::typeId()) {
153 anAttr = new Model_AttributeDouble(anAttrLab);
154 } else if (theAttrType == Model_AttributeBoolean::typeId()) {
155 anAttr = new Model_AttributeBoolean(anAttrLab);
156 } else if (theAttrType == Model_AttributeString::typeId()) {
157 anAttr = new Model_AttributeString(anAttrLab);
158 } else if (theAttrType == Model_AttributeStringArray::typeId()) {
159 anAttr = new Model_AttributeStringArray(anAttrLab);
160 } else if (theAttrType == ModelAPI_AttributeReference::typeId()) {
161 anAttr = new Model_AttributeReference(anAttrLab);
162 } else if (theAttrType == ModelAPI_AttributeSelection::typeId()) {
163 anAttr = new Model_AttributeSelection(anAttrLab);
164 } else if (theAttrType == ModelAPI_AttributeSelectionList::typeId()) {
165 anAttr = new Model_AttributeSelectionList(anAttrLab);
166 } else if (theAttrType == ModelAPI_AttributeRefAttr::typeId()) {
167 anAttr = new Model_AttributeRefAttr(anAttrLab);
168 } else if (theAttrType == ModelAPI_AttributeRefList::typeId()) {
169 anAttr = new Model_AttributeRefList(anAttrLab);
170 } else if (theAttrType == ModelAPI_AttributeRefAttrList::typeId()) {
171 anAttr = new Model_AttributeRefAttrList(anAttrLab);
172 } else if (theAttrType == ModelAPI_AttributeIntArray::typeId()) {
173 anAttr = new Model_AttributeIntArray(anAttrLab);
174 } else if (theAttrType == ModelAPI_AttributeDoubleArray::typeId()) {
175 anAttr = new Model_AttributeDoubleArray(anAttrLab);
176 } else if (theAttrType == ModelAPI_AttributeTables::typeId()) {
177 anAttr = new Model_AttributeTables(anAttrLab);
179 // create also GeomData attributes here because only here the OCAF structure is known
180 else if (theAttrType == GeomData_Point::typeId()) {
181 GeomData_Point* anAttribute = new GeomData_Point();
182 bool anAllInitialized = true;
183 for (int aComponent = 0; aComponent < GeomData_Point::NUM_COMPONENTS; ++aComponent) {
184 TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
185 anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
186 anAllInitialized = anAllInitialized && anAttribute->myExpression[aComponent]->isInitialized();
188 anAttribute->myIsInitialized = anAllInitialized;
189 anAttr = anAttribute;
190 } else if (theAttrType == GeomData_Dir::typeId()) {
191 anAttr = new GeomData_Dir(anAttrLab);
192 } else if (theAttrType == GeomData_Point2D::typeId()) {
193 GeomData_Point2D* anAttribute = new GeomData_Point2D();
194 bool anAllInitialized = true;
195 for (int aComponent = 0; aComponent < GeomData_Point2D::NUM_COMPONENTS; ++aComponent) {
196 TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
197 anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
198 anAllInitialized = anAllInitialized && anAttribute->myExpression[aComponent]->isInitialized();
200 anAttribute->myIsInitialized = anAllInitialized;
201 anAttr = anAttribute;
204 aResult = std::shared_ptr<ModelAPI_Attribute>(anAttr);
205 myAttrs[theID] = aResult;
206 anAttr->setObject(myObject);
207 anAttr->setID(theID);
209 Events_InfoMessage("Model_Data",
210 "Can not create unknown type of attribute %1").arg(theAttrType).send();
215 // macro for the generic returning of the attribute by the ID
216 #define GET_ATTRIBUTE_BY_ID(ATTR_TYPE, METHOD_NAME) \
217 std::shared_ptr<ATTR_TYPE> Model_Data::METHOD_NAME(const std::string& theID) { \
218 std::shared_ptr<ATTR_TYPE> aRes; \
219 std::map<std::string, AttributePtr >::iterator aFound = \
220 myAttrs.find(theID); \
221 if (aFound != myAttrs.end()) { \
222 aRes = std::dynamic_pointer_cast<ATTR_TYPE>(aFound->second); \
226 // implement nice getting methods for all ModelAPI attributes
227 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDocRef, document);
228 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDouble, real);
229 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeInteger, integer);
230 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeBoolean, boolean);
231 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeString, string);
232 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeStringArray, stringArray);
233 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeReference, reference);
234 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection);
235 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
236 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
237 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
238 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttrList, refattrlist);
239 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
240 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDoubleArray, realArray);
241 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeTables, tables);
243 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
245 std::shared_ptr<ModelAPI_Attribute> aResult;
246 if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
248 return myAttrs[theID];
251 const std::string& Model_Data::id(const std::shared_ptr<ModelAPI_Attribute>& theAttr)
253 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr =
255 for (; anAttr != myAttrs.end(); anAttr++) {
256 if (anAttr->second == theAttr)
257 return anAttr->first;
260 static std::string anEmpty;
264 bool Model_Data::isEqual(const std::shared_ptr<ModelAPI_Data>& theData)
266 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theData);
268 return myLab.IsEqual(aData->myLab) == Standard_True ;
272 bool Model_Data::isValid()
274 return !myLab.IsNull() && myLab.HasAttribute();
277 std::list<std::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const std::string& theType)
279 std::list<std::shared_ptr<ModelAPI_Attribute> > aResult;
280 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
282 for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
283 if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
284 aResult.push_back(anAttrsIter->second);
290 std::list<std::string> Model_Data::attributesIDs(const std::string& theType)
292 std::list<std::string> aResult;
293 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
295 for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
296 if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
297 aResult.push_back(anAttrsIter->first);
303 void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
305 theAttr->setInitialized();
306 if (theAttr->isArgument()) {
307 if (mySendAttributeUpdated) {
309 myObject->attributeChanged(theAttr->id());
310 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
311 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
314 // to avoid too many duplications do not add the same like the last
315 if (myWasChangedButBlocked.empty() || *(myWasChangedButBlocked.rbegin()) != theAttr)
316 myWasChangedButBlocked.push_back(theAttr);
319 // trim: need to redisplay
321 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
322 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
327 bool Model_Data::blockSendAttributeUpdated(const bool theBlock, const bool theSendMessage)
329 bool aWasBlocked = !mySendAttributeUpdated;
330 if (mySendAttributeUpdated == theBlock) {
331 mySendAttributeUpdated = !theBlock;
332 if (mySendAttributeUpdated && !myWasChangedButBlocked.empty()) {
333 // so, now it is ok to send the update signal
334 if (theSendMessage) {
335 // make a copy to avoid iteration on modified list
336 // (may be cleared by attribute changed call)
337 std::list<ModelAPI_Attribute*> aWasChangedButBlocked = myWasChangedButBlocked;
338 myWasChangedButBlocked.clear();
339 std::list<ModelAPI_Attribute*>::iterator aChangedIter = aWasChangedButBlocked.begin();
340 for(; aChangedIter != aWasChangedButBlocked.end(); aChangedIter++) {
341 myObject->attributeChanged((*aChangedIter)->id());
343 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
344 ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
346 myWasChangedButBlocked.clear();
353 void Model_Data::erase()
355 if (!myLab.IsNull()) {
356 if (myLab.HasAttribute()) {
357 // remove in order to clear back references in other objects
358 std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
359 referencesToObjects(aRefs);
360 std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator
361 anAttrIter = aRefs.begin();
362 for(; anAttrIter != aRefs.end(); anAttrIter++) {
363 std::list<ObjectPtr>::iterator aReferenced = anAttrIter->second.begin();
364 for(; aReferenced != anAttrIter->second.end(); aReferenced++) {
365 if (aReferenced->get() && (*aReferenced)->data()->isValid()) {
366 std::shared_ptr<Model_Data> aData =
367 std::dynamic_pointer_cast<Model_Data>((*aReferenced)->data());
368 aData->removeBackReference(myAttrs[anAttrIter->first]);
374 myLab.ForgetAllAttributes();
378 // indexes in the state array
380 STATE_INDEX_STATE = 1, // the state type itself
381 STATE_INDEX_TRANSACTION = 2, // transaction ID
384 /// Returns the label array, initialises it by default values if not exists
385 static Handle(TDataStd_IntegerArray) stateArray(TDF_Label& theLab)
387 Handle(TDataStd_IntegerArray) aStateArray;
388 if (!theLab.FindAttribute(TDataStd_IntegerArray::GetID(), aStateArray)) {
389 aStateArray = TDataStd_IntegerArray::Set(theLab, 1, 2);
390 aStateArray->SetValue(STATE_INDEX_STATE, ModelAPI_StateMustBeUpdated); // default state
391 aStateArray->SetValue(STATE_INDEX_TRANSACTION, 0); // default transaction ID (not existing)
396 void Model_Data::execState(const ModelAPI_ExecState theState)
398 if (theState != ModelAPI_StateNothing) {
399 if (stateArray(myLab)->Value(STATE_INDEX_STATE) != (int)theState) {
400 stateArray(myLab)->SetValue(STATE_INDEX_STATE, (int)theState);
405 ModelAPI_ExecState Model_Data::execState()
407 return ModelAPI_ExecState(stateArray(myLab)->Value(STATE_INDEX_STATE));
410 int Model_Data::updateID()
412 return stateArray(myLab)->Value(STATE_INDEX_TRANSACTION);
415 void Model_Data::setUpdateID(const int theID)
417 stateArray(myLab)->SetValue(STATE_INDEX_TRANSACTION, theID);
420 void Model_Data::setError(const std::string& theError, bool theSend)
422 execState(ModelAPI_StateExecFailed);
424 Events_InfoMessage("Model_Data", theError).send();
426 TDataStd_AsciiString::Set(myLab, theError.c_str());
429 void Model_Data::eraseErrorString()
431 myLab.ForgetAttribute(TDataStd_AsciiString::GetID());
434 std::string Model_Data::error() const
436 Handle(TDataStd_AsciiString) anErrorAttr;
437 if (myLab.FindAttribute(TDataStd_AsciiString::GetID(), anErrorAttr)) {
438 return std::string(anErrorAttr->Get().ToCString());
440 return std::string();
443 int Model_Data::featureId() const
445 return myLab.Father().Tag(); // tag of the feature label
448 void Model_Data::eraseBackReferences()
451 std::shared_ptr<ModelAPI_Result> aRes =
452 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
454 aRes->setIsConcealed(false);
457 void Model_Data::removeBackReference(FeaturePtr theFeature, std::string theAttrID)
459 AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
460 removeBackReference(anAttribute);
463 void Model_Data::removeBackReference(AttributePtr theAttr)
465 if (myRefsToMe.find(theAttr) == myRefsToMe.end())
468 myRefsToMe.erase(theAttr);
470 // remove concealment immideately: on deselection it must be posible to reselect in GUI the same
471 FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttr->owner());
472 if (aFeatureOwner.get() &&
473 ModelAPI_Session::get()->validators()->isConcealed(aFeatureOwner->getKind(), theAttr->id())) {
474 updateConcealmentFlag();
478 void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
479 const bool theApplyConcealment)
481 // it is possible to add the same attribute twice: may be last time the owner was not Stable...
482 AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
483 if (myRefsToMe.find(anAttribute) == myRefsToMe.end())
484 myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
486 if (theApplyConcealment && theFeature->isStable() &&
487 ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
488 std::shared_ptr<ModelAPI_Result> aRes =
489 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
490 // the second condition is for history upper than concealment causer, so the feature result may
491 // be displayed and previewed; also for avoiding of quick show/hide on history
493 if (aRes && !theFeature->isDisabled()) {
494 aRes->setIsConcealed(true);
499 void Model_Data::updateConcealmentFlag()
501 std::set<AttributePtr>::iterator aRefsIter = myRefsToMe.begin();
502 for(; aRefsIter != myRefsToMe.end(); aRefsIter++) {
503 if (aRefsIter->get()) {
504 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefsIter)->owner());
505 if (aFeature.get() && !aFeature->isDisabled() && aFeature->isStable()) {
506 if (ModelAPI_Session::get()->validators()->isConcealed(
507 aFeature->getKind(), (*aRefsIter)->id())) {
508 std::shared_ptr<ModelAPI_Result> aRes =
509 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
511 aRes->setIsConcealed(true); // set concealed
518 std::shared_ptr<ModelAPI_Result> aRes =
519 std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
521 aRes->setIsConcealed(false);
525 std::set<std::string> set_union(const std::set<std::string>& theLeft,
526 const std::set<std::string>& theRight)
528 std::set<std::string> aResult;
529 aResult.insert(theLeft.begin(), theLeft.end());
530 aResult.insert(theRight.begin(), theRight.end());
534 std::set<std::string> usedParameters(const AttributePointPtr& theAttribute)
536 std::set<std::string> anUsedParameters;
537 for (int aComponent = 0; aComponent < 3; ++aComponent)
538 anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
539 return anUsedParameters;
542 std::set<std::string> usedParameters(const AttributePoint2DPtr& theAttribute)
544 std::set<std::string> anUsedParameters;
545 for (int aComponent = 0; aComponent < 2; ++aComponent)
546 anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
547 return anUsedParameters;
550 std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters)
552 std::list<ResultParameterPtr> aResult;
553 std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
554 for (; aParamIt != theParameters.cend(); ++aParamIt) {
555 const std::string& aName = *aParamIt;
557 ResultParameterPtr aParam;
558 // theSearcher is not needed here: in expressions
559 // of features the parameters history is not needed
560 if (ModelAPI_Tools::findVariable(FeaturePtr(), aName, aValue, aParam))
561 aResult.push_back(aParam);
566 void Model_Data::referencesToObjects(
567 std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs)
569 static Model_ValidatorsFactory* aValidators =
570 static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
571 FeaturePtr aMyFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(myObject);
573 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
574 std::list<ObjectPtr> aReferenced; // not inside of cycle to avoid excess memory management
575 for(; anAttr != myAttrs.end(); anAttr++) {
576 // skip not-case attributes, that really may refer to anything not-used (issue 671)
577 if (aMyFeature.get() && !aValidators->isCase(aMyFeature, anAttr->second->id()))
580 std::string aType = anAttr->second->attributeType();
581 if (aType == ModelAPI_AttributeReference::typeId()) { // reference to object
582 std::shared_ptr<ModelAPI_AttributeReference> aRef = std::dynamic_pointer_cast<
583 ModelAPI_AttributeReference>(anAttr->second);
584 aReferenced.push_back(aRef->value());
585 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { // reference to attribute or object
586 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = std::dynamic_pointer_cast<
587 ModelAPI_AttributeRefAttr>(anAttr->second);
588 if (aRef->isObject()) {
589 aReferenced.push_back(aRef->object());
591 AttributePtr anAttr = aRef->attr();
593 aReferenced.push_back(anAttr->owner());
595 } else if (aType == ModelAPI_AttributeRefList::typeId()) { // list of references
596 aReferenced = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr->second)->list();
597 } else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute
598 std::shared_ptr<ModelAPI_AttributeSelection> aRef = std::dynamic_pointer_cast<
599 ModelAPI_AttributeSelection>(anAttr->second);
600 aReferenced.push_back(aRef->context());
601 } else if (aType == ModelAPI_AttributeSelectionList::typeId()) { // list of selection attributes
602 std::shared_ptr<ModelAPI_AttributeSelectionList> aRef = std::dynamic_pointer_cast<
603 ModelAPI_AttributeSelectionList>(anAttr->second);
604 for(int a = aRef->size() - 1; a >= 0; a--) {
605 aReferenced.push_back(aRef->value(a)->context());
607 } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
608 std::shared_ptr<ModelAPI_AttributeRefAttrList> aRefAttr = std::dynamic_pointer_cast<
609 ModelAPI_AttributeRefAttrList>(anAttr->second);
610 std::list<std::pair<ObjectPtr, AttributePtr> > aRefs = aRefAttr->list();
611 std::list<std::pair<ObjectPtr, AttributePtr> >::const_iterator anIt = aRefs.begin(),
613 for (; anIt != aLast; anIt++) {
614 aReferenced.push_back(anIt->first);
616 } else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute
617 AttributeIntegerPtr anAttribute =
618 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttr->second);
619 std::set<std::string> anUsedParameters = anAttribute->usedParameters();
620 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
621 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
622 } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute
623 AttributeDoublePtr anAttribute =
624 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr->second);
625 std::set<std::string> anUsedParameters = anAttribute->usedParameters();
626 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
627 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
628 } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute
629 AttributePointPtr anAttribute =
630 std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr->second);
631 std::set<std::string> anUsedParameters = usedParameters(anAttribute);
632 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
633 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
634 } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute
635 AttributePoint2DPtr anAttribute =
636 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->second);
637 std::set<std::string> anUsedParameters = usedParameters(anAttribute);
638 std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
639 aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
641 continue; // nothing to do, not reference
643 if (!aReferenced.empty()) {
644 theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
650 /// makes copy of all attributes on the given label and all sub-labels
651 static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) {
652 TDF_AttributeIterator anAttrIter(theSource);
653 for(; anAttrIter.More(); anAttrIter.Next()) {
654 Handle(TDF_Attribute) aTargetAttr;
655 if (!theDestination.FindAttribute(anAttrIter.Value()->ID(), aTargetAttr)) {
656 // create a new attribute if not yet exists in the destination
657 aTargetAttr = anAttrIter.Value()->NewEmpty();
658 theDestination.AddAttribute(aTargetAttr);
660 // no special relocation, empty map, but self-relocation is on: copy references w/o changes
661 Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(Standard_True);
662 anAttrIter.Value()->Paste(aTargetAttr, aRelocTable);
664 // copy the sub-labels content
665 TDF_ChildIterator aSubLabsIter(theSource);
666 for(; aSubLabsIter.More(); aSubLabsIter.Next()) {
667 copyAttrs(aSubLabsIter.Value(), theDestination.FindChild(aSubLabsIter.Value().Tag()));
671 void Model_Data::copyTo(std::shared_ptr<ModelAPI_Data> theTarget)
673 TDF_Label aTargetRoot = std::dynamic_pointer_cast<Model_Data>(theTarget)->label();
674 copyAttrs(myLab, aTargetRoot);
675 // reinitialize Model_Attributes by TDF_Attributes set
676 std::shared_ptr<Model_Data> aTData = std::dynamic_pointer_cast<Model_Data>(theTarget);
677 aTData->myAttrs.clear();
678 theTarget->owner()->initAttributes(); // reinit feature attributes
681 bool Model_Data::isInHistory()
683 return myFlags->Value(kFlagInHistory) == Standard_True;
686 void Model_Data::setIsInHistory(const bool theFlag)
688 return myFlags->SetValue(kFlagInHistory, theFlag);
691 bool Model_Data::isDeleted()
693 return myFlags->Value(kFlagDeleted) == Standard_True;
696 void Model_Data::setIsDeleted(const bool theFlag)
698 return myFlags->SetValue(kFlagDeleted, theFlag);
701 bool Model_Data::isDisplayed()
703 if (!myObject.get() || !myObject->document().get() || // object is in valid
704 myFlags->Value(kFlagDisplayed) != Standard_True) // or it was not displayed before
706 if (myObject->document()->isActive()) // for active documents it must be ok anyway
708 // any object from the root document except part result may be displayed
709 if (myObject->document() == ModelAPI_Session::get()->moduleDocument() &&
710 myObject->groupName() != ModelAPI_ResultPart::group())
715 void Model_Data::setDisplayed(const bool theDisplay)
717 if (theDisplay != isDisplayed()) {
718 myFlags->SetValue(kFlagDisplayed, theDisplay);
719 static Events_Loop* aLoop = Events_Loop::loop();
720 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
721 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
722 aECreator->sendUpdated(myObject, EVENT_DISP);
726 std::shared_ptr<ModelAPI_Data> Model_Data::invalidPtr()
731 std::shared_ptr<ModelAPI_Data> Model_Data::invalidData()
736 std::shared_ptr<ModelAPI_Object> Model_Data::owner()