def OnDraw(self): machineSize = self.parent.machineSize opengl.DrawMachine(machineSize) if self.parent.svg != None: for path in self.parent.svg.paths: glColor3f(1.0, 0.8, 0.6) glBegin(GL_LINE_STRIP) for p in path: glVertex3f(p.real, p.imag, 1) glEnd() glFlush()
def OnDraw(self): machineSize = self.parent.machineSize if self.parent.gcode != None and self.parent.gcodeDirty: if self.gcodeDisplayListCount < len( self.parent.gcode.layerList ) or self.gcodeDisplayList == None: if self.gcodeDisplayList != None: glDeleteLists(self.gcodeDisplayList, self.gcodeDisplayListCount) self.gcodeDisplayList = glGenLists( len(self.parent.gcode.layerList)) self.gcodeDisplayListCount = len(self.parent.gcode.layerList) self.parent.gcodeDirty = False self.gcodeDisplayListMade = 0 if self.parent.gcode != None and self.gcodeDisplayListMade < len( self.parent.gcode.layerList): glNewList(self.gcodeDisplayList + self.gcodeDisplayListMade, GL_COMPILE) opengl.DrawGCodeLayer( self.parent.gcode.layerList[self.gcodeDisplayListMade]) glEndList() self.gcodeDisplayListMade += 1 self.Refresh() glPushMatrix() glTranslate(self.parent.machineCenter.x, self.parent.machineCenter.y, 0) for obj in self.parent.objectList: if obj.mesh == None: continue if obj.displayList == None: obj.displayList = glGenLists(1) if obj.dirty: obj.dirty = False glNewList(obj.displayList, GL_COMPILE) opengl.DrawMesh(obj.mesh) glEndList() if self.viewMode == "Mixed": glDisable(GL_BLEND) glColor3f(0.0, 0.0, 0.0) self.drawModel(obj) glColor3f(1.0, 1.0, 1.0) glClear(GL_DEPTH_BUFFER_BIT) glPopMatrix() if self.parent.gcode != None and (self.viewMode == "GCode" or self.viewMode == "Mixed"): glEnable(GL_COLOR_MATERIAL) glEnable(GL_LIGHTING) drawUpToLayer = min(self.gcodeDisplayListMade, self.parent.layerSpin.GetValue() + 1) starttime = time.time() for i in xrange(drawUpToLayer - 1, -1, -1): c = 1.0 if i < self.parent.layerSpin.GetValue(): c = 0.9 - (drawUpToLayer - i) * 0.1 if c < 0.4: c = (0.4 + c) / 2 if c < 0.1: c = 0.1 glLightfv(GL_LIGHT0, GL_DIFFUSE, [0, 0, 0, 0]) glLightfv(GL_LIGHT0, GL_AMBIENT, [c, c, c, c]) glCallList(self.gcodeDisplayList + i) if time.time() - starttime > 0.1: break glDisable(GL_LIGHTING) glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0]) glColor3f(1.0, 1.0, 1.0) glPushMatrix() glTranslate(self.parent.machineCenter.x, self.parent.machineCenter.y, 0) for obj in self.parent.objectList: if obj.mesh == None: continue if self.viewMode == "Transparent" or self.viewMode == "Mixed": glLightfv( GL_LIGHT0, GL_DIFFUSE, map(lambda x: x / 2, self.objColor[self.parent.objectList.index(obj)])) glLightfv( GL_LIGHT0, GL_AMBIENT, map(lambda x: x / 10, self.objColor[self.parent.objectList.index(obj)])) #If we want transparent, then first render a solid black model to remove the printer size lines. if self.viewMode != "Mixed": glDisable(GL_BLEND) glColor3f(0.0, 0.0, 0.0) self.drawModel(obj) glColor3f(1.0, 1.0, 1.0) #After the black model is rendered, render the model again but now with lighting and no depth testing. glDisable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_BLEND) glBlendFunc(GL_ONE, GL_ONE) glEnable(GL_LIGHTING) self.drawModel(obj) glEnable(GL_DEPTH_TEST) elif self.viewMode == "X-Ray": glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) glDisable(GL_LIGHTING) glDisable(GL_DEPTH_TEST) glEnable(GL_STENCIL_TEST) glStencilFunc(GL_ALWAYS, 1, 1) glStencilOp(GL_INCR, GL_INCR, GL_INCR) self.drawModel(obj) glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) glStencilFunc(GL_EQUAL, 0, 1) glColor(1, 1, 1) self.drawModel(obj) glStencilFunc(GL_EQUAL, 1, 1) glColor(1, 0, 0) self.drawModel(obj) glPushMatrix() glLoadIdentity() for i in xrange(2, 15, 2): glStencilFunc(GL_EQUAL, i, 0xFF) glColor(float(i) / 10, float(i) / 10, float(i) / 5) glBegin(GL_QUADS) glVertex3f(-1000, -1000, -1) glVertex3f(1000, -1000, -1) glVertex3f(1000, 1000, -1) glVertex3f(-1000, 1000, -1) glEnd() for i in xrange(1, 15, 2): glStencilFunc(GL_EQUAL, i, 0xFF) glColor(float(i) / 10, 0, 0) glBegin(GL_QUADS) glVertex3f(-1000, -1000, -1) glVertex3f(1000, -1000, -1) glVertex3f(1000, 1000, -1) glVertex3f(-1000, 1000, -1) glEnd() glPopMatrix() glDisable(GL_STENCIL_TEST) glEnable(GL_DEPTH_TEST) #Fix the depth buffer glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) self.drawModel(obj) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) elif self.viewMode == "Normal": glLightfv(GL_LIGHT0, GL_DIFFUSE, self.objColor[self.parent.objectList.index(obj)]) glLightfv( GL_LIGHT0, GL_AMBIENT, map(lambda x: x / 5, self.objColor[self.parent.objectList.index(obj)])) glEnable(GL_LIGHTING) self.drawModel(obj) if self.drawBorders and (self.viewMode == "Normal" or self.viewMode == "Transparent" or self.viewMode == "X-Ray"): glEnable(GL_DEPTH_TEST) glDisable(GL_LIGHTING) glColor3f(1, 1, 1) glPushMatrix() modelScale = profile.getProfileSettingFloat('model_scale') glScalef(modelScale, modelScale, modelScale) opengl.DrawMeshOutline(obj.mesh) glPopMatrix() glPopMatrix() if self.viewMode == "Normal" or self.viewMode == "Transparent" or self.viewMode == "X-Ray": glDisable(GL_LIGHTING) glDisable(GL_DEPTH_TEST) glDisable(GL_BLEND) glColor3f(1, 0, 0) glBegin(GL_LINES) for err in self.parent.errorList: glVertex3f(err[0].x, err[0].y, err[0].z) glVertex3f(err[1].x, err[1].y, err[1].z) glEnd() glEnable(GL_DEPTH_TEST) opengl.DrawMachine(machineSize) glPushMatrix() glTranslate(self.parent.machineCenter.x, self.parent.machineCenter.y, 0) #Draw the rotate circle if self.parent.objectsMaxV != None: glDisable(GL_LIGHTING) glDisable(GL_CULL_FACE) glEnable(GL_BLEND) glBegin(GL_TRIANGLE_STRIP) size = (self.parent.objectsMaxV - self.parent.objectsMinV) sizeXY = math.sqrt((size[0] * size[0]) + (size[1] * size[1])) for i in xrange(0, 64 + 1): f = i if i < 64 / 2 else 64 - i glColor4ub(255, int(f * 255 / (64 / 2)), 0, 128) glVertex3f(sizeXY * 0.7 * math.cos(i / 32.0 * math.pi), sizeXY * 0.7 * math.sin(i / 32.0 * math.pi), 0.1) glColor4ub(0, 128, 0, 128) glVertex3f((sizeXY * 0.7 + 3) * math.cos(i / 32.0 * math.pi), (sizeXY * 0.7 + 3) * math.sin(i / 32.0 * math.pi), 0.1) glEnd() glEnable(GL_CULL_FACE) glPopMatrix() glFlush()
def OnDraw(self): machineSize = self.parent.machineSize opengl.DrawMachine(machineSize) if self.parent.gcode != None and self.parent.gcodeDirty: if self.gcodeDisplayListCount < len( self.parent.gcode.layerList ) or self.gcodeDisplayList == None: if self.gcodeDisplayList != None: glDeleteLists(self.gcodeDisplayList, self.gcodeDisplayListCount) self.gcodeDisplayList = glGenLists( len(self.parent.gcode.layerList)) self.gcodeDisplayListCount = len(self.parent.gcode.layerList) self.parent.gcodeDirty = False self.gcodeDisplayListMade = 0 if self.parent.gcode != None and self.gcodeDisplayListMade < len( self.parent.gcode.layerList): glNewList(self.gcodeDisplayList + self.gcodeDisplayListMade, GL_COMPILE) opengl.DrawGCodeLayer( self.parent.gcode.layerList[self.gcodeDisplayListMade]) glEndList() self.gcodeDisplayListMade += 1 self.Refresh() if self.parent.gcode != None and (self.viewMode == "GCode" or self.viewMode == "Mixed"): glEnable(GL_COLOR_MATERIAL) glEnable(GL_LIGHTING) drawUpToLayer = min(self.gcodeDisplayListMade, self.parent.layerSpin.GetValue() + 1) for i in xrange(0, drawUpToLayer): c = 1.0 if i < self.parent.layerSpin.GetValue(): c = 0.9 - (drawUpToLayer - i) * 0.1 if c < 0.4: c = (0.4 + c) / 2 if c < 0.1: c = 0.1 glLightfv(GL_LIGHT0, GL_DIFFUSE, [0, 0, 0, 0]) glLightfv(GL_LIGHT0, GL_AMBIENT, [c, c, c, c]) glCallList(self.gcodeDisplayList + i) glDisable(GL_LIGHTING) glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0]) glColor3f(1.0, 1.0, 1.0) glTranslate(self.parent.machineCenter.x, self.parent.machineCenter.y, 0) for obj in self.parent.objectList: if obj.mesh == None: continue if obj.displayList == None: obj.displayList = glGenLists(1) if obj.dirty: obj.dirty = False glNewList(obj.displayList, GL_COMPILE) opengl.DrawSTL(obj.mesh) glEndList() if self.viewMode == "Transparent" or self.viewMode == "Mixed": glLightfv( GL_LIGHT0, GL_DIFFUSE, map(lambda x: x / 2, self.objColor[self.parent.objectList.index(obj)])) glLightfv( GL_LIGHT0, GL_AMBIENT, map(lambda x: x / 10, self.objColor[self.parent.objectList.index(obj)])) #If we want transparent, then first render a solid black model to remove the printer size lines. if self.viewMode != "Mixed": glDisable(GL_BLEND) glColor3f(0.0, 0.0, 0.0) self.drawModel(obj) glColor3f(1.0, 1.0, 1.0) #After the black model is rendered, render the model again but now with lighting and no depth testing. glDisable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_BLEND) glBlendFunc(GL_ONE, GL_ONE) glEnable(GL_LIGHTING) self.drawModel(obj) elif self.viewMode == "X-Ray": glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) glDisable(GL_DEPTH_TEST) glEnable(GL_STENCIL_TEST) glStencilFunc(GL_ALWAYS, 1, 1) glStencilOp(GL_INCR, GL_INCR, GL_INCR) self.drawModel(obj) glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) glStencilFunc(GL_EQUAL, 0, 1) glColor(1, 1, 1) self.drawModel(obj) glStencilFunc(GL_EQUAL, 1, 1) glColor(1, 0, 0) self.drawModel(obj) glPushMatrix() glLoadIdentity() for i in xrange(2, 15, 2): glStencilFunc(GL_EQUAL, i, 0xFF) glColor(float(i) / 10, float(i) / 10, float(i) / 5) glBegin(GL_QUADS) glVertex3f(-1000, -1000, -1) glVertex3f(1000, -1000, -1) glVertex3f(1000, 1000, -1) glVertex3f(-1000, 1000, -1) glEnd() for i in xrange(1, 15, 2): glStencilFunc(GL_EQUAL, i, 0xFF) glColor(float(i) / 10, 0, 0) glBegin(GL_QUADS) glVertex3f(-1000, -1000, -1) glVertex3f(1000, -1000, -1) glVertex3f(1000, 1000, -1) glVertex3f(-1000, 1000, -1) glEnd() glPopMatrix() glDisable(GL_STENCIL_TEST) glEnable(GL_DEPTH_TEST) elif self.viewMode == "Normal": glLightfv(GL_LIGHT0, GL_DIFFUSE, self.objColor[self.parent.objectList.index(obj)]) glLightfv( GL_LIGHT0, GL_AMBIENT, map(lambda x: x / 5, self.objColor[self.parent.objectList.index(obj)])) glEnable(GL_LIGHTING) self.drawModel(obj) if self.viewMode == "Normal" or self.viewMode == "Transparent" or self.viewMode == "X-Ray": glDisable(GL_LIGHTING) glDisable(GL_DEPTH_TEST) glDisable(GL_BLEND) glColor3f(1, 0, 0) glBegin(GL_LINES) for err in self.parent.errorList: glVertex3f(err[0].x, err[0].y, err[0].z) glVertex3f(err[1].x, err[1].y, err[1].z) glEnd() glEnable(GL_DEPTH_TEST) glFlush()
def OnDraw(self): machineSize = self.parent.machineSize extraSizeMin, extraSizeMax = self.parent.getExtraHeadSize() for item in self.parent.list: item.validPlacement = True item.gotHit = False for idx1 in xrange(0, len(self.parent.list)): item = self.parent.list[idx1] iMin1 = (item.getMinimum() * item.scale) + numpy.array([item.centerX, item.centerY, 0]) - extraSizeMin - self.parent.extruderOffset[item.extruder] iMax1 = (item.getMaximum() * item.scale) + numpy.array([item.centerX, item.centerY, 0]) + extraSizeMax - self.parent.extruderOffset[item.extruder] for idx2 in xrange(0, idx1): item2 = self.parent.list[idx2] iMin2 = (item2.getMinimum() * item2.scale) + numpy.array([item2.centerX, item2.centerY, 0]) iMax2 = (item2.getMaximum() * item2.scale) + numpy.array([item2.centerX, item2.centerY, 0]) if item != item2 and iMax1[0] >= iMin2[0] and iMin1[0] <= iMax2[0] and iMax1[1] >= iMin2[1] and iMin1[1] <= iMax2[1]: item.validPlacement = False item2.gotHit = True seenSelected = False for item in self.parent.list: if item == self.parent.selection: seenSelected = True if item.modelDisplayList == None: item.modelDisplayList = glGenLists(1); if item.modelDirty: item.modelDirty = False modelSize = item.getMaximum() - item.getMinimum() glNewList(item.modelDisplayList, GL_COMPILE) opengl.DrawMesh(item.mesh) glEndList() if item.validPlacement: if self.parent.selection == item: glLightfv(GL_LIGHT0, GL_DIFFUSE, map(lambda x: x + 0.2, self.objColor)) glLightfv(GL_LIGHT0, GL_AMBIENT, map(lambda x: x / 2, self.objColor)) else: glLightfv(GL_LIGHT0, GL_DIFFUSE, self.objColor) glLightfv(GL_LIGHT0, GL_AMBIENT, map(lambda x: x / 2, self.objColor)) else: if self.parent.selection == item: glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 0.0, 0.0, 0.0]) glLightfv(GL_LIGHT0, GL_AMBIENT, [0.2, 0.0, 0.0, 0.0]) else: glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 0.0, 0.0, 0.0]) glLightfv(GL_LIGHT0, GL_AMBIENT, [0.2, 0.0, 0.0, 0.0]) glPushMatrix() glEnable(GL_LIGHTING) glTranslate(item.centerX, item.centerY, 0) glPushMatrix() glScalef(item.scale, item.scale, item.scale) glCallList(item.modelDisplayList) glPopMatrix() vMin = item.getMinimum() * item.scale vMax = item.getMaximum() * item.scale vMinHead = vMin - extraSizeMin - self.parent.extruderOffset[item.extruder] vMaxHead = vMax + extraSizeMax - self.parent.extruderOffset[item.extruder] glDisable(GL_LIGHTING) if not self.parent.alwaysAutoPlace: if self.parent.selection == item: if item.gotHit: glColor3f(1.0,0.0,0.3) else: glColor3f(1.0,0.0,1.0) opengl.DrawBox(vMin, vMax) if item.gotHit: glColor3f(1.0,0.3,0.0) else: glColor3f(1.0,1.0,0.0) opengl.DrawBox(vMinHead, vMaxHead) elif seenSelected: if item.gotHit: glColor3f(0.5,0.0,0.1) else: glColor3f(0.5,0.0,0.5) opengl.DrawBox(vMinHead, vMaxHead) else: if item.gotHit: glColor3f(0.7,0.1,0.0) else: glColor3f(0.7,0.7,0.0) opengl.DrawBox(vMin, vMax) glPopMatrix() opengl.DrawMachine(util3d.Vector3(machineSize[0], machineSize[1], machineSize[2])) glFlush()