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 pp0 = p0 - [0,0,self.parent.getObjectSize()[2]/2]
95 pp1 = p1 - [0,0,self.parent.getObjectSize()[2]/2]
96 cursorX0 = pp0 - (pp1 - pp0) * (pp0[0] / (pp1[0] - pp0[0]))
97 cursorY0 = pp0 - (pp1 - pp0) * (pp0[1] / (pp1[1] - pp0[1]))
98 cursorZ0 = pp0 - (pp1 - pp0) * (pp0[2] / (pp1[2] - pp0[2]))
99 cursorYZ = math.sqrt((cursorX0[1] * cursorX0[1]) + (cursorX0[2] * cursorX0[2]))
100 cursorXZ = math.sqrt((cursorY0[0] * cursorY0[0]) + (cursorY0[2] * cursorY0[2]))
101 cursorXY = math.sqrt((cursorZ0[0] * cursorZ0[0]) + (cursorZ0[1] * cursorZ0[1]))
102 return cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY
104 def OnMouseMove(self, p0, p1):
105 radius = self.parent.getObjectBoundaryCircle()
106 cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY = self._ProjectToPlanes(p0, p1)
107 oldDragPlane = self.dragPlane
108 if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorYZ <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
109 self.parent.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
110 if self.dragStartAngle is None:
111 if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax:
112 self.dragPlane = 'XY'
113 elif radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
114 self.dragPlane = 'XZ'
116 self.dragPlane = 'YZ'
118 if self.dragStartAngle is None:
120 self.parent.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
122 def OnDragStart(self, p0, p1):
123 radius = self.parent.getObjectBoundaryCircle()
124 cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY = self._ProjectToPlanes(p0, p1)
125 if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorYZ <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
126 if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax:
127 self.dragPlane = 'XY'
128 self.dragStartAngle = math.atan2(cursorZ0[1], cursorZ0[0]) * 180 / math.pi
129 elif radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
130 self.dragPlane = 'XZ'
131 self.dragStartAngle = math.atan2(cursorY0[2], cursorY0[0]) * 180 / math.pi
133 self.dragPlane = 'YZ'
134 self.dragStartAngle = math.atan2(cursorX0[2], cursorX0[1]) * 180 / math.pi
138 def OnDrag(self, p0, p1):
139 cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY = self._ProjectToPlanes(p0, p1)
140 if self.dragPlane == 'XY':
141 angle = math.atan2(cursorZ0[1], cursorZ0[0]) * 180 / math.pi
142 elif self.dragPlane == 'XZ':
143 angle = math.atan2(cursorY0[2], cursorY0[0]) * 180 / math.pi
145 angle = math.atan2(cursorX0[2], cursorX0[1]) * 180 / math.pi
146 diff = angle - self.dragStartAngle
147 if wx.GetKeyState(wx.WXK_SHIFT):
148 diff = round(diff / 1) * 1
150 diff = round(diff / 15) * 15
155 rad = diff / 180.0 * math.pi
156 self.dragEndAngle = self.dragStartAngle + diff
157 if self.dragPlane == 'XY':
158 self.parent.tempMatrix = numpy.matrix([[math.cos(rad), math.sin(rad), 0], [-math.sin(rad), math.cos(rad), 0], [0,0,1]], numpy.float64)
159 elif self.dragPlane == 'XZ':
160 self.parent.tempMatrix = numpy.matrix([[math.cos(rad), 0, math.sin(rad)], [0,1,0], [-math.sin(rad), 0, math.cos(rad)]], numpy.float64)
162 self.parent.tempMatrix = numpy.matrix([[1,0,0], [0, math.cos(rad), math.sin(rad)], [0, -math.sin(rad), math.cos(rad)]], numpy.float64)
165 self.dragStartAngle = None
168 glDisable(GL_LIGHTING)
170 glDisable(GL_DEPTH_TEST)
171 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
172 radius = self.parent.getObjectBoundaryCircle()
173 glScalef(self.rotateRingDist * radius, self.rotateRingDist * radius, self.rotateRingDist * radius)
174 if self.dragPlane == 'XY':
176 glColor4ub(255,64,64,255)
177 if self.dragStartAngle is not None:
179 glRotate(self.dragStartAngle, 0,0,1)
186 glRotate(self.dragEndAngle, 0,0,1)
191 glTranslatef(1.1,0,0)
192 glColor4ub(0,0,0,255)
193 opengl.glDrawStringCenter("%d" % (abs(self.dragEndAngle - self.dragStartAngle)))
194 glColor4ub(255,64,64,255)
198 glColor4ub(128,0,0,255)
199 glBegin(GL_LINE_LOOP)
200 for i in xrange(0, 64):
201 glVertex3f(math.cos(i/32.0*math.pi), math.sin(i/32.0*math.pi),0)
203 if self.dragPlane == 'YZ':
204 glColor4ub(64,255,64,255)
206 if self.dragStartAngle is not None:
208 glRotate(self.dragStartAngle, 1,0,0)
215 glRotate(self.dragEndAngle, 1,0,0)
220 glTranslatef(0,1.1,0)
221 glColor4ub(0,0,0,255)
222 opengl.glDrawStringCenter("%d" % (abs(self.dragEndAngle - self.dragStartAngle)))
223 glColor4ub(64,255,64,255)
226 glColor4ub(0,128,0,255)
228 glBegin(GL_LINE_LOOP)
229 for i in xrange(0, 64):
230 glVertex3f(0, math.cos(i/32.0*math.pi), math.sin(i/32.0*math.pi))
232 if self.dragPlane == 'XZ':
234 glColor4ub(255,255,0,255)
235 if self.dragStartAngle is not None:
237 glRotate(self.dragStartAngle, 0,-1,0)
244 glRotate(self.dragEndAngle, 0,-1,0)
249 glTranslatef(1.1,0,0)
250 glColor4ub(0,0,0,255)
251 opengl.glDrawStringCenter("%d" % (abs(self.dragEndAngle - self.dragStartAngle)))
252 glColor4ub(255,255,0,255)
255 glColor4ub(128,128,0,255)
257 glBegin(GL_LINE_LOOP)
258 for i in xrange(0, 64):
259 glVertex3f(math.cos(i/32.0*math.pi), 0, math.sin(i/32.0*math.pi))
261 glEnable(GL_DEPTH_TEST)
263 class toolScale(object):
264 def __init__(self, parent):
269 def _pointDist(self, p0, p1, p2):
270 return numpy.linalg.norm(numpy.cross((p0 - p1), (p0 - p2))) / numpy.linalg.norm(p2 - p1)
272 def _traceNodes(self, p0, p1):
273 pp0 = p0 - [0,0,self.parent.getObjectSize()[2]/2]
274 pp1 = p1 - [0,0,self.parent.getObjectSize()[2]/2]
276 if self._pointDist(numpy.array([0,0,0],numpy.float32), pp0, pp1) < s * 2:
278 if self._pointDist(numpy.array([s*15,0,0],numpy.float32), pp0, pp1) < s * 2:
280 if self._pointDist(numpy.array([0,s*15,0],numpy.float32), pp0, pp1) < s * 2:
282 if self._pointDist(numpy.array([0,0,s*15],numpy.float32), pp0, pp1) < s * 2:
286 def _lineLineCrossingDistOnLine(self, s0, e0, s1, e1):
289 a = numpy.dot(d0, d0)
290 b = numpy.dot(d0, d1)
291 e = numpy.dot(d1, d1)
303 return self.parent.zoom / self.parent.GetSize().GetWidth() * 6
305 def OnMouseMove(self, p0, p1):
306 self.node = self._traceNodes(p0, p1)
308 def OnDragStart(self, p0, p1):
309 if self.node is None:
313 def OnDrag(self, p0, p1):
315 pp0 = p0 - [0,0,self.parent.getObjectSize()[2]/2]
316 pp1 = p1 - [0,0,self.parent.getObjectSize()[2]/2]
324 scale = self._lineLineCrossingDistOnLine(pp0, pp1, numpy.array([0,0,0], numpy.float32), numpy.array(endPoint, numpy.float32)) / 15.0 / s
325 if not wx.GetKeyState(wx.WXK_SHIFT):
326 scale = round(scale * 10) / 10
332 if self.node == 1 or not wx.GetKeyState(wx.WXK_CONTROL):
333 self.parent.tempMatrix = numpy.matrix([[scale,0,0], [0, scale, 0], [0, 0, scale]], numpy.float64)
335 self.parent.tempMatrix = numpy.matrix([[scale,0,0], [0, 1, 0], [0, 0, 1]], numpy.float64)
337 self.parent.tempMatrix = numpy.matrix([[1,0,0], [0, scale, 0], [0, 0, 1]], numpy.float64)
339 self.parent.tempMatrix = numpy.matrix([[1,0,0], [0, 1, 0], [0, 0, scale]], numpy.float64)
349 if self.node == 2 and self.scale is not None:
351 if self.node == 3 and self.scale is not None:
353 if self.node == 4 and self.scale is not None:
355 scaleX = numpy.linalg.norm(self.parent.parent.matrix[0].getA().flatten())
356 scaleY = numpy.linalg.norm(self.parent.parent.matrix[1].getA().flatten())
357 scaleZ = numpy.linalg.norm(self.parent.parent.matrix[2].getA().flatten())
358 if self.scale is not None:
363 glDisable(GL_LIGHTING)
364 glDisable(GL_DEPTH_TEST)
366 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
373 glColor3ub(128,128,0)
383 glColor3ub(255,255,255)
385 glColor3ub(192,192,192)
386 opengl.DrawBox([-s,-s,-s], [s,s,s])
389 opengl.glDrawStringCenter("%0.2f" % ((scaleX + scaleY + scaleZ) / 3.0))
392 glColor3ub(255,64,64)
397 opengl.DrawBox([-s,-s,-s], [s,s,s])
400 opengl.glDrawStringCenter("%0.2f" % (scaleX))
403 glColor3ub(255,255,0)
405 glColor3ub(128,128,0)
408 opengl.DrawBox([-s,-s,-s], [s,s,s])
411 opengl.glDrawStringCenter("%0.2f" % (scaleY))
414 glColor3ub(64,255,64)
419 opengl.DrawBox([-s,-s,-s], [s,s,s])
422 opengl.glDrawStringCenter("%0.2f" % (scaleZ))
425 glEnable(GL_DEPTH_TEST)