Esempio n. 1
1
		/// <summary>
		/// Saves the diagram to NML format
		/// </summary>
		/// <param name="fileName">the file-path</param>
		/// <param name="site">the graph-control instance to be serialized</param>
		/// <returns></returns>
		public static  bool SaveAs(string fileName, GraphControl site)
		{
			XmlTextWriter tw = null;
			try
			{

				tw = new XmlTextWriter(fileName,System.Text.Encoding.Unicode);
				tw.Formatting = System.Xml.Formatting.Indented;
				IO.NML.NMLSerializer g = new IO.NML.NMLSerializer();
				g.Serialize(tw,site.Abstract);
				
				return true;
			}
			catch(Exception exc)			
			{				
				//TODO: more specific exception handling here
				Trace.WriteLine(exc.Message, "NMLSerializer.SaveAs");
			}
			catch
			{
				Trace.WriteLine("Non-CLS exception caught.","BinarySerializer.SaveAs");
			}
			finally
			{
				if(tw!=null) tw.Close();
			}
			return false;

		}
Esempio n. 2
0
		/// <summary>
		/// Opens a NML serialized file
		/// </summary>
		/// <param name="filename"></param>
		/// <param name="site"></param>
		public static void Open(string filename, GraphControl site)
		{
			try
			{
			XmlTextReader reader = new XmlTextReader(filename);
			IO.NML.NMLSerializer ser = new IO.NML.NMLSerializer(site);
			
			site.Abstract = ser.Deserialize(reader) as GraphAbstract;
			reader.Close();
			}
			catch (System.IO.DirectoryNotFoundException exc)
			{
				System.Windows.Forms.MessageBox.Show(exc.Message);
			}
			catch(System.IO.FileLoadException exc)
			{				
				System.Windows.Forms.MessageBox.Show(exc.Message);
			}
			catch (System.IO.FileNotFoundException exc)
			{
				System.Windows.Forms.MessageBox.Show(exc.Message);
			}
			catch
			{				
				site.OutputInfo("Non-CLS exception caught.","BinarySerializer.SaveAs", OutputInfoLevels.Exception);
			}
		}
