Exemple #1
0
        public object Clone()
        {
            Edges clone = new Edges();
            clone.label = label;
            clone.from = from;
            clone.to = to;
            foreach (string key in edgeAttributes.Keys)
            {
                clone.edgeAttributes.Add(key, edgeAttributes[key]);
            }

            return clone;
        }
Exemple #2
0
        public void generateGraph(long structureid, Graph graph)
        {
            GraphVizEngine structuresGraph = new GraphVizEngine();

            structuresGraph.createUndirectedGraph(structureid.ToString());

            long factor = 15000;

            //FileStream fs = new FileStream(workDirectory+"\\Files\\"+structureid+".dot", FileMode.Create, FileAccess.Write);
            //StreamWriter sw = new StreamWriter(fs);
            //sw.Write("graph " + structureid + "{\n");
            //StringBuilder level = new StringBuilder();
            double maxX = 0.0, maxZ = 0.0;
            foreach (KeyValuePair<long, Node> node in graph.Nodes)
            {
                if (maxX < node.Value.position.X)
                    maxX = node.Value.position.X;
                if (maxZ < node.Value.position.Z)
                    maxZ = node.Value.position.Z;

            }

            Console.WriteLine("MaxX =" + maxX);
            Console.WriteLine("MaxZ =" + maxZ);

            structuresGraph.graphAttribites.Add("size", Convert.ToInt32(maxZ / (300 * 5)) + "," + Convert.ToInt32(maxX / (300 * 5)) + "!");

            // sw.Write("graph[size=\"" + Convert.ToInt32(maxZ / (300 * 5)) + "," + Convert.ToInt32(maxX / (300 * 5)) + "!\"];\n");
            // sw.Write("edge[decorate=false];\n");
            // sw.Write("node[fontcolor=white]\n;");
            string color = "green";
            foreach (KeyValuePair<long, Node> node in graph.Nodes)
            {
                Nodes tmpNode = structuresGraph.addNode(node.Value.ID);
                int radii = Convert.ToInt32(Math.Ceiling(node.Value.radius / (300)));

                tmpNode.nodeAttributes.Add("style", "filled");
                tmpNode.nodeAttributes.Add("penwidth", "9.0");
                tmpNode.nodeAttributes.Add("fillcolor", color);
                tmpNode.nodeAttributes.Add("pos", (Convert.ToInt32(Math.Ceiling(node.Value.position.X / 300)) + "," + Convert.ToInt32((maxZ - node.Value.position.Z) / 300) +
                    "!").ToString());
                tmpNode.nodeAttributes.Add("shape", "box");
                tmpNode.nodeAttributes.Add("width", radii.ToString());
                tmpNode.nodeAttributes.Add("height", (radii / 4).ToString());
                tmpNode.nodeAttributes.Add("tooltip", node.Value.ID.ToString());
                tmpNode.nodeAttributes.Add("URL", "#");

                //sw.Write(node.Value.ID + "[label=\"" + node.Value.ID + "\",style=filled,penwidth=\"9.0\",color=black,fillcolor=" + color + ",pos=\"" + Convert.ToInt32(Math.Ceiling(node.Value.position.X / 300)) + "," + Convert.ToInt32((maxZ - node.Value.position.Z) / 300) +
                //    "!\",shape=circle,width=\"" + radii + "\",href=\"http://www.google.com\"];\n");

            }

            List<string> edgeList = new List<string>();

            foreach (Edge edge in graph.Edges)
            {
                Edges tmpEdge = new Edges();
                structuresGraph.addEdge(tmpEdge);
                tmpEdge.from = edge.A;
                tmpEdge.to = edge.B;
                tmpEdge.edgeAttributes.Add("label", Math.Round(edge.distance, 2).ToString() + "nm");
                tmpEdge.edgeAttributes.Add("style", "setlinewidth(5)");
                tmpEdge.edgeAttributes.Add("href", "#");
                tmpEdge.edgeAttributes.Add("fontsize", "30");

                //sw.Write(edge.A + "--" + edge.B + "[label = \"" + Math.Round(edge.distance, 2) + "nm\",style=\"setlinewidth(5)\",href=\".\",fontsize=30];\n");

            }

            string workingDirectory = Server.MapPath("~");
            ViewData["workDirectory"] = workingDirectory;

            string localDir = ViewData["workDirectory"] + "\\Files\\" + HttpContext.User.Identity.Name + "\\";
            string fileDir = localDir + structureid;
            structuresGraph.completePath_local = fileDir;
            ViewData["username"] = HttpContext.User.Identity.Name;

            string svgfile = fileDir + ".svg";
            string virtualRoot = ViewData["virtualRoot"].ToString();

            structuresGraph.completePath_URL = virtualRoot + "/Files/" + HttpContext.User.Identity.Name +"/" + structureid;

            structuresGraph.virtualRoot = virtualRoot;

            if (!System.IO.Directory.Exists(localDir))
                System.IO.Directory.CreateDirectory(localDir);

            GraphJSON sendGraph = new GraphJSON();

            foreach (KeyValuePair<long, Node> node in graph.Nodes)
            {
                NodeJSON tempNode = new NodeJSON();
                tempNode.ID = node.Value.ID;
                tempNode.radius = node.Value.radius / factor;
                tempNode.location[0] = node.Value.position.X / factor;
                tempNode.location[1] = node.Value.position.Y / factor;
                tempNode.location[2] = node.Value.position.Z / factor;
                sendGraph.Nodes.Add(tempNode);
            }

            sendGraph.Edges = graph.Edges;

            sendGraph.Synapses = graph.Synapses;

            using (FileStream fs = new FileStream(fileDir + ".json", FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    JavaScriptSerializer oSerializer = new JavaScriptSerializer();
                    sw.Write(oSerializer.Serialize(sendGraph));
                    sw.Close();
                }
                fs.Close();
            }

            structuresGraph.outputFormats.Add("svg");

            structuresGraph.layout = "dot";

            structuresGraph.Output();

            //Add scripts to svg
            if (System.IO.File.Exists(svgfile))
            {
                StringBuilder contents;
                using (FileStream file = new FileStream(svgfile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    using (StreamReader sr = new StreamReader(file))
                    {
                        contents = new StringBuilder(sr.ReadToEnd());
                    }
                }

                System.IO.File.Delete(svgfile);

                string searchfor = "http://www.w3.org/1999/xlink\">";
                contents.Replace(searchfor, searchfor +
                    "\n<script xlink:href=\"" + virtualRoot + "/Scripts/SVGzoom.js\"/>\n<script xlink:href=\"" + virtualRoot + "/Scripts/effect.js\"/>");

                using (FileStream fl = new FileStream(svgfile, FileMode.Create))
                {
                    using (StreamWriter write = new StreamWriter(fl))
                    {
                        write.Write(contents.ToString());
                    }
                }

                //FileStream f2 = new FileStream(fileDir + "changed.txt", FileMode.Create);
                //StreamWriter wrr = new StreamWriter(f2);
                //wrr.Write(contents.ToString());
                //wrr.Close();
                //f2.Close();
            }
        }
Exemple #3
0
 public void addEdge(Edges edge)
 {
     edges.Add(edge);
 }
Exemple #4
0
 public void removeEdge(Edges edge)
 {
     if(edges.Contains(edge))
         edges.Remove(edge);
 }