Ejemplo n.º 1
0
// For connection only: lookup matching ports to connect.
func getMatchingPorts(fts *models.FilesTreeStore, object tr.TreeElementIf) (ret []bh.PortIf) {
	var thisPort bh.PortIf
	switch object.(type) {
	case bh.PortIf:
		thisPort = object.(bh.PortIf)
	case bh.ConnectionIf:
		log.Fatal("getMatchingPorts error: expecting Port, not Connection")
	default:
		log.Fatal("getMatchingPorts error: expecting Port")
	}
	thisNode := thisPort.Node()
	graph := thisNode.Context()
	for _, n := range graph.Nodes() {
		var ports []bh.PortIf
		if thisPort.Direction() == gr.InPort {
			ports = n.OutPorts()
		} else {
			ports = n.InPorts()
		}
		for _, p := range ports {
			if p.SignalType().TypeName() == thisPort.SignalType().TypeName() {
				ret = append(ret, p)
			}
		}
	}
	return
}
Ejemplo n.º 2
0
func portConnect(port1 bh.PortIf, c *connection) error {
	p1 := port1.(*port)
	var port2 bh.PortIf
	var p2 *port
	if c.from.(*port) == p1 {
		port2 = c.to
	} else if c.to.(*port) == p1 {
		port2 = c.from
	}
	p2 = port2.(*port)
	if port1.SignalType().TypeName() != port2.SignalType().TypeName() {
		return fmt.Errorf("type mismatch")
	}
	if port1.Direction() == port2.Direction() {
		return fmt.Errorf("direction mismatch")
	}
	p1.connected.Append(port2.(*port))
	p1.conn = append(p1.conn, c)
	p2.connected.Append(port1.(*port))
	p2.conn = append(p2.conn, c)
	return nil
}
Ejemplo n.º 3
0
func CreateXmlOutPort(p bh.PortIf) (xmlp *backend.XmlOutPort) {
	xmlp = backend.XmlOutPortNew(p.Name(), p.SignalType().TypeName())
	xmlp.Entry = freesp.CreateXmlModePosition(p).Entry
	return
}