def _editPoint(self, row: int = False): """Edit point function.""" dlg = EditPointDialog(self.EntitiesPoint.dataTuple(), self.EntitiesLink.dataTuple(), row, self) dlg.show() if not dlg.exec_(): return rowCount = self.EntitiesPoint.rowCount() Type = dlg.Type.currentText().split()[0] if Type != 'R': Type += ":{}".format(dlg.Angle.value() % 360) args = [ ','.join( dlg.selected.item(link).text() for link in range(dlg.selected.count())), Type, dlg.Color.currentText(), dlg.X_coordinate.value(), dlg.Y_coordinate.value() ] if row is False: self.CommandStack.beginMacro("Add {{Point{}}}".format(rowCount)) self.CommandStack.push(AddTable(self.EntitiesPoint)) row = rowCount else: row = dlg.Point.currentIndex() self.CommandStack.beginMacro("Edit {{Point{}}}".format(rowCount)) self.CommandStack.push( EditPointTable(row, self.EntitiesPoint, self.EntitiesLink, args)) self.CommandStack.endMacro()
def _toMultipleJoint(self, index: int, points: Tuple[int]): """Merge points into a multiple joint. @index: The index of main joint in the sequence. """ row = points[index] self.CommandStack.beginMacro( "Merge {{{}}} as multiple joint {{{}}}".format( ", ".join('Point{}'.format(p) for p in points), 'Point{}'.format(row))) points_data = self.EntitiesPoint.dataTuple() for i, p in enumerate(points): if i == index: continue newLinks = points_data[row].links for l in points_data[p].links: #Add new links. if l not in newLinks: newLinks.append(l) args = self.EntitiesPoint.rowTexts(row) args[0] = ','.join(newLinks) self.CommandStack.push( EditPointTable(row, self.EntitiesPoint, self.EntitiesLink, args)) _deletePoint(self, p) self.CommandStack.endMacro()
def setFreemoved(self, coordinates: Tuple[Tuple[float, float]]): """Free move function.""" self.CommandStack.beginMacro("Moved {{{}}}".format(", ".join( "Point{}".format(c[0]) for c in coordinates))) for row, (x, y) in coordinates: args = self.EntitiesPoint.rowTexts(row) args[3] = x args[4] = y self.CommandStack.push( EditPointTable(row, self.EntitiesPoint, self.EntitiesLink, args)) self.CommandStack.endMacro()
def clonePoint(self): """Clone a point (with orange color).""" row = self.EntitiesPoint.currentRow() args = self.EntitiesPoint.rowTexts(row) args[2] = 'Orange' rowCount = self.EntitiesPoint.rowCount() self.CommandStack.beginMacro("Clone {{Point{}}} as {{Point{}}}".format( row, rowCount)) self.CommandStack.push(AddTable(self.EntitiesPoint)) self.CommandStack.push( EditPointTable(rowCount, self.EntitiesPoint, self.EntitiesLink, args)) self.CommandStack.endMacro()
def _deletePoint(self, row: int): """Push delete point command to stack.""" args = self.EntitiesPoint.rowTexts(row) args[0] = '' self.CommandStack.beginMacro("Delete {{Point{}}}".format(row)) self.CommandStack.push( EditPointTable(row, self.EntitiesPoint, self.EntitiesLink, args)) for i in range(self.EntitiesLink.rowCount()): self.CommandStack.push(FixSequenceNumber(self.EntitiesLink, i, row)) self.CommandStack.push(DeleteTable(row, self.EntitiesPoint, isRename=True)) self.InputsWidget.variableExcluding(row) self.CommandStack.endMacro()
def lockPoints(self): """Turn a group of points to fixed on ground or not.""" toFixed = self.action_point_context_lock.isChecked() for row in self.EntitiesPoint.selectedRows(): newLinks = self.EntitiesPoint.item(row, 1).text().split(',') if toFixed: if 'ground' not in newLinks: newLinks.append('ground') else: if 'ground' in newLinks: newLinks.remove('ground') args = self.EntitiesPoint.rowTexts(row) args[0] = ','.join(s for s in newLinks if s) self.CommandStack.beginMacro("Edit {{Point{}}}".format(row)) self.CommandStack.push( EditPointTable(row, self.EntitiesPoint, self.EntitiesLink, args)) self.CommandStack.endMacro()
def addPoint(self, x: float, y: float, fixed: bool, color: str) -> int: """Add an ordinary point. Return the row count of new point. """ rowCount = self.EntitiesPoint.rowCount() if fixed: links = 'ground' if color is None: color = 'Blue' else: links = '' if color is None: color = 'Green' self.CommandStack.beginMacro("Add {{Point{}}}".format(rowCount)) self.CommandStack.push(AddTable(self.EntitiesPoint)) self.CommandStack.push( EditPointTable(rowCount, self.EntitiesPoint, self.EntitiesLink, [links, 'R', color, x, y])) self.CommandStack.endMacro() return rowCount
def parseExpression(self, expr: str): """Parse expression.""" try: args_list = PMKSArgsTransformer().transform(PMKS_parser.parse(expr)) except Exception as e: print(e) QMessageBox.warning(self, "Loading failed", "Your expression is in an incorrect format.") else: for args in args_list: linkNames = tuple(vlink.name for vlink in self.EntitiesLink.data()) links = args[0].split(',') for linkName in links: #If link name not exist. if linkName not in linkNames: self.addLink(linkName, 'Blue') rowCount = self.EntitiesPoint.rowCount() self.CommandStack.beginMacro("Add {{Point{}}}".format(rowCount)) self.CommandStack.push(AddTable(self.EntitiesPoint)) self.CommandStack.push( EditPointTable(rowCount, self.EntitiesPoint, self.EntitiesLink, args)) self.CommandStack.endMacro()