Пример #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
}
Пример #2
0
func (n *Node) SelectPort(port bh.PortIf) {
	var index int
	if port.Direction() == gr.InPort {
		index = n.InPortIndex(port.Name())
	} else {
		index = n.OutPortIndex(port.Name())
		if index >= 0 {
			index += n.NumInPorts()
		}
	}
	for i, p := range n.ports {
		if i == index {
			p.Select()
		} else {
			p.Deselect()
		}
	}
	n.selectedPort = index
}
Пример #3
0
func PortNew(box image.Rectangle, userObj bh.PortIf) *Port {
	var config DrawConfig
	if userObj.Direction() == gr.InPort {
		config = DrawConfig{ColorInit(ColorOption(InputPort)),
			ColorInit(ColorOption(HighlightInPort)),
			ColorInit(ColorOption(SelectInPort)),
			ColorInit(ColorOption(BoxFrame)),
			Color{},
			image.Point{}}
	} else {
		config = DrawConfig{ColorInit(ColorOption(OutputPort)),
			ColorInit(ColorOption(HighlightOutPort)),
			ColorInit(ColorOption(SelectOutPort)),
			ColorInit(ColorOption(BoxFrame)),
			Color{},
			image.Point{}}
	}
	return &Port{SelectableBoxInit(box, config), userObj}
}
Пример #4
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
}