Salome HOME
Issue #839 Selection of Part sub-results
authornds <nds@opencascade.com>
Wed, 16 Sep 2015 15:09:31 +0000 (18:09 +0300)
committernds <nds@opencascade.com>
Wed, 16 Sep 2015 15:10:01 +0000 (18:10 +0300)
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp [new file with mode: 0755]
src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.h [new file with mode: 0755]
src/FeaturesPlugin/placement_widget.xml
src/FeaturesPlugin/rotation_widget.xml
src/FeaturesPlugin/translation_widget.xml

index 7650ed84ffa183669a595c95410d833ed4571417..ab09c8cf301e55624aa1d34b1157d80ae2cc653c 100644 (file)
@@ -24,6 +24,7 @@ SET(PROJECT_HEADERS
     FeaturesPlugin_RevolutionBoolean.h
     FeaturesPlugin_RevolutionCut.h
     FeaturesPlugin_RevolutionFuse.h
+    FeaturesPlugin_ValidatorTransform.h
 )
 
 SET(PROJECT_SOURCES
@@ -46,6 +47,7 @@ SET(PROJECT_SOURCES
     FeaturesPlugin_RevolutionBoolean.cpp
     FeaturesPlugin_RevolutionCut.cpp
     FeaturesPlugin_RevolutionFuse.cpp
+    FeaturesPlugin_ValidatorTransform.cpp
 )
 
 SET(XML_RESOURCES
index a92358003b25f5f038796b34e0e9182bf20fc107..26a5b37e6c9f903e42aeb0a326399555abab619f 100644 (file)
@@ -16,6 +16,7 @@
 #include <FeaturesPlugin_RevolutionCut.h>
 #include <FeaturesPlugin_RevolutionFuse.h>
 #include <FeaturesPlugin_Rotation.h>
+#include <FeaturesPlugin_ValidatorTransform.h>
 
 #include <ModelAPI_Session.h>
 
@@ -30,6 +31,11 @@ static FeaturesPlugin_Plugin* MY_FEATURES_INSTANCE = new FeaturesPlugin_Plugin()
 
 FeaturesPlugin_Plugin::FeaturesPlugin_Plugin()
 {
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  aFactory->registerValidator("FeaturesPlugin_ValidatorTransform",
+                              new FeaturesPlugin_ValidatorTransform);  
+
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
 }
diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp
new file mode 100755 (executable)
index 0000000..570d1fb
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include "FeaturesPlugin_ValidatorTransform.h"
+
+#include "ModelAPI_AttributeSelectionList.h"
+#include "ModelAPI_ResultPart.h"
+#include "ModelAPI_ResultBody.h"
+#include "ModelAPI_ResultCompSolid.h"
+#include "ModelAPI_Session.h"
+
+bool FeaturesPlugin_ValidatorTransform::isValid(const AttributePtr& theAttribute,
+                                                const std::list<std::string>& theArguments,
+                                                std::string& theError) const
+{
+  bool aValid = true;
+  std::string anAttributeType = theAttribute->attributeType();
+  if (anAttributeType != ModelAPI_AttributeSelectionList::typeId()) {
+    theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    return false;
+  }
+
+  std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList = 
+                           std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+
+  DocumentPtr aDocument = theAttribute->owner()->document();
+  SessionPtr aMgr = ModelAPI_Session::get();
+  bool isPartSetDocument = aDocument == aMgr->moduleDocument();
+
+  std::string anErrorGroupName;
+  for(int i = 0; i < aCurSelList->size() && aValid; i++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
+    ResultPtr aResult = aSelAttribute->context();
+    if (isPartSetDocument) // PartSet document: Result Part is valid
+      aValid = aResult->groupName() == ModelAPI_ResultPart::group();
+    else { // Part document: Result CompSolid is valid
+      aValid = aResult->groupName() == ModelAPI_ResultBody::group();
+      if (aValid) {
+        ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+        aValid = aComp.get() != NULL;
+      }
+    }
+    if (!aValid)
+      anErrorGroupName = aResult->groupName();
+  }
+  if (!aValid) {
+    std::string aResultGroupName = isPartSetDocument ? ModelAPI_ResultPart::group()
+                                                     : ModelAPI_ResultBody::group();
+    theError = "Objects from the " + aResultGroupName  +
+                " group can be selected in the " + aDocument->kind() +
+                "document, but an objects from the " + anErrorGroupName +
+                " group is selected.";
+  }
+  return aValid;
+}
diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.h b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.h
new file mode 100755 (executable)
index 0000000..b1bb5c2
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        FeaturesPlugin_ValidatorTransform.h
+// Created:     16 Sep 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef FeaturesPlugin_ValidatorTransform_H
+#define FeaturesPlugin_ValidatorTransform_H
+
+#include "ModelAPI_AttributeValidator.h"
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class FeaturesPlugin_ValidatorTransform : public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments,
+                       std::string& theError) const;
+};
+
+#endif
index 4403f94f09b8673313334ffe352df3d2d4b1628c..48dab601c4aa4d2adc96854353534e1ed455fc6d 100644 (file)
@@ -7,6 +7,7 @@
     tooltip="Select a solid objects"
     type_choice=""
     concealment="true" >
+    <validator id="FeaturesPlugin_ValidatorTransform"/>
   </multi_selector>
   <shape_selector id="placement_start_shape"
     label="Select an object" 
index 3a25011b97d4cb4eaafc5564444ff553ca212645..d715df1524fc4c7c4e7a8f444cab7d48b2bee8c6 100755 (executable)
@@ -8,6 +8,7 @@
     type_choice=""
     use_choice="false"
     concealment="true">
+    <validator id="FeaturesPlugin_ValidatorTransform"/>
   </multi_selector>
   <shape_selector id="axis_object"
                   icon=":icons/axis.png"
index ad24f62840490dc661d9bc445e91d2a4bf286b9c..c9261206bfe3fd994e81769b712449a68ceecfaf 100644 (file)
@@ -7,6 +7,7 @@
     tooltip="Select a solid objects"
     type_choice=""
     concealment="true">
+    <validator id="FeaturesPlugin_ValidatorTransform"/>
   </multi_selector>
   <shape_selector id="axis_object"
                   icon=":icons/axis.png"