Esempio n. 1
0
 public static Graph CreateDrawingGraph(GeometryGraph gg)
 {
     counter = 0;
     localMap = new Dictionary<GeometryNode,Node>();
     dg = new Graph(counter++.ToString()) { GeometryGraph = gg };
     foreach (GeometryNode n in gg.Nodes)
     {
         Node node = new Node(counter++.ToString());
         node.Attr.Shape = Shape.Ellipse;
         node.GeometryNode = n;
         dg.AddNode(node);
         localMap[n]=node;
     }
     Subgraph cluster = new Subgraph(counter++.ToString());
     cluster.GeometryNode = gg.RootCluster;
     dg.RootSubgraph = cluster;
     PopulateClusters(cluster, gg.RootCluster);
 
     foreach (GeometryEdge e in gg.Edges)
     {
         Edge edge = new Edge(localMap[e.Source], localMap[e.Target], ConnectionToGraph.Disconnected);
         edge.Attr.ArrowheadAtSource = e.ArrowheadAtSource ? ArrowStyle.Normal : ArrowStyle.None;
         edge.Attr.ArrowheadAtTarget = e.ArrowheadAtTarget ? ArrowStyle.Normal : ArrowStyle.None;
         edge.GeometryEdge = e;
         dg.AddPrecalculatedEdge(edge);
     }
     //PopulateClusterEdges(dg.RootSubgraph, gg.RootCluster);
     
     return dg;
 }
Esempio n. 2
0
        public XNode(Node node, string category = null)
        {
            Node      = node;
            _category = category;

            Border b    = new Border();
            double size = node.Label.Text.Length * 9;

            b.Width       = size + 12;
            b.Height      = size * 2 / 3 + 4;
            _visualObject = b;

            Brush strokeBrush = CommonX.BrushFromMsaglColor(Node.Attr.Color);

            if (category != null)
            {
                Brush brush = Categories.GetBrush(_category);
                if (brush != null)
                {
                    strokeBrush = brush;
                }
            }

            BoundaryPath = new Path {
                //Data = CreatePathFromNodeBoundary(),
                Stroke          = strokeBrush,
                Fill            = CommonX.BrushFromMsaglColor(Node.Attr.FillColor),
                StrokeThickness = Node.Attr.LineWidth
            };

            Node.Attr.LineWidthHasChanged += AttrLineWidthHasChanged;
            //Node.Attr.GeometryNode.LayoutChangeEvent += GeometryNodeBeforeLayoutChangeEvent;
        }
Esempio n. 3
0
        private void GenerateFilesGraph()
        {
            foreach (var file in _mainModel.Files.Values)
            {
                DrawingNode tmpNode = new DrawingNode(file.Filename);
                tmpNode.LabelText  = file.Filename + "\nSize: " + file.Size;
                tmpNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond;
                Color newColor = generateColor(tmpNode.Attr.Color);
                tmpNode.Attr.FillColor = newColor;
                if (file.ChangedSinceLastCommit)
                {
                    tmpNode.LabelText      += "[NEW]";
                    tmpNode.Label.FontStyle = FontStyle.Bold;
                }
                graph.AddNode(tmpNode);
            }

            foreach (var file in _mainModel.Files.Values)
            {
                foreach (var rFile in file.FileRelationsByClassReferences.Values)
                {
                    graph.AddEdge(file.Filename, rFile.ReferencesCount + "", rFile.Reference.Filename);
                }
            }
        }
Esempio n. 4
0
 public virtual void UpdateGraphNode(Node graphNode)
 {
     graphNode.Attr.LabelWidthToHeightRatio = 1;
     graphNode.Attr.Shape = Shape.Box;
     graphNode.Attr.FillColor = GameMasterNode.kGreen;
     graphNode.Attr.LabelMargin = 6;
 }
Esempio n. 5
0
        public void InsertRelationship(string sourceLabel, string targetLabel, Relationship relationship, DrawingEdge edge)
        {
            relationship.IsAddedOnViewGraph = true;
            relationship.Source.Label       = sourceLabel;
            relationship.Target.Label       = targetLabel;

            DrawingNode sourceNode = GraphEditor.Graph.FindNode(relationship.InEntity);
            DrawingNode targetNode = GraphEditor.Graph.FindNode(relationship.OutEntity);

            Submodel.NodeLocalType source = sourceNode.UserData as Submodel.NodeLocalType;
            Submodel.NodeLocalType target = targetNode.UserData as Submodel.NodeLocalType;

            int    count    = 0;
            string relName  = relationship.Name;
            string typeName = relationship.Type;

            while (Relationships.Relationship.Any(item => item.Name == relName))
            {
                relName  += count++;
                typeName += count;
            }

            relationship.Name = relName;
            relationship.Type = typeName;
            relationship.Target.ReferenceGuid = target.Entity.Guid;
            relationship.Source.ReferenceGuid = source.Entity.Guid;

            Model.Relationships.Relationship.Add(relationship);
            relationship.SetDrawingEdge(edge);
        }
Esempio n. 6
0
        protected static void DrawNode(Node n, Graph graph)
        {
            if (n == null)
            {
                return;
            }
            //do not draw what already was drawn
            if (graph.Nodes.Any(nn => nn.Id == n.Id))
            {
                return;
            }

            Microsoft.Msagl.Drawing.Node
                newNode = new Microsoft.Msagl.Drawing.Node(n.Id)
            {
                LabelText = n.Caption ?? "?"
            };
            //newNode.Attr.FillColor = Color.LightGray;
            //font font size
            //newNode.Label.FontSize = 11;
            graph.AddNode(newNode);
            //if (parent != null)
            //    graph.AddEdge(parent.Id, n.Id);

            n.ChildNodes.ForEach(chN => DrawNode(chN, graph));
            n.ChildNodes.ForEach(chN => graph.AddEdge(n.Id, chN.Id));
        }
