Example #1
0
        void WriteFromMsaglCurve(Node node)
        {
            NodeAttr attr = node.Attr;

            var iCurve = node.GeometryNode.BoundaryCurve;
            var c      = iCurve as Curve;

            if (c != null)
            {
                WriteCurve(c, node);
            }
            else
            {
                var ellipse = iCurve as Ellipse;
                if (ellipse != null)//a bug when the axis are rotated
                {
                    WriteEllipseOnPosition(node.Attr, ellipse.Center, ellipse.AxisA.Length, ellipse.AxisB.Length);
                }
                else
                {
                    var poly = iCurve as Polyline;
                    if (poly != null)
                    {
                        WriteCurve(CreateCurveFromPolyline(poly), node);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
        }
Example #2
0
        /// <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.Hexagon:
                return(CurveFactory.CreateHexagon(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()));
            }
            }
        }
        void WriteEllipseOnPosition(NodeAttr nodeAttr, Point center, double rx, double ry)
        {
            WriteStartElement("ellipse");
            WriteFill(nodeAttr);
            WriteStroke(nodeAttr);

            WriteFullEllipseGeometry(center, rx, ry);
            WriteEndElement();
        }
Example #4
0
        /// <summary>
        /// Creates a Node instance
        /// </summary>
        /// <param name="id">node name</param>
        public Node(string id)
        {
            Label = new Label();
            Label.GeometryLabel = null;

            Label.Owner = this;
            Attr        = new NodeAttr();
            attr.Id     = id;
            Label.Text  = id; //one can change the label later
        }
Example #5
0
        /// <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(Microsoft.Msagl.Splines.CurveFactory.CreateEllipse(width, height, new P2(0, 0)));

            case Shape.Circle: {
                double r = Math.Max(width / 2, height / 2);
                return(Microsoft.Msagl.Splines.CurveFactory.CreateEllipse(r, r, new P2(0, 0)));
            }

            case Shape.Box:
                return(Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, nodeAttr.XRadius, nodeAttr.YRadius, new P2(0, 0)));


            case Shape.Diamond:
                return(Microsoft.Msagl.Splines.CurveFactory.CreateDiamond(
                           width, height, new P2(0, 0)));

            case Shape.House:
                return(Microsoft.Msagl.Splines.CurveFactory.CreateHouse(width, height, new P2()));

            case Shape.InvHouse:
                return(Microsoft.Msagl.Splines.CurveFactory.CreateInvHouse(width, height, new P2()));

            case Shape.Octagon:
                return(Microsoft.Msagl.Splines.CurveFactory.CreateOctagon(width, height, new P2()));

#if DEBUG
            case Shape.TestShape:
                return(Microsoft.Msagl.Splines.CurveFactory.CreateTestShape(width, height));
#endif

            default: {
                if (node.Attr.GeometryNode == null || node.Attr.GeometryNode.BoundaryCurve == null)
                {
                    return(new Microsoft.Msagl.Splines.Ellipse(
                               new P2(width / 2, 0), new P2(0, height / 2), new P2()));
                }
                else
                {
                    return(ScaleCurveToDescribeAroundRectangle(node.Attr.GeometryNode.BoundaryCurve.Translate(-node.Attr.GeometryNode.Center), width, height));
                }
            }
            }
        }
Example #6
0
        /// <summary>
        /// Creates a Node instance
        /// </summary>
        /// <param name="id">node name</param>
        public Node(string id)
        {
            this.DefaultStyleKey = typeof(Node);

            Label = new Label();
            Label.GeometryLabel = null;
            Label.Owner         = this;
            Label.Text          = id; // one can change the label text later - TJT: Huh???

            Attr    = new NodeAttr();
            attr.Id = id;
        }
