X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_Validators.cpp;h=2837ba7bff93c2e5e183119e70b0f47e53b05d5d;hb=c910e9e2e9e68bc1a9f857d555a0201c2c4c75f1;hp=fa7ac518f60a1696c8a4b04f5b88cc7392107735;hpb=3d7368386762b057fff327d24d0079b4a73c3004;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index fa7ac518f..2837ba7bf 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -11,11 +11,18 @@ #include #include #include +#include #include +#include #include #include #include +#include +#include +#include + +#include #include #ifdef _DEBUG @@ -56,31 +63,31 @@ int shapesNbLines(const ModuleBase_ISelection* theSelection) return aCount; } -bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const +bool PartSet_DistanceSelection::isValid(const ModuleBase_ISelection* theSelection) const { int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection); return (aCount > 0) && (aCount < 3); } -bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const +bool PartSet_LengthSelection::isValid(const ModuleBase_ISelection* theSelection) const { int aCount = shapesNbLines(theSelection); - return (aCount > 0) && (aCount < 2); + return (aCount == 1); } -bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const +bool PartSet_PerpendicularSelection::isValid(const ModuleBase_ISelection* theSelection) const { int aCount = shapesNbLines(theSelection); return (aCount > 0) && (aCount < 3); } -bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const +bool PartSet_ParallelSelection::isValid(const ModuleBase_ISelection* theSelection) const { int aCount = shapesNbLines(theSelection); return (aCount > 0) && (aCount < 3); } -bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const +bool PartSet_RadiusSelection::isValid(const ModuleBase_ISelection* theSelection) const { QList aList = theSelection->getSelected(); ModuleBase_ViewerPrs aPrs; @@ -98,76 +105,250 @@ bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) } } } - return (aCount > 0) && (aCount < 2); + return (aCount == 1); +} + +bool PartSet_RigidSelection::isValid(const ModuleBase_ISelection* theSelection) const +{ + QList aList = theSelection->getSelected(); + return (aList.count() == 1); +} + + +bool PartSet_CoincidentSelection::isValid(const ModuleBase_ISelection* theSelection) const +{ + int aCount = shapesNbPoints(theSelection); + return (aCount > 0) && (aCount < 3); } -bool PartSet_RigidValidator::isValid(const ModuleBase_ISelection* theSelection) const +bool PartSet_HVDirSelection::isValid(const ModuleBase_ISelection* theSelection) const { int aCount = shapesNbLines(theSelection); - return (aCount > 0) && (aCount < 2); + return (aCount == 1); } -bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const ObjectPtr& theObject) const +bool PartSet_TangentSelection::isValid(const ModuleBase_ISelection* theSelection) const { + QList aList = theSelection->getSelected(); + ModuleBase_ViewerPrs aPrs; + if (aList.size() != 2) + return false; + + ModuleBase_ViewerPrs aPrs1 = aList.first(); + ModuleBase_ViewerPrs aPrs2 = aList.last(); + + const TopoDS_Shape& aShape1 = aPrs1.shape(); + const TopoDS_Shape& aShape2 = aPrs2.shape(); + if (aShape1.IsNull() || aShape2.IsNull()) + return false; + + if ((aShape1.ShapeType() != TopAbs_EDGE) || (aShape2.ShapeType() != TopAbs_EDGE)) + return false; + + TopoDS_Edge aEdge1 = TopoDS::Edge(aShape1); + TopoDS_Edge aEdge2 = TopoDS::Edge(aShape2); + + Standard_Real aStart, aEnd; + Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(aEdge1, aStart, aEnd); + Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(aEdge2, aStart, aEnd); + + GeomAdaptor_Curve aAdaptor1(aCurve1); + GeomAdaptor_Curve aAdaptor2(aCurve2); + if (aAdaptor1.GetType() == GeomAbs_Circle) + return aAdaptor2.GetType() == GeomAbs_Line; + else if (aAdaptor2.GetType() == GeomAbs_Circle) + return aAdaptor1.GetType() == GeomAbs_Line; + return false; +} + + +bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + + // the type of validated attributes should be equal, attributes with different types are not validated // 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; + std::string anAttrType = theAttribute->attributeType(); + std::list > anAttrs; + + if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) { + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); + bool isObject = anAttr->isObject(); + ObjectPtr anObject = anAttr->object(); + AttributePtr anAttributeAttr = anAttr->attr(); + + anAttrs = aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); + if (anAttrs.size() > 0) { + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if ((*anAttr).get() && (*anAttr)->id() != theAttribute->id()) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(*anAttr); + if (aRef->isObject() != isObject) + continue; + if (isObject) { + if (aRef->object() == anObject) + return false; + } + else { // the attribute reference + if (aRef->attr() == theAttribute) + 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; + else if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) { + AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttribute); + ResultPtr aContext = anAttr->context(); + GeomShapePtr aShape = anAttr->value(); + + // Check selection attributes + anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); + if (anAttrs.size() > 0) { + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if ((*anAttr).get() && (*anAttr)->id() != theAttribute->id()) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (aRef->context() == aContext) { + bool aHasShape = aShape.get() != NULL; + if (!aHasShape || aRef->value()->isEqual(aShape)) + 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; + else if (anAttrType == ModelAPI_AttributeReference::typeId()) { + AttributeReferencePtr anAttr = std::dynamic_pointer_cast(theAttribute); + ObjectPtr anObject = anAttr->value(); + // Check selection attributes + anAttrs = aFeature->data()->attributes(ModelAPI_AttributeReference::typeId()); + if (anAttrs.size() > 0) { + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if ((*anAttr).get() && (*anAttr)->id() != theAttribute->id()) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (aRef->value() == anObject) + return false; + } + return true; } } } - return true; + return !featureHasReferences(theAttribute); } -bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const AttributePtr& theAttribute) const +bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr& theAttribute) const { - // not implemented - return true; + std::list > > allRefs; + if (theAttribute->owner().get() && theAttribute->owner()->data().get()) + theAttribute->owner()->data()->referencesToObjects(allRefs); + // collect object referenced by theAttribute + std::list* anAttrObjs = 0; + std::list > >::iterator aRefIter = allRefs.begin(); + for(; aRefIter != allRefs.end(); aRefIter++) { + if (theAttribute->id() == aRefIter->first) + anAttrObjs = &(aRefIter->second); + } + if (!anAttrObjs || anAttrObjs->empty()) + return false; // theAttribute does not references to anything + // check with all others + for(aRefIter = allRefs.begin(); aRefIter != allRefs.end(); aRefIter++) { + if (theAttribute->id() == aRefIter->first) + continue; // do not check with myself + std::list::iterator aReferenced = aRefIter->second.begin(); + for(; aReferenced != aRefIter->second.end(); aReferenced++) { + std::list::iterator aReferencedByMe = anAttrObjs->begin(); + for(; aReferencedByMe != anAttrObjs->end(); aReferencedByMe++) { + if (*aReferenced == *aReferencedByMe) // found same objects! + return true; + } + } + } + return false; } -bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const +bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + bool isSketchEntities = true; + std::set anEntityKinds; + std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); + for (; anIt != aLast; anIt++) { + anEntityKinds.insert(*anIt); + } + + std::string anAttributeType = theAttribute->attributeType(); + if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(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(); + // a context of the selection attribute is a feature result. It can be a case when the result + // of the feature is null, e.g. the feature is modified and has not been executed yet. + // The validator returns an invalid result here. The case is an extrusion built on a sketch + // feature. A new sketch element creation leads to an empty result. + if (!anObject.get()) + isSketchEntities = false; + else { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + } + if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(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; +} + + + +bool PartSet_SameTypeAttrValidator::isValid( + const AttributePtr& theAttribute, const std::list& theArguments ) const { - // not implemented - return true; + // there is a check whether the feature contains a point and a linear edge or two point values + std::string aParamA = theArguments.front(); + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + if (!aRefAttr) + return false; + + bool isObject = aRefAttr->isObject(); + ObjectPtr anObject = aRefAttr->object(); + if (isObject && anObject) { + FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject); + + AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA); + ObjectPtr aOtherObject = aOtherAttr->object(); + FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject); + return aRefFea->getKind() == aOtherFea->getKind(); + } + return false; } +