Ejemplo n.º 1
0
 protected internal DSPlane(DSPoint origin, DSVector normal, double size, bool display = false, DSGeometry context = null)
     : base(ByOriginNormalCore(origin, ref normal, size), false)
 {
     InitializeGuaranteedProperties();
     Size = size;
     Context = context;
     if (display)
         mDisplayPolygon = CreatePlaneVisuals(size,true);
 }
Ejemplo n.º 2
0
        internal override IGeometryEntity[] ProjectOn(DSGeometry other, DSVector direction)
        {
            //Solid solid = other as Solid;
            //if (null != solid)
            //    return solid.SolidEntity.Project(SurfaceEntity, direction);

            return base.ProjectOn(other, direction);
        }
Ejemplo n.º 3
0
        internal override IGeometryEntity[] ProjectOn(DSGeometry other, DSVector direction)
        {
            IVector dir = direction.IVector;
            //Only point can be projected on curve.
            DSSurface surf = other as DSSurface;
            if (null != surf)
                return CurveEntity.ProjectOn(surf.SurfaceEntity, dir);

            DSPlane plane = other as DSPlane;
            if (null != plane)
            {
                ICurveEntity curve = CurveEntity.ProjectOn(plane.PlaneEntity, dir);
                return new IGeometryEntity[] { curve };
            }

            DSSolid solid = other as DSSolid;
            if (null != solid)
                return solid.SolidEntity.Project(CurveEntity, dir);

            return base.ProjectOn(other, direction);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a SubDivisionMesh from Solid or Surface geometry by faceting 
        /// the faces of Solid or Surface.
        /// </summary>
        /// <param name="context">Input geometry, Solid or Surface.</param>
        /// <param name="maxEdgeLength">Maximum allowed edge length 
        /// to define coarseness of the mesh.</param>
        /// <returns>SubDivisionMesh</returns>
        public static DSSubDivisionMesh FromGeometry(DSGeometry context, double maxEdgeLength)
        {
            string kMethodName = "DSSubDivisionMesh.FromGeometry";
            if (null == context)
                throw new System.ArgumentNullException("context");

            ISubDMeshEntity entity = HostFactory.Factory.SubDMeshFromGeometry(context.GeomEntity, maxEdgeLength);
            if(null == entity)
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));

            DSSubDivisionMesh mesh = new DSSubDivisionMesh(entity, true);
            mesh.Context = context;
            mesh.SubDivisionLevel = 0;
            return mesh;
        }
Ejemplo n.º 5
0
        private DSPoint ProjectOnGeometry(DSGeometry contextGeometry, DSVector direction)
        {
            IPointEntity closestPoint = null;
            if (null == direction)
                return contextGeometry.ClosestPointTo(this);
            else
            {
                IGeometryEntity[] entities = ProjectOn(contextGeometry, direction);
                if (null == entities || entities.Length == 0)
                    throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "Project along direction"));

                int nearestIndex = GetIndexOfNearestGeometry(entities, PointEntity);
                IGeometryEntity closestGeometry = entities[nearestIndex];
                //Clone the closest geometry
                closestPoint = closestGeometry.Clone() as IPointEntity;

                //Done with projected entities, dispose them.
                entities.DisposeObject();
            }

            return new DSPoint(closestPoint, true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contextGeometries"></param>
        /// <param name="sortAscending"></param>
        /// <returns></returns>
        public Autodesk.DesignScript.Geometry.DSGeometry[] SortByDistance(DSGeometry[] contextGeometries, bool sortAscending)
        {
            if (contextGeometries == null)
                throw new System.ArgumentNullException("contextGeometries");
            else if (contextGeometries.Length == 0)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "number of context geometries"), "contextGeometries");
            }

            //  insert all the geometries with their distance from this point in this sorted dictionary
            //
            //SortedDictionary<double, Geometry> geomsWithDistance = new SortedDictionary<double, Geometry>();
            List<KeyValuePair<double, DSGeometry>> geomsWithDistance = new List<KeyValuePair<double, DSGeometry>>();
            foreach (var geom in contextGeometries)
            {
                geomsWithDistance.Add(new KeyValuePair<double, DSGeometry>(geom.GeomEntity.DistanceTo(PointEntity), geom));
            }
            DoubleComparer comparer = new DoubleComparer(sortAscending);
            geomsWithDistance.Sort((KeyValuePair<double, DSGeometry> x, KeyValuePair<double, DSGeometry> y) => comparer.Compare(x.Key, y.Key));
            DSGeometry[] sortedList = new DSGeometry[geomsWithDistance.Count];
            int i = 0;
            foreach (var item in geomsWithDistance)
            {
                sortedList[i++] = item.Value;
            }

            return sortedList;
        }
