From: daid303 Date: Mon, 7 Jan 2013 12:40:41 +0000 (+0100) Subject: Pass a matrix to the slicer for scale and rotation. X-Git-Tag: 13.03~125 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=03c2827edca42107faccb9f3f749184d5643699e;p=cura.git Pass a matrix to the slicer for scale and rotation. --- diff --git a/Cura/gui/projectPlanner.py b/Cura/gui/projectPlanner.py index c0a41e1f..4ca569cc 100644 --- a/Cura/gui/projectPlanner.py +++ b/Cura/gui/projectPlanner.py @@ -596,7 +596,7 @@ class projectPlanner(wx.Frame): clearZ = 0 actionList = [] for item in self.list: - if item.profile != None and os.path.isfile(item.profile): + if item.profile is not None and os.path.isfile(item.profile): profile.loadGlobalProfile(item.profile) put('object_center_x', item.centerX - self.extruderOffset[item.extruder][0]) put('object_center_y', item.centerY - self.extruderOffset[item.extruder][1]) @@ -625,7 +625,7 @@ class projectPlanner(wx.Frame): actionList[-2].leaveResultForNextSlice = True actionList[-1].usePreviousSlice = True - if item.profile != None: + if item.profile is not None: profile.loadGlobalProfileFromString(oldProfile) else: @@ -640,9 +640,9 @@ class projectPlanner(wx.Frame): actionList = [] action = Action() - action.sliceCmd = sliceRun.getSliceCommand(resultFilename + "_temp_.stl") - action.centerX = profile.getPreferenceFloat('machine_width') / 2 - action.centerY = profile.getPreferenceFloat('machine_depth') / 2 + action.sliceCmd = sliceRun.getSliceCommand(resultFilename, [resultFilename + "_temp_.stl"], [profile.getMachineCenterCoords()]) + action.centerX = profile.getMachineCenterCoords()[0] + action.centerY = profile.getMachineCenterCoords()[1] action.temperature = profile.getProfileSettingFloat('print_temperature') action.extruder = 0 action.filename = resultFilename + "_temp_.stl" diff --git a/Cura/gui/sliceProgessPanel.py b/Cura/gui/sliceProgessPanel.py index b73f1e2d..7d76d5ed 100644 --- a/Cura/gui/sliceProgessPanel.py +++ b/Cura/gui/sliceProgessPanel.py @@ -44,7 +44,7 @@ class sliceProgessPanel(wx.Panel): self.startTime = time.time() if profile.getPreference('save_profile') == 'True': profile.saveGlobalProfile(self.filelist[0][: self.filelist[0].rfind('.')] + "_profile.ini") - center = profile.getMachineCenterCoords() + center = profile.getMachineCenterCoords() + profile.getObjectMatrix() cmdList = [sliceRun.getSliceCommand(sliceRun.getExportFilename(self.filelist[0]), ['|'.join(self.filelist)], [center])] self.thread = WorkerThread(self, filelist, cmdList) diff --git a/Cura/slice/cura_sf/fabmetheus_utilities/settings.py b/Cura/slice/cura_sf/fabmetheus_utilities/settings.py index 7bbb739e..8087a9d0 100644 --- a/Cura/slice/cura_sf/fabmetheus_utilities/settings.py +++ b/Cura/slice/cura_sf/fabmetheus_utilities/settings.py @@ -96,7 +96,7 @@ def calcLayerSkip(setting): def getProfileInformation(): return { 'carve': { - 'Add_Layer_Template_to_SVG': DEFSET, + 'Add_Layer_Template_to_SVG': 'False', 'Edge_Width_mm': calculateEdgeWidth, 'Extra_Decimal_Places_float': DEFSET, 'Import_Coarseness_ratio': DEFSET, @@ -106,13 +106,7 @@ def getProfileInformation(): 'Correct_Mesh': DEFSET, 'Unproven_Mesh': DEFSET, 'SVG_Viewer': DEFSET, - 'FlipX': storedSetting("flip_x"), - 'FlipY': storedSetting("flip_y"), - 'FlipZ': storedSetting("flip_z"), - 'SwapXZ': storedSetting("swap_xz"), - 'SwapYZ': storedSetting("swap_yz"), - 'Scale': storedSettingFloat("model_scale"), - 'Rotate': storedSettingFloat("model_rotate_base"), + 'ObjectMatrix': storedSetting("object_matrix"), 'CenterX': lambda setting: profile.getProfileSettingFloat('object_center_x') if profile.getProfileSettingFloat('object_center_x') > 0 else profile.getPreferenceFloat("machine_width") / 2, 'CenterY': lambda setting: profile.getProfileSettingFloat('object_center_y') if profile.getProfileSettingFloat('object_center_y') > 0 else profile.getPreferenceFloat("machine_depth") / 2, 'AlternativeCenterFile': storedSetting("alternative_center"), diff --git a/Cura/slice/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/carve.py b/Cura/slice/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/carve.py index 14ef4476..e750cb3a 100644 --- a/Cura/slice/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/carve.py +++ b/Cura/slice/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/carve.py @@ -170,15 +170,9 @@ class CarveRepository(object): settings.LabelSeparator().getFromRepository(self) self.executeTitle = 'Carve' - self.flipX = settings.BooleanSetting().getFromValue('FlipX', self, False) - self.flipY = settings.BooleanSetting().getFromValue('FlipY', self, False) - self.flipZ = settings.BooleanSetting().getFromValue('FlipZ', self, False) - self.swapXZ = settings.BooleanSetting().getFromValue('SwapXZ', self, False) - self.swapYZ = settings.BooleanSetting().getFromValue('SwapYZ', self, False) - self.centerX = settings.FloatSpin().getFromValue(0.0, 'CenterX', self, 1000.0, 0.0) - self.centerY = settings.FloatSpin().getFromValue(0.0, 'CenterY', self, 1000.0, 0.0) - self.scale = settings.FloatSpin().getFromValue( 0.1, 'Scale', self, 10.0, 1.0 ) - self.rotate = settings.FloatSpin().getFromValue( -180.0, 'Rotate', self, 180.0, 0.0 ) + self.centerX = settings.FloatSpin().getFromValue(0.0, 'CenterX', self, 1000.0, 0.0); + self.centerY = settings.FloatSpin().getFromValue(0.0, 'CenterY', self, 1000.0, 0.0); + self.matrix = settings.StringSetting().getFromValue('ObjectMatrix', self, '1,0,0,0,1,0,0,0,1') self.alternativeCenter = settings.StringSetting().getFromValue('AlternativeCenterFile', self, '') @@ -194,36 +188,17 @@ class CarveSkein(object): def getCarvedSVG(self, carving, fileName, repository): "Parse gnu triangulated surface text and store the carved gcode." - scale = repository.scale.value - rotate = repository.rotate.value / 180 * math.pi - scaleX = scale - scaleY = scale - scaleZ = scale - if repository.flipX.value == True: - scaleX = -scaleX - if repository.flipY.value == True: - scaleY = -scaleY - if repository.flipZ.value == True: - scaleZ = -scaleZ - swapXZ = repository.swapXZ.value - swapYZ = repository.swapYZ.value - mat00 = math.cos(rotate) * scaleX - mat01 =-math.sin(rotate) * scaleY - mat10 = math.sin(rotate) * scaleX - mat11 = math.cos(rotate) * scaleY + matrix = map(float, repository.matrix.value.split(',')) + print matrix for i in xrange(0, len(carving.vertexes)): x = carving.vertexes[i].x y = carving.vertexes[i].y z = carving.vertexes[i].z - if swapXZ: - x, z = z, x - if swapYZ: - y, z = z, y carving.vertexes[i] = Vector3( - x * mat00 + y * mat01, - x * mat10 + y * mat11, - z * scaleZ) + x * matrix[0] + y * matrix[3] + z * matrix[6], + x * matrix[1] + y * matrix[4] + z * matrix[7], + x * matrix[2] + y * matrix[5] + z * matrix[8]) if repository.alternativeCenter.value != '': carving2 = svg_writer.getCarving(repository.alternativeCenter.value) @@ -231,14 +206,10 @@ class CarveSkein(object): x = carving2.vertexes[i].x y = carving2.vertexes[i].y z = carving2.vertexes[i].z - if swapXZ: - x, z = z, x - if swapYZ: - y, z = z, y carving2.vertexes[i] = Vector3( - x * mat00 + y * mat01, - x * mat10 + y * mat11, - z * scaleZ) + x * matrix[0] + y * matrix[3] + z * matrix[6], + x * matrix[1] + y * matrix[4] + z * matrix[7], + x * matrix[2] + y * matrix[5] + z * matrix[8]) minZ = carving2.getMinimumZ() minSize = carving2.getCarveCornerMinimum() maxSize = carving2.getCarveCornerMaximum() diff --git a/Cura/util/mesh.py b/Cura/util/mesh.py index a5ed6f8e..6be227c6 100644 --- a/Cura/util/mesh.py +++ b/Cura/util/mesh.py @@ -4,6 +4,7 @@ import time import math import numpy +numpy.seterr(all='ignore') from Cura.util import util3d @@ -65,6 +66,7 @@ class mesh(object): mat = numpy.array([mat[2],mat[1],mat[0]], numpy.float32) if swapYZ: mat = numpy.array([mat[0],mat[2],mat[1]], numpy.float32) + self.matrix = mat self.vertexes = (numpy.matrix(self.origonalVertexes, copy = False) * numpy.matrix(mat)).getA() #Calculate the boundery box of the object diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 26a736c2..d86779f5 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -423,7 +423,31 @@ def calculateSolidLayerCount(): return int(math.ceil(solidThickness / layerHeight - 0.0001)) def getMachineCenterCoords(): - return (getPreferenceFloat('machine_width') / 2, getPreferenceFloat('machine_depth') / 2) + return [getPreferenceFloat('machine_width') / 2, getPreferenceFloat('machine_depth') / 2] + +def getObjectMatrix(): + rotate = getProfileSettingFloat('model_rotate_base') + rotate = rotate / 180.0 * math.pi + scaleX = 1.0 + scaleY = 1.0 + scaleZ = 1.0 + if getProfileSetting('flipX') == 'True': + scaleX = -scaleX + if getProfileSetting('flipY') == 'True': + scaleY = -scaleY + if getProfileSetting('flipZ') == 'True': + scaleZ = -scaleZ + mat00 = math.cos(rotate) * scaleX + mat01 =-math.sin(rotate) * scaleY + mat10 = math.sin(rotate) * scaleX + mat11 = math.cos(rotate) * scaleY + + mat = [mat00,mat10,0, mat01,mat11,0, 0,0,scaleZ] + if getProfileSetting('swap_xz') == 'True': + mat = mat[6:9] + mat[3:6] + mat[0:3] + if getProfileSetting('swap_yz') == 'True': + mat = mat[0:3] + mat[6:9] + mat[3:6] + return mat ######################################################### ## Alteration file functions diff --git a/Cura/util/sliceRun.py b/Cura/util/sliceRun.py index 4b50ef58..094d8f6e 100644 --- a/Cura/util/sliceRun.py +++ b/Cura/util/sliceRun.py @@ -75,7 +75,7 @@ def getSliceCommand(outputfilename, filenames, positions): for idx in xrange(0, len(filenames)): filename = filenames[idx] position = positions[idx] - cmd.append("%f,%f" % (position[0], position[1])) + cmd.append(','.join(map(str, position))) try: cmd.append(str(filename)) except UnicodeEncodeError: