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 Handle(V3d_View) theView, 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 anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
65 gp_Vec aVec(anOriginPnt, thePoint);
67 if (!theView.IsNull())
69 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
70 theView->Eye(XEye, YEye, ZEye);
72 theView->At(XAt, YAt, ZAt);
73 gp_Pnt EyePoint(XEye, YEye, ZEye);
74 gp_Pnt AtPoint(XAt, YAt, ZAt);
76 gp_Vec anEyeVec(EyePoint, AtPoint);
79 boost::shared_ptr<GeomDataAPI_Dir> aNormal =
80 boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
81 gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z());
83 double aDen = anEyeVec*aNormalVec;
84 double aLVec = aDen != 0 ? aVec*aNormalVec/aDen : aVec*aNormalVec;
86 gp_Vec aDeltaVec = anEyeVec*aLVec;
87 aVec = aVec - aDeltaVec;
89 theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
90 theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();