Salome HOME
Placement algorithm takes into account the orientation of the edges since now
authorazv <azv@opencascade.com>
Wed, 25 Mar 2015 08:45:23 +0000 (11:45 +0300)
committerazv <azv@opencascade.com>
Wed, 25 Mar 2015 08:46:00 +0000 (11:46 +0300)
src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp

index d2ab51bd555e31e6f16ef7b0b896bb97842eb4be..4b815e3a10a584bcb2ca22f6f3d892c1bac8fee6 100644 (file)
@@ -82,6 +82,30 @@ void GeomAlgoAPI_Placement::build(
     hasDirection[i] = aSrcDstDirections[i].SquareMagnitude() >= Precision::SquareConfusion();
   }
 
+  // Initial shapes
+  const TopoDS_Shape& aSourceShape = theSourceSolid->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aDestShape = theDestSolid->impl<TopoDS_Shape>();
+  // Check the material of the solids to be on the correct side
+  BRepClass3d_SolidClassifier aClassifier;
+  static const double aTransStep = 10. * Precision::Confusion();
+  if (hasNormal[0]) {
+    aClassifier.Load(aSourceShape);
+    gp_Pnt aPoint = aSrcDstPoints[0];
+    aPoint.Translate(aSrcDstNormals[0] * aTransStep);
+    aClassifier.Perform(aPoint, Precision::Confusion());
+    if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
+        (aClassifier.State() == TopAbs_IN && theIsReverse))
+      aSrcDstNormals[0].Reverse();
+  }
+  if (hasNormal[1]) {
+    aClassifier.Load(aDestShape);
+    gp_Pnt aPoint = aSrcDstPoints[1];
+    aPoint.Translate(aSrcDstNormals[1] * aTransStep);
+    aClassifier.Perform(aPoint, Precision::Confusion());
+    if (aClassifier.State() == TopAbs_IN)
+      aSrcDstNormals[1].Reverse();
+  }
+
   // Calculate directions, which comply the normal, for vertices and edges
   if (!hasNormal[0] || !hasNormal[1]) {
     if (hasNormal[0] || hasNormal[1]) { // plane with line or vertex
@@ -119,8 +143,10 @@ void GeomAlgoAPI_Placement::build(
         }
         aSrcDstNormals[0] = aSrcDstDirections[0].Crossed(aVec);
         aSrcDstNormals[0].Normalize();
-        aSrcDstNormals[1] = aSrcDstDirections[1].Crossed(aVec).Reversed();
+        aSrcDstNormals[1] = aSrcDstDirections[1].Crossed(aVec);
         aSrcDstNormals[1].Normalize();
+        if (aSrcDstDirections[0].Dot(aSrcDstDirections[1]) < -Precision::Confusion())
+          aSrcDstNormals[1].Reverse();
       } else if (!hasDirection[0] && !hasDirection[1]) { // point - point
         aSrcDstNormals[0] = gp_Vec(aSrcDstPoints[0], aSrcDstPoints[1]);
         aSrcDstNormals[0].Normalize();
@@ -142,35 +168,14 @@ void GeomAlgoAPI_Placement::build(
     }
   }
 
-  // Initial shapes
-  const TopoDS_Shape& aSourceShape = theSourceSolid->impl<TopoDS_Shape>();
-  const TopoDS_Shape& aDestShape = theDestSolid->impl<TopoDS_Shape>();
+  // Reverse the normal if it was not done before
+  if (!hasNormal[0] && theIsReverse)
+    aSrcDstNormals[0].Reverse();
 
   // Calculate transformation
   gp_Trsf aTrsf;
   gp_Vec aSrcDir = aSrcDstNormals[0];
   gp_Vec aDstDir = aSrcDstNormals[1];
-  // Check the material of the solids to be on the correct side
-  BRepClass3d_SolidClassifier aClassifier;
-  static const double aTransStep = 10. * Precision::Confusion();
-  if (hasNormal[0]) {
-    aClassifier.Load(aSourceShape);
-    gp_Pnt aPoint = aSrcDstPoints[0];
-    aPoint.Translate(aSrcDir * aTransStep);
-    aClassifier.Perform(aPoint, Precision::Confusion());
-    if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
-        (aClassifier.State() == TopAbs_IN && theIsReverse))
-      aSrcDir.Reverse();
-  } else if (theIsReverse)
-    aSrcDir.Reverse();
-  if (hasNormal[1]) {
-    aClassifier.Load(aDestShape);
-    gp_Pnt aPoint = aSrcDstPoints[1];
-    aPoint.Translate(aDstDir * aTransStep);
-    aClassifier.Perform(aPoint, Precision::Confusion());
-    if (aClassifier.State() == TopAbs_IN)
-      aDstDir.Reverse();
-  }
   // Calculate rotation
   gp_Quaternion aRot(aSrcDir, aDstDir);
   aTrsf.SetRotation(aRot);