Ejemplo n.º 1
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.º 2
0
        /// <summary>
        /// Instantiates the specified block by name with the orientation
        /// specified by the coordinate system into the target file.
        /// If the block does not exist in the target file, the block will be exported to the
        /// target file first.
        /// If the block already exists in the target file, the old block will be replaced with
        /// the new one.
        /// </summary>
        /// <param name="contextCoordinateSystem">
        /// Specifies the orientation of the block. Origin is the placement point.
        /// This coordinate system must be orthogonal, can be non-uniformly scaled
        /// </param>
        /// <param name="targetFileName">the outside file name</param>
        /// <returns>If the insertion succeeds, returns true</returns>
        public bool ByCoordinateSystem(DSCoordinateSystem contextCoordinateSystem, string targetFileName)
        {
            string kMethodName = "DSBlock.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(targetFileName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, Name, kMethodName), "blockName");
            }

            targetFileName = DSGeometry.GetFullPath(targetFileName);

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

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

            return(helper.InsertBlockInTargetFile(contextCoordinateSystem.CSEntity, Name, targetFileName));
        }
Ejemplo n.º 3
0
 protected DSText(DSCoordinateSystem contextCoordinateSystem, Orientation orientation, string textString, double fontSize, bool persist)
     : base(ByCoordinateSystemCore(contextCoordinateSystem, orientation, textString, fontSize), persist)
 {
     InitializeGuaranteedProperties();
     ContextCoordinateSystem = contextCoordinateSystem;
     Orientation             = orientation;
 }
Ejemplo n.º 4
0
 protected DSPoint(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double height, bool persist, bool unused)
     : base(ByCylindricalCoordinatesCore(contextCoordinateSystem, radius, theta, height), true)
 {
     InitializeGuaranteedProperties();
     Radius = radius;
     Theta  = theta;
     Height = height;
 }
Ejemplo n.º 5
0
 protected DSPoint(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double phi, bool persist, int unused)
     : base(BySphericalCoordinatesCore(contextCoordinateSystem, radius, theta, phi), persist)
 {
     InitializeGuaranteedProperties();
     Radius = radius;
     Theta  = theta;
     Phi    = phi;
 }
Ejemplo n.º 6
0
 protected DSCylinder(DSCoordinateSystem contextCoordinateSystem, double radius, double height, bool persist)
     : base(CylinderByRadiusHeightCore(contextCoordinateSystem.CSEntity, radius, height), persist)
 {
     InitializeGuaranteedProperties();
     ContextCoordinateSystem = contextCoordinateSystem;
     Radius = radius;
     Height = height;
 }
Ejemplo n.º 7
0
 protected DSPoint(DSCoordinateSystem contextCoordinateSystem, double xTranslation, double yTranslation, double zTranslation, bool persist)
     : base(ByCartesianCoordinatesCore(contextCoordinateSystem, xTranslation, yTranslation, zTranslation), persist)
 {
     InitializeGuaranteedProperties();
     ContextCoordinateSystem = contextCoordinateSystem;
     XTranslation            = xTranslation;
     YTranslation            = yTranslation;
     ZTranslation            = zTranslation;
 }
Ejemplo n.º 8
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.º 9
0
        /// <summary>
        /// Constructors a plane on a surface by given parameter. 
        /// </summary>
        /// <param name="contextSurface"></param>
        /// <param name="u"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static DSPlane AtParameter(DSSurface contextSurface, double u, double v)
        {
            DSCoordinateSystem cs    = DSCoordinateSystem.AtParameterCore(contextSurface, u, v, false);
            DSPlane            plane = DSPlane.FromCoordinateSystem(cs);

            plane.Context = contextSurface;
            plane.U       = u;
            plane.V       = v;
            return(plane);
        }
Ejemplo n.º 10
0
 private DSSurfaceCurvature(DSSurface contextSurface, double u, double v, ICoordinateSystemEntity coordinateSystemEntity)
 {
     FirstPrincipleCurvature  = new DSVector(coordinateSystemEntity.XAxis);
     SecondPrincipleCurvature = new DSVector(coordinateSystemEntity.YAxis);
     GaussianCurvature        = FirstPrincipleCurvature.Length * SecondPrincipleCurvature.Length;
     mPointOnSurface          = DSPoint.ToGeometry(coordinateSystemEntity.Origin, false, contextSurface) as DSPoint;
     U = u;
     V = v;
     ContextSurface    = contextSurface;
     mCoordinateSystem = DSCoordinateSystem.ToCS(coordinateSystemEntity, false);
 }
