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()
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 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()
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 parse_expression(self, expr: str) -> None: """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.links.split(',') link_names = {vlink.name for vlink in self.vlink_list} 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.vpoint_list, self.entities_point )) self.command_stack.push(EditPointTable( row_count, self.vpoint_list, self.vlink_list, self.entities_point, self.entities_link, args )) self.command_stack.endMacro()
def __to_multiple_joint(self, index: int, points: Sequence[int]) -> None: """Merge points into a multiple joint. @index: The index of main joint in the sequence. """ row = points[index] self.command_stack.beginMacro( f"Merge {sorted(points)} as multiple joint {{Point{row}}}" ) links = list(self.vpoint_list[row].links) args = self.entities_point.row_data(row) for point in sorted(points, reverse=True): for link in self.vpoint_list[point].links: if link not in links: links.append(link) self.delete_point(point) args.links = ','.join(links) self.command_stack.push(AddTable(self.vpoint_list, self.entities_point)) self.command_stack.push(EditPointTable( self.entities_point.rowCount() - 1, self.vpoint_list, self.vlink_list, self.entities_point, self.entities_link, args )) self.command_stack.endMacro()
def clone_point(self) -> None: """Clone a point (with orange color).""" row = self.entities_point.currentRow() args = self.entities_point.row_data(row) args.color = '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.vpoint_list, self.entities_point)) self.command_stack.push( EditPointTable(row_count, self.vpoint_list, self.vlink_list, self.entities_point, self.entities_link, args)) self.command_stack.endMacro()
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()