def importFile(self, path): self.display_file.wipeOut() #print("{}".format(path)) vertices = dict() vertice_counter = 0 name = "" self.file = open(path, "r+") # read and write for line in self.file: if (line[0] == "v"): # store vertices in a dictionary vertice_counter += 1 vertices[vertice_counter] = line elif (line[0] == "o" ): # store temporarily the name of the object to come match = re.findall(r"\S+", line) name = match[1] elif (line[0] == "p"): # TODO: FINISH THIS match = re.findall(r"\S+", line) vertice_for_point = vertices[float(match[1])] match = re.findall(r"\S+", vertice_for_point) coord = {"x": float(match[1]), "y": float(match[2])} p1 = Point(name) p1.addCoords(coord["x"], coord["y"]) self.display_file.addObject(p1) elif (line[0] == "l"): match = re.findall(r"\S+", line) if (len(match) == 3): # line l = Line(name) else: # polygon l = None if (match[1] == match[-1]): l = Polygon(name) else: l = Curve(name) for item in match: if ( item != "l" ): # ignore the first character, only compute coordinates vertice_for_point = vertices[float(item)] match_vertice = re.findall(r"\S+", vertice_for_point) coord = { "x": float(match_vertice[1]), "y": float(match_vertice[2]) } l.addCoords(coord["x"], coord["y"]) if (match[1] == match[-1] ): # if polygon (last coords == first coords) l.popCoords() # remove repeated coords self.display_file.addObject(l)
def onAddPoint(self, button): self.printToLog("onAddPoint") name_entry = self.builder.get_object("PointNameEntry") x_entry = self.builder.get_object("PointXEntry") y_entry = self.builder.get_object("PointYEntry") p1 = Point(name_entry.get_text()) p1.addCoords(float(x_entry.get_text()), float(y_entry.get_text())) self.display_file.addObject(p1) self.add_object_window.hide()