Ejemplo n.º 1
0
 /// <summary>
 /// Disables the simulator by deleting the project information
 /// </summary>
 public void DeactivateSimulator()
 {
     //If the simulator is running, it stops
     if (this.state == SimState.Running)
     {
         this.stopSimulate = true;
         this.simulatorThread.Join();
         this.state = SimState.Pause;
         if (this.StateChanged != null)
         {
             this.StateChanged(this, new EventArgs());
         }
     }
     //All simulation layers are hidden from all functions
     foreach (GraphDiagram function in this.functions.Values)
     {
         function.SimulatorLayer.Visible = false;
     }
     //The stroke indicator of the current function is removed
     this.presentFunction.SimulatorLayer.Remove(this.graphTrace);
     this.presentFunction.SimulatorLayer.UpdateSurface();
     //The Simulator status is updated
     this.state = SimState.Inactive;
     if (this.StateChanged != null)
     {
         this.StateChanged(this, new EventArgs());
     }
     //Project information is deleted to simulate
     this.mainFunction = null;
     this.functions.Clear();
     this.variables = null;
     //The simulated model of the Moway is eliminated
     this.mowayModel = null;
 }
Ejemplo n.º 2
0
 public void Undo()
 {
     //The entered arrow is removed
     GraphDiagram.DeleteElement(this.diagramLayer, this.diagram, this.graphArrow);
     //Add the deleted arrow starting with the next element
     this.graphArrowToDelete.Next.AddPrevious(this.graphArrowToDelete.FinalConnector, this.graphArrowToDelete);
     foreach (GraphElement prevElement in this.graphArrowToDelete.Previous)
     {
         if (prevElement is GraphConditional)
         {
             ((GraphConditional)prevElement).AddNext(this.graphArrowToDelete.InitConnector, this.graphArrowToDelete, this.conditionalOut);
         }
         else
         {
             prevElement.AddNext(this.graphArrowToDelete.InitConnector, this.graphArrowToDelete);
         }
     }
     //The arrow is added to the diagram layer, and to the logical diagram
     this.diagramLayer.AddElement(this.graphArrowToDelete);
     this.diagram.AddElement(this.graphArrowToDelete.Element);
     //The diagram layer is updated
     this.diagramLayer.UpdateSurface();
     //It is indicated that the diagram has changed
     if (this.DiagramChanged != null)
     {
         this.DiagramChanged(this, new EventArgs());
     }
 }
