Exemplo n.º 1
0
        public static Dictionary <string, object> FromOrigin(
            DSGeom.Point origin,
            List <DSGeom.Point> points,
            List <DSGeom.Polygon> boundary,
            [DefaultArgument("[]")] List <DSGeom.Polygon> obstacles)
        {
            DSGeom.Polygon isovist = IsovistPolygon(boundary, obstacles, origin);
            GTGeom.Polygon gPol    = GTGeom.Polygon.ByVertices(isovist.Points.Select(p => GTGeom.Vertex.ByCoordinates(p.X, p.Y, p.Z)).ToList());

            List <DSGeom.Point> visPoints = new List <DSGeom.Point>();
            double totalPoints            = points.Count;
            double visibilityAmount       = 0;

            foreach (DSGeom.Point point in points)
            {
                GTGeom.Vertex vertex = GTGeom.Vertex.ByCoordinates(point.X, point.Y, point.Z);

                if (gPol.ContainsVertex(vertex))
                {
                    ++visibilityAmount;
                    visPoints.Add(point);
                }
            }
            isovist.Dispose();

            return(new Dictionary <string, object>()
            {
                { scoreOutputPort, (1 / totalPoints) * visibilityAmount },
                { geometryOutputPort, visPoints }
            });
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create Advance Steel Variable Grating by Dynamo Polygon
 /// </summary>
 /// <param name="gratingClass"> Input Grating Class</param>
 /// <param name="gratingName"> Input Grating Size</param>
 /// <param name="poly"> Input dynamo Polygon</param>
 /// <param name="additionalGratingParameters"> Optional Input Grating Build Properties </param>
 /// <returns name="variableGrating"> grating</returns>
 public static VariableGrating ByPolygon(Autodesk.DesignScript.Geometry.Polygon poly,
                                         string gratingClass,
                                         string gratingName,
                                         [DefaultArgument("null")] List <Property> additionalGratingParameters)
 {
     additionalGratingParameters = PreSetDefaults(additionalGratingParameters, gratingClass, gratingName);
     return(new VariableGrating(poly, Utils.ToAstVector3d(poly.Normal, true), additionalGratingParameters));
 }
Exemplo n.º 3
0
        /// <summary>
        /// DS Polygon to closed SpecklePolyline
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public Polyline PolylineToSpeckle(DS.Polygon polygon)
        {
            var poly = new Polyline(PointListToFlatArray(polygon.Points), ModelUnits)
            {
                closed = true,
            };

            CopyProperties(poly, polygon);

            return(poly);
        }
        /// <summary>
        /// DS Polygon to closed SpecklePolyline
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public Polyline PolylineToSpeckle(DS.Polygon polygon, string units = null)
        {
            var u    = units ?? ModelUnits;
            var poly = new Polyline(PointListToFlatArray(polygon.Points), u)
            {
                closed = true,
            };

            CopyProperties(poly, polygon);
            poly.length = polygon.Length;
            poly.bbox   = BoxToSpeckle(polygon.BoundingBox.ToCuboid(), u);
            return(poly);
        }
        public static PdfAnnotation ToPDFPolygon(this Autodesk.DesignScript.Geometry.Polygon polygon, string content, PdfWriter writer)
        {
            List <float> points = new List <float>();

            foreach (var pt in polygon.Points)
            {
                PDFCoords coords = pt.ToPDFCoords();
                points.Add(coords.X);
                points.Add(coords.Y);
            }

            iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(0, 0);

            var app  = new PdfContentByte(writer);
            var anno = PdfAnnotation.CreatePolygonPolyline(writer, rect, content, true, new PdfArray(points.ToArray()));

            return(anno);
        }
Exemplo n.º 6
0
        internal VariableGrating(Autodesk.DesignScript.Geometry.Polygon poly,
                                 Vector3d vNormal,
                                 List <Property> additionalGratingParameters)
        {
            lock (access_obj)
            {
                using (var ctx = new SteelServices.DocContext())
                {
                    List <Property> defaultData     = additionalGratingParameters.Where(x => x.Level == ".").ToList <Property>();
                    List <Property> postWriteDBData = additionalGratingParameters.Where(x => x.Level == "Z_PostWriteDB").ToList <Property>();

                    string strClass = (string)defaultData.FirstOrDefault <Property>(x => x.Name == "GratingClass").InternalValue;
                    string strName  = (string)defaultData.FirstOrDefault <Property>(x => x.Name == "GratingSize").InternalValue;

                    Autodesk.AdvanceSteel.Geometry.Plane    plane    = new Plane(Utils.ToAstPoint(poly.Center(), true), vNormal);
                    Autodesk.AdvanceSteel.Modelling.Grating gratings = null;
                    string    handle    = SteelServices.ElementBinder.GetHandleFromTrace();
                    Point3d[] astPoints = Utils.ToAstPoints(poly.Points, true);

                    if (string.IsNullOrEmpty(handle) || Utils.GetObject(handle) == null)
                    {
                        gratings = new Autodesk.AdvanceSteel.Modelling.Grating(strClass, strName, plane, astPoints);

                        if (defaultData != null)
                        {
                            Utils.SetParameters(gratings, defaultData);
                        }

                        gratings.WriteToDb();

                        if (postWriteDBData != null)
                        {
                            Utils.SetParameters(gratings, postWriteDBData);
                        }
                    }
                    else
                    {
                        gratings = Utils.GetObject(handle) as Autodesk.AdvanceSteel.Modelling.Grating;
                        if (gratings != null && gratings.IsKindOf(FilerObject.eObjectType.kGrating))
                        {
                            gratings.GratingClass    = strClass;
                            gratings.GratingSize     = strName;
                            gratings.DefinitionPlane = plane;
                            gratings.SetPolygonContour(astPoints);

                            if (defaultData != null)
                            {
                                Utils.SetParameters(gratings, defaultData);
                            }

                            if (postWriteDBData != null)
                            {
                                Utils.SetParameters(gratings, postWriteDBData);
                            }
                        }
                        else
                        {
                            throw new System.Exception("Not a Variable Grating pattern");
                        }
                    }

                    Handle = gratings.Handle;
                    SteelServices.ElementBinder.CleanupAndSetElementForTrace(gratings);
                }
            }
        }
Exemplo n.º 7
0
        public void ToPDF(iTextSharp.text.pdf.PdfWriter w)
        {
            PdfContentByte cb = w.DirectContent;

            cb.SetLineWidth((float)Settings.Thickness);
            if (Settings.Fill != null)
            {
                cb.SetColorFill(Settings.Fill.ToPDFColor());
            }

            if (Settings.Stroke != null)
            {
                cb.SetColorStroke(Settings.Stroke.ToPDFColor());
            }

            if (Geometry.GetType() == typeof(Dyn.Arc))
            {
                Dyn.Arc arc = Geometry as Dyn.Arc;
                cb.MoveTo(arc.StartPoint.X, arc.EndPoint.Y);
                cb.CurveTo(arc.PointAtParameter(0.5).X, arc.PointAtParameter(0.5).Y, arc.EndPoint.X, arc.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Line))
            {
                Dyn.Line line = Geometry as Dyn.Line;
                cb.MoveTo(line.StartPoint.X, line.StartPoint.Y);
                cb.LineTo(line.EndPoint.X, line.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Circle))
            {
                Dyn.Circle circle = Geometry as Dyn.Circle;
                cb.Circle(circle.CenterPoint.X, circle.CenterPoint.Y, circle.Radius);
            }
            else if (Geometry.GetType() == typeof(Dyn.Ellipse))
            {
                Dyn.Ellipse ellipse = Geometry as Dyn.Ellipse;
                cb.Ellipse(ellipse.StartPoint.X, ellipse.StartPoint.Y, ellipse.EndPoint.X, ellipse.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Rectangle))
            {
                Dyn.Rectangle rect = Geometry as Dyn.Rectangle;
                cb.Rectangle(rect.Center().X, rect.Center().Y, rect.Width, rect.Height);
            }
            else if (Geometry.GetType() == typeof(Dyn.Polygon))
            {
                Dyn.Polygon p = Geometry as Dyn.Polygon;
                foreach (var curve in p.Curves())
                {
                    CurveToPDF(curve, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.PolyCurve))
            {
                Dyn.PolyCurve pc = Geometry as Dyn.PolyCurve;
                foreach (var curve in pc.Curves())
                {
                    CurveToPDF(curve, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.NurbsCurve))
            {
                Dyn.NurbsCurve nc = Geometry as Dyn.NurbsCurve;

                foreach (var linearc in nc.ApproximateWithArcAndLineSegments())
                {
                    CurveToPDF(linearc, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.Curve))
            {
                Dyn.Curve curve = Geometry as Dyn.Curve;
                CurveToPDF(curve, cb);
            }
            else
            {
                throw new Exception(Properties.Resources.NotSupported);
            }

            if (Settings.Fill != null && Settings.Stroke != null)
            {
                cb.FillStroke();
            }
            else
            {
                if (Settings.Stroke != null)
                {
                    cb.Stroke();
                }
                if (Settings.Fill != null)
                {
                    cb.Fill();
                }
            }
        }