def add_point( self, x: float, y: float, links: str = "", color: str = 'Green', type_num: Union[int, VJoint] = VJoint.R, angle: float = 0. ) -> int: """Add an ordinary point. Return the row count of new point.""" row_count = self.entities_point.rowCount() self.cmd_stack.beginMacro(f"Add {{Point{row_count}}}") self.cmd_stack.push(AddTable(self.vpoint_list, self.entities_point)) if type_num == VJoint.R: type_str = 'R' elif type_num == VJoint.P: type_str = f'P:{angle}' else: type_str = f'RP:{angle}' self.cmd_stack.push(EditPointTable( row_count, self.vpoint_list, self.vlink_list, self.entities_point, self.entities_link, PointArgs(links, type_str, color, x, y) )) self.cmd_stack.endMacro() return row_count
def __edit_point(self, row: Union[int, bool] = False) -> None: """Edit point function.""" dlg = EditPointDialog(self.vpoint_list, self.vlink_list, 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 = PointArgs( ','.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.vpoint_list, 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.vpoint_list, self.vlink_list, self.entities_point, self.entities_link, args)) self.command_stack.endMacro()
def row_data(self, row: int) -> PointArgs: """Return row data for 'edit_point' method.""" args = self.row_text(row, has_name=False) x = float(args[3]) if args[3] else 0. y = float(args[4]) if args[4] else 0. return PointArgs(args[0], args[1], args[2], x, y)