Esempio n. 7
0
        private void AddInitNode(Graph graph, string nodeName, bool IsFinal = false, State s = null)
        {
            Microsoft.Msagl.Drawing.Node init = new Microsoft.Msagl.Drawing.Node(nodeName);
            init.Attr.FillColor = Color.LavenderBlush;
            init.Attr.Shape     = Shape.Octagon;
            if (IsFinal)
            {
                init.Attr.AddStyle(Style.Bold);
                init.Attr.FillColor = Color.PowderBlue;
            }

            init.Attr.XRadius   = 6;
            init.Attr.YRadius   = 6;
            init.Attr.LineWidth = 2;
            if (s != null)
            {
                init.UserData = s;
            }
            else
            {
                init.UserData = nodeName;
            }

            graph.AddNode(init);
        }
        ICurve GetNodeBoundaryCurve(DrawingNode node)
        {
            double width  = 0;
            double height = 0;

            if (graphObjectsToFrameworkElements.ContainsKey(node))
            {
                FrameworkElement fe = graphObjectsToFrameworkElements[node];
                if (fe == null)
                {
                    return(CurveFactory.CreateRectangleWithRoundedCorners(10, 10, 1, 1, new Point()));
                }
                width  = fe.Width + 2 * node.Attr.LabelMargin;
                height = fe.Height + 2 * node.Attr.LabelMargin;
            }
            else
            {
                return(CurveFactory.CreateRectangleWithRoundedCorners(10, 10, 5, 5, new Point()));
            }


            if (width < drawingGraph.Attr.MinNodeWidth * 2)
            {
                width = drawingGraph.Attr.MinNodeWidth * 2;
            }
            if (height < drawingGraph.Attr.MinNodeHeight * 2)
            {
                height = drawingGraph.Attr.MinNodeHeight * 2;
            }

            return(NodeBoundaryCurves.GetNodeBoundaryCurve(node, width, height));
        }
 private void UpdateMsaglNodeLabel(MsaglGraphs.Node node, SgvlGraphs.Vertex vertex) {
     // Если метка пустая - номер вершины, если непустая, то ставим метку рядом с номером (иначе никак)
     if (string.IsNullOrEmpty(vertex.Label))
         node.LabelText = node.Id.ToString();
     else
         node.LabelText = $"{node.Id}   {vertex.Label}";
 }
Esempio n. 10
0
        private static void DrawIcon(Graphics g, DrawingNode node)
        {
            NodeDisplaySettings settings = node.UserData as NodeDisplaySettings;
            Image image = settings.Icon;

            if (image == null)
            {
                return;
            }

            // Flip the image around its center.
            var m     = g.Transform;
            var saveM = m.Clone();

            m.Multiply(new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y));

            g.Transform = m;

            var x = (float)(node.GeometryNode.Center.X - (node.GeometryNode.Width / 2) + (node.Attr.LabelMargin / 2));
            var y = (float)(node.GeometryNode.Center.Y - (kIconSize / 2));

            // Apply fade-out alpha to the icon.
            ColorMatrix colorMatrix = new ColorMatrix();

            colorMatrix.Matrix33 = settings.IsFadedOut ? 0.5f : 1.0f;
            ImageAttributes imageAttributes = new ImageAttributes();

            imageAttributes.SetColorMatrix(colorMatrix);

            g.DrawImage(image, new Rectangle((int)x, (int)y, kIconSize, kIconSize), 0, 0, kIconSize, kIconSize, GraphicsUnit.Pixel, imageAttributes);

            g.Transform = saveM;
        }
Esempio n. 11
0
 public static void SetupNodeRendering(DrawingNode node)
 {
     System.Diagnostics.Debug.Assert(node.Attr.Shape == Shape.Box, "Only box nodes are supported");
     node.DrawNodeDelegate     = new DelegateToOverrideNodeRendering(DrawNode);
     node.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(GetNodeBoundary);
     node.UserData             = new NodeDisplaySettings();
 }
Esempio n. 12
0
        public bool DrawNode18(DrawingNode node, object graphics)
        {
            var g = (Graphics)graphics;

            //flip the image around its center
            using (Matrix m = g.Transform){
                using (Matrix saveM = m.Clone()){
                    var clipNow = g.Clip;
                    g.Clip = new Region(Draw.CreateGraphicsPath(node.GeometryNode.BoundaryCurve));
                    var geomNode = node.GeometryNode;
                    var leftTop  = geomNode.BoundingBox.LeftTop;
                    using (var m2 = new Matrix(1, 0, 0, -1, (float)leftTop.X, (float)leftTop.Y)){
                        m.Multiply(m2);
                        g.Transform = m;
                        var rect = new RectangleF(0, 0, (float)geomNode.Width, (float)geomNode.Height);
                        using (var lBrush = new LinearGradientBrush(rect, System.Drawing.Color.Red,
                                                                    System.Drawing.Color.Yellow,
                                                                    LinearGradientMode.BackwardDiagonal)
                               ){
                            g.FillRectangle(lBrush, rect);
                        }
                        g.Transform = saveM;
                        g.Clip      = clipNow;
                    }
                }
            }
            return(false); //returning false would enable the default rendering
        }
Esempio n. 13
0
        private static void DrawLabel(Graphics g, DrawingNode node)
        {
            var label    = node.Label;
            var settings = node.UserData as NodeDisplaySettings;

            var labelColor = Draw.MsaglColorToDrawingColor(label.FontColor);

            if (settings.IsFadedOut)
            {
                labelColor = Color.FromArgb(128, labelColor.R, labelColor.G, labelColor.B);
            }

            var brush = new SolidBrush(labelColor);

            var fontStyle = (System.Drawing.FontStyle)(int) label.FontStyle;

            if (settings.HasUnsavedChanges)
            {
                fontStyle = System.Drawing.FontStyle.Bold;
            }
            var font = new Font(label.FontName, (float)label.FontSize, fontStyle);

            var bbox = node.GeometryNode.BoundingBox;
            var rect = new RectangleF((float)bbox.Left, (float)bbox.Bottom - node.Attr.LabelMargin, (float)bbox.Width, (float)bbox.Height);

            if ((node.UserData as NodeDisplaySettings).Icon != null)
            {
                rect.Offset(kIconSize, 0);
                var size = rect.Size;
                size.Width -= kIconSize;
                rect.Size   = size;
            }

            DrawStringInRectCenter(g, brush, font, label.Text, rect);
        }
Esempio n. 14
0
 protected void MakeNodePrivate(Node node)
 {
     node.Attr.Shape = Shape.Box;
     node.Attr.LabelMargin = 3;
     node.Attr.FillColor = GameMasterNode.kPurple;
     node.Label.FontSize = 6;
 }
        void RemoveVNode(DrawingNode drawingNode)
        {
            //            foreach (var outEdge in drawingNode.OutEdges) {
            //                graph.Edges.Remove(outEdge);
            //                outEdge.TargetNode.RemoveInEdge(outEdge);
            //            }
            //            foreach (var inEdge in drawingNode.InEdges) {
            //                graph.Edges.Remove(inEdge);
            //                inEdge.SourceNode.RemoveOutEdge(inEdge);
            //            }
            //            var selfEdges = drawingNode.SelfEdges.ToArray();
            //            foreach (var selfEdge in selfEdges)
            //                drawingNode.RemoveSelfEdge(selfEdge);
            //
            //            foreach (var edge in drawingNode.Edges.Concat(selfEdges)) {
            //                IViewerObjectX vedge;
            //                if (!drawingObjectsToIViewerObjects.TryGetValue(edge, out vedge)) continue;
            //
            //                graphCanvas.Children.Remove(((VEdge)vedge).Path);
            //                drawingObjectsToIViewerObjects.Remove(edge);
            //            }
            var vnode = (XNode)drawingObjectsToIViewerObjects[drawingNode];
            var vgrid = graphObjectsToFrameworkElements[drawingNode];

            graphCanvas.Children.Remove(vgrid);
            graphCanvas.Children.Remove(vnode.BoundaryPath);
            drawingObjectsToIViewerObjects.Remove(drawingNode);
        }
Esempio n. 16
0
        private bool DrawNode(Node node, object graphics)
        {
            var graphic = (Graphics)graphics;
            var image   = (Image)this.imagesHashtable[node.Id];

            using (Matrix matrix = graphic.Transform)
            {
                using (Matrix matrixClone = matrix.Clone())
                {
                    graphic.SetClip(this.FillTheGraphicsPath(node.GeometryNode.BoundaryCurve));
                    using (var matrixMult = new Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y))
                        matrix.Multiply(matrixMult);

                    graphic.Transform = matrix;
                    graphic.DrawImage(image, new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2),
                                                        (float)(node.GeometryNode.Center.Y - node.GeometryNode.Height / 2)));
                    var centerX = (float)node.GeometryNode.Center.X;
                    var centerY = (float)node.GeometryNode.Center.Y;
                    graphic.DrawString(node.LabelText, this.drawFont, this.drawBrush, new PointF(centerX, centerY), this.format);
                    graphic.Transform = matrixClone;
                    graphic.ResetClip();
                }
            }
            return(true); // Returning false would enable the default rendering
        }
        List<Edge> Bfs(Node root, Node target)
        {
            ((NodeData)(root.UserData)).TraverseParent = null;
            ((NodeData)(target.UserData)).TraverseParent = null;

            var queue = new Queue<Node>();
            var discovered = new HashSet<Node>();
            queue.Enqueue(root);

            while (queue.Count > 0)
            {
                Node current = queue.Dequeue();
                discovered.Add(current);

                if (current.Id == target.Id)
                    return GetPath(current);

                var nodeEdges = current.OutEdges;
                foreach (var edge in nodeEdges)
                {
                    var next = edge.TargetNode;
                    var c = ((EdgeData)(edge.UserData)).currFlow;
                    if (c > 0 && !discovered.Contains(next))
                    {
                        ((NodeData)(next.UserData)).TraverseParent = current;
                        queue.Enqueue(next);
                    }
                }
            }
            return null;
        }
Esempio n. 18
0
        void ReadNodeFeatures(Node node)
        {
            GexfNodeAttr gexfNodeAttr;

            idsToGexfNodeAttr[node.Id] = gexfNodeAttr = new GexfNodeAttr();
            while (xmlReader.IsStartElement())
            {
                switch (xmlReader.Name)
                {
                case "viz:color":
                    ReadColor(node);
                    break;

                case "viz:position":
                    ReadPosition(gexfNodeAttr);
                    break;

                case "viz:size":
                    ReadSize(gexfNodeAttr);
                    break;

                default:
                    xmlReader.Skip();
                    break;
                }
                xmlReader.Read();
            }
        }
Esempio n. 19
0
        internal static DGraph CreateDGraphAndGeometryInfo(DrawingGraph drawingGraph, GeometryGraph gleeGraph)
        {
            DGraph ret = new DGraph(drawingGraph);

            //create dnodes and glee node boundary curves
            foreach (GeometryNode geomNode in gleeGraph.NodeMap.Values)
            {
                DrawingNode drawingNode = geomNode.UserData as DrawingNode;
                CreateDNodeAndSetNodeBoundaryCurve(drawingGraph, ret, geomNode, drawingNode);
            }

            foreach (GeometryEdge gleeEdge in gleeGraph.Edges)
            {
                DEdge dEdge = new DEdge(ret.GetNode(gleeEdge.Source), ret.GetNode(gleeEdge.Target), gleeEdge.UserData as DrawingEdge, Connection.Connected);
                ret.AddEdge(dEdge);
                DrawingEdge drawingEdge             = dEdge.Edge;
                Microsoft.Msagl.Drawing.Label label = drawingEdge.Label;

                if (label != null)
                {
                    double width, height;
                    CreateDLabel(dEdge, label, out width, out height);
                }
            }

            return(ret);
        }
