def __init__(self, parent, filename):
		super(ProjectObject, self).__init__()

		self.mesh = meshLoader.loadMesh(filename)

		self.parent = parent
		self.filename = filename
		self.scale = 1.0
		self.rotate = 0.0
		self.flipX = False
		self.flipY = False
		self.flipZ = False
		self.swapXZ = False
		self.swapYZ = False
		self.extruder = 0
		self.profile = None
		
		self.modelDisplayList = None
		self.modelDirty = False

		self.mesh.getMinimumZ()
		
		self.centerX = -self.getMinimum()[0] + 5
		self.centerY = -self.getMinimum()[1] + 5
		
		self.updateModelTransform()

		self.centerX = -self.getMinimum()[0] + 5
		self.centerY = -self.getMinimum()[1] + 5
Ejemplo n.º 2
0
 def OnCutMesh(self, e):
     dlg = wx.FileDialog(
         self,
         "Open file to cut",
         os.path.split(profile.getPreference("lastFile"))[0],
         style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST,
     )
     dlg.SetWildcard(meshLoader.wildcardFilter())
     if dlg.ShowModal() == wx.ID_OK:
         filename = dlg.GetPath()
         model = meshLoader.loadMesh(filename)
         pd = wx.ProgressDialog(
             "Splitting model.",
             "Splitting model into multiple parts.",
             model.vertexCount,
             self,
             wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME | wx.PD_SMOOTH,
         )
         parts = model.splitToParts(pd.Update)
         for part in parts:
             partFilename = filename[: filename.rfind(".")] + "_part%d.stl" % (parts.index(part))
             stl.saveAsSTL(part, partFilename)
             item = ProjectObject(self, partFilename)
             self.list.append(item)
             self.selection = item
             self._updateListbox()
             self.OnListSelect(None)
         pd.Destroy()
     self.preview.Refresh()
     dlg.Destroy()
Ejemplo n.º 3
0
	def doFileLoadThread(self):
		for obj in self.objectList:
			if obj.filename is not None and os.path.isfile(obj.filename) and obj.fileTime != os.stat(obj.filename).st_mtime:
				obj.fileTime = os.stat(obj.filename).st_mtime
				mesh = meshLoader.loadMesh(obj.filename)
				obj.mesh = mesh
				obj.dirty = True
				obj.steepDirty = True
				self.updateModelTransform()
				self.glCanvas.zoom = self.objectsBoundaryCircleSize * 6.0
				self.errorList = []
				wx.CallAfter(self.updateToolbar)
				wx.CallAfter(self.glCanvas.Refresh)
		
		if os.path.isfile(self.gcodeFilename) and self.gcodeFileTime != os.stat(self.gcodeFilename).st_mtime:
			self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime
			self.gcodeDirty = True
			self.gcode = gcodeInterpreter.gcode()
			self.gcode.progressCallback = self.loadProgress
			self.gcode.load(self.gcodeFilename)

			errorList = []
			for line in open(self.gcodeFilename, "rt"):
				res = re.search(';Model error\(([a-z ]*)\): \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\) \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\)', line)
				if res is not None:
					v1 = util3d.Vector3(float(res.group(2)), float(res.group(3)), float(res.group(4)))
					v2 = util3d.Vector3(float(res.group(5)), float(res.group(6)), float(res.group(7)))
					errorList.append([v1, v2])
			self.errorList = errorList

			wx.CallAfter(self.updateToolbar)
			wx.CallAfter(self.glCanvas.Refresh)
		elif not os.path.isfile(self.gcodeFilename):
			self.gcode = None
		wx.CallAfter(self.checkReloadFileTimer.Start, 1000)
Ejemplo n.º 4
0
 def OnCutMesh(self, e):
     dlg = wx.FileDialog(self,
                         "Open file to cut",
                         os.path.split(
                             profile.getPreference('lastFile'))[0],
                         style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
     dlg.SetWildcard(meshLoader.wildcardFilter())
     if dlg.ShowModal() == wx.ID_OK:
         filename = dlg.GetPath()
         model = meshLoader.loadMesh(filename)
         pd = wx.ProgressDialog(
             'Splitting model.', 'Splitting model into multiple parts.',
             model.vertexCount, self,
             wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME | wx.PD_SMOOTH)
         parts = model.splitToParts(pd.Update)
         for part in parts:
             partFilename = filename[:filename.rfind(
                 '.')] + "_part%d.stl" % (parts.index(part))
             stl.saveAsSTL(part, partFilename)
             item = ProjectObject(self, partFilename)
             self.list.append(item)
             self.selection = item
             self._updateListbox()
             self.OnListSelect(None)
         pd.Destroy()
     self.glCanvas.Refresh()
     dlg.Destroy()
Ejemplo n.º 5
0
    def doFileLoadThread(self):
        for obj in self.objectList:
            if obj.filename is not None and os.path.isfile(
                    obj.filename) and obj.fileTime != os.stat(
                        obj.filename).st_mtime:
                obj.fileTime = os.stat(obj.filename).st_mtime
                try:
                    mesh = meshLoader.loadMesh(obj.filename)
                except:
                    wx.CallAfter(self.ShowWarningPopup,
                                 'Failed to load %s' % (obj.filename))
                    obj.mesh = None
                    obj.filename = None
                else:
                    obj.mesh = mesh
                obj.dirty = True
                obj.steepDirty = True
                self.updateModelTransform()
                if self.objectsBoundaryCircleSize is not None:
                    self.glCanvas.zoom = self.objectsBoundaryCircleSize * 6.0
                self.errorList = []
                wx.CallAfter(self.updateToolbar)
                wx.CallAfter(self.glCanvas.Refresh)
            elif obj.filename is None or not os.path.isfile(obj.filename):
                obj.mesh = None
                obj.filename = None

        if os.path.isfile(
                self.gcodeFilename) and self.gcodeFileTime != os.stat(
                    self.gcodeFilename).st_mtime:
            self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime
            self.gcodeDirty = True
            self.gcode = gcodeInterpreter.gcode()
            self.gcode.progressCallback = self.loadProgress
            self.gcode.load(self.gcodeFilename)

            errorList = []
            for line in open(self.gcodeFilename, "rt"):
                res = re.search(
                    ';Model error\(([a-z ]*)\): \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\) \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\)',
                    line)
                if res is not None:
                    v1 = util3d.Vector3(float(res.group(2)),
                                        float(res.group(3)),
                                        float(res.group(4)))
                    v2 = util3d.Vector3(float(res.group(5)),
                                        float(res.group(6)),
                                        float(res.group(7)))
                    errorList.append([v1, v2])
            self.errorList = errorList

            wx.CallAfter(self.updateToolbar)
            wx.CallAfter(self.glCanvas.Refresh)
        elif not os.path.isfile(self.gcodeFilename):
            self.gcode = None
        wx.CallAfter(self.checkReloadFileTimer.Start, 1000)
Ejemplo n.º 6
0
    def doFileLoadThread(self):
        for obj in self.objectList:
            if obj.filename is not None and os.path.isfile(
                    obj.filename) and obj.fileTime != os.stat(
                        obj.filename).st_mtime:
                obj.fileTime = os.stat(obj.filename).st_mtime
                mesh = meshLoader.loadMesh(obj.filename)
                obj.mesh = mesh
                obj.dirty = True
                obj.steepDirty = True
                self.updateModelTransform()
                self.OnScaleMax(True)
                self.glCanvas.zoom = numpy.max(self.objectsSize) * 3.5
                self.errorList = []
                wx.CallAfter(self.updateToolbar)
                wx.CallAfter(self.glCanvas.Refresh)

        if os.path.isfile(
                self.gcodeFilename) and self.gcodeFileTime != os.stat(
                    self.gcodeFilename).st_mtime:
            self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime
            gcode = gcodeInterpreter.gcode()
            gcode.progressCallback = self.loadProgress
            gcode.load(self.gcodeFilename)
            self.gcodeDirty = False
            self.gcode = gcode
            self.gcodeDirty = True

            errorList = []
            for line in open(self.gcodeFilename, "rt"):
                res = re.search(
                    ';Model error\(([a-z ]*)\): \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\) \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\)',
                    line)
                if res is not None:
                    v1 = util3d.Vector3(float(res.group(2)),
                                        float(res.group(3)),
                                        float(res.group(4)))
                    v2 = util3d.Vector3(float(res.group(5)),
                                        float(res.group(6)),
                                        float(res.group(7)))
                    errorList.append([v1, v2])
            self.errorList = errorList

            wx.CallAfter(self.updateToolbar)
            wx.CallAfter(self.glCanvas.Refresh)
        elif not os.path.isfile(self.gcodeFilename):
            self.gcode = None
        wx.CallAfter(self.checkReloadFileTimer.Start, 1000)
Ejemplo n.º 7
0
	def __init__(self, parent, filename):
		super(ProjectObject, self).__init__()

		self.mesh = meshLoader.loadMesh(filename)

		self.parent = parent
		self.filename = filename
		self.matrix = numpy.matrix([[1,0,0],[0,1,0],[0,0,1]], numpy.float64)
		self.profile = None
		
		self.modelDisplayList = None
		self.modelDirty = True

		self.centerX = self.getSize()[0]/2 + 5
		self.centerY = self.getSize()[1]/2 + 5

		self.updateMatrix()
Ejemplo n.º 8
0
    def __init__(self, parent, filename):
        super(ProjectObject, self).__init__()

        self.mesh = meshLoader.loadMesh(filename)

        self.parent = parent
        self.filename = filename
        self.matrix = numpy.matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                                   numpy.float64)
        self.profile = None

        self.modelDisplayList = None
        self.modelDirty = True

        self.centerX = self.getSize()[0] / 2 + 5
        self.centerY = self.getSize()[1] / 2 + 5

        self.updateMatrix()
