예제 #1
0
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()
예제 #2
0
def addLink(self, name: str, color: str, points: Tuple[int]):
    """Push a new link command to stack."""
    linkArgs = [name, color, ','.join('Point{}'.format(i) for i in points)]
    self.CommandStack.beginMacro("Add {{Link: {}}}".format(name))
    self.CommandStack.push(AddTable(self.EntitiesLink))
    self.CommandStack.push(
        EditLinkTable(self.EntitiesLink.rowCount() - 1, self.EntitiesLink,
                      self.EntitiesPoint, linkArgs))
    self.CommandStack.endMacro()
예제 #3
0
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()
예제 #4
0
def releaseGround(self):
    """Clone ground to a new link, then make ground no points."""
    name = _getLinkSerialNumber(self)
    args = [name, 'Blue', self.EntitiesLink.item(0, 2).text()]
    self.CommandStack.beginMacro("Release ground to {{Link: {}}}".format(name))
    #Free all points.
    self.CommandStack.push(
        EditLinkTable(0, self.EntitiesLink, self.EntitiesPoint,
                      ['ground', 'White', '']))
    #Create new link.
    self.CommandStack.push(AddTable(self.EntitiesLink))
    self.CommandStack.push(
        EditLinkTable(self.EntitiesLink.rowCount() - 1, self.EntitiesLink,
                      self.EntitiesPoint, args))
    self.CommandStack.endMacro()
예제 #5
0
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
예제 #6
0
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()
예제 #7
0
def _editLink(self, row=False):
    """Edit link function."""
    dlg = EditLinkDialog(self.EntitiesPoint.dataTuple(),
                         self.EntitiesLink.dataTuple(), row, self)
    dlg.show()
    if not dlg.exec_():
        return
    name = dlg.name_edit.text()
    args = [
        name,
        dlg.Color.currentText(), ','.join(
            dlg.selected.item(point).text()
            for point in range(dlg.selected.count()))
    ]
    if row is False:
        self.CommandStack.beginMacro("Add {{Link: {}}}".format(name))
        self.CommandStack.push(AddTable(self.EntitiesLink))
        row = self.EntitiesLink.rowCount() - 1
    else:
        row = dlg.Link.currentIndex()
        self.CommandStack.beginMacro("Edit {{Link: {}}}".format(name))
    self.CommandStack.push(
        EditLinkTable(row, self.EntitiesLink, self.EntitiesPoint, args))
    self.CommandStack.endMacro()