Ejemplo n.º 1
0
func (t *signalGraphType) AddNode(n bh.NodeIf) error {
	nType := n.ItsType()
	if !isAutoType(nType) {
		libname := nType.DefinedAt()
		if len(libname) == 0 {
			return fmt.Errorf("signalGraphType.AddNode error: node type %s has no DefinedAt...", nType.TypeName())
		}
		if !t.containsLibRef(libname) {
			lib, ok := freesp.GetLibraryByName(libname)
			if !ok {
				return fmt.Errorf("signalGraphType.AddNode error: library %s not registered", libname)
			}
			t.libraries = append(t.libraries, lib)
		}
	}
	return t.addNode(n)
}
Ejemplo n.º 2
0
func createSignalGraphTypeFromXml(g *backend.XmlSignalGraph, name string, context mod.ModelContextIf,
	resolvePort func(portname string, dir gr.PortDirection) *portType) (t *signalGraphType, err error) {
	t = SignalGraphTypeNew(context)
	for _, ref := range g.Libraries {
		l, ok := freesp.GetLibraryByName(ref.Name)
		if !ok {
			var f fd.FileDataIf
			f, err = t.context.LibraryMgr().Access(ref.Name)
			if err != nil {
				err = fmt.Errorf("createSignalGraphTypeFromXml error: referenced library file %s not found", ref.Name)
				return
			}
			l = f.(bh.LibraryIf)
			freesp.RegisterLibrary(l)
			fmt.Println("createSignalGraphTypeFromXml: library", ref.Name, "successfully loaded")
		}
		t.libraries = append(t.libraries, l)
	}
	for _, n := range g.InputNodes {
		var nnode *node
		nnode, err = t.createInputNodeFromXml(n, resolvePort)
		if err != nil {
			return
		}
		t.inputNodes = append(t.inputNodes, nnode)
		t.nodes.Append(nnode)
	}
	for _, n := range g.OutputNodes {
		var nnode *node
		nnode, err = t.createOutputNodeFromXml(n, resolvePort)
		if err != nil {
			return
		}
		t.outputNodes = append(t.outputNodes, nnode)
		t.nodes.Append(nnode)
	}
	for _, n := range g.ProcessingNodes {
		nnode := t.createNodeFromXml(n.XmlNode)
		t.processingNodes = append(t.processingNodes, nnode)
		t.nodes.Append(nnode)
	}
	for i, c := range g.Connections {
		n1, ok := t.NodeByName(c.From)
		if !ok {
			dump, _ := g.Write()
			log.Println("createSignalGraphTypeFromXml error:")
			log.Fatal(fmt.Sprintf("invalid edge %d: node %s not found\n%s", i, c.From, dump))
		}
		n2, ok := t.NodeByName(c.To)
		if !ok {
			dump, _ := g.Write()
			log.Println("createSignalGraphTypeFromXml error:")
			log.Fatal(fmt.Sprintf("invalid edge %d: node %s not found\n%s", i, c.To, dump))
		}
		p1, err := n1.(*node).outPortFromName(c.FromPort)
		if err != nil {
			dump, _ := g.Write()
			log.Println("createSignalGraphTypeFromXml error:")
			log.Printf("edge = %v\n", c)
			log.Printf("node = %v, missing port = %s\n", n1, c.FromPort)
			log.Fatal(fmt.Sprintf("invalid edge %d outPortFromName failed: %s\n%s", i, err, dump))
		}
		p2, err := n2.(*node).inPortFromName(c.ToPort)
		if err != nil {
			dump, _ := g.Write()
			log.Println("createSignalGraphTypeFromXml error:")
			log.Fatal(fmt.Sprintf("invalid edge %d inPortFromName failed: %s\n%s", i, err, dump))
		}
		err = p1.AddConnection(ConnectionNew(p1, p2))
		if err != nil {
			dump, _ := g.Write()
			log.Println("createSignalGraphTypeFromXml error:")
			log.Fatal(fmt.Sprintf("invalid edge %d PortConnect failed: %s\n%s", i, err, dump))
		}
	}
	return
}