]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Thu, 8 May 2014 09:03:14 +0000 (13:03 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 8 May 2014 09:03:14 +0000 (13:03 +0400)
Correct the line point projection for turned view.

src/PartSet/PartSet_OperationEditLine.cpp
src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/XGUI/XGUI_msg_fr.ts

index 1085f2d334f5c78ed88c801624abd1d20f2efe7b..46f3b4056127880237f6253f3bbcaa76bea6f374 100644 (file)
@@ -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;
index a0ab16944dccf4adb1b251849df9405b39846d20..6fe2f6a013724c9ead1dd7f97ca38406a3887531 100644 (file)
@@ -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<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
 }
 
 void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
+                                               Handle(V3d_View) theView,
                                                const std::string& theAttribute)
 {
   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
@@ -148,6 +149,6 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
         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);
 }
index e979034ddbc46c74f878143b5631025c37389d6c..b4979a9c3e3288838fa8ad3d55f6ca567e3593cf 100644 (file)
@@ -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
index b2d24c3963eb56eb2edb9363b6692dad9c281949..04a41572a457de064d2738ef8a746171bcd1f0c9 100644 (file)
@@ -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<ModelAPI_Feature> 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<ModelA
   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();
 }
index 759f490d540b0edd87a4aadc0cfec040ae2fe1b8..19cdccb2ed1580255fbc50945cc48bd4d269d75e 100644 (file)
@@ -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<ModelAPI_Feature> theSketch,
-                          double& theX, double& theY);
+                          Handle(V3d_View) theView, double& theX, double& theY);
 };
 
 #endif
index 5562247ba790b50313d639e712491ecfa5defbab..001a0a3315cae7feefc7eb46fabbb76359cd2fc0 100644 (file)
@@ -4,12 +4,12 @@
 <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>