From 09f1be479f0f405c4d6278fb3354e606eae77a88 Mon Sep 17 00:00:00 2001 From: spo Date: Tue, 14 Jun 2016 13:23:58 +0300 Subject: [PATCH] Add some constraint to SketchAPI_Sketch --- src/SketchAPI/SketchAPI_Sketch.cpp | 79 +++++++++++++++++++++++++++--- src/SketchAPI/SketchAPI_Sketch.h | 35 ++++++++++++- 2 files changed, 104 insertions(+), 10 deletions(-) diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index c0bdae5e8..52119f62b 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -9,7 +9,6 @@ //-------------------------------------------------------------------------------------- #include #include -//#include #include #include #include @@ -27,7 +26,10 @@ #include //-------------------------------------------------------------------------------------- #include +#include +#include #include +//-------------------------------------------------------------------------------------- #include "SketchAPI_Circle.h" #include "SketchAPI_Line.h" //-------------------------------------------------------------------------------------- @@ -86,6 +88,17 @@ void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal) execute(); } +//-------------------------------------------------------------------------------------- +void SketchAPI_Sketch::setValue( + const std::shared_ptr & theConstraint, + const ModelHighAPI_Double & theValue) +{ + // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE + fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE())); + + theConstraint->execute(); +} + //-------------------------------------------------------------------------------------- SketchPtr addSketch(const std::shared_ptr & thePart, const std::shared_ptr & thePlane) @@ -103,6 +116,14 @@ SketchPtr addSketch(const std::shared_ptr & thePart, return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal)); } +SketchPtr addSketch(const std::shared_ptr & thePart, + const std::string & theExternalName) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(SketchAPI_Sketch::ID()); + return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName))); +} + //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2) { @@ -178,19 +199,61 @@ std::shared_ptr SketchAPI_Sketch::setCoincident( const ModelHighAPI_RefAttr & thePoint1, const ModelHighAPI_RefAttr & thePoint2) { - std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID()); - fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A())); - fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B())); + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID()); + fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); + fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); aFeature->execute(); return aFeature; } -//-------------------------------------------------------------------------------------- -void SketchAPI_Sketch::setValue( - const std::shared_ptr & theConstraint, +std::shared_ptr SketchAPI_Sketch::setDistance( + const ModelHighAPI_RefAttr & thePoint, + const ModelHighAPI_RefAttr & theLine, const ModelHighAPI_Double & theValue) { - fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE())); + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID()); + fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); + fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); + fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE())); + aFeature->execute(); + return aFeature; +} + +std::shared_ptr SketchAPI_Sketch::setLength( + const ModelHighAPI_RefAttr & theLine, + const ModelHighAPI_Double & theValue) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID()); + fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); + fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE())); + aFeature->execute(); + return aFeature; } +std::shared_ptr SketchAPI_Sketch::setParallel( + const ModelHighAPI_RefAttr & theLine1, + const ModelHighAPI_RefAttr & theLine2) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID()); + fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); + fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); + aFeature->execute(); + return aFeature; +} + +std::shared_ptr SketchAPI_Sketch::setPerpendicular( + const ModelHighAPI_RefAttr & theLine1, + const ModelHighAPI_RefAttr & theLine2) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID()); + fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); + fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); + aFeature->execute(); + return aFeature; +} //-------------------------------------------------------------------------------------- diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 3dce93862..70ec19cb9 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -115,15 +115,39 @@ public: /// Set coincident SKETCHAPI_EXPORT std::shared_ptr setCoincident( - // TODO(spo): should it be more concrete type (e.g. ModelAPI_Object)? const ModelHighAPI_RefAttr & thePoint1, const ModelHighAPI_RefAttr & thePoint2); + /// Set distance + SKETCHAPI_EXPORT + std::shared_ptr setDistance( + const ModelHighAPI_RefAttr & thePoint, + const ModelHighAPI_RefAttr & theLine, + const ModelHighAPI_Double & theValue); + + /// Set length + SKETCHAPI_EXPORT + std::shared_ptr setLength( + const ModelHighAPI_RefAttr & theLine, + const ModelHighAPI_Double & theValue); + + /// Set parallel + SKETCHAPI_EXPORT + std::shared_ptr setParallel( + const ModelHighAPI_RefAttr & theLine1, + const ModelHighAPI_RefAttr & theLine2); + + /// Set perpendicular + SKETCHAPI_EXPORT + std::shared_ptr setPerpendicular( + const ModelHighAPI_RefAttr & theLine1, + const ModelHighAPI_RefAttr & theLine2); + // TODO(spo): set* (constraints) // TODO(spo): addMirror - /// Set value + /// Set constraint value SKETCHAPI_EXPORT void setValue( const std::shared_ptr & theConstraint, @@ -153,6 +177,13 @@ SKETCHAPI_EXPORT SketchPtr addSketch(const std::shared_ptr & thePart, const ModelHighAPI_Selection & theExternal); +/**\ingroup CPPHighAPI + * \brief Create Sketch feature + */ +SKETCHAPI_EXPORT +SketchPtr addSketch(const std::shared_ptr & thePart, + const std::string & theExternalName); + //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */ -- 2.39.2