Salome HOME
Task 2.1. Management of result names
authorazv <azv@opencascade.com>
Tue, 14 Nov 2017 07:24:21 +0000 (10:24 +0300)
committerazv <azv@opencascade.com>
Tue, 14 Nov 2017 12:26:08 +0000 (15:26 +0300)
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
src/Config/Config_AttributeMessage.h
src/Config/Config_FeatureReader.cpp
src/Config/Config_Keywords.h
src/Model/Model_Session.cpp
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Validator.h

index b8d4de423075c7755ddcee4fad8806969afb7e87..32051337cd23c0e703978d8cd3146387bb639565 100644 (file)
@@ -84,3 +84,13 @@ void Config_AttributeMessage::setCases(const std::list<std::pair<std::string,
 {
   myCases = theCases;
 }
+
+bool Config_AttributeMessage::isMainArgument() const
+{
+  return myIsMainArgument;
+}
+
+void Config_AttributeMessage::setMainArgument(bool isMainArg)
+{
+  myIsMainArgument = isMainArg;
+}
index ad5279ed92b52c34b82977df6630a5bc09359c42..cb4ef232c79b2740c8768b8a49ccf716e3a57484 100644 (file)
@@ -41,6 +41,7 @@ class Config_AttributeMessage : public Events_Message
   std::string myFeatureId; ///< Attribute's feature's unique id
   bool myIsObligatory; ///< Required to be set by user, else it's feature is invalid.
   bool myIsConcealment; ///< If true, conceals features used as input
+  bool myIsMainArgument; ///< Mark attribute as a main argument of the feature
   ///< a list of pairs, if the attribute is placed inside paged containers: (case, switch)
   std::list<std::pair<std::string, std::string> > 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<std::pair<std::string, std::string> >& 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
index 71261ba95849971d0085bd12d102cdb38b42d0db..6115d715f7f76d90593e8bc51bebbc8492b78e3d 100644 (file)
@@ -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<std::pair<std::string, std::string> > aCases;
         xmlNodePtr aCaseNode =
index 95a54bb42ca7226ee5c27aea6cbc43963170f30c..da19a07e643d1a85b87774a1ef0ed5316bbbb175 100644 (file)
@@ -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;
index 065e6276dbd5e8e95bc5ac4ba7ea445040af3ad6..8a0b7b89f6d10bb8ee6cc6360eb848b3d39ea837 100644 (file)
@@ -464,6 +464,9 @@ void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessa
         if(aMsgAttr->isConcealment()) {
           validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
         }
+        if(aMsgAttr->isMainArgument()) {
+          validators()->registerMainArgument(aMsgAttr->featureId(), aMsgAttr->attributeId());
+        }
         const std::list<std::pair<std::string, std::string> >& aCases = aMsgAttr->getCases();
         if (!aCases.empty()) {
           validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), aCases);
index fa0235b0d2fd0cf804d9d34326fca00940f041dc..41fa0f7014a03e24137734cbd4bc447925905271 100644 (file)
@@ -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<std::string, std::string>::iterator aFound = myMainArgument.find(theFeature);
+  if (aFound == myMainArgument.end())
+    myMainArgument[theFeature] = theAttribute;
+}
+
+bool Model_ValidatorsFactory::isMainArgument(std::string theFeature, std::string theAttribute)
+{
+  std::map<std::string, std::string>::iterator aFound = myMainArgument.find(theFeature);
+  return aFound != myMainArgument.end() && aFound->second == theAttribute;
+}
index 014d7ce673aa0e54578b8f3d7cf216b2bfc374b9..939cdf21390017aebd1c22b3bc2de2de5e62e94e 100644 (file)
@@ -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<std::string, std::map<std::string,
           std::map<std::string, std::set<std::string> > > > myCases;
+  /// Stores main attribute for each feature
+  std::map<std::string, std::string> 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.
index 7956c4dbb91966ec0a54917e62e6c7d0777b0e2b..f22b73c23c1ce295cf320d64d933fa12440a4992 100755 (executable)
@@ -658,14 +658,20 @@ std::string getDefaultName(const std::shared_ptr<ModelAPI_Result>& 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;
     }
   }
 
index 8f584ffefb4d6205122c52ff48528a46a14bd273..a2c8af67abe69d060c96f75bcb140f12376753e4 100644 (file)
@@ -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<std::pair<std::string, std::string> >& theCases) = 0;