1 // File: PartSet_Tools.h
2 // Created: 28 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_Tools.h>
7 #include <V3d_View.hxx>
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>
22 gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
27 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
28 theView->Eye( XEye, YEye, ZEye );
30 theView->At( XAt, YAt, ZAt );
31 gp_Pnt EyePoint( XEye, YEye, ZEye );
32 gp_Pnt AtPoint( XAt, YAt, ZAt );
34 gp_Vec EyeVector( EyePoint, AtPoint );
35 gp_Dir EyeDir( EyeVector );
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 );
42 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
43 gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
47 void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
48 double& theX, double& theY)
53 boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
54 boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
56 boost::shared_ptr<GeomDataAPI_Point> anOrigin =
57 boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
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));
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();