From 1320a1b94861f71a751e0c04eb8b97becb4c6008 Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 18 Nov 2015 19:13:55 +0300 Subject: [PATCH] Fillet vertex validator --- src/SketchPlugin/SketchPlugin_Validators.cpp | 61 +++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index d774e390e..3b79ad68c 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -29,6 +29,7 @@ #include +const double tolerance = 1.e-7; bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute, const std::list& theArguments, @@ -406,19 +407,73 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut } AttributeRefAttrPtr aBase = std::dynamic_pointer_cast(theAttribute); + AttributePtr anAttrBase = aBase->attr(); if(aBase->isObject()) { return false; } - // If we alredy have some result then all ok + // If we alredy have some result then: + // - if it is the same point all ok + // - if it is point on the fillet arc then it is not valid FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); AttributePtr aBaseLinesAttribute = aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()); AttributeRefListPtr aRefListOfBaseLines = std::dynamic_pointer_cast(aBaseLinesAttribute); + std::list anOldFeatList = aRefListOfBaseLines->list(); if(!aRefListOfBaseLines->list().empty()) { - return true; + FeaturePtr anOldFeatureA, anOldFeatureB; + std::list::iterator aFeatIt = anOldFeatList.begin(); + anOldFeatureA = ModelAPI_Feature::feature(*aFeatIt++); + anOldFeatureB = ModelAPI_Feature::feature(*aFeatIt); + + AttributePtr anAttrStartA = + anOldFeatureA->attribute(anOldFeatureA->getKind() == SketchPlugin_Line::ID() ? SketchPlugin_Line::START_ID() : SketchPlugin_Arc::START_ID()); + AttributePtr anAttrEndA = + anOldFeatureA->attribute(anOldFeatureA->getKind() == SketchPlugin_Line::ID() ? SketchPlugin_Line::END_ID() : SketchPlugin_Arc::END_ID()); + AttributePtr anAttrStartB = + anOldFeatureB->attribute(anOldFeatureB->getKind() == SketchPlugin_Line::ID() ? SketchPlugin_Line::START_ID() : SketchPlugin_Arc::START_ID()); + AttributePtr anAttrEndB = + anOldFeatureB->attribute(anOldFeatureB->getKind() == SketchPlugin_Line::ID() ? SketchPlugin_Line::END_ID() : SketchPlugin_Arc::END_ID()); + + std::shared_ptr aBasePnt = std::dynamic_pointer_cast(anAttrBase)->pnt(); + std::shared_ptr aStartPntA = std::dynamic_pointer_cast(anAttrStartA)->pnt(); + std::shared_ptr anEndPntA = std::dynamic_pointer_cast(anAttrEndA)->pnt(); + std::shared_ptr aStartPntB = std::dynamic_pointer_cast(anAttrStartB)->pnt(); + std::shared_ptr anEndPntB = std::dynamic_pointer_cast(anAttrEndB)->pnt(); + double aDistBaseStartA = aBasePnt->distance(aStartPntA); + double aDistBaseEndA = aBasePnt->distance(anEndPntA); + double aDistStartAStartB = aStartPntA->distance(aStartPntB); + double aDistStartAEndB = aStartPntA->distance(anEndPntB); + double aDistEndAStartB = anEndPntA->distance(aStartPntB); + double aDistEndAEndB = anEndPntA->distance(anEndPntB); + + if((aDistBaseStartA < tolerance && (aDistStartAStartB < tolerance || aDistStartAEndB < tolerance)) || + (aDistBaseEndA < tolerance && (aDistEndAStartB < tolerance || aDistEndAStartB < tolerance))) { + return true; + } + + // Check that point not on fillet arc + AttributeRefListPtr aRefListOfFillet = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Constraint::ENTITY_B())); + std::list aNewFeatList = aRefListOfFillet->list(); + if(!aNewFeatList.empty()) { + aFeatIt = aNewFeatList.begin(); + FeaturePtr aNewArc; + //aNewFeatureA = ModelAPI_Feature::feature(*aFeatIt++); + //aNewFeatureB = ModelAPI_Feature::feature(*aFeatIt++); + aFeatIt++; aFeatIt++; + aNewArc = ModelAPI_Feature::feature(*aFeatIt); + AttributePtr anArcStart = aNewArc->attribute(SketchPlugin_Arc::START_ID()); + AttributePtr anArcEnd = aNewArc->attribute(SketchPlugin_Arc::END_ID()); + std::shared_ptr anArcStartPnt = std::dynamic_pointer_cast(anArcStart)->pnt(); + std::shared_ptr anArcEndPnt = std::dynamic_pointer_cast(anArcEnd)->pnt(); + double aDistBaseArcStart = aBasePnt->distance(anArcStartPnt); + double aDistBaseArcEnd = aBasePnt->distance(anArcEndPnt); + if(aDistBaseArcStart < tolerance || aDistBaseArcEnd < tolerance) { + return false; + } + } } - AttributePtr anAttrBase = aBase->attr(); const std::set& aRefsList = anAttrBase->owner()->data()->refsToMe(); std::set::const_iterator aIt; FeaturePtr aCoincident; -- 2.39.2