Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/geom.git] / src / GEOM_PY / structelem / orientation.py
index 1bf11179141f9f4519dbb224d18e5329cdc995e7..44c9b90f950531bb7975ee15a07b2b597822d676 100644 (file)
@@ -1,22 +1,22 @@
 # -*- coding: utf-8 -*-
 #
-#  Copyright (C) 2007-2009      EDF R&D
-# 
-#    This file is part of PAL_SRC.
+# Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 #
-#    PAL_SRC is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
 #
-#    PAL_SRC is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
-#    You should have received a copy of the GNU General Public License
-#    along with PAL_SRC; if not, write to the Free Software
-#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 """
 This module is used to compute the orientation of the different parts in a
@@ -80,11 +80,11 @@ class Orientation1D:
             logger.warning("Invalid orientation parameter(s) (ignored): %s" %
                            str(mydict))
 
-    def _buildDefaultMarker(self, center, vecX):
+    def _getDefaultVecYZ(self, center, vecX):
         """
-        Create the default marker, that use the main direction of the 1D
-        object as the local X axis and the global Z axis to determine the
-        local Z axis.
+        Get the vectors Y and Z for the default LCS, that use the main
+        direction of the 1D object as the local X axis and the global Z axis
+        to determine the local Z axis.
         """
         xPoint = self.geom.MakeTranslationVector(center, vecX)
         givenVecZ = self.geom.MakeVectorDXDYDZ(0.0, 0.0, 1.0)
@@ -97,18 +97,31 @@ class Orientation1D:
         zPoint = self.geom.MakeTranslationVector(center, givenVecZ)
         locPlaneZX = self.geom.MakePlaneThreePnt(center, zPoint, xPoint, 1.0)
         locY = self.geom.GetNormal(locPlaneZX)
-        marker = self.geom.MakeMarkerPntTwoVec(center,vecX,locY)
-        return marker
+        yPoint = self.geom.MakeTranslationVector(center, locY)
+        locPlaneXY = self.geom.MakePlaneThreePnt(center, xPoint, yPoint, 1.0)
+        locZ = self.geom.GetNormal(locPlaneXY)
+        return (locY, locZ)
 
     def buildMarker(self, geom, center, vecX):
         """
         Create a marker with origin `center` and X axis `vecX`. `geom` is the
         pseudo-geompy object used to build the geometric shapes.
         """
+        (locY, locZ) = self.getVecYZ(geom, center, vecX)
+        marker = geom.MakeMarkerPntTwoVec(center, vecX, locY)
+        return marker
+
+    def getVecYZ(self, geom, center, vecX):
+        """
+        Get the vectors Y and Z for the LCS with origin `center` and X axis
+        `vecX`. `geom` is the pseudo-geompy object used to build the geometric
+        shapes.
+        """
         self.geom = geom
-        marker = None
+        locY = None
+        locZ = None
         if self._vectorYCoords is None:
-            marker = self._buildDefaultMarker(center, vecX)
+            (locY, locZ) = self._getDefaultVecYZ(center, vecX)
         else:
             xPoint = self.geom.MakeTranslationVector(center, vecX)
             givenLocY = self.geom.MakeVectorDXDYDZ(self._vectorYCoords[0],
@@ -118,7 +131,7 @@ class Orientation1D:
             if abs(angle) < 1e-7 or abs(angle - math.pi) < 1e-7:
                 logger.warning("Vector Y is colinear to the beam X axis, "
                                "using default LCS.")
-                marker = self._buildDefaultMarker(center, vecX)
+                (locY, locZ) = self._getDefaultVecYZ(center, vecX)
             else:
                 yPoint = self.geom.MakeTranslationVector(center, givenLocY)
                 locPlaneXY = self.geom.MakePlaneThreePnt(center, xPoint,
@@ -128,13 +141,13 @@ class Orientation1D:
                 locPlaneZX = self.geom.MakePlaneThreePnt(center, zPoint,
                                                          xPoint, 1.0)
                 locY = self.geom.GetNormal(locPlaneZX)
-                marker = self.geom.MakeMarkerPntTwoVec(center,vecX,locY)
 
         if self._angle != 0.0:
             angleRad = math.radians(self._angle)
-            marker = self.geom.Rotate(marker, vecX, angleRad)
+            locY = self.geom.Rotate(locY, vecX, angleRad)
+            locZ = self.geom.Rotate(locZ, vecX, angleRad)
 
-        return marker
+        return (locY, locZ)
 
 
 class Orientation2D: