Example #1
0
        /// <summary>
        /// The menu items for this tree node
        /// </summary>
        /// <returns></returns>
        protected override List <MenuItem> GetMenuItems()
        {
            List <MenuItem> retVal = base.GetMenuItems();

            retVal.Add(new MenuItem("-"));
            retVal.Add(new MenuItem("Add parameter", new EventHandler(AddParameterHandler)));
            retVal.Add(new MenuItem("Add case", new EventHandler(AddCaseHandler)));
            retVal.Add(new MenuItem("-"));

            DataDictionary.Interpreter.InterpretationContext context = new DataDictionary.Interpreter.InterpretationContext(Item);
            if (Item.FormalParameters.Count == 1)
            {
                Parameter parameter = (Parameter)Item.FormalParameters[0];
                DataDictionary.Functions.Graph graph = Item.createGraph(context, parameter);
                if (graph != null && graph.Segments.Count != 0)
                {
                    retVal.Add(new MenuItem("Display", new EventHandler(DisplayHandler)));
                    retVal.Add(new MenuItem("-"));
                }
            }
            else if (Item.FormalParameters.Count == 2)
            {
                DataDictionary.Functions.Surface surface = Item.createSurface(context);
                if (surface != null && surface.Segments.Count != 0)
                {
                    retVal.Add(new MenuItem("Display", new EventHandler(DisplayHandler)));
                    retVal.Add(new MenuItem("-"));
                }
            }

            retVal.Add(new MenuItem("Delete", new EventHandler(DeleteHandler)));

            return(retVal);
        }
Example #2
0
 /// <summary>
 ///     Adds a new function to this graph
 /// </summary>
 /// <param name="function"></param>
 /// <param name="explain"></param>
 private void AddFunction(Function function, ExplanationPart explain)
 {
     if (function != null)
     {
         InterpretationContext context = new InterpretationContext(function);
         if (function.FormalParameters.Count == 1)
         {
             Parameter parameter = (Parameter)function.FormalParameters[0];
             Graph     graph     = function.CreateGraph(context, parameter, explain);
             if (graph != null)
             {
                 Functions.Add(function);
                 Refresh();
             }
         }
         else if (function.FormalParameters.Count == 2)
         {
             Surface surface = function.CreateSurface(context, explain);
             if (surface != null)
             {
                 Functions.Add(function);
                 Refresh();
             }
             else
             {
                 MessageBox.Show(
                     Resources.GraphView_AddFunction_Cannot_add_this_function_to_the_display_view,
                     Resources.GraphView_AddFunction_Cannot_display_function,
                     MessageBoxButtons.OK,
                     MessageBoxIcon.Error);
             }
         }
     }
 }
Example #3
0
        /// <summary>
        ///     Displays the graph
        /// </summary>
        /// <returns></returns>
        public void Display()
        {
            Util.DontNotify(() =>
            {
                GraphVisualiser.Reset();
                String name = null;

                // Computes the expected end to display
                double expectedEndX = 0;
                Dictionary <Function, Graph> graphs = new Dictionary <Function, Graph>();
                foreach (Function function in Functions)
                {
                    InterpretationContext context = new InterpretationContext(function);
                    if (function.FormalParameters.Count == 1)
                    {
                        Parameter parameter = (Parameter)function.FormalParameters[0];
                        Graph graph         = function.CreateGraph(context, parameter, null);
                        if (graph != null)
                        {
                            expectedEndX = Math.Max(expectedEndX, graph.ExpectedEndX());
                            graphs.Add(function, graph);
                        }
                    }
                }

                double expectedEndY = 0;
                Dictionary <Function, Surface> surfaces = new Dictionary <Function, Surface>();
                foreach (Function function in Functions)
                {
                    InterpretationContext context = new InterpretationContext(function);
                    if (function.FormalParameters.Count == 2)
                    {
                        Surface surface = function.CreateSurface(context, null);
                        if (surface != null)
                        {
                            expectedEndX = Math.Max(expectedEndX, surface.ExpectedEndX());
                            expectedEndY = Math.Max(expectedEndY, surface.ExpectedEndY());
                            surfaces.Add(function, surface);
                        }
                    }
                }

                try
                {
                    int maxX     = Int32.Parse(Tb_MaxX.Text);
                    expectedEndX = Math.Min(expectedEndX, maxX);
                }
                catch (Exception)
                {
                }

                // Creates the graphs
                foreach (KeyValuePair <Function, Graph> pair in graphs)
                {
                    Function function = pair.Key;
                    Graph graph       = pair.Value;

                    if (function != null && graph != null)
                    {
                        EfsProfileFunction efsProfileFunction = new EfsProfileFunction(graph);
                        if (function.Name.Contains("Gradient"))
                        {
                            GraphVisualiser.AddGraph(new EfsGradientProfileGraph(GraphVisualiser, efsProfileFunction,
                                                                                 function.FullName));
                        }
                        else
                        {
                            GraphVisualiser.AddGraph(new EfsProfileFunctionGraph(GraphVisualiser, efsProfileFunction,
                                                                                 function.FullName));
                        }

                        if (name == null)
                        {
                            name = function.Name;
                        }
                    }
                }

                // Creates the surfaces
                foreach (KeyValuePair <Function, Surface> pair in surfaces)
                {
                    Function function = pair.Key;
                    Surface surface   = pair.Value;

                    if (surface != null)
                    {
                        EfsSurfaceFunction efsSurfaceFunction = new EfsSurfaceFunction(surface);
                        GraphVisualiser.AddGraph(new EfsSurfaceFunctionGraph(GraphVisualiser, efsSurfaceFunction,
                                                                             function.FullName));
                        if (name == null)
                        {
                            name = function.Name;
                        }
                    }
                }

                Train train = new Train(GraphVisualiser);
                train.InitializeTrain(TrainPosition.GetDistance(), TrainPosition.GetSpeed(), TrainPosition.GetUnderReadingAmount(), TrainPosition.GetOverReadingAmount());
                GraphVisualiser.AddGraph(train);
                GraphVisualiser.Annotations.Add(train.TrainLineAnnotation);
                GraphVisualiser.Annotations.Add(train.TrainAnnotation);

                if (name != null)
                {
                    try
                    {
                        double val = double.Parse(Tb_MinX.Text);
                        GraphVisualiser.SetMinX(val);
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        double val = double.Parse(Tb_MaxX.Text);
                        GraphVisualiser.SetMaxX(val);
                    }
                    catch (Exception)
                    {
                    }

                    if (Cb_AutoYSize.Checked)
                    {
                        GraphVisualiser.SetMaxY(double.NaN);
                    }
                    else
                    {
                        double height;
                        if (double.TryParse(Tb_MaxY.Text, out height))
                        {
                            GraphVisualiser.SetMaxY(height);
                        }
                        else
                        {
                            GraphVisualiser.SetMaxY(double.NaN);
                        }
                    }

                    GraphVisualiser.SetMinY2(double.NaN);
                    GraphVisualiser.SetMaxY2(double.NaN);
                    double top, bottom;
                    if (double.TryParse(Tb_MinGrad.Text, out bottom))
                    {
                        GraphVisualiser.SetMinY2(bottom);
                    }
                    if (double.TryParse(Tb_MaxGrad.Text, out top))
                    {
                        GraphVisualiser.SetMaxY2(top);
                    }

                    GraphVisualiser.DrawGraphs(expectedEndX);
                }
            });
        }