コード例 #1
0
ファイル: Block.cs プロジェクト: radumg/DesignScriptStudio
        /// <summary>
        /// Imports all blocks in the outside file to the current drawing
        /// </summary>
        /// <param name="filePath">the file path for the outside file</param>
        /// <returns></returns>
        public static Block[] ImportAll(string filePath)
        {
            string kMethodName = "Block.ImportAll";

            filePath = GeometryExtension.LocateFile(filePath);
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            string[]     blockNames = helper.ImportAllBlocksFromFile(filePath);
            List <Block> blocks     = new List <Block>();

            foreach (var name in blockNames)
            {
                Block block = new Block(name, filePath);
                blocks.Add(block);
            }
            return(blocks.ToArray());
        }
コード例 #2
0
ファイル: Solid.cs プロジェクト: seasailor/designscript
        private static ISolidEntity RevolveCore(Curve profile, Point axisOrigin, Vector axisDirection, double startAngle, double sweepAngle)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }
            if (axisOrigin == null)
            {
                throw new ArgumentNullException("axisOrigin");
            }
            if (axisDirection == null)
            {
                throw new ArgumentNullException("axisDirection");
            }
            if (!profile.IsPlanar)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "profile"), "profile");
            }
            if (GeometryExtension.Equals(axisDirection.Length, 0.0))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "axisDirection"), "axisDirection");
            }
            if (GeometryExtension.Equals(sweepAngle, 0.0))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "sweepAngle"), "sweepAngle");
            }

            ISolidEntity entity = HostFactory.Factory.SolidByRevolve(profile.CurveEntity, axisOrigin.PointEntity, axisDirection.IVector, startAngle, sweepAngle);

            if (entity == null)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "Solid.Revolve"));
            }
            return(entity);
        }
コード例 #3
0
        private static ISurfaceEntity FromCrossSectionsGuidesCore(Curve[] crossSections, Curve[] guides)
        {
            bool isClosed = crossSections[0].IsClosed;

            //Validation
            ICurveEntity[] hostXCurves = crossSections.ConvertAll((Curve c) => GeometryExtension.GetCurveEntity(c, isClosed));
            if (hostXCurves == null || hostXCurves.Length < 2)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "cross sections"), "crossSections");
            }

            ICurveEntity[] hostGuides = guides.ConvertAll(GeometryExtension.ToEntity <Curve, ICurveEntity>);
            if (hostGuides == null || hostGuides.Length < 1)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "guides"), "guides");
            }

            ISurfaceEntity entity = HostFactory.Factory.SurfaceByLoftCrossSectionsGuides(hostXCurves, hostGuides);

            if (entity == null)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Surface.LoftFromCrossSectionsGuides"));
            }
            return(entity);
        }
コード例 #4
0
ファイル: Point.cs プロジェクト: seasailor/designscript
        /// <summary>
        ///
        /// </summary>
        /// <param name="contextGeometries"></param>
        /// <param name="distanceCriteria"></param>
        /// <returns></returns>
        public Autodesk.DesignScript.Geometry.Geometry[] SelectWithinDistance(Geometry[] 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 <Geometry> selectedGeoms = new List <Geometry>();

            foreach (var geom in contextGeometries)
            {
                double distance = geom.GeomEntity.DistanceTo(PointEntity);
                if (GeometryExtension.LessThanOrEquals(distance, absDist))
                {
                    selectedGeoms.Add(geom);
                }
            }

            return(selectedGeoms.ToArray());
        }
コード例 #5
0
ファイル: Arc.cs プロジェクト: radumg/DesignScriptStudio
 private void InitializeGuaranteedProperties()
 {
     Radius     = ArcEntity.Radius;
     StartAngle = GeometryExtension.RadiansToDegrees(ArcEntity.StartAngle);
     SweepAngle = GeometryExtension.RadiansToDegrees(ArcEntity.SweepAngle);
     Normal     = new Vector(ArcEntity.Normal);
 }
コード例 #6
0
ファイル: Block.cs プロジェクト: radumg/DesignScriptStudio
        /// <summary>
        /// Imports a block with the given name from the outside file to the
        /// current drawing
        /// </summary>
        /// <param name="blockName">the given block name</param>
        /// <param name="filePath">the file path for the outside file</param>
        /// <returns></returns>
        public static Block Import(string blockName, string filePath)
        {
            string kMethodName = "Block.Import";

            filePath = GeometryExtension.LocateFile(filePath);
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath");
            }

            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            helper.ImportBlockFromFile(filePath, blockName);
            return(new Block(blockName, filePath));
        }
コード例 #7
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mProfile);
     }
     base.Dispose(disposing);
 }
コード例 #8
0
ファイル: Point.cs プロジェクト: seasailor/designscript
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mReferencePoint);
     }
     base.Dispose(disposing);
 }
コード例 #9
0
 internal static void DisposeObject <T>(ref T[][] obj) where T : DesignScriptEntity
 {
     obj.ForEach((T[] item) => GeometryExtension.DisposeObject(ref item));
     if (obj.IsDisposed())
     {
         obj = null;
     }
 }
