示例#1
0
    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)
示例#2
0
    def onAddLine(self, button):
        self.printToLog("onAddLine")
        name_entry = self.builder.get_object("EntryNameNewLine")
        x1_entry = self.builder.get_object("EntryX1Line")
        y1_entry = self.builder.get_object("EntryY1Line")
        x2_entry = self.builder.get_object("EntryX2Line")
        y2_entry = self.builder.get_object("EntryY2Line")

        l1 = Line(name_entry.get_text())
        l1.addCoords(float(x1_entry.get_text()), float(y1_entry.get_text()))
        l1.addCoords(float(x2_entry.get_text()), float(y2_entry.get_text()))

        self.display_file.addObject(l1)
        self.add_object_window.hide()