Ejemplo n.º 9
0
	def doFileLoadThread(self):
		for obj in self.objectList:
			if obj.filename != None and os.path.isfile(obj.filename) and obj.fileTime != os.stat(obj.filename).st_mtime:
				obj.fileTime = os.stat(obj.filename).st_mtime
				mesh = meshLoader.loadMesh(obj.filename)
				obj.dirty = False
				obj.mesh = mesh
				self.updateModelTransform()
				self.OnScaleMax(None, True)
				scale = profile.getProfileSettingFloat('model_scale')
				size = (self.objectsMaxV - self.objectsMinV) * scale
				self.toolbarInfo.SetValue('%0.1f %0.1f %0.1f' % (size[0], size[1], size[2]))
				self.glCanvas.zoom = numpy.max(size) * 2.5
				self.errorList = []
				wx.CallAfter(self.updateToolbar)
				wx.CallAfter(self.glCanvas.Refresh)
		
		if os.path.isfile(self.gcodeFilename) and self.gcodeFileTime != os.stat(self.gcodeFilename).st_mtime:
			self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime
			gcode = gcodeInterpreter.gcode()
			gcode.progressCallback = self.loadProgress
			gcode.load(self.gcodeFilename)
			self.gcodeDirty = False
			self.gcode = gcode
			self.gcodeDirty = True

			errorList = []
			for line in open(self.gcodeFilename, "rt"):
				res = re.search(';Model error\(([a-z ]*)\): \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\) \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\)', line)
				if res != None:
					v1 = util3d.Vector3(float(res.group(2)), float(res.group(3)), float(res.group(4)))
					v2 = util3d.Vector3(float(res.group(5)), float(res.group(6)), float(res.group(7)))
					errorList.append([v1, v2])
			self.errorList = errorList

			wx.CallAfter(self.updateToolbar)
			wx.CallAfter(self.glCanvas.Refresh)
		elif not os.path.isfile(self.gcodeFilename):
			self.gcode = None
		wx.CallAfter(self.checkReloadFileTimer.Start, 1000)
