X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSketchPlugin%2FSketchPlugin_Validators.cpp;h=729424d96c72ea9d2d66c9f98df966a727dd7950;hb=07889bdf129940bf25021b91aa58902e634a64ce;hp=5cb16e6b0b6bd737b5dc2a4b2bd82917e2f02d82;hpb=1993f63b15d942f2360ee0dabc7d01adf71338b9;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 5cb16e6b0..729424d96 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -107,12 +107,55 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribut return true; } +static bool isCoincident(FeaturePtr theFeature1, FeaturePtr theFeature2) +{ + AttributePtr aFeature1PointAttr[2]; + if(theFeature1->getKind() == SketchPlugin_Line::ID()) { + aFeature1PointAttr[0] = theFeature1->attribute(SketchPlugin_Line::START_ID()); + aFeature1PointAttr[1] = theFeature1->attribute(SketchPlugin_Line::END_ID()); + } else if(theFeature1->getKind() == SketchPlugin_Arc::ID()) { + aFeature1PointAttr[0] = theFeature1->attribute(SketchPlugin_Arc::START_ID()); + aFeature1PointAttr[1] = theFeature1->attribute(SketchPlugin_Arc::END_ID()); + } + + std::set aRefsList = theFeature1->data()->refsToMe(); + for(std::set::const_iterator aRefIt = aRefsList.begin(); + aRefIt != aRefsList.end(); + ++aRefIt) { + // Find constraint + FeaturePtr aRefFeature = std::dynamic_pointer_cast((*aRefIt)->owner()); + if(aRefFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID()) + continue; + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(*aRefIt); + AttributePtr anAttr = aRefAttr->attr(); + if(anAttr != aFeature1PointAttr[0] && anAttr != aFeature1PointAttr[1]) + continue; + + // Get coincides from constraint. + std::set aCoinsides; + SketchPlugin_Tools::findCoincidences(aRefFeature, + SketchPlugin_ConstraintCoincidence::ENTITY_A(), + aCoinsides); + SketchPlugin_Tools::findCoincidences(aRefFeature, + SketchPlugin_ConstraintCoincidence::ENTITY_B(), + aCoinsides); + + if(aCoinsides.find(theFeature2) != aCoinsides.end()) { + return true; + } + } + + return false; +} static bool hasCoincidentPoint(FeaturePtr theFeature1, FeaturePtr theFeature2) { - FeaturePtr aCoincidenceFeature = SketchPlugin_ConstraintCoincidence::findCoincidenceFeature - (theFeature1, theFeature2); - return aCoincidenceFeature.get() != NULL; + if(theFeature1->getKind() == SketchPlugin_Circle::ID() || + theFeature2->getKind() == SketchPlugin_Circle::ID()) { + return false; + } + + return (isCoincident(theFeature1, theFeature2) && isCoincident(theFeature2, theFeature1)); } bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute, @@ -648,9 +691,9 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut aFirstEndPnt = std::dynamic_pointer_cast(aFirstFeature->attribute(anEndAttr))->pnt(); aSecondStartPnt = std::dynamic_pointer_cast(aSecondFeature->attribute(aStartAttr))->pnt(); aSecondEndPnt = std::dynamic_pointer_cast(aSecondFeature->attribute(anEndAttr))->pnt(); - double aCheck1 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) - + double aCheck1 = fabs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) - (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y())); - double aCheck2 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) - + double aCheck2 = fabs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) - (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y())); if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) { return false; @@ -863,7 +906,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute, aData->attribute(SketchPlugin_Sketch::NORM_ID())); std::shared_ptr aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); - std::set > aPoints; + std::list > aPoints; std::map, std::shared_ptr > aPointToAttributes; ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(), aX->dir(), aDirY, aPoints, aPointToAttributes); @@ -891,13 +934,16 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute, AttributeSelectionPtr aFeatureAttr = std::dynamic_pointer_cast(theAttribute); std::shared_ptr anEdge; - if(aFeatureAttr && aFeatureAttr->value() && aFeatureAttr->value()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(aFeatureAttr->value())); - } else if(aFeatureAttr->context() && aFeatureAttr->context()->shape() && - aFeatureAttr->context()->shape()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(aFeatureAttr->context()->shape())); + if (aFeatureAttr.get()) { + GeomShapePtr aVal = aFeatureAttr->value(); + ResultPtr aRes = aFeatureAttr->context(); + if(aFeatureAttr->value() && aFeatureAttr->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aFeatureAttr->value())); + } else if(aFeatureAttr->context() && aFeatureAttr->context()->shape() && + aFeatureAttr->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aFeatureAttr->context()->shape())); + } } - if (!anEdge) { theError = "The attribute %1 should be an edge"; theError.arg(theAttribute->id());