]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Validators improvements (arguments for feature validator)
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 4 Sep 2014 06:12:29 +0000 (10:12 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 4 Sep 2014 06:12:29 +0000 (10:12 +0400)
21 files changed:
src/Config/Config_PropManager.h
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Curve.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Curve.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/Model/CMakeLists.txt
src/Model/Model_PluginManager.cpp
src/Model/Model_ResultValidators.cpp [deleted file]
src/Model/Model_ResultValidators.h [deleted file]
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/ModelAPI_Validator.h
src/ModuleBase/ModuleBase_ResultValidators.cpp [deleted file]
src/ModuleBase/ModuleBase_ResultValidators.h [deleted file]
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_ResultValidators.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ResultValidators.h [new file with mode: 0644]
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_Workshop.cpp

index eae15b1c38a782adae285a479aa6894fc6aea024..496cddd6dce8e9017b095168dca77639bb39fdec 100644 (file)
@@ -27,10 +27,10 @@ class Config_PropManager
    * Returns True if the property succesfully registered
    */
   CONFIG_EXPORT static bool registerProp(const std::string& theSection, const std::string& theName,
-                           const std::string& theTitle, Config_Prop::PropType theType,
-                           const std::string& theValue);
+    const std::string& theTitle, Config_Prop::PropType theType, const std::string& theValue);
 
-  CONFIG_EXPORT static Config_Prop* findProp(const std::string& theSection, const std::string& theName);
+  CONFIG_EXPORT static Config_Prop* findProp(
+    const std::string& theSection, const std::string& theName);
 
   CONFIG_EXPORT static Config_Properties getProperties();
 
@@ -41,14 +41,17 @@ class Config_PropManager
   CONFIG_EXPORT static Config_Properties getProperties(const std::string& theSection);
 
   //! Returns value of the property by its owner, section, and name
-  CONFIG_EXPORT static std::string string(const std::string& theSection, const std::string& theName,
-                            const std::string& theDefault);
-  CONFIG_EXPORT static std::vector<int> color(const std::string& theSection, const std::string& theName,
-                                const std::string& theDefault);
-  CONFIG_EXPORT static int integer(const std::string& theSection, const std::string& theName,
-                     const std::string& theDefault);
-  CONFIG_EXPORT static double real(const std::string& theSection, const std::string& theName,
-                     const std::string& theDefault);
+  CONFIG_EXPORT static std::string string(
+    const std::string& theSection, const std::string& theName, const std::string& theDefault);
+  
+  CONFIG_EXPORT static std::vector<int> color(
+    const std::string& theSection, const std::string& theName, const std::string& theDefault);
+  
+  CONFIG_EXPORT static int integer(
+    const std::string& theSection, const std::string& theName, const std::string& theDefault);
+  
+  CONFIG_EXPORT static double real(
+    const std::string& theSection, const std::string& theName, const std::string& theDefault);
 
  private:
   CONFIG_EXPORT static Config_Properties myProps;