Ejemplo n.º 10
0
def DrawMachine(machineSize):
	glDisable(GL_LIGHTING)
	glDisable(GL_CULL_FACE)
	glEnable(GL_BLEND)
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

	sx = machineSize.x
	sy = machineSize.y
	for x in xrange(-int(sx/20)-1, int(sx / 20) + 1):
		for y in xrange(-int(sx/20)-1, int(sy / 20) + 1):
			x1 = sx/2+x * 10
			x2 = x1 + 10
			y1 = sx/2+y * 10
			y2 = y1 + 10
			x1 = max(min(x1, sx), 0)
			y1 = max(min(y1, sy), 0)
			x2 = max(min(x2, sx), 0)
			y2 = max(min(y2, sy), 0)
			if (x & 1) == (y & 1):
				glColor4ub(5, 171, 231, 127)
			else:
				glColor4ub(5 * 8 / 10, 171 * 8 / 10, 231 * 8 / 10, 128)
			glBegin(GL_QUADS)
			glVertex3f(x1, y1, -0.02)
			glVertex3f(x2, y1, -0.02)
			glVertex3f(x2, y2, -0.02)
			glVertex3f(x1, y2, -0.02)
			glEnd()

	glEnable(GL_CULL_FACE)

	if profile.getPreference('machine_type') == 'ultimaker':
		glPushMatrix()
		glEnable(GL_LIGHTING)
		glTranslate(100, 200, -1)
		glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8, 0.8, 0.8])
		glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5, 0.5, 0.5])
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR)

		global platformMesh
		if platformMesh is None:
			try:
				platformMesh = meshLoader.loadMesh(getPathForMesh('ultimaker_platform.stl'))
			except:
				platformMesh = False

		if platformMesh:
			DrawMesh(platformMesh)
		glPopMatrix()
		glDisable(GL_LIGHTING)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

	glColor4ub(5, 171, 231, 64)
	glBegin(GL_QUADS)
	glVertex3f(0, 0, machineSize.z)
	glVertex3f(0, machineSize.y, machineSize.z)
	glVertex3f(machineSize.x, machineSize.y, machineSize.z)
	glVertex3f(machineSize.x, 0, machineSize.z)
	glEnd()

	glColor4ub(5, 171, 231, 96)
	glBegin(GL_QUADS)
	glVertex3f(0, 0, 0)
	glVertex3f(0, 0, machineSize.z)
	glVertex3f(machineSize.x, 0, machineSize.z)
	glVertex3f(machineSize.x, 0, 0)

	glVertex3f(0, machineSize.y, machineSize.z)
	glVertex3f(0, machineSize.y, 0)
	glVertex3f(machineSize.x, machineSize.y, 0)
	glVertex3f(machineSize.x, machineSize.y, machineSize.z)
	glEnd()

	glColor4ub(5, 171, 231, 128)
	glBegin(GL_QUADS)
	glVertex3f(0, 0, machineSize.z)
	glVertex3f(0, 0, 0)
	glVertex3f(0, machineSize.y, 0)
	glVertex3f(0, machineSize.y, machineSize.z)

	glVertex3f(machineSize.x, 0, 0)
	glVertex3f(machineSize.x, 0, machineSize.z)
	glVertex3f(machineSize.x, machineSize.y, machineSize.z)
	glVertex3f(machineSize.x, machineSize.y, 0)
	glEnd()

	glDisable(GL_BLEND)

	#Draw the X/Y/Z indicator
	glPushMatrix()
	glTranslate(5, 5, 2)
	glLineWidth(2)
	glColor3f(0.5, 0, 0)
	glBegin(GL_LINES)
	glVertex3f(0, 0, 0)
	glVertex3f(20, 0, 0)
	glEnd()
	glColor3f(0, 0.5, 0)
	glBegin(GL_LINES)
	glVertex3f(0, 0, 0)
	glVertex3f(0, 20, 0)
	glEnd()
	glColor3f(0, 0, 0.5)
	glBegin(GL_LINES)
	glVertex3f(0, 0, 0)
	glVertex3f(0, 0, 20)
	glEnd()

	glDisable(GL_DEPTH_TEST)
	#X
	glColor3f(1, 0, 0)
	glPushMatrix()
	glTranslate(20, 0, 0)
	noZ = ResetMatrixRotationAndScale()
	glDrawStringCenter("X")
	glPopMatrix()

	#Y
	glColor3f(0, 1, 0)
	glPushMatrix()
	glTranslate(0, 20, 0)
	glDrawStringCenter("Y")
	glPopMatrix()

	#Z
	if not noZ:
		glColor3f(0, 0, 1)
		glPushMatrix()
		glTranslate(0, 0, 20)
		glDrawStringCenter("Z")
		glPopMatrix()

	glPopMatrix()
	glEnable(GL_DEPTH_TEST)
