def OnSettingChange(self, e): if self.type == 'profile': profile.putProfileSetting(self.configName, self.GetValue()) else: profile.putPreference(self.configName, self.GetValue()) result = validators.SUCCESS msgs = [] for validator in self.validators: res, err = validator.validate() if res == validators.ERROR: result = res elif res == validators.WARNING and result != validators.ERROR: result = res if res != validators.SUCCESS: msgs.append(err) if result == validators.ERROR: self.ctrl.SetBackgroundColour('Red') elif result == validators.WARNING: self.ctrl.SetBackgroundColour('Yellow') else: self.ctrl.SetBackgroundColour(self.defaultBGColour) self.ctrl.Refresh() self.validationMsg = '\n'.join(msgs) self.panel.main.UpdatePopup(self)
def OnButtonProfile(self, event): if buttons.GenBitmapToggleButton.GetValue(self): self.SetBitmap(True) profile.putProfileSetting(self.profileSetting, 'True') else: self.SetBitmap(False) profile.putProfileSetting(self.profileSetting, 'False') self.callback() event.Skip()
def OnMouseMotion(self,e): if self.parent.objectsMaxV != None: size = (self.parent.objectsMaxV - self.parent.objectsMinV) sizeXY = math.sqrt((size[0] * size[0]) + (size[1] * size[1])) p0 = numpy.array(gluUnProject(e.GetX(), self.viewport[1] + self.viewport[3] - e.GetY(), 0, self.modelMatrix, self.projMatrix, self.viewport)) p1 = numpy.array(gluUnProject(e.GetX(), self.viewport[1] + self.viewport[3] - e.GetY(), 1, self.modelMatrix, self.projMatrix, self.viewport)) cursorZ0 = p0 - (p1 - p0) * (p0[2] / (p1[2] - p0[2])) cursorXY = math.sqrt((cursorZ0[0] * cursorZ0[0]) + (cursorZ0[1] * cursorZ0[1])) if cursorXY >= sizeXY * 0.7 and cursorXY <= sizeXY * 0.7 + 3: self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) else: self.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) if e.Dragging() and e.LeftIsDown(): if self.dragType == '': #Define the drag type depending on the cursor position. if cursorXY >= sizeXY * 0.7 and cursorXY <= sizeXY * 0.7 + 3: self.dragType = 'modelRotate' self.dragStart = math.atan2(cursorZ0[0], cursorZ0[1]) else: self.dragType = 'viewRotate' if self.dragType == 'viewRotate': if self.view3D: self.yaw += e.GetX() - self.oldX self.pitch -= e.GetY() - self.oldY if self.pitch > 170: self.pitch = 170 if self.pitch < 10: self.pitch = 10 else: self.offsetX += float(e.GetX() - self.oldX) * self.zoom / self.GetSize().GetHeight() * 2 self.offsetY -= float(e.GetY() - self.oldY) * self.zoom / self.GetSize().GetHeight() * 2 elif self.dragType == 'modelRotate': angle = math.atan2(cursorZ0[0], cursorZ0[1]) diff = self.dragStart - angle self.tempRotate = diff * 180 / math.pi #Workaround for buggy ATI cards. size = self.GetSizeTuple() self.SetSize((size[0]+1, size[1])) self.SetSize((size[0], size[1])) self.Refresh() else: if self.tempRotate != 0: profile.putProfileSetting('model_rotate_base', profile.getProfileSettingFloat('model_rotate_base') + self.tempRotate) self.parent.updateModelTransform() self.tempRotate = 0 self.dragType = '' if e.Dragging() and e.RightIsDown(): self.zoom += e.GetY() - self.oldY if self.zoom < 1: self.zoom = 1 self.Refresh() self.oldX = e.GetX() self.oldY = e.GetY()
def OnScaleMax(self, e): if self.objectsMinV == None: return vMin = self.objectsMinV vMax = self.objectsMaxV scaleX1 = (self.machineSize.x - self.machineCenter.x) / ((vMax[0] - vMin[0]) / 2) scaleY1 = (self.machineSize.y - self.machineCenter.y) / ((vMax[1] - vMin[1]) / 2) scaleX2 = (self.machineCenter.x) / ((vMax[0] - vMin[0]) / 2) scaleY2 = (self.machineCenter.y) / ((vMax[1] - vMin[1]) / 2) scaleZ = self.machineSize.z / (vMax[2] - vMin[2]) scale = min(scaleX1, scaleY1, scaleX2, scaleY2, scaleZ) self.scale.SetValue(str(scale)) profile.putProfileSetting('model_scale', self.scale.GetValue()) self.glCanvas.Refresh()
def OnScaleMax(self, e): if self.objectsMinV == None: return vMin = self.objectsMinV vMax = self.objectsMaxV scaleX1 = (self.machineSize.x - self.machineCenter.x) / ( (vMax[0] - vMin[0]) / 2) scaleY1 = (self.machineSize.y - self.machineCenter.y) / ( (vMax[1] - vMin[1]) / 2) scaleX2 = (self.machineCenter.x) / ((vMax[0] - vMin[1]) / 2) scaleY2 = (self.machineCenter.y) / ((vMax[1] - vMin[1]) / 2) scaleZ = self.machineSize.z / (vMax[2] - vMin[2]) scale = min(scaleX1, scaleY1, scaleX2, scaleY2, scaleZ) self.scale.SetValue(str(scale)) profile.putProfileSetting('model_scale', self.scale.GetValue()) self.glCanvas.Refresh()
def StoreData(self): profile.putPreference('machine_width', self.machineWidth.GetValue()) profile.putPreference('machine_depth', self.machineDepth.GetValue()) profile.putPreference('machine_height', self.machineHeight.GetValue()) profile.putProfileSetting('nozzle_size', self.nozzleSize.GetValue()) profile.putProfileSetting('machine_center_x', profile.getPreferenceFloat('machine_width') / 2) profile.putProfileSetting('machine_center_y', profile.getPreferenceFloat('machine_depth') / 2) profile.putProfileSetting('wall_thickness', float(profile.getProfileSettingFloat('nozzle_size')) * 2) profile.putPreference('has_heated_bed', str(self.heatedBed.GetValue()))
def StoreData(self): profile.putPreference('machine_width', self.machineWidth.GetValue()) profile.putPreference('machine_depth', self.machineDepth.GetValue()) profile.putPreference('machine_height', self.machineHeight.GetValue()) profile.putProfileSetting('nozzle_size', self.nozzleSize.GetValue()) profile.putProfileSetting( 'machine_center_x', profile.getPreferenceFloat('machine_width') / 2) profile.putProfileSetting( 'machine_center_y', profile.getPreferenceFloat('machine_depth') / 2) profile.putProfileSetting( 'wall_thickness', float(profile.getProfileSettingFloat('nozzle_size')) * 2) profile.putPreference('has_heated_bed', str(self.heatedBed.GetValue()))
def OnResetProfile(self, e): dlg = wx.MessageDialog(self, 'This will reset all profile settings to defaults.\nUnless you have saved your current profile, all settings will be lost!\nDo you really want to reset?', 'Profile reset', wx.YES_NO | wx.ICON_QUESTION) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() if result: profile.resetGlobalProfile() if profile.getPreference('machine_type') == 'reprap': profile.putProfileSetting('nozzle_size', '0.5') profile.putProfileSetting('machine_center_x', '40') profile.putProfileSetting('machine_center_y', '40') self.updateProfileToControls()
def OnResetProfile(self, e): dlg = wx.MessageDialog( self, 'This will reset all profile settings to defaults.\nUnless you have saved your current profile, all settings will be lost!\nDo you really want to reset?', 'Profile reset', wx.YES_NO | wx.ICON_QUESTION) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() if result: profile.resetGlobalProfile() if profile.getPreference('machine_type') == 'reprap': profile.putProfileSetting('nozzle_size', '0.5') profile.putProfileSetting('machine_center_x', '40') profile.putProfileSetting('machine_center_y', '40') self.updateProfileToControls()
def OnResetProfile(self, e): dlg = wx.MessageDialog( self, "This will reset all profile settings to defaults.\nUnless you have saved your current profile, all settings will be lost!\nDo you really want to reset?", "Profile reset", wx.YES_NO | wx.ICON_QUESTION, ) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() if result: profile.resetGlobalProfile() if profile.getPreference("machine_type") == "reprap": profile.putProfileSetting("nozzle_size", "0.5") profile.putProfileSetting("machine_center_x", "40") profile.putProfileSetting("machine_center_y", "40") self.updateProfileToControls()
def OnMulXAddClick(self, e): profile.putProfileSetting( 'model_multiply_x', str(max(1, int(profile.getProfileSetting('model_multiply_x')) + 1))) self.glCanvas.Refresh()
def updateModelTransform(self, f=0): if len(self.objectList) < 1 or self.objectList[0].mesh == None: return rotate = 0 mirrorX = self.mirrorx mirrorY = self.mirrory mirrorZ = self.mirrorz swapXZ = self.flipxy swapYZ = self.flipyz profile.putProfileSetting('model_scale', self.scale) profile.putProfileSetting('model_rotate_base', '0') profile.putProfileSetting('flip_x', mirrorX) profile.putProfileSetting('flip_y', mirrorY) profile.putProfileSetting('flip_z', mirrorZ) profile.putProfileSetting('swap_xz', swapXZ) profile.putProfileSetting('swap_yz', swapYZ) for obj in self.objectList: if obj.mesh == None: continue obj.mesh.setRotateMirror(rotate, mirrorX, mirrorY, mirrorZ, swapXZ, swapYZ) minV = self.objectList[0].mesh.getMinimum() maxV = self.objectList[0].mesh.getMaximum() for obj in self.objectList: if obj.mesh == None: continue obj.mesh.getMinimumZ() minV = numpy.minimum(minV, obj.mesh.getMinimum()) maxV = numpy.maximum(maxV, obj.mesh.getMaximum()) self.objectsMaxV = maxV self.objectsMinV = minV for obj in self.objectList: if obj.mesh == None: continue obj.mesh.vertexes -= numpy.array([minV[0] + (maxV[0] - minV[0]) / 2, minV[1] + (maxV[1] - minV[1]) / 2, minV[2]]) obj.mesh.getMinimumZ() obj.dirty = True self.glCanvas.Refresh()
def StoreData(self): if self.UltimakerRadio.GetValue(): profile.putPreference('machine_width', '205') profile.putPreference('machine_depth', '205') profile.putPreference('machine_height', '200') profile.putPreference('machine_type', 'ultimaker') profile.putProfileSetting('nozzle_size', '0.4') profile.putProfileSetting('machine_center_x', '100') profile.putProfileSetting('machine_center_y', '100') else: profile.putPreference('machine_width', '80') profile.putPreference('machine_depth', '80') profile.putPreference('machine_height', '60') profile.putPreference('machine_type', 'reprap') profile.putPreference('startMode', 'Normal') profile.putProfileSetting('nozzle_size', '0.5') profile.putProfileSetting('machine_center_x', '40') profile.putProfileSetting('machine_center_y', '40') profile.putProfileSetting( 'wall_thickness', float(profile.getProfileSetting('nozzle_size')) * 2)
def StoreData(self): profile.putProfileSetting('filament_diameter', self.filamentDiameter.GetValue())
def OnResetAll(self, e=None): profile.putProfileSetting('model_scale', '1.0') profile.putProfileSetting('model_rotate_base', '0') profile.putProfileSetting('flip_x', 'False') profile.putProfileSetting('flip_y', 'False') profile.putProfileSetting('flip_z', 'False') profile.putProfileSetting('swap_xz', 'False') profile.putProfileSetting('swap_yz', 'False') self.updateProfileToControls()
def OnScale(self, scale): self.scale = scale profile.putProfileSetting('model_scale', scale) self.glCanvas.Refresh()
def StoreData(self): if self.UltimakerRadio.GetValue(): profile.putPreference("machine_width", "205") profile.putPreference("machine_depth", "205") profile.putPreference("machine_height", "200") profile.putProfileSetting("nozzle_size", "0.4") profile.putProfileSetting("machine_center_x", "100") profile.putProfileSetting("machine_center_y", "100") else: profile.putPreference("machine_width", "80") profile.putPreference("machine_depth", "80") profile.putPreference("machine_height", "60") profile.putProfileSetting("nozzle_size", "0.5") profile.putProfileSetting("machine_center_x", "40") profile.putProfileSetting("machine_center_y", "40") profile.putProfileSetting("wall_thickness", float(profile.getProfileSetting("nozzle_size")) * 2)
def OnRotate(self, e): profile.putProfileSetting('model_rotate_base', self.rotate.GetValue()) self.updateModelTransform()
def OnResetAll(self, e = None): profile.putProfileSetting('model_scale', '1.0') profile.putProfileSetting('model_rotate_base', '0') profile.putProfileSetting('flip_x', 'False') profile.putProfileSetting('flip_y', 'False') profile.putProfileSetting('flip_z', 'False') profile.putProfileSetting('swap_xz', 'False') profile.putProfileSetting('swap_yz', 'False') self.updateProfileToControls()
def OnScale(self, e): scale = 1.0 if self.scale.GetValue() != '': scale = self.scale.GetValue() profile.putProfileSetting('model_scale', scale) self.glCanvas.Refresh()
def OnResetAll(self, e): profile.putProfileSetting('model_scale', '1.0') profile.putProfileSetting('model_rotate_base', '0') profile.putProfileSetting('flip_x', 'False') profile.putProfileSetting('flip_y', 'False') profile.putProfileSetting('flip_z', 'False') profile.putProfileSetting('swap_xz', 'False') profile.putProfileSetting('swap_yz', 'False') self.updateProfileToControls() self.warningPopup.Show(False) self.warningPopup.timer.Stop()
def main(): parser = OptionParser(usage="usage: %prog [options] <filename>.stl") parser.add_option("-i", "--ini", action="store", type="string", dest="profileini", help="Load settings from a profile ini file") parser.add_option( "-r", "--print", action="store", type="string", dest="printfile", help= "Open the printing interface, instead of the normal cura interface.") parser.add_option("-p", "--profile", action="store", type="string", dest="profile", help="Internal option, do not use!") parser.add_option("-x", "--scale", action="store", type="string", dest="scale", help="scale the stl object") parser.add_option( "-s", "--slice", action="store_true", dest="slice", help="Slice the given files instead of opening them in Cura") parser.add_option("-o", "--output", action="store", type="string", dest="output", help="path to write sliced file to") parser.add_option("-t", "--transform", action="store", type="string", dest="transform", help="rotate and transform the object") (options, args) = parser.parse_args() #print "load preferences from " + profile.getPreferencePath() profile.loadPreferences(profile.getPreferencePath()) #default_profile_string = profile.getProfileString() #print("default_profile_string = %s" % (default_profile_string)) #profile.setProfileFromString(default_profile_string) if options.profile is not None: profile.loadProfile( r"/home/buccaneer/bin/buccaneer-slicer/current/slicer.ini") #profile.setProfileFromString(options.profile) #print("options.profile Input\n\n") #print(options.profile) custom_params = [] for param in options.profile.split(','): param = param.replace("++", " ") custom_params.append(param) #print(custom_params) profile.setProfileFromString(custom_params) elif options.profileini is not None: profile.loadProfile(options.profileini) else: #print("Default Path: %s" % (profile.getDefaultProfilePath())) profile.loadProfile( r"/home/buccaneer/bin/buccaneer-slicer/current/slicer.ini") if options.printfile is not None: from Cura.gui import printWindow printWindow.startPrintInterface(options.printfile) elif options.slice is not None: from util import sliceEngine from util import objectScene from util import meshLoader from util import mesh import shutil import numpy as np def commandlineProgessCallback(progress, ready, loading): if progress >= 0 and not ready and not loading: sys.stdout.write("Slicing: %d%%\n" % (progress * 100, )) sys.stdout.flush() elif progress >= 0 and not ready and loading: sys.stdout.write("Loading: %d%%" % (progress * 100, )) sys.stdout.flush() profile.putMachineSetting('machine_name', 'Buccaneer') profile.putMachineSetting('machine_width', '138') profile.putMachineSetting('machine_depth', '112') profile.putMachineSetting('machine_height', '149.5') profile.putProfileSetting('nozzle_size', '0.4') profile.putProfileSetting( 'wall_thickness', float(profile.getProfileSettingFloat('nozzle_size')) * 2) profile.putMachineSetting('has_heated_bed', str(False)) profile.putMachineSetting('machine_center_is_zero', str(False)) profile.putMachineSetting('extruder_head_size_min_x', '0') profile.putMachineSetting('extruder_head_size_min_y', '0') profile.putMachineSetting('extruder_head_size_max_x', '0') profile.putMachineSetting('extruder_head_size_max_y', '0') profile.putMachineSetting('extruder_head_size_height', '0') profile.checkAndUpdateMachineName() scene = objectScene.Scene() scene.updateMachineDimensions() slicer = sliceEngine.Slicer(commandlineProgessCallback) matrix = [] if options.transform is not None: transform_params = [] for param in options.transform.split(','): param = param.replace("[", " ") param = param.replace("]", " ") transform_params.append(param) data = np.array(transform_params) print data matrix = [[ transform_params[0], transform_params[1], transform_params[2] ], [transform_params[3], transform_params[4], transform_params[5]], [ transform_params[6], transform_params[7], transform_params[8] ]] if options.scale is not None: if (int(options.scale) >= 1): obj = meshLoader.loadMeshes(args[0], int(options.scale)) else: obj = meshLoader.loadMeshes(args[0]) else: obj = meshLoader.loadMeshes(args[0]) for m in obj: scene.addNewMatrix(m, matrix) sys.stdout.write("Slicing: %d%%\n" % (0 * 100, )) sys.stdout.flush() slicer.runSlicer(scene) slicer.wait() profile.replaceGCodeTagsFromSlicer(slicer.getGCodeFilename(), slicer) if options.output: shutil.copyfile(slicer.getGCodeFilename(), options.output) print 'GCode file saved : %s' % options.output else: shutil.copyfile(slicer.getGCodeFilename(), args[0] + '.gcode') print 'GCode file saved as: %s' % (args[0] + '.gcode') slicer.cleanup() else: from Cura.gui import app app.CuraApp(args).MainLoop()
def StoreData(self): if self.UltimakerRadio.GetValue(): profile.putPreference('machine_width', '205') profile.putPreference('machine_depth', '205') profile.putPreference('machine_height', '200') profile.putPreference('machine_type', 'ultimaker') profile.putProfileSetting('nozzle_size', '0.4') profile.putProfileSetting('machine_center_x', '100') profile.putProfileSetting('machine_center_y', '100') else: profile.putPreference('machine_width', '80') profile.putPreference('machine_depth', '80') profile.putPreference('machine_height', '60') profile.putPreference('machine_type', 'reprap') profile.putPreference('startMode', 'Normal') profile.putProfileSetting('nozzle_size', '0.5') profile.putProfileSetting('machine_center_x', '40') profile.putProfileSetting('machine_center_y', '40') profile.putProfileSetting('wall_thickness', float(profile.getProfileSetting('nozzle_size')) * 2)
def OnMulYSubClick(self, e): profile.putProfileSetting( 'model_multiply_y', str(max(1, int(profile.getProfileSetting('model_multiply_y')) - 1))) self.glCanvas.Refresh()
def OnMulXAddClick(self, e): profile.putProfileSetting('model_multiply_x', str(max(1, int(profile.getProfileSetting('model_multiply_x'))+1))) self.glCanvas.Refresh()
def OnMouseMotion(self, e): if self.parent.objectsMaxV != None: size = (self.parent.objectsMaxV - self.parent.objectsMinV) sizeXY = math.sqrt((size[0] * size[0]) + (size[1] * size[1])) p0 = numpy.array( gluUnProject(e.GetX(), self.viewport[1] + self.viewport[3] - e.GetY(), 0, self.modelMatrix, self.projMatrix, self.viewport)) p1 = numpy.array( gluUnProject(e.GetX(), self.viewport[1] + self.viewport[3] - e.GetY(), 1, self.modelMatrix, self.projMatrix, self.viewport)) cursorZ0 = p0 - (p1 - p0) * (p0[2] / (p1[2] - p0[2])) cursorXY = math.sqrt((cursorZ0[0] * cursorZ0[0]) + (cursorZ0[1] * cursorZ0[1])) if cursorXY >= sizeXY * 0.7 and cursorXY <= sizeXY * 0.7 + 3: self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) else: self.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) if e.Dragging() and e.LeftIsDown(): if self.dragType == '': #Define the drag type depending on the cursor position. if cursorXY >= sizeXY * 0.7 and cursorXY <= sizeXY * 0.7 + 3: self.dragType = 'modelRotate' self.dragStart = math.atan2(cursorZ0[0], cursorZ0[1]) else: self.dragType = 'viewRotate' if self.dragType == 'viewRotate': if self.view3D: self.yaw += e.GetX() - self.oldX self.pitch -= e.GetY() - self.oldY if self.pitch > 170: self.pitch = 170 if self.pitch < 10: self.pitch = 10 else: self.offsetX += float( e.GetX() - self.oldX) * self.zoom / self.GetSize().GetHeight() * 2 self.offsetY -= float( e.GetY() - self.oldY) * self.zoom / self.GetSize().GetHeight() * 2 elif self.dragType == 'modelRotate': angle = math.atan2(cursorZ0[0], cursorZ0[1]) diff = self.dragStart - angle self.tempRotate = diff * 180 / math.pi #Workaround for buggy ATI cards. size = self.GetSizeTuple() self.SetSize((size[0] + 1, size[1])) self.SetSize((size[0], size[1])) self.Refresh() else: if self.tempRotate != 0: profile.putProfileSetting( 'model_rotate_base', profile.getProfileSettingFloat('model_rotate_base') + self.tempRotate) self.parent.updateModelTransform() self.tempRotate = 0 self.dragType = '' if e.Dragging() and e.RightIsDown(): self.zoom += e.GetY() - self.oldY if self.zoom < 1: self.zoom = 1 self.Refresh() self.oldX = e.GetX() self.oldY = e.GetY()
def OnMulYSubClick(self, e): profile.putProfileSetting('model_multiply_y', str(max(1, int(profile.getProfileSetting('model_multiply_y'))-1))) self.glCanvas.Refresh()