index 0b2eb97638ccd07f2e16601243f3e76c9c373da6..b46cafcee07563ca52c13238d28301ac1a79a89d 100644 (file)
@@ -21,6 +21,7 @@ SET(PROJECT_HEADERS
     GeomAPI_Edge.h
     GeomAPI_AISObject.h
     GeomAPI_IPresentable.h
+    GeomAPI_Curve.h 
 )
 
 SET(PROJECT_SOURCES
@@ -39,6 +40,7 @@ SET(PROJECT_SOURCES
     GeomAPI_Shape.cpp
     GeomAPI_Edge.cpp
     GeomAPI_AISObject.cpp
+    GeomAPI_Curve.cpp
 )
 
 ADD_DEFINITIONS(-DGEOMAPI_EXPORTS ${CAS_DEFINITIONS})
diff --git a/src/GeomAPI/GeomAPI_Curve.cpp b/src/GeomAPI/GeomAPI_Curve.cpp
new file mode 100644 (file)
index 0000000..77bf7d9
--- /dev/null
@@ -0,0 +1,49 @@
+// File:        GeomAPI_Curve.cpp
+// Created:     04 Sep 2014
+// Author:      Mikhail PONIKAROV
+
+#include<GeomAPI_Curve.h>
+
+#include <TopoDS_Shape.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_Circle.hxx>
+#include <BRep_Tool.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+
+#define MY_CURVE (*(static_cast<Handle_Geom_Curve*>(myImpl)))
+
+GeomAPI_Curve::GeomAPI_Curve()
+    : GeomAPI_Interface(new Handle_Geom_Curve())
+{
+}
+
+GeomAPI_Curve::GeomAPI_Curve(const boost::shared_ptr<GeomAPI_Shape>& theShape)
+  : GeomAPI_Interface(new Handle_Geom_Curve()) // initially it is null
+{
+  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+  TopoDS_Edge anEdge = TopoDS::Edge(aShape);
+  if (!anEdge.IsNull()) {
+    Standard_Real aStart, anEnd;
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aStart, anEnd);
+    if (!aCurve.IsNull()) {
+      setImpl(&aCurve);
+    }
+  }
+}
+
+bool GeomAPI_Curve::isNull() const
+{
+  return MY_CURVE.IsNull() == Standard_True;
+}
+
+bool GeomAPI_Curve::isLine() const
+{
+  return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Line);
+}
+
+bool GeomAPI_Curve::isCircle() const
+{
+  return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
+}
diff --git a/src/GeomAPI/GeomAPI_Curve.h b/src/GeomAPI/GeomAPI_Curve.h
new file mode 100644 (file)
index 0000000..e4f4948
--- /dev/null
@@ -0,0 +1,36 @@
+// File:        GeomAPI_Curve.hxx
+// Created:     04 Sep 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomAPI_Curve_H_
+#define GeomAPI_Curve_H_
+
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+
+/**\class GeomAPI_Curve
+ * \ingroup DataModel
+ * \brief Interface to the generic curve object
+ */
+
+class GEOMAPI_EXPORT GeomAPI_Curve : public GeomAPI_Interface
+{
+ public:
+  /// Creation of empty (null) shape
+  GeomAPI_Curve();
+
+  /// Creates a curve from the shape (edge)
+  GeomAPI_Curve(const boost::shared_ptr<GeomAPI_Shape>& theShape);
+
+  /// Returns true if curve is not initialized
+  bool isNull() const;
+
+  /// Returns whether the curve is linear
+  virtual bool isLine() const;
+
+  /// Returns whether the curve is circular
+  virtual bool isCircle() const;
+
+};
+
+#endif
index 30e2f342522498a2ea66f752eedd880f513b7584..e51d30ca6bc6c75ecc79b3563163af554fb76c79 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <TopoDS_Shape.hxx>
 
-#define MY_PNT static_cast<gp_Pnt*>(myImpl)
+#define MY_SHAPE static_cast<TopoDS_Shape*>(myImpl)
 
 GeomAPI_Shape::GeomAPI_Shape()
     : GeomAPI_Interface(new TopoDS_Shape())
@@ -15,17 +15,17 @@ GeomAPI_Shape::GeomAPI_Shape()
 
 bool GeomAPI_Shape::isNull()
 {
-  return MY_SHAPE->IsNull();
+  return MY_SHAPE->IsNull() == Standard_True;
 }
 
 bool GeomAPI_Shape::isVertex() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
-  return aShape.TShape()->ShapeType() == TopAbs_VERTEX;
+  return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX;
 }
 
 bool GeomAPI_Shape::isEdge() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
-  return aShape.TShape()->ShapeType() == TopAbs_EDGE;
+  return aShape.ShapeType() == TopAbs_EDGE;
 }
index 64292dee39122146c42b86ed4511a8a825a6ecac..c2e3507b4cf94dffd0cef99587443da47b136ec4 100644 (file)
  * \ingroup DataModel
  * \brief Interface to the topological shape object
  */
