Example #1
0
 void RemoveEdge(UiComponent sender, Object args)
 {
     int id = (int)args;
     //Console.WriteLine(id);
     Edge e = dict[id];
     graph.RemoveEdge(e);
     Remove();
 }
Example #2
0
        void BtnAddVertex(UiComponent sender, Object arg)
        {

            float x = (float)random.NextDouble() * 1600.0f - 800.0f;
            float y = (float)random.NextDouble() * 1400.0f - 700.0f;

            activeGraph.vertices.Add(new Vertex(x, y));

            if (activeGraph.vertices.Count < 2) return;

            int n = random.Next(3);
            for (int i = 0; i < n; i++)
            {
                int e_choice = random.Next(activeGraph.vertices.Count - 2);
                activeGraph.AddEdge(activeGraph.vertices.Count - 1, e_choice);
            }
        }
Example #3
0
        void EditEdge(UiComponent sender, Object arg)
        {
            ui.edgeInputLabel.visible = true;
            ui.inputEdge = edge;

            if (Property.EdgeWeightId == -1) Property.SetSpecialProperty(Property.GetPropertyId("тегло"), SpecialProperty.EdgeWeight);

            if (edge.HasProperty(Property.EdgeWeightId))
            {
                object val = edge.GetPropertyValue(Property.EdgeWeightId);
                edge.SetProperty(Property.EdgeWeightId, val.ToString());
                ui.inputWeight = edge.GetProperty(Property.EdgeWeightId);
            }
            else
            {
                edge.SetProperty(Property.EdgeWeightId, "");
                ui.inputWeight = edge.GetProperty(Property.EdgeWeightId);
            }
        }
Example #4
0
        /// <summary>
        /// Обработва позицията на мишката в компонента. Предава на децата, ако е необходимо
        /// </summary>
        public bool ProcessMousePosition(Vector2i mousePos)
        {
            Vector2i localPos = new Vector2i(mousePos.X - box.Left, mousePos.Y - box.Top); // превръща координатите в локални
            if (!CheckMouseEvents(mousePos)) return false;// проверява за влизане/излизане, връща дали мишката е вътрe

            gui.lastChildMoused = this;

            if(children!= null) foreach (UiComponent uic in children)
            { // предава позицията на мишката на децата
                if(uic.ProcessMousePosition(localPos))
                { // мишката е върху текущия под-компонент; уведомяваме предния такъв(ако има), че мишката е излязла от него
                    if (lastMoused != null) if (lastMoused != uic) lastMoused.CallMouseLeave(); 
                    lastMoused = uic;
                    FinalizeLastChildMoused();
                    return true;
                }
            }
            lastMoused = null;
            gui.lastChildMoused = this;
            return true;
        }
Example #5
0
 void menu_FileOpen(UiComponent sender, Object arg)
 {
     System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
     if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         Graph g = new Graph();
         IOHandler.ReadGraphFile(ofd.FileName, ref g);
         ChangeGraph(g);
         DisableEdgeAdding();
         DisablePhysics();
     }
 }
Example #6
0
 void BtnCenterGraph(UiComponent sender, Object arg)
 {
     CenterGraph();
 }
Example #7
0
 void MenuBtnPause(UiComponent sender, Object arg)
 {
     timerEnabled = false;
 }
Example #8
0
 void BtnPhysToggle(UiComponent sender, Object arg)
 {
     if (physics) DisablePhysics();
     else EnablePhysics();
 }
Example #9
0
 void menu_FileClicked(UiComponent sender, Object arg)
 {
     fileMenu.visible = true;
 }
Example #10
0
        protected bool shouldAdd = false; // Предпазна мярка някой да не ползва AddChild вместо AddItem

        /// <summary>
        /// НЕ използвай!
        /// </summary>
        /// <param name="uic"></param>
        public override void AddChild(UiComponent uic)
        {
            if (!shouldAdd) throw new InvalidOperationException("Use AddItem!");
            else base.AddChild(uic);
            shouldAdd = false;
        }
Example #11
0
 void SetFocus(UiComponent sender, Object arg)
 {
     gui.keyboardFocusComponent = this;
 }
