Ejemplo n.º 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
}
Ejemplo n.º 2
0
func (f *fileManagerSG) New() (sg tr.ToplevelTreeElementIf, err error) {
	filename := f.NewFilename()
	sg = behaviour.SignalGraphNew(filename, f.context)
	f.signalGraphMap[filename] = sg.(bh.SignalGraphIf)
	var newId string
	newId, err = f.context.FTS().AddToplevel(sg.(bh.SignalGraphIf))
	if err != nil {
		err = fmt.Errorf("fileManagerSG.New: %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.New: %s", err)
		return
	}
	f.context.GVC().Add(gv, filename)
	f.context.ShowAll()
	return
}