internal EdgeController(GraphController graphController)
 {
     this.graphController = graphController;
     edgeCollection = new Dictionary<uint, VisualEdge>();
     this.selectedSlots = new List<uint>();
     connectingEdge = new VisualEdge(this, EdgeType.ExplicitConnection);
 }
        public bool CheckEdgeType(uint compId)
        {
            if (compId == 0 || compId == uint.MaxValue)
            {
                return(false);
            }

            VisualEdge edge = GetVisualEdge(compId);

            return(edge.EdgeType == EdgeType.ExplicitConnection);
        }
        internal static IVisualEdge Create(EdgeController edgeController, IStorage storage)
        {
            if (edgeController == null || storage == null)
            {
                throw new ArgumentNullException("edgeController, storage");
            }

            IVisualEdge edge = new VisualEdge(edgeController);

            edge.Deserialize(storage);
            return(edge);
        }
        public void TestDeserializeNullException()
        {
            IStorage storage = null;
            GraphController graphController = new GraphController(null);
            EdgeController edgeController = new EdgeController(graphController);
            IVisualEdge edge = new VisualEdge(edgeController, 0x30000001, 0x30000002, false);

            Assert.Throws<ArgumentNullException>(() =>
            {
                edge.Deserialize(storage);
            });
        }
        public void TestCreate02()
        {
            IStorage storage = new BinaryStorage();
            GraphController graphController = new GraphController(null);
            EdgeController edgeController = new EdgeController(graphController);
            IVisualEdge edge00 = new VisualEdge(edgeController, 0x30000001, 0x30000002, false);

            edge00.Serialize(storage);
            storage.Seek(0, SeekOrigin.Begin);
            IVisualEdge edge01 = VisualEdge.Create(edgeController, storage);

            Assert.AreEqual(edge00.EdgeId, edge01.EdgeId);
            Assert.AreEqual(edge00.StartSlotId, edge01.StartSlotId);
            Assert.AreEqual(edge00.EndSlotId, edge01.EndSlotId);
        }
        public void TestRecordEdgeCreationForUndo00()
        {
            GraphController graphController = new GraphController(null);
            UndoRedoRecorder urr = new UndoRedoRecorder(graphController);
            EdgeController edgeController = new EdgeController(graphController);

            List<IVisualEdge> edgeList = new List<IVisualEdge>();
            VisualEdge edge = new VisualEdge(edgeController, EdgeType.ExplicitConnection);
            edgeList.Add(edge);

            Assert.Throws<InvalidOperationException>(() =>
            {
                urr.RecordEdgeCreationForUndo(edgeList);
            });
        }
        internal IVisualEdge CreateEdgeFromStorage(IStorage storage)
        {
            if (!this.IsInUndoRedoCommand)
            {
                throw new InvalidOperationException("Can only be access for undo/redo");
            }

            if (null == edgeController)
            {
                throw new InvalidOperationException("'edgeController' was not created");
            }

            if (null == storage)
            {
                throw new ArgumentNullException("storage");
            }

            return(VisualEdge.Create(this.edgeController, storage));
        }
        internal void ClearPreviewSelection(uint componentId)
        {
            selectedEdge = null;
            edgeCollection.TryGetValue(componentId, out selectedEdge);

            if (selectedEdge != null)
            {
                selectedEdge.PreviewSelected = selectedEdge.Selected;
                selectedEdge.Compose();
            }
        }
        //just remove the edge but no operation on slots
        // undo/redo helpers
        private void DeleteVisualEdge(VisualEdge edgToDelete)
        {
            IGraphVisualHost visualHost = graphController.GetVisualHost();
            if (null != visualHost)
                visualHost.RemoveDrawingVisual(edgToDelete.EdgeId);

            edgeCollection.Remove(edgToDelete.EdgeId);
        }
Exemple #10
0
        private void DrawSingleConnectingEdgeTo(uint startSlotId, Point endPoint, DrawingContext context)
        {
            Slot startSlot = graphController.GetSlot(startSlotId) as Slot;
            Point startPoint = startSlot.GetPosition();

            VisualEdge connectingEdge = new VisualEdge(this, EdgeType.ExplicitConnection);
            connectingEdge.ComposeConnectingEdge(context, startPoint, endPoint, (startSlot.SlotType != SlotType.Output));
        }
Exemple #11
0
        internal bool SelectComponent(uint componentId, ModifierKeys modifiers)
        {
            selectedEdge = null;
            edgeCollection.TryGetValue(componentId, out selectedEdge);

            if (selectedEdge != null)
            {
                if (modifiers.HasFlag(ModifierKeys.Control))
                    selectedEdge.Selected = !selectedEdge.Selected;
                else
                    selectedEdge.Selected = true;

                selectedEdge.Compose();
            }

            return true;
        }
