Salome HOME
Copyright update 2022
[modules/smesh.git] / src / Tools / blocFissure / gmu / rotTrans.py
index 7b8ff6e476cee960d0625dfb049c504966e156c1..fcdd25af79ea5da8dc9b160fae2ded56f302905c 100644 (file)
@@ -1,13 +1,35 @@
 # -*- coding: utf-8 -*-
+# Copyright (C) 2014-2022  EDF R&D
+#
+# 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, or (at your option) any later version.
+#
+# 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 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
+#
+"""Opérateur de rotation translation d'un objet centré à l'origine"""
 
 import logging
-from geomsmesh import geompy
 import math
-from triedreBase import triedreBase
-O, OX, OY, OZ = triedreBase()
 
-# -----------------------------------------------------------------------------
-# --- operateur de rotation translation d'un objet centré à l'origine
+from .geomsmesh import geompy
+from .geomsmesh import geomPublish
+
+from . import initLog
+
+from .triedreBase import triedreBase
+
+O, OX, OY, OZ = triedreBase()
 
 def rotTrans(objet, orientation, point, normal, trace = False):
   """
@@ -20,38 +42,40 @@ def rotTrans(objet, orientation, point, normal, trace = False):
   @return trans : objet transformé (geomObject)
   """
   logging.info("start")
+
   planXY = geompy.MakePlaneLCS(None, 2000, 1)
   projXY = geompy.MakeProjection(normal, planXY)
-  [v1,v2] = geompy.ExtractShapes(projXY, geompy.ShapeType["VERTEX"], False)
-  xyz1 = geompy.PointCoordinates(v1)
-  xyz2 = geompy.PointCoordinates(v2)
+
+  [v_1,v_2] = geompy.ExtractShapes(projXY, geompy.ShapeType["VERTEX"], False)
+  xyz1 = geompy.PointCoordinates(v_1)
+  xyz2 = geompy.PointCoordinates(v_2)
   x = xyz2[0] - xyz1[0]
   y = xyz2[1] - xyz1[1]
   sinalpha = y / math.sqrt(x*x + y*y)
   cosalpha = x / math.sqrt(x*x + y*y)
   alpha = math.asin(sinalpha)
-  if cosalpha < 0:
+  if ( cosalpha < 0. ):
     alpha = math.pi -alpha
 
   beta = geompy.GetAngleRadians(OZ, normal)
-  [v1,v2] = geompy.ExtractShapes(normal, geompy.ShapeType["VERTEX"], False)
-  xyz1 = geompy.PointCoordinates(v1)
-  xyz2 = geompy.PointCoordinates(v2)
-  z = xyz2[2] - xyz1[2]
-  if z < 0:
+  [v_1,v_2] = geompy.ExtractShapes(normal, geompy.ShapeType["VERTEX"], False)
+  xyz1 = geompy.PointCoordinates(v_1)
+  xyz2 = geompy.PointCoordinates(v_2)
+  if ( (xyz2[2] - xyz1[2]) < 0 ):
     beta = math.pi -beta
 
   rot0 = geompy.MakeRotation(objet, OX, orientation*math.pi/180.0)
   rot1 = geompy.MakeRotation(rot0, OZ, alpha)
   axe2 = geompy.MakeRotation(OY, OZ, alpha)
   rot2 = geompy.MakeRotation(rot1, axe2, beta -math.pi/2.)
-  logging.debug("alpha",alpha)
-  logging.debug("beta",beta)
+  logging.debug("alpha %f",alpha)
+  logging.debug("beta %f",beta)
   if trace:
-    geompy.addToStudy( rot1, 'rot1' )
-    geompy.addToStudy( axe2, 'axe2' )
-    geompy.addToStudy( rot2, 'rot2' )
+    geomPublish(initLog.debug,  rot1, 'rot1' )
+    geomPublish(initLog.debug,  axe2, 'axe2' )
+    geomPublish(initLog.debug,  rot2, 'rot2' )
 
   xyz = geompy.PointCoordinates(point)
   trans = geompy.MakeTranslation(rot2, xyz[0], xyz[1], xyz[2])
+
   return trans