chiark / gitweb /
Add proper line width calculation to GCode preview. Added raft settings.
authorDaid <daid303@gmail.com>
Sun, 18 Mar 2012 22:00:33 +0000 (23:00 +0100)
committerDaid <daid303@gmail.com>
Sun, 18 Mar 2012 22:00:33 +0000 (23:00 +0100)
SkeinPyPy/fabmetheus_utilities/settings.py
SkeinPyPy/newui/mainWindow.py
SkeinPyPy/newui/preview3d.py
SkeinPyPy/newui/profile.py

index daa99dc923c46fc5d21c9e690067b470d56625bf..72b542327c495838b4ecad3c0ac211281b2134de 100644 (file)
@@ -25,6 +25,11 @@ def ifSettingAboveZero(name):
 def ifSettingIs(name, value):
        return lambda setting: profile.getProfileSetting(name) == value
 
+def raftLayerCount(setting):
+       if profile.getProfileSetting('enable_raft') == "True":
+               return '1'
+       return '0'
+
 def storedPercentSetting(name):
        return lambda setting: float(profile.getProfileSetting(name)) / 100
 
@@ -196,7 +201,7 @@ def getSkeinPyPyProfileInformation():
                        'Base_Flow_Rate_Multiplier_ratio': DEFSET,
                        'Base_Infill_Density_ratio': DEFSET,
                        'Base_Layer_Thickness_over_Layer_Thickness': DEFSET,
-                       'Base_Layers_integer': '0',
+                       'Base_Layers_integer': raftLayerCount,
                        'Base_Nozzle_Lift_over_Base_Layer_Thickness_ratio': DEFSET,
                        'Initial_Circling': DEFSET,
                        'Infill_Overhang_over_Extrusion_Width_ratio': DEFSET,
@@ -204,7 +209,7 @@ def getSkeinPyPyProfileInformation():
                        'Interface_Flow_Rate_Multiplier_ratio': DEFSET,
                        'Interface_Infill_Density_ratio': DEFSET,
                        'Interface_Layer_Thickness_over_Layer_Thickness': DEFSET,
-                       'Interface_Layers_integer': '0',
+                       'Interface_Layers_integer': raftLayerCount,
                        'Interface_Nozzle_Lift_over_Interface_Layer_Thickness_ratio': DEFSET,
                        'Name_of_Support_End_File': DEFSET,
                        'Name_of_Support_Start_File': DEFSET,
index 13f0e89388e505f9442965de5c629111eb941afc..3d2d0ab6a3167cbaad6211d6f757f41c4b30ea1d 100644 (file)
@@ -88,7 +88,6 @@ class mainWindow(configBase.configWindowBase):
                c = configBase.SettingRow(left, "Wall thickness (mm)", 'wall_thickness', '0.8', 'Thickness of the walls.\nThis is used in combination with the nozzle size to define the number\nof perimeter lines and the thickness of those perimeter lines.')
                validators.validFloat(c, 0.0)
                validators.wallThicknessValidator(c)
-               configBase.settingNotify(c, self.preview3d.updateWallLineWidth)
                
                configBase.TitleRow(left, "Fill")
                c = configBase.SettingRow(left, "Bottom/Top thickness (mm)", 'solid_layer_thickness', '0.6', 'This controls the thickness of the bottom and top layers, the amount of solid layers put down is calculated by the layer thickness and this value.\nHaving this value a multiply of the layer thickness makes sense. And keep it near your wall thickness to make an evenly strong part.')
@@ -114,6 +113,7 @@ class mainWindow(configBase.configWindowBase):
                
                configBase.TitleRow(right, "Support")
                c = configBase.SettingRow(right, "Support type", 'support', ['None', 'Exterior Only', 'Everywhere', 'Empty Layers Only'], 'Type of support structure build.\nNone does not do any support.\nExterior only only creates support on the outside.\nEverywhere creates support even on the insides of the model.\nOnly on empty layers is for stacked objects.')
+               c = configBase.SettingRow(right, "Add raft", 'enable_raft', False, 'A raft is a few layers of lines below the bottom of the object. It prevents warping. Full raft settings can be found in the advanced settings.\nFor PLA this is usually not required. But if you print with ABS it is almost required.')
 
                configBase.TitleRow(right, "Filament")
                c = configBase.SettingRow(right, "Diameter (mm)", 'filament_diameter', '2.89', 'Diameter of your filament, as accurately as possible.\nIf you cannot measure this value you will have to callibrate it, a higher number means less extrusion, a smaller number generates more extrusion.')
@@ -135,8 +135,6 @@ class mainWindow(configBase.configWindowBase):
                configBase.TitleRow(left, "Machine nozzle")
                c = configBase.SettingRow(left, "Nozzle size (mm)", 'nozzle_size', '0.4', 'The nozzle size is very important, this is used to calculate the line width of the infill, and used to calculate the amount of outside wall lines and thickness for the wall thickness you entered in the print settings.')
                validators.validFloat(c, 0.1, 1.0)
-               configBase.settingNotify(c, self.preview3d.updateWallLineWidth)
-               configBase.settingNotify(c, self.preview3d.updateInfillLineWidth)
 
                configBase.TitleRow(left, "Retraction")
                c = configBase.SettingRow(left, "Minimal travel (mm)", 'retraction_min_travel', '5.0', 'Minimal amount of travel needed for a retraction to happen at all. To make sure you do not get a lot of retractions in a small area')
index 7611ab2dd2fd2cb8bfb131d6aad1f1da0b076d59..8bdcc22e79940757fbd7ff34c7e3c75aba24858a 100644 (file)
@@ -19,7 +19,6 @@ from newui import profile
 from newui import gcodeInterpreter\r
 from newui import util3d\r
 \r
-from fabmetheus_utilities import settings\r
 from fabmetheus_utilities.fabmetheus_tools import fabmetheus_interpret\r
 from fabmetheus_utilities.vector3 import Vector3\r
 \r
@@ -92,14 +91,6 @@ class previewPanel(wx.Panel):
                self.moveModel()\r
                self.glCanvas.Refresh()\r
        \r
-       def updateWallLineWidth(self, setting):\r
-               #TODO: this shouldn't be needed, you can calculate the line width from the E values combined with the steps_per_E and the filament diameter (reverse volumatric)\r
-               self.glCanvas.lineWidth = settings.calculateEdgeWidth(setting)\r
-       \r
-       def updateInfillLineWidth(self, setting):\r
-               #TODO: this shouldn't be needed, you can calculate the line width from the E values combined with the steps_per_E and the filament diameter (reverse volumatric)\r
-               self.glCanvas.infillLineWidth = profile.getProfileSetting('nozzle_size')\r
-       \r
        def loadModelFile(self, filename):\r
                self.modelFilename = filename\r
                self.gcodeFilename = filename[: filename.rfind('.')] + "_export.gcode"\r
@@ -216,8 +207,6 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                self.zoom = 150\r
                self.offsetX = 0\r
                self.offsetY = 0\r
-               self.lineWidth = 0.4\r
-               self.fillLineWidth = 0.4\r
                self.view3D = True\r
                self.modelDisplayList = None\r
                self.gcodeDisplayList = None\r
@@ -315,7 +304,22 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                        if self.parent.gcodeDirty:\r
                                self.parent.gcodeDirty = False\r
                                glNewList(self.gcodeDisplayList, GL_COMPILE)\r
+                               prevLayerZ = 0.0\r
+                               curLayerZ = 0.0\r
+                               \r
+                               layerThickness = 0.0\r
+                               filamentRadius = float(profile.getProfileSetting('filament_diameter')) / 2\r
+                               filamentArea = math.pi * filamentRadius * filamentRadius\r
+                               lineWidth = float(profile.getProfileSetting('nozzle_size')) / 2\r
+                               \r
+                               curLayerNum = 0\r
                                for path in self.parent.gcode.pathList:\r
+                                       if path['layerNr'] != curLayerNum:\r
+                                               prevLayerZ = curLayerZ\r
+                                               curLayerZ = path['list'][1].z\r
+                                               curLayerNum = path['layerNr']\r
+                                               layerThickness = curLayerZ - prevLayerZ\r
+                                       \r
                                        c = 1.0\r
                                        if path['layerNr'] != self.parent.layerSpin.GetValue():\r
                                                if path['layerNr'] < self.parent.layerSpin.GetValue():\r
@@ -336,16 +340,14 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                                        if path['type'] == 'retract':\r
                                                glColor3f(0,c,c)\r
                                        if c > 0.4 and path['type'] == 'extrude':\r
-                                               if path['pathType'] == 'FILL':\r
-                                                       lineWidth = self.fillLineWidth / 2\r
-                                               else:\r
-                                                       lineWidth = self.lineWidth / 2\r
                                                for i in xrange(0, len(path['list'])-1):\r
                                                        v0 = path['list'][i]\r
                                                        v1 = path['list'][i+1]\r
                                                        dist = (v0 - v1).vsize()\r
-                                                       if dist > 0:\r
-                                                               extrusionMMperDist = (v1.e - v0.e) / (v0 - v1).vsize() / self.parent.gcode.stepsPerE\r
+                                                       if dist > 0 and layerThickness > 0:\r
+                                                               extrusionMMperDist = (v1.e - v0.e) / (v0 - v1).vsize()\r
+                                                               lineWidth = extrusionMMperDist * filamentArea / layerThickness / 2\r
+\r
                                                        #TODO: Calculate line width from ePerDistance (needs layer thickness, steps_per_E and filament diameter)\r
                                                        normal = (v0 - v1).cross(util3d.Vector3(0,0,1))\r
                                                        normal.normalize()\r
@@ -394,12 +396,12 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                                modelSize = self.parent.triangleMesh.getCarveCornerMaximum() - self.parent.triangleMesh.getCarveCornerMinimum()\r
                                glNewList(self.modelDisplayList, GL_COMPILE)\r
                                glPushMatrix()\r
-                               glTranslate(-(modelSize.x+self.lineWidth*15)*(multiX-1)/2,-(modelSize.y+self.lineWidth*15)*(multiY-1)/2, 0)\r
+                               glTranslate(-(modelSize.x+10)*(multiX-1)/2,-(modelSize.y+10)*(multiY-1)/2, 0)\r
                                for mx in xrange(0, multiX):\r
                                        for my in xrange(0, multiY):\r
                                                for face in self.parent.triangleMesh.faces:\r
                                                        glPushMatrix()\r
-                                                       glTranslate((modelSize.x+self.lineWidth*15)*mx,(modelSize.y+self.lineWidth*15)*my, 0)\r
+                                                       glTranslate((modelSize.x+10)*mx,(modelSize.y+10)*my, 0)\r
                                                        glBegin(GL_TRIANGLES)\r
                                                        v1 = self.parent.triangleMesh.vertexes[face.vertexIndexes[0]]\r
                                                        v2 = self.parent.triangleMesh.vertexes[face.vertexIndexes[1]]\r
index f672bc8a7f10fce3a8c5b543feb4216fe1bc41fa..0f04a5206dc20f051a66106be7fc665560edec0e 100644 (file)
@@ -46,6 +46,7 @@ profileDefaultSettings = {
        'support_rate': '100',\r
        'support_distance': '0.5',\r
        'joris': 'False',\r
+       'enable_raft': 'False',\r
 }\r
 preferencesDefaultSettings = {\r
        'wizardDone': 'False',\r