Ejemplo n.º 11
0
 public static DSVector ByCoordinates(DSCoordinateSystem coordinateSystem, double x, double y, double z)
 {
     if (coordinateSystem == null)
     {
         throw new System.ArgumentNullException("coordinateSystem");
     }
     using (var p = DSPoint.ByCartesianCoordinates(coordinateSystem, x, y, z))
     {
         DSVector vec = coordinateSystem.Origin.DirectionTo(p);
         vec.ContextCoordinateSystem = coordinateSystem;
         return(vec);
     }
 }
Ejemplo n.º 12
0
        private static IPointEntity ByCartesianCoordinatesCore(DSCoordinateSystem contextCoordinateSystem, double xTranslation, double yTranslation, double zTranslation)
        {
            if (contextCoordinateSystem == null)
            {
                return(ByCoordinatesCore(xTranslation, yTranslation, zTranslation));
            }
            IPointEntity pos = HostFactory.Factory.PointByCartesianCoordinates(contextCoordinateSystem.CSEntity, xTranslation, yTranslation, zTranslation);

            if (pos == null)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSPoint.ByCartesianCoordinates"));
            }
            return(pos);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Transforms this geometry from source CoordinateSystem to a new
        /// context CoordinateSystem.
        /// </summary>
        /// <param name="fromCoordinateSystem"></param>
        /// <param name="contextCoordinateSystem"></param>
        /// <returns>Transformed Geometry.</returns>
        public DSGeometry Transform(DSCoordinateSystem fromCoordinateSystem, DSCoordinateSystem contextCoordinateSystem)
        {
            ICoordinateSystemEntity csEntity = contextCoordinateSystem.CSEntity.PostMultiplyBy(fromCoordinateSystem.CSEntity.Inverse());
            DSGeometry geom = TransformBy(csEntity);

            if (null == geom)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSGeometry.Transform"));
            }

            geom.ContextCoordinateSystem = contextCoordinateSystem;
            SetDisplayPropertiesTo(geom.Display);
            return(geom);
        }
Ejemplo n.º 14
0
        internal DSCoordinateSystem GetCSAtParameters(double u, double v)
        {
            bool uchange = DSGeometryExtension.ClipParamRange(ref u);
            bool vchange = DSGeometryExtension.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);
            DSPoint      origin = pos.ToPoint(false, null);
            DSVector     xAxis  = new DSVector(SurfaceEntity.TangentAtUParameter(u, v));
            DSVector     yAxis  = new DSVector(SurfaceEntity.TangentAtVParameter(u, v));
            DSVector     zAxis  = xAxis.Cross(yAxis);

            return(DSCoordinateSystem.ByOriginVectors(origin, xAxis, yAxis, zAxis, false, true, false));
        }
Ejemplo n.º 15
0
        private static DSPlane FromCoordinateSystem(DSCoordinateSystem cs)
        {
            if (null == cs)
            {
                return(null);
            }

            DSPlane plane = DSPlane.ByOriginNormal(cs.Origin, cs.ZAxis);

            if (null == plane)
            {
                return(null);
            }

            plane.ContextCoordinateSystem = cs;
            return(plane);
        }
Ejemplo n.º 16
0
 public DSVector Transform(DSCoordinateSystem fromCoordinateSystem, DSCoordinateSystem contextCoordinateSystem)
 {
     if (fromCoordinateSystem == null)
     {
         throw new ArgumentNullException("fromCoordinateSystem");
     }
     if (contextCoordinateSystem == null)
     {
         throw new ArgumentNullException("contextCoordinateSystem");
     }
     using (IPointEntity translatedPt = fromCoordinateSystem.Origin.PointEntity.CopyAndTranslate(vector) as IPointEntity)
     {
         using (IPointEntity transformedPt = translatedPt.CopyAndTransform(fromCoordinateSystem.CSEntity, contextCoordinateSystem.CSEntity) as IPointEntity)
         {
             return(contextCoordinateSystem.Origin.PointEntity.GetVectorTo(transformedPt));
         }
     }
 }
