def __init__(self, master): """ This is the highest class in the hierarchy. It maintains a reference to the main data structure that this GUI is manipulating. All other classes keep a reference to their parent and can access the Truss via this class. """ self.master = master # Instantiate data structure self.truss = Truss() # Graphics self.frame = Frame(master, width=WINDOW_WIDTH, height=WINDOW_HEIGHT) self.designSpace = DesignSpace(self) #self.infoPane = InfoPane(self) self.toolbar = Toolbar(self) # Menu TopMenu(self) # Display self.toolbar.frame.grid(row=0, column=0) self.frame.pack() # Event Binding root.bind("<Control-g>", self.designSpace.toggleSnap) # Current filename self.fileName = None
def __init__(self, master): """ This is the highest class in the hierarchy. It maintains a reference to the main data structure that this GUI is manipulating. All other classes keep a reference to their parent and can access the Truss via this class. """ self.master = master # Instantiate data structure self.truss = Truss() # Graphics self.frame = Frame(master, width=WINDOW_WIDTH, height=WINDOW_HEIGHT) self.designSpace = DesignSpace(self) # self.infoPane = InfoPane(self) self.toolbar = Toolbar(self) # Menu TopMenu(self) # Display self.toolbar.frame.grid(row=0, column=0) self.frame.pack() # Event Binding root.bind("<Control-g>", self.designSpace.toggleSnap) # Current filename self.fileName = None
class App: def __init__(self, master): """ This is the highest class in the hierarchy. It maintains a reference to the main data structure that this GUI is manipulating. All other classes keep a reference to their parent and can access the Truss via this class. """ self.master = master # Instantiate data structure self.truss = Truss() # Graphics self.frame = Frame(master, width=WINDOW_WIDTH, height=WINDOW_HEIGHT) self.designSpace = DesignSpace(self) # self.infoPane = InfoPane(self) self.toolbar = Toolbar(self) # Menu TopMenu(self) # Display self.toolbar.frame.grid(row=0, column=0) self.frame.pack() # Event Binding root.bind("<Control-g>", self.designSpace.toggleSnap) # Current filename self.fileName = None def addMember(self, joint1, joint2): self.truss.addMember(joint1, joint2) def addJoint(self, x, y): pass def clearTruss(self): self.truss = Truss() self.designSpace.clear() def reanalyzeTruss(self): self.truss.setUnsolved() self.updateTrussSolution() self.solveTruss() def solveTruss(self): if not self.truss.isSolved and self.truss.isDeterminate(): self.truss.analyze() self.updateTrussSolution() def updateTrussSolution(self): for member in self.truss.getMembers(): member.graphic.update() ## for joint in self.truss.getJoints(): ## joint.graphic.update() if self.truss.fixedJoint: self.truss.fixedJoint.graphic.update() if self.truss.rollerJoint: self.truss.rollerJoint.graphic.update() def saveas(self): fileName = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text Files", ".txt")]) # print(fileName) if fileName: # print("yes filename") self.save(fileName) self.fileName = fileName # Since the current truss has links to TK classes that cannot be pickled, we need a data structure that preserves the essence of the truss but is simpler def save(self, fileName=None): if fileName: self.truss.save(fileName) self.designSpace.statusBar.setTempText(" Saved.") # Two spaces before saved are INTENTIONAL self.master.after(1000, self.designSpace.statusBar.update) elif self.fileName: self.truss.save(self.fileName) self.designSpace.statusBar.setTempText(" Saved.") self.master.after(1000, self.designSpace.statusBar.update) else: self.saveas() def saveEventHandle(self, event): self.save() def openEventHandle(self, event): self.load() def load(self): fileName = filedialog.askopenfilename(defaultextension=".txt", filetypes=[("Text Files", ".txt")]) if fileName: print(fileName) self.fileName = fileName loadFile = open(fileName, mode="rb") abstractTruss = pickle.load(loadFile) loadFile.close() self.clearTruss() generatedJoints = {} for jointID in abstractTruss["nodes"]: x, y = abstractTruss["nodes"][jointID] newJoint = self.truss.addJoint(x, y) newJoint.graphic = JointGraphic(self.designSpace.canvas, newJoint) newJoint.loadLine = None generatedJoints[jointID] = newJoint print(generatedJoints) for memberID in abstractTruss["edges"]: startJointID, endJointID = memberID startJoint = generatedJoints[startJointID] endJoint = generatedJoints[endJointID] newMember = self.truss.addMember(startJoint, endJoint) newMember.graphic = MemberGraphic(self.designSpace.canvas, newMember) if abstractTruss["fixed joint"]: self.designSpace.currentJoint = generatedJoints[abstractTruss["fixed joint"]] self.designSpace.selectFixedJoint() if abstractTruss["roller joint"]: self.designSpace.currentJoint = generatedJoints[abstractTruss["roller joint"]] self.designSpace.selectRollerJoint() for jointID in abstractTruss["loads"]: joint = generatedJoints[jointID] fx, fy = abstractTruss["loads"][jointID] jx, jy = joint.getLoc() cx, cy = rectifyPos((jx, jy), self.designSpace.canvas) joint.loadLine = LoadGraphic( self.designSpace.canvas, joint, cx + fx / LOAD_SCALE_FACTOR, cy - fy / LOAD_SCALE_FACTOR ) joint.loadLine.makeInactive() self.truss.setExternalLoad(joint, fx, fy) self.solveTruss() for joint in self.truss.getJoints(): joint.graphic.update() self.designSpace.mjCount.setText( " (" + str(len(self.truss.getJoints())) + " Joints / " + str(len(self.truss.getMembers())) + " Members)" )
class App: def __init__(self, master): """ This is the highest class in the hierarchy. It maintains a reference to the main data structure that this GUI is manipulating. All other classes keep a reference to their parent and can access the Truss via this class. """ self.master = master # Instantiate data structure self.truss = Truss() # Graphics self.frame = Frame(master, width=WINDOW_WIDTH, height=WINDOW_HEIGHT) self.designSpace = DesignSpace(self) #self.infoPane = InfoPane(self) self.toolbar = Toolbar(self) # Menu TopMenu(self) # Display self.toolbar.frame.grid(row=0, column=0) self.frame.pack() # Event Binding root.bind("<Control-g>", self.designSpace.toggleSnap) # Current filename self.fileName = None def addMember(self, joint1, joint2): self.truss.addMember(joint1, joint2) def addJoint(self, x, y): pass def clearTruss(self): self.truss = Truss() self.designSpace.clear() def reanalyzeTruss(self): self.truss.setUnsolved() self.updateTrussSolution() self.solveTruss() def solveTruss(self): if not self.truss.isSolved and self.truss.isDeterminate(): self.truss.analyze() self.updateTrussSolution() def updateTrussSolution(self): for member in self.truss.getMembers(): member.graphic.update() ## for joint in self.truss.getJoints(): ## joint.graphic.update() if self.truss.fixedJoint: self.truss.fixedJoint.graphic.update() if self.truss.rollerJoint: self.truss.rollerJoint.graphic.update() def saveas(self): fileName = filedialog.asksaveasfilename(defaultextension='.txt', filetypes=[('Text Files', '.txt')]) #print(fileName) if fileName: #print("yes filename") self.save(fileName) self.fileName = fileName # Since the current truss has links to TK classes that cannot be pickled, we need a data structure that preserves the essence of the truss but is simpler def save(self, fileName=None): if fileName: self.truss.save(fileName) self.designSpace.statusBar.setTempText( " Saved.") # Two spaces before saved are INTENTIONAL self.master.after(1000, self.designSpace.statusBar.update) elif self.fileName: self.truss.save(self.fileName) self.designSpace.statusBar.setTempText(" Saved.") self.master.after(1000, self.designSpace.statusBar.update) else: self.saveas() def saveEventHandle(self, event): self.save() def openEventHandle(self, event): self.load() def load(self): fileName = filedialog.askopenfilename(defaultextension='.txt', filetypes=[('Text Files', '.txt') ]) if fileName: print(fileName) self.fileName = fileName loadFile = open(fileName, mode='rb') abstractTruss = pickle.load(loadFile) loadFile.close() self.clearTruss() generatedJoints = {} for jointID in abstractTruss['nodes']: x, y = abstractTruss['nodes'][jointID] newJoint = self.truss.addJoint(x, y) newJoint.graphic = JointGraphic(self.designSpace.canvas, newJoint) newJoint.loadLine = None generatedJoints[jointID] = newJoint print(generatedJoints) for memberID in abstractTruss['edges']: startJointID, endJointID = memberID startJoint = generatedJoints[startJointID] endJoint = generatedJoints[endJointID] newMember = self.truss.addMember(startJoint, endJoint) newMember.graphic = MemberGraphic(self.designSpace.canvas, newMember) if abstractTruss['fixed joint']: self.designSpace.currentJoint = generatedJoints[ abstractTruss['fixed joint']] self.designSpace.selectFixedJoint() if abstractTruss['roller joint']: self.designSpace.currentJoint = generatedJoints[ abstractTruss['roller joint']] self.designSpace.selectRollerJoint() for jointID in abstractTruss['loads']: joint = generatedJoints[jointID] fx, fy = abstractTruss['loads'][jointID] jx, jy = joint.getLoc() cx, cy = rectifyPos((jx, jy), self.designSpace.canvas) joint.loadLine = LoadGraphic(self.designSpace.canvas,\ joint,\ cx+fx/LOAD_SCALE_FACTOR,\ cy-fy/LOAD_SCALE_FACTOR) joint.loadLine.makeInactive() self.truss.setExternalLoad(joint, fx, fy) self.solveTruss() for joint in self.truss.getJoints(): joint.graphic.update() self.designSpace.mjCount.setText( " (" + str(len(self.truss.getJoints())) + " Joints / " + str(len(self.truss.getMembers())) + " Members)")