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
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.ileTime = os.stat(obj.filename).st_mtime mesh = meshLoader.loadMesh(obj.filename) obj.dirty = False obj.mesh = mesh self.updateModelTransform() scale = profile.getProfileSettingFloat('model_scale') size = (self.objectsMaxV - self.objectsMinV) * scale if size[0] > self.machineSize.x or size[ 1] > self.machineSize.y or size[2] > self.machineSize.z: self.OnScaleMax(None) 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
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.ileTime = os.stat(obj.filename).st_mtime mesh = meshLoader.loadMesh(obj.filename) obj.dirty = False obj.mesh = mesh self.updateModelTransform() scale = self.scale size = (self.objectsMaxV - self.objectsMinV) * scale if size[0] > self.machineSize.x or size[1] > self.machineSize.y or size[2] > self.machineSize.z: self.OnScaleMax(None) self.glCanvas.zoom = numpy.max(size) * 2.5 self.errorList = [] wx.CallAfter(self.glCanvas.Refresh)
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()
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.ileTime = os.stat(obj.filename).st_mtime mesh = meshLoader.loadMesh(obj.filename) obj.dirty = False obj.mesh = mesh self.updateModelTransform() scale = profile.getProfileSettingFloat('model_scale') size = (self.objectsMaxV - self.objectsMinV) * scale if size[0] > self.machineSize.x or size[1] > self.machineSize.y or size[2] > self.machineSize.z: self.OnScaleMax(None) 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
def DrawMachine(machineSize): if profile.getPreference("machine_type") == "ultimaker": glPushMatrix() glEnable(GL_LIGHTING) glTranslate(100, 120, -285) 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 == None: platformMesh = meshLoader.loadMesh( os.path.normpath(os.path.join(os.path.split(__file__)[0], "../images", "ultimaker_platform.stl")) ) platformMesh.setRotateMirror(0, False, True, False, False, True) 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) glColor4ub(5, 171, 231, 127) glBegin(GL_QUADS) for x in xrange(0, int(machineSize.x), 20): for y in xrange(0, int(machineSize.y), 20): glVertex3f(x, y, -0.01) glVertex3f(min(x + 10, machineSize.x), y, -0.01) glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) glVertex3f(x, min(y + 10, machineSize.y), -0.01) for x in xrange(10, int(machineSize.x), 20): for y in xrange(10, int(machineSize.y), 20): glVertex3f(x, y, -0.01) glVertex3f(min(x + 10, machineSize.x), y, -0.01) glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) glVertex3f(x, min(y + 10, machineSize.y), -0.01) glEnd() glColor4ub(5 / 2, 171 / 2, 231 / 2, 128) glBegin(GL_QUADS) for x in xrange(10, int(machineSize.x), 20): for y in xrange(0, int(machineSize.y), 20): glVertex3f(x, y, -0.01) glVertex3f(min(x + 10, machineSize.x), y, -0.01) glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) glVertex3f(x, min(y + 10, machineSize.y), -0.01) for x in xrange(0, int(machineSize.x), 20): for y in xrange(10, int(machineSize.y), 20): glVertex3f(x, y, -0.01) glVertex3f(min(x + 10, machineSize.x), y, -0.01) glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) glVertex3f(x, min(y + 10, machineSize.y), -0.01) glEnd() glEnable(GL_CULL_FACE) glColor4ub(5, 171, 231, 128) 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, 192) 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, 255) 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.y, 0, 0) glVertex3f(machineSize.y, 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)
def DrawMachine(machineSize): if profile.getPreference('machine_type') == 'ultimaker': glPushMatrix() glEnable(GL_LIGHTING) glTranslate(100, 120, -285) 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 == None: platformMesh = meshLoader.loadMesh( os.path.normpath( os.path.join( os.path.split(__file__)[0], "../images", 'ultimaker_platform.stl'))) platformMesh.setRotateMirror(0, False, True, False, False, True) 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) glColor4ub(5, 171, 231, 127) glBegin(GL_QUADS) for x in xrange(0, int(machineSize.x), 20): for y in xrange(0, int(machineSize.y), 20): glVertex3f(x, y, -0.01) glVertex3f(min(x + 10, machineSize.x), y, -0.01) glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) glVertex3f(x, min(y + 10, machineSize.y), -0.01) for x in xrange(10, int(machineSize.x), 20): for y in xrange(10, int(machineSize.y), 20): glVertex3f(x, y, -0.01) glVertex3f(min(x + 10, machineSize.x), y, -0.01) glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) glVertex3f(x, min(y + 10, machineSize.y), -0.01) glEnd() glColor4ub(5 / 2, 171 / 2, 231 / 2, 128) glBegin(GL_QUADS) for x in xrange(10, int(machineSize.x), 20): for y in xrange(0, int(machineSize.y), 20): glVertex3f(x, y, -0.01) glVertex3f(min(x + 10, machineSize.x), y, -0.01) glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) glVertex3f(x, min(y + 10, machineSize.y), -0.01) for x in xrange(0, int(machineSize.x), 20): for y in xrange(10, int(machineSize.y), 20): glVertex3f(x, y, -0.01) glVertex3f(min(x + 10, machineSize.x), y, -0.01) glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) glVertex3f(x, min(y + 10, machineSize.y), -0.01) glEnd() glEnable(GL_CULL_FACE) glColor4ub(5, 171, 231, 128) 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, 192) 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, 255) 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.y, 0, 0) glVertex3f(machineSize.y, 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)