コード例 #10
0
ファイル: Vertex.cs プロジェクト: radumg/DesignScriptStudio
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mAdjacentEdges);
         GeometryExtension.DisposeObject(ref mAdjacentFaces);
     }
     base.Dispose(disposing);
 }
コード例 #11
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mCoordinateSystem);
         GeometryExtension.DisposeObject(ref mPointOnSurface);
         GeometryExtension.DisposeObject(ref mContextSurface);
     }
 }
コード例 #12
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mContainingCell);
         GeometryExtension.DisposeObject(ref mContainingFace);
     }
     base.Dispose(disposing);
 }
コード例 #13
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mCrossSections);
         GeometryExtension.DisposeObject(ref mGuides);
         GeometryExtension.DisposeObject(ref mPath);
     }
     base.Dispose(disposing);
 }
コード例 #14
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mVertices);
         GeometryExtension.DisposeObject(ref mEdges);
         mSurfaceEntity.DisposeObject(); mSurfaceEntity = null;
     }
     base.Dispose(disposing);
 }
コード例 #15
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                GeometryExtension.DisposeObject(ref mControlVertices);
                GeometryExtension.DisposeObject(ref mPoints);
            }

            base.Dispose(disposing);
        }
コード例 #16
0
ファイル: Polygon.cs プロジェクト: seasailor/designscript
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mEdges);
         GeometryExtension.DisposeObject(ref mVertices);
         GeometryExtension.DisposeObject(ref mPlane);
     }
     base.Dispose(disposing);
 }
コード例 #17
0
ファイル: Circle.cs プロジェクト: radumg/DesignScriptStudio
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mFirstPoint);
         GeometryExtension.DisposeObject(ref mSecondPoint);
         GeometryExtension.DisposeObject(ref mThirdPoint);
         GeometryExtension.DisposeObject(ref mCenterPoint);
     }
     base.Dispose(disposing);
 }
コード例 #18
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                GeometryExtension.DisposeObject(ref mStartPoint);
                GeometryExtension.DisposeObject(ref mEndPoint);
                GeometryExtension.DisposeObject(ref mCenterLine);
            }

            base.Dispose(disposing);
        }
コード例 #19
0
ファイル: Circle.cs プロジェクト: radumg/DesignScriptStudio
        private static ICircleEntity ByPointsOnCurveCore(Point firstPoint, Point secondPoint, Point thirdPoint)
        {
            if (firstPoint == null)
            {
                throw new ArgumentNullException("firstPoint");
            }
            else if (secondPoint == null)
            {
                throw new ArgumentNullException("secondPoint");
            }
            else if (thirdPoint == null)
            {
                throw new ArgumentNullException("thirdPoint");
            }
            else if (firstPoint.Equals(secondPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "first point", "second point"), "firstPoint, secondPoint");
            }
            else if (secondPoint.Equals(thirdPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "second point", "thrid point"), "secondPoint, thirdPoint");
            }
            else if (thirdPoint.Equals(firstPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "third point", "first point"), "thirdPoint, firstPoint");
            }
            else if (GeometryExtension.ArePointsColinear(firstPoint, secondPoint, thirdPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.PointsColinear, "first, second and thrid points"), "firstPoint, secondPoint, thirdPoint");
            }

            /*
             * Vector normal = null;
             * var centerPt = Utils.GetCircumCenter(firstPoint, secondPoint, thirdPoint, out normal);
             * if (centerPt == null || normal == null)
             * {
             *  return null;
             * }
             * double rad = firstPoint.PointEntity.DistanceTo(centerPt.PointEntity);
             * if( rad <= 0.0)
             * {
             *  return null;
             * }
             */
            var entity = HostFactory.Factory.CircleByPointsOnCurve(firstPoint.PointEntity,
                                                                   secondPoint.PointEntity, thirdPoint.PointEntity);

            if (null == entity)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "Circle.ByPointsOnCurve"));
            }
            return(entity);
        }
コード例 #20
0
ファイル: Vector.cs プロジェクト: radumg/DesignScriptStudio
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool IsPerpendicular(Vector other)
        {
            if (other == null)
            {
                throw new System.ArgumentNullException("other");
            }
            var normalizedThis  = Normalize();
            var normalizedOther = other.Normalize();

            var dotProd = normalizedThis.Dot(normalizedOther);

            return(GeometryExtension.Equals(Math.Abs(dotProd), 0.0));
        }
コード例 #21
0
 internal static IGeometryEntity[] ImportFromSAT(ref string fileName)
 {
     if (string.IsNullOrWhiteSpace(fileName))
     {
         throw new System.ArgumentNullException("fileName");
     }
     fileName = GeometryExtension.LocateFile(fileName);
     if (!File.Exists(fileName))
     {
         throw new System.ArgumentException(string.Format(Properties.Resources.FileNotFound, fileName), "fileName");
     }
     IGeometryEntity[] objects = HostFactory.Factory.LoadSat(fileName);
     return(objects);
 }
