From: nds Date: Wed, 30 Apr 2014 05:27:16 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~101^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ab505646633ccc9524d4e6ed84de0a823bbdb1a4;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Line is initialized by 2D coordinates obtained from 3D point --- diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 45121e285..366d650e8 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -6,8 +6,11 @@ #include #include +#include +#include #include +#include #include #ifdef _DEBUG @@ -92,7 +95,30 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, boost::shared_ptr aData = feature()->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - double aX = thePoint.X(), anY = thePoint.Y(); + + double aX = 0; + double anY = 0; + convertTo2D(thePoint, aX, anY); aPoint->setValue(aX, anY); } +void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY) +{ + if (!mySketch) + return; + + boost::shared_ptr anAttr; + boost::shared_ptr aData = mySketch->data(); + + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + + boost::shared_ptr aX = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + boost::shared_ptr anY = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + + gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z()); + theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z(); + theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); +} diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index a01220b10..456bcf013 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -59,6 +59,12 @@ protected: /// \param theAttribute the start or end attribute of the line void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute); + /// \brief Converts the 3D point to the projected coodinates on the sketch plane. + /// \param thePoint the 3D point in the viewer + /// \param theX the X coordinate + /// \param theY the Y coordinate + void convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY); + protected: ///< Structure to lists the possible types of point selection modes enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None};