private static ISolidEntity RevolveCore(DSCurve profile, DSPoint axisOrigin, DSVector 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 (DSGeometryExtension.Equals(axisDirection.Length, 0.0)) { throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "axisDirection"), "axisDirection"); } if (DSGeometryExtension.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, "DSSolid.Revolve")); } return(entity); }
private static ISurfaceEntity FromCrossSectionsGuidesCore(DSCurve[] crossSections, DSCurve[] guides) { bool isClosed = crossSections[0].IsClosed; //Validation ICurveEntity[] hostXCurves = crossSections.ConvertAll((DSCurve c) => DSGeometryExtension.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(DSGeometryExtension.ToEntity <DSCurve, 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, "DSSurface.LoftFromCrossSectionsGuides")); } return(entity); }
/// <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()); }
/// <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 DSBlock Import(string blockName, string filePath) { string kMethodName = "DSBlock.Import"; filePath = DSGeometryExtension.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 DSBlock(blockName, filePath)); }
/// <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 DSBlock[] ImportAll(string filePath) { string kMethodName = "DSBlock.ImportAll"; filePath = DSGeometryExtension.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 <DSBlock> blocks = new List <DSBlock>(); foreach (var name in blockNames) { DSBlock block = new DSBlock(name, filePath); blocks.Add(block); } return(blocks.ToArray()); }
private void InitializeGuaranteedProperties() { Radius = ArcEntity.Radius; StartAngle = DSGeometryExtension.RadiansToDegrees(ArcEntity.StartAngle); SweepAngle = DSGeometryExtension.RadiansToDegrees(ArcEntity.SweepAngle); Normal = new DSVector(ArcEntity.Normal); }
internal static void DisposeObject <T>(ref T[][] obj) where T : DesignScriptEntity { obj.ForEach((T[] item) => DSGeometryExtension.DisposeObject(ref item)); if (obj.IsDisposed()) { obj = null; } }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mFaces); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mReferencePoint); } base.Dispose(disposing); }
private void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mCoordinateSystem); DSGeometryExtension.DisposeObject(ref mPointOnSurface); DSGeometryExtension.DisposeObject(ref mContextSurface); } }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mContainingCell); DSGeometryExtension.DisposeObject(ref mContainingFace); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mProfile); DSGeometryExtension.DisposeObject(ref mPath); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mVertices); DSGeometryExtension.DisposeObject(ref mEdges); mSurfaceEntity.DisposeObject(); mSurfaceEntity = null; } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mEdges); DSGeometryExtension.DisposeObject(ref mVertices); DSGeometryExtension.DisposeObject(ref mPlane); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mAdjacentFaces); DSGeometryExtension.DisposeObject(ref mStartVertex); DSGeometryExtension.DisposeObject(ref mEndVertex); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mControlVertices); DSGeometryExtension.DisposeObject(ref mPoints); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mCrossSections); DSGeometryExtension.DisposeObject(ref mGuides); DSGeometryExtension.DisposeObject(ref mPath); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mStartPoint); DSGeometryExtension.DisposeObject(ref mEndPoint); DSGeometryExtension.DisposeObject(ref mCenterLine); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mFirstPoint); DSGeometryExtension.DisposeObject(ref mSecondPoint); DSGeometryExtension.DisposeObject(ref mThirdPoint); DSGeometryExtension.DisposeObject(ref mCenterPoint); } base.Dispose(disposing); }
private static ICircleEntity ByPointsOnCurveCore(DSPoint firstPoint, DSPoint secondPoint, DSPoint 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 (DSGeometryExtension.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, "DSCircle.ByPointsOnCurve")); } return(entity); }
/// <summary> /// /// </summary> /// <param name="other"></param> /// <returns></returns> public bool IsPerpendicular(DSVector other) { if (other == null) { throw new System.ArgumentNullException("other"); } var normalizedThis = Normalize(); var normalizedOther = other.Normalize(); var dotProd = normalizedThis.Dot(normalizedOther); return(DSGeometryExtension.Equals(Math.Abs(dotProd), 0.0)); }
internal static IGeometryEntity[] ImportFromSAT(ref string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { throw new System.ArgumentNullException("fileName"); } fileName = DSGeometryExtension.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); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mCellFaces); DSGeometryExtension.DisposeObject(ref mAdjacentCells); DSGeometryExtension.DisposeObject(ref mEdges); DSGeometryExtension.DisposeObject(ref mVertices); DSGeometryExtension.DisposeObject(ref mShell); DSGeometryExtension.DisposeObject(ref mCentroid); } base.Dispose(disposing); }
internal static bool EqualsTo(this IPointEntity thisValue, IPointEntity value) { if (Object.ReferenceEquals(thisValue, value)) { return(true); } if (null == thisValue || null == value) { return(false); } return(DSGeometryExtension.Equals(thisValue.X, value.X) && DSGeometryExtension.Equals(thisValue.Y, value.Y) && DSGeometryExtension.Equals(thisValue.Z, value.Z)); }
/// <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 DSSubDivisionMesh[] ImportFromOBJ(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) { throw new System.ArgumentNullException("filePath"); } filePath = DSGeometryExtension.LocateFile(filePath); if (!File.Exists(filePath)) { throw new System.ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath"); } DSMeshData result = ObjHandler.Import(filePath); return(result.ConvertToSubDivisionMesh()); }
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)); }
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} = DSArc.ByCenterPointRadiusAngle({1}, {2}, {3}, {4}, {5});", paramName, center, arc.Radius, DSGeometryExtension.RadiansToDegrees(arc.StartAngle), DSGeometryExtension.RadiansToDegrees(arc.SweepAngle), normal); mExpression.AppendLine(); return(paramName); }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (Object.ReferenceEquals(this, obj)) { return(true); } DSVector vec = obj as DSVector; if (null == vec) { return(false); } return(DSGeometryExtension.Equals(vec.X, X) && DSGeometryExtension.Equals(vec.Y, Y) && DSGeometryExtension.Equals(vec.Z, Z)); }
protected override void Dispose(bool disposing) { if (disposing) { DSGeometryExtension.DisposeObject(ref mVertices); DSGeometryExtension.DisposeObject(ref mEdges); DSGeometryExtension.DisposeObject(ref mFaces); DSGeometryExtension.DisposeObject(ref mShells); DSGeometryExtension.DisposeObject(ref mCrossSections); DSGeometryExtension.DisposeObject(ref mPath); DSGeometryExtension.DisposeObject(ref mGuides); DSGeometryExtension.DisposeObject(ref mProfile); DSGeometryExtension.DisposeObject(ref mAxisOrigin); DSGeometryExtension.DisposeObject(ref mAxis); } base.Dispose(disposing); }
/// <summary> /// /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { if (disposing) { if (null != mPersistent && !Object.ReferenceEquals(mPersistent, base.HostImpl)) { mPersistent.Dispose(); } DSGeometryExtension.DisposeObject(ref mContext); DSGeometryExtension.DisposeObject(ref mContextCS); } mPersistent = null; mDisplayAttributes = null; base.Dispose(disposing); //allow base class to release it's resources }