コード例 #22
0
        internal static bool EqualsTo(this IPointEntity thisValue, IPointEntity value)
        {
            if (Object.ReferenceEquals(thisValue, value))
            {
                return(true);
            }
            if (null == thisValue || null == value)
            {
                return(false);
            }

            return(GeometryExtension.Equals(thisValue.X, value.X) && GeometryExtension.Equals(thisValue.Y, value.Y) &&
                   GeometryExtension.Equals(thisValue.Z, value.Z));
        }
コード例 #23
0
ファイル: Face.cs プロジェクト: radumg/DesignScriptStudio
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                GeometryExtension.DisposeObject(ref mCellFaces);
                GeometryExtension.DisposeObject(ref mAdjacentCells);
                GeometryExtension.DisposeObject(ref mEdges);
                GeometryExtension.DisposeObject(ref mVertices);

                GeometryExtension.DisposeObject(ref mShell);
                GeometryExtension.DisposeObject(ref mCentroid);
            }
            base.Dispose(disposing);
        }
コード例 #24
0
        internal CoordinateSystem GetCSAtParameters(double u, double v)
        {
            bool uchange = GeometryExtension.ClipParamRange(ref u);
            bool vchange = GeometryExtension.ClipParamRange(ref v);
            // TO DO - throw a warning each time a condition above is satisfied.
            //throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "u or v parameter", "Surface.PointAtUVParameters"));

            IPointEntity pos    = SurfaceEntity.PointAtParameter(u, v);
            Point        origin = pos.ToPoint(false, null);
            Vector       xAxis  = new Vector(SurfaceEntity.TangentAtUParameter(u, v));
            Vector       yAxis  = new Vector(SurfaceEntity.TangentAtVParameter(u, v));
            Vector       zAxis  = xAxis.Cross(yAxis);

            return(CoordinateSystem.ByOriginVectors(origin, xAxis, yAxis, zAxis, false, true, false));
        }
コード例 #25
0
        /// <summary>
        /// Creates an array of Sub Division Mesh from the .Obj file given by the user.
        /// Each Group within the .Obj file is represented by one SubDivsion Mesh.
        /// </summary>
        /// <param name="filePath">The file to be imported</param>
        /// <returns></returns>
        public static SubDivisionMesh[] ImportFromOBJ(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new System.ArgumentNullException("filePath");
            }
            filePath = GeometryExtension.LocateFile(filePath);
            if (!File.Exists(filePath))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath");
            }
            MeshData result = ObjHandler.Import(filePath);

            return(result.ConvertToSubDivisionMesh());
        }
コード例 #26
0
        public string WriteEntity(IArcEntity arc, string paramName = null)
        {
            if (string.IsNullOrEmpty(paramName))
            {
                paramName = string.Format("__arc_{0}", ++id);
            }

            string center = WriteEntity(arc.CenterPoint);
            string normal = WriteEntity(arc.Normal);

            mExpression.AppendFormat("{0} = Arc.ByCenterPointRadiusAngle({1}, {2}, {3}, {4}, {5});", paramName, center,
                                     arc.Radius, GeometryExtension.RadiansToDegrees(arc.StartAngle), GeometryExtension.RadiansToDegrees(arc.SweepAngle), normal);
            mExpression.AppendLine();
            return(paramName);
        }
コード例 #27
0
ファイル: Vector.cs プロジェクト: radumg/DesignScriptStudio
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (Object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            Vector vec = obj as Vector;

            if (null == vec)
            {
                return(false);
            }

            return(GeometryExtension.Equals(vec.X, X) && GeometryExtension.Equals(vec.Y, Y) && GeometryExtension.Equals(vec.Z, Z));
        }
コード例 #28
0
ファイル: Arc.cs プロジェクト: radumg/DesignScriptStudio
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected override bool Equals(DesignScriptEntity obj)
        {
            if (base.Equals(obj))
            {
                return(true);
            }

            var arc = obj as Arc;

            if (arc == null)
            {
                return(false);
            }

            return(CenterPoint.Equals(arc.CenterPoint) && Normal.Equals(arc.Normal) &&
                   GeometryExtension.Equals(Radius, arc.Radius));
        }
コード例 #29
0
ファイル: Solid.cs プロジェクト: seasailor/designscript
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         GeometryExtension.DisposeObject(ref mVertices);
         GeometryExtension.DisposeObject(ref mEdges);
         GeometryExtension.DisposeObject(ref mFaces);
         GeometryExtension.DisposeObject(ref mShells);
         GeometryExtension.DisposeObject(ref mCrossSections);
         GeometryExtension.DisposeObject(ref mPath);
         GeometryExtension.DisposeObject(ref mGuides);
         GeometryExtension.DisposeObject(ref mProfile);
         GeometryExtension.DisposeObject(ref mAxisOrigin);
         GeometryExtension.DisposeObject(ref mAxis);
     }
     base.Dispose(disposing);
 }
コード例 #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (null != mPersistent && !Object.ReferenceEquals(mPersistent, base.HostImpl))
                {
                    mPersistent.Dispose();
                }

                GeometryExtension.DisposeObject(ref mContext);
                GeometryExtension.DisposeObject(ref mContextCS);
            }

            mPersistent        = null;
            mDisplayAttributes = null;
            base.Dispose(disposing); //allow base class to release it's resources
        }