X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_Validators.cpp;h=fa7ac518f60a1696c8a4b04f5b88cc7392107735;hb=8abaa3d7f05f4f3cfe57d5d6921a66e29da72640;hp=296f8daa6e8e44a8c49b56444befb1e539063cb4;hpb=72ccabc2a906e229fe487dfeae61d38f921927d0;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 296f8daa6..fa7ac518f 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -1,37 +1,173 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: PartSet_Validators.cpp // Created: 09 July 2014 // Author: Vitaly SMETANNIKOV #include "PartSet_Validators.h" -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#ifdef _DEBUG +#include +#endif -int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType) +int shapesNbPoints(const ModuleBase_ISelection* theSelection) { - std::list aList = theSelection->getSelected(); - std::list::iterator it; - ModuleBase_ViewerPrs aPrs; + QList aList = theSelection->getSelected(); int aCount = 0; - for (it = aList.begin(); it != aList.end(); ++it) { - aPrs = *it; + foreach (ModuleBase_ViewerPrs aPrs, aList) { const TopoDS_Shape& aShape = aPrs.shape(); if (!aShape.IsNull()) { - if (aShape.ShapeType() == theType) + if (aShape.ShapeType() == TopAbs_VERTEX) aCount++; } } return aCount; } +int shapesNbLines(const ModuleBase_ISelection* theSelection) +{ + QList aList = theSelection->getSelected(); + int aCount = 0; + foreach(ModuleBase_ViewerPrs aPrs, aList) { + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) { + 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); + if (aAdaptor.GetType() == GeomAbs_Line) + aCount++; + } + } + } + return aCount; +} + bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const { - int aCount = shapesNb(theSelection, TopAbs_VERTEX); + int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection); 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 + int aCount = shapesNbLines(theSelection); + return (aCount > 0) && (aCount < 2); +} + +bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const +{ + int aCount = shapesNbLines(theSelection); + return (aCount > 0) && (aCount < 3); +} + +bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const +{ + int aCount = shapesNbLines(theSelection); + return (aCount > 0) && (aCount < 3); +} + +bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const +{ + QList aList = theSelection->getSelected(); + ModuleBase_ViewerPrs aPrs; + int aCount = 0; + foreach (ModuleBase_ViewerPrs aPrs, aList) { + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) { + 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); + if (aAdaptor.GetType() == GeomAbs_Circle) + aCount++; + } + } + } + return (aCount > 0) && (aCount < 2); +} + +bool PartSet_RigidValidator::isValid(const ModuleBase_ISelection* theSelection) const +{ + int aCount = shapesNbLines(theSelection); + return (aCount > 0) && (aCount < 2); +} + +bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject) const +{ + // Check RefAttr attributes + std::list > anAttrs = + theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type()); + if (anAttrs.size() > 0) { + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if (*anAttr) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (aRef->isObject() && aRef->object() == theObject) + return false; + } + } + } + // Check selection attributes + anAttrs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type()); + if (anAttrs.size() > 0) { + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if (*anAttr) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (aRef->isInitialized() && aRef->context() == theObject) + return false; + } + } + } + // Check selection attributes + anAttrs = theFeature->data()->attributes(ModelAPI_AttributeReference::type()); + if (anAttrs.size() > 0) { + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if (*anAttr) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (aRef->isInitialized() && aRef->value() == theObject) + return false; + } + } + } + return true; +} + +bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const AttributePtr& theAttribute) const +{ + // not implemented + return true; +} + +bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + // not implemented + return true; +}