From: daid303 Date: Thu, 17 Jan 2013 10:47:41 +0000 (+0100) Subject: Add visual nodes for the scale tool. X-Git-Tag: 13.03~92^2~4 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0ac4f4e571f59f610a2de3cbcab6673fe0ef8aae;p=cura.git Add visual nodes for the scale tool. --- diff --git a/Cura/gui/preview3d.py b/Cura/gui/preview3d.py index ad562139..3826e603 100644 --- a/Cura/gui/preview3d.py +++ b/Cura/gui/preview3d.py @@ -73,6 +73,7 @@ class toolInfo(object): 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) @@ -107,6 +108,8 @@ class toolRotate(object): 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 @@ -126,12 +129,12 @@ class toolRotate(object): 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' @@ -145,11 +148,11 @@ class toolRotate(object): 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: @@ -190,10 +193,12 @@ class toolRotate(object): 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() @@ -215,6 +220,7 @@ class toolRotate(object): glColor4ub(255,64,64,255) glPopMatrix() else: + glLineWidth(1) glColor4ub(128,0,0,255) glBegin(GL_LINE_LOOP) for i in xrange(0, 64): @@ -222,6 +228,7 @@ class toolRotate(object): 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) @@ -243,11 +250,13 @@ class toolRotate(object): 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() @@ -270,17 +279,43 @@ class toolRotate(object): 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 @@ -292,9 +327,59 @@ class toolScale(object): 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): @@ -1041,6 +1126,8 @@ class PreviewGLCanvas(glcanvas.GLCanvas): # 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() @@ -1048,24 +1135,19 @@ class PreviewGLCanvas(glcanvas.GLCanvas): 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]) diff --git a/Cura/gui/util/opengl.py b/Cura/gui/util/opengl.py index 72a0d627..1a9a43ff 100644 --- a/Cura/gui/util/opengl.py +++ b/Cura/gui/util/opengl.py @@ -257,6 +257,9 @@ def unproject(winx, winy, winz, modelMatrix, projMatrix, viewport): ret = list(vector)[0:3] / vector[3] return ret +def convert3x3MatrixTo4x4(matrix): + return list(matrix.getA()[0]) + [0] + list(matrix.getA()[1]) + [0] + list(matrix.getA()[2]) + [0, 0,0,0,1] + def ResetMatrixRotationAndScale(): matrix = glGetFloatv(GL_MODELVIEW_MATRIX) noZ = False