Ejemplo n.º 17
0
        private static ITextEntity ByCoordinateSystemCore(DSCoordinateSystem contextCoordinateSystem, Orientation orientation, string textString, double fontSize)
        {
            if (fontSize < 0.0001)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, fontSize, "DSText fontSize"), "fontSize");
            }
            if (null == contextCoordinateSystem)
            {
                throw new System.ArgumentNullException("contextCoordinateSystem");
            }

            AssertUniScaledOrtho(contextCoordinateSystem.CSEntity);

            ITextEntity entity = HostFactory.Factory.TextByCoordinateSystem(contextCoordinateSystem.CSEntity, (int)orientation, textString, fontSize);

            if (null == entity)
            {
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSText.ByCoordinateSystem"));
            }
            return(entity);
        }
Ejemplo n.º 18
0
 private static IPointEntity BySphericalCoordinatesCore(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double phi)
 {
     if (contextCoordinateSystem == null)
     {
         throw new ArgumentNullException(string.Format("contextCoordinateSystem"));
     }
     else if (radius == 0.0)
     {
         throw new ArgumentException(Properties.Resources.IsZeroRadius);
     }
     using (var csEntity = HostFactory.Factory.CoordinateSystemBySphericalCoordinates(DSCoordinateSystem.WCS.CSEntity, radius, theta, phi))
     {
         IPointEntity origin = csEntity.Origin;
         IPointEntity pt     = ByCartesianCoordinatesCore(contextCoordinateSystem, origin.X, origin.Y, origin.Z);
         if (null == pt)
         {
             throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSPoint.BySphericalCoordinates"));
         }
         return(pt);
     }
 }
Ejemplo n.º 19
0
        private static IConeEntity ByRadiusHeightCore(DSCoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height)
        {
            string kMethod = "DSCone.ByRadiusHeight";

            if (startRadius.LessThanOrEqualTo(0.0))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "start radius"), "startRadius");
            }
            if (endRadius < 0.0)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "end radius"), "endRadius");
            }
            if (height.LessThanOrEqualTo(0.0))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "height"), "height");
            }
            if (null == contextCoordinateSystem)
            {
                throw new System.ArgumentNullException("contextCoordinateSystem");
            }
            if (!contextCoordinateSystem.IsUniscaledOrtho())
            {
                if (contextCoordinateSystem.IsScaledOrtho())
                {
                    throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "Non Uniform Scaled DSCoordinateSystem", kMethod));
                }
                else
                {
                    throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "Shear DSCoordinateSystem", kMethod));
                }
            }

            IConeEntity entity = HostFactory.Factory.ConeByRadiusLength(contextCoordinateSystem.CSEntity, startRadius, endRadius, height);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethod));
            }
            return(entity);
        }
Ejemplo n.º 20
0
        internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, ref string fileName, string blockName)
        {
            string kMethodName = "DSBlock.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

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

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

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

            IBlockEntity entity = helper.InsertBlockFromFile(contextCoordinateSystem.CSEntity, fileName, blockName);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            return(entity);
        }
