From: mpv Date: Thu, 30 Oct 2014 08:17:38 +0000 (+0300) Subject: External edges for sketch: lines and circles X-Git-Tag: V_0.5~48^2~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fa107dfb3ba274eaeb191c5ec4f6c96517b55a02;p=modules%2Fshaper.git External edges for sketch: lines and circles --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index eeafb1db6..7316f3c2c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -65,6 +65,7 @@ void FeaturesPlugin_Extrusion::execute() if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value()) aSize = -aSize; + eraseResults(); // to erase the previously stored naming structures boost::shared_ptr aResultBody = document()->createBody(data()); GeomAlgoAPI_Extrusion aFeature(aFace, aSize); if(!aFeature.isDone()) { diff --git a/src/GeomAPI/GeomAPI_Edge.cpp b/src/GeomAPI/GeomAPI_Edge.cpp index 2cde7c24d..a4b42b207 100644 --- a/src/GeomAPI/GeomAPI_Edge.cpp +++ b/src/GeomAPI/GeomAPI_Edge.cpp @@ -3,6 +3,9 @@ // Author: Artem ZHIDKOV #include +#include +#include +#include #include #include @@ -10,12 +13,20 @@ #include #include #include +#include GeomAPI_Edge::GeomAPI_Edge() - : GeomAPI_Shape() + : GeomAPI_Shape() { } +GeomAPI_Edge::GeomAPI_Edge(const boost::shared_ptr& theShape) +{ + if (!theShape->isNull() && theShape->isEdge()) { + setImpl(new TopoDS_Shape(theShape->impl())); + } +} + bool GeomAPI_Edge::isLine() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); @@ -45,3 +56,41 @@ bool GeomAPI_Edge::isArc() const return true; return false; } + +boost::shared_ptr GeomAPI_Edge::firstPoint() +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + double aFirst, aLast; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); + gp_Pnt aPoint; + aCurve->D0(aFirst, aPoint); + return boost::shared_ptr(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())); +} + +boost::shared_ptr GeomAPI_Edge::lastPoint() +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + double aFirst, aLast; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); + gp_Pnt aPoint; + aCurve->D0(aLast, aPoint); + return boost::shared_ptr(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())); +} + +boost::shared_ptr GeomAPI_Edge::circle() +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + double aFirst, aLast; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); + if (aCurve) { + Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve); + if (aCirc) { + gp_Pnt aLoc = aCirc->Location(); + boost::shared_ptr aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); + gp_Dir anAxis = aCirc->Axis().Direction(); + boost::shared_ptr aDir(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z())); + return boost::shared_ptr(new GeomAPI_Circ(aCenter, aDir, aCirc->Radius())); + } + } + return boost::shared_ptr(); // not circle +} diff --git a/src/GeomAPI/GeomAPI_Edge.h b/src/GeomAPI/GeomAPI_Edge.h index f1c74c5d5..6814bb687 100644 --- a/src/GeomAPI/GeomAPI_Edge.h +++ b/src/GeomAPI/GeomAPI_Edge.h @@ -7,28 +7,22 @@ #include +class GeomAPI_Pnt; +class GeomAPI_Circ; + /**\class GeomAPI_Edge - * \ingroup DataModel +* \ingroup DataModel * \brief Interface to the edge object */ class GEOMAPI_EXPORT GeomAPI_Edge : public GeomAPI_Shape { - public: - /// Creation of empty (null) shape - GeomAPI_Edge(); - - /// Returns whether the shape is a vertex - virtual bool isVertex() const - { - return false; - } - - /// Returns whether the shape is an edge - virtual bool isEdge() const - { - return true; - } +public: + /// Creation of empty (null) shape + GeomAPI_Edge(); + + /// Creation of edge by the edge-shape + GeomAPI_Edge(const boost::shared_ptr& theShape); /// Verifies that the edge is a line bool isLine() const; @@ -38,6 +32,15 @@ class GEOMAPI_EXPORT GeomAPI_Edge : public GeomAPI_Shape /// Verifies that the edge is an arc of circle bool isArc() const; + + /// Returns the first vertex coordinates of the edge + boost::shared_ptr firstPoint(); + + /// Returns the Last vertex coordinates of the edge + boost::shared_ptr lastPoint(); + + /// Returns a circle if edge is based on the cirsle curve + boost::shared_ptr circle(); }; #endif diff --git a/src/GeomAPI/GeomAPI_Pnt.cpp b/src/GeomAPI/GeomAPI_Pnt.cpp index 0455c1513..aae0d1b8b 100644 --- a/src/GeomAPI/GeomAPI_Pnt.cpp +++ b/src/GeomAPI/GeomAPI_Pnt.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include @@ -58,3 +60,14 @@ double GeomAPI_Pnt::distance(const boost::shared_ptr& theOther) con { return MY_PNT->Distance(theOther->impl()); } + +boost::shared_ptr GeomAPI_Pnt::to2D(const boost::shared_ptr& theOrigin, + const boost::shared_ptr& theDirX, const boost::shared_ptr& theDirY) +{ + gp_Pnt anOriginPnt(theOrigin->x(), theOrigin->y(), theOrigin->z()); + gp_Vec aVec(anOriginPnt, impl()); + + double aX = aVec.X() * theDirX->x() + aVec.Y() * theDirX->y() + aVec.Z() * theDirX->z(); + double aY = aVec.X() * theDirY->x() + aVec.Y() * theDirY->y() + aVec.Z() * theDirY->z(); + return boost::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); +} diff --git a/src/GeomAPI/GeomAPI_Pnt.h b/src/GeomAPI/GeomAPI_Pnt.h index 6e4e527d5..af4cce849 100644 --- a/src/GeomAPI/GeomAPI_Pnt.h +++ b/src/GeomAPI/GeomAPI_Pnt.h @@ -9,6 +9,8 @@ #include class GeomAPI_XYZ; +class GeomAPI_Pnt2d; +class GeomAPI_Dir; /**\class GeomAPI_Pnt * \ingroup DataModel @@ -42,7 +44,11 @@ class GEOMAPI_EXPORT GeomAPI_Pnt : public GeomAPI_Interface /// Distance between two points double distance(const boost::shared_ptr& theOther) const; + + /// Projects a point to the plane defined by the origin and 2 axes vectors in this plane + boost::shared_ptr to2D(const boost::shared_ptr& theOrigin, + const boost::shared_ptr& theDirX, + const boost::shared_ptr& theDirY); }; #endif - diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index a3a117741..573086ed0 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -328,6 +328,9 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr) if (theAttr->isArgument()) { static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent); + if (myObject) { + myObject->attributeChanged(); + } } } diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 14a1e396f..94b1a64e8 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -20,6 +20,11 @@ boost::shared_ptr ModelAPI_Feature::firstResult() return myResults.empty() ? boost::shared_ptr() : *(myResults.begin()); } +boost::shared_ptr ModelAPI_Feature::lastResult() +{ + return myResults.empty() ? boost::shared_ptr() : *(myResults.rbegin()); +} + void ModelAPI_Feature::setResult(const boost::shared_ptr& theResult) { if (firstResult() == theResult) { // just updated diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 269471f84..c266b505e 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -72,6 +72,8 @@ class ModelAPI_Feature : public ModelAPI_Object MODELAPI_EXPORT const std::list >& results(); /// returns the first result in the list or NULL reference MODELAPI_EXPORT boost::shared_ptr firstResult(); + /// returns the last result in the list or NULL reference + MODELAPI_EXPORT boost::shared_ptr lastResult(); /// sets the alone result MODELAPI_EXPORT void setResult(const boost::shared_ptr& theResult); /// sets the result by index (zero based), results before this must be set before diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 7ac6696f5..aba6567eb 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -54,6 +54,10 @@ class ModelAPI_Object /// Returns the group identifier of this object virtual std::string groupName() = 0; + /// Called on change of any argument-attribute of this object + MODELAPI_EXPORT virtual void attributeChanged() + {} + /// To use virtuality for destructors virtual ~ModelAPI_Object() {} diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index f11abff58..916a31a71 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -364,13 +364,13 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& the Standard_Real aStart, aEnd; Handle(V3d_View) aNullView; - FeaturePtr myFeature; + FeaturePtr aMyFeature; Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aStart, aEnd); GeomAdaptor_Curve aAdaptor(aCurve); if (aAdaptor.GetType() == GeomAbs_Line) { // Create line - myFeature = theSketch->addFeature(SketchPlugin_Line::ID()); + aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID()); //DataPtr aData = myFeature->data(); //boost::shared_ptr anEndAttr = @@ -387,7 +387,7 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& the } else if (aAdaptor.GetType() == GeomAbs_Circle) { if (aAdaptor.IsClosed()) { // Create circle - myFeature = theSketch->addFeature(SketchPlugin_Circle::ID()); + aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID()); //gp_Circ aCirc = aAdaptor.Circle(); //gp_Pnt aCenter = aCirc.Location(); @@ -397,11 +397,11 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& the //setFeatureValue(myFeature, aCirc.Radius(), SketchPlugin_Circle::RADIUS_ID()); } else { // Create arc - myFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); + aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); } } - if (myFeature) { - DataPtr aData = myFeature->data(); + if (aMyFeature) { + DataPtr aData = aMyFeature->data(); AttributeSelectionPtr anAttr = boost::dynamic_pointer_cast (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); @@ -412,8 +412,8 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& the anEdge->setImpl(new TopoDS_Shape(aShape)); anAttr->setValue(aRes, anEdge); - myFeature->execute(); - return myFeature->firstResult(); + aMyFeature->execute(); + return aMyFeature->lastResult(); } } return ResultPtr(); diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 992fc321d..06ab76d14 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -25,8 +26,8 @@ SketchPlugin_Circle::SketchPlugin_Circle() void SketchPlugin_Circle::initAttributes() { - data()->addAttribute(SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D::type()); - data()->addAttribute(SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::type()); data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); } @@ -39,14 +40,13 @@ void SketchPlugin_Circle::execute() // compute a circle point in 3D view boost::shared_ptr aCenterAttr = boost::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Circle::CENTER_ID())); - AttributeDoublePtr aRadiusAttr = boost::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Circle::RADIUS_ID())); + GeomDataAPI_Point2D>(data()->attribute(CENTER_ID())); + AttributeDoublePtr aRadiusAttr = + boost::dynamic_pointer_cast(data()->attribute(RADIUS_ID())); if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) { boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); // make a visible point boost::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); - //aShapes.push_back(aCenterPointShape); boost::shared_ptr aConstr1 = document()->createConstruction( data(), 0); aConstr1->setShape(aCenterPointShape); @@ -72,15 +72,6 @@ void SketchPlugin_Circle::execute() setResult(aConstr2, 1); } } - /* - boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); - // store the result - boost::shared_ptr aConstr = - document()->createConstruction(data()); - aConstr->setShape(aCompound); - aConstr->setIsInHistory(false); - setResult(aConstr); - */ } } @@ -91,15 +82,15 @@ void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY) return; boost::shared_ptr aPoint1 = boost::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Circle::CENTER_ID())); + aData->attribute(CENTER_ID())); aPoint1->move(theDeltaX, theDeltaY); } double SketchPlugin_Circle::distanceToPoint(const boost::shared_ptr& thePoint) { boost::shared_ptr aData = data(); - boost::shared_ptr aPoint = boost::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Circle::CENTER_ID())); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(CENTER_ID())); return aPoint->pnt()->distance(thePoint); } @@ -107,3 +98,18 @@ double SketchPlugin_Circle::distanceToPoint(const boost::shared_ptrselection(EXTERNAL_ID())->context(); } + +void SketchPlugin_Circle::attributeChanged() { + static bool myIsUpdated = false; // to avoid infinitive cycle on attrubtes change + boost::shared_ptr aSelection = data()->selection(EXTERNAL_ID())->value(); + if (aSelection && !myIsUpdated) { // update arguments due to the selection value + myIsUpdated = true; + boost::shared_ptr anEdge( new GeomAPI_Edge(aSelection)); + boost::shared_ptr aCirc = anEdge->circle(); + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(attribute(CENTER_ID())); + aCenterAttr->setValue(sketch()->to2D(aCirc->center())); + real(RADIUS_ID())->setValue(aCirc->radius()); + myIsUpdated = false; + } +} diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index 11311dcb0..70ee0c892 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -76,6 +76,9 @@ class SketchPlugin_Circle : public SketchPlugin_Feature //, public GeomAPI_IPre /// \param thePoint the point virtual double distanceToPoint(const boost::shared_ptr& thePoint); + /// Called on change of any argument-attribute of this object + SKETCHPLUGIN_EXPORT virtual void attributeChanged(); + /// Use plugin manager for features creation SketchPlugin_Circle(); }; diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index dac422267..75c404a77 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -26,8 +26,8 @@ SketchPlugin_Line::SketchPlugin_Line() void SketchPlugin_Line::initAttributes() { - data()->addAttribute(SketchPlugin_Line::START_ID(), GeomDataAPI_Point2D::type()); - data()->addAttribute(SketchPlugin_Line::END_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type()); data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); } @@ -38,15 +38,15 @@ void SketchPlugin_Line::execute() if (aSketch) { // compute a start point in 3D view boost::shared_ptr aStartAttr = boost::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Line::START_ID())); + GeomDataAPI_Point2D>(data()->attribute(START_ID())); // compute an end point in 3D view boost::shared_ptr anEndAttr = boost::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Line::END_ID())); + GeomDataAPI_Point2D>(data()->attribute(END_ID())); if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) { boost::shared_ptr aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); boost::shared_ptr anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); // make linear edge - boost::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + boost::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); // store the result boost::shared_ptr aConstr = document()->createConstruction( data()); @@ -63,12 +63,12 @@ void SketchPlugin_Line::move(double theDeltaX, double theDeltaY) if (!aData->isValid()) return; - boost::shared_ptr aPoint1 = boost::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Line::START_ID())); + boost::shared_ptr aPoint1 = boost::dynamic_pointer_cast + (aData->attribute(START_ID())); aPoint1->move(theDeltaX, theDeltaY); - boost::shared_ptr aPoint2 = boost::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Line::END_ID())); + boost::shared_ptr aPoint2 = boost::dynamic_pointer_cast + (aData->attribute(END_ID())); aPoint2->move(theDeltaX, theDeltaY); } @@ -77,10 +77,10 @@ double SketchPlugin_Line::distanceToPoint(const boost::shared_ptr double aDelta = 0; boost::shared_ptr aData = data(); - boost::shared_ptr aPoint1 = boost::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Line::START_ID())); - boost::shared_ptr aPoint2 = boost::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Line::END_ID())); + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(START_ID())); + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aData->attribute(END_ID())); GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y()); @@ -97,3 +97,19 @@ double SketchPlugin_Line::distanceToPoint(const boost::shared_ptr bool SketchPlugin_Line::isFixed() { return data()->selection(EXTERNAL_ID())->context(); } + +void SketchPlugin_Line::attributeChanged() { + static bool myIsUpdated = false; // to avoid infinitive cycle on attrubtes change + boost::shared_ptr aSelection = data()->selection(EXTERNAL_ID())->value(); + if (aSelection && !myIsUpdated) { // update arguments due to the selection value + myIsUpdated = true; + boost::shared_ptr anEdge( new GeomAPI_Edge(aSelection)); + boost::shared_ptr aStartAttr = + boost::dynamic_pointer_cast(attribute(START_ID())); + aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint())); + boost::shared_ptr anEndAttr = + boost::dynamic_pointer_cast(attribute(END_ID())); + anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint())); + myIsUpdated = false; + } +} diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index d24f1af52..3943eafd3 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -67,6 +67,9 @@ class SketchPlugin_Line : public SketchPlugin_Feature /// \param thePoint the point virtual double distanceToPoint(const boost::shared_ptr& thePoint); + /// Called on change of any argument-attribute of this object + SKETCHPLUGIN_EXPORT virtual void attributeChanged(); + /// Use plugin manager for features creation SketchPlugin_Line(); }; diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 5429b2b60..42b70c4c6 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -165,6 +165,19 @@ boost::shared_ptr SketchPlugin_Sketch::to3D(const double theX, cons return boost::shared_ptr(new GeomAPI_Pnt(aSum)); } +boost::shared_ptr SketchPlugin_Sketch::to2D( + const boost::shared_ptr& thePnt) +{ + boost::shared_ptr aC = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + boost::shared_ptr aX = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::DIRX_ID())); + boost::shared_ptr aY = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::DIRY_ID())); + return thePnt->to2D(aC->pnt(), aX->dir(), aY->dir()); +} + + bool SketchPlugin_Sketch::isPlaneSet() { boost::shared_ptr aNormal = boost::dynamic_pointer_cast( diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 23147d97f..637bd34a9 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -132,6 +132,9 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_IPr /// Construction result is allways recomuted on the fly SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;} + /// Returns the point projected into the sketch plane + boost::shared_ptr to2D(const boost::shared_ptr& thePnt); + protected: /// Creates a plane and append it to the list /// \param theX the X normal value