Esempio n. 1
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)
	}
}
Esempio n. 2
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()
}