]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Tools.cpp
Salome HOME
b2d24c3963eb56eb2edb9363b6692dad9c281949
[modules/shaper.git] / src / PartSet / PartSet_Tools.cpp
1 // File:        PartSet_Tools.h
2 // Created:     28 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_Tools.h>
6
7 #include <V3d_View.hxx>
8 #include <gp_Pln.hxx>
9 #include <ProjLib.hxx>
10 #include <ElSLib.hxx>
11
12 #include <ModelAPI_Data.h>
13 #include <ModelAPI_AttributeDouble.h>
14 #include <GeomDataAPI_Point.h>
15 #include <GeomDataAPI_Dir.h>
16 #include <SketchPlugin_Sketch.h>
17
18 #ifdef _DEBUG
19 #include <QDebug>
20 #endif
21
22 gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
23 {
24   if (theView.IsNull())
25     return gp_Pnt();
26
27   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
28   theView->Eye( XEye, YEye, ZEye );
29
30   theView->At( XAt, YAt, ZAt );
31   gp_Pnt EyePoint( XEye, YEye, ZEye );
32   gp_Pnt AtPoint( XAt, YAt, ZAt );
33
34   gp_Vec EyeVector( EyePoint, AtPoint );
35   gp_Dir EyeDir( EyeVector );
36
37   gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
38   Standard_Real X, Y, Z;
39   theView->Convert( thePoint.x(), thePoint.y(), X, Y, Z );
40   gp_Pnt ConvertedPoint( X, Y, Z );
41
42   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
43   gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
44   return ResultPoint;
45 }
46
47 void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
48                                 double& theX, double& theY)
49 {
50   if (!theSketch)
51     return;
52
53   boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
54   boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
55
56   boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
57     boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
58
59   boost::shared_ptr<GeomDataAPI_Dir> aX = 
60     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
61   boost::shared_ptr<GeomDataAPI_Dir> anY = 
62     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
63
64   gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z());
65   theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
66   theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
67 }