Exemplo n.º 1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare variables
            string F = null;
            bool   S = false;

            CompileSVG X = new CompileSVG();

            // Access the input parameters
            if (!DA.GetData(0, ref X))
            {
                return;
            }
            if (!DA.GetData(1, ref F))
            {
                return;
            }
            if (!DA.GetData(2, ref S))
            {
                return;
            }


            string FilePath = "C:\\Users\\Public\\Documents\\untitled.svg";

            if (F == null)
            {
                if (this.OnPingDocument().FilePath != null)
                {
                    FilePath = Path.GetDirectoryName(this.OnPingDocument().FilePath) + "\\" + Path.GetFileNameWithoutExtension(this.OnPingDocument().FilePath) + ".svg";
                }
            }
            else
            {
                FilePath = F;
            }

            if (S)
            {
                X.Save(FilePath);
            }

            DA.SetData(0, FilePath);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Set Unique Control Properties

            List <IGH_Goo> Shps = new List <IGH_Goo>();
            Rectangle3d    B    = new Rectangle3d(Plane.WorldXY, 0, 0);
            Interval       Fx   = new Interval(600, 600);
            bool           D    = true;

            if (!DA.GetDataList(0, Shps))
            {
                return;
            }
            if (!DA.GetData(1, ref B))
            {
                return;
            }
            if (!DA.GetData(2, ref Fx))
            {
                return;
            }
            if (!DA.GetData(3, ref D))
            {
                return;
            }

            List <wShapeCollection> Shapes = new List <wShapeCollection>();

            Rectangle3d F = new Rectangle3d(Plane.WorldXY, Fx.T0, Fx.T1);

            wObject          Wx = new wObject();
            wShapeCollection Sx = new wShapeCollection();

            Shps[0].CastTo(out Wx);
            Sx = (wShapeCollection)Wx.Element;

            BoundingBox bBox = new BoundingBox();

            if (D)
            {
                SavedBox = new BoundingBox();
            }
            else
            {
                bBox = SavedBox;
            }
            bBox.Union(new BoundingBox(Sx.Boundary.CornerPoints[0].X, Sx.Boundary.CornerPoints[0].Y, 0, Sx.Boundary.CornerPoints[2].X, Sx.Boundary.CornerPoints[2].Y, 0));

            SavedBox = bBox;

            foreach (IGH_Goo Obj in Shps)
            {
                wObject          W = new wObject();
                wShapeCollection S = new wShapeCollection();

                Obj.CastTo(out W);
                S = (wShapeCollection)W.Element;
                Shapes.Add(S);

                wPoint PtA = S.Boundary.CornerPoints[0];
                wPoint PtB = S.Boundary.CornerPoints[2];

                bBox.Union(new Point3d(PtA.X, PtA.Y, PtA.Z));
                bBox.Union(new Point3d(PtB.X, PtB.Y, PtB.Z));
            }

            if ((B.Width == 0.0) & (B.Height == 0.0))
            {
                Plane pln = Plane.WorldXY;
                pln.Origin = bBox.Center;
                B          = new Rectangle3d(pln,
                                             new Interval(-bBox.Diagonal.X / 2.0, bBox.Diagonal.X / 2.0),
                                             new Interval(-bBox.Diagonal.Y / 2.0, bBox.Diagonal.Y / 2.0));
            }

            wPlane PlnB = new wPlane(
                new wPoint(B.Center.X, B.Center.Y, B.Center.Z),
                new wVector(B.Plane.XAxis.X, B.Plane.XAxis.Y, B.Plane.XAxis.Z),
                new wVector(B.Plane.YAxis.X, B.Plane.YAxis.Y, B.Plane.YAxis.Z));
            wPlane PlnF = new wPlane(
                new wPoint(F.Center.X, F.Center.Y, F.Center.Z),
                new wVector(F.Plane.XAxis.X, F.Plane.XAxis.Y, F.Plane.XAxis.Z),
                new wVector(F.Plane.YAxis.X, F.Plane.YAxis.Y, F.Plane.YAxis.Z));

            CompileSVG SVGobject = new CompileSVG();

            double X = F.Width / B.Width;
            double Y = F.Height / B.Height;
            double Z = 1.0;

            if (X < Y)
            {
                Z = X;
            }
            else
            {
                Z = Y;
            }


            SVGobject.SetSize((int)F.Width, (int)F.Height, new wRectangle(PlnB, B.Width, B.Height), Z);
            SVGobject.SetQuality(QualityType);

            if (D)
            {
                SavedPathSets.Clear();
            }
            else
            {
                SVGobject.LoadPaths(SavedPathSets);
            }

            int i = 0;

            foreach (wShapeCollection S in Shapes)
            {
                SVGobject.SetShapeType(S, i);
                i += 1;
            }

            SavedPathSets = SVGobject.PathSet;

            if (SVGobject.FrameCount > 0)
            {
                SVGobject.SetFrames();
            }
            else
            {
                SVGobject.SetGroups();
            }


            SVGobject.Build();

            DA.SetData(0, SVGobject);
        }