From: azv Date: Wed, 25 Mar 2015 08:45:23 +0000 (+0300) Subject: Placement algorithm takes into account the orientation of the edges since now X-Git-Tag: V_1.1.0~91^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c7f578893a15f81349d32556b3501c44763e9418;p=modules%2Fshaper.git Placement algorithm takes into account the orientation of the edges since now --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp index d2ab51bd5..4b815e3a1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp @@ -82,6 +82,30 @@ void GeomAlgoAPI_Placement::build( hasDirection[i] = aSrcDstDirections[i].SquareMagnitude() >= Precision::SquareConfusion(); } + // Initial shapes + const TopoDS_Shape& aSourceShape = theSourceSolid->impl(); + const TopoDS_Shape& aDestShape = theDestSolid->impl(); + // 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(); - const TopoDS_Shape& aDestShape = theDestSolid->impl(); + // 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);