예제 #1
0
func (f *fileManagerSG) Access(name string) (sg tr.ToplevelTreeElementIf, err error) {
	var ok bool
	sg, ok = f.signalGraphMap[name]
	if ok {
		return
	}
	sg = behaviour.SignalGraphNew(name, f.context)
	var filedir string
	for _, filedir = range backend.XmlSearchPaths() {
		err = sg.ReadFile(fmt.Sprintf("%s/%s", filedir, name))
		if err == nil {
			break
		}
	}
	if err != nil {
		err = fmt.Errorf("fileManagerSG.Access: graph file %s not found.", name)
		return
	}
	var filename string
	if len(filedir) > 0 {
		filename = fmt.Sprintf("%s/%s", filedir, name)
	} else {
		filename = name
	}
	sg.SetPathPrefix(filedir)
	hint := backend.XmlGraphHintNew(name)
	hintfilename := f.HintFilename(filename)
	var buf []byte
	buf, err = tool.ReadFile(hintfilename)
	if err == nil {
		_, err = hint.Read(buf)
		if err != nil {
			return
		}
		err = behaviour.SignalGraphApplyHints(sg.(bh.SignalGraphIf), hint)
		if err != nil {
			err = fmt.Errorf("fileManagerSG.Access: %s", err)
			return
		}
	}
	var newId string
	newId, err = f.context.FTS().AddToplevel(sg.(bh.SignalGraphIf))
	if err != nil {
		err = fmt.Errorf("fileManagerSG.Access: %s", err)
		return
	}
	f.context.FTV().SelectId(newId)

	var gv views.GraphViewIf
	gv, err = views.SignalGraphViewNew(sg.(bh.SignalGraphIf), f.context)
	if err != nil {
		err = fmt.Errorf("fileManagerSG.Access: %s", err)
		return
	}
	f.context.GVC().Add(gv, name)
	f.signalGraphMap[name] = sg.(bh.SignalGraphIf)
	log.Printf("fileManagerSG.Access: graph %s successfully loaded.\n", name)

	return
}
예제 #2
0
func CreateXmlGraphHint(g bh.SignalGraphIf) (xmlg *backend.XmlGraphHint) {
	xmlg = backend.XmlGraphHintNew(g.Filename())
	for _, n := range g.ItsType().InputNodes() {
		xmlg.InputNode = append(xmlg.InputNode, *CreateXmlIONodePosHint(n, ""))
	}
	for _, n := range g.ItsType().OutputNodes() {
		xmlg.OutputNode = append(xmlg.OutputNode, *CreateXmlIONodePosHint(n, ""))
	}
	for _, n := range g.ItsType().ProcessingNodes() {
		hintlist := CreateXmlNodePosHint(n, "")
		for _, h := range hintlist {
			xmlg.ProcessingNode = append(xmlg.ProcessingNode, h)
		}
	}
	return
}