Пример #1
0
func MappingApplyHints(m mp.MappingIf, xmlhints *backend.XmlMappingHint) (err error) {
	if m.Filename() != xmlhints.Ref {
		err = fmt.Errorf("MappingApplyHints error: filename mismatch\n")
		return
	}
	//log.Printf("MappingApplyHints: xmlhints = %v\n", xmlhints)
	for _, nId := range m.MappedIds() {
		melem, ok := m.MappedElement(nId)
		if !ok {
			log.Fatalf("MappingApplyHints internal error: %v has no mapping\n", nId)
		}
		log.Printf("MappingApplyHints: %v\n", nId)
		xmlh, ok := findMapHint(xmlhints, nId.String())
		if ok {
			melem.SetExpanded(xmlh.Expanded)
			log.Printf("MappingApplyHints: %v expanded: %v\n", nId, melem.Expanded())
			freesp.ModePositionerApplyHints(melem, xmlh.XmlModeHint)
			for i, xmlp := range xmlh.InPorts {
				freesp.ModePositionerApplyHints(&melem.(*mapelem).inports[i], xmlp.XmlModeHint)
			}
			for i, xmlp := range xmlh.OutPorts {
				freesp.ModePositionerApplyHints(&melem.(*mapelem).outports[i], xmlp.XmlModeHint)
			}
		}
	}
	return
}
Пример #2
0
func (f *fileManagerMap) Consistent(m mp.MappingIf) (err error) {
	nodelist := m.Graph().ItsType().Nodes()
	idlist := m.MappedIds()
	for _, n := range nodelist {
		// check that every node has a mapping
		if !findNodeInIdList(n, behaviour.NodeIdFromString("", m.Graph().Filename()), idlist) {
			// TODO: add missing mapping(s)
			err = fmt.Errorf("fileManagerMap.Consistent error: node %s is not fully mapped\n", n.Name())
			return
		}
		addExpandedMappings(m, n, behaviour.NodeIdFromString("", m.Graph().Filename()))
	}
	for _, id := range idlist {
		// check that every mapping has a node
		melem, ok := m.MappedElement(id)
		if !ok {
			// Should never occur, nothing to recover though...
			err = fmt.Errorf("fileManagerMap.Consistent error: invalid maplist\n")
			return
		}
		n := melem.Node()
		if n == nil {
			// TODO: remove this mapping from mappings
			err = fmt.Errorf("fileManagerMap.Consistent error: mapping %s has no node\n", id)
			return
		}
	}
	return
}
Пример #3
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
}