]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Wed, 30 Apr 2014 05:27:16 +0000 (09:27 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 30 Apr 2014 05:27:16 +0000 (09:27 +0400)
Line is initialized by 2D coordinates obtained from 3D point

src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h

index 45121e28572def4a10d6d9e359799b8ca74d58f5..366d650e8427a1220cafbe6208c8ebdc54de4916 100644 (file)
@@ -6,8 +6,11 @@
 
 #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
@@ -92,7 +95,30 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
   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();
+}
index a01220b102a77a2bb4123484da6062c09dc1ea97..456bcf01343daa3f0ac93bda7992d9faf1432837 100644 (file)
@@ -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};