-
Notifications
You must be signed in to change notification settings - Fork 0
/
monkeyprintCommands.py
189 lines (158 loc) · 5.84 KB
/
monkeyprintCommands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# -*- coding: latin-1 -*-
#
# Copyright (c) 2015-2016 Paul Bomke
# Distributed under the GNU GPL v2.
#
# This file is part of monkeyprint.
#
# monkeyprint is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# monkeyprint is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You have received a copy of the GNU General Public License
# along with monkeyprint. If not, see <http://www.gnu.org/licenses/>.
import re
class command:
def __init__(self, commandType, displayName, paramName=None, param=None, string=None):
self.commandType = commandType
self.displayName = displayName
self.string = string
if self.commandType == 'monkeyprintSerial':
pass
elif self.commandType == 'gCodeSerial':
pass
elif self.commandType == 'internal':
self.fcn = fcn
self.paramName = paramName
self.param = param
class commandListAll(dict):
# Override init function.
def __init__(self):
# Call super class init function.
dict.__init__(self)
# Create commands.
# Internal.
self['prepare'] = command(commandType=internal, displayName='Prepare printer', )
self['wait'] = command(commandType=internal, displayName='Wait', paramName="Time", param=1)
self['expose']
self['loopStart']
self['loopEnd']
# G-Code board.
self['gCodeSerial'] = command(commandType=gCode)
# Monkeyprint board.
self['monkeyprintLayerUp'] = command(commandType=monkeyprint)
self['monkeyprintShutterOpen'] = command(commandType=monkeyprint)
self['monkeyprintShutterClose'] = command(commandType=monkeyprint)
self['monkeyprintTilt'] = command(commandType=monkeyprint)
self['monkeyprintHome'] = command(commandType=monkeyprint)
self['monkeyprintTop'] = command(commandType=monkeyprint)
self['monkeyprintProjectorOn'] = command(commandType=monkeyprint)
self['monkeyprintProjectorOff'] = command(commandType=monkeyprint)
class commandListPrintProcess(list):
# Override init function.
def __init__(self):
# Call super class init function.
list.__init__(self)
# Create default print process.
# if settings
# If file found, load the file.
self.loadFile
def loadFile(self):
pass
def writeFile(self):
pass
class printProcess:
pass
class commandExecutor:
def __init__():
pass
#if command.commandType == internal
class stringEvaluator:
def __init__(self, settings, modelCollection):
self.settings = settings
self.modelCollection = modelCollection
def parseCommand(self,command):
# Find stuff in curly braces.
# Add () around [...]+ to suppress the curly braces in the result.
#curlyBraceContents = re.findall(r"\{[A-Za-z\$\+\*\-\/]+\}", command)
curlyBraceContents = re.findall(r"\{[^\{^\}]+\}", command)
# Find substrings.
curlyBraceContentsEvaluated = []
for expression in curlyBraceContents:
# Strip the curly braces.
expressionContent = expression[1:-1]
# print "Found expression: " + expressionContent
# Test if there are prohibited chars inside.
# We only want letters, spaces and +-*/.
# Create a pattern that matches what we don't want.
allowedPattern = re.compile('[^A-Z^a-z^\+^\-^\*^\/^\$^ ]+')
# Findall will return a list of prohibited chars if it finds any.
prohibitedChars = allowedPattern.findall(expressionContent)
# If not...
if len(prohibitedChars) == 0:
# print " Expression valid. Processing..."
# ... do the processing.
# Replace all $-variables with the corresponding values.
#values = []
# First, find all $-variables.
variables = re.findall(r"\$[A-Za-z]+", expressionContent)
# print " Found variables: " + str(variables)
# Iterate through the $-variables...
for variable in variables:
# ... and get the corresponding value from the settings.
#values.append(self.replaceWithValue(variable))
value = self.replaceWithValue(variable[1:])
expressionContent = expressionContent.replace(variable, value)
# print " Replaced variables: " + str(expressionContent)
# Evaluate the expression.
result = "0"
try:
result = str(eval(expressionContent))
# print "Result: " + result
except SyntaxError:
print " Something went wrong while parsing G-Code variables. Replacing by \"0\""
#curlyBraceContentsEvaluated.append(result)
# Replace curly brace expression by result.
command = command.replace(expression, result)
# If we found prohibited chars...
else:
# print "Prohibited characters " + str(prohibitedChars) + " found. Check your G-Code string."
command = command.replace(expression, "0")
# print "Finished G-Code command: " + command
return command
def replaceWithValue(self, variable):
# print " Processing variable: " + variable
variableValid = True
if variable == "layerHeight":
value = str(self.modelCollection.jobSettings['layerHeight'].value)
elif variable == "buildDir":
if self.settings['Reverse build'].value:
value = "-1"
else:
value = "1"
elif variable == "tiltDist":
value = str(self.settings['Tilt distance GCode'].value)
elif variable == "tiltDir":
if self.settings['Reverse tilt'].value:
value = "-1"
else:
value = "1"
elif variable == "shutterPosOpen":
value = str(self.settings['Shutter position open GCode'].value)
elif variable == "shutterPosClosed":
value = str(self.settings['Shutter position closed GCode'].value)
else:
value = "0"
variableValid = False
if variableValid:
pass
# print " Replacing by " + value + "."
else:
print " Unknown G-Code variable found: \"" + variable + "\". Replacing by \"0\"."
return value