Commit 49c0f255 authored by Michael Büsch's avatar Michael Büsch

fup: Add automatic interface field name matching

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent 55027363
......@@ -26,7 +26,6 @@ GUI
FBD / FUP
---------
* Add feature: Automatically add # to interface variable names in operand
* Add feature: Exchange elements
* Add feature: Duplicate diagrams
* Add feature: Copy & paste elements
......
......@@ -170,6 +170,15 @@ class FupElem_OPERAND(FupElem):
QLineEdit.Normal,
self.contentText)
if ok:
# Try to find the field in the interface and use the
# actual interface field name. But only do this, if
# the name does not start with a space. This way the user
# can disable this automatic matching.
if not text.startswith(" "):
field = self.grid.interfDef.findByName(text)
if field:
# Found it. Use the actual name.
text = "#" + field.name
self.contentText = text
return True
return False
......
......@@ -127,6 +127,12 @@ class FupGrid(object):
return True
return False
@property
def interfDef(self):
"""Get the block interface definition (AwlInterfDef() instance).
"""
return self.__drawWidget.interfDef
def getUnusedWireIdNum(self):
"""Get an unused wire idNum.
"""
......
......@@ -143,9 +143,14 @@ class FupDrawWidget(QWidget):
# Signal: Something in the FUP diagram changed
diagramChanged = Signal()
def __init__(self, parent=None):
def __init__(self, parent, interfWidget):
"""parent => Parent QWidget().
interfWidget => AwlInterfWidget() instance
"""
QWidget.__init__(self, parent)
self.__interfWidget = interfWidget
self.__suppressMousePress = 0
self.__repaintBlocked = Blocker()
......@@ -193,6 +198,12 @@ class FupDrawWidget(QWidget):
self.setFocusPolicy(Qt.FocusPolicy(Qt.ClickFocus | Qt.WheelFocus | Qt.StrongFocus))
self.setMouseTracking(True)
@property
def interfDef(self):
"""Get the block interface definition (AwlInterfDef() instance).
"""
return self.__interfWidget.interfDef
def __handleGridResize(self, gridWidth, gridHeight):
self.resize(gridWidth * self.__cellWidth,
gridHeight * self.__cellHeight)
......
......@@ -121,7 +121,7 @@ class FupEditWidgetMenu(QMenu):
self.addAction("Show STL code (EN)...", self.showStl)
class FupEditWidget(QWidget):
def __init__(self, parent=None):
def __init__(self, parent, interfWidget):
QWidget.__init__(self, parent)
self.setLayout(QGridLayout())
self.layout().setContentsMargins(QMargins())
......@@ -143,7 +143,7 @@ class FupEditWidget(QWidget):
self.__splitter.addWidget(self.__leftWidget)
self.draw = FupDrawWidget(self)
self.draw = FupDrawWidget(self, interfWidget)
self.__drawScroll = QScrollArea(self)
self.__drawScroll.setWidget(self.draw)
......@@ -168,7 +168,7 @@ class FupWidget(QWidget):
self.interf = AwlInterfWidget(self)
self.splitter.addWidget(self.interf)
self.edit = FupEditWidget(self)
self.edit = FupEditWidget(self, self.interf)
self.splitter.addWidget(self.edit)
self.layout().addWidget(self.splitter, 0, 0)
......
......@@ -202,6 +202,24 @@ class AwlInterfDef(object):
if field:
yield field
def findByName(self, name, caseSensitive=False, strip=True):
"""Find a field by its name.
caseSensitive => Do a case sensitive match
strip => Strip the name and remove leading #
"""
if strip:
name = name.strip() # Strip leading and trailing white space
if name.startswith("#"):
name = name[1:] # Strip #-prefix
for field in self.allFields:
fieldName = field.name
if not caseSensitive:
fieldName = fieldName.upper()
name = name.upper()
if fieldName == name:
return field # Found it
return None
class AbstractTableModel(QAbstractTableModel):
def __init__(self, *args, **kwargs):
self.__resetCount = 0
......
......@@ -54,6 +54,12 @@ class AwlInterfWidget(QWidget):
self.blockTypeEdit.dbChanged.connect(self.__handleBlockDBChange)
self.interfView.model().contentChanged.connect(self.contentChanged)
@property
def interfDef(self):
"""Get the active AwlInterfDef().
"""
return self.interfView.model().interf
def __handleBlockTypeChange(self):
if self.__changeSignalBlocked:
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment