Exemplo n.º 1
0
 def release_ground(self):
     """Clone ground to a new link, then make ground no points."""
     name = self.__get_link_serial_number()
     args = [name, 'Blue', self.entities_link.item(0, 2).text()]
     self.command_stack.beginMacro(f"Release ground to {{Link: {name}}}")
     # Free all points.
     self.command_stack.push(
         EditLinkTable(0, self.entities_link, self.entities_point,
                       ['ground', 'White', '']))
     # Create new link.
     self.command_stack.push(AddTable(self.entities_link))
     self.command_stack.push(
         EditLinkTable(self.entities_link.rowCount() - 1,
                       self.entities_link, self.entities_point, args))
     self.command_stack.endMacro()
Exemplo n.º 2
0
    def __merge_link(self, index: int, links: Tuple[int]):
        """Merge links to a base link.

        @index: The index of main joint in the sequence.
        """
        row = links[index]
        links_text = ", ".join(
            self.EntitiesLink.item(link, 0).text() for link in links)
        name = self.EntitiesLink.item(row, 0).text()
        self.CommandStack.beginMacro(
            f"Merge {{{links_text}}} to joint {{{name}}}")
        vlinks = self.EntitiesLink.dataTuple()
        points = list(vlinks[row].points)
        args = self.EntitiesLink.rowTexts(row, has_name=True)
        for link in sorted(links, reverse=True):
            if vlinks[link].name == vlinks[row].name:
                continue
            for point in vlinks[link].points:
                if point not in points:
                    points.append(point)
            self.deleteLink(link)
        args[2] = ','.join(f'Point{p}' for p in points)
        self.CommandStack.push(
            EditLinkTable([vlink.name for vlink in self.EntitiesLink.data()
                           ].index(args[0]), self.EntitiesLink,
                          self.EntitiesPoint, args))
        self.CommandStack.endMacro()
Exemplo n.º 3
0
    def __edit_link(self, row: Union[int, bool] = False):
        """Edit link function."""
        dlg = EditLinkDialog(self.entities_point.data_tuple(),
                             self.entities_link.data_tuple(), row, self)
        dlg.show()
        if not dlg.exec():
            dlg.deleteLater()
            return

        name = dlg.name_edit.text()
        args = [
            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.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.entities_link, self.entities_point, args))
        self.command_stack.endMacro()
Exemplo n.º 4
0
 def add_link(self,
              name: str,
              color: str,
              points: Optional[Sequence[int]] = None):
     """Push a new link command to stack."""
     if points is None:
         points: List[int] = []
     link_args = [name, color, ','.join(f'Point{i}' for i in points)]
     self.command_stack.beginMacro(f"Add {{Link: {name}}}")
     self.command_stack.push(AddTable(self.entities_link))
     self.command_stack.push(
         EditLinkTable(self.entities_link.rowCount() - 1,
                       self.entities_link, self.entities_point, link_args))
     self.command_stack.endMacro()
Exemplo n.º 5
0
 def constrain_link(self, row1: Optional[int] = None, row2: int = 0):
     """Turn a link to ground, then delete this link."""
     if row1 is None:
         row1 = self.entities_link.currentRow()
     name = self.entities_link.item(row1, 0).text()
     link_args = self.entities_link.row_text(row1, has_name=True)
     link_args[2] = ''
     new_points = sorted(
         set(self.entities_link.item(0, 2).text().split(','))
         | set(self.entities_link.item(row1, 2).text().split(',')))
     base_args = self.entities_link.row_text(row2, has_name=True)
     base_args[2] = ','.join(e for e in new_points if e)
     self.command_stack.beginMacro(f"Constrain {{Link: {name}}} to ground")
     # Turn to ground.
     self.command_stack.push(
         EditLinkTable(row2, self.entities_link, self.entities_point,
                       base_args))
     # Free all points and delete the link.
     self.command_stack.push(
         EditLinkTable(row1, self.entities_link, self.entities_point,
                       link_args))
     self.command_stack.push(
         DeleteTable(row1, self.entities_link, is_rename=False))
     self.command_stack.endMacro()
Exemplo n.º 6
0
    def deleteLink(self, row: int):
        """Push delete link command to stack.

        Remove link will not remove the points.
        """
        if not row > 0:
            return
        args = self.EntitiesLink.rowTexts(row, has_name=True)
        args[2] = ''
        name = self.EntitiesLink.item(row, 0).text()
        self.CommandStack.beginMacro(f"Delete {{Link: {name}}}")
        self.CommandStack.push(
            EditLinkTable(row, self.EntitiesLink, self.EntitiesPoint, args))
        self.CommandStack.push(
            DeleteTable(row, self.EntitiesLink, is_rename=False))
        self.CommandStack.endMacro()
Exemplo n.º 7
0
    def delete_link(self, row: Optional[int] = 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_text(row, has_name=True)
        args[2] = ''
        name = self.entities_link.item(row, 0).text()
        self.command_stack.beginMacro(f"Delete {{Link: {name}}}")
        self.command_stack.push(
            EditLinkTable(row, self.entities_link, self.entities_point, args))
        self.command_stack.push(
            DeleteTable(row, self.entities_link, is_rename=False))
        self.command_stack.endMacro()
Exemplo n.º 8
0
    def new_link(self):
        """Create a link with arguments.

        + Last than one point:

            - Create a new link

        + 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(
            chain(*(self.entities_point.get_links(row) for row in rows)))
        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_text(row, has_name=True)
        points = set(self.entities_link.get_points(row))
        points.update(rows)
        args[2] = ','.join(f'Point{p}' for p in points)
        self.command_stack.push(
            EditLinkTable(row, self.entities_link, self.entities_point, args))
        self.command_stack.endMacro()