/// <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); }
/// <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)); }
protected DSText(DSCoordinateSystem contextCoordinateSystem, Orientation orientation, string textString, double fontSize, bool persist) : base(ByCoordinateSystemCore(contextCoordinateSystem, orientation, textString, fontSize), persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; Orientation = orientation; }
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; }
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; }
protected DSCylinder(DSCoordinateSystem contextCoordinateSystem, double radius, double height, bool persist) : base(CylinderByRadiusHeightCore(contextCoordinateSystem.CSEntity, radius, height), persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; Radius = radius; Height = height; }
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; }
/// <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)); }
/// <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); }
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); }
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); } }
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); }
/// <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); }
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)); }
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); }
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)); } } }
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); }
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); } }
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); }
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); }
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); }
/// <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)); }
/// <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)); }
/// <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)); }
protected DSCone(DSCoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height, bool persist) : base(ByRadiusHeightCore(contextCoordinateSystem, startRadius, endRadius, height), persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; }
internal DSBlockInstance(DSCoordinateSystem contextCoordinateSystem, string blockName, bool persist) : base(DSBlock.InsertCore(contextCoordinateSystem, blockName), persist) { Definition = new DSBlock(blockName); ContextCoordinateSystem = contextCoordinateSystem; }
protected DSCuboid(DSCoordinateSystem contextCoordinateSystem, double length, double width, double height, bool persist) : base(CuboidByLengthsCore(contextCoordinateSystem.CSEntity, length, width, height), persist) { InitializeGuaranteedProperties(); }
/// <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)); }
/// <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)); }
/// <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)); }