/// <summary> /// Gets interface from node /// </summary> /// <param name="node">The node</param> /// <param name="inter">Prototype</param> /// <returns>The interface</returns> public static IDrawingInterface GetInterface(XElement node, IDrawingInterface inter) { if (node is XElement) { XElement el = node as XElement; IDrawingInterface id = inter.GetDrawing(el); if (id != null) { return(id); } } XElement parent = node.Parent; if (parent == null) { return(inter); } IDrawingInterface ind = GetInterface(parent, inter); if (ind != null) { return(ind); } return(inter); }
IDrawingInterface IDrawingInterface.GetDrawing(XElement element) { foreach (IDrawingInterface id in list) { IDrawingInterface f = id.GetDrawing(element); if (f != null) { return(f); } } return(null); }
public void rearrangeGraphFromModel(Model.SBML.Model model, IDrawingInterface drawable) { if (!finishing) { if (thread != null) { thread.stop(); Console.WriteLine("Rearrange thread already running"); } GraphLayoutManager rearranger = new GraphLayoutManager_SpringEmbedder(); thread = new RearrangeThread(rearranger, model, drawable); Thread newThread = new Thread(new ThreadStart(thread.run)); thread.setThread(newThread); newThread.Start(); } }
private void CreateGraphicsStructure() { Dictionary <string, GraphicsStructure> d = new Dictionary <string, GraphicsStructure>(); XElement r = root; while (true) { if (r.Name.Equals("Model")) { break; } XElement p = r.Parent as XElement; if (p == null) { break; } r = p; } XElement[] children = SimulinkXmlParser.GetChildren(r); foreach (XElement e in children) { string tn = e.Name.LocalName; if (tn.Contains(Defaults)) { string s = tn.Substring(0, tn.Length - Defaults.Length); GraphicsStructure gs = CreateStucrure(e); d[s] = gs; } } if (d.ContainsKey(SimulinkXmlParser.Line)) { d[SimulinkXmlParser.Branch] = d[SimulinkXmlParser.Line]; } IDrawingInterface din = TagNameDrawingInterface.GetInterface(d); IList <IDrawingInterface> list = new List <IDrawingInterface>(); list.Add(din); list.Add(this); di = new DrawingInterfaceList(list); }
public MacroCommand rearrangeGraphFromModel(Model.SBML.Model model, IDrawingInterface drawable) { int modelDegree = model.listOfSpecies.Count; //convert the model to nodes and links List<GraphNode> nodes = new List<GraphNode>(); List<GraphLink> links = new List<GraphLink>(); foreach (Species n in model.listOfSpecies) { nodes.Add(new GraphNode(n, n.getPosition())); } foreach (Reaction n in model.listOfReactions) { nodes.Add(new GraphNode(n, n.getPosition())); } foreach (ComponentBase n in model.listOfComponents) { nodes.Add(new GraphNode(n, n.getPosition())); } foreach (Reaction r in model.listOfReactions) { GraphNode hubNode=findNode(r,nodes); if (hubNode != null) { foreach (SimpleSpeciesReference s in r.Reactants) { GraphNode sNode = findNode(s.species, nodes); if (sNode != null) { links.Add(new GraphLink(sNode, hubNode, modelDegree)); } } foreach (SimpleSpeciesReference s in r.Products) { GraphNode sNode = findNode(s.species, nodes); if (sNode != null) { links.Add(new GraphLink(sNode, hubNode, modelDegree)); } } foreach (SimpleSpeciesReference s in r.Modifiers) { GraphNode sNode = findNode(s.species, nodes); if (sNode != null) { links.Add(new GraphLink(sNode, hubNode, modelDegree)); } } } } foreach (ComponentBase c in model.listOfComponents) { GraphNode hubNode = findNode(c, nodes); if (hubNode != null) { foreach (SimpleSpeciesReference s in c.Reactants) { if (s != null) { GraphNode sNode = findNode(s.species, nodes); if (sNode != null) { links.Add(new GraphLink(sNode, hubNode, modelDegree)); } } } foreach (SimpleSpeciesReference s in c.Products) { if (s != null) { GraphNode sNode = findNode(s.species, nodes); if (sNode != null) { links.Add(new GraphLink(sNode, hubNode, modelDegree)); } } } } } GraphNode[] graphNodes = nodes.ToArray(); GraphLink[] graphLinks = links.ToArray(); return resolveGraph(graphNodes, graphLinks, drawable); }
protected virtual MacroCommand resolveGraph(GraphNode[] nodes, GraphLink[] links, IDrawingInterface drawable) { //try and rearrange the graph by setting node positions //if want to, call drawable update to refresh return null; }
/// <summary> /// Gets brush from Xml element /// </summary> /// <param name="element">The element</param> /// <param name="inter">Interface</param> /// <returns>The brush</returns> public static Brush GetBrush(XElement element, IDrawingInterface inter) { IDrawingInterface id = inter.GetDrawing(element); return(id.GetForegroundBrush(element)); }
/// <summary> /// Gets font from Xml element /// </summary> /// <param name="element">The element</param> /// <param name="inter">Interface</param> /// <returns>The font</returns> public static Font GetFont(XElement element, IDrawingInterface inter) { IDrawingInterface id = inter.GetDrawing(element); return(id.GetFont(element)); }
/// <summary> /// Gets pen from Xml element /// </summary> /// <param name="element">The element</param> /// <param name="inter">Interface</param> /// <returns>The pen</returns> public static Pen GetPen(XElement element, IDrawingInterface inter) { IDrawingInterface id = inter.GetDrawing(element); return(id.GetPen(element)); }
public RearrangeThread(GraphLayoutManager rearranger, Model.SBML.Model model, IDrawingInterface drawable) { this.rearranger = rearranger; this.model = model; this.drawable = drawable; }