Esempio n. 20
0
        public ICurve GetNodeBoundary(DrawingNode node)
        {
            double width  = treeImage.Width / 2.0;
            double height = treeImage.Height / 2.0;

            return(CurveFactory.CreateRectangleWithRoundedCorners(width, height, width * radiusRatio, height * radiusRatio, new Point()));
        }
Esempio n. 21
0
        private void ToggleActorsForCharacter(DrawingNode n)
        {
            // Already have Characters showing // remove all Out Edges and descendants that only come from here.
            if (n.OutEdges.Count() > 0)
            {
                RemoveAllOutItems(n);
            }
            else
            {
                Character c       = n.UserData as Character;
                String    movieID = c.Name; // + " (" + m.ReleaseYear + ")";
                //////Compile Error now that Character has Actor ID.
                ////foreach (Person a in c.Actors)
                ////{
                ////    AE(master, aeMaster, movieID, a.Name, ActorColor, a);
                ////    SetNodeDelegate(FN(master, a.Name)); // Allows this node to be custom draw

                ////    //    foreach (Actor a in m.GetActorsWhoPlayedCharacter(c.Name))
                ////    //    {
                ////    //        AE(master, aeMaster, c.Name, a.Name, ActorColor, a);
                ////    //        SetNodeDelegate(FN(master, a.Name)); // Allows this node to be custom draw

                ////    //    }

                ////}
            }
        }
Esempio n. 22
0
        private void ToggleCharactersForMovie(DrawingNode n)
        {
            // Already have Characters showing // remove all Out Edges and descendants that only come from here.
            if (n.OutEdges.Count() > 0)
            {
                RemoveAllOutItems(n);
            }
            else
            {
                Movie m = n.UserData as Movie;
                //String movieID = m.Title + " (" + m.ReleaseYear + ")";
                String movieID = m.Title + " (" + m.ReleaseDate.Value.ToShortDateString() + ")";
                foreach (Character c in u.GetCharactersInMovie(m.TmdbId, 10)) // Need GetCharacters in Movie
                {
                    AE(master, aeMaster, movieID, c.Name, CharacterColor, c);
                    SetNodeDelegate(FN(master, c.Name)); // Allows this node to be custom draw

                    //    foreach (Actor a in m.GetActorsWhoPlayedCharacter(c.Name))
                    //    {
                    //        AE(master, aeMaster, c.Name, a.Name, ActorColor, a);
                    //        SetNodeDelegate(FN(master, a.Name)); // Allows this node to be custom draw

                    //    }
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Draw new shape
        /// </summary>
        /// <param name="centerLocation"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private Microsoft.Msagl.Drawing.Node Draw(Microsoft.Msagl.Core.Geometry.Point centerLocation)
        {
            graph = gViewer.Graph;
            var id = drawForm.ShapeId;

            Microsoft.Msagl.Drawing.Node node = graph.AddNode(id);
            node.Label.Text     = drawForm.ShapeLabel;
            node.Attr.Shape     = drawForm.ChosenShape;
            node.Attr.Color     = Color.Black;
            node.Attr.FillColor = new Microsoft.Msagl.Drawing.Color(drawForm.ChosenColor.A,
                                                                    drawForm.ChosenColor.R,
                                                                    drawForm.ChosenColor.G,
                                                                    drawForm.ChosenColor.B);
            node.Attr.LineWidth  = MinSize / 5;
            node.Attr.XRadius    = node.Attr.YRadius = MinSize / 2;
            node.Label.FontColor = Color.Black;
            node.Label.FontSize  = drawForm.FontSize;

            NodeWidth  = drawForm.ShapeWidth;
            NodeHeight = drawForm.ShapeHeight;
            NodeCenter = centerLocation;
            node.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(DrawCurve);
            //if (drawForm.BackgroundNode)
            //{
            //    node.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(GetNodeBoundary);
            //    node.DrawNodeDelegate = new DelegateToOverrideNodeRendering(DrawImageNode);
            //    drawForm.BackgroundNode = false;
            //}
            IViewerNode dNode = gViewer.CreateIViewerNode(node, centerLocation, null);

            gViewer.AddNode(dNode, true);
            // gViewer.ResizeNodeToLabel(node);
            return(node);
        }
Esempio n. 24
0
            void CreateNodeGeometry(DrawingNode node, Graph graph, GeometryGraph geometryGraph, GeometryPoint center, ConnectionToGraph connectionTo = ConnectionToGraph.Connected)
            {
                double width, height;

                StringMeasure.MeasureWithFont(node.Label.Text, new Font(node.Label.FontName, (float)node.Label.FontSize, (System.Drawing.FontStyle)(int) node.Label.FontStyle), out width,
                                              out height);

                node.Label.Width  = width;
                node.Label.Height = height;

                if (node.Label != null)
                {
                    width  += 2 * node.Attr.LabelMargin;
                    height += 2 * node.Attr.LabelMargin;
                }
                if (width < graph.Attr.MinNodeWidth)
                {
                    width = graph.Attr.MinNodeWidth;
                }
                if (height < graph.Attr.MinNodeHeight)
                {
                    height = graph.Attr.MinNodeHeight;
                }

                Node geomNode =
                    node.GeometryNode =
                        GeometryGraphCreator.CreateGeometryNode(graph, geometryGraph, node, connectionTo);

                geomNode.BoundaryCurve = NodeBoundaryCurves.GetNodeBoundaryCurve(node, width, height);
                geomNode.BoundaryCurve.Translate(center);
                geomNode.Center = center;
            }
Esempio n. 25
0
        internal bool DrawNode(DrawingNode node, object graphics)
        {
            var g = (Graphics)graphics;

            //flip the image around its center
            using (Matrix m = g.Transform) {
                using (Matrix saveM = m.Clone()) {
                    var clipNow = g.Clip;
                    g.Clip = new Region(Draw.CreateGraphicsPath(node.GeometryNode.BoundaryCurve));
                    var geomNode = node.GeometryNode;
                    var leftTop  = geomNode.BoundingBox.LeftTop;
                    var scale    =
                        (float)
                        Math.Min(node.BoundingBox.Height / treeImage.Height, node.BoundingBox.Width / treeImage.Width);
                    using (var m2 = new Matrix(scale, 0, 0, -scale, (float)leftTop.X, (float)leftTop.Y)) {
                        m.Multiply(m2);
                        g.Transform = m;
                        g.DrawImage(treeImage, 0, 0);
                        g.Transform = saveM;
                        g.Clip      = clipNow;
                    }
                }
            }
            return(false); //returning false would enable the default rendering
        }
        internal VNode(Node node, FrameworkElement frameworkElementOfNodeForLabelOfLabel,
                       Func <Edge, VEdge> funcFromDrawingEdgeToVEdge, Func <double> pathStrokeThicknessFunc)
        {
            PathStrokeThicknessFunc = pathStrokeThicknessFunc;
            Node = node;
            FrameworkElementOfNodeForLabel = frameworkElementOfNodeForLabelOfLabel;

            _funcFromDrawingEdgeToVEdge = funcFromDrawingEdgeToVEdge;

            CreateNodeBoundaryPath();
            if (FrameworkElementOfNodeForLabel != null)
            {
                FrameworkElementOfNodeForLabel.Tag = this; //get a backpointer to the VNode
                Common.PositionFrameworkElement(FrameworkElementOfNodeForLabel, node.GeometryNode.Center, 1);
                Panel.SetZIndex(FrameworkElementOfNodeForLabel, Panel.GetZIndex(BoundaryPath) + 1);
            }
            SetupSubgraphDrawing();
            Node.Attr.VisualsChanged += (a, b) => Invalidate();
            Node.IsVisibleChanged    += obj =>
            {
                foreach (var frameworkElement in FrameworkElements)
                {
                    frameworkElement.Visibility = Node.IsVisible ? Visibility.Visible : Visibility.Hidden;
                }
            };
        }
        void FordFulkersonAlgo(Node nodeSource, Node nodeTerminal)
        {
            label_flow.Text = "Przepływ = 0";
            invalidateFlow();

            var flow = 0f;
            var path = Bfs(nodeSource, nodeTerminal);
            List<AlgoState> steps = new List<AlgoState>(); AlgoState cas = new AlgoState();

            while (path != null && path.Count > 0)
            {
                label_flow.Text = "Przepływ = " + flow;
                var minCapacity = float.MaxValue;
                foreach (var edge in path)
                {
                    if (((EdgeData)(edge.UserData)).currFlow < minCapacity)
                        minCapacity = ((EdgeData)(edge.UserData)).currFlow;
                }

                AugmentPath(path, minCapacity);
                flow += minCapacity;

                clearColors();
                reloadLabels();
                foreach (Edge e in path)
                {
                    foreach (Edge e2 in graph.Edges)
                    {
                        if (e2.Source == e.Source && e2.Target == e.Target) e2.Attr.Color = Color.Red;
                        //dirty code written without understanding Graph class - fixme!
                    }
                }
                label_flow.Text = "Przepływ = " + flow;
                redraw();
                DialogResult dr = MessageBox.Show("Tak=kontynuuj, Nie=wstecz o jeden krok", "pauza", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes) {
                    cas.g = graph; cas.p = path; steps.Add(cas); 
                    path = Bfs(nodeSource, nodeTerminal);
                }
                else if (dr == DialogResult.No)
                {
                    if (steps.Count < 1)
                    {
                        MessageBox.Show("Nie można sie cofnąć!");
                    }
                    else { 
                        cas = steps[steps.Count - 1];
                        steps.RemoveAt(steps.Count - 1);
                        graph = cas.g; path = cas.p;
                        label_flow.Text = "Przepływ = " + flow;
                        continue;
                    }
                }
            }

            clearColors();
            reloadLabels();
            MessageBox.Show("Maksymalny przepływ wynosi: "+flow.ToString());
        }
Esempio n. 28
0
 /// <summary>
 /// Compute the size of the block
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public ICurve GetNodeBoundary(Node node)
 {
     const double radiusRatio = 0.3;
     var extent = Layout.CalculateExtent();
     double height = extent.Height;
     double width = extent.Width;
     return CurveFactory.CreateRectangleWithRoundedCorners(width, height, width * radiusRatio, height * radiusRatio, new P2());
 }
        LgNodeInfo GetCorrespondingLgNode(DrawingNode node)
        {
            var lgGraphBrowsingSettings = drawingGraph.LayoutAlgorithmSettings as LgLayoutSettings;

            return(lgGraphBrowsingSettings == null
                       ? null
                       : lgGraphBrowsingSettings.GeometryNodesToLgNodeInfos[node.GeometryNode]);
        }
Esempio n. 30
0
        private ICurve NodeBoundaryDelegate(Node node)
        {
            var    image  = (Image)this.imagesHashtable[node.Id];
            double width  = image.Width;
            double height = image.Height;

            return(CurveFactory.CreateRectangle(width, height, new Point()));
        }
Esempio n. 31
0
        public static RectangleF getHeaderRectangle(Microsoft.Msagl.Drawing.Node node)
        {
            Microsoft.Msagl.Core.Geometry.Point p = node.GeometryNode.Center;
            float w = (float)node.Width;
            float h = (float)node.Height;

            return(new RectangleF((float)(p.X - w / 2), (float)(p.Y - h / 2), w, WIDTH));
        }
Esempio n. 32
0
 protected void SetNodeForStatement(IStatement ist, Stage stg, Node nd)
 {
     if (!stmtNodeMap.ContainsKey(stg))
     {
         stmtNodeMap[stg] = new Dictionary <IStatement, Node>(ReferenceEqualityComparer <IStatement> .Instance);
     }
     stmtNodeMap[stg][ist] = nd;
 }
Esempio n. 33
0
        void ReadColor(Node node)
        {
            var r = byte.Parse(GetAttr("r"));
            var g = byte.Parse(GetAttr("g"));
            var b = byte.Parse(GetAttr("b"));

            node.Attr.Color = new Color(r, g, b);
        }
Esempio n. 34
0
 private static void CreateSourceNode(Node a)
 {
     a.Attr.Shape     = Microsoft.Msagl.Drawing.Shape.Box;
     a.Attr.XRadius   = 3;
     a.Attr.YRadius   = 3;
     a.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Green;
     a.Attr.LineWidth = 10;
 }
Esempio n. 35
0
        ICurve GetNodeBoundary(Microsoft.Msagl.Drawing.Node node)
        {
            Image  image  = ImageOfNode(node);
            double width  = image.Width;
            double height = image.Height;

            return(CurveFactory.CreateRectangleWithRoundedCorners(width, height, width * radiusRatio, height * radiusRatio, new MSAGLPoint()));
        }
Esempio n. 36
0
        private void CreateTargetNode(Node a)
        {
            a.Attr.Shape     = Microsoft.Msagl.Drawing.Shape.DoubleCircle;
            a.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGray;

            a.Attr.LabelMargin = -4;
            a.UserData         = this;
        }
Esempio n. 37
0
 public AutomatonViewModel()
 {
     graph = new Graph();
     graph.Attr.LayerDirection = LayerDirection.LR;
     dummy = new Node(" ");
     dummy.IsVisible = false;
     graph.AddNode(dummy);
     ResetAll();
 }
Esempio n. 38
0
        internal DNode(DGraph graph, DrawingNode drawingNode)
            : base(graph)
        {
            this.DrawingNode = drawingNode;
            _OutEdges = new List<DEdge>();
            _InEdges = new List<DEdge>();
            _SelfEdges = new List<DEdge>();
            PortsToDraw = new Set<Port>();

            if (drawingNode.Label != null)
                Label = new DTextLabel(this, drawingNode.Label);
        }
Esempio n. 39
0
 private Image ImageOfNode(DrawingNode node) {
     Image image;
     if (node.Id == leavesId)
         image = leaves;
     else if (node.Id == creekId)
         image = creek;
     else if (node.Id == wId)
         image = waterfall;
     else
         image = tree;
     return image;
 }
Esempio n. 40
0
 static ICurve CreateLabelAndBoundary(Node node)
 {
     node.Attr.Shape = Shape.DrawFromGeometry;
     node.Attr.LabelMargin *= 2;
     double width;
     double height;
     StringMeasure.MeasureWithFont(node.Label.Text,
                                   new Font(node.Label.FontName, (float)node.Label.FontSize), out width, out height);
     node.Label.Width = width;
     node.Label.Height = height;
     int r = node.Attr.LabelMargin;
     return CurveFactory.CreateRectangleWithRoundedCorners(width + r * 2, height + r * 2, r, r, new Point());
 }
Esempio n. 41
0
        internal DNode(DObject graph, DrawingNode drawingNode)
            : base(graph)
        {
            this.DrawingNode = drawingNode;
            _OutEdges = new List<DEdge>();
            _InEdges = new List<DEdge>();
            _SelfEdges = new List<DEdge>();
            PortsToDraw = new Set<Port>();

            if (drawingNode.Label != null && drawingNode.Label.GeometryLabel != null)
                Label = new DTextLabel(this, drawingNode.Label);

            if (!(this is DCluster))
                Canvas.SetZIndex(this, 10000);
        }
      /// <summary>
      /// a helper function to creat a node boundary curve 
      /// </summary>
      /// <param name="node">the node</param>
      /// <param name="width">the node width</param>
      /// <param name="height">the node height</param>
      /// <returns></returns>
    public  static ICurve GetNodeBoundaryCurve(Node node, double width, double height)
    {
      if (node == null)
        throw new InvalidOperationException();
      NodeAttr nodeAttr = node.Attr;

      switch (nodeAttr.Shape)
      {
        case Shape.Ellipse:
        case Shape.DoubleCircle:
          return CurveFactory.CreateEllipse(width, height, new P2(0, 0));
        case Shape.Circle:
          {
            double r = Math.Max(width / 2, height / 2);
            return CurveFactory.CreateEllipse(r, r, new P2(0, 0));
          }

        case Shape.Box:
              if (nodeAttr.XRadius != 0 || nodeAttr.YRadius != 0)
                  return CurveFactory.CreateRectangleWithRoundedCorners(width, height, nodeAttr.XRadius,
                                                                       nodeAttr.YRadius, new P2(0, 0));
              return CurveFactory.CreateRectangle(width, height, new P2(0, 0));


          case Shape.Diamond:
          return CurveFactory.CreateDiamond(
            width, height, new P2(0, 0));
              
          case Shape.House:
              return CurveFactory.CreateHouse(width, height, new P2());

          case Shape.InvHouse:
              return CurveFactory.CreateInvertedHouse(width, height, new P2());
          case Shape.Octagon:
              return CurveFactory.CreateOctagon(width, height, new P2());
#if DEBUG
          case Shape.TestShape:
              return CurveFactory.CreateTestShape(width, height);
#endif
      
        default:
          {
            //  Console.WriteLine("creating ellipse for shape {0}",nodeAttr.Shape);
            return new Ellipse(
              new P2(width / 2, 0), new P2(0, height / 2), new P2());
          }
      }
    }
        internal GraphmapsNode(Node node, LgNodeInfo lgNodeInfo, FrameworkElement frameworkElementOfNodeForLabelOfLabel,
            Func<Edge, GraphmapsEdge> funcFromDrawingEdgeToVEdge, Func<double> pathStrokeThicknessFunc)
        {
            PathStrokeThicknessFunc = pathStrokeThicknessFunc;
            LgNodeInfo = lgNodeInfo;
            Node = node;
            FrameworkElementOfNodeForLabel = frameworkElementOfNodeForLabelOfLabel;

            this.funcFromDrawingEdgeToVEdge = funcFromDrawingEdgeToVEdge;

            CreateNodeBoundaryPath();
            if (FrameworkElementOfNodeForLabel != null) {
                FrameworkElementOfNodeForLabel.Tag = this; //get a backpointer to the VNode 
                Common.PositionFrameworkElement(FrameworkElementOfNodeForLabel, node.GeometryNode.Center, 1);
                Panel.SetZIndex(FrameworkElementOfNodeForLabel, Panel.GetZIndex(BoundaryPath) + 1);
            }
            SetupSubgraphDrawing();
            Node.GeometryNode.BeforeLayoutChangeEvent += GeometryNodeBeforeLayoutChangeEvent;
            Node.Attr.VisualsChanged += (a, b) => Invalidate();         
           
        }
Esempio n. 44
0
        internal VNode(Node node, FrameworkElement frameworkElementOfNodeForLabelOfLabel,
            Func<Edge, VEdge> funcFromDrawingEdgeToVEdge, Func<double> pathStrokeThicknessFunc) {
            PathStrokeThicknessFunc = pathStrokeThicknessFunc;
            Node = node;
            FrameworkElementOfNodeForLabel = frameworkElementOfNodeForLabelOfLabel;

            _funcFromDrawingEdgeToVEdge = funcFromDrawingEdgeToVEdge;

            CreateNodeBoundaryPath();
            if (FrameworkElementOfNodeForLabel != null) {
                FrameworkElementOfNodeForLabel.Tag = this; //get a backpointer to the VNode 
                Common.PositionFrameworkElement(FrameworkElementOfNodeForLabel, node.GeometryNode.Center, 1);
                Panel.SetZIndex(FrameworkElementOfNodeForLabel, Panel.GetZIndex(BoundaryPath) + 1);
            }
            SetupSubgraphDrawing();
            Node.Attr.VisualsChanged += (a, b) => Invalidate();
            Node.IsVisibleChanged += obj => {
                foreach (var frameworkElement in FrameworkElements) {
                    frameworkElement.Visibility = Node.IsVisible ? Visibility.Visible : Visibility.Hidden;
                }
            };
        }
Esempio n. 45
0
        public bool DrawNode(Node node, object graphics)
        {
            Graphics g = (Graphics)graphics;

            var m = g.Transform;
            var saveM = g.Transform.Clone();
            //      g.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve));

            // This is supposed to flip the text around its center

            var c = (float)node.GeometryNode.Center.Y;
            using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c))
            {
                m.Multiply(m2);
            }

            m.Translate(
                (float)node.GeometryNode.Center.X,
                (float)node.GeometryNode.Center.Y);

            g.Transform = m;

            var styleStack = GetStyleStack();
            var painter = new TextViewPainter(
                Layout, g,
                SystemColors.WindowText,
                SystemColors.Window,
                SystemFonts.DefaultFont, styleStack);
            var ptr = new TextPointer { Character = 0, Span = 0, Line = TextModel.StartPosition };
            painter.SetSelection(ptr, ptr);
            painter.PaintGdiPlus();
            g.Transform = saveM;
            g.ResetClip();

            saveM.Dispose();
       //     m.Dispose();
            return true;//returning false would enable the default rendering
        }
Esempio n. 46
0
        bool DrawNode(DrawingNode node, object graphics) {
            Graphics g = (Graphics)graphics;
            Image image = ImageOfNode(node);

            //flip the image around its center
            using (System.Drawing.Drawing2D.Matrix m = g.Transform)
            {
                using (System.Drawing.Drawing2D.Matrix saveM = m.Clone())
                {

                    g.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve));
                    using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y))
                        m.Multiply(m2);

                    g.Transform = m;
                    g.DrawImage(image, new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2),
                        (float)(node.GeometryNode.Center.Y - node.GeometryNode.Height / 2)));
                    g.Transform = saveM;

                }
            }

            return true;//returning false would enable the default rendering
        }
 void WriteBox(Node node)
 {
     WriteStartElement("rect");
     WriteFill(node.Attr);
     WriteStroke(node.Attr);
     var curve = node.GeometryNode.BoundaryCurve;
     WriteAttribute("x", node.BoundingBox.Left);
     WriteAttribute("y", node.BoundingBox.Bottom);
     WriteAttribute("width", curve.BoundingBox.Width);
     WriteAttribute("height", curve.BoundingBox.Height);
     WriteAttribute("rx", node.Attr.XRadius);
     WriteAttribute("ry", node.Attr.YRadius);
     WriteEndElement();
 }
