Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit 89cf3bd

Browse files
authored
Fixed some junk
1 parent 10e16e5 commit 89cf3bd

1 file changed

Lines changed: 48 additions & 24 deletions

File tree

Rails.py

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
Z = [1.0, 5.0, 4.0]
1414

1515
# Set up HashID
16-
HashID = "0x0"
16+
HashID = "Auto"
1717

1818
# Set up other preferences
19-
IsClosed = "false"
19+
IsClosed = "true"
2020
RailType = "Bezier"
2121
Translate = [100, 50, 25]
2222

@@ -83,6 +83,8 @@ def CoreCalculation():
8383
global FilePath
8484
global FolderPath
8585

86+
87+
8688
#Read DefaultPath and save it as FilePath
8789
FolderPath = top.PathEntry
8890
if (FolderPath == ""):
@@ -96,7 +98,7 @@ def CoreCalculation():
9698
LineList = ReadFromFile(None, False, FilePath).splitlines()
9799
HashIDReadCurrentLine = 0;
98100
for line in LineList:
99-
print("Line: " + line)
101+
#print("Line: " + line)
100102
if ("- HashId" in line):
101103
splitLine = line.split()
102104
CurrentHashID = int(splitLine[3], 0)
@@ -110,17 +112,17 @@ def CoreCalculation():
110112
LineList = ReadFromFile(None, False, FilePath).splitlines()
111113
HashIDReadCurrentLine = 0;
112114
for line in LineList:
113-
print("Line: " + line)
115+
#print("Line: " + line)
114116
if ("- HashId" in line):
115117
splitLine = line.split()
116118
CurrentHashID = int(splitLine[3], 0)
117119
if (CurrentHashID > HighestHashID):
118120
HighestHashID = CurrentHashID
119121
HashIDReadCurrentLine += 1;
120122

121-
print("HighestHashID: " + str(HighestHashID))
123+
#print("HighestHashID: " + str(HighestHashID))
122124
HashID = str(hex(HighestHashID + 1))
123-
print(HashID)
125+
#print(HashID)
124126

125127

126128
X[CurrentPoint] = float(top.XEntry.get())
@@ -134,15 +136,15 @@ def CoreCalculation():
134136
ZSum = 0
135137
# Set HashId
136138
if (top.HashIDEntry.get() != "Auto"):
137-
HashID = str(hex(top.HashIDEntry.get()))
139+
HashID = str(hex(int(top.HashIDEntry.get(), 0)))
138140
#Set IsClosed
139141
IsClosed = top.IsClosedDropdown.get()
140142
#Set RailType
141143
RailType = top.RailTypeDropdown.get()
142144
# Set NextDistanceIndex
143145
while NextDistanceIndexCounter < len(X)-1:
144146
NextDistanceIndex.append(NextDistanceIndexCounter)
145-
print(NextDistanceIndexCounter)
147+
#print(NextDistanceIndexCounter)
146148
NextDistanceIndexCounter = NextDistanceIndexCounter + 1
147149
# Calculate distance formula for NextDistance
148150
for LineNum in NextDistanceIndex:
@@ -151,7 +153,7 @@ def CoreCalculation():
151153
#Calculate midpoint for Translate
152154
while MidpointCounter < len(X)-1:
153155
MidpointCounter += 1
154-
print("MidPointCounter: " + str(MidpointCounter))
156+
#print("MidPointCounter: " + str(MidpointCounter))
155157
XSum += X[MidpointCounter]
156158
YSum += Y[MidpointCounter]
157159
ZSum += Z[MidpointCounter]
@@ -160,19 +162,31 @@ def CoreCalculation():
160162
Translate[2] = ZSum/len(Z)
161163

