Make 3D model colour configurable.

master
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()
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)

View File

@ -15,6 +15,7 @@ class preferencesDialog(configBase.configWindowBase):
wx.EVT_CLOSE(self, self.OnClose)
self.parent = parent
self.oldExtruderAmount = int(profile.getPreference('extruder_amount'))
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')
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')
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)
@ -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, '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')
left.GetSizer().Add(self.okButton, (left.GetSizer().GetRows(), 1))
self.okButton = wx.Button(right, -1, 'Ok')
right.GetSizer().Add(self.okButton, (right.GetSizer().GetRows(), 0))
self.okButton.Bind(wx.EVT_BUTTON, self.OnClose)
self.MakeModal(True)
@ -71,6 +75,7 @@ class preferencesDialog(configBase.configWindowBase):
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)
self.MakeModal(False)
self.parent.updateProfileToControls()
self.Destroy()
def getDrives():

View File

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

View File

@ -178,6 +178,8 @@ preferencesDefaultSettings = {
'extruder_head_size_max_x': '18.0',
'extruder_head_size_max_y': '35.0',
'extruder_head_size_height': '80.0',
'model_colour': '#FFCC99',
}
#########################################################
@ -311,6 +313,10 @@ def getPreferenceFloat(name):
except (ValueError, SyntaxError, TypeError):
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):
if name in tempOverride:
return unicode(tempOverride[name])