#include <ModelAPI_Validator.h>
-class MODULEBASE_EXPORT ModuleBase_SelectionValidator: public ModelAPI_Validator
+class ModuleBase_SelectionValidator: public ModelAPI_Validator
{
public:
virtual bool isValid(const ModuleBase_ISelection* theSelection) const = 0;
#include <PartSet_Listener.h>
#include <PartSet_TestOCC.h>
#include <PartSet_WidgetSketchLabel.h>
+#include <PartSet_Validators.h>
#include <ModuleBase_Operation.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Validator.h>
#include <ModelAPI_Data.h>
#include <GeomDataAPI_Point2D.h>
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)
--- /dev/null
+// File: PartSet_Validators.cpp
+// Created: 09 July 2014
+// Author: Vitaly SMETANNIKOV
+
+#include "PartSet_Validators.h"
+
+#include <list>
+
+
+int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType)
+{
+ std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
+ std::list<ModuleBase_ViewerPrs>::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
--- /dev/null
+// File: PartSet_Validators.h
+// Created: 09 July 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef PartSet_Validators_H
+#define PartSet_Validators_H
+
+#include "PartSet.h"
+
+#include <ModuleBase_SelectionValidator.h>
+#include <ModuleBase_ISelection.h>
+
+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
../GeomAPI
../GeomAlgoAPI
../GeomDataAPI
+ ../ModuleBase
)
INSTALL(TARGETS SketchPlugin DESTINATION plugins)