From: mpv Date: Thu, 4 Sep 2014 06:12:29 +0000 (+0400) Subject: Validators improvements (arguments for feature validator) X-Git-Tag: V_0.4.4~87 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cc917b5dfaca1fcba1a25c1e54d6bd1ef0b4c057;p=modules%2Fshaper.git Validators improvements (arguments for feature validator) --- diff --git a/src/Config/Config_PropManager.h b/src/Config/Config_PropManager.h index eae15b1c3..496cddd6d 100644 --- a/src/Config/Config_PropManager.h +++ b/src/Config/Config_PropManager.h @@ -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 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 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; diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 0b2eb9763..b46cafcee 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -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 index 000000000..77bf7d9a2 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Curve.cpp @@ -0,0 +1,49 @@ +// File: GeomAPI_Curve.cpp +// Created: 04 Sep 2014 +// Author: Mikhail PONIKAROV + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define MY_CURVE (*(static_cast(myImpl))) + +GeomAPI_Curve::GeomAPI_Curve() + : GeomAPI_Interface(new Handle_Geom_Curve()) +{ +} + +GeomAPI_Curve::GeomAPI_Curve(const boost::shared_ptr& theShape) + : GeomAPI_Interface(new Handle_Geom_Curve()) // initially it is null +{ + const TopoDS_Shape& aShape = theShape->impl(); + 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 index 000000000..e4f494875 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Curve.h @@ -0,0 +1,36 @@ +// File: GeomAPI_Curve.hxx +// Created: 04 Sep 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAPI_Curve_H_ +#define GeomAPI_Curve_H_ + +#include +#include + +/**\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& 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 diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 30e2f3425..e51d30ca6 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -6,7 +6,7 @@ #include -#define MY_PNT static_cast(myImpl) +#define MY_SHAPE static_cast(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(this)->impl(); - return aShape.TShape()->ShapeType() == TopAbs_VERTEX; + return !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX; } bool GeomAPI_Shape::isEdge() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); - return aShape.TShape()->ShapeType() == TopAbs_EDGE; + return aShape.ShapeType() == TopAbs_EDGE; } diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 64292dee3..c2e3507b4 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -11,10 +11,6 @@ * \ingroup DataModel * \brief Interface to the topological shape object */ -class TopoDS_Shape; - -#define MY_SHAPE static_cast(myImpl) - class GEOMAPI_EXPORT GeomAPI_Shape : public GeomAPI_Interface { public: diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 63d79a60e..1642fbaca 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -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 diff --git a/src/Model/Model_PluginManager.cpp b/src/Model/Model_PluginManager.cpp index c41d3922c..06893e6fc 100644 --- a/src/Model/Model_PluginManager.cpp +++ b/src/Model/Model_PluginManager.cpp @@ -134,7 +134,7 @@ void Model_PluginManager::processEvent(const Events_Message* theMessage) const Config_ValidatorMessage* aMsg = dynamic_cast(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 index 66840d450..000000000 --- a/src/Model/Model_ResultValidators.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// File: Model_ResultValidators.cpp -// Created: 23 July 2014 -// Author: Vitaly SMETANNIKOV - -#include "Model_ResultValidators.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -ResultPtr result(const ObjectPtr theObject) -{ - return boost::dynamic_pointer_cast(theObject); -} - -TopoDS_Shape shape(ResultPtr theResult) -{ - boost::shared_ptr aShape = ModelAPI_Tools::shape(theResult); - if (aShape) - return aShape->impl(); - 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 index dbbf60dd4..000000000 --- a/src/Model/Model_ResultValidators.h +++ /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 -#include - -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 diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index eaab5d3c3..a1741e3b7 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -3,7 +3,6 @@ // Author: Mikhail PONIKAROV #include -#include #include #include #include @@ -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(); + 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(); + } +} + +void Model_ValidatorsFactory::assignValidator(const std::string& theID, + const std::string& theFeatureID, + const std::list& 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 >(theID, theArguments)); + aFeature->second[theAttrID][theID] = theArguments; } void Model_ValidatorsFactory::validators(const std::string& theFeatureID, - std::list& theResult) const + std::list& theResult, + std::list >& theArguments) const { - std::map >::const_iterator aFeature = myFeatures.find( - theFeatureID); + std::map::const_iterator aFeature = myFeatures.find(theFeatureID); if (aFeature != myFeatures.cend()) { - std::set::const_iterator aValIter = aFeature->second.cbegin(); + AttrValidators::const_iterator aValIter = aFeature->second.cbegin(); for (; aValIter != aFeature->second.cend(); aValIter++) { - std::map::const_iterator aFound = myIDs.find(*aValIter); + std::map::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); } diff --git a/src/Model/Model_Validator.h b/src/Model/Model_Validator.h index 56d65d181..645c4bdc6 100644 --- a/src/Model/Model_Validator.h +++ b/src/Model/Model_Validator.h @@ -26,10 +26,10 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory { private: std::map myIDs; ///< map from ID to registered validator + /// validators IDs to list of arguments + typedef std::map > AttrValidators; /// validators IDs by feature ID - std::map > myFeatures; - /// set of pairs: validators IDs, list of arguments - typedef std::set > > AttrValidators; + std::map myFeatures; /// validators IDs and arguments by feature and attribute IDs std::map > 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& 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& theResult) const; + std::list& theResult, + std::list >& 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, diff --git a/src/ModelAPI/ModelAPI_Validator.h b/src/ModelAPI/ModelAPI_Validator.h index 6f9e26f2a..78754d074 100644 --- a/src/ModelAPI/ModelAPI_Validator.h +++ b/src/ModelAPI/ModelAPI_Validator.h @@ -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& 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& theResult) const = 0; + std::list& theResult, + std::list >& 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& theValidators, diff --git a/src/ModuleBase/ModuleBase_ResultValidators.cpp b/src/ModuleBase/ModuleBase_ResultValidators.cpp deleted file mode 100644 index 4fde0437b..000000000 --- a/src/ModuleBase/ModuleBase_ResultValidators.cpp +++ /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 -#include - -#include -#include -#include -#include -#include - -ResultPtr result(const ObjectPtr theObject) -{ - return boost::dynamic_pointer_cast(theObject); -} - -TopoDS_Shape shape(ResultPtr theResult) -{ - boost::shared_ptr aShape = ModuleBase_Tools::shape(theResult); - if (aShape) - return aShape->impl(); - 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 index ee4b23ded..000000000 --- a/src/ModuleBase/ModuleBase_ResultValidators.h +++ /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 -#include - -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 diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 6895c3deb..898a852b3 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 0ac34f1f2..04ad750a2 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -11,6 +11,7 @@ #include "SketchPlugin_ConstraintPerpendicular.h" #include "SketchPlugin_ConstraintRadius.h" #include "SketchPlugin_Validators.h" +#include "SketchPlugin_ResultValidators.h" #include #include #include @@ -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 index 000000000..b611a9970 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ResultValidators.cpp @@ -0,0 +1,53 @@ +// File: Model_ResultValidators.cpp +// Created: 23 July 2014 +// Author: Vitaly SMETANNIKOV + +#include "SketchPlugin_ResultValidators.h" + +#include +#include +#include + +ResultPtr result(const ObjectPtr theObject) +{ + return boost::dynamic_pointer_cast(theObject); +} + +bool SketchPlugin_ResultPointValidator::isValid(const ObjectPtr theObject) const +{ + ResultPtr aResult = result(theObject); + if (!aResult) + return false; + boost::shared_ptr 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 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 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 index 000000000..0a6f7a692 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ResultValidators.h @@ -0,0 +1,30 @@ +// File: Model_ResultValidators.h +// Created: 23 July 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef Model_ResultValidators_H +#define Model_ResultValidators_H + +#include +#include +#include + +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 diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index e6855819a..c5972b9b9 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -85,7 +85,8 @@ void XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation) PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); std::list aValidators; - aFactory->validators(anOperationId.toStdString(), aValidators); + std::list > anArguments; + aFactory->validators(anOperationId.toStdString(), aValidators, anArguments); // std::list::iterator it = aValidators.begin(); bool isValid = true; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 6aacc23e3..54ea79e52 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #include "ModuleBase_WidgetFactory.h" #include @@ -1064,7 +1063,8 @@ void XGUI_Workshop::updateCommandsOnViewSelection() { QString aId = aAction->data().toString(); std::list aValidators; - aFactory->validators(aId.toStdString(), aValidators); + std::list > anArguments; + aFactory->validators(aId.toStdString(), aValidators, anArguments); std::list::iterator aValidator = aValidators.begin(); for (; aValidator != aValidators.end(); aValidator++) { if (*aValidator) {