Exemple #12
0
        internal void ResetParameters()
        {
            currentlySelectedNodeId = uint.MaxValue;
            currentlySelectedSlotId = uint.MaxValue;
            currentlySelectedSlotType = SlotType.None;

            connectNodeId = uint.MaxValue;
            connectSlotId = uint.MaxValue;
            connectSlotType = SlotType.None;

            reconnectingEdges = new List<uint>();
            reconnectingSlots = new List<uint>();
            lastConnectedSlotId = uint.MaxValue;
            reconnectEdgeId = uint.MaxValue;

            connectingEdge = null;
        }
Exemple #13
0
 internal void AddEdge(VisualEdge edge)
 {
     edgeCollection.Add(edge.EdgeId, edge);
 }
Exemple #14
0
        private void DeleteEdge(VisualEdge edgeToDelete)
        {
            //Assignment Swapping
            if (edgeToDelete.EdgeType == EdgeType.ExplicitConnection)
            {
                VisualNode outputNode = graphController.GetVisualNode(graphController.GetSlot(edgeToDelete.StartSlotId).Owners.Last());
                outputNode.HandleRemoveConnection(edgeToDelete.StartSlotId);
                VisualNode intputNode = graphController.GetVisualNode(graphController.GetSlot(edgeToDelete.EndSlotId).Owners.Last());
                intputNode.HandleRemoveConnection(edgeToDelete.EndSlotId);
            }

            UndoRedoRecorder urr = graphController.GetUndoRedoRecorder();
            List<IVisualEdge> edgesToDelete = new List<IVisualEdge>();
            edgesToDelete.Add(edgeToDelete);
            urr.RecordEdgeDeletionForUndo(edgesToDelete);

            IGraphVisualHost visualHost = graphController.GetVisualHost();
            if (null != visualHost)
                visualHost.RemoveDrawingVisual(edgeToDelete.EdgeId);

            Slot.Disconnect((Slot)graphController.GetSlot(edgeToDelete.StartSlotId), (Slot)graphController.GetSlot(edgeToDelete.EndSlotId));
            edgeCollection.Remove(edgeToDelete.EdgeId);
        }
Exemple #15
0
        private bool FindEdgeToBeReplaced(uint startSlotId, out VisualEdge edgeToBeReplaced)
        {
            bool findEdgeToBeReplaced;
            edgeToBeReplaced = null;
            if (connectSlotType == SlotType.Input)
            {
                this.inputSlotId = startSlotId;
                this.outputSlotId = connectSlotId;
            }
            else
            {
                this.inputSlotId = connectSlotId;
                this.inputSlotId = startSlotId;
            }

            findEdgeToBeReplaced = FindEdgeToBeReplaced(out edgeToBeReplaced);
            return findEdgeToBeReplaced;
        }
Exemple #16
0
        private VisualEdge RebuildImplicitEdge(Slot outputSlot, Slot inputSlot)
        {
            this.outputSlotId = outputSlot.SlotId;
            this.inputSlotId = inputSlot.SlotId;
            var entry = edgeCollection.FirstOrDefault(x => IsAdded(x.Value));
            if ((edgeCollection.Count() == 0) || (entry.Value == null))
            {
                IdGenerator idGenerator = ((GraphController)graphController).GetIdGenerator();
                VisualEdge visualEdge = new VisualEdge(this, outputSlot.SlotId, inputSlot.SlotId, true);
                edgeCollection.Add(visualEdge.EdgeId, visualEdge);
                visualEdge.Dirty = true;
                visualEdge.Compose();
                return visualEdge;
            }

            entry.Value.Dirty = true;
            entry.Value.Compose();
            return entry.Value;
        }
Exemple #17
0
        private VisualEdge RebuildEdge(uint outputNodeId, uint outputSlotId, int outputSlotIndex, uint inputNodeId, uint inputSlotId, int inputSlotIndex)
        {
            this.inputSlotId = inputSlotId;
            var entry = new KeyValuePair<uint, VisualEdge>();

            List<uint> connectingSlots = new List<uint>();
            if (graphController.GetSlot(inputSlotId).ConnectingSlots != null)
                connectingSlots.AddRange(graphController.GetSlot(inputSlotId).ConnectingSlots);

            this.outputSlotId = outputSlotId;

            entry = edgeCollection.FirstOrDefault(x => IsAdded(x.Value));
            if ((edgeCollection.Count() == 0) || (entry.Value == null))//need to recover edge and drawing
            {
                IdGenerator idGenerator = ((GraphController)graphController).GetIdGenerator();
                VisualEdge visualEdge = new VisualEdge(this, outputSlotId, inputSlotId, false);

                edgeCollection.Add(visualEdge.EdgeId, visualEdge);

                //addVisual
                visualEdge.Dirty = true;
                visualEdge.Compose();
                return visualEdge;
            }

            entry.Value.Dirty = true;
            entry.Value.Compose();
            return entry.Value;
        }