162164
# Create one-time initial string + first point string
163-
InitString = ("- HashId: !u " + HashID + "\n" + " IsClosed: " + str(IsClosed) + "\n" + " RailPoints:" + "\n" + " - '!Parameters': {IsAdjustPosAndDirToPoint: false, WaitASKeyName: Search, WaitFrame: 60.0}" + "\n" + " NextDistance: " + str(NextDistanceArray[0]) + "\n" + " PrevDistance: " + str(-1) + "\n" + " Translate: " + "[" + str(X[0]) + ", " + str(Y[0]) + ", " + str(Z[0]) + "]" + "\n" + " UnitConfigName: GuidePoint")
164-
PrevDistance = str(NextDistanceArray[0])
165+
FirstLastDist = math.sqrt((X[-1]-X[0])**2+(Y[-1]-Y[0])**2+(Z[-1]-Z[0])**2)
166+
if (IsClosed == "true"):
167+
print("yay")
168+
InitString = ("- HashId: !u " + HashID + "\n" + " IsClosed: " + str(IsClosed) + "\n" + " RailPoints:" + "\n" + " - '!Parameters': {IsAdjustPosAndDirToPoint: false, WaitASKeyName: Search, WaitFrame: 60.0}" + "\n" + " NextDistance: " + str(NextDistanceArray[0]) + "\n" + " PrevDistance: " + str(FirstLastDist) + "\n" + " Translate: " + "[" + str(X[0]) + ", " + str(Y[0]) + ", " + str(Z[0]) + "]" + "\n" + " UnitConfigName: GuidePoint")
169+
elif (IsClosed == "false"):
170+
InitString = ("- HashId: !u " + HashID + "\n" + " IsClosed: " + str(IsClosed) + "\n" + " RailPoints:" + "\n" + " - '!Parameters': {IsAdjustPosAndDirToPoint: false, WaitASKeyName: Search, WaitFrame: 60.0}" + "\n" + " NextDistance: " + str(NextDistanceArray[0]) + "\n" + " PrevDistance: " + str(NextDistanceArray[0]) + "\n" + " Translate: " + "[" + str(X[0]) + ", " + str(Y[0]) + ", " + str(Z[0]) + "]" + "\n" + " UnitConfigName: GuidePoint")
171+
else:
172+
print("Please specify IsClosed!")
173+
return
165174

166175
# Create repeatable main body string
167176
BodyString = ""
177+
PrevDistance = str(NextDistanceArray[0])
168178
for PointNum in range(1, len(X)-1):
169179
BodyString = (BodyString + "\n" + " - '!Parameters': {IsAdjustPosAndDirToPoint: false, WaitFrame: 0.0}" + "\n" + " NextDistance: " + str(NextDistanceArray[PointNum]) + "\n" + " PrevDistance: " + str(PrevDistance) + "\n" + " Translate: " + "[" + str(X[PointNum]) + ", " + str(Y[PointNum]) + ", " + str(Z[PointNum]) + "]" + "\n" + " UnitConfigName: GuidePoint")
170180
PrevDistance = NextDistanceArray[PointNum]
171181
# Create One-time end string + end point string
172-
EndString = ("\n" + " - '!Parameters': {IsAdjustPosAndDirToPoint: false, WaitASKeyName: Search, WaitFrame: 60.0}" + "\n" + " NextDistance: " + str(-1) + "\n" + " PrevDistance: " + str(PrevDistance) + "\n" + " Translate: " + "[" + str(X[-1]) + ", " + str(Y[-1]) + ", " + str(Z[-1]) + "]" + "\n" + " UnitConfigName: GuidePoint" + "\n" + " RailType: " + RailType + "\n" + " Translate: " + str(Translate) + "\n" + " UnitConfigName: Guide")
182+
if (IsClosed == "true"):
183+
print("yay2")
184+
EndString = ("\n" + " - '!Parameters': {IsAdjustPosAndDirToPoint: false, WaitASKeyName: Search, WaitFrame: 60.0}" + "\n" + " NextDistance: " + str(FirstLastDist) + "\n" + " PrevDistance: " + str(PrevDistance) + "\n" + " Translate: " + "[" + str(X[-1]) + ", " + str(Y[-1]) + ", " + str(Z[-1]) + "]" + "\n" + " UnitConfigName: GuidePoint" + "\n" + " RailType: " + RailType + "\n" + " Translate: " + str(Translate) + "\n" + " UnitConfigName: Guide")
185+
elif (IsClosed == "false"):
186+
EndString = ("\n" + " - '!Parameters': {IsAdjustPosAndDirToPoint: false, WaitASKeyName: Search, WaitFrame: 60.0}" + "\n" + " NextDistance: " + str(PrevDistance) + "\n" + " PrevDistance: " + str(PrevDistance) + "\n" + " Translate: " + "[" + str(X[-1]) + ", " + str(Y[-1]) + ", " + str(Z[-1]) + "]" + "\n" + " UnitConfigName: GuidePoint" + "\n" + " RailType: " + RailType + "\n" + " Translate: " + str(Translate) + "\n" + " UnitConfigName: Guide")
173187
FinalString = (InitString + BodyString + EndString)
174188
clipboard.copy(FinalString)
175-
print(FinalString)
189+
#print(FinalString)
176190
ReadFromFile(FinalString, True, FilePath)
177191