Ejemplo n.º 3
0
        public override void SaveInFile(XmlWriter file, int elementId, Hashtable elementsId)
        {
            file.WriteElementString("id", elementId.ToString());
            file.WriteElementString("key", this.key);

            file.WriteStartElement("start");
            file.WriteStartElement("position");
            file.WriteElementString("x", this.Center.X.ToString());
            file.WriteElementString("y", this.Center.Y.ToString());
            file.WriteEndElement();
            file.WriteStartElement("next");
            if (this.Next != null)
            {
                int id;
                if (elementsId.ContainsKey(this.Next))
                {
                    id = (int)elementsId[this.Next];
                }
                else
                {
                    id = GraphDiagram.GetElementId();
                    elementsId.Add(this.Next, id);
                }
                file.WriteElementString("elementId", id.ToString());
                file.WriteElementString("connectorId", this.next.IdConnector.ToString());
            }
            file.WriteEndElement();

            file.WriteEndElement();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Undo the operation
 /// </summary>
 public void Undo()
 {
     //The entered arrow is removed
     GraphDiagram.DeleteElement(this.diagramLayer, this.diagram, this.graphArrow);
     //Resets the eliminated arrow in the case that there was
     if (this.graphArrowToDelete != null)
     {
         //Add the deleted arrow starting with the element next
         this.graphArrowToDelete.Next.AddPrevious(this.graphArrowToDelete.FinalConnector, this.graphArrowToDelete);
         foreach (GraphElement prevElement in this.graphArrowToDelete.Previous)
         {
             prevElement.AddNext(this.graphArrowToDelete.InitConnector, this.graphArrowToDelete);
         }
         //The arrow is added to the diagram layer, and to the logical diagram
         this.diagramLayer.AddElement(this.graphArrowToDelete);
         this.diagram.AddElement(this.graphArrowToDelete.Element);
     }
     //The diagram layer is updated
     this.diagramLayer.UpdateSurface();
     //it is indicated that the diagram has changed
     if (this.DiagramChanged != null)
     {
         this.DiagramChanged(this, new EventArgs());
     }
 }
Ejemplo n.º 5
0
        private void CreateArrowSurface(List <Point> locations)
        {
            Point minPoint = GraphDiagram.MinPoint(locations);
            Point maxPoint = GraphDiagram.MaxPoint(locations);

            this.Position = new Point(minPoint.X - 5, minPoint.Y - 5);

            this.segments.Clear();
            for (int i = 0; i < locations.Count - 1; i++)
            {
                if (i == 0)
                {
                    this.segments.Add(new StartSegment(this.initConnector, (Point)locations[i], (Point)locations[i + 1], this.Position));
                }
                else if (i < locations.Count - 2)
                {
                    this.segments.Add(new LineSegment((Point)locations[i], (Point)locations[i + 1], (Point)locations[i - 1], this.Position));
                }
                else
                {
                    this.segments.Add(new EndSegment(this.next, (Point)locations[i], (Point)locations[i + 1], (Point)locations[i - 1], this.Position));
                }
            }

            Size size = new Size(maxPoint.X - minPoint.X + 10, maxPoint.Y - minPoint.Y + 10);

            this.Surface = new Surface(size);
            //the color of transparency is indicated
            this.Transparent      = true;
            this.TransparentColor = GraphDiagram.TRASPARENT_COLOR;
            this.UpdateSurface();
        }
Ejemplo n.º 6
0
        public override void SaveInFile(XmlWriter file, int elementId, Hashtable elementsId)
        {
            file.WriteElementString("id", elementId.ToString());
            file.WriteElementString("key", this.key);

            file.WriteStartElement("finish");
            file.WriteStartElement("position");
            file.WriteElementString("x", this.Center.X.ToString());
            file.WriteElementString("y", this.Center.Y.ToString());
            file.WriteEndElement();
            file.WriteStartElement("previous");
            foreach (Connector connector in this.previous)
            {
                foreach (GraphElement prevElement in connector.Connections)
                {
                    int id;
                    if (elementsId.ContainsKey(prevElement))
                    {
                        id = (int)elementsId[prevElement];
                    }
                    else
                    {
                        id = GraphDiagram.GetElementId();
                        elementsId.Add(prevElement, id);
                    }
                    file.WriteElementString("elementId", id.ToString());
                    file.WriteElementString("connectorId", connector.IdConnector.ToString());
                }
            }
            file.WriteEndElement();

            file.WriteEndElement();
        }
Ejemplo n.º 7
0
        private List <Point> GetPathPoints(GridPoint[,] gridPoints)
        {
            List <Point> locations = new List <Point>();
            // you get the arrow path
            List <GridPoint> path = GraphDiagram.GetGridPath(gridPoints, GraphDiagram.GetNearGridPoint(this.initConnector), this.initConnector.Side, GraphDiagram.GetNearGridPoint(this.next));

            locations.Add(this.initConnector.AbsCenter);
            locations.Add(path[0].Location); //one must always be kept so that the beginning and end of the arrow are created
            //If the arrow path has more than one element, it seeks to minimize the sectors
            if (path.Count != 1)
            {
                int presentX = locations[1].X;
                int presentY = locations[1].Y;
                for (int i = 2; i < path.Count; i++)
                {
                    if ((path[i].Location.X != presentX) && (path[i].Location.Y != presentY))
                    {
                        locations.Add(path[i - 1].Location);
                        presentX = path[i - 1].Location.X;
                        presentY = path[i - 1].Location.Y;
                    }
                }
                locations.Add(path[path.Count - 1].Location);
            }
            locations.Add(this.next.AbsCenter);
            return(locations);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Insert Operation Builder
        /// </summary>
        /// <param name="diagram">Logical diagram del GraphDrawing</param>
        /// <param name="diagramLayer">GraphDrawing diagram Layer</param>
        /// <param name="tempLayer">Temporal layer of the GraphDrawing</param>
        /// <param name="element">Elements to insert</param>
        public Paste(Diagram diagram, GraphLayer diagramLayer, GraphLayer tempLayer)
        {
            this.diagram           = diagram;
            this.diagramLayer      = diagramLayer;
            this.tempLayer         = tempLayer;
            this.tempLayer.Visible = true;
            this.displacement      = new Point(0, 0);
            //You get the items to paste
            this.graphElements.AddRange(GraphDiagram.CloneElements(GraphManager.Clipboard.GetElements()));
            //Add the item to the temporary layer from the Clipboard
            this.tempLayer.AddElements(this.graphElements);
            foreach (GraphElement element in this.tempLayer.Elements)
            {
                if (!(element is GraphArrow))
                {
                    this.displacement = element.Center;
                    break;
                }
            }
            this.tempLayer.UpdateSurface();
            //The initial positions of the items to be moved are saved
            foreach (GraphElement element in this.tempLayer.Elements)
            {
                this.initLocations.Add(element, new Point(element.Center.X - this.displacement.X, element.Center.Y - displacement.Y));
            }
            MenuItem miCancel = new MenuItem(PasteMessages.CANCEL);

            miCancel.Click += new EventHandler(MiCancel_Click);
            this.menu       = new ContextMenu(new MenuItem[] { miCancel });
        }
Ejemplo n.º 9
0
        /// <summary>
        /// This method executes the insert operation after the insertion position has been set
        /// </summary>
        public void Do()
        {
            if (!GraphDiagram.ValidateCopy(this.selectLayer.Elements))
            {
                MowayMessageBox.Show(CutMessages.CUT_START, CutMessages.CUT, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Cancel();
                return;
            }
            //The items to be copied are loaded
            List <GraphElement> elementsToCut = GraphDiagram.GetElementsToCopy(this.selectLayer);
            List <GraphElement> cloneElements = GraphDiagram.CloneElements(elementsToCut);

            GraphManager.Clipboard.SetElements(cloneElements);

            this.elementsToDelete = GraphDiagram.GetElementsToDelete(this.selectLayer);
            GraphDiagram.DeleteElements(this.diagramLayer, this.diagram, this.elementsToDelete);
            //Cleans and hides the selection layer
            this.selectLayer.ClearAndHide();
            //Updates the diagram layer
            this.diagramLayer.UpdateSurface();
            if (this.DiagramChanged != null)
            {
                this.DiagramChanged(this, new EventArgs());
            }
            if (this.ElementSelectedChanged != null)
            {
                this.ElementSelectedChanged(this, new EventArgs());
            }
            //Launch Event of operation completed
            if (this.OperationFinished != null)
            {
                this.OperationFinished(this, new OperationEventArgs(Operation.Cut));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Press one of the mouse buttons (at the moment of pressing)
        /// </summary>
        /// <param name="e">Mouse Properties</param>
        public void MouseDown(MouseEventArgs e)
        {
            //If the initial connector is empty...
            if (this.initialConnector == null)
            {
                //You look for if you clicked on a different element of an arrow or a finish
                GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location);
                if ((element != null) && !((element is GraphArrow) || (element is GraphFinish)))
                {
                    Connector connector = element.GetConnector(e.Location);
                    if (connector != null)
                    {
                        this.initialConnector = connector;
                        this.initFixed        = true;
                    }
                    else
                    {
                        this.initialConnector = this.GetConnector(element, e.Location);
                    }
                    if (this.initialConnector.Parent is GraphConditional)
                    {
                        this.conditionalOut = ((GraphConditional)this.initialConnector.Parent).GetPredefOut(this.initialConnector);
                    }
                    element.DisableConnectors();
                    element.EnableConnector(this.initialConnector);

                    this.tempGraphArrow.UpdateArrow(this.initialConnector.AbsCenter, e.Location);
                    this.tempLayer.UpdateSurface();
                }
            }
        }
Ejemplo n.º 11
0
 public void MouseUp(MouseEventArgs e)
 {
     if (!this.preCanceled)
     {
         this.finalConnector = GraphDiagram.GetConnector(this.tempLayer, e.Location);
         if (this.finalConnector == null)
         {
             this.PreCancel();
             throw new OperationException(Operation.InsertArrow, "Change to Nop Operation");
         }
         else if (this.finalConnector == this.initialConnector)
         {
             this.finalConnector = null;
             dragMode            = false;
         }
         else
         {
             this.Do();
             throw new OperationException(Operation.InsertArrow, "Send a MouseMoveEvent");
         }
     }
     else
     {
         this.Cancel();
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Press one of the mouse buttons (at the moment of release)
 /// </summary>
 /// <param name="e">Mouse Properties</param>
 public void MouseUp(MouseEventArgs e)
 {
     if (this.initialConnector != null)
     {
         GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location);
         if ((element != null) && !(element is GraphArrow))
         {
             if (this.initialConnector.Parent == element)
             {
                 if (this.initFixed)
                 {
                     Connector connector = element.GetConnector(e.Location);
                     if (this.initialConnector == connector)
                     {
                         this.dragMode = false;
                     }
                     else if (connector != null)
                     {
                         this.finalConnector = this.presentConnector;
                         this.Do();
                     }
                 }
                 else
                 {
                     this.dragMode = false;
                 }
             }
             else if (!(element is GraphStart))
             {
                 this.finalConnector = this.presentConnector;
                 this.Do();
             }
         }
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Updates the stroke flag in the simulation graphical layer (updates the function and current element if they were different from the function parameters)
 /// </summary>
 /// <param name="function"></param>
 /// <param name="element"></param>
 /// <returns></returns>
 private void UpdateTrace(GraphDiagram function, GraphElement element)
 {
     //The item to be noted is updated if it is not the same as the current
     if (this.presentElement != element)
     {
         this.presentElement = element;
     }
     //The stroke is placed on the current element
     if ((this.presentElement is GraphStart) || (this.presentElement is GraphFinish))
     {
         this.graphTrace.Position = new Point(this.presentElement.Position.X - 12, this.presentElement.Position.Y + 3);
     }
     else if (this.presentElement is GraphModule)
     {
         this.graphTrace.Position = new Point(this.presentElement.Position.X - 14, this.presentElement.Position.Y + 9);
     }
     else if (this.presentElement is GraphConditional)
     {
         this.graphTrace.Position = new Point(this.presentElement.Position.X - 6, this.presentElement.Position.Y + 19);
     }
     else
     {
         throw new SimulatorException("Ningún otro elemento puede ser apuntado por la flecha");
     }
     //Update the simulation layer of the current function
     if (this.presentFunction != function)
     {
         this.presentFunction.SimulatorLayer.Remove(this.graphTrace);
         this.presentFunction.SimulatorLayer.UpdateSurface();
         this.presentFunction = function;
         this.presentFunction.SimulatorLayer.Add(this.graphTrace);
     }
     this.presentFunction.SimulatorLayer.UpdateSurface();
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Completely reset the simulator
 /// </summary>
 private void ResetSimulator()
 {
     //indicated that a reset is not necessary
     this.requireReset = false;
     //The simulator indicator is updated with new references
     this.UpdateTrace(this.mainFunction, this.mainFunction.StartElement);
     this.tempFunction = presentFunction;
     //The function returns stack is cleaned
     this.functionCallstack.Clear();
     //Model records are reset
     foreach (Variable variable in this.variables)
     {
         this.mowayModel.GetRegister(variable.Name).Value = variable.InitValue;
     }
     //Model is reset
     this.mowayModel.ResetSimulation();
     //The simulated state is updated if it is different from Pause
     if (this.state != SimState.Pause)
     {
         this.state = SimState.Pause;
         if (this.StateChanged != null)
         {
             this.StateChanged(this, new EventArgs());
         }
     }
 }
        public EditAreaSizeForm(GraphDiagram graphDiagram)
        {
            InitializeComponent();
            this.graphDiagram = graphDiagram;
            switch (this.graphDiagram.AreaFormat)
            {
            case AreaFormat.A3_Vertical:
                this.cbSize.SelectedIndex = 0;
                this.rbVertical.Checked   = true;
                break;

            case AreaFormat.A3_Horizontal:
                this.cbSize.SelectedIndex = 0;
                this.rbHorizontal.Checked = true;
                break;

            case AreaFormat.A4_Vertical:
                this.cbSize.SelectedIndex = 1;
                this.rbVertical.Checked   = true;
                break;

            case AreaFormat.A4_Horizontal:
                this.cbSize.SelectedIndex = 1;
                this.rbHorizontal.Checked = true;
                break;
            }
        }
Ejemplo n.º 16
0
 public GraphPdfDocument(string projectName, string projectOwner, GraphDiagram function)
     : base()
 {
     this.projectName  = projectName;
     this.projectOwner = projectOwner;
     this.function     = function;
 }
Ejemplo n.º 17
0
 public GraphPrintDocument(string projectName, string projectOwner, GraphDiagram presentFunction, List <GraphDiagram> functions)
 {
     this.projectName     = projectName;
     this.projectOwner    = projectOwner;
     this.presentFunction = presentFunction;
     this.functions       = functions;
     this.PrintPage      += new PrintPageEventHandler(PrinterDocument_PrintPage);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Removes a function
 /// </summary>
 /// <param name="function">function to delete</param>
 public void RemoveFunction(GraphDiagram function)
 {
     if (!this.functions.ContainsValue(function))
     {
         throw new SimulatorException("Simulator don't constain this function");
     }
     this.functions.Remove(function.Name);
     this.requireValidate = true;
 }
Ejemplo n.º 19
0
 public void MouseUp(MouseEventArgs e)
 {
     //Only checks for left mouse button
     if (e.Button == MouseButtons.Left)
     {
         //Looking for the affected element
         GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location);
         //If there is none, it is changed to Operation Nop
         if (element == null)
         {
             //The context of the Select operation is cleaned
             this.ClearOperationContext();
             throw new OperationException(Operation.Select, "Change to Nop Operation");
         }
         else
         {
             //If you are pressing the CONTROL key, a multiple selection is being made
             if (Control.ModifierKeys == Keys.Control)
             {
                 //If the item is selected, it is deselected
                 if (element.Selected)
                 {
                     DeselectElement(element);
                     //If there is no item selected, it changes to the NOP operation
                     if (this.selectLayer.Elements.Count == 0)
                     {
                         //The context of the Select operation is cleaned
                         this.ClearOperationContext();
                         throw new OperationException(Operation.Select, "Change to Nop Operation");
                     }
                 }
                 //without, it selects
                 else
                 {
                     this.SelectElement(element);
                 }
                 this.selectLayer.UpdateSurface();
                 if (this.ElementSelectedChanged != null)
                 {
                     this.ElementSelectedChanged(this, new EventArgs());
                 }
             }
             //If the item is not selected, the others are deselected and the current is selected
             else if (!element.Selected)
             {
                 this.DeselectAll();
                 this.SelectElement(element);
                 //The temporary layer is updated
                 this.selectLayer.UpdateSurface();
                 if (this.ElementSelectedChanged != null)
                 {
                     this.ElementSelectedChanged(this, new EventArgs());
                 }
             }
         }
     }
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Add a new feature
 /// </summary>
 /// <param name="function">New Function</param>
 public void AddFunction(GraphDiagram function)
 {
     if (this.functions.ContainsValue(function))
     {
         throw new SimulatorException("Simulator already constain this function");
     }
     function.SimulatorLayer.Visible = true;
     this.functions.Add(function.Name, function);
     this.requireValidate = true;
 }
Ejemplo n.º 21
0
 public void Do()
 {
     //If you are modifying the next of an item...
     if (this.nextEnable)
     {
         if (this.presentConnector.Parent is GraphConditional)
         {
             this.conditionalOut = ((GraphConditional)this.presentConnector.Parent).GetPredefOut(this.presentConnector);
             if ((conditionalOut == ConditionalOut.True) && (((GraphConditional)this.presentConnector.Parent).NextTrue != null))
             {
                 if (DialogResult.Yes != MowayMessageBox.Show(InsertArrowMessages.REPLACE_TRUE + "\r\n" + InsertArrowMessages.CONTINUE, InsertArrowMessages.INSERT_ARROW, MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                 {
                     this.Cancel();
                     return;
                 }
                 else if ((conditionalOut == ConditionalOut.False) && (((GraphConditional)this.presentConnector.Parent).NextFalse != null))
                 {
                     if (DialogResult.Yes != MowayMessageBox.Show(InsertArrowMessages.REPLACE_FALSE + "\r\n" + InsertArrowMessages.CONTINUE, InsertArrowMessages.INSERT_ARROW, MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                     {
                         this.Cancel();
                         return;
                     }
                 }
             }
         }
         GraphDiagram.DeleteElement(diagramLayer, diagram, this.graphArrowToDelete);
         this.graphArrow = GraphDiagram.InsertArrow(this.diagram, this.diagramLayer, this.presentConnector, this.fixedConnector, this.conditionalOut, this.gridStatus);
     }
     else        //If you are modifying an item's prev
     {
         if (fixedConnector.Parent is GraphConditional)
         {
             if (((GraphConditional)fixedConnector.Parent).NextTrue == this.graphArrowToDelete)
             {
                 this.conditionalOut = ConditionalOut.True;
             }
             else
             {
                 this.conditionalOut = ConditionalOut.False;
             }
         }
         GraphDiagram.DeleteElement(this.diagramLayer, this.diagram, this.graphArrowToDelete);
         this.graphArrow = GraphDiagram.InsertArrow(this.diagram, this.diagramLayer, this.fixedConnector, this.presentConnector, this.conditionalOut, this.gridStatus);
     }
     foreach (GraphElement element in this.tempLayer.Elements)
     {
         element.DisableConnectors();
     }
     this.tempLayer.ClearAndHide();
     this.diagramLayer.UpdateSurface();
     if (this.OperationFinished != null)
     {
         this.OperationFinished(this, new OperationEventArgs(Operation.Reconnect));
     }
 }
Ejemplo n.º 22
0
        public void MouseMove(MouseEventArgs e)
        {
            GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location);

            //If you are right-clicking and no item found, you switch to Operation Nop
            if ((e.Button == MouseButtons.Right) && (element == null))
            {
                //The context of the Select operation is cleaned
                this.ClearOperationContext();
                throw new OperationException(Operation.Select, "Change to Nop operation");
            }
            //If you are pressing the left button, the selection is checked and Drag & Drop operation starts
            else if (e.Button == MouseButtons.Left)
            {
                if (element == null)
                {
                    element = GraphDiagram.GetElement(this.diagramLayer, this.downInitialpoint);
                }
                //If the item is not selected, it is selected before the drag & Drop operation is started
                if (!element.Selected)
                {
                    //If the CONTROL key is not pressed the other elements are deselected
                    if (Control.ModifierKeys != Keys.Control)
                    {
                        DeselectAll();
                    }
                    SelectElement(element);
                    //The temporary layer is updated
                    this.selectLayer.UpdateSurface();
                    if (this.ElementSelectedChanged != null)
                    {
                        this.ElementSelectedChanged(this, new EventArgs());
                    }
                }
                throw new OperationException(Operation.Select, "Change to Drag&Drop operation");
            }
            //The mouse cursor is updated as appropriate
            else
            {
                if (element == null)
                {
                    if ((Cursor.Current != Cursors.Hand) && (this.CursorChanged != null))
                    {
                        this.CursorChanged(this, new CursorEventArgs(Cursors.Hand));
                    }
                }
                else
                if ((Cursor.Current != Cursors.Default) && (this.CursorChanged != null))
                {
                    this.CursorChanged(this, new CursorEventArgs(Cursors.Default));
                }
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// This method undos the operation
 /// </summary>
 public void Undo()
 {
     //se eliminan los GraphElements de la capa de diagrama y del Logical diagram
     GraphDiagram.DeleteElements(this.diagramLayer, this.diagram, this.graphElements);
     //The diagram layer is updated
     this.diagramLayer.UpdateSurface();
     //It is indicated that the diagram has changed
     if (this.DiagramChanged != null)
     {
         this.DiagramChanged(this, new EventArgs());
     }
 }
Ejemplo n.º 24
0
 /// <summary>
 /// This method undos the operation
 /// </summary>
 public void Undo()
 {
     //The GraphElement of the diagram layer and the logical diagram is removed
     GraphDiagram.DeleteElement(this.diagramLayer, this.diagram, this.graphElement);
     //The diagram layer is updated
     this.diagramLayer.UpdateSurface();
     //It is indicated that the diagram has changed
     if (this.DiagramChanged != null)
     {
         this.DiagramChanged(this, new EventArgs());
     }
 }
Ejemplo n.º 25
0
        public void CanConstructGraphDiagram()
        {
            var A = Tensor.TwoD("A", (4, 3), "a", out Index a, out Index b);
            var B = Tensor.TwoD("B", (6, 7));
            var C = Tensor.TwoD("C", (8, 9));
            TensorExpression te = A[a, b];

            GraphDiagram d = new GraphDiagram(te.ToTree());

            Assert.Equal(4, d.Graph.NodeCount);
            Assert.Equal(3, d.Graph.EdgeCount);

            te = A[a, b] * C[a, b];
            d  = new GraphDiagram(te.ToTree());
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Initializes a new instance of the UndirectedConnectToExpression object.
        /// </summary>
        /// <param name="graph">Reference to the graph that contains all nodes in the set of sources.</param>
        /// <param name="sources">The set of sources.</param>
        public UndirectedConnectToExpression(GraphDiagram <T, UndirectedEdge> graph, IEnumerable <GraphNode <T, UndirectedEdge> > sources)
        {
            if (null == graph)
            {
                throw new ArgumentNullException();
            }

            if (null == sources)
            {
                throw new ArgumentNullException();
            }

            this.graph   = graph;
            this.sources = sources;
        }
Ejemplo n.º 27
0
 public void MouseDown(MouseEventArgs e)
 {
     //This is for the right and left mouse buttons
     if ((e.Button == MouseButtons.Left) || (e.Button == MouseButtons.Right))
     {
         //The position of the Down event is saved for possible new operations
         this.downInitialpoint = e.Location;
         GraphElement element = GraphDiagram.GetElement(this.diagramLayer, e.Location);
         //If it is not pressed on any element, it is changed to the Nop operation
         if (element == null)
         {
             //The context of the Select operation is cleaned
             this.ClearOperationContext();
             throw new OperationException(Operation.Select, "Change to Nop Operation");
         }
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Occurs when the context menu is opened: Selects the item if it is not in that state
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Menu_Popup(object sender, EventArgs e)
        {
            GraphElement element = GraphDiagram.GetElement(this.diagramLayer, this.downInitialpoint);

            //You look at the selected state of the item
            if (!element.Selected)
            {
                //If the CONTROL key is not pressed the other elements are deselected
                if (Control.ModifierKeys != Keys.Control)
                {
                    DeselectAll();
                }
                SelectElement(element);
                //The temporary layer is updated
                this.selectLayer.UpdateSurface();
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Selects the item sent as a parameter
 /// </summary>
 /// <param name="element">Item to select</param>
 private void SelectElement(GraphElement element)
 {
     //The item is selected
     element.Selected = true;
     //The element is loaded into the temporary layer
     this.selectLayer.AddElement(element);
     if (GraphDiagram.ValidateCopy(this.selectLayer.Elements))
     {
         this.miCopy.Enabled = true;
         this.miCut.Enabled  = true;
     }
     else
     {
         if (this.OperationDisabled != null)
         {
             this.OperationDisabled(this, new OperationEventArgs(Operation.Copy));
             this.OperationDisabled(this, new OperationEventArgs(Operation.Cut));
         }
         this.miCopy.Enabled = false;
         this.miCut.Enabled  = false;
     }
     if (GraphDiagram.ValidateDelete(this.selectLayer.Elements))
     {
         this.miRemove.Enabled = true;
     }
     else
     {
         if (this.OperationDisabled != null)
         {
             this.OperationDisabled(this, new OperationEventArgs(Operation.Delete));
         }
         this.miRemove.Enabled = false;
     }
     if (GraphDiagram.ValidateSettings(this.selectLayer.Elements))
     {
         this.miSettings.Enabled = true;
     }
     else
     {
         if (this.OperationDisabled != null)
         {
             this.OperationDisabled(this, new OperationEventArgs(Operation.Settings));
         }
         this.miSettings.Enabled = false;
     }
 }
Ejemplo n.º 30
0
        public void UpdateArrow(List <Point> points, Color arrowColor)
        {
            Point minPoint = GraphDiagram.MinPoint(points);
            Point maxPoint = GraphDiagram.MaxPoint(points);
            Size  size     = new Size(maxPoint.X - minPoint.X + 1, maxPoint.Y - minPoint.Y + 1);

            this.Surface = new Surface(size);
            this.Surface.Fill(GraphDiagram.TRASPARENT_COLOR);
            for (int i = 0; i < (points.Count - 1); i++)
            {
                this.Surface.Draw(new Line(new Point(points[i].X - minPoint.X, points[i].Y - minPoint.Y), new Point(points[i + 1].X - minPoint.X, points[i + 1].Y - minPoint.Y)), arrowColor);
            }
            //The color of transparency is indicated
            this.Transparent      = true;
            this.TransparentColor = GraphDiagram.TRASPARENT_COLOR;
            this.Position         = minPoint;
        }