Esempio n. 1
0
func (p *port) Connection(c bh.PortIf) bh.ConnectionIf {
	_, ok, index := p.connected.Find(c.Node().Name(), c.Name())
	if !ok {
		log.Fatalf("port.bh.ConnectionIf error: port %v not in connected list of port %v\n", c, p)
	}
	return p.conn[index]
}
Esempio n. 2
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
}
Esempio n. 3
0
func (p *port) RemoveConnection(c bh.PortIf) {
	_, ok, index := p.connected.Find(c.Node().Name(), c.Name())
	if !ok {
		log.Fatalf("port.bh.ConnectionIf error: port %v not in connected list of port %v\n", c, p)
	}
	p.connected.Remove(c)
	for index++; index < len(p.conn); index++ {
		p.conn[index-1] = p.conn[index]
	}
	p.conn = p.conn[:len(p.conn)-1]
}
Esempio n. 4
0
func (p *port) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	switch obj.(type) {
	case bh.ConnectionIf:
		conn := obj.(bh.ConnectionIf)
		var thisPort, otherPort bh.PortIf
		if p.Direction() == gr.InPort {
			otherPort = conn.From()
			thisPort = conn.To()
		} else {
			otherPort = conn.To()
			thisPort = conn.From()
		}
		if p != thisPort {
			log.Println("p =", p)
			log.Println("thisPort =", thisPort)
			log.Fatal("port.AddNewObject error: invalid connection ", conn)
		}
		sgt := thisPort.Node().Context()
		if sgt != otherPort.Node().Context() {
			log.Fatal("port.AddNewObject error: nodes have different context: ", conn)
		}
		contextCursor := tree.Parent(tree.Parent(cursor))

		thisPort.AddConnection(conn)
		newCursor = p.treeAddNewObject(tree, cursor, conn, otherPort)

		context := tree.Object(contextCursor)
		switch context.(type) {
		case bh.SignalGraphIf:
		case bh.ImplementationIf:
			// propagate new edge to all instances of embracing type
			nt := tree.Object(tree.Parent(contextCursor))
			for _, nn := range nt.(bh.NodeTypeIf).Instances() {
				nCursor := tree.Cursor(nn)
				tCursor := tree.CursorAt(nCursor, context)
				pCursor := tree.CursorAt(tCursor, p)
				pCursor.Position = cursor.Position

				p.treeAddNewObject(tree, pCursor, conn, otherPort)
			}

		default:
			log.Fatalf("port.AddNewObject error: wrong context type %T: %v\n", context, context)
		}

	default:
		log.Fatalf("port.AddNewObject error: invalid type %T: %v\n", obj, obj)
	}
	return
}
Esempio n. 5
0
func updateConnections(p bh.PortIf, fts *models.FilesTreeStore) {
	nodeCursor := fts.Cursor(p.Node())
	portCursor := fts.CursorAt(nodeCursor, p)
	for _, c := range p.Connections() {
		conn := p.Connection(c)
		connCursor := fts.CursorAt(portCursor, conn)
		otherNode := c.Node()
		otherNodeCursor := fts.Cursor(otherNode)
		otherPortCursor := fts.CursorAt(otherNodeCursor, c)
		otherConnCursor := fts.CursorAt(otherPortCursor, conn)
		connText := fmt.Sprintf("%s/%s -> %s/%s",
			conn.From().Node().Name(), conn.From().Name(),
			conn.To().Node().Name(), conn.To().Name())
		fts.SetValueById(connCursor.Path, connText)
		fts.SetValueById(otherConnCursor.Path, connText)
	}
}
Esempio n. 6
0
func (l *portList) Remove(p bh.PortIf) {
	var i int
	for i = range l.ports {
		if p.Node().Name() == l.ports[i].Node().Name() && p.Name() == l.ports[i].Name() {
			break
		}
	}
	if i >= len(l.ports) {
		for _, v := range l.ports {
			log.Printf("portList.RemovePort have bh.PortIf %v\n", v)
		}
		log.Fatalf("portList.RemovePort error: bh.PortIf %v not in this list\n", p)
	}
	for i++; i < len(l.ports); i++ {
		l.ports[i-1] = l.ports[i]
	}
	l.ports = l.ports[:len(l.ports)-1]
}