示例#1
0
文件: port.go 项目: axel-freesp/sge
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]
}
示例#2
0
func (t *signalGraphType) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	switch obj.(type) {
	case bh.NodeIf:
		// TODO: Check if IO node and exists: copy position only and return
		n := obj.(bh.NodeIf)
		err = t.AddNode(n)
		if err != nil {
			err = fmt.Errorf("signalGraphType.AddNewObject error: %s", err)
			nt := n.ItsType().(*nodeType)
			if nt != nil {
				ok, _ := nt.instances.Find(n)
				if ok {
					nt.instances.Remove(n)
				}
			}
			return
		}
		newCursor = t.treeAddNewObject(tree, cursor, n)

		parent := tree.Object(cursor)
		switch parent.(type) {
		case bh.SignalGraphIf:
		case bh.ImplementationIf:
			// propagate new node to all instances of embracing type
			pCursor := tree.Parent(cursor)
			nt := tree.Object(pCursor)
			for _, nn := range nt.(bh.NodeTypeIf).Instances() {
				nCursor := tree.Cursor(nn)
				tCursor := tree.CursorAt(nCursor, parent)
				tCursor.Position = cursor.Position
				t.treeAddNewObject(tree, tCursor, n)
			}

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

	case bh.ConnectionIf:
		conn := obj.(bh.ConnectionIf)
		var n bh.NodeIf
		var p bh.PortIf
		for _, n = range t.Nodes() {
			if n.Name() == conn.From().Node().Name() {
				nCursor := tree.CursorAt(cursor, n)
				for _, p = range n.OutPorts() {
					if conn.From().Name() == p.Name() {
						pCursor := tree.CursorAt(nCursor, p)
						return p.AddNewObject(tree, pCursor, obj)
					}
				}
			}
		}
	default:
		log.Fatalf("signalGraphType.AddNewObject error: wrong type %t: %v\n", obj, obj)
	}
	return
}
示例#3
0
文件: port.go 项目: axel-freesp/sge
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]
}
示例#4
0
// Remove object mirrored in all instance node type
func (t *nodeType) treeRemoveInstObject(tree tr.TreeIf, cursor tr.Cursor) (removed []tr.IdWithObject) {
	parentId := tree.Parent(cursor)
	if t != tree.Object(parentId) {
		log.Fatal("nodeType.RemoveObject error: not removing child of mine.")
	}
	obj := tree.Object(cursor)
	switch obj.(type) {
	case bh.ImplementationIf:
		for _, n := range t.Instances() {
			nCursor := tree.Cursor(n)
			tCursor := tree.CursorAt(nCursor, t)
			iCursor := tree.CursorAt(tCursor, obj)
			iCursor.Position = cursor.Position
			tree.Remove(iCursor)
		}

	case bh.PortTypeIf:
		nt := obj.(bh.PortTypeIf)
		for _, n := range t.Instances() {
			var p bh.PortIf
			var list []bh.PortIf
			nCursor := tree.Cursor(n)
			if nt.Direction() == gr.InPort {
				list = n.InPorts()
			} else {
				list = n.OutPorts()
			}
			for _, p = range list {
				if p.Name() == nt.Name() {
					break
				}
			}
			_ = p.(*port)
			pCursor := tree.CursorAt(nCursor, p)
			prefix, index := tree.Remove(pCursor)
			removed = append(removed, tr.IdWithObject{prefix, index, p})
			tCursor := tree.CursorAt(nCursor, obj)
			del := t.treeRemoveObject(tree, tCursor)
			for _, d := range del {
				removed = append(removed, d)
			}
			tree.Remove(tCursor)
		}

	default:
		log.Fatalf("nodeType.RemoveObject error: invalid type %T\n", obj)
	}
	return
}
示例#5
0
文件: port.go 项目: axel-freesp/sge
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]
}
示例#6
0
文件: node.go 项目: axel-freesp/sge
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
}
示例#7
0
func CreateXmlOutPort(p bh.PortIf) (xmlp *backend.XmlOutPort) {
	xmlp = backend.XmlOutPortNew(p.Name(), p.SignalType().TypeName())
	xmlp.Entry = freesp.CreateXmlModePosition(p).Entry
	return
}