#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_ResultPart.h>
-#include <ModelAPI_ResultCompSolid.h>
#include <ModelAPI_Tools.h>
#include <Model_Validator.h>
#include <TDataStd_Name.hxx>
#include <TDataStd_AsciiString.hxx>
#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_UAttribute.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_RelocationTable.hxx>
static const int kFlagDisplayed = 1;
// 2 - is deleted (for results) or not
static const int kFlagDeleted = 2;
+// TDataStd_Integer - 0 if the name of the object is generated automatically,
+// otherwise the name is defined by user
+Standard_GUID kUSER_DEFINED_NAME("9c694d18-a83c-4a56-bc9b-8020628a8244");
// invalid data
const static std::shared_ptr<ModelAPI_Data> kInvalid(new Model_Data());
isModified = true;
} else {
isModified = !aName->Get().IsEqual(theName.c_str());
- if (isModified)
+ if (isModified) {
aName->Set(theName.c_str());
+
+ // check the name of result is defined by user
+ // (name of result does not composed of the name of feature and the result index)
+ bool isUserDefined = true;
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+ if (aResult) {
+ std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult, false).first;
+ isUserDefined = aDefaultName != theName;
+ }
+ if (isUserDefined) {
+ // name is user-defined, thus special attribute is set
+ TDataStd_UAttribute::Set(myLab, kUSER_DEFINED_NAME);
+ }
+ }
}
if (mySendAttributeUpdated && isModified)
ModelAPI_ObjectRenamedMessage::send(myObject, anOldName, theName, this);
#endif
}
+bool Model_Data::hasUserDefinedName() const
+{
+ return myLab.IsAttribute(kUSER_DEFINED_NAME);
+}
+
AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
{
AttributePtr aResult;
void Model_Data::eraseBackReferences()
{
myRefsToMe.clear();
- std::shared_ptr<ModelAPI_Result> aRes =
- std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
- if (aRes)
+ std::shared_ptr<ModelAPI_Result> aRes = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+ if (aRes) {
aRes->setIsConcealed(false);
+ }
}
-void Model_Data::removeBackReference(FeaturePtr theFeature, std::string theAttrID)
+void Model_Data::removeBackReference(ObjectPtr theObject, std::string theAttrID)
{
- AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
+ AttributePtr anAttribute = theObject->data()->attribute(theAttrID);
removeBackReference(anAttribute);
}
void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
const bool theApplyConcealment)
{
- // it is possible to add the same attribute twice: may be last time the owner was not Stable...
- AttributePtr anAttribute = theFeature->data()->attribute(theAttrID);
- if (myRefsToMe.find(anAttribute) == myRefsToMe.end())
- myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
+ addBackReference(ObjectPtr(theFeature), theAttrID);
if (theApplyConcealment && theFeature->isStable() &&
ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
- std::shared_ptr<ModelAPI_Result> aRes =
- std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+ std::shared_ptr<ModelAPI_Result> aRes = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
// the second condition is for history upper than concealment causer, so the feature result may
// be displayed and previewed; also for avoiding of quick show/hide on history
// moving deep down
}
}
+void Model_Data::addBackReference(ObjectPtr theObject, std::string theAttrID)
+{
+ // it is possible to add the same attribute twice: may be last time the owner was not Stable...
+ AttributePtr anAttribute = theObject->data()->attribute(theAttrID);
+ if (myRefsToMe.find(anAttribute) == myRefsToMe.end())
+ myRefsToMe.insert(anAttribute);
+}
+
void Model_Data::updateConcealmentFlag()
{
std::set<AttributePtr>::iterator aRefsIter = myRefsToMe.begin();
return anUsedParameters;
}
-std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters)
+std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters,
+ const DocumentPtr& theDocument)
{
std::list<ResultParameterPtr> aResult;
std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
ResultParameterPtr aParam;
// theSearcher is not needed here: in expressions
// of features the parameters history is not needed
- if (ModelAPI_Tools::findVariable(FeaturePtr(), aName, aValue, aParam))
+ if (ModelAPI_Tools::findVariable(FeaturePtr(), aName, aValue, aParam, theDocument))
aResult.push_back(aParam);
}
return aResult;
}
} else if (aType == ModelAPI_AttributeRefList::typeId()) { // list of references
aReferenced = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr)->list();
- } else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute
+ }
+ else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute
std::shared_ptr<ModelAPI_AttributeSelection> aRef = std::dynamic_pointer_cast<
- ModelAPI_AttributeSelection>(anAttr);
- aReferenced.push_back(aRef->context());
+ ModelAPI_AttributeSelection>(anAttr);
+ FeaturePtr aRefFeat = aRef->contextFeature();
+ if (aRefFeat.get()) { // reference to all results of the referenced feature
+ const std::list<ResultPtr>& allRes = aRefFeat->results();
+ std::list<ResultPtr>::const_iterator aRefRes = allRes.cbegin();
+ for(; aRefRes != allRes.cend(); aRefRes++) {
+ aReferenced.push_back(*aRefRes);
+ }
+ } else {
+ aReferenced.push_back(aRef->context());
+ }
} else if (aType == ModelAPI_AttributeSelectionList::typeId()) { // list of selection attributes
std::shared_ptr<ModelAPI_AttributeSelectionList> aRef = std::dynamic_pointer_cast<
ModelAPI_AttributeSelectionList>(anAttr);
for(int a = 0, aSize = aRef->size(); a < aSize; ++a) {
- aReferenced.push_back(aRef->value(a)->context());
+ FeaturePtr aRefFeat = aRef->value(a)->contextFeature();
+ if (aRefFeat.get()) { // reference to all results of the referenced feature
+ const std::list<ResultPtr>& allRes = aRefFeat->results();
+ std::list<ResultPtr>::const_iterator aRefRes = allRes.cbegin();
+ for (; aRefRes != allRes.cend(); aRefRes++) {
+ aReferenced.push_back(*aRefRes);
+ }
+ } else {
+ aReferenced.push_back(aRef->value(a)->context());
+ }
}
} else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
std::shared_ptr<ModelAPI_AttributeRefAttrList> aRefAttr = std::dynamic_pointer_cast<
AttributeIntegerPtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttr);
std::set<std::string> anUsedParameters = anAttribute->usedParameters();
- std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
+ std::list<ResultParameterPtr> aParameters =
+ findVariables(anUsedParameters, owner()->document());
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
} else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute
AttributeDoublePtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr);
std::set<std::string> anUsedParameters = anAttribute->usedParameters();
- std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
+ std::list<ResultParameterPtr> aParameters =
+ findVariables(anUsedParameters, owner()->document());
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
} else if (aType == GeomDataAPI_Point::typeId()) { // point attribute
AttributePointPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr);
std::set<std::string> anUsedParameters = usedParameters(anAttribute);
- std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
+ std::list<ResultParameterPtr> aParameters =
+ findVariables(anUsedParameters, owner()->document());
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
} else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute
AttributePoint2DPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr);
std::set<std::string> anUsedParameters = usedParameters(anAttribute);
- std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters);
+ std::list<ResultParameterPtr> aParameters =
+ findVariables(anUsedParameters, owner()->document());
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
} else
continue; // nothing to do, not reference