From 325816a58ad824dbb155f0cd91902a0147f04101 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 9 Jul 2014 16:38:41 +0400 Subject: [PATCH] Create validators for constraint operations --- .../ModuleBase_SelectionValidator.h | 2 +- src/PartSet/PartSet_Module.cpp | 12 ++++++ src/PartSet/PartSet_Validators.cpp | 37 +++++++++++++++++++ src/PartSet/PartSet_Validators.h | 25 +++++++++++++ src/SketchPlugin/CMakeLists.txt | 1 + 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/PartSet/PartSet_Validators.cpp create mode 100644 src/PartSet/PartSet_Validators.h diff --git a/src/ModuleBase/ModuleBase_SelectionValidator.h b/src/ModuleBase/ModuleBase_SelectionValidator.h index ff0c0a669..1dd380139 100644 --- a/src/ModuleBase/ModuleBase_SelectionValidator.h +++ b/src/ModuleBase/ModuleBase_SelectionValidator.h @@ -11,7 +11,7 @@ #include -class MODULEBASE_EXPORT ModuleBase_SelectionValidator: public ModelAPI_Validator +class ModuleBase_SelectionValidator: public ModelAPI_Validator { public: virtual bool isValid(const ModuleBase_ISelection* theSelection) const = 0; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 3114ef944..2824363e1 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -9,10 +9,12 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -102,6 +104,16 @@ void PartSet_Module::createFeatures() Config_ModuleReader aXMLReader = Config_ModuleReader(); aXMLReader.readAll(); myFeaturesInFiles = aXMLReader.featuresInFiles(); + + //!! Test registering of validators + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + + aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator); + aFactory->assignValidator("PartSet_DistanceValidator", "SketchConstraintDistance"); + + aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator); + aFactory->assignValidator("PartSet_LengthValidator", "SketchConstraintLength"); } void PartSet_Module::featureCreated(QAction* theFeature) diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp new file mode 100644 index 000000000..296f8daa6 --- /dev/null +++ b/src/PartSet/PartSet_Validators.cpp @@ -0,0 +1,37 @@ +// File: PartSet_Validators.cpp +// Created: 09 July 2014 +// Author: Vitaly SMETANNIKOV + +#include "PartSet_Validators.h" + +#include + + +int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType) +{ + std::list aList = theSelection->getSelected(); + std::list::iterator it; + ModuleBase_ViewerPrs aPrs; + int aCount = 0; + for (it = aList.begin(); it != aList.end(); ++it) { + aPrs = *it; + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) { + if (aShape.ShapeType() == theType) + aCount++; + } + } + return aCount; +} + +bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const +{ + int aCount = shapesNb(theSelection, TopAbs_VERTEX); + return (aCount > 0) && (aCount < 3); +} + +bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const +{ + int aCount = shapesNb(theSelection, TopAbs_EDGE); + return (aCount == 1); +} \ No newline at end of file diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h new file mode 100644 index 000000000..10cdcf26a --- /dev/null +++ b/src/PartSet/PartSet_Validators.h @@ -0,0 +1,25 @@ +// File: PartSet_Validators.h +// Created: 09 July 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef PartSet_Validators_H +#define PartSet_Validators_H + +#include "PartSet.h" + +#include +#include + +class PartSet_DistanceValidator: public ModuleBase_SelectionValidator +{ +public: + PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const; +}; + +class PartSet_LengthValidator: public ModuleBase_SelectionValidator +{ +public: + PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const; +}; + +#endif diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 2bbac462f..1f5228ffd 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -54,6 +54,7 @@ INCLUDE_DIRECTORIES( ../GeomAPI ../GeomAlgoAPI ../GeomDataAPI + ../ModuleBase ) INSTALL(TARGETS SketchPlugin DESTINATION plugins) -- 2.39.2