2012-02-24 16:07:03 +00:00
from __future__ import absolute_import
import __init__
2012-02-24 18:19:00 +00:00
from fabmetheus_utilities import settings
2012-02-24 16:07:03 +00:00
SUCCESS = 0
WARNING = 1
ERROR = 2
class validFloat ( ) :
2012-02-24 18:19:00 +00:00
def __init__ ( self , setting , minValue = None , maxValue = None ) :
self . setting = setting
self . setting . validators . append ( self )
2012-02-24 16:07:03 +00:00
self . minValue = minValue
self . maxValue = maxValue
def validate ( self ) :
try :
2012-02-24 18:19:00 +00:00
f = float ( self . setting . GetValue ( ) )
2012-02-24 16:07:03 +00:00
if self . minValue != None and f < self . minValue :
2012-02-27 13:51:52 +00:00
return ERROR , ' This setting should not be below ' + str ( self . minValue )
2012-02-24 16:07:03 +00:00
if self . maxValue != None and f > self . maxValue :
2012-02-27 13:51:52 +00:00
return ERROR , ' This setting should not be above ' + str ( self . maxValue )
2012-02-24 16:07:03 +00:00
return SUCCESS , ' '
except ValueError :
2012-02-27 13:51:52 +00:00
return ERROR , ' " ' + str ( self . setting . GetValue ( ) ) + ' " is not a valid number '
2012-02-24 16:07:03 +00:00
class validInt ( ) :
2012-02-24 18:19:00 +00:00
def __init__ ( self , setting , minValue = None , maxValue = None ) :
self . setting = setting
self . setting . validators . append ( self )
2012-02-24 16:07:03 +00:00
self . minValue = minValue
self . maxValue = maxValue
def validate ( self ) :
try :
2012-02-24 18:19:00 +00:00
f = int ( self . setting . GetValue ( ) )
2012-02-24 16:07:03 +00:00
if self . minValue != None and f < self . minValue :
2012-02-27 13:51:52 +00:00
return ERROR , ' This setting should not be below ' + str ( self . minValue )
2012-02-24 16:07:03 +00:00
if self . maxValue != None and f > self . maxValue :
2012-02-27 13:51:52 +00:00
return ERROR , ' This setting should not be above ' + str ( self . maxValue )
2012-02-24 16:07:03 +00:00
return SUCCESS , ' '
except ValueError :
2012-02-27 13:51:52 +00:00
return ERROR , ' " ' + str ( self . setting . GetValue ( ) ) + ' " is not a valid whole number '
2012-02-24 18:19:00 +00:00
class warningAbove ( ) :
def __init__ ( self , setting , minValueForWarning , warningMessage ) :
self . setting = setting
self . setting . validators . append ( self )
self . minValueForWarning = minValueForWarning
self . warningMessage = warningMessage
def validate ( self ) :
try :
f = float ( self . setting . GetValue ( ) )
if f > = self . minValueForWarning :
return WARNING , self . warningMessage
return SUCCESS , ' '
except ValueError :
#We already have an error by the int/float validator in this case.
return SUCCESS , ' '
class wallThicknessValidator ( ) :
def __init__ ( self , setting ) :
self . setting = setting
self . setting . validators . append ( self )
def validate ( self ) :
try :
wallThickness = float ( self . setting . GetValue ( ) )
2012-03-05 21:30:54 +00:00
nozzleSize = float ( settings . getProfileSetting ( ' nozzle_size ' ) )
2012-02-24 18:19:00 +00:00
if wallThickness < = nozzleSize * 0.5 :
return ERROR , ' Trying to print walls thinner then the half of your nozzle size, this will not produce anything usable '
if wallThickness < = nozzleSize * 0.85 :
return WARNING , ' Trying to print walls thinner then the 0.8 * nozzle size. Small chance that this will produce usable results '
if wallThickness < nozzleSize :
return SUCCESS , ' '
lineCount = int ( wallThickness / nozzleSize )
lineWidth = wallThickness / lineCount
lineWidthAlt = wallThickness / ( lineCount + 1 )
2012-02-24 21:44:18 +00:00
if lineWidth > = nozzleSize * 1.5 and lineWidthAlt < = nozzleSize * 0.85 :
2012-02-24 18:19:00 +00:00
return WARNING , ' Current selected wall thickness results in a line thickness of ' + str ( lineWidthAlt ) + ' mm which is not recommended with your nozzle of ' + str ( nozzleSize ) + ' mm '
return SUCCESS , ' '
except ValueError :
#We already have an error by the int/float validator in this case.
return SUCCESS , ' '
2012-02-24 16:07:03 +00:00