From 52d2c585a70385e30f13898f46ee5e27f5dbccdf Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 14 Nov 2017 10:24:21 +0300 Subject: [PATCH] Task 2.1. Management of result names Implement special keyword "main_argument" to mark concealed attribute as granting its name in case of several concealed attributes in the feature when the main attribute is not first. --- src/Config/Config_AttributeMessage.cpp | 10 ++++++++++ src/Config/Config_AttributeMessage.h | 5 +++++ src/Config/Config_FeatureReader.cpp | 5 ++++- src/Config/Config_Keywords.h | 1 + src/Model/Model_Session.cpp | 3 +++ src/Model/Model_Validator.cpp | 14 ++++++++++++++ src/Model/Model_Validator.h | 8 ++++++++ src/ModelAPI/ModelAPI_Tools.cpp | 10 ++++++++-- src/ModelAPI/ModelAPI_Validator.h | 6 ++++++ 9 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/Config/Config_AttributeMessage.cpp b/src/Config/Config_AttributeMessage.cpp index b8d4de423..32051337c 100644 --- a/src/Config/Config_AttributeMessage.cpp +++ b/src/Config/Config_AttributeMessage.cpp @@ -84,3 +84,13 @@ void Config_AttributeMessage::setCases(const std::list > myCases; @@ -66,6 +67,8 @@ public: CONFIG_EXPORT bool isObligatory() const; /// Returns true if attribute should conceal input features CONFIG_EXPORT bool isConcealment() const; + /// Returns true if attribute is a main argument of the feature + CONFIG_EXPORT bool isMainArgument() const; /// Returns container of ids of pair of a case and switches CONFIG_EXPORT const std::list >& getCases() const; /// Sets ids of pair of a case and switches @@ -79,6 +82,8 @@ public: CONFIG_EXPORT void setConcealment(bool isConcealment); /// Set attribute's obligatory state CONFIG_EXPORT void setObligatory(bool isObligatory); + /// Set a state that the attribute is a main argument of the feature + CONFIG_EXPORT void setMainArgument(bool isMainArg); }; #endif // ATTRIBUTE_MESSAGE_H diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 71261ba95..6115d715f 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -84,7 +84,10 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode) if (!anAttributeID.empty()) { aMessage->setAttributeId(anAttributeID); aMessage->setObligatory(getBooleanAttribute(theNode, ATTR_OBLIGATORY, true)); - aMessage->setConcealment(getBooleanAttribute(theNode, ATTR_CONCEALMENT, false)); + bool isConcealment = getBooleanAttribute(theNode, ATTR_CONCEALMENT, false); + aMessage->setConcealment(isConcealment); + bool isMainArg = isConcealment && getBooleanAttribute(theNode, ATTR_MAIN_ARG, false); + aMessage->setMainArgument(isMainArg); std::list > aCases; xmlNodePtr aCaseNode = diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 95a54bb42..da19a07e6 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -92,6 +92,7 @@ const static char* ATTR_CONCEALMENT = "concealment"; const static char* ATTR_USE_RESET = "use_reset"; const static char* ATTR_GREED = "greed"; const static char* ATTR_MODIFIED_IN_EDIT = "modified_in_edit"; +const static char* ATTR_MAIN_ARG = "main_argument"; // WDG_INFO properties const static char* INFO_WDG_TEXT = FEATURE_TEXT; diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 065e6276d..8a0b7b89f 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -464,6 +464,9 @@ void Model_Session::processEvent(const std::shared_ptr& theMessa if(aMsgAttr->isConcealment()) { validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId()); } + if(aMsgAttr->isMainArgument()) { + validators()->registerMainArgument(aMsgAttr->featureId(), aMsgAttr->attributeId()); + } const std::list >& aCases = aMsgAttr->getCases(); if (!aCases.empty()) { validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), aCases); diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index fa0235b0d..41fa0f701 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -363,3 +363,17 @@ bool Model_ValidatorsFactory::isCase(FeaturePtr theFeature, std::string theAttri } return anInCase; // if no additional conditions, this attribute is the case to be validated } + +void Model_ValidatorsFactory::registerMainArgument(std::string theFeature, + std::string theAttribute) +{ + std::map::iterator aFound = myMainArgument.find(theFeature); + if (aFound == myMainArgument.end()) + myMainArgument[theFeature] = theAttribute; +} + +bool Model_ValidatorsFactory::isMainArgument(std::string theFeature, std::string theAttribute) +{ + std::map::iterator aFound = myMainArgument.find(theFeature); + return aFound != myMainArgument.end() && aFound->second == theAttribute; +} diff --git a/src/Model/Model_Validator.h b/src/Model/Model_Validator.h index 014d7ce67..939cdf213 100644 --- a/src/Model/Model_Validator.h +++ b/src/Model/Model_Validator.h @@ -56,6 +56,8 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory // (switchId (ID of the attribute) and case Ids (possible values of the switch attribute)) std::map > > > myCases; + /// Stores main attribute for each feature + std::map myMainArgument; public: /// Registers the instance of the validator by the ID @@ -115,6 +117,12 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory /// Returns true if the attribute must be checked (the case is selected) virtual bool isCase(FeaturePtr theFeature, std::string theAttribute); + /// Register the attribute as a main argument of the feature + virtual void registerMainArgument(std::string theFeature, std::string theAttribute); + + /// Returns true is the attribute is a main argument of the feature + virtual bool isMainArgument(std::string theFeature, std::string theAttribute); + protected: /// Adds the defualt validators that are usefull for all features. diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 7956c4dbb..f22b73c23 100755 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -658,14 +658,20 @@ std::string getDefaultName(const std::shared_ptr& theResult, ListOfReferences::const_iterator aFoundRef = aReferences.end(); for (ListOfReferences::const_iterator aRefIt = aReferences.begin(); aRefIt != aReferences.end(); ++aRefIt) { - if (aSession->validators()->isConcealed(anOwner->getKind(), aRefIt->first)) { + bool isConcealed = aSession->validators()->isConcealed(anOwner->getKind(), aRefIt->first); + bool isMainArg = isConcealed && + aSession->validators()->isMainArgument(anOwner->getKind(), aRefIt->first); + if (isConcealed) { // check the referred object is a Body // (for example, ExtrusionCut has a sketch as a first attribute which is concealing) bool isBody = aRefIt->second.size() > 1 || (aRefIt->second.size() == 1 && aRefIt->second.front()->groupName() == ModelAPI_ResultBody::group()); - if (isBody && (aFoundRef == aReferences.end() || + if (isBody && (isMainArg || aFoundRef == aReferences.end() || aData->isPrecedingAttribute(aRefIt->first, aFoundRef->first))) aFoundRef = aRefIt; + + if (isMainArg) + break; } } diff --git a/src/ModelAPI/ModelAPI_Validator.h b/src/ModelAPI/ModelAPI_Validator.h index 8f584ffef..a2c8af67a 100644 --- a/src/ModelAPI/ModelAPI_Validator.h +++ b/src/ModelAPI/ModelAPI_Validator.h @@ -115,6 +115,12 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory /// Returns true that it was registered that attribute conceals the referenced result virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0; + /// Register the attribute as a main argument of the feature + virtual void registerMainArgument(std::string theFeature, std::string theAttribute) = 0; + + /// Returns true is the attribute is a main argument of the feature + virtual bool isMainArgument(std::string theFeature, std::string theAttribute) = 0; + /// Register the case-attribute: this attribute is checked only if its case is selected virtual void registerCase(std::string theFeature, std::string theAttribute, const std::list >& theCases) = 0; -- 2.30.2