chiark / gitweb /
Make 3D model colour configurable.
authordaid <daid303@gmail.com>
Mon, 30 Jul 2012 10:26:30 +0000 (12:26 +0200)
committerdaid <daid303@gmail.com>
Mon, 30 Jul 2012 10:26:30 +0000 (12:26 +0200)
Cura/gui/configBase.py
Cura/gui/preferencesDialog.py
Cura/gui/preview3d.py
Cura/util/profile.py

index 2ce3b7005f922984adb790f0698cf138df469d96..14f38c547074e9420707907b86803a7de7773681 100644 (file)
@@ -102,6 +102,7 @@ class SettingRow():
                sizer = panel.GetSizer()
                x = sizer.GetRows()
                y = 0
+               flag = 0
                
                self.validators = []
                self.validationMsg = ''
@@ -120,16 +121,22 @@ class SettingRow():
                if isinstance(defaultValue, types.StringTypes):
                        self.ctrl = wx.TextCtrl(panel, -1, getSettingFunc(configName))
                        self.ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
+                       flag = wx.EXPAND
                elif isinstance(defaultValue, types.BooleanType):
                        self.ctrl = wx.CheckBox(panel, -1, style=wx.ALIGN_RIGHT)
                        self.SetValue(getSettingFunc(configName))
                        self.ctrl.Bind(wx.EVT_CHECKBOX, self.OnSettingChange)
+               elif isinstance(defaultValue, wx.Colour):
+                       self.ctrl = wx.ColourPickerCtrl(panel, -1)
+                       self.SetValue(getSettingFunc(configName))
+                       self.ctrl.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnSettingChange)
                else:
                        self.ctrl = wx.ComboBox(panel, -1, getSettingFunc(configName), choices=defaultValue, style=wx.CB_DROPDOWN|wx.CB_READONLY)
                        self.ctrl.Bind(wx.EVT_COMBOBOX, self.OnSettingChange)
+                       flag = wx.EXPAND
 
                sizer.Add(self.label, (x,y), flag=wx.ALIGN_CENTER_VERTICAL)
-               sizer.Add(self.ctrl, (x,y+1), flag=wx.ALIGN_BOTTOM|wx.EXPAND)
+               sizer.Add(self.ctrl, (x,y+1), flag=wx.ALIGN_BOTTOM|flag)
                sizer.SetRows(x+1)
 
                self.ctrl.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
@@ -172,11 +179,16 @@ class SettingRow():
                self.panel.main.UpdatePopup(self)
 
        def GetValue(self):
-               return str(self.ctrl.GetValue())
+               if isinstance(self.ctrl, wx.ColourPickerCtrl):
+                       return str(self.ctrl.GetColour().GetAsString(wx.C2S_HTML_SYNTAX))
+               else:
+                       return str(self.ctrl.GetValue())
 
        def SetValue(self, value):
                if isinstance(self.ctrl, wx.CheckBox):
                        self.ctrl.SetValue(str(value) == "True")
+               elif isinstance(self.ctrl, wx.ColourPickerCtrl):
+                       self.ctrl.SetColour(value)
                else:
                        self.ctrl.SetValue(value)
 
index 10c946a5c7b773c1ce56292c1c4aa727a68bc90b..7c7819608c8a24ea2246676e3242e7c05189d215 100644 (file)
@@ -15,6 +15,7 @@ class preferencesDialog(configBase.configWindowBase):
                \r
                wx.EVT_CLOSE(self, self.OnClose)\r
                \r
+               self.parent = parent\r
                self.oldExtruderAmount = int(profile.getPreference('extruder_amount'))\r
                \r
                left, right, main = self.CreateConfigPanel(self)\r
@@ -36,6 +37,9 @@ class preferencesDialog(configBase.configWindowBase):
                        c = configBase.SettingRow(left, 'Offset Y', 'extruder_offset_y%d' % (i), '0.0', 'The offset of your secondary extruder compared to the primary.', type = 'preference')\r
                        validators.validFloat(c)\r
 \r
+               configBase.TitleRow(left, 'Colours')\r
+               c = configBase.SettingRow(left, 'Model colour', 'model_colour', wx.Colour(0,0,0), '', type = 'preference')\r
+\r
                configBase.TitleRow(right, 'Filament settings')\r
                c = configBase.SettingRow(right, 'Filament density (kg/m3)', 'filament_density', '1300', 'Weight of the filament per m3. Around 1300 for PLA. And around 1040 for ABS. This value is used to estimate the weight if the filament used for the print.', type = 'preference')\r
                validators.validFloat(c, 500.0, 3000.0)\r
@@ -59,8 +63,8 @@ class preferencesDialog(configBase.configWindowBase):
                        c = configBase.SettingRow(right, 'SD card path', 'sdpath', '', 'Location of your SD card, when using the copy to SD feature.', type = 'preference')\r
                c = configBase.SettingRow(right, 'Copy to SD with 8.3 names', 'sdshortnames', False, 'Save the gcode files in short filenames, so they are properly shown on the UltiController', type = 'preference')\r
 \r
-               self.okButton = wx.Button(left, -1, 'Ok')\r
-               left.GetSizer().Add(self.okButton, (left.GetSizer().GetRows(), 1))\r
+               self.okButton = wx.Button(right, -1, 'Ok')\r
+               right.GetSizer().Add(self.okButton, (right.GetSizer().GetRows(), 0))\r
                self.okButton.Bind(wx.EVT_BUTTON, self.OnClose)\r
                \r
                self.MakeModal(True)\r
@@ -71,6 +75,7 @@ class preferencesDialog(configBase.configWindowBase):
                if self.oldExtruderAmount != int(profile.getPreference('extruder_amount')):\r
                        wx.MessageBox('After changing the amount of extruders you need to restart Cura for full effect.', 'Extruder amount warning.', wx.OK | wx.ICON_INFORMATION)\r
                self.MakeModal(False)\r
+               self.parent.updateProfileToControls()\r
                self.Destroy()\r
 \r
 def getDrives():\r
index ef27dc04b9ab8852e609b916d9e44b5471b25c31..7baf2a6bfd21623087713cba941d2ccae0ef7be3 100644 (file)
@@ -384,6 +384,7 @@ class previewPanel(wx.Panel):
                self.swapXZ.SetValue(profile.getProfileSetting('swap_xz') == 'True')\r
                self.swapYZ.SetValue(profile.getProfileSetting('swap_yz') == 'True')\r
                self.updateModelTransform()\r
+               self.glCanvas.updateProfileToControls()\r
 \r
 class PreviewGLCanvas(glcanvas.GLCanvas):\r
        def __init__(self, parent):\r
@@ -406,7 +407,11 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
                self.gcodeDisplayListMade = None\r
                self.gcodeDisplayListCount = 0\r
                self.objColor = [[1.0, 0.8, 0.6, 1.0], [0.2, 1.0, 0.1, 1.0], [1.0, 0.2, 0.1, 1.0], [0.1, 0.2, 1.0, 1.0]]\r
+               self.objColor[0] = profile.getPreferenceColour('model_colour')\r
        \r
+       def updateProfileToControls(self):\r
+               self.objColor[0] = profile.getPreferenceColour('model_colour')\r
+\r
        def OnMouseMotion(self,e):\r
                if e.Dragging() and e.LeftIsDown():\r
                        if self.view3D:\r
index c90bdf52867f6a07df995cdf0932c83325e9990e..b7bd21c84704bc5630a60c57d5ee22d5ab8f8cac 100644 (file)
@@ -178,6 +178,8 @@ preferencesDefaultSettings = {
        'extruder_head_size_max_x': '18.0',\r
        'extruder_head_size_max_y': '35.0',\r
        'extruder_head_size_height': '80.0',\r
+       \r
+       'model_colour': '#FFCC99',\r
 }\r
 \r
 #########################################################\r
@@ -311,6 +313,10 @@ def getPreferenceFloat(name):
        except (ValueError, SyntaxError, TypeError):\r
                return 0.0\r
 \r
+def getPreferenceColour(name):\r
+       colorString = getPreference(name)\r
+       return [float(int(colorString[1:3], 16)) / 255, float(int(colorString[3:5], 16)) / 255, float(int(colorString[5:7], 16)) / 255, 1.0]\r
+\r
 def getPreference(name):\r
        if name in tempOverride:\r
                return unicode(tempOverride[name])\r