Exemplo n.º 1
0
    def __edit_point(self, row: Union[int, bool] = False):
        """Edit point function."""
        dlg = EditPointDialog(self.entities_point.data_tuple(),
                              self.entities_link.data_tuple(), row, self)
        dlg.show()
        if not dlg.exec():
            dlg.deleteLater()
            return

        row_count = self.entities_point.rowCount()
        type_str = dlg.type_box.currentText().split()[0]
        if type_str != 'R':
            type_str += f":{dlg.angle_box.value() % 360}"
        args = (','.join(
            dlg.selected.item(link).text()
            for link in range(dlg.selected.count())), type_str,
                dlg.color_box.currentText(), dlg.x_box.value(),
                dlg.y_box.value())
        if row is False:
            self.command_stack.beginMacro(f"Add {{Point{row_count}}}")
            self.command_stack.push(AddTable(self.entities_point))
            row = row_count
        else:
            row = dlg.name_box.currentIndex()
            self.command_stack.beginMacro(f"Edit {{Point{row}}}")

        dlg.deleteLater()

        self.command_stack.push(
            EditPointTable(row, self.entities_point, self.entities_link, args))
        self.command_stack.endMacro()
Exemplo n.º 2
0
 def parse_expression(self, expr: str):
     """Parse expression."""
     try:
         args_list = parse_params(expr)
     except LarkError:
         QMessageBox.warning(
             self,
             "Loading failed",
             f"Your expression is in an incorrect format."
         )
     else:
         for args in args_list:
             links = args[0].split(',')
             link_names = {
                 vlink.name for vlink in self.entities_link.data()
             }
             for link_name in links:
                 # If link name not exist.
                 if link_name not in link_names:
                     self.add_link(link_name, 'Blue')
             row_count = self.entities_point.rowCount()
             self.command_stack.beginMacro(f"Add {{Point{row_count}}}")
             self.command_stack.push(AddTable(self.entities_point))
             self.command_stack.push(EditPointTable(
                 row_count,
                 self.entities_point,
                 self.entities_link,
                 args
             ))
             self.command_stack.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 clone_point(self):
     """Clone a point (with orange color)."""
     row = self.entities_point.currentRow()
     args = self.entities_point.row_text(row)
     args[2] = 'Orange'
     row_count = self.entities_point.rowCount()
     self.command_stack.beginMacro(
         f"Clone {{Point{row}}} as {{Point{row_count}}}")
     self.command_stack.push(AddTable(self.entities_point))
     self.command_stack.push(
         EditPointTable(row_count, self.entities_point, self.entities_link,
                        args))
     self.command_stack.endMacro()
Exemplo n.º 5
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.º 6
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.º 7
0
 def add_point(self,
               x: float,
               y: float,
               links: str = "",
               color: str = 'Green',
               type_num: int = VJoint.R,
               angle: float = 0.) -> int:
     """Add an ordinary point. Return the row count of new point."""
     row_count = self.entities_point.rowCount()
     self.command_stack.beginMacro(f"Add {{Point{row_count}}}")
     self.command_stack.push(AddTable(self.entities_point))
     self.command_stack.push(
         EditPointTable(
             row_count, self.entities_point, self.entities_link,
             (links,
              ('R', f'P:{angle}', f'RP:{angle}')[type_num], color, x, y)))
     self.command_stack.endMacro()
     return row_count
Exemplo n.º 8
0
    def __to_multiple_joint(self, index: int, points: Tuple[int]):
        """Merge points into a multiple joint.

        @index: The index of main joint in the sequence.
        """
        row = points[index]
        points_text = ", ".join(f'Point{p}' for p in points)
        self.CommandStack.beginMacro(
            f"Merge {{{points_text}}} as multiple joint {{Point{row}}}")
        vpoints = self.EntitiesPoint.dataTuple()
        links = list(vpoints[row].links)
        args = self.EntitiesPoint.rowTexts(row)
        for point in sorted(points, reverse=True):
            for link in vpoints[point].links:
                if link not in links:
                    links.append(link)
            self.deletePoint(point)
        args[0] = ','.join(links)
        self.CommandStack.push(AddTable(self.EntitiesPoint))
        self.CommandStack.push(
            EditPointTable(self.EntitiesPoint.rowCount() - 1,
                           self.EntitiesPoint, self.EntitiesLink, args))
        self.CommandStack.endMacro()