from . import odict
from Element import Element
-from Block import Block
-from Connection import Connection
from .. gui import Messages
class FlowGraph(Element):
def get_block(self, id): return filter(lambda b: b.get_id() == id, self.get_blocks())[0]
def get_blocks(self): return filter(lambda e: e.is_block(), self.get_elements())
def get_connections(self): return filter(lambda e: e.is_connection(), self.get_elements())
+ def get_children(self): return self.get_elements()
def get_elements(self):
"""
Get a list of all the elements.
@param key the block key
@return the new block or None if not found
"""
- self.flag()
if key not in self.get_parent().get_block_keys(): return None
block = self.get_parent().get_new_block(self, key)
self.get_elements().append(block)
@throw Exception bad connection
@return the new connection
"""
- self.flag()
- connection = self.get_parent().Connection(self, porta, portb)
+ connection = self.get_parent().Connection(flow_graph=self, porta=porta, portb=portb)
self.get_elements().append(connection)
return connection
If the element is a block, remove its connections.
If the element is a connection, just remove the connection.
"""
- self.flag()
if element not in self.get_elements(): return
#found a port, set to parent signal block
if element.is_port():
"""
raise NotImplementedError
- def validate(self):
- """
- Validate the flow graph.
- All connections and blocks must be valid.
- """
- Element.validate(self)
- for c in self.get_elements():
- try:
- c.validate()
- assert c.is_valid()
- except AssertionError: self.add_error_message('Element "%s" is not valid.'%c)
-
##############################################
## Import/Export Methods
##############################################
#only load the block when the block key was valid
if block: block.import_data(block_n)
else: Messages.send_error_load('Block key "%s" not found in %s'%(key, self.get_parent()))
- self.validate() #validate all blocks before connections are made (in case of nports)
#build the connections
for connection_n in connections_n:
#try to make the connection
#build the connection
self.connect(source, sink)
except AssertionError: Messages.send_error_load('Connection between %s(%s) and %s(%s) could not be made.'%(source_block_id, source_key, sink_block_id, sink_key))
+ self.rewrite() #global rewrite