Esempio n. 48
0
        public void AddState(string id, bool isAccepting)
        {
            if (IsDuplicated(id))
                throw new ArgumentException("State ID is duplicated.");

            var state = new StateViewModel(id, isAccepting);
            states.Add(state);

            Node node = new Node(id);
            if (isAccepting)
                node.Attr.Shape = Shape.DoubleCircle;
            else
                node.Attr.Shape = Shape.Circle;
            graph.AddNode(node);

            if (InitialStateIndex == -1)
                InitialStateIndex = 0;
        }
Esempio n. 49
0
        private void CreateTargetNode(Node a) {
            a.Attr.Shape = Microsoft.Msagl.Drawing.Shape.DoubleCircle;
            a.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGray;

            a.Attr.LabelMargin = -4;
            a.UserData = this;
        }
Esempio n. 50
0
 private static void CreateSourceNode(Node a) {
     a.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box;
     a.Attr.XRadius = 3;
     a.Attr.YRadius = 3;
     a.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Green;
     a.Attr.LineWidth = 10;
 }
 void WriteDoubleCircle(Node node)
 {
     var geomNode = node.GeometryNode;
     var center = geomNode.Center;
     var rx = geomNode.Width / 2;
     var ry = geomNode.Height / 2;
     WriteEllipseOnPosition(node.Attr, center, rx * DoubleCircleOffsetRatio, ry * DoubleCircleOffsetRatio);
     WriteEllipseOnPosition(node.Attr, center, rx, ry);
 }
 void WriteEllipse(Node node)
 {
     var geomNode = node.GeometryNode;
     var center = geomNode.Center;
     var rx = geomNode.Width / 2;
     var ry = geomNode.Height / 2;
     WriteEllipseOnPosition(node.Attr, center, rx, ry);
 }
