It replaces ResultValidator to AttributeValidator in order to have a similar interface for most of validators.
icon=":icons/sketch.png"
tooltip="Select a sketch face"
type_choice="Faces">
- <validator id="PartSet_SketchEntityValidator"/>
+ <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
</multi_selector>
<doublevalue
id="size"
ModelAPI_FeatureValidator.h
ModelAPI_Object.h
ModelAPI_Plugin.h
- ModelAPI_RefAttrValidator.h
ModelAPI_Result.h
ModelAPI_ResultBody.h
ModelAPI_ResultConstruction.h
ModelAPI_ResultGroup.h
ModelAPI_ResultParameters.h
ModelAPI_ResultPart.h
- ModelAPI_ResultValidator.h
ModelAPI_Session.h
ModelAPI_Tools.h
ModelAPI_ShapeValidator.h
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModelAPI_RefAttrValidator.h
-// Created: 5 Aug 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_RefAttrValidator_H
-#define ModelAPI_RefAttrValidator_H
-
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeValidator.h>
-
-/**\class ModelAPI_RefAttrValidator
- * \ingroup DataModel
- * Used for filtering out the object that can be used for reference attribute value
- */
-class ModelAPI_RefAttrValidator : public ModelAPI_AttributeValidator
-{
-public:
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModelAPI_ResultValidators.h
-// Created: 23 July 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_ResultValidators_H
-#define ModelAPI_ResultValidators_H
-
-#include "ModelAPI_Validator.h"
-#include "ModelAPI_Object.h"
-
-/**\class ModelAPI_ResultValidator
- * \ingroup DataModel
- * \brief The base class for selection filter for results of features.
- *
- * The referenced arguments of feature is normally results displayed in the viewer or by the
- * selection attribute. This filter allows to filter out the results not usable as this argument.
- */
-class ModelAPI_ResultValidator : public ModelAPI_Validator
-{
-public:
- /// The abstract method for implementation in the specific validator.
- /// \param theObject the checked object as an argument
- /// \returns true if object is OK for this filter
- virtual bool isValid(const ObjectPtr theObject) const = 0;
-};
-
-#endif
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_ShapeValidator.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeValidator.h>
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
return aValid;
}
-//********************************************************************
-bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const
-{
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- std::list<ModelAPI_Validator*> aValidators;
- std::list<std::list<std::string> > anArguments;
- aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
-
- // Check the type of selected object
- std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
- bool isValid = true;
- for (; aValidator != aValidators.end(); aValidator++) {
- const ModelAPI_ResultValidator* aResValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
- if (aResValidator) {
- isValid = false;
- if (aResValidator->isValid(theObj)) {
- isValid = true;
- break;
- }
- }
- }
- return isValid;
-}
-
-#define VALIDATOR_FILTER
void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
const bool toActivate) const
{
ModuleBase_IViewer* aViewer = theWorkshop->viewer();
-#ifdef VALIDATOR_FILTER
Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
if (toActivate)
aViewer->addSelectionFilter(aSelFilter);
else
aViewer->removeSelectionFilter(aSelFilter);
-#else
- // apply filters loaded from the XML definition of the widget
- ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
- SelectMgr_ListOfFilter aFactoryFilters;
- aFactory->filters(parentID(), attributeID(), aFactoryFilters);
- SelectMgr_ListIteratorOfListOfFilter aFactoryIt(aFactoryFilters);
- for (; aFactoryIt.More(); aFactoryIt.Next()) {
- Handle(SelectMgr_Filter) aSelFilter = aFactoryIt.Value();
- if (aSelFilter.IsNull())
- continue;
- if (toActivate)
- aViewer->addSelectionFilter(aSelFilter);
- else
- aViewer->removeSelectionFilter(aSelFilter);
- }
-#endif
-}
-
-void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop,
- SelectMgr_ListOfFilter& theFilters) const
-{
- ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
- SelectMgr_ListOfFilter aFilters;
- aFactory->filters(parentID(), attributeID(), aFilters);
- SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
- for (; aIt.More(); aIt.Next()) {
- Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
- if (aSelFilter.IsNull())
- continue;
-
- theFilters.Append(aSelFilter);
- }
}
// \return true if all validators return that the attribute is valid
bool isValidAttribute() const;
- /// Check the selected with validators if installed
- /// \param theObj the object for checking
- /// \param theShape the shape for checking
- virtual bool isValid(ObjectPtr theObj, GeomShapePtr theShape) const;
-
/// It obtains selection filters from the workshop and activates them in the active viewer
/// \param theWorkshop an active workshop
/// \param toActivate a flag about activation or deactivation the filters
virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const;
-
- /// Fills the given list with all widget filters.
- /// \param theWorkshop an active workshop
- /// \param theFilters a list of filters
- void selectionFilters(ModuleBase_IWorkshop* theWorkshop,
- SelectMgr_ListOfFilter& theFilters) const;
};
#endif /* MODULEBASE_WIDGETVALIDATED_H_ */
aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
- aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge);
aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const
{
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-
- // it filters only selection list attributes
- if (aSelectionListAttr.get() == NULL)
- return true;
-
- std::string aType = aSelectionListAttr->selectionType().c_str();
-
- // all context objects should be sketch entities
bool isSketchEntities = true;
- int aSize = aSelectionListAttr->size();
- for (int i = 0; i < aSelectionListAttr->size(); i++) {
- AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
- ObjectPtr anObject = aSelectAttr->context();
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- isSketchEntities = aFeature->getKind() == SketchPlugin_Sketch::ID();
+ std::set<std::string> anEntityKinds;
+ std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+ for (; anIt != aLast; anIt++) {
+ anEntityKinds.insert(*anIt);
}
- return isSketchEntities;
-}
-bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const
-{
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- return aFeature->getKind() == SketchPlugin_Sketch::ID();
+ std::string anAttributeType = theAttribute->attributeType();
+ if (anAttributeType == ModelAPI_AttributeSelectionList::type()) {
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ // it filters only selection list attributes
+ std::string aType = aSelectionListAttr->selectionType().c_str();
+ // all context objects should be sketch entities
+ int aSize = aSelectionListAttr->size();
+ for (int i = 0; i < aSelectionListAttr->size() && isSketchEntities; i++) {
+ AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+ ObjectPtr anObject = aSelectAttr->context();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+ }
+ }
+ if (anAttributeType == ModelAPI_AttributeRefAttr::type()) {
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ isSketchEntities = false;
+ if (aRef->isObject()) {
+ ObjectPtr anObject = aRef->object();
+ if (anObject.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if (aFeature.get() != NULL)
+ isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+ }
+ }
+ }
+
+ return isSketchEntities;
}
#include <ModuleBase_SelectionValidator.h>
#include <ModuleBase_ISelection.h>
-#include <ModelAPI_RefAttrValidator.h>
-#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_AttributeValidator.h>
/*
* Selector validators
* \ingroup Validators
* A validator which checks that objects selected for feature attributes are different (not the same)
*/
-class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
+class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator
{
public:
//! Returns true if the attribute is good for the feature attribute
* \ingroup Validators
* A validator which checks that objects selected for feature attributes are different (not the same)
*/
-class PartSet_SketchEntityValidator : public ModelAPI_RefAttrValidator
+class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator
{
public:
//! Returns true if the attribute is good for the feature attribute
const std::list<std::string>& theArguments) const;
};
-/**
-* \ingroup Validators
-* A Validator which validates tha selected object is a Sketch
-*/
-class PartSet_SketchValidator : public ModelAPI_ResultValidator
-{
- public:
- /// Returns True if the given object is a sketch
- /// \param theObject an object
- virtual bool isValid(const ObjectPtr theObject) const;
-};
-
#endif
\ No newline at end of file
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_RefAttrValidator.h>
-#include <ModelAPI_ResultValidator.h>
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
SketchPlugin_ConstraintFillet.h
SketchPlugin_ShapeValidator.h
SketchPlugin_Validators.h
- SketchPlugin_ResultValidators.h
)
SET(PROJECT_SOURCES
SketchPlugin_ConstraintFillet.cpp
SketchPlugin_ShapeValidator.cpp
SketchPlugin_Validators.cpp
- SketchPlugin_ResultValidators.cpp
)
SET(PROJECT_LIBRARIES
#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_ConstraintVertical.h>
#include <SketchPlugin_Validators.h>
-#include <SketchPlugin_ResultValidators.h>
#include <SketchPlugin_ShapeValidator.h>
#include <Events_Loop.h>
new SketchPlugin_DistanceAttrValidator);
//aFactory->registerValidator("SketchPlugin_DifferentObjects",
// new SketchPlugin_DifferentObjectsValidator);
- aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
- aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator);
- aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator);
+
aFactory->registerValidator("SketchPlugin_ShapeValidator",
new SketchPlugin_ShapeValidator);
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// 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 std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-}
-
-bool SketchPlugin_ResultPointValidator::isValid(const ObjectPtr theObject) const
-{
- ResultPtr aResult = result(theObject);
- if (!aResult)
- return false;
- std::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;
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
- return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isLine();
-}
-
-bool SketchPlugin_ResultArcValidator::isValid(const ObjectPtr theObject) const
-{
- ResultPtr aResult = result(theObject);
- if (!aResult)
- return false;
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
- return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isCircle();
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// 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
- * \ingroup Validators
- * \brief Validator for the points selection
- *
- * Allows to select points only.
- */
-class SketchPlugin_ResultPointValidator : public ModelAPI_ResultValidator
-{
-public:
- /// Returns true if theObject is a point
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-/**\class SketchPlugin_ResultLineValidator
- * \ingroup Validators
- * \brief Validator for the linear segments selection
- *
- * Allows to select linear segments only.
- */
-class SketchPlugin_ResultLineValidator : public ModelAPI_ResultValidator
-{
-public:
- /// Returns true if theObject is a line
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-/**\class SketchPlugin_ResultArcValidator
- * \ingroup Validators
- * \brief Validator for the circular segments selection
- *
- * Allows to select circular segments only.
- */
-class SketchPlugin_ResultArcValidator : public ModelAPI_ResultValidator
-{
- public:
- /// Returns true if theObject is an arc
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-#endif
#include <ModelAPI_Result.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_ResultValidator.h>
bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const
#include "SketchPlugin_ConstraintDistance.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Session.h>
+
+//#include <ModuleBase_ValidatorLinearEdge.h>
+
#include <GeomDataAPI_Point2D.h>
bool SketchPlugin_DistanceAttrValidator::isValid(
} else {
// 1. check whether the references object is a linear
ObjectPtr anObject = aRefAttr->object();
- const ModelAPI_ResultValidator* anArcValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
+ /*
+ const ModelAPI_AttributeValidator* aCircleValidator =
+ dynamic_cast<ModuleBase_ValidatorLinearEdge*>(aFactory->validator("ModuleBase_ValidatorLinearEdge"));
+ std::list<std::string> anArguments;
+ anArguments.push_back("circle");
+ bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments);
+ if (anEdgeValid)
+ return false;
+
+ anArguments.clear();
+ anArguments.push_back("line");
+ bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments);
+ if (!anEdgeValid)
+ return true;*/
+
+ /*const ModelAPI_ResultValidator* anArcValidator = aFactory->validator("ModuleBase_ValidatorLinearEdge");
+ //dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
bool anArcValid = anArcValidator->isValid(anObject);
if (anArcValid)
return false;
dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
bool aLineValid = aLineValidator->isValid(anObject);
if (!aLineValid)
- return true;
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ return true;*/
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
// If it is a line then we have to check that first attribute id not a line
std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
if (aPoint)
#define SketchPlugin_Validators_H
#include "SketchPlugin.h"
-#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_AttributeValidator.h>
/**\class SketchPlugin_DistanceAttrValidator
* \ingroup Validators
*
* It just checks that distance is greater than zero.
*/
-class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
+class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
{
public:
//! returns true if attribute is valid
<label title="Select a line on which to calculate length" tooltip="Select a line on which to calculate length"/>
<shape_selector id="ConstraintEntityA" label="Line" tooltip="Select an line"
shape_types="edge" >
- <validator id="SketchPlugin_ResultLine"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
- <validator id="SketchPlugin_ResultLine"/>
+ <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Length" id="ConstraintValue" default="computed">
<label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
<shape_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc"
shape_types="edge">
- <validator id="SketchPlugin_ResultArc"/>
<validator id="ModuleBase_ValidatorLinearEdge" parameters="circle"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<feature id="SketchConstraintRigid" title="Fixed" tooltip="Fix an object" icon=":icons/fixed.png">
<shape_selector id="ConstraintEntityA" label="Object" tooltip="Select an object"
shape_types="edge vertex">
- <validator id="SketchPlugin_ResultPoint"/>
- <validator id="SketchPlugin_ResultLine"/>
- <validator id="SketchPlugin_ResultArc"/>
+ <validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>
</shape_selector>
<validator id="PartSet_RigidValidator"/>
</feature>