1 from __future__ import absolute_import
8 OpenGL.ERROR_CHECKING = False
9 from OpenGL.GLU import *
10 from OpenGL.GL import *
12 from Cura.gui.util import opengl
14 class toolInfo(object):
15 def __init__(self, parent):
18 def OnMouseMove(self, p0, p1):
21 def OnDragStart(self, p0, p1):
24 def OnDrag(self, p0, p1):
31 glDisable(GL_LIGHTING)
33 glDisable(GL_DEPTH_TEST)
34 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
36 size = self.parent.getObjectSize()
37 radius = self.parent.getObjectBoundaryCircle()
39 glTranslate(0,0,size[2]/2 + 5)
40 glRotate(-self.parent.yaw, 0,0,1)
41 if self.parent.pitch < 80:
42 glTranslate(0, radius + 5,0)
43 elif self.parent.pitch < 100:
44 glTranslate(0, (radius + 5) * (90 - self.parent.pitch) / 10,0)
46 glTranslate(0,-(radius + 5),0)
47 opengl.glDrawStringCenter("%dx%dx%d" % (size[0], size[1], size[2]))
54 glVertex3f(size[0], size[1], size[2])
55 glVertex3f(size[0], size[1], size[2]/4*3)
56 glVertex3f(size[0], size[1], size[2])
57 glVertex3f(size[0], size[1]/4*3, size[2])
58 glVertex3f(size[0], size[1], size[2])
59 glVertex3f(size[0]/4*3, size[1], size[2])
61 glVertex3f(-size[0], -size[1], size[2])
62 glVertex3f(-size[0], -size[1], size[2]/4*3)
63 glVertex3f(-size[0], -size[1], size[2])
64 glVertex3f(-size[0], -size[1]/4*3, size[2])
65 glVertex3f(-size[0], -size[1], size[2])
66 glVertex3f(-size[0]/4*3, -size[1], size[2])
68 glVertex3f(size[0], -size[1], -size[2])
69 glVertex3f(size[0], -size[1], -size[2]/4*3)
70 glVertex3f(size[0], -size[1], -size[2])
71 glVertex3f(size[0], -size[1]/4*3, -size[2])
72 glVertex3f(size[0], -size[1], -size[2])
73 glVertex3f(size[0]/4*3, -size[1], -size[2])
75 glVertex3f(-size[0], size[1], -size[2])
76 glVertex3f(-size[0], size[1], -size[2]/4*3)
77 glVertex3f(-size[0], size[1], -size[2])
78 glVertex3f(-size[0], size[1]/4*3, -size[2])
79 glVertex3f(-size[0], size[1], -size[2])
80 glVertex3f(-size[0]/4*3, size[1], -size[2])
83 class toolRotate(object):
84 def __init__(self, parent):
86 self.rotateRingDist = 1.5
87 self.rotateRingDistMin = 1.3
88 self.rotateRingDistMax = 1.7
90 self.dragStartAngle = None
91 self.dragEndAngle = None
93 def _ProjectToPlanes(self, p0, p1):
94 cursorX0 = p0 - (p1 - p0) * (p0[0] / (p1[0] - p0[0]))
95 cursorY0 = p0 - (p1 - p0) * (p0[1] / (p1[1] - p0[1]))
96 cursorZ0 = p0 - (p1 - p0) * (p0[2] / (p1[2] - p0[2]))
97 cursorYZ = math.sqrt((cursorX0[1] * cursorX0[1]) + (cursorX0[2] * cursorX0[2]))
98 cursorXZ = math.sqrt((cursorY0[0] * cursorY0[0]) + (cursorY0[2] * cursorY0[2]))
99 cursorXY = math.sqrt((cursorZ0[0] * cursorZ0[0]) + (cursorZ0[1] * cursorZ0[1]))
100 return cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY
102 def OnMouseMove(self, p0, p1):
103 radius = self.parent.getObjectBoundaryCircle()
104 cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY = self._ProjectToPlanes(p0, p1)
105 oldDragPlane = self.dragPlane
106 if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorYZ <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
107 self.parent.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
108 if self.dragStartAngle is None:
109 if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax:
110 self.dragPlane = 'XY'
111 elif radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
112 self.dragPlane = 'XZ'
114 self.dragPlane = 'YZ'
116 if self.dragStartAngle is None:
118 self.parent.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
120 def OnDragStart(self, p0, p1):
121 radius = self.parent.getObjectBoundaryCircle()
122 cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY = self._ProjectToPlanes(p0, p1)
123 if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorYZ <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
124 if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax:
125 self.dragPlane = 'XY'
126 self.dragStartAngle = math.atan2(cursorZ0[1], cursorZ0[0]) * 180 / math.pi
127 elif radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
128 self.dragPlane = 'XZ'
129 self.dragStartAngle = math.atan2(cursorY0[2], cursorY0[0]) * 180 / math.pi
131 self.dragPlane = 'YZ'
132 self.dragStartAngle = math.atan2(cursorX0[2], cursorX0[1]) * 180 / math.pi
136 def OnDrag(self, p0, p1):
137 cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY = self._ProjectToPlanes(p0, p1)
138 if self.dragPlane == 'XY':
139 angle = math.atan2(cursorZ0[1], cursorZ0[0]) * 180 / math.pi
140 elif self.dragPlane == 'XZ':
141 angle = math.atan2(cursorY0[2], cursorY0[0]) * 180 / math.pi
143 angle = math.atan2(cursorX0[2], cursorX0[1]) * 180 / math.pi
144 diff = angle - self.dragStartAngle
145 if wx.GetKeyState(wx.WXK_SHIFT):
146 diff = round(diff / 1) * 1
148 diff = round(diff / 15) * 15
153 rad = diff / 180.0 * math.pi
154 self.dragEndAngle = self.dragStartAngle + diff
155 if self.dragPlane == 'XY':
156 self.parent.tempMatrix = numpy.matrix([[math.cos(rad), math.sin(rad), 0], [-math.sin(rad), math.cos(rad), 0], [0,0,1]], numpy.float64)
157 elif self.dragPlane == 'XZ':
158 self.parent.tempMatrix = numpy.matrix([[math.cos(rad), 0, math.sin(rad)], [0,1,0], [-math.sin(rad), 0, math.cos(rad)]], numpy.float64)
160 self.parent.tempMatrix = numpy.matrix([[1,0,0], [0, math.cos(rad), math.sin(rad)], [0, -math.sin(rad), math.cos(rad)]], numpy.float64)
163 self.dragStartAngle = None
166 glDisable(GL_LIGHTING)
168 glDisable(GL_DEPTH_TEST)
169 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
170 radius = self.parent.getObjectBoundaryCircle()
171 glScalef(self.rotateRingDist * radius, self.rotateRingDist * radius, self.rotateRingDist * radius)
172 if self.dragPlane == 'XY':
174 glColor4ub(255,64,64,255)
175 if self.dragStartAngle is not None:
177 glRotate(self.dragStartAngle, 0,0,1)
184 glRotate(self.dragEndAngle, 0,0,1)
189 glTranslatef(1.1,0,0)
190 glColor4ub(0,0,0,255)
191 opengl.glDrawStringCenter("%d" % (abs(self.dragEndAngle - self.dragStartAngle)))
192 glColor4ub(255,64,64,255)
196 glColor4ub(128,0,0,255)
197 glBegin(GL_LINE_LOOP)
198 for i in xrange(0, 64):
199 glVertex3f(math.cos(i/32.0*math.pi), math.sin(i/32.0*math.pi),0)
201 if self.dragPlane == 'YZ':
202 glColor4ub(64,255,64,255)
204 if self.dragStartAngle is not None:
206 glRotate(self.dragStartAngle, 1,0,0)
213 glRotate(self.dragEndAngle, 1,0,0)
218 glTranslatef(0,1.1,0)
219 glColor4ub(0,0,0,255)
220 opengl.glDrawStringCenter("%d" % (abs(self.dragEndAngle - self.dragStartAngle)))
221 glColor4ub(64,255,64,255)
224 glColor4ub(0,128,0,255)
226 glBegin(GL_LINE_LOOP)
227 for i in xrange(0, 64):
228 glVertex3f(0, math.cos(i/32.0*math.pi), math.sin(i/32.0*math.pi))
230 if self.dragPlane == 'XZ':
232 glColor4ub(255,255,0,255)
233 if self.dragStartAngle is not None:
235 glRotate(self.dragStartAngle, 0,-1,0)
242 glRotate(self.dragEndAngle, 0,-1,0)
247 glTranslatef(1.1,0,0)
248 glColor4ub(0,0,0,255)
249 opengl.glDrawStringCenter("%d" % (abs(self.dragEndAngle - self.dragStartAngle)))
250 glColor4ub(255,255,0,255)
253 glColor4ub(128,128,0,255)
255 glBegin(GL_LINE_LOOP)
256 for i in xrange(0, 64):
257 glVertex3f(math.cos(i/32.0*math.pi), 0, math.sin(i/32.0*math.pi))
259 glEnable(GL_DEPTH_TEST)
261 class toolScale(object):
262 def __init__(self, parent):
267 def _pointDist(self, p0, p1, p2):
268 return numpy.linalg.norm(numpy.cross((p0 - p1), (p0 - p2))) / numpy.linalg.norm(p2 - p1)
270 def _traceNodes(self, p0, p1):
272 if self._pointDist(numpy.array([0,0,0],numpy.float32), p0, p1) < s * 2:
274 if self._pointDist(numpy.array([s*15,0,0],numpy.float32), p0, p1) < s * 2:
276 if self._pointDist(numpy.array([0,s*15,0],numpy.float32), p0, p1) < s * 2:
278 if self._pointDist(numpy.array([0,0,s*15],numpy.float32), p0, p1) < s * 2:
282 def _lineLineCrossingDistOnLine(self, s0, e0, s1, e1):
285 a = numpy.dot(d0, d0)
286 b = numpy.dot(d0, d1)
287 e = numpy.dot(d1, d1)
299 return float(self.parent.zoom) / float(self.parent.GetSize().GetWidth()) * 6.0
301 def OnMouseMove(self, p0, p1):
302 self.node = self._traceNodes(p0, p1)
304 def OnDragStart(self, p0, p1):
305 if self.node is None:
309 def OnDrag(self, p0, p1):
318 scale = self._lineLineCrossingDistOnLine(p0, p1, numpy.array([0,0,0], numpy.float32), numpy.array(endPoint, numpy.float32)) / 15.0 / s
319 if not wx.GetKeyState(wx.WXK_SHIFT):
320 scale = round(scale * 10) / 10
326 if self.node == 1 or not wx.GetKeyState(wx.WXK_CONTROL):
327 self.parent.tempMatrix = numpy.matrix([[scale,0,0], [0, scale, 0], [0, 0, scale]], numpy.float64)
329 self.parent.tempMatrix = numpy.matrix([[scale,0,0], [0, 1, 0], [0, 0, 1]], numpy.float64)
331 self.parent.tempMatrix = numpy.matrix([[1,0,0], [0, scale, 0], [0, 0, 1]], numpy.float64)
333 self.parent.tempMatrix = numpy.matrix([[1,0,0], [0, 1, 0], [0, 0, scale]], numpy.float64)
343 if self.node == 2 and self.scale is not None:
345 if self.node == 3 and self.scale is not None:
347 if self.node == 4 and self.scale is not None:
349 objMatrix = self.parent.getObjectMatrix()
350 scaleX = numpy.linalg.norm(objMatrix[0].getA().flatten())
351 scaleY = numpy.linalg.norm(objMatrix[1].getA().flatten())
352 scaleZ = numpy.linalg.norm(objMatrix[2].getA().flatten())
353 if self.scale is not None:
358 glDisable(GL_LIGHTING)
359 glDisable(GL_DEPTH_TEST)
361 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
364 size = self.parent.getObjectSize()
365 radius = self.parent.getObjectBoundaryCircle() * max(scaleX, scaleY, scaleZ)
367 glTranslate(0,0,size[2]/2 + 5)
368 glRotate(-self.parent.yaw, 0,0,1)
369 if self.parent.pitch < 80:
370 glTranslate(0, radius + 5,0)
371 elif self.parent.pitch < 100:
372 glTranslate(0, (radius + 5) * (90 - self.parent.pitch) / 10,0)
374 glTranslate(0,-(radius + 5),0)
375 opengl.glDrawStringCenter("%dx%dx%d" % (size[0] * scaleX, size[1] * scaleY, size[2] * scaleZ))
383 glColor3ub(128,128,0)
393 glColor3ub(255,255,255)
395 glColor3ub(192,192,192)
396 opengl.DrawBox([-s,-s,-s], [s,s,s])
399 opengl.glDrawStringCenter("%0.2f" % ((scaleX + scaleY + scaleZ) / 3.0))
402 glColor3ub(255,64,64)
407 opengl.DrawBox([-s,-s,-s], [s,s,s])
410 opengl.glDrawStringCenter("%0.2f" % (scaleX))
413 glColor3ub(255,255,0)
415 glColor3ub(128,128,0)
418 opengl.DrawBox([-s,-s,-s], [s,s,s])
421 opengl.glDrawStringCenter("%0.2f" % (scaleY))
424 glColor3ub(64,255,64)
429 opengl.DrawBox([-s,-s,-s], [s,s,s])
432 opengl.glDrawStringCenter("%0.2f" % (scaleZ))
435 glEnable(GL_DEPTH_TEST)