Exemplo n.º 1
0
        /// <summary>
        /// When left mouse button clicked
        /// Opens menu from which user can select a coloring option
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem      menuItem = (MenuItem)sender;
            VertexControl vertex   = toManipulate as VertexControl;// the previosly clicked element

            if (vertex != null)
            {
                // get the shapes cordinates
                GeneralTransform gt         = vertex.TransformToVisual(Application.Current.RootVisual as UIElement);
                Point            vertex_loc = gt.Transform(new Point(0, 0));

                // The mouse pointer is inside the Vertex
                if (Math.Abs(vertex_loc.X - _mX) < vertex_radius)
                {
                    if (Math.Abs(vertex_loc.Y - _mY) < vertex_radius)
                    {
                        // Retrive userId from Isolated Storage
                        int userID = 0;
                        if (i_storage.Contains("userID"))
                        {
                            userID = (int)i_storage["userID"];
                        }

                        switch (menuItem.Header.ToString())
                        {
                        case "Green":
                            if (vertex.Red_Ellipse.Visibility == Visibility.Visible)
                            {
                                vertex.Red_Ellipse.Visibility   = Visibility.Collapsed;
                                vertex.Green_Ellipse.Visibility = Visibility.Visible;
                                vertex.VertexColor = "Green";
                                // call Web Service Method Asynchronicly for each log entery (so nothing will be logged for changing to same color)
                                client.InsertIntoExperimentActionsAsync(1, userID, vertex.VertexID, vertex.VertexColor, DateTime.Now);
                                // the selected Vertex and true to increase thickness
                                ChangeEdgeThickness(vertex, true);
                            }
                            break;

                        case "Red":
                            if (vertex.Green_Ellipse.Visibility == Visibility.Visible)
                            {
                                vertex.Red_Ellipse.Visibility   = Visibility.Visible;
                                vertex.Green_Ellipse.Visibility = Visibility.Collapsed;
                                vertex.VertexColor = "Red";
                                // call Web Service Method Asynchronicly for each log entery
                                client.InsertIntoExperimentActionsAsync(1, userID, vertex.VertexID, vertex.VertexColor, DateTime.Now);
                                // the selected Vertex and false to decrease thickness
                                ChangeEdgeThickness(vertex, false);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
                cm.IsOpen = false;// sets a value to make the ContextMenu invisible
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Change the Edges thickness when alligned Vertex pressed
        /// </summary>
        /// <param name="ellipse">The Ellipese pressed</param>
        /// <param name="increase">Variable indicating whether to increase or decrease the thickness</param>
        void ChangeEdgeThickness(VertexControl ellipse, bool increase)
        {
            // Change Edge thickness according to number of aligned Vertices selected
            System.Windows.Shapes.Line line;
            // Iterate through all the edges connected to clicked vertex
            foreach (var item in vertexEdges[ellipse.VertexID])
            {
                // if edge wasn't selected before - add it to list
                if (!(thickerEdges.ContainsKey(item)))
                {
                    thickerEdges.Add(item, new List <string>());
                }

                // get the edge instance on the canvas
                line            = (System.Windows.Shapes.Line)canvas1.FindName(item);
                line.Visibility = Visibility.Collapsed;

                if (increase)
                {
                    // foreach edge holds the two verteces connected to it (as known for now)
                    thickerEdges[item].Add(ellipse.VertexID);

                    #region Story Board
                    SolidColorBrush myAnimatedBrush = new SolidColorBrush();
                    Storyboard      colorStoryboard = new Storyboard();
                    Storyboard.SetTargetProperty(colorStoryboard, new PropertyPath("Color"));//(SolidColorBrush.ColorProperty));
                    Storyboard.SetTarget(colorStoryboard, myAnimatedBrush);
                    ColorAnimationUsingKeyFrames caukf = new ColorAnimationUsingKeyFrames();
                    // caukf.BeginTime = new TimeSpan(0, 0, 0, 0);

                    LinearColorKeyFrame lckf0 = new LinearColorKeyFrame();
                    lckf0.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 900));
                    lckf0.Value   = Colors.Red;

                    LinearColorKeyFrame lckf1 = new LinearColorKeyFrame();
                    lckf1.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 1900));
                    lckf1.Value   = Colors.White;

                    LinearColorKeyFrame lckf2 = new LinearColorKeyFrame();
                    lckf2.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 1900));
                    lckf2.Value   = Colors.Red;

                    LinearColorKeyFrame lckf3 = new LinearColorKeyFrame();
                    lckf3.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 2300));
                    lckf3.Value   = Colors.White;

                    caukf.KeyFrames.Add(lckf0);
                    caukf.KeyFrames.Add(lckf1);
                    //caukf.KeyFrames.Add(lckf2);
                    //caukf.KeyFrames.Add(lckf3);

                    colorStoryboard.Children.Add(caukf);
                    colorStoryboard.Begin();
                    #endregion

                    line.Stroke = myAnimatedBrush;

                    // increase Edge thickness
                    if (line.StrokeThickness == 4)
                    {
                        line.StrokeThickness += 5;
                    }
                }
                else// The edge's thickness needs to be decreased (the vertex was unselected)
                {
                    // Holds all the thick Edges
                    List <string> EdgeVerticesList = thickerEdges[item];
                    List <string> copy             = new List <string>();

                    if ((line.StrokeThickness > 4))
                    {
                        foreach (string s in EdgeVerticesList)
                        {
                            if (s != ellipse.VertexID)
                            {
                                copy.Add(s);
                            }
                        }

                        thickerEdges[item] = copy;

                        if (copy.Count == 0)
                        {
                            line.StrokeThickness -= 5;
                            // line.Stroke = new SolidColorBrush(Colors.White);
                        }
                    }
                }
                line.Visibility = Visibility.Visible;
            }

            // Check if graph solved correctly
            bool solved_correctly = true;
            foreach (var item in m_line_list)// Iterate on all edges and check thier thickness
            {
                if (item.StrokeThickness <= 4)
                {
                    solved_correctly = false;
                }
            }
            // Write conclusion for graph solution to the DB

            client.SolvedProblemGraphAsync((int)i_storage["userID"], solved_correctly, DateTime.Now);
        }