Ejemplo n.º 11
0
def DrawMachine(machineSize):
	if profile.getPreference('machine_type') == 'ultimaker':
		glPushMatrix()
		glEnable(GL_LIGHTING)
		glTranslate(100, 200, -5)
		glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8, 0.8, 0.8])
		glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5, 0.5, 0.5])
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR)

		global platformMesh
		if platformMesh is None:
			platformMesh = meshLoader.loadMesh(getPathForMesh('ultimaker_platform.stl'))
			platformMesh.setRotateMirror(0, False, False, False, False, False)

		DrawMesh(platformMesh)
		glPopMatrix()

	glDisable(GL_LIGHTING)
	if False:
		glColor3f(0.7, 0.7, 0.7)
		glLineWidth(2)
		glBegin(GL_LINES)
		for i in xrange(0, int(machineSize.x), 10):
			glVertex3f(i, 0, 0)
			glVertex3f(i, machineSize.y, 0)
		for i in xrange(0, int(machineSize.y), 10):
			glVertex3f(0, i, 0)
			glVertex3f(machineSize.x, i, 0)
		glEnd()

		glEnable(GL_LINE_SMOOTH)
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
		glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);

		glColor3f(0.0, 0.0, 0.0)
		glLineWidth(4)
		glBegin(GL_LINE_LOOP)
		glVertex3f(0, 0, 0)
		glVertex3f(machineSize.x, 0, 0)
		glVertex3f(machineSize.x, machineSize.y, 0)
		glVertex3f(0, machineSize.y, 0)
		glEnd()

		glLineWidth(2)
		glBegin(GL_LINE_LOOP)
		glVertex3f(0, 0, machineSize.z)
		glVertex3f(machineSize.x, 0, machineSize.z)
		glVertex3f(machineSize.x, machineSize.y, machineSize.z)
		glVertex3f(0, machineSize.y, machineSize.z)
		glEnd()
		glBegin(GL_LINES)
		glVertex3f(0, 0, 0)
		glVertex3f(0, 0, machineSize.z)
		glVertex3f(machineSize.x, 0, 0)
		glVertex3f(machineSize.x, 0, machineSize.z)
		glVertex3f(machineSize.x, machineSize.y, 0)
		glVertex3f(machineSize.x, machineSize.y, machineSize.z)
		glVertex3f(0, machineSize.y, 0)
		glVertex3f(0, machineSize.y, machineSize.z)
		glEnd()
	else:
		glDisable(GL_CULL_FACE)
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

		sx = machineSize.x
		sy = machineSize.y
		for x in xrange(-int(sx/20)-1, int(sx / 20) + 1):
			for y in xrange(-int(sx/20)-1, int(sy / 20) + 1):
				x1 = sx/2+x * 10
				x2 = x1 + 10
				y1 = sx/2+y * 10
				y2 = y1 + 10
				x1 = max(min(x1, sx), 0)
				y1 = max(min(y1, sy), 0)
				x2 = max(min(x2, sx), 0)
				y2 = max(min(y2, sy), 0)
				if (x & 1) == (y & 1):
					glColor4ub(5, 171, 231, 127)
				else:
					glColor4ub(5 * 8 / 10, 171 * 8 / 10, 231 * 8 / 10, 128)
				glBegin(GL_QUADS)
				glVertex3f(x1, y1, -0.01)
				glVertex3f(x2, y1, -0.01)
				glVertex3f(x2, y2, -0.01)
				glVertex3f(x1, y2, -0.01)
				glEnd()

		glEnable(GL_CULL_FACE)

		glColor4ub(5, 171, 231, 64)
		glBegin(GL_QUADS)
		glVertex3f(0, 0, machineSize.z)
		glVertex3f(0, machineSize.y, machineSize.z)
		glVertex3f(machineSize.x, machineSize.y, machineSize.z)
		glVertex3f(machineSize.x, 0, machineSize.z)
		glEnd()

		glColor4ub(5, 171, 231, 96)
		glBegin(GL_QUADS)
		glVertex3f(0, 0, 0)
		glVertex3f(0, 0, machineSize.z)
		glVertex3f(machineSize.x, 0, machineSize.z)
		glVertex3f(machineSize.x, 0, 0)

		glVertex3f(0, machineSize.y, machineSize.z)
		glVertex3f(0, machineSize.y, 0)
		glVertex3f(machineSize.x, machineSize.y, 0)
		glVertex3f(machineSize.x, machineSize.y, machineSize.z)
		glEnd()

		glColor4ub(5, 171, 231, 128)
		glBegin(GL_QUADS)
		glVertex3f(0, 0, machineSize.z)
		glVertex3f(0, 0, 0)
		glVertex3f(0, machineSize.y, 0)
		glVertex3f(0, machineSize.y, machineSize.z)

		glVertex3f(machineSize.x, 0, 0)
		glVertex3f(machineSize.x, 0, machineSize.z)
		glVertex3f(machineSize.x, machineSize.y, machineSize.z)
		glVertex3f(machineSize.x, machineSize.y, 0)
		glEnd()

		glDisable(GL_BLEND)

	glPushMatrix()
	glTranslate(5, 5, 2)
	glLineWidth(2)
	glColor3f(0.5, 0, 0)
	glBegin(GL_LINES)
	glVertex3f(0, 0, 0)
	glVertex3f(20, 0, 0)
	glEnd()
	glColor3f(0, 0.5, 0)
	glBegin(GL_LINES)
	glVertex3f(0, 0, 0)
	glVertex3f(0, 20, 0)
	glEnd()
	glColor3f(0, 0, 0.5)
	glBegin(GL_LINES)
	glVertex3f(0, 0, 0)
	glVertex3f(0, 0, 20)
	glEnd()

	glDisable(GL_DEPTH_TEST)
	#X
	glColor3f(1, 0, 0)
	glPushMatrix()
	glTranslate(23, 0, 0)
	noZ = ResetMatrixRotationAndScale()
	glBegin(GL_LINES)
	glVertex3f(-0.8, 1, 0)
	glVertex3f(0.8, -1, 0)
	glVertex3f(0.8, 1, 0)
	glVertex3f(-0.8, -1, 0)
	glEnd()
	glPopMatrix()

	#Y
	glColor3f(0, 1, 0)
	glPushMatrix()
	glTranslate(0, 23, 0)
	ResetMatrixRotationAndScale()
	glBegin(GL_LINES)
	glVertex3f(-0.8, 1, 0)
	glVertex3f(0.0, 0, 0)
	glVertex3f(0.8, 1, 0)
	glVertex3f(-0.8, -1, 0)
	glEnd()
	glPopMatrix()

	#Z
	if not noZ:
		glColor3f(0, 0, 1)
		glPushMatrix()
		glTranslate(0, 0, 23)
		ResetMatrixRotationAndScale()
		glBegin(GL_LINES)
		glVertex3f(-0.8, 1, 0)
		glVertex3f(0.8, 1, 0)
		glVertex3f(0.8, 1, 0)
		glVertex3f(-0.8, -1, 0)
		glVertex3f(-0.8, -1, 0)
		glVertex3f(0.8, -1, 0)
		glEnd()
		glPopMatrix()

	glPopMatrix()
	glEnable(GL_DEPTH_TEST)