178192

@@ -234,20 +248,24 @@ def NextPoint():
234248
global WindowX
235249
global WindowY
236250
global HashID
251+
global IsClosed
252+
global RailType
237253
# This isn't needed for some reason.
238254
global root
239255

240-
print(CurrentPoint + 1)
256+
#print(CurrentPoint + 1)
241257
X[CurrentPoint] = float(top.XEntry.get())
242258
Y[CurrentPoint] = float(top.YEntry.get())
243259
Z[CurrentPoint] = float(top.ZEntry.get())
244-
print(X)
245-
print(Y)
246-
print(Z)
260+
IsClosed = top.IsClosedDropdown.get()
261+
RailType = top.RailTypeDropdown.get()
262+
#print(X)
263+
#print(Y)
264+
#print(Z)
247265
if (CurrentPoint < len(X)-1):
248266
CurrentPoint = CurrentPoint + 1
249267
if (top.HashIDEntry.get() != "Auto"):
250-
HashID = str(hex(top.HashIDEntry.get()))
268+
HashID = str(hex(int(top.HashIDEntry.get(), 0)))
251269
WindowX = root.winfo_x()
252270
WindowY = root.winfo_y()
253271
top = Toplevel1 (root)
@@ -262,20 +280,24 @@ def PrevPoint():
262280
global WindowX
263281
global WindowY
264282
global HashID
283+
global IsClosed
284+
global RailType
265285
# This isn't needed for some reason.
266286
global root
267287

268-
print(CurrentPoint + 1)
288+
#print(CurrentPoint + 1)
269289
X[CurrentPoint] = float(top.XEntry.get())
270290
Y[CurrentPoint] = float(top.YEntry.get())
271291
Z[CurrentPoint] = float(top.ZEntry.get())
272-
print(X)
273-
print(Y)
274-
print(Z)
292+
IsClosed = top.IsClosedDropdown.get()
293+
RailType = top.RailTypeDropdown.get()
294+
#print(X)
295+
#print(Y)
296+
#print(Z)
275297
if (CurrentPoint > 0):
276298
CurrentPoint = CurrentPoint - 1
277299
if (top.HashIDEntry.get() != "Auto"):
278-
HashID = str(hex(top.HashIDEntry.get()))
300+
HashID = str(hex(int(top.HashIDEntry.get(), 0)))
279301
WindowX = root.winfo_x()
280302
WindowY = root.winfo_y()
281303
top = Toplevel1 (root)
@@ -472,7 +494,7 @@ def __init__(self, top=None):
472494
self.HashIDEntry.configure(takefocus="")
473495
self.HashIDEntry.configure(cursor="xterm")
474496

475-
self.HashIDEntry.insert(0, "Auto")
497+
self.HashIDEntry.insert(0, HashID)
476498

477499

478500

@@ -551,12 +573,14 @@ def __init__(self, top=None):
551573
self.IsClosedValueList = ['true','false',]
552574
self.IsClosedDropdown.configure(values=self.IsClosedValueList)
553575
self.IsClosedDropdown.configure(takefocus="")
576+
self.IsClosedDropdown.insert(0, IsClosed)
554577

555578
self.RailTypeDropdown = ttk.Combobox(top)
556579
self.RailTypeDropdown.place(relx=0.225, rely=--0.95, relheight=0.047, relwidth=0.165)
557580
self.RailTypeValueList = ['Linear','Bezier',]
558581
self.RailTypeDropdown.configure(values=self.RailTypeValueList)
559582
self.RailTypeDropdown.configure(takefocus="")
583+
self.RailTypeDropdown.insert(0, RailType)
560584

561585
if __name__ == '__main__':
562586
vp_start_gui()

0 commit comments

Comments
 (0)