Esempio n. 53
0
        Node CreateDrawingNodeByUsingDialog() {
            RichTextBox richBox;
            var window = CreateNodeDialog(out richBox);
            window.ShowDialog();

            var r = new Random();
            var i = r.Next();

            var createdNode = new Node(i.ToString());
            var s = new TextRange(richBox.Document.ContentStart, richBox.Document.ContentEnd).Text;
            createdNode.LabelText = s.Trim('\r', '\n', ' ', '\t');
            return createdNode;
        }
 void WriteDiamond(Node node)
 {
     NodeAttr nodeAttr = node.Attr;
     double w2 = node.GeometryNode.Width / 2.0f;
     double h2 = node.GeometryNode.Height / 2.0f;
     double cx = node.GeometryNode.Center.X;
     double cy = node.GeometryNode.Center.Y;
     var ps = new[]{
                       new Point(cx - w2,  cy),
                       new Point( cx,  cy + h2),
                       new Point(cx +  w2,  cy),
                       new Point( cx,  cy -  h2)
                   };
     DrawPolygon(node.Attr, ps);
 }
Esempio n. 55
0
        public bool DrawNode18(DrawingNode node, object graphics){
            var g = (Graphics)graphics;

            //flip the image around its center
            using (Matrix m = g.Transform){
                using (Matrix saveM = m.Clone()){
                    var clipNow = g.Clip;
                    g.Clip = new Region(Draw.CreateGraphicsPath(node.GeometryNode.BoundaryCurve));
                    var geomNode = node.GeometryNode;
                    var leftTop = geomNode.BoundingBox.LeftTop;
                    using (var m2 = new Matrix(1, 0, 0, -1, (float) leftTop.X, (float) leftTop.Y)){

                        m.Multiply(m2);
                        g.Transform = m;
                        var rect = new RectangleF(0, 0, (float)geomNode.Width, (float)geomNode.Height);
                        using (var lBrush = new LinearGradientBrush(rect, System.Drawing.Color.Red,
                                                                    System.Drawing.Color.Yellow,
                                                                    LinearGradientMode.BackwardDiagonal)
                            ){
                            g.FillRectangle(lBrush, rect);
                        }
                        g.Transform = saveM;
                        g.Clip = clipNow;
                    }
                }
            }
            return false; //returning false would enable the default rendering

        }