Example #12
0
 /// <summary>
 /// Добавя компонент-дете
 /// </summary>
 /// <param name="uic"></param>
 public virtual void AddChild(UiComponent uic)
 {
     uic.parent = this;
     uic.gui = gui;
     uic.UpdateChildrenGuiReference();
     children.Add(uic);
 }
Example #13
0
 void RemoveVertex(UiComponent sender, Object args)
 {
     graph.RemoveVertex(v);
     Remove();
 }
Example #14
0
 void rmbMenu_AddVertex(UiComponent sender, Object arg)
 {
     Vector2f pos = ToGlobalCoords(Mouse.GetPosition(window));
     activeGraph.vertices.Add(new Vertex(pos.X, pos.Y));
     rmbMenu.visible = false;
 }
Example #15
0
        void menu_Generate(UiComponent sender, Object arg)
        {
            Vertex.ResetCounter();
            Graph g = new Graph();
            int n = random.Next(50);
            int m = random.Next(100);
            for (int i = 0; i < n; i++)
            {
                Vertex v = new Vertex((float)random.NextDouble() * 1000 - 500.0f, (float)random.NextDouble() * 600 - 300.0f);
                g.AddVertex(v);
                if (i == 0) continue;

                int connections = random.Next(1, (int)Math.Min(i, 3));
                for(int j = 0; j < connections; j++)
                {
                    int vo = random.Next(0, i);

                    bool contains = false;
                    foreach(Edge e in v.edges)
                    {
                        if(e.source.id == vo || e.destination.id == vo)
                        {
                            contains = true;
                            break;
                        }
                    }
                    if (contains) j--;
                    else g.AddEdge(v.id, vo);
                }
            }

            

            fs.SetForce(50);

            activeGraph = g;
            fs.SetGraph(g);
        }
Example #16
0
 void rmbMenu_Deselect(UiComponent sender, Object arg)
 {
     if(lastClickedVertex!=null)
     {
         lastClickedVertex.selected = false;
         lastClickedVertex = null;
     }
     
     rmbMenu.visible = false;
 }
Example #17
0
 private void badButton_ComponentClicked(UiComponent sender, Object arg)
 {
     Console.WriteLine("Why did you click me?");
 }
Example #18
0
 void menu_ArrangeClicked(UiComponent sender, Object arg)
 {
     arrangeMenu.visible = true;
 }
Example #19
0
 void menu_Shuffle(UiComponent sender, Object arg)
 {
     foreach(Vertex v in activeGraph.vertices)
     {
         v.x = (float)(random.NextDouble() * 1000 - 500);
         v.y = (float)(random.NextDouble() * 600 - 300);
     }
 }
Example #20
0
 void BtnAddEdgeToggle(UiComponent sender, Object arg)
 {
     if (addEdgeEnabled) DisableEdgeAdding();
     else EnableEdgeAdding();
 }
Example #21
0
 void menu_FileSave(UiComponent sender, Object arg)
 {
     System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
     if(sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         IOHandler.WriteGraphFile(sfd.FileName, activeGraph);
     }
 }
Example #22
0
 void MenuBtnPlay(UiComponent sender, Object arg)
 {
     timerEnabled = true;
     if (connector != null) connector.Resume();
 }
Example #23
0
 void menu_Clear(UiComponent sender, Object arg)
 {
     ClearAll();
 }
Example #24
0
 void menu_Circle(UiComponent sender, Object arg)
 {
     activeGraph.ArrangeInCircle();
 }
Example #25
0
 void menu_Directivity(UiComponent sender, Object arg)
 {
     if (activeGraph.Directed) DisableDirected();
     else EnableDirected();
 }
Example #26
0
 void BtnSingleStep(UiComponent sender, Object arg)
 {
     if (connector != null) connector.Resume();
 }
Example #27
0
 void menu_Weight(UiComponent sender, Object arg)
 {
     if (weighted) DisableWeight();
     else EnableWeight();
 }
Example #28
0
 void menu_newclick(UiComponent sender, Object arg)
 {
     Console.WriteLine("You clicked a new button." + arg.ToString());
 }
Example #29
0
 void RemoveEdge(UiComponent sender, Object args)
 {
     graph.RemoveEdge(edge);
     Remove();
 }