Ejemplo n.º 21
0
        internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, string blockName)
        {
            string kMethodName = "DSBlock.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            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));
            }
            if (!helper.BlockExistsInCurrentDocument(blockName))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.DoesNotExist, "DSBlock : " + blockName));
            }

            IBlockEntity entity = helper.InsertBlockFromCurrentDocument(contextCoordinateSystem.CSEntity, blockName);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            return(entity);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Instantiates the specified block by name with the orientation
 /// specified by the coordinate system
 /// </summary>
 /// <param name="contextCoordinateSystem">
 /// Specifies the orientation of the block. Origin is the placement point.
 /// This coordinate system must be orthogonal, can be non-uniformly scaled
 /// </param>
 /// <returns>BlockInstance</returns>
 public DSBlockInstance ByCoordinateSystem(DSCoordinateSystem contextCoordinateSystem)
 {
     return(new DSBlockInstance(contextCoordinateSystem, Name, true));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Constructs a CoordinateSystem at the given u, v parameters on
 /// the given surface. The x-axis of the CoordinateSystem is aligned
 /// with the u-directional tangent, the y-axis with the v-directional
 /// tangent and the z-axis is mutually perpendicular to the x and y axes.
 /// </summary>
 /// <param name="u">U parameter value in the range of [0.0, 1.0]. </param>
 /// <param name="v">V parameter value in the range of [0.0, 1.0]. </param>
 /// <returns>CoordinateSystem</returns>
 public DSCoordinateSystem CoordinateSystemAtParameter(double u, double v)
 {
     return(DSCoordinateSystem.AtParameter(this, u, v));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Constructs a solid cone defined a parent CoordinateSystem, start radius, end radius and height
 /// </summary>
 /// <param name="contextCoordinateSystem">The parent CoordinateSystem of the cone</param>
 /// <param name="startRadius">The radius of the base of the cone</param>
 /// <param name="endRadius">The radius of the top of the cone</param>
 /// <param name="height">The height of the cone</param>
 /// <returns></returns>
 public static DSCone ByRadiusHeight(DSCoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height)
 {
     return(new DSCone(contextCoordinateSystem, startRadius, endRadius, height, true));
 }
Ejemplo n.º 25
0
 protected DSCone(DSCoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height, bool persist)
     : base(ByRadiusHeightCore(contextCoordinateSystem, startRadius, endRadius, height), persist)
 {
     InitializeGuaranteedProperties();
     ContextCoordinateSystem = contextCoordinateSystem;
 }
Ejemplo n.º 26
0
 internal DSBlockInstance(DSCoordinateSystem contextCoordinateSystem, string blockName, bool persist)
     : base(DSBlock.InsertCore(contextCoordinateSystem, blockName), persist)
 {
     Definition = new DSBlock(blockName);
     ContextCoordinateSystem = contextCoordinateSystem;
 }
Ejemplo n.º 27
0
 protected DSCuboid(DSCoordinateSystem contextCoordinateSystem, double length, double width, double height, bool persist)
     : base(CuboidByLengthsCore(contextCoordinateSystem.CSEntity, length, width, height), persist)
 {
     InitializeGuaranteedProperties();
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Constructs a cuboid on a coordinate system with length on X Axis, width on Y Axis and Height on Z Axis. The origin of coordinate system is the centroid of the cuboid.
 /// </summary>
 /// <param name="contextCoordinateSystem">The parent CoordinateSystem of the cuboid</param>
 /// <param name="length">The length of the cuboid</param>
 /// <param name="width">The width of the cuboid</param>
 /// <param name="height">The height of the cuboid</param>
 /// <returns></returns>
 public static DSCuboid ByLengths(DSCoordinateSystem contextCoordinateSystem, double length, double width, double height)
 {
     return(new DSCuboid(contextCoordinateSystem, length, width, height, true));
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Constructs the Text starting from the origin of ParentCoordinateSystem.
 /// </summary>
 /// <param name="contextCoordinateSystem">The origin of the
 /// ParentCoordinateSystem will serve as the starting point of the newly
 /// constructed text</param>
 /// <param name="orientation">
 /// The orientation of the text object constructed</param>
 /// <param name="textString">
 /// The text string content of the text object constructed</param>
 /// <param name="fontSize">
 /// The font of the text string content of the text object constructed</param>
 /// <returns></returns>
 public static DSText ByCoordinateSystem(DSCoordinateSystem contextCoordinateSystem, Orientation orientation, string textString, double fontSize)
 {
     return(new DSText(contextCoordinateSystem, orientation, textString, fontSize, true));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Constructs a solid cylinder defined by a line the start and end radii of its base and top respectively.
 /// </summary>
 /// <param name="contextCoordinateSystem">The parent CoordinateSystem of the cylinder</param>
 /// <param name="radius">The radius of the cylinder</param>
 /// <param name="height">The height of the cylinder</param>
 /// <returns></returns>
 public static DSCylinder ByRadiusHeight(DSCoordinateSystem contextCoordinateSystem, double radius, double height)
 {
     return(new DSCylinder(contextCoordinateSystem, radius, height, true));
 }