Ejemplo n.º 7
0
        internal override IGeometryEntity[] ProjectOn(DSGeometry other, DSVector direction)
        {
            IVector dir = direction.IVector;
            DSSurface surf = other as DSSurface;
            if (null != surf)
                return surf.SurfaceEntity.Project(PointEntity, dir);

            DSCurve curve = other as DSCurve;
            if (null != curve)
            {
                IPointEntity pt = curve.CurveEntity.Project(PointEntity, dir);
                return new IGeometryEntity[] { pt };
            }

            DSPlane plane = other as DSPlane;
            if (null != plane)
            {
                IPointEntity pt = plane.PlaneEntity.Project(PointEntity, dir);
                return new IGeometryEntity[] { pt };
            }

            DSSolid solid = other as DSSolid;
            if (null != solid)
                return solid.SolidEntity.Project(PointEntity, dir);

            return base.ProjectOn(other, direction);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contextGeometries"></param>
        /// <param name="distanceCriteria"></param>
        /// <returns></returns>
        public Autodesk.DesignScript.Geometry.DSGeometry[] SelectWithinDistance(DSGeometry[] contextGeometries, double distanceCriteria)
        {
            if (contextGeometries == null)
                throw new System.ArgumentNullException("contextGeometries");
            else if (contextGeometries.Length == 0)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "number of context geometries"), "contextGeometries");
            }

            var absDist = Math.Abs(distanceCriteria);

            List<DSGeometry> selectedGeoms = new List<DSGeometry>();
            foreach (var geom in contextGeometries)
            {
                double distance = geom.GeomEntity.DistanceTo(PointEntity);
                if (DSGeometryExtension.LessThanOrEquals(distance, absDist))
                {
                    selectedGeoms.Add(geom);
                }
            }

            return selectedGeoms.ToArray();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contextGeometries"></param>
        /// <returns></returns>
        public Autodesk.DesignScript.Geometry.DSGeometry[] SortByDistance(DSGeometry[] contextGeometries)
        {
            if (contextGeometries == null)
                throw new System.ArgumentNullException("contextGeometries");
            else if (contextGeometries.Length == 0)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "number of context geometries"), "contextGeometries");
            }

            return SortByDistance(contextGeometries, true);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public DSGeometry SelectNearest(DSGeometry[] contextGeometries)
 {
     if (contextGeometries == null)
         throw new System.ArgumentNullException("contextGeometries");
     IGeometryEntity[] hostentities = contextGeometries.ConvertAll(DSGeometryExtension.ToEntity<DSGeometry, IGeometryEntity>);
     if(hostentities == null)
         throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "contextGeometries", "SelectNearest"), "contextGeometries");
     int nearestIndex = GetIndexOfNearestGeometry(hostentities, PointEntity);
     IGeometryEntity nearestGeom = hostentities[nearestIndex];
     return DSGeometry.ToGeometry(nearestGeom, false); //returning one of the existing geometry, so persist is no-op.
 }
Ejemplo n.º 11
0
 public int IndexOfNearest(DSGeometry[] contextGeometries)
 {
     if (contextGeometries == null)
         throw new System.ArgumentNullException("contextGeometries");
     IGeometryEntity[] hostentities = contextGeometries.ConvertAll(DSGeometryExtension.ToEntity<DSGeometry, IGeometryEntity>);
     if(hostentities == null)
         throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "contextGeometries", "IndexOfNearest"), "contextGeometries");
     return GetIndexOfNearestGeometry(hostentities, PointEntity);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a block with the given name, reference coordinate system and from the
        /// specified geometries
        /// </summary>
        /// <param name="blockName">the block name</param>
        /// <param name="referenceCoordinateSystem">the reference coordinate system</param>
        /// <param name="contents">the geometries contained in the block</param>
        /// <returns></returns>
        public static DSBlock FromGeometry(string blockName, DSCoordinateSystem referenceCoordinateSystem,
            DSGeometry[] contents)
        {
            string kMethodName = "DSBlock.FromGeometry";
            if (null == referenceCoordinateSystem)
                throw new ArgumentNullException("contextCoordinateSystem");
            if (string.IsNullOrEmpty(blockName))
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");

            IGeometryEntity[] hosts = contents.ConvertAll(DSGeometryExtension.ToEntity<DSGeometry, IGeometryEntity>);
            if (null == hosts || hosts.Length == 0)
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, "geometries", kMethodName), "geometries");

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();
            if (null == helper)
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));

            if (helper.DefineBlock(referenceCoordinateSystem.CSEntity, blockName, hosts))
            {
                return new DSBlock(blockName);
            }

            return null;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a block with the given name, reference point and from the
 /// specified geometries
 /// </summary>
 /// <param name="blockName">the block name</param>
 /// <param name="referencePoint">the reference point</param>
 /// <param name="contents">the geometries contained in the block</param>
 /// <returns></returns>
 public static DSBlock FromGeometry(string blockName, DSPoint referencePoint,
     DSGeometry[] contents)
 {
     DSCoordinateSystem referenceCoordinateSystem = DSCoordinateSystem.Identity();
     referenceCoordinateSystem.Translate(referencePoint.X, referencePoint.Y,
         referencePoint.Z);
     return FromGeometry(blockName, referenceCoordinateSystem, contents);
 }
Ejemplo n.º 14
0
 protected override void DisposeDisplayable()
 {
     if (null != mGeometry && mAutoDispose)
     {
         mGeometry.Dispose();
         mGeometry = null;
     }
 }