From: dbv Date: Mon, 27 Mar 2017 10:08:47 +0000 (+0300) Subject: Issue #2024: Redesign of circle and arc of circle X-Git-Tag: V_2.7.0~177 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=98b38b67dba6bf63f63dc678c7a07c4db86faedf;p=modules%2Fshaper.git Issue #2024: Redesign of circle and arc of circle Updated validators for arc. --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index 1df2c7f87..cf3ab9623 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -648,6 +648,27 @@ bool GeomAlgoAPI_ShapeTools::isSubShapeInsideShape( return true; } +//================================================================================================== +bool GeomAlgoAPI_ShapeTools::isShapesIntersects( + const std::shared_ptr theShape1, + const std::shared_ptr theShape2) +{ + if(!theShape1.get() || !theShape2.get()) { + return false; + } + + const TopoDS_Shape& aShape1 = theShape1->impl(); + const TopoDS_Shape& aShape2 = theShape2->impl(); + + BRepExtrema_DistShapeShape aDist(aShape1, aShape2); + aDist.Perform(); + if(aDist.IsDone() && aDist.Value() < Precision::Confusion()) { + return true; + } + + return false; +} + //================================================================================================== bool GeomAlgoAPI_ShapeTools::isShapeValid(const std::shared_ptr theShape) { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h index d3b712585..e6df0520b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h @@ -108,6 +108,14 @@ public: const std::shared_ptr theSubShape, const std::shared_ptr theBaseShape); + /// \brief Checks that shapes intersects. + /// \param[in] theShape1 first shape. + /// \param[in] theShape2 second shape. + /// \return true if shapes intersects. + GEOMALGOAPI_EXPORT static bool GeomAlgoAPI_ShapeTools::isShapesIntersects( + const std::shared_ptr theShape1, + const std::shared_ptr theShape2); + /// \return true if theShape is valid. GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr theShape); diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.cpp b/src/SketchPlugin/SketchPlugin_MacroArc.cpp index 2ebb18dd4..de876dc96 100644 --- a/src/SketchPlugin/SketchPlugin_MacroArc.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroArc.cpp @@ -148,28 +148,44 @@ void SketchPlugin_MacroArc::attributeChanged(const std::string& theID) data()->blockSendAttributeUpdated(aWasBlocked, false); } -AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious) +GeomShapePtr SketchPlugin_MacroArc::getArcShape() { if(!myStart.get() || !myEnd.get() || !myCenter.get()) { - return AISObjectPtr(); + return GeomShapePtr(); } SketchPlugin_Sketch* aSketch = sketch(); if(!aSketch) { - return AISObjectPtr(); + return GeomShapePtr(); } - std::shared_ptr aStart = aSketch->to3D(myStart->x(), myStart->y()); - std::shared_ptr anEnd = aSketch->to3D(myEnd->x(), myEnd->y()); - std::shared_ptr aCenter = aSketch->to3D(myCenter->x(), myCenter->y());; - + std::shared_ptr aCenter(aSketch->to3D(myCenter->x(), myCenter->y())); + std::shared_ptr aStart(aSketch->to3D(myStart->x(), myStart->y())); + std::shared_ptr anEnd(aSketch->to3D(myEnd->x(), myEnd->y())); std::shared_ptr aNDir = - std::dynamic_pointer_cast( - aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - std::shared_ptr aNormal = aNDir->dir(); + std::dynamic_pointer_cast(aSketch->attribute(SketchPlugin_Sketch::NORM_ID())); + std::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); + GeomShapePtr anArcShape = boolean(REVERSED_ID())->value() ? GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal) : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal); + + return anArcShape; +} + +AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious) +{ + if(!myStart.get() || !myEnd.get() || !myCenter.get()) { + return AISObjectPtr(); + } + + SketchPlugin_Sketch* aSketch = sketch(); + if(!aSketch) { + return AISObjectPtr(); + } + + GeomShapePtr anArcShape = getArcShape(); + std::shared_ptr aCenter = aSketch->to3D(myCenter->x(), myCenter->y());; GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); if(!anArcShape.get() || !aCenterPointShape.get()) { diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.h b/src/SketchPlugin/SketchPlugin_MacroArc.h index 9fb6bdb3f..cc49b0e02 100644 --- a/src/SketchPlugin/SketchPlugin_MacroArc.h +++ b/src/SketchPlugin/SketchPlugin_MacroArc.h @@ -192,6 +192,9 @@ class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity, /// Use plugin manager for features creation. SketchPlugin_MacroArc(); + /// Returns shape of arc. + GeomShapePtr getArcShape(); + private: /// Set fields for center, start and end points void fillByCenterAndTwoPassed(); diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index c09102540..05ba4c501 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -96,6 +96,10 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_CirclePassedPointValidator); aFactory->registerValidator("SketchPlugin_ThirdPointValidator", new SketchPlugin_ThirdPointValidator); + aFactory->registerValidator("SketchPlugin_ArcEndPointValidator", + new SketchPlugin_ArcEndPointValidator); + aFactory->registerValidator("SketchPlugin_ArcEndPointIntersectionValidator", + new SketchPlugin_ArcEndPointIntersectionValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 00298e297..398827f61 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -41,6 +41,8 @@ #include #include +#include + #include #include #include @@ -1278,3 +1280,93 @@ bool SketchPlugin_ThirdPointValidator::arePointsNotSeparated( theError = aErrorPointsApart; return isOk; } + +bool SketchPlugin_ArcEndPointValidator::isValid( + const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + AttributeRefAttrPtr anEndPointRef = aFeature->refattr(theArguments.front()); + + if(!anEndPointRef.get()) { + return true; + } + + if(!anEndPointRef->isInitialized()) { + return true; + } + + if(anEndPointRef->attr().get()) { + return false; + } + + ObjectPtr anObject = anEndPointRef->object(); + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if(aResult.get()) { + GeomShapePtr aShape = aResult->shape(); + if(aShape.get() && aShape->isVertex()) { + return false; + } + } + + aFeature = ModelAPI_Feature::feature(anObject); + if(aFeature.get()) { + if(aFeature->getKind() == SketchPlugin_Point::ID()) { + return false; + } + } + + return true; +} + +bool SketchPlugin_ArcEndPointIntersectionValidator::isValid( + const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + std::shared_ptr anArcFeature = + std::dynamic_pointer_cast(theAttribute->owner()); + AttributeRefAttrPtr anEndPointRef = anArcFeature->refattr(theArguments.front()); + + if(!anEndPointRef.get()) { + return true; + } + + if(!anEndPointRef->isInitialized()) { + return true; + } + + GeomShapePtr anArcShape = anArcFeature->getArcShape(); + + if(!anArcShape.get() || anArcShape->isNull()) { + return true; + } + + ObjectPtr anObject = anEndPointRef->object(); + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if(aResult.get()) { + GeomShapePtr aShape = aResult->shape(); + if(aShape.get() && !aShape->isNull()) { + return GeomAlgoAPI_ShapeTools::isShapesIntersects(anArcShape, aShape); + } + } + + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(anObject); + if(aSelectedFeature.get()) { + std::list aResults = aSelectedFeature->results(); + for(std::list::const_iterator anIt = aResults.cbegin(); + anIt != aResults.cend(); + ++anIt) + { + GeomShapePtr aShape = (*anIt)->shape(); + if(aShape.get() && !aShape->isNull()) { + if(GeomAlgoAPI_ShapeTools::isShapesIntersects(anArcShape, aShape)) { + return true; + } + } + } + } + + return false; +} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 441bd1793..bea581a48 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -359,4 +359,40 @@ private: Events_InfoMessage& theError) const; }; +/**\class SketchPlugin_ArcEndPointValidator + * \ingroup Validators + * \brief Validator for the end point of MacroArc feature. + * + * Checks that third point does not lie on a point. + */ +class SketchPlugin_ArcEndPointValidator: public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + //! \param theError error message + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +}; + +/**\class SketchPlugin_ArcEndPointIntersectionValidator + * \ingroup Validators + * \brief Validator for the end point of MacroArc feature. + * + * Checks that third point does lie on edge which intersects arc. + */ +class SketchPlugin_ArcEndPointIntersectionValidator: public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + //! \param theError error message + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +}; + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index f4d726156..ec0ed9521 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -216,7 +216,10 @@ title="End point" tooltip="End point" accept_expressions="0" - enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"> + + + + + enable_value="enable_by_preferences"> + +