-class TopoDS_Shape;
-
-#define MY_SHAPE static_cast<TopoDS_Shape*>(myImpl)
-
 class GEOMAPI_EXPORT GeomAPI_Shape : public GeomAPI_Interface
 {
  public:
index 63d79a60eb9d0c02433bb48cb561820c428e6449..1642fbaca30f73cd6ab6a0940e27de69f5309b09 100644 (file)
@@ -20,8 +20,7 @@ SET(PROJECT_HEADERS
     Model_ResultBody.h
     Model_ResultConstruction.h
     Model_ResultPart.h
-       Model_ResultValidators.h
-       Model_FeatureValidator.h
+    Model_FeatureValidator.h
 )
 
 SET(PROJECT_SOURCES
@@ -43,8 +42,7 @@ SET(PROJECT_SOURCES
     Model_ResultBody.cpp
     Model_ResultConstruction.cpp
     Model_ResultPart.cpp
-       Model_ResultValidators.cpp
-       Model_FeatureValidator.cpp
+    Model_FeatureValidator.cpp
 )
 
 SET(PROJECT_LIBRARIES
index c41d3922c9a9b5a0958327a9027d2273a210fc44..06893e6fc343c6615bac7b9f097d1cccb56af633 100644 (file)
@@ -134,7 +134,7 @@ void Model_PluginManager::processEvent(const Events_Message* theMessage)
     const Config_ValidatorMessage* aMsg = dynamic_cast<const Config_ValidatorMessage*>(theMessage);
     if (aMsg) {
       if (aMsg->attributeId().empty()) {  // feature validator
-        validators()->assignValidator(aMsg->validatorId(), aMsg->featureId());
+        validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->parameters());
       } else {  // attribute validator
         validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->attributeId(),
                                       aMsg->parameters());
diff --git a/src/Model/Model_ResultValidators.cpp b/src/Model/Model_ResultValidators.cpp
deleted file mode 100644 (file)
index 66840d4..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// File:        Model_ResultValidators.cpp
-// Created:     23 July 2014
-// Author:      Vitaly SMETANNIKOV
-
-#include "Model_ResultValidators.h"
-
-#include <ModelAPI_Result.h>
-#include <ModelAPI_Tools.h>
-#include <GeomAPI_Shape.h>
-
-#include <TopoDS_Shape.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
-#include <GeomAdaptor_Curve.hxx>
-
-ResultPtr result(const ObjectPtr theObject)
-{
-  return boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-}
-
-TopoDS_Shape shape(ResultPtr theResult)
-{
-  boost::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(theResult);
-  if (aShape)
-    return aShape->impl<TopoDS_Shape>();
-  return TopoDS_Shape();
-}
-
-bool Model_ResultPointValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  TopoDS_Shape aShape = shape(aResult);
-  if (aShape.IsNull())
-    return false;
-
-  return aShape.ShapeType() == TopAbs_VERTEX;
-}
-
-bool Model_ResultLineValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  TopoDS_Shape aShape = shape(aResult);
-  if (aShape.IsNull())
-    return false;
-
-  if (aShape.ShapeType() == TopAbs_EDGE) {
-    TopoDS_Edge aEdge = TopoDS::Edge(aShape);
-    Standard_Real aStart, aEnd;
-    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
-    GeomAdaptor_Curve aAdaptor(aCurve);
-    return aAdaptor.GetType() == GeomAbs_Line;
-  }
-  return false;
-}
-
-bool Model_ResultArcValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  TopoDS_Shape aShape = shape(aResult);
-  if (aShape.IsNull())
-    return false;
-
-  TopAbs_ShapeEnum aa = aShape.ShapeType();
-  if (aShape.ShapeType() == TopAbs_EDGE) {
-    TopoDS_Edge aEdge = TopoDS::Edge(aShape);
-    Standard_Real aStart, aEnd;
-    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
-    GeomAdaptor_Curve aAdaptor(aCurve);
-    return aAdaptor.GetType() == GeomAbs_Circle;
-  }
-  return false;
-}
-
diff --git a/src/Model/Model_ResultValidators.h b/src/Model/Model_ResultValidators.h
deleted file mode 100644 (file)
index dbbf60d..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// File:        Model_ResultValidators.h
-// Created:     23 July 2014
-// Author:      Vitaly SMETANNIKOV
-
-#ifndef Model_ResultValidators_H
-#define Model_ResultValidators_H
-
-#include "Model.h"
-#include <ModelAPI_ResultValidator.h>
-#include <ModelAPI_Object.h>
-
-class Model_ResultPointValidator : public ModelAPI_ResultValidator
-{
- public:
-  MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-class Model_ResultLineValidator : public ModelAPI_ResultValidator
-{
- public:
-  MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-class Model_ResultArcValidator : public ModelAPI_ResultValidator
-{
- public:
-  MODEL_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-#endif
index eaab5d3c3323ba145a4d98f081e59300c100ef45..a1741e3b7a81333723483afbb3d5f707f44fdefc 100644 (file)
@@ -3,7 +3,6 @@
 // Author:      Mikhail PONIKAROV
 
 #include <Model_Validator.h>
-#include <Model_ResultValidators.h>
 #include <Model_FeatureValidator.h>
 #include <ModelAPI_Feature.h>
 #include <Events_Error.h>
@@ -22,9 +21,30 @@ void Model_ValidatorsFactory::assignValidator(const std::string& theID,
                                               const std::string& theFeatureID)
 {
   if (myFeatures.find(theFeatureID) == myFeatures.end()) {
-    myFeatures[theFeatureID] = std::set<std::string>();
+    myFeatures[theFeatureID] = AttrValidators();
+  }
+  if (myFeatures[theFeatureID].find(theID) != myFeatures[theFeatureID].end()) {
+    //Events_Error::send(std::string("Validator ") + theID + 
+    //  " for feature " + theFeatureID + "is already registered");
+  } else {
+    myFeatures[theFeatureID][theID] = std::list<std::string>();
+  }
+}
+
+void Model_ValidatorsFactory::assignValidator(const std::string& theID,
+                                              const std::string& theFeatureID,
+                                              const std::list<std::string>& theArguments)
+{
+  if (myFeatures.find(theFeatureID) == myFeatures.end()) {
+    myFeatures[theFeatureID] = AttrValidators();
+  }
+
+  if (myFeatures[theFeatureID].find(theID) != myFeatures[theFeatureID].end()) {
+    //Events_Error::send(std::string("Validator ") + theID + 
+    //  " for feature " + theFeatureID + "is already registered");
+  } else {
+    myFeatures[theFeatureID][theID] = theArguments;
   }
-  myFeatures[theFeatureID].insert(theID);
 }
 
 void Model_ValidatorsFactory::assignValidator(const std::string& theID,
@@ -44,23 +64,24 @@ void Model_ValidatorsFactory::assignValidator(const std::string& theID,
   if (anAttr == aFeature->second.end()) {
     aFeature->second[theAttrID] = AttrValidators();
   }
-  aFeature->second[theAttrID].insert(
-      std::pair<std::string, std::list<std::string> >(theID, theArguments));
+  aFeature->second[theAttrID][theID] = theArguments;
 }
 
 void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
-                                         std::list<ModelAPI_Validator*>& theResult) const
+                                         std::list<ModelAPI_Validator*>& theResult,
+                                         std::list<std::list<std::string> >& theArguments) const
 {
-  std::map<std::string, std::set<std::string> >::const_iterator aFeature = myFeatures.find(
-      theFeatureID);
+  std::map<std::string, AttrValidators>::const_iterator aFeature = myFeatures.find(theFeatureID);
   if (aFeature != myFeatures.cend()) {
-    std::set<std::string>::const_iterator aValIter = aFeature->second.cbegin();
+    AttrValidators::const_iterator aValIter = aFeature->second.cbegin();
     for (; aValIter != aFeature->second.cend(); aValIter++) {
-      std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = myIDs.find(*aValIter);
+      std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = 
+        myIDs.find(aValIter->first);
       if (aFound == myIDs.end()) {
-        Events_Error::send(std::string("Validator ") + *aValIter + " was not registered");
+        Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered");
       } else {
         theResult.push_back(aFound->second);
+        theArguments.push_back(aValIter->second);
       }
     }
   }
@@ -95,9 +116,6 @@ void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
 Model_ValidatorsFactory::Model_ValidatorsFactory()
     : ModelAPI_ValidatorsFactory()
 {
-  registerValidator("Model_ResultPointValidator", new Model_ResultPointValidator);
-  registerValidator("Model_ResultLineValidator", new Model_ResultLineValidator);
-  registerValidator("Model_ResultArcValidator", new Model_ResultArcValidator);
   registerValidator("Model_FeatureValidator", new Model_FeatureValidator);
 }
 
index 56d65d18194d11aa799a9182a607ff4639bb2bdc..645c4bdc693271039f2ae640aa87090d4a67b99b 100644 (file)
@@ -26,10 +26,10 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
 {
  private:
   std::map<std::string, ModelAPI_Validator*> myIDs;  ///< map from ID to registered validator
+  /// validators IDs to list of arguments
+  typedef std::map<std::string, std::list<std::string> > AttrValidators;
   /// validators IDs by feature ID
-  std::map<std::string, std::set<std::string> > myFeatures;
-  /// set of pairs: validators IDs, list of arguments
-  typedef std::set<std::pair<std::string, std::list<std::string> > > AttrValidators;
+  std::map<std::string, AttrValidators> myFeatures;
   /// validators IDs and arguments by feature and attribute IDs
   std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
  public:
@@ -41,6 +41,11 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
                                             const std::string& theFeatureID);
 
+  /// Assigns validator to the feature with arguments of the validator
+  MODEL_EXPORT virtual void assignValidator(const std::string& theID,
+                                            const std::string& theFeatureID,
+                                            const std::list<std::string>& theArguments);
+
   /// Assigns validator to the attribute of the feature
   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
                                             const std::string& theFeatureID,
@@ -49,7 +54,8 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
 
   /// Provides a validator for the feature, returns NULL if no validator
   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
-                                       std::list<ModelAPI_Validator*>& theResult) const;
+                                       std::list<ModelAPI_Validator*>& theResult,
+                                       std::list<std::list<std::string> >& theArguments) const;
   /// Provides a validator for the attribute, returns NULL if no validator
   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
                                        const std::string& theAttrID,
index 6f9e26f2a765fbf4e8b221bfe30a510ba9a9934a..78754d074e3dd581c6ebb6ba97b7751af8566cb6 100644 (file)
@@ -61,6 +61,11 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
   /// Assigns validator to the feature
   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
 
+  /// Assigns validator to the feature with arguments of the validator
+  virtual void assignValidator(const std::string& theID,
+                                            const std::string& theFeatureID,
+                                            const std::list<std::string>& theArguments) = 0;
+
   /// Assigns validator to the attribute of the feature
   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID,
                                const std::string& theAttrID,
@@ -68,7 +73,8 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
 
   /// Provides a validator for the feature, returns NULL if no validator
   virtual void validators(const std::string& theFeatureID,
-                          std::list<ModelAPI_Validator*>& theResult) const = 0;
+                          std::list<ModelAPI_Validator*>& theResult,
+                          std::list<std::list<std::string> >& theArguments) const = 0;
   /// Provides a validator for the attribute, returns NULL if no validator
   virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
                           std::list<ModelAPI_Validator*>& theValidators,