Esempio n. 56
0
 void InsertNodeIntoGraph(Rectangle rectangle) {
     Node node = new Node("testNode");
     node.Attr.FillColor=Color.Red;
     node.Attr.Shape = Shape.DrawFromGeometry;
      node.Label=null;
     var geomNode =
         node.GeometryNode = GeometryGraphCreator.CreateGeometryNode(gViewer.Graph, gViewer.Graph.GeometryGraph, node, ConnectionToGraph.Disconnected);
     var center = (rectangle.LeftBottom + rectangle.RightTop) / 2;
     geomNode.BoundaryCurve = CurveFactory.CreateRectangle(rectangle.Width, rectangle.Height, center);
     node.GeometryNode=geomNode;
     var dNode = gViewer.CreateIViewerNode(node);
     gViewer.AddNode(dNode, true);
 }
Esempio n. 57
0
        public ICurve GetNodeBoundary(DrawingNode node) {
            double width = treeImage.Width/2.0;
            double height = treeImage.Height/2.0;

            return CurveFactory.CreateRectangleWithRoundedCorners(width, height, width * radiusRatio, height * radiusRatio, new Point());
        }
Esempio n. 58
0
 /// <summary>
 /// Changes a node's label and updates the display
 /// </summary>
 /// <param name="n">The node whose label has to be changed</param>
 /// <param name="newLabel">The new label</param>
 internal void RelabelNode(DrawingNode n, string newLabel) {
     n.Label.Text = newLabel;
     
     gViewer.ResizeNodeToLabel(n);
     System.Diagnostics.Debug.WriteLine(n.Label.Text);
 }
Esempio n. 59
0
        internal bool DrawNode(DrawingNode node, object graphics) {
            var g = (Graphics) graphics;

            //flip the image around its center
            using (Matrix m = g.Transform) {
                using (Matrix saveM = m.Clone()) {
                    var clipNow = g.Clip;
                    g.Clip = new Region(Draw.CreateGraphicsPath(node.GeometryNode.BoundaryCurve));
                    var geomNode = node.GeometryNode;
                    var leftTop = geomNode.BoundingBox.LeftTop;
                    var scale =
                        (float)
                        Math.Min(node.BoundingBox.Height/treeImage.Height, node.BoundingBox.Width/treeImage.Width);
                    using (var m2 = new Matrix(scale, 0, 0, -scale, (float) leftTop.X, (float) leftTop.Y)) {
                        m.Multiply(m2);
                        g.Transform = m;
                        g.DrawImage(treeImage, 0, 0);
                        g.Transform = saveM;
                        g.Clip = clipNow;
                    }
                }
            }
            return false; //returning false would enable the default rendering

        }
Esempio n. 60
-29
        public XNode(Node node, string category = null)
        {
            Node = node;
            _category = category;

            Border b = new Border();
            double size = node.Label.Text.Length * 9;
            b.Width = size + 12;
            b.Height = size * 2 / 3 + 4;
            _visualObject = b;

            Brush strokeBrush = CommonX.BrushFromMsaglColor(Node.Attr.Color);
            if (category != null)
            {
                Brush brush = Categories.GetBrush(_category);
                if (brush != null) strokeBrush = brush;
            }

            BoundaryPath = new Path {
                //Data = CreatePathFromNodeBoundary(),
                Stroke = strokeBrush,
                Fill = CommonX.BrushFromMsaglColor(Node.Attr.FillColor),
                StrokeThickness = Node.Attr.LineWidth
            };

            Node.Attr.LineWidthHasChanged += AttrLineWidthHasChanged;
            //Node.Attr.GeometryNode.LayoutChangeEvent += GeometryNodeBeforeLayoutChangeEvent;
        }