glColor(255,255,255)
size = size / 2
+ glLineWidth(1)
glBegin(GL_LINES)
glVertex3f(size[0], size[1], size[2])
glVertex3f(size[0], size[1], size[2]/4*3)
def __init__(self, parent):
self.parent = parent
self.rotateRingDist = 1.5
+ self.rotateRingDistMin = 1.3
+ self.rotateRingDistMax = 1.7
self.dragPlane = None
self.dragStartAngle = None
self.dragEndAngle = None
radius = self.parent.getObjectBoundaryCircle()
cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY = self._ProjectToPlanes(p0, p1)
oldDragPlane = self.dragPlane
- if radius * (self.rotateRingDist - 0.1) <= cursorXY <= radius * (self.rotateRingDist + 0.1) or radius * (self.rotateRingDist - 0.1) <= cursorYZ <= radius * (self.rotateRingDist + 0.1) or radius * (self.rotateRingDist - 0.1) <= cursorXZ <= radius * (self.rotateRingDist + 0.1):
+ if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorYZ <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
self.parent.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
if self.dragStartAngle is None:
- if radius * (self.rotateRingDist - 0.1) <= cursorXY <= radius * (self.rotateRingDist + 0.1):
+ if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax:
self.dragPlane = 'XY'
- elif radius * (self.rotateRingDist - 0.1) <= cursorXZ <= radius * (self.rotateRingDist + 0.1):
+ elif radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
self.dragPlane = 'XZ'
else:
self.dragPlane = 'YZ'
def OnDragStart(self, p0, p1):
radius = self.parent.getObjectBoundaryCircle()
cursorX0, cursorY0, cursorZ0, cursorYZ, cursorXZ, cursorXY = self._ProjectToPlanes(p0, p1)
- if radius * (self.rotateRingDist - 0.1) <= cursorXY <= radius * (self.rotateRingDist + 0.1) or radius * (self.rotateRingDist - 0.1) <= cursorYZ <= radius * (self.rotateRingDist + 0.1) or radius * (self.rotateRingDist - 0.1) <= cursorXZ <= radius * (self.rotateRingDist + 0.1):
- if radius * (self.rotateRingDist - 0.1) <= cursorXY <= radius * (self.rotateRingDist + 0.1):
+ if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorYZ <= radius * self.rotateRingDistMax or radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
+ if radius * self.rotateRingDistMin <= cursorXY <= radius * self.rotateRingDistMax:
self.dragPlane = 'XY'
self.dragStartAngle = math.atan2(cursorZ0[1], cursorZ0[0]) * 180 / math.pi
- elif radius * (self.rotateRingDist - 0.1) <= cursorXZ <= radius * (self.rotateRingDist + 0.1):
+ elif radius * self.rotateRingDistMin <= cursorXZ <= radius * self.rotateRingDistMax:
self.dragPlane = 'XZ'
self.dragStartAngle = math.atan2(cursorY0[2], cursorY0[0]) * 180 / math.pi
else:
def OnDraw(self):
glDisable(GL_LIGHTING)
glDisable(GL_BLEND)
+ glDisable(GL_DEPTH_TEST)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
radius = self.parent.getObjectBoundaryCircle()
glScalef(self.rotateRingDist * radius, self.rotateRingDist * radius, self.rotateRingDist * radius)
if self.dragPlane == 'XY':
+ glLineWidth(3)
glColor4ub(255,64,64,255)
if self.dragStartAngle is not None:
glPushMatrix()
glColor4ub(255,64,64,255)
glPopMatrix()
else:
+ glLineWidth(1)
glColor4ub(128,0,0,255)
glBegin(GL_LINE_LOOP)
for i in xrange(0, 64):
glEnd()
if self.dragPlane == 'YZ':
glColor4ub(64,255,64,255)
+ glLineWidth(3)
if self.dragStartAngle is not None:
glPushMatrix()
glRotate(self.dragStartAngle, 1,0,0)
glPopMatrix()
else:
glColor4ub(0,128,0,255)
+ glLineWidth(1)
glBegin(GL_LINE_LOOP)
for i in xrange(0, 64):
glVertex3f(0, math.cos(i/32.0*math.pi), math.sin(i/32.0*math.pi))
glEnd()
if self.dragPlane == 'XZ':
+ glLineWidth(3)
glColor4ub(255,255,0,255)
if self.dragStartAngle is not None:
glPushMatrix()
glPopMatrix()
else:
glColor4ub(128,128,0,255)
+ glLineWidth(1)
glBegin(GL_LINE_LOOP)
for i in xrange(0, 64):
glVertex3f(math.cos(i/32.0*math.pi), 0, math.sin(i/32.0*math.pi))
glEnd()
+ glEnable(GL_DEPTH_TEST)
class toolScale(object):
def __init__(self, parent):
self.parent = parent
+ self.node = None
+
+ def _pointDist(self, p0, p1, p2):
+ return numpy.linalg.norm(numpy.cross((p0 - p1), (p0 - p2))) / numpy.linalg.norm(p2 - p1)
+
+ def _traceNodes(self, p0, p1):
+ pp0 = p0 - [0,0,self.parent.getObjectSize()[2]/2]
+ pp1 = p1 - [0,0,self.parent.getObjectSize()[2]/2]
+ s = self._nodeSize()
+ if self._pointDist(numpy.array([0,0,0]), pp0, pp1) < s * 2:
+ return 1
+ if self._pointDist(numpy.array([s*15,0,0]), pp0, pp1) < s * 2:
+ return 2
+ if self._pointDist(numpy.array([0,s*15,0]), pp0, pp1) < s * 2:
+ return 3
+ if self._pointDist(numpy.array([0,0,s*15]), pp0, pp1) < s * 2:
+ return 4
+ return None
+
+ def _nodeSize(self):
+ return self.parent.zoom / self.parent.GetSize().GetWidth() * 6
def OnMouseMove(self, p0, p1):
- pass
+ oldNode = self.node
+ self.node = self._traceNodes(p0, p1)
+ if oldNode != self.node:
+ self.parent.Refresh()
def OnDragStart(self, p0, p1):
pass
pass
def OnDraw(self):
+ s = self._nodeSize()
+
glDisable(GL_LIGHTING)
- size = self.parent.getObjectSize() / 2
- opengl.DrawBox(-size, size)
+ glDisable(GL_DEPTH_TEST)
+ glEnable(GL_BLEND)
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+
+ glLineWidth(1)
+ glBegin(GL_LINES)
+ glColor3ub(128,0,0)
+ glVertex3f(0, 0, 0)
+ glVertex3f(s*15, 0, 0)
+ glColor3ub(128,128,0)
+ glVertex3f(0, 0, 0)
+ glVertex3f(0, s*15, 0)
+ glColor3ub(0,128,0)
+ glVertex3f(0, 0, 0)
+ glVertex3f(0, 0, s*15)
+ glEnd()
+
+ glLineWidth(2)
+ if self.node == 1:
+ glColor3ub(255,255,255)
+ else:
+ glColor3ub(192,192,192)
+ opengl.DrawBox([-s,-s,-s], [s,s,s])
+
+ if self.node == 2:
+ glColor3ub(255,64,64)
+ else:
+ glColor3ub(128,0,0)
+ glPushMatrix()
+ glTranslatef(s*15,0,0)
+ opengl.DrawBox([-s,-s,-s], [s,s,s])
+ glPopMatrix()
+ if self.node == 3:
+ glColor3ub(255,255,0)
+ else:
+ glColor3ub(128,128,0)
+ glPushMatrix()
+ glTranslatef(0,s*15,0)
+ opengl.DrawBox([-s,-s,-s], [s,s,s])
+ glPopMatrix()
+ if self.node == 4:
+ glColor3ub(64,255,64)
+ else:
+ glColor3ub(0,128,0)
+ glPushMatrix()
+ glTranslatef(0,0,s*15)
+ opengl.DrawBox([-s,-s,-s], [s,s,s])
+ glPopMatrix()
+
+ glEnable(GL_DEPTH_TEST)
class previewPanel(wx.Panel):
def __init__(self, parent):
# glEnd()
# glEnable(GL_DEPTH_TEST)
+ opengl.DrawMachine(machineSize)
+
#Draw the current selected tool
if self.parent.objectsMaxV is not None and self.viewMode != 'GCode' and self.viewMode != 'Mixed':
glPushMatrix()
self.parent.tool.OnDraw()
glPopMatrix()
- opengl.DrawMachine(machineSize)
-
glFlush()
- def convert3x3MatrixTo4x4(self, matrix):
- return list(matrix.getA()[0]) + [0] + list(matrix.getA()[1]) + [0] + list(matrix.getA()[2]) + [0, 0,0,0,1]
-
def drawModel(self, obj):
vMin = self.parent.objectsMinV
vMax = self.parent.objectsMaxV
offset = - vMin - (vMax - vMin) / 2
- matrix = self.convert3x3MatrixTo4x4(obj.mesh.matrix)
+ matrix = opengl.convert3x3MatrixTo4x4(obj.mesh.matrix)
glPushMatrix()
glTranslate(0, 0, self.parent.objectsSize[2]/2)
if self.tempMatrix is not None:
- tempMatrix = self.convert3x3MatrixTo4x4(self.tempMatrix)
+ tempMatrix = opengl.convert3x3MatrixTo4x4(self.tempMatrix)
glMultMatrixf(tempMatrix)
glTranslate(0, 0, -self.parent.objectsSize[2]/2)
glTranslate(offset[0], offset[1], -vMin[2])