Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
improved
  • Loading branch information
jeff-dh committed Jun 8, 2021
commit 67e83fe9a2cf5b0b45171307f736a72a7eb2e33c
4 changes: 2 additions & 2 deletions solid/greedy_scad_interface/customizer_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self, name, default_value, options='', label='', tab=''):
options_str = '[' + ", ".join(map(str, options)) + ']'

if isinstance(options, dict):
reverse_options = [ f"{options[k]} : {k}" for k in options.keys()]
reverse_options = [ f'{options[k]} : "{k}"' for k in options.keys()]
options_str = f'[{", ".join(reverse_options)}]'

super().__init__(name, default_value, options_str, label=label, tab=tab)
Expand All @@ -27,5 +27,5 @@ def __init__(self, name, default_value, label='', tab=''):
class CustomizerTextboxVariable(ScadVariable):
def __init__(self, name, default_value, max_length='', label='', tab=''):
options_str = max_length and str(max_length)
super().__init__(name, f'"{default_value}"', options_str, label=label, tab=tab)
super().__init__(name, default_value, options_str, label=label, tab=tab)

2 changes: 1 addition & 1 deletion solid/greedy_scad_interface/scad_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def set_global_viewport_distance(d):

def get_scad_header():
base_str = "\n\n".join(ScadVariable.registered_variables.values())
return f'//=== custmizer variables start ===\n{base_str}\n//=== customizer variables end===\n'
return f'{base_str}\n'

29 changes: 16 additions & 13 deletions solid/greedy_scad_interface/scad_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def __operator_base__(self, op, other):
def __unary_operator_base__(self, op):
return ScadValue(f'({op}{self})')

def __illegal_operator__(self):
raise Exception("You can't compare a ScadValue with something else, " +\
"because we don't know the customized value at " +\
"SolidPythons runtime because it might get customized " +\
"at OpenSCAD runtime.")

#basic operators +, -, *, /, %, **
def __add__(self, other): return self.__operator_base__("+", other)
def __sub__(self, other): return self.__operator_base__("-", other)
Expand All @@ -43,23 +49,20 @@ def __neg__(self): return self.__unary_operator_base__("-")
#other operators
def __abs__(self): return ScadValue(f'abs({self})')

def __bool__(self):
raise Exception("You can't use scad variables as truth statement because " +\
"we don't know the value of a customized variable at SolidPython " +\
"runtime.")

def __illegal_operator__(self):
raise Exception("You can't compare a ScadValue with something else, " +\
"because we don't know the customized value at SolidPythons runtime " +\
"because it might get customized at OpenSCAD runtime.")

#"illegal" operators
def __eq__(self, other): return self.__illegal_operator__()
def __ne__(self, other): return self.__illegal_operator__()
def __le__(self, other): return self.__illegal_operator__()
def __ge__(self, other): return self.__illegal_operator__()
def __lt__(self, other): return self.__illegal_operator__()
def __gt__(self, other): return self.__illegal_operator__()

#do not allow to evaluate to bool
def __bool__(self):
raise Exception("You can't use scad variables as truth statement because " +\
"we don't know the value of a customized variable at " +\
"SolidPython runtime.")

class ScadVariable(ScadValue):
registered_variables = {}

Expand All @@ -73,12 +76,12 @@ def __init__(self, name, default_value, options_str='', label='', tab=''):
self.registered_variables.update({name : def_str})

def get_definition(self, name, default_value, options_str, label, tab):
from ..solidpython import py2openscad

tab = tab and f'/* [{tab}] */\n'
label = label and f'//{label}\n'
options_str = options_str and f' //{options_str}'

if isinstance(default_value, str):
default_value = f'"{default_value}"'
default_value = py2openscad(default_value)

return f'{tab}{label}{name} = {default_value};{options_str}'