Exemplo n.º 1
0
func CreateXmlMappingHint(m mp.MappingIf) (xmlm *backend.XmlMappingHint) {
	xmlm = backend.XmlMappingHintNew(m.Filename())
	for _, nId := range m.MappedIds() {
		melem, ok := m.MappedElement(nId)
		if !ok {
			log.Fatal("CreateXmlMappingHint internal error: inconsistent maplist.\n")
		}
		log.Printf("CreateXmlMappingHint(%s): nId=%s, melem.mode=%v, pos=%v\n", melem.NodeId(), nId.String(), melem.ActiveMode(), melem.Position())
		xmln := backend.XmlNodePosHintNew(nId.String())
		empty := image.Point{}
		for _, mod := range gr.ValidModes {
			pos := melem.ModePosition(mod)
			log.Printf("mod %v, pos=%v\n", mod, pos)
			if pos != empty {
				xmln.Entry = append(xmln.Entry, *backend.XmlModeHintEntryNew(string(mod), pos.X, pos.Y))
			}
		}
		for i, p := range melem.(*mapelem).inports {
			xmlp := backend.XmlPortPosHintNew(melem.(*mapelem).node.InPorts()[i].Name())
			log.Printf("CreateXmlMappingHint(inports):    xmlp=%s\n", xmlp.Name)
			for _, mod := range gr.ValidModes {
				pos := p.ModePosition(mod)
				log.Printf("   mod %v, pos=%v\n", mod, pos)
				if pos != empty {
					xmlp.Entry = append(xmlp.Entry, *backend.XmlModeHintEntryNew(string(mod), pos.X, pos.Y))
				}
			}
			xmln.InPorts = append(xmln.InPorts, *xmlp)
		}
		for i, p := range melem.(*mapelem).outports {
			xmlp := backend.XmlPortPosHintNew(melem.(*mapelem).node.OutPorts()[i].Name())
			log.Printf("CreateXmlMappingHint(outports):    xmlp=%s\n", xmlp.Name)
			for _, mod := range gr.ValidModes {
				pos := p.ModePosition(mod)
				log.Printf("   mod %v, pos=%v\n", mod, pos)
				if pos != empty {
					xmlp.Entry = append(xmlp.Entry, *backend.XmlModeHintEntryNew(string(mod), pos.X, pos.Y))
				}
			}
			xmln.OutPorts = append(xmln.InPorts, *xmlp)
		}
		xmlm.MappedNodes = append(xmlm.MappedNodes, *xmln)
	}
	return
}
Exemplo n.º 2
0
func (f *fileManagerMap) Access(name string) (m tr.ToplevelTreeElementIf, err error) {
	var ok bool
	m, ok = f.mappingMap[name]
	if ok {
		return
	}
	m = mapping.MappingNew(name, f.context)
	var filedir string
	for _, filedir = range backend.XmlSearchPaths() {
		err = m.ReadFile(fmt.Sprintf("%s/%s", filedir, name))
		if err != nil {
			log.Printf("fileManagerMap.Access error: %s\n", err)
		}
		if err == nil {
			break
		}
	}
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: mapping file %s not found.", name)
		return
	}
	var filename string
	if len(filedir) > 0 {
		filename = fmt.Sprintf("%s/%s", filedir, name)
	} else {
		filename = name
	}
	m.SetPathPrefix(filedir)
	// TODO: check consistency with graph/platform
	//mapping.AddMapping(n, nId, nil)
	//melem, _ = mapping.MappedElement(nId)
	err = f.Consistent(m.(mp.MappingIf))
	if err != nil {
		return
	}

	hint := backend.XmlMappingHintNew(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 = mapping.MappingApplyHints(m.(mp.MappingIf), hint)
		if err != nil {
			err = fmt.Errorf("fileManagerMap.Access: %s", err)
			return
		}
	}
	var newId string
	newId, err = f.context.FTS().AddToplevel(m.(mp.MappingIf))
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: %s", err)
		return
	}
	f.context.FTV().SelectId(newId)
	var mv views.GraphViewIf
	mv, err = views.MappingViewNew(m.(mp.MappingIf), f.context)
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: Could not create platform view.")
		return
	}
	f.context.GVC().Add(mv, name)
	log.Printf("fileManagerMap.Access: platform %s successfully loaded.\n", name)
	f.mappingMap[name] = m.(mp.MappingIf)
	return
}