Esempio n. 3
0
        public void updateFromGraphControl(Netron.GraphLib.UI.GraphControl graphControl1)
        {
            try
            {
                designGraph graph;

                if (graphControl1.Name == "graphControlLHS")
                {
                    graph = L;
                }
                else
                {
                    graph = R;
                }

                graph.addNodesFromGraphControl(graphControl1, true);
                graph.addArcsFromGraphControl(graphControl1, true);
                graph.internallyConnectGraph();
                graph.removeNodesAndArcsFromGraphControl(graphControl1);
            }
            catch (Exception e)
            {
                MessageBox.Show("There was an error updating the rule from the display. Please save work and re-open. (Error: " + e.ToString() + ")", "Error Updating Rule", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        public static Boolean checkRule(grammarRule rule, GraphControl graphControlLHS,
            GraphControl graphControlRHS, Label LglobalLabelsText, Label RglobalLabelsText)
        {
            rule.updateFromGraphControl(graphControlLHS);
            rule.updateFromGraphControl(graphControlRHS);
            rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);

            if ((rule.L.checkForRepeatNames()) &&
                (DialogResult.Cancel ==
                (MessageBox.Show("Sorry, but you are not allowed to have repeat names in L. I have changed these " +
                    "names to be unique, which may have disrupted your context graph, K", "Repeat Names in L",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Information))))
                return false;
            else
                rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);

            if ((rule.R.checkForRepeatNames()) &&
            (DialogResult.Cancel ==
                (MessageBox.Show("Sorry, but you are not allowed to have repeat names in R. I have changed" +
                    " these names to be unique, which may have disrupted your context graph, K", "Repeat Names in R",
                    MessageBoxButtons.OK, MessageBoxIcon.Information))))
                return false;
            else
                            rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);

            if ((rule.numElementsInK == 0) && (DialogResult.No == MessageBox.Show(
                    "There appears to be no common elements between the left and right hand sides of the rule." +
                    " Is this intentional? If so, click yes to continue.", "No Context Graph",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question)))

                return false;
            if ((rule.KarcsChangeDirection() != "") && (DialogResult.No ==
                MessageBox.Show("It appears that arc(s): " + rule.KarcsChangeDirection() +
                    " change direction (to = from or vice-versa). Even though the arc(s) might be undirected," +
                    " this can still lead to problems in the rule application, it is recommended that this is" +
                    " fixed before saving. Save anyway?", "Misdirected Arcs in K", MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question)))
                return false;

            return true;
        }
        public static void Open(string fileName, GraphControl site)
        {
            FileStream fs=null;

            try
            {
                fs= File.OpenRead(fileName);
            }
            catch (System.IO.DirectoryNotFoundException exc)
            {
                System.Windows.Forms.MessageBox.Show(exc.Message);
            }
            catch(System.IO.FileLoadException exc)
            {
                System.Windows.Forms.MessageBox.Show(exc.Message);
            }
            catch (System.IO.FileNotFoundException exc)
            {
                System.Windows.Forms.MessageBox.Show(exc.Message);
            }
            //donnot open anything if filestream is not there
            if (fs==null) return;
            try
            {

                BinaryFormatter f = new BinaryFormatter();

                GraphAbstract tmp = (GraphAbstract) f.Deserialize(fs); //so simple, so powerful
                tmp.Site=site;

                if(tmp.Shapes.Count<1) return;
                // paint the connections
                foreach (Shape o in tmp.Shapes)
                    foreach (Connector c in o.Connectors)
                        foreach (Connection n in c.Connections)
                        {

                            n.Site = site;
                            if(site.Abstract.mConnections.Contains(n)) continue;
                            site.Abstract.mConnections.Add(n);//is not done automatically
                            n.InitEntity();
                        }
                // paint the shapes
                foreach (Shape o in tmp.Shapes)
                {
                    o.Site = site;
                    o.InitEntity();
                }
                //paint the connector
                foreach (Shape o in tmp.Shapes)
                    foreach (Connector c in o.Connectors)
                        if ((o.Hover) || (c.Hover))
                        {
                            c.Site = site;
                            c.InitEntity();
                        }

                site.extract = tmp;

            }
            catch(SerializationException exc)
            {
                System.Windows.Forms.MessageBox.Show(exc.Message);
            }
            finally
            {
                if(fs!=null)
                    fs.Close();
            }
        }
        public static bool SaveAs(string fileName, GraphControl site)
        {
            FileStream fs = new FileStream(fileName, FileMode.Create);

            BinaryFormatter f = new BinaryFormatter();
            //XmlSerializer f = new XmlSerializer(typeof(GraphAbstract),"Netron.GraphLib");

            try
            {
                //Warning!: cleaning up, you need to unhook all events since unserializable classes hooked to events will give problems
                f.Serialize(fs, site.extract);
                return true;
            }
            //catch(SerializationException exc)
            catch(Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("The graph was not saved, because some graph events were attached to non-serializable classes.\r\n This is a known issue and will be resolved in a later stadium.");
                Debug.WriteLine(exc.Message);

                DumpInfo();
            }
            finally
            {
                fs.Close();
            }
            return false;
        }
