Exemple #1
0
func (v *mappingView) Select2(obj interface{}, id string) {
	switch obj.(type) {
	case bh.NodeIf:
		p, ok := v.mapping.Mapped(id)
		if !ok {
			// todo: unmapped nodes
			return
		}
		var a graph.ArchIf
		a, ok = v.focusArchFromUserObject(p.Arch())
		if !ok {
			log.Printf("mappingView.Select error: arch %s not found\n", a.Name())
			return
		}
		/*
			pr := a.SelectProcess(p)
			if pr == nil {
				log.Printf("mappingView.Select error: process %v not found\n", p)
				return
			}
			* */
		for _, n := range v.nodes {
			// TODO: filenames...
			modified, _ := n.SelectNode(freesp.NodeIdFromString(n.Name(), ""),
				freesp.NodeIdFromString(id, ""))
			if modified {
				v.repaintArch(a)
			}
		}
	}
}
Exemple #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
}
Exemple #3
0
func (m *mapping) createMappingFromXml(xmlm *backend.XmlMapping) (err error) {
	var f fd.FileDataIf
	f, err = m.context.SignalGraphMgr().Access(xmlm.SignalGraph)
	if err != nil {
		err = fmt.Errorf("mapping.CreateMappingFromXml: graph.ReadFile failed: %s\n", err)
		return
	}
	m.graph = f.(bh.SignalGraphIf)
	f, err = m.context.PlatformMgr().Access(xmlm.Platform)
	if err != nil {
		err = fmt.Errorf("mapping.CreateMappingFromXml: platform.ReadFile failed: %s\n", err)
		return
	}
	m.platform = f.(pf.PlatformIf)
	var n bh.NodeIf
	var p pf.ProcessIf
	var ok bool
	for _, x := range xmlm.IOMappings {
		n, ok = m.graph.ItsType().NodeByName(x.Name)
		if !ok {
			err = fmt.Errorf("mapping.CreateMappingFromXml FIXME: node %s not in graph %s\n", x.Name, m.graph.Filename())
			continue
		}
		if len(x.Process) > 0 {
			p, ok = m.platform.ProcessByName(x.Process)
			if !ok {
				fmt.Printf("mapping.CreateMappingFromXml warning: process %s not in platform %s, assume unmapped\n", x.Process, m.platform.Filename())
				//continue
			}
		}
		nId := behaviour.NodeIdFromString(x.Name, m.Graph().Filename())
		m.maps[nId.String()] = mapelemNew(n, nId, p, m)
		m.maplist.Append(nId)
	}
	for _, x := range xmlm.Mappings {
		n, ok = m.graph.ItsType().NodeByPath(x.Name)
		if !ok {
			err = fmt.Errorf("mapping.CreateMappingFromXml FIXME: node %s not in graph %s\n", x.Name, m.graph.Filename())
			continue
		}
		if len(x.Process) > 0 {
			p, ok = m.platform.ProcessByName(x.Process)
			if !ok {
				fmt.Printf("mapping.CreateMappingFromXml warning: process %s not in platform %s\n", x.Process, m.platform.Filename())
				//continue
			}
		}
		nId := behaviour.NodeIdFromString(x.Name, m.Graph().Filename())
		m.maps[nId.String()] = mapelemNew(n, nId, p, m)
		m.maplist.Append(nId)
	}
	return
}
Exemple #4
0
func (v *signalGraphView) Select2(obj interface{}, id string) {
	switch obj.(type) {
	case bh.NodeIf:
		v.deselectConnects()
		v.selectNode(freesp.NodeIdFromString(id, v.graphId))
	case bh.PortIf:
		v.deselectConnects()
		n := v.selectNode(freesp.NodeIdFromString(id, v.graphId))
		if n != nil {
			n.SelectPort(obj.(bh.PortIf))
			v.repaintNode(n)
		}
	}
}
Exemple #5
0
func (v *signalGraphView) Sync() {
	g := v.sgType
	var selected bh.NodeIdIf
	var wasSelected bool
	if v.nodes != nil {
		selected, wasSelected = v.getSelectedNode()
	}
	v.nodes = make([]graph.NodeIf, len(g.Nodes()))

	var numberOfConnections = 0
	for _, n := range g.Nodes() {
		for _, p := range n.OutPorts() {
			numberOfConnections += len(p.Connections())
		}
	}
	v.connections = make([]graph.ConnectIf, numberOfConnections)

	getPositioner := func(nId bh.NodeIdIf) gr.ModePositioner {
		n, ok := g.NodeByPath(nId.String())
		if !ok {
			log.Panicf("getPositioner: could not find node %v\n", nId)
		}
		log.Printf("getPositioner(%v): node=%s\n", nId, n.Name())
		proxy := gr.PathModePositionerProxyNew(n)
		proxy.SetActivePath(nId.Parent().String())
		return proxy
	}
	for i, n := range g.Nodes() {
		nId := freesp.NodeIdFromString(n.Name(), v.graphId)
		if n.Expanded() {
			n.SetActiveMode(gr.PositionModeExpanded)
			v.nodes[i] = graph.ExpandedNodeNew(getPositioner, n, nId)
		} else {
			n.SetActiveMode(gr.PositionModeNormal)
			v.nodes[i] = graph.NodeNew(getPositioner, n, nId)
		}
	}
	var index = 0
	for _, n := range g.Nodes() {
		from := v.findNode(n.Name())
		for _, p := range n.OutPorts() {
			fromId := from.OutPortIndex(p.Name())
			for _, c := range p.Connections() {
				to := v.findNode(c.Node().Name())
				toId := to.InPortIndex(c.Name())
				v.connections[index] = graph.ConnectionNew(from, to, fromId, toId)
				index++
			}
		}
	}
	v.area.SetSizeRequest(v.calcSceneWidth(), v.calcSceneHeight())
	v.drawAll()
	if wasSelected {
		log.Printf("signalGraphView.Sync: select %v after sync\n", selected)
		v.selectNode(selected)
	}
}
Exemple #6
0
func (v signalGraphView) getSelectedNode() (id bh.NodeIdIf, ok bool) {
	for _, n := range v.nodes {
		id, ok = n.GetSelectedNode(freesp.NodeIdFromString(n.Name(), v.graphId))
		if ok {
			break
		}
	}
	return
}
Exemple #7
0
func (v *signalGraphView) selectNode(id bh.NodeIdIf) (node graph.NodeIf) {
	var n graph.NodeIf
	for _, n = range v.nodes {
		ok, nd := n.SelectNode(freesp.NodeIdFromString(n.Name(), v.graphId), id)
		if ok {
			v.repaintNode(n)
		}
		if nd != nil {
			node = nd
		}
	}
	return
}
Exemple #8
0
func (v *signalGraphView) handleNodeSelect(pos image.Point) {
	for _, n := range v.nodes {
		hit, _ := n.CheckHit(pos)
		if hit {
			nodeId := freesp.NodeIdFromString(n.Name(), v.graphId)
			selected, ok := n.GetHighlightedNode(nodeId)
			if !ok {
				log.Printf("signalGraphView.handleNodeSelect: FIXME: hit=true, GetSelectedNode() is not ok\n")
				return
			}
			selected.SetFilename(v.graphId)
			v.context.SelectNode(selected)
			port, ok := n.GetSelectedPort(nodeId)
			if ok {
				v.context.SelectPort(port, selected)
			}
		}
	}
}
Exemple #9
0
func (g *Global) nodePath(n bh.NodeIf, nCursor tr.Cursor, selectId bh.NodeIdIf) (cursor tr.Cursor) {
	ids := strings.Split(selectId.String(), "/")
	if len(ids) == 1 {
		cursor = nCursor
		return
	}
	nt := n.ItsType()
	for _, impl := range nt.Implementation() {
		if impl.ImplementationType() == bh.NodeTypeGraph {
			for _, nn := range impl.Graph().ProcessingNodes() {
				if nn.Name() == ids[1] {
					nnId := behaviour.NodeIdFromString(strings.Join(ids[1:], "/"), selectId.Filename())
					cursor = g.nodePath(nn, g.fts.CursorAt(nCursor, nn), nnId)
					break
				}
			}
			break
		}
	}
	return
}
Exemple #10
0
func (v *signalGraphView) ButtonCallback(area DrawArea, evType gdk.EventType, position image.Point) {
	pos := v.parent.Position(position)
	switch evType {
	case gdk.EVENT_BUTTON_PRESS:
		v.button1Pressed = true
		v.dragOffs = pos
		v.handleNodeSelect(pos)
		v.handleConnectSelect(pos)
	case gdk.EVENT_2BUTTON_PRESS:
		log.Println("areaButtonCallback 2BUTTON_PRESS")
		for _, n := range v.nodes {
			selected, ok := n.GetHighlightedNode(freesp.NodeIdFromString(n.Name(), v.graphId))
			if ok {
				v.context.EditNode(selected)
				break
			}
		}

	case gdk.EVENT_BUTTON_RELEASE:
		v.button1Pressed = false
	default:
	}
}
Exemple #11
0
func (v *mappingView) Sync() {
	g := v.mapping.Graph()
	//gFilename := g.Filename()
	v.nodes = make([]graph.NodeIf, len(g.Nodes()))
	var numberOfConnections = 0
	for _, n := range g.Nodes() {
		for _, p := range n.OutPorts() {
			numberOfConnections += len(p.Connections())
		}
	}
	v.connections = make([]graph.ConnectIf, numberOfConnections)
	// Construct node tree
	mapping := v.mapping
	getPositioner := func(nId bh.NodeIdIf) gr.ModePositioner {
		melem, ok := mapping.MappedElement(nId)
		if !ok {
			log.Printf("mappingView.Sync warning: no mapped element for node %s\n", nId)
			return gr.ModePositionerObjectNew()
		}
		return melem
	}
	for i, n := range g.Nodes() {
		nId := freesp.NodeIdFromString(n.Name(), g.Filename())
		melem, ok := v.mapping.MappedElement(nId)
		if !ok {
			log.Printf("mappingView.Sync error: node %s is expanded\n", n.Name())
			continue
		}
		if melem.Expanded() {
			n.SetExpanded(true)
			v.nodes[i] = graph.ExpandedNodeNew(getPositioner, n, nId)
		} else {
			melem.SetActiveMode(gr.PositionModeNormal)
			v.nodes[i] = graph.NodeNew(getPositioner, n, nId)
		}
	}
	// Construct edges
	var index = 0
	for _, n := range g.Nodes() {
		from, ok := v.findNode(n.Name())
		if !ok {
			log.Printf("mappingView.Sync error: from node %s not in nodelist\n", n.Name())
			continue
		}
		for _, p := range n.OutPorts() {
			fromId := from.OutPortIndex(p.Name())
			for _, c := range p.Connections() {
				to, ok := v.findNode(c.Node().Name())
				if !ok {
					log.Printf("mappingView.Sync error: to node %s not in nodelist\n", c.Node().Name())
					continue
				}
				toId := to.InPortIndex(c.Name())
				v.connections[index] = graph.ConnectionNew(from, to, fromId, toId)
				index++
			}
		}
	}
	// Construct node leaves mapping
	p := v.mapping.Platform()
	v.arch = make([]graph.ArchIf, len(p.Arch()))
	for i, a := range p.Arch() {
		v.arch[i] = graph.ArchMappingNew(a, v.nodes, v.mapping)
	}
	// Handle unmapped nodes
	var unmappedNodes []graph.NodeIf
	var unmappedIds []bh.NodeIdIf
	/*
		for _, n := range v.nodes {
			nId := freesp.NodeIdFromString(n.Name(), g.Filename())
			_, ok := v.mapping.Mapped(n.Name())
			if !ok {
				unmappedNodes = append(unmappedNodes, n)
				unmappedIds = append(unmappedIds, nId)
			}
		}
	*/
	for _, id := range v.mapping.MappedIds() {
		melem, ok := v.mapping.MappedElement(id)
		if !ok {
			log.Fatalf("mappingView.Sync FIXME: internal error inconsistent maplist\n")
		}
		if !melem.Expanded() {
			_, ok = melem.Process()
			if !ok { // we want unmapped nodes
				n, ok := findNodeByPath(v.nodes, melem.NodeId().String())
				if !ok {
					log.Printf("mappingView.Sync: unmapped node %s not found\n", melem.NodeId().String())
					continue
				}
				unmappedNodes = append(unmappedNodes, n)
				unmappedIds = append(unmappedIds, id)
			}
		}
	}
	for _, n := range v.nodes {
		if n.UserObj().Expanded() {
			n.Layout()
		}
	}
	v.unmapped = graph.ProcessMappingNew(unmappedNodes, unmappedIds, v.unmappedObj)
	v.area.SetSizeRequest(v.calcSceneWidth(), v.calcSceneHeight())
	v.drawAll()
}
Exemple #12
0
func (v *mappingView) handleArchSelect(pos image.Point) {
	for _, a := range v.arch {
		hit, _ := a.CheckHit(pos)
		if !hit {
			if a.Deselect() {
				v.repaintArch(a)
			}
			continue
		}
		if a.Select() {
			v.repaintArch(a)
		}
		v.context.SelectArch(a.UserObj())
		var ok bool
		var pr pf.ProcessIf
		var ch pf.ChannelIf
		var n graph.NodeIf
		var p graph.ProcessIf
		ok, pr, p = a.GetSelectedProcess()
		if !ok {
			continue
		}
		//log.Printf("mappingView.handleArchSelect: select process %v\n", pr)
		v.context.SelectProcess(pr)
		ok, ch = a.GetSelectedChannel()
		if ok {
			//log.Printf("mappingView.handleArchSelect: select channel %v\n", ch)
			v.context.SelectChannel(ch)
			continue
		}
		ok, n = p.(*graph.ProcessMapping).GetSelectedNode()
		if !ok {
			continue
		}
		var melem mp.MappedElementIf
		nId := freesp.NodeIdFromString(n.Name(), v.mapping.Graph().Filename())
		melem, ok = v.mapping.MappedElement(nId)
		if !ok {
			// todo: unmapped node
		} else {
			v.context.SelectMapElement(melem)
		}
	}
	hit, _ := v.unmapped.CheckHit(pos)
	if !hit {
		if v.unmapped.Deselect() {
			v.repaintUnmapped(v.unmapped)
		}
		return
	}
	if v.unmapped.Select() {
		v.repaintUnmapped(v.unmapped)
	}
	var ok bool
	var n graph.NodeIf
	//log.Printf("mappingView.handleArchSelect: select process %v\n", pr)
	ok, n = v.unmapped.(*graph.ProcessMapping).GetSelectedNode()
	if !ok {
		return
	}
	var melem mp.MappedElementIf
	nId := freesp.NodeIdFromString(n.Name(), v.mapping.Graph().Filename())
	melem, ok = v.mapping.MappedElement(nId)
	if !ok {
		// todo: unmapped node
	} else {
		v.context.SelectMapElement(melem)
	}
}