Ejemplo n.º 12
0
def DrawMachine(machineSize):
    glDisable(GL_LIGHTING)
    glDisable(GL_CULL_FACE)
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    sx = machineSize.x
    sy = machineSize.y
    for x in xrange(-int(sx / 20) - 1, int(sx / 20) + 1):
        for y in xrange(-int(sx / 20) - 1, int(sy / 20) + 1):
            x1 = sx / 2 + x * 10
            x2 = x1 + 10
            y1 = sx / 2 + y * 10
            y2 = y1 + 10
            x1 = max(min(x1, sx), 0)
            y1 = max(min(y1, sy), 0)
            x2 = max(min(x2, sx), 0)
            y2 = max(min(y2, sy), 0)
            if (x & 1) == (y & 1):
                glColor4ub(5, 171, 231, 127)
            else:
                glColor4ub(5 * 8 / 10, 171 * 8 / 10, 231 * 8 / 10, 128)
            glBegin(GL_QUADS)
            glVertex3f(x1, y1, -0.02)
            glVertex3f(x2, y1, -0.02)
            glVertex3f(x2, y2, -0.02)
            glVertex3f(x1, y2, -0.02)
            glEnd()

    glEnable(GL_CULL_FACE)

    if profile.getPreference('machine_type') == 'ultimaker':
        glPushMatrix()
        glEnable(GL_LIGHTING)
        glTranslate(100, 200, -1)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8, 0.8, 0.8])
        glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5, 0.5, 0.5])
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR)

        global platformMesh
        if platformMesh is None:
            try:
                platformMesh = meshLoader.loadMesh(
                    getPathForMesh('ultimaker_platform.stl'))
            except:
                platformMesh = False

        if platformMesh:
            DrawMesh(platformMesh)
        glPopMatrix()
        glDisable(GL_LIGHTING)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    glColor4ub(5, 171, 231, 64)
    glBegin(GL_QUADS)
    glVertex3f(0, 0, machineSize.z)
    glVertex3f(0, machineSize.y, machineSize.z)
    glVertex3f(machineSize.x, machineSize.y, machineSize.z)
    glVertex3f(machineSize.x, 0, machineSize.z)
    glEnd()

    glColor4ub(5, 171, 231, 96)
    glBegin(GL_QUADS)
    glVertex3f(0, 0, 0)
    glVertex3f(0, 0, machineSize.z)
    glVertex3f(machineSize.x, 0, machineSize.z)
    glVertex3f(machineSize.x, 0, 0)

    glVertex3f(0, machineSize.y, machineSize.z)
    glVertex3f(0, machineSize.y, 0)
    glVertex3f(machineSize.x, machineSize.y, 0)
    glVertex3f(machineSize.x, machineSize.y, machineSize.z)
    glEnd()

    glColor4ub(5, 171, 231, 128)
    glBegin(GL_QUADS)
    glVertex3f(0, 0, machineSize.z)
    glVertex3f(0, 0, 0)
    glVertex3f(0, machineSize.y, 0)
    glVertex3f(0, machineSize.y, machineSize.z)

    glVertex3f(machineSize.x, 0, 0)
    glVertex3f(machineSize.x, 0, machineSize.z)
    glVertex3f(machineSize.x, machineSize.y, machineSize.z)
    glVertex3f(machineSize.x, machineSize.y, 0)
    glEnd()

    glDisable(GL_BLEND)

    #Draw the X/Y/Z indicator
    glPushMatrix()
    glTranslate(5, 5, 2)
    glLineWidth(2)
    glColor3f(0.5, 0, 0)
    glBegin(GL_LINES)
    glVertex3f(0, 0, 0)
    glVertex3f(20, 0, 0)
    glEnd()
    glColor3f(0, 0.5, 0)
    glBegin(GL_LINES)
    glVertex3f(0, 0, 0)
    glVertex3f(0, 20, 0)
    glEnd()
    glColor3f(0, 0, 0.5)
    glBegin(GL_LINES)
    glVertex3f(0, 0, 0)
    glVertex3f(0, 0, 20)
    glEnd()

    glDisable(GL_DEPTH_TEST)
    #X
    glColor3f(1, 0, 0)
    glPushMatrix()
    glTranslate(20, 0, 0)
    noZ = ResetMatrixRotationAndScale()
    glDrawStringCenter("X")
    glPopMatrix()

    #Y
    glColor3f(0, 1, 0)
    glPushMatrix()
    glTranslate(0, 20, 0)
    glDrawStringCenter("Y")
    glPopMatrix()

    #Z
    if not noZ:
        glColor3f(0, 0, 1)
        glPushMatrix()
        glTranslate(0, 0, 20)
        glDrawStringCenter("Z")
        glPopMatrix()

    glPopMatrix()
    glEnable(GL_DEPTH_TEST)