Esempio n. 7
0
        public void updateGraphControl(Netron.GraphLib.UI.GraphControl graphControlLHS,
                                       Netron.GraphLib.UI.GraphControl graphControlRHS, Label LglobalLabelsText, Label RglobalLabelsText)
        {
            try
            {
                numElementsInK = 0;

                foreach (node a in L.nodes)
                {
                    if (R.nodes.Exists(delegate(node b) { return(b.name == a.name); }))
                    {
                        numElementsInK++;
                        a.displayShape.ShapeColor = System.Drawing.Color.FromArgb(214, 145, 82);
                    }
                    else
                    {
                        a.displayShape.ShapeColor = System.Drawing.Color.White;
                    }
                }
                foreach (arc a in L.arcs)
                {
                    if (R.arcs.Exists(delegate(arc b) { return(b.name == a.name); }))
                    {
                        numElementsInK++;
                        a.displayShape.LineColor  = System.Drawing.Color.FromArgb(214, 145, 82);
                        a.displayShape.LineWeight = ConnectionWeight.Fat;
                    }
                    else
                    {
                        a.displayShape.LineColor  = System.Drawing.Color.Black;
                        a.displayShape.LineWeight = ConnectionWeight.Medium;
                    }
                }

                foreach (node a in R.nodes)
                {
                    if (L.nodes.Exists(delegate(node b) { return(b.name == a.name); }))
                    {
                        numElementsInK++;
                        a.displayShape.ShapeColor = System.Drawing.Color.FromArgb(214, 145, 82);
                    }
                    else
                    {
                        a.displayShape.ShapeColor = System.Drawing.Color.White;
                    }
                }
                foreach (arc a in R.arcs)
                {
                    if (L.arcs.Exists(delegate(arc b) { return(b.name == a.name); }))
                    {
                        numElementsInK++;
                        a.displayShape.LineColor  = System.Drawing.Color.FromArgb(214, 145, 82);
                        a.displayShape.LineWeight = ConnectionWeight.Fat;
                    }
                    else
                    {
                        a.displayShape.LineColor  = System.Drawing.Color.Black;
                        a.displayShape.LineWeight = ConnectionWeight.Medium;
                    }
                }
                L.updateGraphControl(graphControlLHS, LglobalLabelsText);
                R.updateGraphControl(graphControlRHS, RglobalLabelsText);
            }
            catch (Exception e)
            {
                MessageBox.Show("There was an error displaying the graphs. Please save work and re-open." +
                                " (Error: " + e.ToString() + ")", "Error Displaying Graphs", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Esempio n. 8
0
        public void updateFromGraphControl(Netron.GraphLib.UI.GraphControl graphControl1)
        {
            try
            {
                node        tempnode;
                arc         temparc;
                Shape       fromShape, toShape;
                designGraph graph;

                if (graphControl1.Name == "graphControlLHS")
                {
                    graph = L;
                }
                else
                {
                    graph = R;
                }

                foreach (Shape a in graphControl1.Shapes)
                {
                    if (!graph.nodes.Exists(delegate(node b) { return(b.displayShape == a); }))
                    {
                        graph.nodes.Add(new ruleNode(graph.nameFromText(a.Text)));
                        tempnode = graph.nodes[graph.lastNode];
                    }
                    else
                    {
                        tempnode = graph.nodes.Find(delegate(node b) { return(b.displayShape == a); });
                    }
                    if (a.Text != "[Not_set]")
                    {
                        tempnode.name        = graph.nameFromText(a.Text);
                        tempnode.localLabels = graph.labelsFromText(a.Text);
                    }
                    tempnode.screenX      = a.X;
                    tempnode.screenY      = a.Y;
                    tempnode.shapekey     = node.lookupShapeKey(a);
                    tempnode.displayShape = a;
                }
                foreach (Connection a in graphControl1.Connections)
                {
                    if (!graph.arcs.Exists(delegate(arc b) { return(b.displayShape == a); }))
                    {
                        graph.arcs.Add(new ruleArc(graph.nameFromText(a.Text)));
                        temparc = graph.arcs[graph.lastArc];
                    }
                    else
                    {
                        temparc = graph.arcs.Find(delegate(arc b) { return(b.displayShape == a); });
                    }
                    fromShape = a.From.BelongsTo;
                    toShape   = a.To.BelongsTo;

                    temparc.From = graph.nodes.Find(delegate(node c)
                                                    { return(graph.sameName(c.name, fromShape.Text)); });
                    temparc.To = graph.nodes.Find(delegate(node c)
                                                  { return(graph.sameName(c.name, toShape.Text)); });

                    for (int i = 0; i != fromShape.Connectors.Count; i++)
                    {
                        if (fromShape.Connectors[i] == a.From)
                        {
                            temparc.fromConnector = i;
                        }
                    }
                    for (int i = 0; i != toShape.Connectors.Count; i++)
                    {
                        if (toShape.Connectors[i] == a.To)
                        {
                            temparc.toConnector = i;
                        }
                    }
                    if (a.Text != "[Not_set]")
                    {
                        temparc.name        = graph.nameFromText(a.Text);
                        temparc.localLabels = graph.labelsFromText(a.Text);
                    }
                    temparc.curveStyle = a.LinePath;
                    if (a.LineEnd != ConnectionEnd.NoEnds)
                    {
                        temparc.directed = true;
                    }
                    else
                    {
                        temparc.directed = false;
                    }
                    if (a.LineEnd == ConnectionEnd.BothFilledArrow)
                    {
                        temparc.doublyDirected = true;
                    }
                    else
                    {
                        temparc.doublyDirected = false;
                    }
                    temparc.displayShape = a;
                }
                graph.internallyConnectGraph();
            }
            catch (Exception e)
            {
                MessageBox.Show("There was an error updating the rule from the display. Please save work and re-open. (Error: " + e.ToString() + ")", "Error Updating Rule", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 9
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="site"></param>
		public NMLSerializer(GraphControl site)
		{
			this.site = site;
		}
Esempio n. 10
0
		/// <summary>
		/// Default constructor
		/// </summary>
		/// <param name="site"></param>
		public HTMLExporter(GraphControl site)
		{
			mSite = site;
		}
Esempio n. 11
0
 public void updateGraphControl(Netron.GraphLib.UI.GraphControl graphControlLHS,
                                Netron.GraphLib.UI.GraphControl graphControlRHS, Label LglobalLabelsText, Label RglobalLabelsText)
 {
     try
     {
         numElementsInK = 0;
         #region check for same names in R and L and turn orange
         // first turn all nodes in R white
         foreach (node a in R.nodes)
         {
             a.displayShape.ShapeColor = System.Drawing.Color.White;
         }
         foreach (node a in L.nodes)
         {
             int rIndex = R.nodes.FindIndex(delegate(node b) { return(b.name == a.name); });
             if (rIndex >= 0)
             {
                 numElementsInK++;
                 a.displayShape.ShapeColor = System.Drawing.Color.FromArgb(214, 145, 82);
                 R.nodes[rIndex].displayShape.ShapeColor = System.Drawing.Color.FromArgb(214, 145, 82);
             }
             else
             {
                 a.displayShape.ShapeColor = System.Drawing.Color.White;
             }
         }
         #endregion
         #region check for same arcs in R and L and turn orange
         foreach (arc a in R.arcs)
         {
             a.displayShape.LineColor  = System.Drawing.Color.Black;
             a.displayShape.LineWeight = ConnectionWeight.Medium;
         }
         foreach (arc a in L.arcs)
         {
             int rIndex = R.arcs.FindIndex(delegate(arc b) { return(b.name == a.name); });
             if (rIndex >= 0)
             {
                 numElementsInK++;
                 a.displayShape.LineColor = System.Drawing.Color.FromArgb(214, 145, 82);
                 R.arcs[rIndex].displayShape.LineColor  = System.Drawing.Color.FromArgb(214, 145, 82);
                 a.displayShape.LineWeight              = ConnectionWeight.Fat;
                 R.arcs[rIndex].displayShape.LineWeight = ConnectionWeight.Fat;
             }
             else
             {
                 a.displayShape.LineColor  = System.Drawing.Color.Black;
                 a.displayShape.LineWeight = ConnectionWeight.Medium;
             }
         }
         #endregion
         L.updateGraphControl(graphControlLHS, LglobalLabelsText);
         R.updateGraphControl(graphControlRHS, RglobalLabelsText);
     }
     catch (Exception e)
     {
         MessageBox.Show("There was an error displaying the graphs. Please save work and re-open." +
                         " (Error: " + e.ToString() + ")", "Error Displaying Graphs", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
 /// <summary> 
 /// Required method for Designer support - do not modify 
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.graphControl1 = new Netron.GraphLib.UI.GraphControl();
     this.SuspendLayout();
     //
     // graphControl1
     //
     this.graphControl1.AllowDrop = true;
     this.graphControl1.AutomataPulse = 10;
     this.graphControl1.BackgroundColor = System.Drawing.Color.WhiteSmoke;
     this.graphControl1.BackgroundImagePath = null;
     this.graphControl1.BackgroundType = Netron.GraphLib.CanvasBackgroundTypes.FlatColor;
     this.graphControl1.Dock = System.Windows.Forms.DockStyle.Fill;
     this.graphControl1.EnableContextMenu = true;
     this.graphControl1.EnableLayout = false;
     this.graphControl1.FileName = null;
     this.graphControl1.GradientBottom = System.Drawing.Color.White;
     this.graphControl1.GradientTop = System.Drawing.Color.LightSteelBlue;
     this.graphControl1.GraphLayoutAlgorithm = Netron.GraphLib.GraphLayoutAlgorithms.SpringEmbedder;
     this.graphControl1.Location = new System.Drawing.Point(0, 0);
     this.graphControl1.Name = "graphControl1";
     this.graphControl1.RestrictToCanvas = true;
     this.graphControl1.Size = new System.Drawing.Size(400, 424);
     this.graphControl1.TabIndex = 0;
     this.graphControl1.Text = "graphControl1";
     this.graphControl1.Zoom = 100;
     this.graphControl1.ShowNodeProperties += new Netron.GraphLib.ShowPropsDelegate(this.graphControl_ShowNodeProperties);
     //
     // GraphUserControl
     //
     this.Controls.Add(this.graphControl1);
     this.Name = "GraphUserControl";
     this.Size = new System.Drawing.Size(400, 424);
     this.ResumeLayout(false);
 }