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 }
func (t *signalGraphType) treeAddNewObject(tree tr.TreeIf, cursor tr.Cursor, n bh.NodeIf) (newCursor tr.Cursor) { newCursor = tree.Insert(cursor) n.AddToTree(tree, newCursor) return }