Exemple #18
0
 private bool IsSelected(VisualEdge visualEdge)
 {
     return (visualEdge == selectedEdge);
 }
Exemple #19
0
 private bool IsAdded(VisualEdge visualEdge)
 {
     return (visualEdge.StartSlotId == outputSlotId) && (visualEdge.EndSlotId == inputSlotId);
 }
Exemple #20
0
        private bool FindEdgeToBeReplaced(out VisualEdge edgeToBeReplaced)
        {
            edgeToBeReplaced = null;

            List<uint> slotsConnectToInputSlot = new List<uint>();
            ISlot inputSlot = graphController.GetSlot(this.inputSlotId);

            if (inputSlot != null && inputSlot.ConnectingSlots != null)
                slotsConnectToInputSlot.AddRange(inputSlot.ConnectingSlots);
            if (slotsConnectToInputSlot.Count() > 0)
            {
                this.outputSlotId = inputSlot.ConnectingSlots[0];
                var pair = edgeCollection.FirstOrDefault(x => IsAdded(x.Value));
                edgeToBeReplaced = pair.Value;
            }

            return (edgeToBeReplaced != null);
        }
        public void TestDeserilaizeOperationException()
        {
            IStorage storage = new BinaryStorage();
            GraphController graphController = new GraphController(null);
            EdgeController edgeController = new EdgeController(graphController);
            IVisualEdge edge = new VisualEdge(edgeController, 0x30000001, 0x30000002, false);

            storage.WriteUnsignedInteger(FieldCode.EdgeSignature, 12);
            storage.Seek(0, SeekOrigin.Begin);

            Assert.Throws<InvalidOperationException>(() =>
            {
                edge.Deserialize(storage);
            });
        }
Exemple #22
0
        internal VisualEdge CreateLinkingEdge(Slot outputSlot, Slot inputSlot)
        {
            this.outputSlotId = outputSlot.SlotId;
            this.inputSlotId = inputSlot.SlotId;
            var entry = edgeCollection.FirstOrDefault(x => IsAdded(x.Value));
            if ((edgeCollection.Count() != 0) && (entry.Value != null))
                return null;

            IdGenerator idGenerator = ((GraphController)graphController).GetIdGenerator();
            VisualEdge visualEdge = new VisualEdge(this, outputSlot.SlotId, inputSlot.SlotId, false);
            Slot.Connect(outputSlot, inputSlot);
            edgeCollection.Add(visualEdge.EdgeId, visualEdge);
            visualEdge.Dirty = true;
            visualEdge.Compose();

            //record
            UndoRedoRecorder urr = graphController.GetUndoRedoRecorder();
            List<IVisualEdge> edgesCreated = new List<IVisualEdge>();
            edgesCreated.Add(visualEdge);
            urr.RecordEdgeCreationForUndo(edgesCreated);

            return visualEdge;
        }
Exemple #23
0
        internal static IVisualEdge Create(EdgeController edgeController, IStorage storage)
        {
            if (edgeController == null || storage == null)
                throw new ArgumentNullException("edgeController, storage");

            IVisualEdge edge = new VisualEdge(edgeController);
            edge.Deserialize(storage);
            return edge;
        }
Exemple #24
0
        private VisualEdge AddEdge(uint outputSlotId, uint inputSlotId)
        {
            UndoRedoRecorder urr = graphController.GetUndoRedoRecorder();

            //for edge replace
            this.inputSlotId = inputSlotId;
            this.outputSlotId = outputSlotId;
            if (FindEdgeToBeReplaced(out edgeToBeReplaced))
            {
                DeleteEdge(edgeToBeReplaced);
            }

            //add edge
            VisualEdge visualEdge = null;

            IdGenerator idGenerator = ((GraphController)graphController).GetIdGenerator();
            visualEdge = new VisualEdge(this, outputSlotId, inputSlotId, false);

            edgeCollection.Add(visualEdge.EdgeId, visualEdge);

            //maintain connection
            Slot outputSlot = (Slot)graphController.GetSlot(outputSlotId);
            Slot inputSlot = (Slot)graphController.GetSlot(inputSlotId);
            Slot.Connect(outputSlot, inputSlot);

            //addVisual
            visualEdge.Dirty = true;
            visualEdge.Compose();

            //record
            List<IVisualEdge> edgesCreated = new List<IVisualEdge>();
            edgesCreated.Add(visualEdge);
            urr.RecordEdgeCreationForUndo(edgesCreated);

            // Assignment Swapping
            VisualNode outputNode = graphController.GetVisualNode(graphController.GetSlot(outputSlotId).Owners.Last());
            outputNode.HandleNewConnection(outputSlotId);
            VisualNode inputNode = graphController.GetVisualNode(graphController.GetSlot(inputSlotId).Owners.Last());
            inputNode.HandleNewConnection(inputSlotId);

            return visualEdge;
        }