Example #7
0
 private void WriteNodeAttr(NodeAttr na)
 {
     WriteStartElement(Tokens.NodeAttribute);
     WriteBaseAttr(na as AttributeBase);
     WriteColorElement(Tokens.Fillcolor, na.FillColor);
     WriteStringElement(Tokens.LabelMargin, na.LabelMargin);
     WriteStringElement(Tokens.Padding, na.Padding);
     WriteStringElement(Tokens.Shape, na.Shape);
     WriteStringElement(Tokens.XRad, na.XRadius);
     WriteStringElement(Tokens.YRad, na.YRadius);
     WriteEndElement();
 }
Example #8
0
        /// <summary>
        /// Creates a Node instance
        /// </summary>
        /// <param name="id">node name</param>
        public Node(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                throw new InvalidOperationException("creating a node with a null or empty id");
            }

            this.Label = new Label();

            this.Attr       = new NodeAttr();
            this.attr.Id    = id;
            this.Label.Text = id; //one can change the label later
        }
Example #9
0
        private void ReadNode()
        {
            CheckToken(Tokens.Node);
            XmlRead();
            NodeAttr nodeAttr = new NodeAttr();

            ReadNodeAttr(nodeAttr);
            Node node = graph.AddNode(nodeAttr.Id);

            node.Attr = nodeAttr;
            ReadLabel(node);
            ReadEndElement();
        }
Example #10
0
 private void ReadNodeAttr(NodeAttr na)
 {
     CheckToken(Tokens.NodeAttribute);
     XmlRead();
     ReadBaseAttr(na);
     na.FillColor   = ReadColorElement(Tokens.Fillcolor);
     na.LabelMargin = ReadIntElement(Tokens.LabelMargin);
     na.Padding     = ReadDoubleElement(Tokens.Padding);
     na.Shape       = (Shape)Enum.Parse(typeof(Shape), ReadStringElement(Tokens.Shape), false);
     na.XRadius     = ReadDoubleElement(Tokens.XRad);
     na.YRadius     = ReadDoubleElement(Tokens.YRad);
     ReadEndElement();
 }
 void WriteFill(NodeAttr attr)
 {
     var color = attr.FillColor;
     if (color.A == 0 && !attr.Styles.Contains(Style.Filled))
     {
         WriteAttribute("fill", "none");
     }
     else
     {
         WriteAttribute("fill", MsaglColorToSvgColor(color));
         WriteAttribute("fill-opacity", MsaglColorToSvgOpacity(color));
     }
 }
 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);
 }
Example #13
0
        void ReadNodeContent()
        {
            XmlRead();
            object userData = null;

            if (TokenIs(Tokens.UserData))
            {
                userData = ReadUserData();
            }
            var    nodeAttr     = new NodeAttr();
            Node   node         = null;
            string nodeTypeName = "";
            Type   nodeType;

            try
            {
                // Only try reading to ensure backward compatibility with older MSAGL file formates
                nodeTypeName = ReadNodeType();
                ReadNodeAttr(nodeAttr);
                nodeType = GetTypeByName(nodeTypeName);
                node     = (Node)Activator.CreateInstance(nodeType, new object[] { nodeAttr.Id });
            }
            catch
            {
                // fall back to Node
                ReadNodeAttr(nodeAttr);
                node = graph.AddNode(nodeAttr.Id);
            }
            try
            {
                // Only try reading to ensure backward compatibility with older MSAGL file formates
                node.IsVisible = ReadVisibility();
            }
            catch
            {
                node.IsVisible = true;
            }
            graph.AddNode(node);
            node.Label    = null;
            node.Attr     = nodeAttr;
            node.UserData = userData;
            ReadLabel(node);
            ReadEndElement();
        }
Example #14
0
        void ReadNodeContent()
        {
            XmlRead();
            object userData = null;

            if (TokenIs(Tokens.UserData))
            {
                userData = ReadUserData();
            }
            var nodeAttr = new NodeAttr();

            ReadNodeAttr(nodeAttr);
            var node = graph.AddNode(nodeAttr.Id);

            node.Label    = null;
            node.Attr     = nodeAttr;
            node.UserData = userData;
            ReadLabel(node);
            ReadEndElement();
        }
