#include <SketchPlugin_Feature.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <ModelAPI_Data.h>
+#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
#ifdef _DEBUG
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(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<ModelAPI_AttributeDouble> anAttr;
+ boost::shared_ptr<ModelAPI_Data> aData = mySketch->data();
+
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+
+ boost::shared_ptr<GeomDataAPI_Dir> aX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ boost::shared_ptr<GeomDataAPI_Dir> anY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(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();
+}
/// \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};