Beispiel #1
0
 def constrain_link(self,
                    row1: Optional[int] = None,
                    row2: int = 0) -> None:
     """Turn a link to ground, then delete this link."""
     if row1 is None:
         row1 = self.entities_link.currentRow()
     vlink1 = self.vlink_list[row1]
     link_args = self.entities_link.row_data(row1)
     link_args.points = ''
     new_points = sorted(
         set(self.vlink_list[0].points) | set(vlink1.points))
     base_args = self.entities_link.row_data(row2)
     base_args.points = ','.join(f"Point{e}" for e in new_points if e)
     self.command_stack.beginMacro(
         f"Constrain {{Link: {vlink1.name}}} to ground")
     # Turn to ground
     self.command_stack.push(
         EditLinkTable(row2, self.vpoint_list, self.vlink_list,
                       self.entities_point, self.entities_link, base_args))
     # Free all points and delete the link
     self.command_stack.push(
         EditLinkTable(row1, self.vpoint_list, self.vlink_list,
                       self.entities_point, self.entities_link, link_args))
     self.command_stack.push(
         DeleteTable(row1,
                     self.vlink_list,
                     self.entities_link,
                     is_rename=False))
     self.command_stack.endMacro()
Beispiel #2
0
 def release_ground(self) -> None:
     """Clone ground to a new link, then make ground no points."""
     name = self.__get_link_serial_number()
     args = LinkArgs(name, 'Blue', self.entities_link.item(0, 2).text())
     self.cmd_stack.beginMacro(f"Release ground to {{Link: {name}}}")
     # Free all points
     self.cmd_stack.push(EditLinkTable(
         0,
         self.vpoint_list,
         self.vlink_list,
         self.entities_point,
         self.entities_link,
         LinkArgs(VLink.FRAME, 'White', '')
     ))
     # Create new link
     self.cmd_stack.push(AddTable(self.vlink_list, self.entities_link))
     self.cmd_stack.push(EditLinkTable(
         self.entities_link.rowCount() - 1,
         self.vpoint_list,
         self.vlink_list,
         self.entities_point,
         self.entities_link,
         args
     ))
     self.cmd_stack.endMacro()
Beispiel #3
0
    def new_link(self) -> None:
        """Create a link with arguments.

        + Last than one point:
            + Create a new link (Dialog)
        + Search method:
            + Find the intersection between points that was including any link.
            + Add the points that is not in the intersection to the link.
        + If no, just create a new link by selected points.
        """
        rows = self.entities_point.selected_rows()
        if not len(rows) > 1:
            self.__edit_link()
            return
        inter: Counter_t[str] = Counter()
        for p in rows:
            inter.update(self.vpoint_list[p].links)
        name = inter.most_common(1)[0][0] if inter else ""
        if inter[name] < 2:
            self.add_normal_link(rows)
            return
        row = self.entities_link.find_name(name)
        self.command_stack.beginMacro(f"Edit {{Link: {name}}}")
        args = self.entities_link.row_data(row)
        points = set(self.entities_link.get_points(row))
        points.update(rows)
        args.points = ','.join(f'Point{p}' for p in points)
        self.command_stack.push(
            EditLinkTable(row, self.vpoint_list, self.vlink_list,
                          self.entities_point, self.entities_link, args))
        self.command_stack.endMacro()
Beispiel #4
0
    def __edit_link(self, row: Union[int, bool] = False) -> None:
        """Edit link function."""
        dlg = EditLinkDialog(self.vpoint_list, self.vlink_list, row, self)
        dlg.show()
        if not dlg.exec_():
            dlg.deleteLater()
            return

        name = dlg.name_edit.text()
        args = LinkArgs(
            name, dlg.color_box.currentText(), ','.join(
                dlg.selected.item(point).text()
                for point in range(dlg.selected.count())))
        if row is False:
            self.command_stack.beginMacro(f"Add {{Link: {name}}}")
            self.command_stack.push(
                AddTable(self.vlink_list, self.entities_link))
            row = self.entities_link.rowCount() - 1
        else:
            row = dlg.name_box.currentIndex()
            self.command_stack.beginMacro(f"Edit {{Link: {name}}}")

        dlg.deleteLater()

        self.command_stack.push(
            EditLinkTable(row, self.vpoint_list, self.vlink_list,
                          self.entities_point, self.entities_link, args))
        self.command_stack.endMacro()