Example #15
0
        Subgraph ReadSubgraphContent()
        {
            object userData = null;

            if (TokenIs(Tokens.UserData))
            {
                userData = ReadUserData();
            }
            var nodeAttr = new NodeAttr();

            ReadNodeAttr(nodeAttr);
            var subgraph = new Subgraph(nodeAttr.Id)
            {
                Label = null, Attr = nodeAttr, UserData = userData
            };

            ReadLabel(subgraph);
            ReadEndElement();
            return(subgraph);
        }
Example #16
0
        static void DrawEllipseOnPosition(DNode dNode, NodeAttr nodeAttr, Canvas g, float x, float y, float width,
                                          float height, Brush pen)
        {
            throw new NotImplementedException();
            /*
            if (NeedToFill(dNode.FillColor))
                g.FillEllipse(new SolidBrush(dNode.FillColor), x, y, width, height);
            if (nodeAttr.Shape == Shape.Point)
                g.FillEllipse(new SolidBrush(pen.Color), x, y, width, height);

            g.DrawEllipse(pen, x, y, width, height); //*/
        }
 Subgraph ReadSubgraphContent()
 {
     object userData = null;
     if (TokenIs(Tokens.UserData))
         userData = ReadUserData();
     var nodeAttr = new NodeAttr();
     ReadNodeAttr(nodeAttr);
     var subgraph = new Subgraph(nodeAttr.Id) {Label = null, Attr = nodeAttr, UserData = userData};
     ReadLabel(subgraph);
     ReadEndElement();
     return subgraph;
 }
 void WriteFill(NodeAttr attr)
 {
     var color = attr.FillColor;
     if (color.A == 0 && !attr.Styles.Contains(Style.Filled))
     {
         WriteAttribute("fill", "none");
     }
     else
     {
         WriteAttribute("fill", MsaglColorToSvgColor(color));
         WriteAttribute("fill-opacity", MsaglColorToSvgOpacity(color));
     }
 }
        void WriteEllipseOnPosition(NodeAttr nodeAttr, Point center, double rx, double ry)
        {
            WriteStartElement("ellipse");
            WriteFill(nodeAttr);
            WriteStroke(nodeAttr);

            WriteFullEllipseGeometry(center, rx, ry);
            WriteEndElement();
        }
 void WriteFillAndStroke(NodeAttr attr)
 {
     WriteFill(attr);
     WriteStroke(attr);
 }
 void WritePolyline(Polyline poly, NodeAttr attr)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Clones the node attribute
        /// </summary>
        /// <returns></returns>
        public NodeAttr Clone()
        {
            NodeAttr r = this.MemberwiseClone() as NodeAttr;

            return(r);
        }
 void ReadNodeContent() {
     XmlRead();
     object userData = null;
     if (TokenIs(Tokens.UserData))
         userData = ReadUserData();
     var nodeAttr = new NodeAttr();
     ReadNodeAttr(nodeAttr);
     var node = graph.AddNode(nodeAttr.Id);
     node.Label = null;
     node.Attr = nodeAttr;
     node.UserData = userData;
     ReadLabel(node);
     ReadEndElement();
 }
  private void ReadNodeAttr(NodeAttr na) {
      CheckToken(Tokens.NodeAttribute); 
      XmlRead();
      ReadBaseAttr(na);
      na.FillColor = ReadColorElement(Tokens.Fillcolor);
      na.LabelMargin=ReadIntElement(Tokens.LabelMargin);
      na.Padding=ReadDoubleElement(Tokens.Padding);
      na.Shape = (Shape) Enum.Parse(typeof(Shape), ReadStringElement(Tokens.Shape), false);
      na.XRadius=ReadDoubleElement(Tokens.XRad);
      na.YRadius=ReadDoubleElement(Tokens.YRad);
      ReadEndElement();
 
  }
 static Node TryToCreateGeomNode(double width, double height, P2 center, NodeAttr nodeAttr) {
     if (width == 0 || height == 0)
         return null;
    
     var curve = CreateCurveByShape(72*width, 72*height, center, nodeAttr);
     if (curve != null)
         return new Node(curve);
     return null;
 }
 void WriteFillAndStroke(NodeAttr attr)
 {
     WriteFill(attr);
     WriteStroke(attr);
 }
        static ICurve CreateCurveByShape(double width, double height, P2 center, NodeAttr nodeAttr) {
            ICurve curve = null;
            switch (nodeAttr.Shape) {
                case Shape.Diamond:
                    curve = CurveFactory.CreateDiamond(width, height, center);
                    break;
                case Shape.Ellipse:
                    break;
                case Shape.Box:
                    curve = CurveFactory.CreateRectangleWithRoundedCorners(width, height, nodeAttr.XRadius,
                                                                           nodeAttr.YRadius, center);
                    break;
                case Shape.Circle:
                    curve = CurveFactory.CreateCircle(width/2, center);
                    break;
                case Shape.Record:
                    return null;
                case Shape.Plaintext:
                    return null;
                case Shape.Point:
                    break;
                case Shape.Mdiamond:
                    break;
                case Shape.Msquare:
                    break;
                case Shape.Polygon:
                    break;
                case Shape.DoubleCircle:
                    curve = CurveFactory.CreateCircle(width/2, center);
                    break;
                case Shape.House:
                    curve = CurveFactory.CreateHouse(width, height, center);
                    break;
                case Shape.InvHouse:
                    curve = CurveFactory.CreateInvertedHouse(width, height, center);
                    break;
                case Shape.Parallelogram:
                    break;
                case Shape.Octagon:
                    curve = CurveFactory.CreateOctagon(width, height, center);
                    break;
                case Shape.TripleOctagon:
                    break;
                case Shape.Triangle:
                    break;
                case Shape.Trapezium:
                    break;
                case Shape.DrawFromGeometry:
                    break;
#if DEBUG
                case Shape.TestShape:
                    break;
#endif
                case Shape.Hexagon:
                    curve = CurveFactory.CreateHexagon(width, height, center);
                    break;

            }
            return curve ?? CurveFactory.CreateEllipse(width/2, height/2, center);
        }
 private void WriteNodeAttr(NodeAttr na) {
     WriteStartElement(Tokens.NodeAttribute);
     WriteBaseAttr(na);
     WriteColorElement(Tokens.Fillcolor, na.FillColor);
     WriteStringElement(Tokens.LabelMargin, na.LabelMargin);
     WriteStringElement(Tokens.Padding, na.Padding);
     WriteStringElement(Tokens.Shape, na.Shape);
     WriteStringElement(Tokens.XRad, na.XRadius);
     WriteStringElement(Tokens.YRad, na.YRadius);
     WriteEndElement();
 }
Example #29
0
 static Color FillColor(NodeAttr nodeAttr)
 {
     return MsaglColorToDrawingColor(nodeAttr.FillColor);
 }
        /// <summary>
        /// Creates a Node instance
        /// </summary>
        /// <param name="id">node name</param>
        public Node(string id) {            
            Label = new Label();
            Label.GeometryLabel = null;

            Label.Owner = this;
            Attr = new NodeAttr();
            attr.Id = id;
            Label.Text = id; //one can change the label later
        }
 void WritePolyline(Polyline poly, NodeAttr attr)
 {
     throw new NotImplementedException();
 }
        static void DrawEllipseOnPosition(DNode dNode, NodeAttr nodeAttr, Graphics g, float x, float y, float width,
                                          float height, Pen pen){
            if(NeedToFill(dNode.FillColor))
                g.FillEllipse(new SolidBrush(dNode.FillColor), x, y, width, height);
            if(nodeAttr.Shape == Shape.Point)
                g.FillEllipse(new SolidBrush(pen.Color), x, y, width, height);

            g.DrawEllipse(pen, x, y, width, height);
        }