diff --git a/src/ModuleBase/ModuleBase_ResultValidators.cpp b/src/ModuleBase/ModuleBase_ResultValidators.cpp
deleted file mode 100644 (file)
index 4fde043..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// File:        ModuleBase_ResultValidators.cpp
-// Created:     23 July 2014
-// Author:      Vitaly SMETANNIKOV
-
-#include "ModuleBase_ResultValidators.h"
-#include "ModuleBase_Tools.h"
-
-#include <ModelAPI_Result.h>
-#include <GeomAPI_Shape.h>
-
-#include <TopoDS_Shape.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
-#include <GeomAdaptor_Curve.hxx>
-
-ResultPtr result(const ObjectPtr theObject)
-{
-  return boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-}
-
-TopoDS_Shape shape(ResultPtr theResult)
-{
-  boost::shared_ptr<GeomAPI_Shape> aShape = ModuleBase_Tools::shape(theResult);
-  if (aShape)
-    return aShape->impl<TopoDS_Shape>();
-  return TopoDS_Shape();
-}
-
-bool ModuleBase_ResultPointValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  TopoDS_Shape aShape = shape(aResult);
-  if (aShape.IsNull())
-    return false;
-
-  return aShape.ShapeType() == TopAbs_VERTEX;
-}
-
-bool ModuleBase_ResultLineValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  TopoDS_Shape aShape = shape(aResult);
-  if (aShape.IsNull())
-    return false;
-
-  if (aShape.ShapeType() == TopAbs_EDGE) {
-    TopoDS_Edge aEdge = TopoDS::Edge(aShape);
-    Standard_Real aStart, aEnd;
-    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
-    GeomAdaptor_Curve aAdaptor(aCurve);
-    return aAdaptor.GetType() == GeomAbs_Line;
-  }
-  return false;
-}
-
-bool ModuleBase_ResultArcValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  TopoDS_Shape aShape = shape(aResult);
-  if (aShape.IsNull())
-    return false;
-
-  TopAbs_ShapeEnum aa = aShape.ShapeType();
-  if (aShape.ShapeType() == TopAbs_EDGE) {
-    TopoDS_Edge aEdge = TopoDS::Edge(aShape);
-    Standard_Real aStart, aEnd;
-    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
-    GeomAdaptor_Curve aAdaptor(aCurve);
-    return aAdaptor.GetType() == GeomAbs_Circle;
-  }
-  return false;
-}
-
diff --git a/src/ModuleBase/ModuleBase_ResultValidators.h b/src/ModuleBase/ModuleBase_ResultValidators.h
deleted file mode 100644 (file)
index ee4b23d..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// File:        ModuleBase_ResultValidators.h
-// Created:     23 July 2014
-// Author:      Vitaly SMETANNIKOV
-
-#ifndef ModuleBase_ResultValidators_H
-#define ModuleBase_ResultValidators_H
-
-#include "ModuleBase.h"
-#include <ModelAPI_Validator.h>
-#include <ModelAPI_Object.h>
-
-class ModuleBase_ResultValidator : public ModelAPI_Validator
-{
- public:
-  virtual bool isValid(const ObjectPtr theObject) const = 0;
-};
-
-class ModuleBase_ResultPointValidator : public ModuleBase_ResultValidator
-{
- public:
-  MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-class ModuleBase_ResultLineValidator : public ModuleBase_ResultValidator
-{
- public:
-  MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-class ModuleBase_ResultArcValidator : public ModuleBase_ResultValidator
-{
- public:
-  MODULEBASE_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-#endif
index 6895c3debc731fa037371bbffaa22d24e4296b58..898a852b3003091a5f41b72b48c6bcb7c29cf219 100644 (file)
@@ -18,7 +18,8 @@ SET(PROJECT_HEADERS
     SketchPlugin_ConstraintParallel.h
     SketchPlugin_ConstraintPerpendicular.h
     SketchPlugin_ConstraintRadius.h
-       SketchPlugin_Validators.h
+    SketchPlugin_Validators.h
+    SketchPlugin_ResultValidators.h 
 )
 
 SET(PROJECT_SOURCES
@@ -36,7 +37,8 @@ SET(PROJECT_SOURCES
     SketchPlugin_ConstraintParallel.cpp
     SketchPlugin_ConstraintPerpendicular.cpp
     SketchPlugin_ConstraintRadius.cpp
-       SketchPlugin_Validators.cpp
+    SketchPlugin_Validators.cpp
+    SketchPlugin_ResultValidators.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 0ac34f1f2c93a605f4a179e91ede927b1ca121af..04ad750a2ee821e47d4afde0d4ac0e212bab19a0 100644 (file)
@@ -11,6 +11,7 @@
 #include "SketchPlugin_ConstraintPerpendicular.h"
 #include "SketchPlugin_ConstraintRadius.h"
 #include "SketchPlugin_Validators.h"
+#include "SketchPlugin_ResultValidators.h"
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Validator.h>
@@ -28,6 +29,9 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   aFactory->registerValidator("SketchPlugin_DistanceAttrValidator",
                               new SketchPlugin_DistanceAttrValidator);
+  aFactory->registerValidator("Sketch_ResultPointValidator", new SketchPlugin_ResultPointValidator);
+  aFactory->registerValidator("Sketch_ResultLineValidator", new SketchPlugin_ResultLineValidator);
+  aFactory->registerValidator("Sketch_ResultArcValidator", new SketchPlugin_ResultArcValidator);
 
   // register this plugin
   ModelAPI_PluginManager::get()->registerPlugin(this);
diff --git a/src/SketchPlugin/SketchPlugin_ResultValidators.cpp b/src/SketchPlugin/SketchPlugin_ResultValidators.cpp
new file mode 100644 (file)
index 0000000..b611a99
--- /dev/null
@@ -0,0 +1,53 @@
+// File:        Model_ResultValidators.cpp
+// Created:     23 July 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include "SketchPlugin_ResultValidators.h"
+
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Tools.h>
+#include <GeomAPI_Curve.h>
+
+ResultPtr result(const ObjectPtr theObject)
+{
+  return boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+}
+
+bool SketchPlugin_ResultPointValidator::isValid(const ObjectPtr theObject) const
+{
+  ResultPtr aResult = result(theObject);
+  if (!aResult)
+    return false;
+  boost::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
+  return aShape && aShape->isVertex();
+}
+
+bool SketchPlugin_ResultLineValidator::isValid(const ObjectPtr theObject) const
+{
+  ResultPtr aResult = result(theObject);
+  if (!aResult)
+    return false;
+  boost::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
+  return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isLine();
+
+  /*
+  if (aShape.ShapeType() == TopAbs_EDGE) {
+    TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+    Standard_Real aStart, aEnd;
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
+    GeomAdaptor_Curve aAdaptor(aCurve);
+    return aAdaptor.GetType() == GeomAbs_Line;
+  }
+  return false;
+  */
+}
+
+bool SketchPlugin_ResultArcValidator::isValid(const ObjectPtr theObject) const
+{
+  ResultPtr aResult = result(theObject);
+  if (!aResult)
+    return false;
+  boost::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
+  return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isCircle();
+}
+
diff --git a/src/SketchPlugin/SketchPlugin_ResultValidators.h b/src/SketchPlugin/SketchPlugin_ResultValidators.h
new file mode 100644 (file)
index 0000000..0a6f7a6
--- /dev/null
@@ -0,0 +1,30 @@
+// File:        Model_ResultValidators.h
+// Created:     23 July 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef Model_ResultValidators_H
+#define Model_ResultValidators_H
+
+#include <SketchPlugin.h>
+#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_Object.h>
+
+class SketchPlugin_ResultPointValidator : public ModelAPI_ResultValidator
+{
+ public:
+  SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
+};
+
+class SketchPlugin_ResultLineValidator : public ModelAPI_ResultValidator
+{
+ public:
+  SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
+};
+
+class SketchPlugin_ResultArcValidator : public ModelAPI_ResultValidator
+{
+ public:
+  SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
+};
+
+#endif
index e6855819a4a9853dc5f9062215183edd0296a8a8..c5972b9b9ba77444a78279cef7437a84221ee9e5 100644 (file)
@@ -85,7 +85,8 @@ void XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation)
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   std::list<ModelAPI_Validator*> aValidators;
-  aFactory->validators(anOperationId.toStdString(), aValidators);
+  std::list<std::list<std::string> > anArguments;
+  aFactory->validators(anOperationId.toStdString(), aValidators, anArguments);
   //
   std::list<ModelAPI_Validator*>::iterator it = aValidators.begin();
   bool isValid = true;
index 6aacc23e3fe327437035c39d8dff387c8686fe0a..54ea79e5208a12c63069c0777d8ff3d73aa7d7f3 100644 (file)
@@ -43,7 +43,6 @@
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_SelectionValidator.h>
-#include <ModuleBase_ResultValidators.h>
 #include "ModuleBase_WidgetFactory.h"
 
 #include <Config_Common.h>
@@ -1064,7 +1063,8 @@ void XGUI_Workshop::updateCommandsOnViewSelection()
   {
     QString aId = aAction->data().toString();
     std::list<ModelAPI_Validator*> aValidators;
-    aFactory->validators(aId.toStdString(), aValidators);
+    std::list<std::list<std::string> > anArguments;
+    aFactory->validators(aId.toStdString(), aValidators, anArguments);
     std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
     for (; aValidator != aValidators.end(); aValidator++) {
       if (*aValidator) {