func (s *signalGraph) RemoveFromTree(tree tr.TreeIf) { gt := s.ItsType() tree.Remove(tree.Cursor(s)) for len(gt.Nodes()) > 0 { gt.RemoveNode(gt.Nodes()[0].(*node)) } }
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 }
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 }
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 }
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 }
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 }
// 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 }
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 }
func (m *mapping) RemoveFromTree(tree tr.TreeIf) { tree.Remove(tree.Cursor(m)) }
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 }
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 }
func (p *process) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) { if obj == nil { err = fmt.Errorf("process.AddNewObject error: %v nil object", p) return } switch obj.(type) { case pf.ChannelIf: c := obj.(*channel) c.process = p cLinkText := c.linkText link := strings.Split(cLinkText, "/") if len(link) != 2 { err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s (abort)\n", p, c.linkText) return } archlist := p.Arch().Platform().(*platform).archlist aa, ok := archlist.Find(link[0]) if !ok { err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s: no such arch (abort)\n", p, c.linkText) return } var pp pf.ProcessIf pp, ok = aa.(*arch).processes.Find(link[1]) if !ok { err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s: no such process (abort)\n", p, c.linkText) return } var l *channelList var dd gr.PortDirection var ll *channelList var cPos, ccPos int if c.Direction() == gr.InPort { l = &p.inChannels ll = &pp.(*process).outChannels dd = gr.OutPort cPos = len(l.Channels()) ccPos = tr.AppendCursor } else { l = &p.outChannels ll = &pp.(*process).inChannels dd = gr.InPort cPos = tr.AppendCursor ccPos = len(ll.Channels()) } cName := channelMakeName(c.iotype, pp) _, ok = l.Find(cName) if ok { err = fmt.Errorf("process.AddNewObject warning: %v duplicate %v channel name %s/%s (abort)\n", p, c.Direction(), c.linkText, c.iotype.Name()) return } ccLinkText := fmt.Sprintf("%s/%s", p.Arch().Name(), p.Name()) ccName := channelMakeName(c.iotype, p) _, ok = l.Find(ccName) _, ok = ll.Find(cName) if ok { err = fmt.Errorf("process.AddNewObject warning: %v duplicate %v channel name %s/%s on other side (abort)\n", pp, dd, ccLinkText, c.iotype.Name()) return } cc := ChannelNew(dd, c.iotype, pp, ccLinkText) cc.link = c c.link = cc l.Append(c) ll.Append(cc) ppCursor := tree.Cursor(pp) if ppCursor.Position == tr.AppendCursor { ppCursor.Position = ccPos } newCursor = tree.Insert(ppCursor) cc.AddToTree(tree, newCursor) if cursor.Position == tr.AppendCursor { cursor.Position = cPos } newCursor = tree.Insert(cursor) c.AddToTree(tree, newCursor) if p.Arch().Name() != aa.Name() { p.Arch().(*arch).AddArchPort(c) aa.(*arch).AddArchPort(cc) } //log.Printf("process.AddNewObject: %v successfully added channel %v\n", p, c) default: log.Fatalf("process.AddNewObject error: invalid type %T\n", obj) } return }
func (l *library) RemoveFromTree(tree tr.TreeIf) { tree.Remove(tree.Cursor(l)) freesp.RemoveRegisteredLibrary(l) }