chiark / gitweb /
Pass a matrix to the slicer for scale and rotation.
authordaid303 <daid303@gmail.com>
Mon, 7 Jan 2013 12:40:41 +0000 (13:40 +0100)
committerdaid303 <daid303@gmail.com>
Mon, 7 Jan 2013 12:40:41 +0000 (13:40 +0100)
Cura/gui/projectPlanner.py
Cura/gui/sliceProgessPanel.py
Cura/slice/cura_sf/fabmetheus_utilities/settings.py
Cura/slice/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/carve.py
Cura/util/mesh.py
Cura/util/profile.py
Cura/util/sliceRun.py

index c0a41e1f30df71345ef7027af524310bcb2de41c..4ca569ccdbb5f88b34d78d798b3bf9e451c8ec4f 100644 (file)
@@ -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"
index b73f1e2df1cc04a9d9849e203a02906a84324035..7d76d5ed3221dc0824b4560526f55a8a20f78851 100644 (file)
@@ -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)
        
index 7bbb739e08d4b0dcfeec9b611423236f11550907..8087a9d039e454a70e6a8e6fae9a352583c3c0e4 100644 (file)
@@ -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"),
index 14ef4476bf8bc01f4855995558d9ed72d14ced0f..e750cb3a01d9fd77951819243389286dd79c3565 100644 (file)
@@ -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()
index a5ed6f8ee0f77cd97832735f4caa73b6574afb4e..6be227c6828cf28ccf800e3ae8a7651519f88945 100644 (file)
@@ -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
index 26a736c2e323a31de257a911bdc2ed142a7aaede..d86779f5116d26826a2c05303f7ceb4e16470d1e 100644 (file)
@@ -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
index 4b50ef582c8ba6bcbd72a18e5deb50b95992a42c..094d8f6e1fc9f8a7ff1c6078abc144d4e35d013d 100644 (file)
@@ -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: