Make 3D model colour configurable.

This commit is contained in:
daid 2012-07-30 12:26:30 +02:00
parent 05d3c36c61
commit 50ff10bd6d
4 changed files with 32 additions and 4 deletions

View File

@ -102,6 +102,7 @@ class SettingRow():
sizer = panel.GetSizer() sizer = panel.GetSizer()
x = sizer.GetRows() x = sizer.GetRows()
y = 0 y = 0
flag = 0
self.validators = [] self.validators = []
self.validationMsg = '' self.validationMsg = ''
@ -120,16 +121,22 @@ class SettingRow():
if isinstance(defaultValue, types.StringTypes): if isinstance(defaultValue, types.StringTypes):
self.ctrl = wx.TextCtrl(panel, -1, getSettingFunc(configName)) self.ctrl = wx.TextCtrl(panel, -1, getSettingFunc(configName))
self.ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange) self.ctrl.Bind(wx.EVT_TEXT, self.OnSettingChange)
flag = wx.EXPAND
elif isinstance(defaultValue, types.BooleanType): elif isinstance(defaultValue, types.BooleanType):
self.ctrl = wx.CheckBox(panel, -1, style=wx.ALIGN_RIGHT) self.ctrl = wx.CheckBox(panel, -1, style=wx.ALIGN_RIGHT)
self.SetValue(getSettingFunc(configName)) self.SetValue(getSettingFunc(configName))
self.ctrl.Bind(wx.EVT_CHECKBOX, self.OnSettingChange) 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: else:
self.ctrl = wx.ComboBox(panel, -1, getSettingFunc(configName), choices=defaultValue, style=wx.CB_DROPDOWN|wx.CB_READONLY) 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) 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.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) sizer.SetRows(x+1)
self.ctrl.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter) self.ctrl.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
@ -172,11 +179,16 @@ class SettingRow():
self.panel.main.UpdatePopup(self) self.panel.main.UpdatePopup(self)
def GetValue(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): def SetValue(self, value):
if isinstance(self.ctrl, wx.CheckBox): if isinstance(self.ctrl, wx.CheckBox):
self.ctrl.SetValue(str(value) == "True") self.ctrl.SetValue(str(value) == "True")
elif isinstance(self.ctrl, wx.ColourPickerCtrl):
self.ctrl.SetColour(value)
else: else:
self.ctrl.SetValue(value) self.ctrl.SetValue(value)

View File

@ -15,6 +15,7 @@ class preferencesDialog(configBase.configWindowBase):
wx.EVT_CLOSE(self, self.OnClose) wx.EVT_CLOSE(self, self.OnClose)
self.parent = parent
self.oldExtruderAmount = int(profile.getPreference('extruder_amount')) self.oldExtruderAmount = int(profile.getPreference('extruder_amount'))
left, right, main = self.CreateConfigPanel(self) left, right, main = self.CreateConfigPanel(self)
@ -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') 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')
validators.validFloat(c) validators.validFloat(c)
configBase.TitleRow(left, 'Colours')
c = configBase.SettingRow(left, 'Model colour', 'model_colour', wx.Colour(0,0,0), '', type = 'preference')
configBase.TitleRow(right, 'Filament settings') configBase.TitleRow(right, 'Filament settings')
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') 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')
validators.validFloat(c, 500.0, 3000.0) validators.validFloat(c, 500.0, 3000.0)
@ -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') c = configBase.SettingRow(right, 'SD card path', 'sdpath', '', 'Location of your SD card, when using the copy to SD feature.', type = 'preference')
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') 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')
self.okButton = wx.Button(left, -1, 'Ok') self.okButton = wx.Button(right, -1, 'Ok')
left.GetSizer().Add(self.okButton, (left.GetSizer().GetRows(), 1)) right.GetSizer().Add(self.okButton, (right.GetSizer().GetRows(), 0))
self.okButton.Bind(wx.EVT_BUTTON, self.OnClose) self.okButton.Bind(wx.EVT_BUTTON, self.OnClose)
self.MakeModal(True) self.MakeModal(True)
@ -71,6 +75,7 @@ class preferencesDialog(configBase.configWindowBase):
if self.oldExtruderAmount != int(profile.getPreference('extruder_amount')): if self.oldExtruderAmount != int(profile.getPreference('extruder_amount')):
wx.MessageBox('After changing the amount of extruders you need to restart Cura for full effect.', 'Extruder amount warning.', wx.OK | wx.ICON_INFORMATION) wx.MessageBox('After changing the amount of extruders you need to restart Cura for full effect.', 'Extruder amount warning.', wx.OK | wx.ICON_INFORMATION)
self.MakeModal(False) self.MakeModal(False)
self.parent.updateProfileToControls()
self.Destroy() self.Destroy()
def getDrives(): def getDrives():

View File

@ -384,6 +384,7 @@ class previewPanel(wx.Panel):
self.swapXZ.SetValue(profile.getProfileSetting('swap_xz') == 'True') self.swapXZ.SetValue(profile.getProfileSetting('swap_xz') == 'True')
self.swapYZ.SetValue(profile.getProfileSetting('swap_yz') == 'True') self.swapYZ.SetValue(profile.getProfileSetting('swap_yz') == 'True')
self.updateModelTransform() self.updateModelTransform()
self.glCanvas.updateProfileToControls()
class PreviewGLCanvas(glcanvas.GLCanvas): class PreviewGLCanvas(glcanvas.GLCanvas):
def __init__(self, parent): def __init__(self, parent):
@ -406,6 +407,10 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
self.gcodeDisplayListMade = None self.gcodeDisplayListMade = None
self.gcodeDisplayListCount = 0 self.gcodeDisplayListCount = 0
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]] 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]]
self.objColor[0] = profile.getPreferenceColour('model_colour')
def updateProfileToControls(self):
self.objColor[0] = profile.getPreferenceColour('model_colour')
def OnMouseMotion(self,e): def OnMouseMotion(self,e):
if e.Dragging() and e.LeftIsDown(): if e.Dragging() and e.LeftIsDown():

View File

@ -178,6 +178,8 @@ preferencesDefaultSettings = {
'extruder_head_size_max_x': '18.0', 'extruder_head_size_max_x': '18.0',
'extruder_head_size_max_y': '35.0', 'extruder_head_size_max_y': '35.0',
'extruder_head_size_height': '80.0', 'extruder_head_size_height': '80.0',
'model_colour': '#FFCC99',
} }
######################################################### #########################################################
@ -311,6 +313,10 @@ def getPreferenceFloat(name):
except (ValueError, SyntaxError, TypeError): except (ValueError, SyntaxError, TypeError):
return 0.0 return 0.0
def getPreferenceColour(name):
colorString = getPreference(name)
return [float(int(colorString[1:3], 16)) / 255, float(int(colorString[3:5], 16)) / 255, float(int(colorString[5:7], 16)) / 255, 1.0]
def getPreference(name): def getPreference(name):
if name in tempOverride: if name in tempOverride:
return unicode(tempOverride[name]) return unicode(tempOverride[name])