Beispiel #5
0
    def delete_link(self, row: Optional[int] = None) -> None:
        """Push delete link command to stack.

        Remove link will not remove the points.
        """
        if row is None:
            row = self.entities_link.currentRow()
        if row < 1:
            return
        args = self.entities_link.row_data(row)
        args.points = ''
        self.cmd_stack.beginMacro(
            f"Delete {{Link: {self.vlink_list[row].name}}}")
        self.cmd_stack.push(EditLinkTable(
            row,
            self.vpoint_list,
            self.vlink_list,
            self.entities_point,
            self.entities_link,
            args
        ))
        self.cmd_stack.push(DeleteTable(
            row,
            self.vlink_list,
            self.entities_link,
            is_rename=False
        ))
        self.cmd_stack.endMacro()
Beispiel #6
0
    def __merge_link(self, index: int, links: Sequence[int]) -> None:
        """Merge links to a base link.

        @index: The index of main joint in the sequence.
        """
        row = links[index]
        links_text = ", ".join(self.vlink_list[link].name for link in links)
        name = self.vlink_list[row].name
        self.command_stack.beginMacro(f"Merge {{{links_text}}} to joint {{{name}}}")
        points = list(self.vlink_list[row].points)
        args = self.entities_link.row_data(row)
        for link in sorted(links, reverse=True):
            if self.vlink_list[link].name == self.vlink_list[row].name:
                continue
            for point in self.vlink_list[link].points:
                if point not in points:
                    points.append(point)
            self.delete_link(link)
        args.points = ','.join(f'Point{p}' for p in points)
        row = [vlink.name for vlink in self.vlink_list].index(args.name)
        self.command_stack.push(EditLinkTable(
            row,
            self.vpoint_list,
            self.vlink_list,
            self.entities_point,
            self.entities_link,
            args
        ))
        self.command_stack.endMacro()
Beispiel #7
0
 def add_link(self,
              name: str,
              color: str,
              points: Optional[Sequence[int]] = None) -> None:
     """Push a new link command to stack."""
     if points is None:
         points = []
     args = LinkArgs(name, color, ','.join(f'Point{i}' for i in points))
     self.command_stack.beginMacro(f"Add {{Link: {name}}}")
     self.command_stack.push(AddTable(self.vlink_list, self.entities_link))
     self.command_stack.push(
         EditLinkTable(self.entities_link.rowCount() - 1, self.vpoint_list,
                       self.vlink_list, self.entities_point,
                       self.entities_link, args))
     self.command_stack.endMacro()
Beispiel #8
0
    def new_link(self) -> None:
        """Create a link with arguments.

        + Last than one point:
            + Create a new link (Dialog)
        + Search method:
            + Find the intersection between points that was including any link.
            + Add the points that is not in the intersection to the link.
        + If no, just create a new link by selected points.
        """
        rows = self.entities_point.selected_rows()
        if not len(rows) > 1:
            self.__edit_link()
            return

        links_all: List[str] = []
        for vpoint in self.vpoint_list:
            links_all.extend(vpoint.links)
        count_0 = False
        for p in set(links_all):
            if links_all.count(p) > 1:
                count_0 = True
                break
        if not links_all or not count_0:
            self.add_normal_link(rows)
            return

        name = max(set(links_all), key=links_all.count)
        row = self.entities_link.find_name(name)
        self.command_stack.beginMacro(f"Edit {{Link: {name}}}")
        args = self.entities_link.row_data(row)
        points = set(self.entities_link.get_points(row))
        points.update(rows)
        args.points = ','.join(f'Point{p}' for p in points)
        self.command_stack.push(
            EditLinkTable(row, self.vpoint_list, self.vlink_list,
                          self.entities_point, self.entities_link, args))
        self.command_stack.endMacro()