Commit fbfe649b authored by sumpfralle's avatar sumpfralle

fixed visualization of toolpath directions again


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@855 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 84178b38
...@@ -25,6 +25,7 @@ from pycam.Geometry import TransformableContainer ...@@ -25,6 +25,7 @@ from pycam.Geometry import TransformableContainer
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
from pycam.Geometry.Plane import Plane from pycam.Geometry.Plane import Plane
from pycam.Geometry.utils import epsilon, sqrt from pycam.Geometry.utils import epsilon, sqrt
import pycam.Gui.OpenGLTools
import math import math
...@@ -179,35 +180,7 @@ class Line(TransformableContainer): ...@@ -179,35 +180,7 @@ class Line(TransformableContainer):
GL.glEnd() GL.glEnd()
# (optional) draw a cone for visualizing the direction of each line # (optional) draw a cone for visualizing the direction of each line
if show_directions and (self.len > 0): if show_directions and (self.len > 0):
cone_radius = self.len / 30 pycam.Gui.OpenGLTools.draw_direction_cone(self.p1, self.p2)
cone_length = self.len / 10
GL.glPushMatrix()
# move the cone to the middle of the line
GL.glTranslatef((self.p1.x + self.p2.x) / 2,
(self.p1.y + self.p2.y) / 2,
(self.p1.z + self.p2.z) / 2)
# rotate the cone according to the line direction
# The cross product is a good rotation axis.
cross = self.dir.cross(Point(0, 0, -1))
if cross.norm != 0:
# The line direction is not in line with the z axis.
angle = math.asin(sqrt(self.dir.x ** 2 + self.dir.y ** 2))
# convert from radians to degree
angle = angle / math.pi * 180
if self.dir.z < 0:
angle = 180 - angle
GL.glRotatef(angle, cross.x, cross.y, cross.z)
elif self.dir.z == -1:
# The line goes down the z axis - turn it around.
GL.glRotatef(180, 1, 0, 0)
else:
# The line goes up the z axis - nothing to be done.
pass
# center the cone
GL.glTranslatef(0, 0, -cone_length / 2)
# draw the cone
GLUT.glutSolidCone(cone_radius, cone_length, 12, 1)
GL.glPopMatrix()
def get_intersection(self, line, infinite_lines=False): def get_intersection(self, line, infinite_lines=False):
""" Get the point of intersection between two lines. Intersections """ Get the point of intersection between two lines. Intersections
......
...@@ -31,7 +31,6 @@ except (ImportError, RuntimeError): ...@@ -31,7 +31,6 @@ except (ImportError, RuntimeError):
GL_ENABLED = False GL_ENABLED = False
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
from pycam.Geometry.Line import Line
import pycam.Geometry.Matrix as Matrix import pycam.Geometry.Matrix as Matrix
from pycam.Geometry.utils import sqrt, number, epsilon from pycam.Geometry.utils import sqrt, number, epsilon
import pycam.Utils.log import pycam.Utils.log
...@@ -647,6 +646,37 @@ def keep_matrix(func): ...@@ -647,6 +646,37 @@ def keep_matrix(func):
return result return result
return keep_matrix_wrapper return keep_matrix_wrapper
@keep_matrix
def draw_direction_cone(p1, p2):
distance = p2.sub(p1)
length = distance.norm
direction = distance.normalized()
cone_radius = length / 30
cone_length = length / 10
# move the cone to the middle of the line
GL.glTranslatef((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, (p1.z + p2.z) / 2)
# rotate the cone according to the line direction
# The cross product is a good rotation axis.
cross = direction.cross(Point(0, 0, -1))
if cross.norm != 0:
# The line direction is not in line with the z axis.
angle = math.asin(sqrt(direction.x ** 2 + direction.y ** 2))
# convert from radians to degree
angle = angle / math.pi * 180
if direction.z < 0:
angle = 180 - angle
GL.glRotatef(angle, cross.x, cross.y, cross.z)
elif direction.z == -1:
# The line goes down the z axis - turn it around.
GL.glRotatef(180, 1, 0, 0)
else:
# The line goes up the z axis - nothing to be done.
pass
# center the cone
GL.glTranslatef(0, 0, -cone_length / 2)
# draw the cone
GLUT.glutSolidCone(cone_radius, cone_length, 12, 1)
@keep_matrix @keep_matrix
def draw_string(x, y, z, p, s, scale=.01): def draw_string(x, y, z, p, s, scale=.01):
GL.glPushMatrix() GL.glPushMatrix()
...@@ -817,4 +847,9 @@ def draw_toolpath(moves, color_cut, color_rapid, show_directions=False): ...@@ -817,4 +847,9 @@ def draw_toolpath(moves, color_cut, color_rapid, show_directions=False):
GL.glVertex3f(position.x, position.y, position.z) GL.glVertex3f(position.x, position.y, position.z)
last_position = position last_position = position
GL.glEnd() GL.glEnd()
if show_directions:
for index in range(len(moves) - 1):
p1 = moves[index][0]
p2 = moves[index + 1][0]
draw_direction_cone(p1, p2)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment