2012-02-19 23:30:49 +00:00
from __future__ import absolute_import
import __init__
2012-02-20 17:55:54 +00:00
import wx , os
2012-02-19 23:30:49 +00:00
2012-02-20 15:44:43 +00:00
from fabmetheus_utilities import archive
from fabmetheus_utilities import settings
from skeinforge_application . skeinforge_utilities import skeinforge_profile
2012-02-19 23:30:49 +00:00
2012-02-21 14:27:03 +00:00
from newui import preview3d
from newui import sliceProgessPanel
2012-02-21 22:05:30 +00:00
from newui import alterationPanel
2012-02-21 14:27:03 +00:00
2012-02-19 23:30:49 +00:00
def main ( ) :
app = wx . App ( False )
mainWindow ( )
app . MainLoop ( )
class mainWindow ( wx . Frame ) :
" Main user interface window "
def __init__ ( self ) :
super ( mainWindow , self ) . __init__ ( None , title = ' SkeinPyPy ' )
menubar = wx . MenuBar ( )
fileMenu = wx . Menu ( )
2012-02-20 17:55:54 +00:00
fitem = fileMenu . Append ( - 1 , ' Open Profile... ' , ' Open Profile... ' )
2012-02-21 16:33:02 +00:00
self . Bind ( wx . EVT_MENU , self . OnLoadProfile , fitem )
2012-02-20 17:55:54 +00:00
fitem = fileMenu . Append ( - 1 , ' Save Profile... ' , ' Save Profile... ' )
2012-02-20 22:27:34 +00:00
self . Bind ( wx . EVT_MENU , self . OnSaveProfile , fitem )
2012-02-19 23:30:49 +00:00
fitem = fileMenu . Append ( wx . ID_EXIT , ' Quit ' , ' Quit application ' )
2012-02-20 17:55:54 +00:00
self . Bind ( wx . EVT_MENU , self . OnQuit , fitem )
2012-02-19 23:30:49 +00:00
menubar . Append ( fileMenu , ' &File ' )
2012-02-21 16:33:02 +00:00
#menubar.Append(wx.Menu(), 'Expert')
2012-02-19 23:30:49 +00:00
self . SetMenuBar ( menubar )
2012-02-21 22:05:30 +00:00
wx . ToolTip . SetDelay ( 0 )
2012-02-21 14:27:03 +00:00
self . lastPath = " "
2012-02-20 22:27:34 +00:00
self . filename = None
2012-02-21 15:37:31 +00:00
self . progressPanelList = [ ]
2012-02-20 22:27:34 +00:00
self . controlList = [ ]
self . plugins = { }
2012-02-20 15:44:43 +00:00
for m in skeinforge_profile . getCraftTypePluginModule ( ) . getCraftSequence ( ) :
2012-02-20 22:27:34 +00:00
self . plugins [ m ] = archive . getModuleWithDirectoryPath ( archive . getCraftPluginsDirectoryPath ( ) , m ) . getNewRepository ( )
settings . getReadRepository ( self . plugins [ m ] )
2012-02-20 15:44:43 +00:00
2012-02-23 11:04:23 +00:00
skeinPyPySettingInfo = settings . getSkeinPyPyProfileInformation ( )
2012-02-20 22:27:34 +00:00
for pluginName in self . plugins . keys ( ) :
self . plugins [ pluginName ] . preferencesDict = { }
for pref in self . plugins [ pluginName ] . preferences :
if skeinPyPySettingInfo [ pluginName ] [ settings . safeConfigName ( pref . name ) ] == ' save ' :
self . plugins [ pluginName ] . preferencesDict [ settings . safeConfigName ( pref . name ) ] = pref
2012-02-23 17:15:29 +00:00
p = self #wx.Panel(self)
nb = wx . Notebook ( p )
2012-02-19 23:30:49 +00:00
2012-02-20 22:27:34 +00:00
configPanel = wx . Panel ( nb ) ;
2012-02-21 16:59:44 +00:00
nb . AddPage ( configPanel , " Print config " )
2012-02-23 17:15:29 +00:00
leftConfigPanel = wx . Panel ( configPanel )
rightConfigPanel = wx . Panel ( configPanel )
2012-02-20 22:27:34 +00:00
sizer = wx . GridBagSizer ( 2 , 2 )
2012-02-23 17:15:29 +00:00
leftConfigPanel . SetSizer ( sizer )
sizer = wx . GridBagSizer ( 2 , 2 )
rightConfigPanel . SetSizer ( sizer )
sizer = wx . BoxSizer ( wx . HORIZONTAL )
2012-02-20 22:27:34 +00:00
configPanel . SetSizer ( sizer )
2012-02-23 17:15:29 +00:00
sizer . Add ( leftConfigPanel )
sizer . Add ( rightConfigPanel )
2012-02-20 22:27:34 +00:00
2012-02-23 17:15:29 +00:00
self . AddTitle ( leftConfigPanel , " Accuracy " )
self . AddSetting ( leftConfigPanel , " Layer height (mm) " , self . plugins [ ' carve ' ] . preferencesDict [ ' Layer_Height_mm ' ] , ' Layer height in millimeters. \n 0.2 is a good value for quick prints. \n 0.1 gives high quality prints. ' )
self . AddTitle ( leftConfigPanel , " Fill " )
self . AddSetting ( leftConfigPanel , " Solid layers " , self . plugins [ ' fill ' ] . preferencesDict [ ' Solid_Surface_Thickness_layers ' ] )
self . AddSetting ( leftConfigPanel , " Fill Density " , self . plugins [ ' fill ' ] . preferencesDict [ ' Infill_Solidity_ratio ' ] )
self . AddTitle ( leftConfigPanel , " Skirt " )
self . AddSetting ( leftConfigPanel , " Line count " , self . plugins [ ' skirt ' ] . preferencesDict [ ' Skirt_line_count ' ] )
self . AddSetting ( leftConfigPanel , " Start distance (mm) " , self . plugins [ ' skirt ' ] . preferencesDict [ ' Gap_Width_mm ' ] )
self . AddTitle ( leftConfigPanel , " Cool " )
2012-02-23 11:04:23 +00:00
#self.AddSetting(configPanel, "Cool type", self.plugins['cool'].preferencesDict['Cool_Type'])
2012-02-23 17:15:29 +00:00
self . AddSetting ( leftConfigPanel , " Minimal layer time " , self . plugins [ ' cool ' ] . preferencesDict [ ' Minimum_Layer_Time_seconds ' ] )
self . AddTitle ( rightConfigPanel , " Retraction " )
self . AddSetting ( rightConfigPanel , " Speed (mm/s) " , self . plugins [ ' dimension ' ] . preferencesDict [ ' Extruder_Retraction_Speed_mm/s ' ] )
self . AddSetting ( rightConfigPanel , " Distance (mm) " , self . plugins [ ' dimension ' ] . preferencesDict [ ' Retraction_Distance_millimeters ' ] )
self . AddSetting ( rightConfigPanel , " Extra length on start (mm) " , self . plugins [ ' dimension ' ] . preferencesDict [ ' Restart_Extra_Distance_millimeters ' ] )
self . AddSetting ( rightConfigPanel , " Minimal travel (mm) " , self . plugins [ ' dimension ' ] . preferencesDict [ ' Minimum_Travel_for_Retraction_millimeters ' ] )
2012-02-20 22:27:34 +00:00
configPanel = wx . Panel ( nb ) ;
2012-02-22 19:44:00 +00:00
nb . AddPage ( configPanel , " Machine && Filament " )
2012-02-23 17:15:29 +00:00
leftConfigPanel = wx . Panel ( configPanel )
rightConfigPanel = wx . Panel ( configPanel )
sizer = wx . GridBagSizer ( 2 , 2 )
leftConfigPanel . SetSizer ( sizer )
2012-02-20 15:44:43 +00:00
sizer = wx . GridBagSizer ( 2 , 2 )
2012-02-23 17:15:29 +00:00
rightConfigPanel . SetSizer ( sizer )
sizer = wx . BoxSizer ( wx . HORIZONTAL )
2012-02-20 22:27:34 +00:00
configPanel . SetSizer ( sizer )
2012-02-23 17:15:29 +00:00
sizer . Add ( leftConfigPanel )
sizer . Add ( rightConfigPanel )
2012-02-20 17:55:54 +00:00
2012-02-23 17:15:29 +00:00
self . AddTitle ( leftConfigPanel , " Machine size " )
self . AddSetting ( leftConfigPanel , " Width (mm) " , settings . IntSpin ( ) . getFromValue ( 10 , " machine_width " , None , 1000 , 205 ) )
self . AddSetting ( leftConfigPanel , " Depth (mm) " , settings . IntSpin ( ) . getFromValue ( 10 , " machine_depth " , None , 1000 , 205 ) )
self . AddSetting ( leftConfigPanel , " Height (mm) " , settings . IntSpin ( ) . getFromValue ( 10 , " machine_height " , None , 1000 , 200 ) )
self . AddTitle ( leftConfigPanel , " Machine nozzle " )
self . AddSetting ( leftConfigPanel , " Nozzle size (mm) " , self . plugins [ ' carve ' ] . preferencesDict [ ' Edge_Width_mm ' ] )
self . AddTitle ( leftConfigPanel , " Speed " )
self . AddSetting ( leftConfigPanel , " Print speed (mm/s) " , self . plugins [ ' speed ' ] . preferencesDict [ ' Feed_Rate_mm/s ' ] )
self . AddSetting ( leftConfigPanel , " Travel speed (mm/s) " , self . plugins [ ' speed ' ] . preferencesDict [ ' Travel_Feed_Rate_mm/s ' ] )
self . AddSetting ( leftConfigPanel , " Max Z speed (mm/z) " , self . plugins [ ' speed ' ] . preferencesDict [ ' Maximum_Z_Feed_Rate_mm/s ' ] )
self . AddSetting ( leftConfigPanel , " Bottom Layer Speed Ratio " , self . plugins [ ' speed ' ] . preferencesDict [ ' Object_First_Layer_Feed_Rate_Infill_Multiplier_ratio ' ] )
self . AddTitle ( rightConfigPanel , " Filament " )
self . AddSetting ( rightConfigPanel , " Diameter (mm) " , self . plugins [ ' dimension ' ] . preferencesDict [ ' Filament_Diameter_mm ' ] )
self . AddSetting ( rightConfigPanel , " Packing Density " , self . plugins [ ' dimension ' ] . preferencesDict [ ' Filament_Packing_Density_ratio ' ] )
2012-02-20 15:44:43 +00:00
2012-02-21 22:05:30 +00:00
nb . AddPage ( alterationPanel . alterationPanel ( nb ) , " Start/End-GCode " )
2012-02-19 23:30:49 +00:00
2012-02-20 17:55:54 +00:00
#Preview window, load and slice buttons.
2012-02-23 13:08:34 +00:00
self . preview3d = preview3d . previewPanel ( p )
2012-02-19 23:30:49 +00:00
2012-02-20 22:27:34 +00:00
loadButton = wx . Button ( p , - 1 , ' Load STL ' )
sliceButton = wx . Button ( p , - 1 , ' Slice to GCode ' )
2012-02-20 17:55:54 +00:00
self . Bind ( wx . EVT_BUTTON , self . OnLoadSTL , loadButton )
2012-02-20 22:27:34 +00:00
self . Bind ( wx . EVT_BUTTON , self . OnSlice , sliceButton )
2012-02-21 22:05:30 +00:00
2012-02-19 23:30:49 +00:00
sizer = wx . GridBagSizer ( )
2012-02-23 17:15:29 +00:00
p . SetSizer ( sizer )
sizer . Add ( nb , ( 0 , 0 ) , span = ( 1 , 1 ) , flag = wx . EXPAND )
2012-02-20 22:27:34 +00:00
sizer . Add ( self . preview3d , ( 0 , 1 ) , span = ( 1 , 3 ) , flag = wx . EXPAND )
sizer . AddGrowableCol ( 2 )
2012-02-19 23:30:49 +00:00
sizer . AddGrowableRow ( 0 )
2012-02-23 17:15:29 +00:00
sizer . Add ( loadButton , ( 1 , 1 ) )
sizer . Add ( sliceButton , ( 1 , 2 ) )
2012-02-21 14:27:03 +00:00
self . panel = p
self . sizer = sizer
2012-02-23 17:15:29 +00:00
self . Fit ( )
2012-02-19 23:30:49 +00:00
self . Centre ( )
self . Show ( True )
2012-02-20 22:27:34 +00:00
def AddTitle ( self , panel , name ) :
2012-02-21 16:59:44 +00:00
" Add a title row to the configuration panel "
2012-02-20 22:27:34 +00:00
sizer = panel . GetSizer ( )
title = wx . StaticText ( panel , - 1 , name )
title . SetFont ( wx . Font ( 8 , wx . FONTFAMILY_DEFAULT , wx . NORMAL , wx . FONTWEIGHT_BOLD ) )
2012-02-23 17:15:29 +00:00
sizer . Add ( title , ( sizer . GetRows ( ) , sizer . GetCols ( ) ) , ( 1 , 3 ) , flag = wx . EXPAND )
sizer . Add ( wx . StaticLine ( panel ) , ( sizer . GetRows ( ) + 1 , sizer . GetCols ( ) ) , ( 1 , 3 ) , flag = wx . EXPAND )
2012-02-20 22:27:34 +00:00
sizer . SetRows ( sizer . GetRows ( ) + 2 )
2012-02-20 15:44:43 +00:00
2012-02-22 19:44:00 +00:00
def AddSetting ( self , panel , name , setting , help = ' Help: TODO ' ) :
2012-02-21 16:59:44 +00:00
" Add a setting to the configuration panel "
2012-02-20 15:44:43 +00:00
sizer = panel . GetSizer ( )
2012-02-23 17:15:29 +00:00
sizer . Add ( wx . StaticText ( panel , - 1 , name ) , ( sizer . GetRows ( ) , sizer . GetCols ( ) ) , flag = wx . ALIGN_CENTER_VERTICAL )
2012-02-20 22:27:34 +00:00
ctrl = None
if setting . __class__ is settings . FloatSpin :
ctrl = wx . TextCtrl ( panel , - 1 , str ( setting . value ) )
if setting . __class__ is settings . IntSpin :
ctrl = wx . TextCtrl ( panel , - 1 , str ( setting . value ) )
if setting . __class__ is settings . BooleanSetting :
ctrl = wx . CheckBox ( panel , - 1 , ' ' )
ctrl . SetValue ( setting . value )
if ctrl == None :
print " No WX control for: " + str ( setting ) , str ( setting . __class__ )
else :
ctrl . setting = setting
self . controlList . append ( ctrl )
2012-02-23 17:15:29 +00:00
sizer . Add ( ctrl , ( sizer . GetRows ( ) , sizer . GetCols ( ) + 1 ) , flag = wx . ALIGN_BOTTOM | wx . EXPAND )
2012-02-21 16:33:02 +00:00
helpButton = wx . Button ( panel , - 1 , " ? " , style = wx . BU_EXACTFIT )
2012-02-23 17:15:29 +00:00
sizer . Add ( helpButton , ( sizer . GetRows ( ) , sizer . GetCols ( ) + 2 ) )
2012-02-21 22:05:30 +00:00
helpButton . SetToolTip ( wx . ToolTip ( help ) )
2012-02-20 15:44:43 +00:00
sizer . SetRows ( sizer . GetRows ( ) + 1 )
2012-02-20 23:54:04 +00:00
return ctrl
2012-02-21 16:33:02 +00:00
def OnLoadProfile ( self , e ) :
dlg = wx . FileDialog ( self , " Select profile file to load " , self . lastPath , style = wx . FD_OPEN | wx . FD_FILE_MUST_EXIST )
dlg . SetWildcard ( " ini files (*.ini)|*.ini " )
if dlg . ShowModal ( ) == wx . ID_OK :
profileFile = dlg . GetPath ( )
self . lastPath = os . path . split ( profileFile ) [ 0 ]
2012-02-23 11:04:23 +00:00
settings . loadGlobalProfile ( profileFile )
self . updateProfileToControls ( )
2012-02-21 16:33:02 +00:00
dlg . Destroy ( )
2012-02-20 15:44:43 +00:00
2012-02-20 22:27:34 +00:00
def OnSaveProfile ( self , e ) :
2012-02-21 14:27:03 +00:00
dlg = wx . FileDialog ( self , " Select profile file to save " , self . lastPath , style = wx . FD_SAVE )
2012-02-20 22:27:34 +00:00
dlg . SetWildcard ( " ini files (*.ini)|*.ini " )
if dlg . ShowModal ( ) == wx . ID_OK :
profileFile = dlg . GetPath ( )
2012-02-21 14:27:03 +00:00
self . lastPath = os . path . split ( profileFile ) [ 0 ]
2012-02-23 11:04:23 +00:00
settings . saveGlobalProfile ( profileFile )
self . updateProfileFromControls ( )
2012-02-21 14:27:03 +00:00
dlg . Destroy ( )
2012-02-20 22:27:34 +00:00
2012-02-20 17:55:54 +00:00
def OnLoadSTL ( self , e ) :
2012-02-21 14:27:03 +00:00
dlg = wx . FileDialog ( self , " Open file to print " , self . lastPath , style = wx . FD_OPEN | wx . FD_FILE_MUST_EXIST )
dlg . SetWildcard ( " OBJ, STL files (*.stl;*.obj)|*.stl;*.obj " )
2012-02-20 17:55:54 +00:00
if dlg . ShowModal ( ) == wx . ID_OK :
self . filename = dlg . GetPath ( )
if not ( os . path . exists ( self . filename ) ) :
return
2012-02-21 14:27:03 +00:00
self . lastPath = os . path . split ( self . filename ) [ 0 ]
2012-02-21 22:05:30 +00:00
self . preview3d . loadModelFile ( self . filename )
2012-02-21 14:27:03 +00:00
dlg . Destroy ( )
2012-02-20 17:55:54 +00:00
2012-02-20 22:27:34 +00:00
def OnSlice ( self , e ) :
if self . filename == None :
return
2012-02-23 11:04:23 +00:00
self . updateProfileFromControls ( )
2012-02-21 22:05:30 +00:00
2012-02-21 16:59:44 +00:00
#Create a progress panel and add it to the window. The progress panel will start the Skein operation.
2012-02-21 15:37:31 +00:00
spp = sliceProgessPanel . sliceProgessPanel ( self , self . panel , self . filename )
self . sizer . Add ( spp , ( len ( self . progressPanelList ) + 2 , 0 ) , span = ( 1 , 4 ) , flag = wx . EXPAND )
2012-02-21 14:27:03 +00:00
self . sizer . Layout ( )
2012-02-21 15:37:31 +00:00
newSize = self . GetSize ( ) ;
newSize . IncBy ( 0 , spp . GetSize ( ) . GetHeight ( ) )
self . SetSize ( newSize )
self . progressPanelList . append ( spp )
def removeSliceProgress ( self , spp ) :
self . progressPanelList . remove ( spp )
newSize = self . GetSize ( ) ;
newSize . IncBy ( 0 , - spp . GetSize ( ) . GetHeight ( ) )
self . SetSize ( newSize )
spp . Destroy ( )
for spp in self . progressPanelList :
self . sizer . Remove ( spp )
i = 2
for spp in self . progressPanelList :
self . sizer . Add ( spp , ( i , 0 ) , span = ( 1 , 4 ) , flag = wx . EXPAND )
i + = 1
2012-02-21 22:05:30 +00:00
self . sizer . Layout ( )
2012-02-20 22:27:34 +00:00
2012-02-23 11:04:23 +00:00
def updateProfileToControls ( self ) :
2012-02-21 16:59:44 +00:00
" Update the configuration wx controls to show the new configuration settings "
2012-02-21 16:33:02 +00:00
for pluginName in self . plugins . keys ( ) :
settings . getReadRepository ( self . plugins [ pluginName ] )
2012-02-23 11:04:23 +00:00
settings . saveGlobalProfile ( settings . getDefaultProfilePath ( ) )
2012-02-21 16:33:02 +00:00
for ctrl in self . controlList :
if ctrl . setting . __class__ is settings . BooleanSetting :
ctrl . SetValue ( ctrl . setting . value )
else :
ctrl . SetValue ( str ( ctrl . setting . value ) )
2012-02-21 15:37:31 +00:00
2012-02-23 11:04:23 +00:00
def updateProfileFromControls ( self ) :
2012-02-21 16:59:44 +00:00
" Update the configuration settings with values from the wx controls "
2012-02-20 22:27:34 +00:00
for ctrl in self . controlList :
ctrl . setting . setValueToString ( ctrl . GetValue ( ) )
for pluginName in self . plugins . keys ( ) :
settings . storeRepository ( self . plugins [ pluginName ] )
2012-02-23 11:04:23 +00:00
settings . saveGlobalProfile ( settings . getDefaultProfilePath ( ) )
2012-02-20 22:27:34 +00:00
2012-02-19 23:30:49 +00:00
def OnQuit ( self , e ) :
self . Close ( )