Correct the line point projection for turned view.
return;
double aCurX, aCurY;
- PartSet_Tools::ConvertTo2D(myCurPressed, mySketch, aCurX, aCurY);
+ PartSet_Tools::ConvertTo2D(myCurPressed, mySketch, theView, aCurX, aCurY);
double aX, anY;
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, aX, anY);
+ PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
double aDeltaX = aX - aCurX;
double aDeltaY = anY - aCurY;
switch (myPointSelectionMode)
{
case SM_FirstPoint: {
- setLinePoint(aPoint, LINE_ATTR_START);
+ setLinePoint(aPoint, theView, LINE_ATTR_START);
myPointSelectionMode = SM_SecondPoint;
}
break;
case SM_SecondPoint: {
- setLinePoint(aPoint, LINE_ATTR_END);
+ setLinePoint(aPoint, theView, LINE_ATTR_END);
commit();
emit featureConstructed(feature(), FM_Deactivation);
emit launchOperation(PartSet_OperationSketchLine::Type(), feature());
case SM_SecondPoint:
{
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
- setLinePoint(aPoint, LINE_ATTR_END);
+ setLinePoint(aPoint, theView, LINE_ATTR_END);
}
break;
default:
}
void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
+ Handle(V3d_View) theView,
const std::string& theAttribute)
{
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
double aX, anY;
- PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY);
+ PartSet_Tools::ConvertTo2D(thePoint, mySketch, theView, aX, anY);
aPoint->setValue(aX, anY);
}
/// \brief Save the point to the line.
/// \param thePoint the 3D point in the viewer
/// \param theAttribute the start or end attribute of the line
- void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
+ void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
protected:
///< Structure to lists the possible types of point selection modes
return gp_Pnt();
V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
- theView->Eye( XEye, YEye, ZEye );
+ theView->Eye(XEye, YEye, ZEye);
- theView->At( XAt, YAt, ZAt );
- gp_Pnt EyePoint( XEye, YEye, ZEye );
- gp_Pnt AtPoint( XAt, YAt, ZAt );
+ theView->At(XAt, YAt, ZAt);
+ gp_Pnt EyePoint(XEye, YEye, ZEye);
+ gp_Pnt AtPoint(XAt, YAt, ZAt);
- gp_Vec EyeVector( EyePoint, AtPoint );
- gp_Dir EyeDir( EyeVector );
+ gp_Vec EyeVector(EyePoint, AtPoint);
+ gp_Dir EyeDir(EyeVector);
- gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
+ gp_Pln PlaneOfTheView = gp_Pln(AtPoint, EyeDir);
Standard_Real X, Y, Z;
- theView->Convert( thePoint.x(), thePoint.y(), X, Y, Z );
- gp_Pnt ConvertedPoint( X, Y, Z );
+ theView->Convert(thePoint.x(), thePoint.y(), X, Y, Z);
+ gp_Pnt ConvertedPoint(X, Y, Z);
- gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
- gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
+ gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
+ gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
return ResultPoint;
}
void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
- double& theX, double& theY)
+ Handle(V3d_View) theView, double& theX, double& theY)
{
if (!theSketch)
return;
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());
+ gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
+ gp_Vec aVec(anOriginPnt, thePoint);
+
+ if (!theView.IsNull())
+ {
+ V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
+ theView->Eye(XEye, YEye, ZEye);
+
+ theView->At(XAt, YAt, ZAt);
+ gp_Pnt EyePoint(XEye, YEye, ZEye);
+ gp_Pnt AtPoint(XAt, YAt, ZAt);
+
+ gp_Vec anEyeVec(EyePoint, AtPoint);
+ anEyeVec.Normalize();
+
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z());
+
+ double aDen = anEyeVec*aNormalVec;
+ double aLVec = aDen != 0 ? aVec*aNormalVec/aDen : aVec*aNormalVec;
+
+ gp_Vec aDeltaVec = anEyeVec*aLVec;
+ aVec = aVec - aDeltaVec;
+ }
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 theX the X coordinate
/// \param theY the Y coordinate
static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
- double& theX, double& theY);
+ Handle(V3d_View) theView, double& theX, double& theY);
};
#endif
<context>
<name>XGUI_DocumentDataModel</name>
<message>
- <location filename="XGUI_DocumentDataModel.cpp" line="152"/>
+ <location filename="XGUI_DocumentDataModel.cpp" line="151"/>
<source>Parts</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_DocumentDataModel.cpp" line="156"/>
+ <location filename="XGUI_DocumentDataModel.cpp" line="155"/>
<source>Parts folder</source>
<translation type="unfinished"></translation>
</message>
<context>
<name>XGUI_PartDataModel</name>
<message>
- <location filename="XGUI_PartDataModel.cpp" line="191"/>
+ <location filename="XGUI_PartDataModel.cpp" line="190"/>
<source>Parameters</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_PartDataModel.cpp" line="193"/>
+ <location filename="XGUI_PartDataModel.cpp" line="192"/>
<source>Constructions</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_PartDataModel.cpp" line="195"/>
+ <location filename="XGUI_PartDataModel.cpp" line="194"/>
<source>Bodies</source>
<translation type="unfinished"></translation>
</message>
<context>
<name>XGUI_TopDataModel</name>
<message>
- <location filename="XGUI_PartDataModel.cpp" line="29"/>
+ <location filename="XGUI_PartDataModel.cpp" line="28"/>
<source>Parameters</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="XGUI_PartDataModel.cpp" line="37"/>
+ <location filename="XGUI_PartDataModel.cpp" line="36"/>
<source>Constructions</source>
<translation type="unfinished"></translation>
</message>