-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFakeFreeCad.py
243 lines (191 loc) · 6.64 KB
/
FakeFreeCad.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
from tkinter import *
class TKDisplay(object):
def __init__(self, width, height):
self.message = ""
self.drawObjects = []
self.root = Tk()
self.root.title("FakeFreeCad 1.0 Rob Miles")
self.xOffset = 20
self.yOffset = 20
self.width = width
self.height = height
self.canvas = Canvas(self.root, width=width, height=height)
self.canvas.grid(row=0, column=0)
self.output_Text = Text(self.root, height=5)
self.output_Text.grid(row=1, column=0, padx=5, pady=5, sticky='nsew')
output_Scrollbar = Scrollbar(self.root, command=self.output_Text.yview)
output_Scrollbar.grid(row=1, column=1, sticky='nsew')
self.output_Text['yscrollcommand'] = output_Scrollbar.set
self.root.update()
def zoomIn(self,amount):
self.canvas.scale(ALL, 0, 0, amount, amount)
def mainloop(self):
self.root.mainloop()
def addMessageLine(self, text):
text = text + "\n"
self.output_Text.insert(END,text)
self.output_Text.see(END)
def addDrawelement(self,item):
self.drawObjects.append(item)
def drawRectangle(self,x1,y1,x2,y2,fill, outline):
x1 = x1+self.xOffset
x2 = x2+self.xOffset
y1 = self.height-(y1+self.yOffset)
y2 = self.height-(y2+self.yOffset)
print("draw rectangle: ", fill)
self.canvas.create_rectangle(x1,y1,x2,y2,fill=fill, outline=outline)
def drawCircle(self,x,y,r,fill, outline):
x = x+self.xOffset
y = self.height-(y+self.yOffset)
print("draw circle: ", fill)
self.canvas.create_oval(x-r, y-r, x+r, y+r,fill=fill, outline=outline)
class Display(object):
message = ""
drawObjects = []
imageCanvas = None
@staticmethod
def addMessageLine(text):
print(text)
if Display.imageCanvas!=None:
Display.imageCanvas.addMessageLine(text)
@staticmethod
def addDrawelement(item):
if Display.imageCanvas!=None:
Display.imageCanvas.addDrawelement(item)
scalefactor = 1
@staticmethod
def setCanvas(c):
Display.imageCanvas = c
@staticmethod
def drawRectangle(x1,y1,x2,y2,fill, outline):
if Display.imageCanvas!=None:
Display.imageCanvas.drawRectangle(x1,y1,x2,y2,fill,outline)
@staticmethod
def drawCircle(x,y,r,fill, outline):
if Display.imageCanvas!=None:
Display.imageCanvas.drawCircle(x,y,r,fill,outline)
class FreeCadView(object):
@staticmethod
def viewAxometric():
Display.addMessageLine("Freecad Axiometric view selected")
class FreeCadDocument(object):
@staticmethod
def activeView():
return FreeCadView()
class Gui(object):
@staticmethod
def SendMsgToActiveView(message):
Display.addMessageLine(message)
@staticmethod
def activeDocument():
return FreeCadDocument()
class FreeCAD(object):
@staticmethod
def newDocument():
print("New Document")
return "New Document"
class Base(object):
class Vector:
x=0
y=0
z=0
def __init__(self, x,y,z):
self.x=x
self.y=y
self.z=z
class Component(object):
drawAction = "none"
componentList = []
position=Base.Vector(0,0,0)
def __init__(self, position):
self.position = position
def fuse(self, component):
selfCopy = self.copy()
fuseCopy = component.copy()
fuseCopy.drawAction="fuse"
selfCopy.componentList.append(fuseCopy)
return selfCopy
def cut(self, component):
selfCopy = self.copy()
fuseCopy = component.copy()
fuseCopy.drawAction="cut"
selfCopy.componentList.append(fuseCopy)
return selfCopy
def copy(self):
result = Component(self.position)
result.componentList = list(self.componentList)
result.drawAction = self.drawAction
return result
def translate(self,vector):
pass
def show(self):
message = "Component "+self.drawAction+" at (" + str(self.position.x) + ","+str(self.position.y)+","+str(self.position.y) + ")"
Display.addMessageLine(message)
for c in self.componentList:
c.show()
def drawColour(self):
colour = "cyan"
if self.drawAction == "fuse":
colour="blue"
else:
if self.drawAction == "cut":
colour="red"
else:
colour = "yellow"
return colour
class Box(Component):
width=0
height=0
depth=0
def __init__(self, width,height,depth,position):
super(Box,self).__init__(position)
self.width=width
self.height=height
self.depth=depth
def copy(self):
result = Box(self.width, self.height, self.depth,self.position)
result.componentList = list(self.componentList)
return result
def show(self):
message = "Box "+self.drawAction+" at (" + str(self.position.x) + ","+str(self.position.y)+","+str(self.position.y) + ") W:"+str(self.width) + " H:"+str(self.height)+" D:"+str(self.depth)
Display.addMessageLine(message)
x1=self.position.x
y1=self.position.y
x2=x1+self.width
y2=y1+self.height
colour = self.drawColour()
Display.drawRectangle(x1,y1,x2,y2,colour,colour)
for c in self.componentList:
c.show()
class Cylinder(Component):
radius=0
height=0
dir = Base.Vector(0,0,1)
def __init__(self, radius,height,position, dir=Base.Vector(0,0,1)):
super(Cylinder,self).__init__(position)
self.radius=radius
self.height=height
self.dir = dir
def copy(self):
result = Cylinder(self.radius, self.height, self.position, self.dir)
result.componentList = list(self.componentList)
return result
def show(self):
message = "Cylinder "+self.drawAction+" at (" + str(self.position.x) + ","+str(self.position.y)+","+str(self.position.y) + ")"
Display.addMessageLine(message)
colour = self.drawColour()
Display.drawCircle(self.position.x, self.position.y, self.radius, colour, colour)
for c in self.componentList:
c.show()
def rotate(self,origin, axis, amount):
pass
class Part(object):
@staticmethod
def makeBox(width, height, depth, position=Base.Vector(0,0,0)):
return Box(width,height,depth,position)
@staticmethod
def makeCylinder(radius,height,position,dir=Base.Vector(0,0,1)):
return Cylinder(radius,height,position)
@staticmethod
def show(component):
component.show()