From: nds Date: Thu, 8 May 2014 09:03:14 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~78^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4cf50a4691e74d25af0974685281647d575adedc;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Correct the line point projection for turned view. --- diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index 1085f2d33..46f3b4056 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -65,11 +65,11 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie 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; diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index a0ab16944..6fe2f6a01 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -60,12 +60,12 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 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()); @@ -83,7 +83,7 @@ void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_V 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: @@ -141,6 +141,7 @@ boost::shared_ptr PartSet_OperationSketchLine::createFeature() } void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, + Handle(V3d_View) theView, const std::string& theAttribute) { boost::shared_ptr aData = feature()->data(); @@ -148,6 +149,6 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, boost::dynamic_pointer_cast(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); } diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index e979034dd..b4979a9c3 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -80,7 +80,7 @@ protected: /// \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 diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index b2d24c396..04a41572a 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -25,27 +25,27 @@ gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theV 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 theSketch, - double& theX, double& theY) + Handle(V3d_View) theView, double& theX, double& theY) { if (!theSketch) return; @@ -61,7 +61,31 @@ void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr anY = boost::dynamic_pointer_cast(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 aNormal = + boost::dynamic_pointer_cast(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(); } diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 759f490d5..19cdccb2e 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -34,7 +34,7 @@ public: /// \param theX the X coordinate /// \param theY the Y coordinate static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr theSketch, - double& theX, double& theY); + Handle(V3d_View) theView, double& theX, double& theY); }; #endif diff --git a/src/XGUI/XGUI_msg_fr.ts b/src/XGUI/XGUI_msg_fr.ts index 5562247ba..001a0a331 100644 --- a/src/XGUI/XGUI_msg_fr.ts +++ b/src/XGUI/XGUI_msg_fr.ts @@ -4,12 +4,12 @@ XGUI_DocumentDataModel - + Parts - + Parts folder @@ -54,17 +54,17 @@ XGUI_PartDataModel - + Parameters - + Constructions - + Bodies @@ -80,12 +80,12 @@ XGUI_TopDataModel - + Parameters - + Constructions