示例#1
0
func (p *process) RemoveObject(tree tr.TreeIf, cursor tr.Cursor) (removed []tr.IdWithObject) {
	parent := tree.Parent(cursor)
	if p != tree.Object(parent) {
		log.Fatal("process.RemoveObject error: not removing child of mine.")
	}
	obj := tree.Object(cursor)
	switch obj.(type) {
	case pf.ChannelIf:
		c := obj.(pf.ChannelIf)
		cc := c.Link()
		pp := cc.Process()
		ppCursor := tree.Cursor(pp) // TODO. better search over platform...
		ccCursor := tree.CursorAt(ppCursor, cc)
		var l *channelList
		var ll *channelList
		if c.Direction() == gr.InPort {
			l = &p.inChannels
			ll = &pp.(*process).outChannels
		} else {
			l = &p.outChannels
			ll = &pp.(*process).inChannels
		}
		l.Remove(c)
		ll.Remove(cc)
		tree.Remove(ccCursor)
		prefix, index := tree.Remove(cursor)
		removed = append(removed, tr.IdWithObject{prefix, index, c})

	default:
		log.Fatalf("Port.RemoveObject error: invalid type %T: %v\n", obj, obj)
	}
	return
}
示例#2
0
文件: port.go 项目: axel-freesp/sge
func (p *port) treeRemoveObject(tree tr.TreeIf, cursor tr.Cursor, conn bh.ConnectionIf, otherPort bh.PortIf) (removed []tr.IdWithObject) {
	contextCursor := tree.Parent(tree.Parent(tree.Parent(cursor)))
	pCursor := tree.CursorAt(contextCursor, otherPort)
	otherCursor := tree.CursorAt(pCursor, conn)
	prefix, index := tree.Remove(cursor)
	removed = append(removed, tr.IdWithObject{prefix, index, conn})
	tree.Remove(otherCursor)
	return
}
示例#3
0
文件: port.go 项目: axel-freesp/sge
func (p *port) treeAddNewObject(tree tr.TreeIf, cursor tr.Cursor, conn bh.ConnectionIf, otherPort bh.PortIf) (newCursor tr.Cursor) {
	newCursor = tree.Insert(cursor)
	conn.AddToTree(tree, newCursor)
	contextCursor := tree.Parent(tree.Parent(cursor))
	cCursor := tree.CursorAt(contextCursor, otherPort)
	cChild := tree.Append(cCursor)
	conn.AddToTree(tree, cChild)
	return
}
示例#4
0
文件: port.go 项目: axel-freesp/sge
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
}
示例#5
0
func (t *nodeType) treeInstObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor) {
	switch obj.(type) {
	case bh.ImplementationIf:
		impl := obj.(bh.ImplementationIf)
		// update all instance nodes in the tree with new implementation
		for _, n := range t.Instances() {
			nCursor := tree.Cursor(n)
			tCursor := tree.CursorAt(nCursor, t)
			tCursor.Position = len(t.Implementation()) - 1
			newICursor := tree.Insert(tCursor)
			impl.AddToTree(tree, newICursor)
		}

	case bh.PortTypeIf:
		pt := obj.(bh.PortTypeIf)
		// update all instance nodes in the tree with new port
		for _, n := range t.Instances() {
			var p bh.PortIf
			var ok bool
			if pt.Direction() == gr.InPort {
				p, ok, _ = n.(*node).inPort.Find(n.Name(), pt.Name())
			} else {
				p, ok, _ = n.(*node).outPort.Find(n.Name(), pt.Name())
			}
			if !ok {
				log.Fatalf("nodeType.treeInstObject error: port %s not found.\n", pt.Name())
			}
			nCursor := tree.Cursor(n)
			// Insert new port at the same position as in the type:
			// Need to deal with implementations in type VS type in node
			if cursor.Position >= 0 {
				nCursor.Position = cursor.Position - len(t.Implementation()) + 1
			}
			newNCursor := tree.Insert(nCursor)
			p.AddToTree(tree, newNCursor)
			// Update mirrored type in node:
			tCursor := tree.CursorAt(nCursor, t)
			tCursor.Position = cursor.Position
			t.treeNewObject(tree, tCursor, obj)
		}

	default:
		log.Fatalf("nodeType.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
示例#6
0
func (t *nodeType) treeNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor) {
	switch obj.(type) {
	case bh.ImplementationIf:
		cursor.Position = len(t.Implementation()) - 1
		newCursor = tree.Insert(cursor)
		obj.(bh.ImplementationIf).AddToTree(tree, newCursor)

	case bh.PortTypeIf:
		pt := obj.(bh.PortTypeIf)
		newCursor = tree.Insert(cursor)
		pt.AddToTree(tree, newCursor)
		for _, impl := range t.Implementation() {
			if impl.ImplementationType() == bh.NodeTypeGraph {
				// bh.NodeIf linked to outer port
				g := impl.Graph().(*signalGraphType)
				var n bh.NodeIf
				index := -len(t.Implementation())
				if pt.Direction() == gr.InPort {
					n = g.findInputNodeFromPortType(pt)
					if cursor.Position == tr.AppendCursor {
						index += len(g.InputNodes())
					}
				} else {
					n = g.findOutputNodeFromPortType(pt)
					if cursor.Position == tr.AppendCursor {
						index += len(g.InputNodes()) + len(g.OutputNodes())
					}
				}
				if n == nil {
					log.Fatalf("nodeType.AddNewObject error: invalid implementation...\n")
				}
				if cursor.Position != tr.AppendCursor {
					index += cursor.Position
				}
				gCursor := tree.CursorAt(cursor, impl)
				gCursor.Position = index
				n.AddToTree(tree, tree.Insert(gCursor))
			}
		}

	default:
		log.Fatalf("nodeType.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
示例#7
0
func (t *signalGraphType) RemoveObject(tree tr.TreeIf, cursor tr.Cursor) (removed []tr.IdWithObject) {
	obj := tree.Object(cursor)
	switch obj.(type) {
	case bh.NodeIf:
		n := obj.(bh.NodeIf)
		// Remove all connections first
		for _, p := range n.OutPorts() {
			for _, c := range p.Connections() {
				conn := p.Connection(c)
				cCursor := tree.CursorAt(cursor, conn)
				del := p.RemoveObject(tree, cCursor)
				for _, d := range del {
					removed = append(removed, d)
				}
			}
		}
		for _, p := range n.InPorts() {
			for _, c := range p.Connections() {
				conn := p.Connection(c)
				cCursor := tree.CursorAt(cursor, conn)
				del := p.RemoveObject(tree, cCursor)
				for _, d := range del {
					removed = append(removed, d)
				}
			}
		}
		parentCursor := tree.Parent(cursor)
		parent := tree.Object(parentCursor)
		switch parent.(type) {
		case bh.SignalGraphIf:
		case bh.ImplementationIf:
			// propagate new node to all instances of embracing type
			pCursor := tree.Parent(parentCursor)
			nt := tree.Object(pCursor)
			for _, nn := range nt.(bh.NodeTypeIf).Instances() {
				nCursor := tree.Cursor(nn)
				tCursor := tree.CursorAt(nCursor, parent)
				tree.Remove(tree.CursorAt(tCursor, n))
			}

		default:
			log.Fatalf("signalGraphType.RemoveObject error: wrong parent type %t: %v\n", parent, parent)
		}
		prefix, index := tree.Remove(cursor)
		removed = append(removed, tr.IdWithObject{prefix, index, obj})
		t.RemoveNode(n)

	default:
		log.Fatalf("signalGraphType.RemoveObject error: wrong type %t: %v", obj, obj)
	}
	return
}
示例#8
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
}
示例#9
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
}
示例#10
0
文件: port.go 项目: axel-freesp/sge
func (p *port) RemoveObject(tree tr.TreeIf, cursor tr.Cursor) (removed []tr.IdWithObject) {
	parent := tree.Parent(cursor)
	if p != tree.Object(parent) {
		log.Fatal("port.RemoveObject error: not removing child of mine.")
	}
	obj := tree.Object(cursor)
	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()
			if p != thisPort {
				log.Fatal("port.RemoveObject error: invalid connection ", conn)
			}
		} else {
			otherPort = conn.To()
			thisPort = conn.From()
			if p != thisPort {
				log.Fatal("port.RemoveObject error: invalid connection ", conn)
			}
		}
		contextCursor := tree.Parent(tree.Parent(tree.Parent(cursor)))
		removed = p.treeRemoveObject(tree, cursor, conn, otherPort)
		context := tree.Object(contextCursor)
		switch context.(type) {
		case bh.SignalGraphIf:
		case bh.ImplementationIf:
			// propagate removed 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)
				cCursor := tree.CursorAt(pCursor, conn)
				p.treeRemoveObject(tree, cCursor, conn, otherPort)
			}

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

	default:
		log.Fatalf("bh.PortIf.RemoveObject error: invalid type %T: %v\n", obj, obj)
	}
	return
}
示例#11
0
func (t *nodeType) treeRemoveObject(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:
		impl := obj.(bh.ImplementationIf)
		if impl.ImplementationType() == bh.NodeTypeGraph {
			// TODO: This is redundant with implementation.go
			// Simply remove all nodes? Do not traverse a modifying list...
			// Removed Input- and Output nodes are NOT stored (they are
			// created automatically when adding the implementation graph).
			// Return all removed edges ...
			for _, n := range impl.Graph().Nodes() {
				nCursor := tree.Cursor(n)
				for _, p := range n.OutPorts() {
					pCursor := tree.CursorAt(nCursor, p)
					for index, c := range p.Connections() {
						conn := p.Connection(c)
						removed = append(removed, tr.IdWithObject{pCursor.Path, index, conn})
					}
				}
			}
			// ... and processing nodes
			for _, n := range impl.Graph().ProcessingNodes() {
				nCursor := tree.Cursor(n)
				gCursor := tree.Parent(nCursor)
				nIndex := gCursor.Position
				removed = append(removed, tr.IdWithObject{nCursor.Path, nIndex, n})
			}
		}

	case bh.PortTypeIf:
		nt := obj.(bh.PortTypeIf)
		for _, impl := range t.Implementation() {
			if impl.ImplementationType() == bh.NodeTypeGraph {
				// Remove and store all edges connected to the nodes linked to the outer ports
				g := impl.Graph().(*signalGraphType)
				var n bh.NodeIf
				if nt.Direction() == gr.InPort {
					n = g.findInputNodeFromPortType(nt)
				} else {
					n = g.findOutputNodeFromPortType(nt)
				}
				if n == nil {
					log.Fatalf("nodeType.RemoveObject error: invalid implementation...\n")
				}
				nCursor := tree.CursorAt(parentId, n)
				for _, p := range n.InPorts() {
					pCursor := tree.CursorAt(nCursor, p)
					for _, c := range p.Connections() {
						conn := p.Connection(c)
						removed = append(removed, tr.IdWithObject{pCursor.Path, -1, conn})
					}
				}
				for _, p := range n.OutPorts() {
					pCursor := tree.CursorAt(nCursor, p)
					for _, c := range p.Connections() {
						conn := p.Connection(c)
						removed = append(removed, tr.IdWithObject{pCursor.Path, -1, conn})
					}
				}
				// Remove (but dont store) the nodes linked to the outer ports:
				tree.Remove(nCursor)
			}
		}

	default:
		log.Fatalf("nodeType.RemoveObject error: invalid type %T\n", obj)
	}
	return
}
示例#12
0
文件: arch.go 项目: axel-freesp/sge
func (a *arch) RemoveObject(tree tr.TreeIf, cursor tr.Cursor) (removed []tr.IdWithObject) {
	parent := tree.Parent(cursor)
	if a != tree.Object(parent) {
		log.Printf("arch.RemoveObject error: not removing child of mine.")
		return
	}
	obj := tree.Object(cursor)
	switch obj.(type) {
	case pf.IOTypeIf:
		t := obj.(pf.IOTypeIf)
		_, ok := a.iotypes.Find(t.Name())
		if ok {
			a.iotypes.Remove(t)
		} else {
			log.Printf("arch.RemoveObject error: iotype to be removed not found.\n")
		}
		prefix, index := tree.Remove(cursor)
		removed = append(removed, tr.IdWithObject{prefix, index, t})

	case pf.ProcessIf:
		p := obj.(pf.ProcessIf)
		if p.Arch() != a {
			log.Printf("arch.RemoveObject error: process to be removed is no child of mine.")
		}
		_, ok := a.processes.Find(p.Name())
		if ok {
			a.processes.Remove(p)
		} else {
			log.Printf("arch.RemoveObject error: process to be removed not found.\n")
		}
		for _, c := range p.InChannels() {
			cc := c.Link()
			pp := cc.Process()
			ppCursor := tree.Cursor(pp) // TODO: better search over platform...
			ccCursor := tree.CursorAt(ppCursor, cc)
			//log.Printf("arch.RemoveObject: remove %v\n", cc)
			pp.(*process).outChannels.Remove(cc)
			prefix, index := tree.Remove(ccCursor)
			removed = append(removed, tr.IdWithObject{prefix, index, cc})
		}
		for _, c := range p.InChannels() {
			p.(*process).inChannels.Remove(c)
		}
		for _, c := range p.OutChannels() {
			cc := c.Link()
			pp := cc.Process()
			ppCursor := tree.Cursor(pp) // TODO: better search over platform...
			ccCursor := tree.CursorAt(ppCursor, cc)
			//log.Printf("arch.RemoveObject: remove %v\n", cc)
			pp.(*process).inChannels.Remove(cc)
			prefix, index := tree.Remove(ccCursor)
			removed = append(removed, tr.IdWithObject{prefix, index, cc})
		}
		for _, c := range p.OutChannels() {
			p.(*process).outChannels.Remove(c)
		}
		prefix, index := tree.Remove(cursor)
		removed = append(removed, tr.IdWithObject{prefix, index, p})
		//log.Printf("arch.RemoveObject: successfully removed process %v\n", p)

	default:
		log.Fatalf("arch.AddNewObject error: invalid type %T\n", obj)
	}
	return
}