/// <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()); }
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); }
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); }
/// <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()); }
private void InitializeGuaranteedProperties() { Radius = ArcEntity.Radius; StartAngle = GeometryExtension.RadiansToDegrees(ArcEntity.StartAngle); SweepAngle = GeometryExtension.RadiansToDegrees(ArcEntity.SweepAngle); Normal = new Vector(ArcEntity.Normal); }
/// <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)); }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mProfile); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mReferencePoint); } base.Dispose(disposing); }
internal static void DisposeObject <T>(ref T[][] obj) where T : DesignScriptEntity { obj.ForEach((T[] item) => GeometryExtension.DisposeObject(ref item)); if (obj.IsDisposed()) { obj = null; } }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mAdjacentEdges); GeometryExtension.DisposeObject(ref mAdjacentFaces); } base.Dispose(disposing); }
private void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mCoordinateSystem); GeometryExtension.DisposeObject(ref mPointOnSurface); GeometryExtension.DisposeObject(ref mContextSurface); } }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mContainingCell); GeometryExtension.DisposeObject(ref mContainingFace); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mCrossSections); GeometryExtension.DisposeObject(ref mGuides); GeometryExtension.DisposeObject(ref mPath); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mVertices); GeometryExtension.DisposeObject(ref mEdges); mSurfaceEntity.DisposeObject(); mSurfaceEntity = null; } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mControlVertices); GeometryExtension.DisposeObject(ref mPoints); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mEdges); GeometryExtension.DisposeObject(ref mVertices); GeometryExtension.DisposeObject(ref mPlane); } base.Dispose(disposing); }
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); }
protected override void Dispose(bool disposing) { if (disposing) { GeometryExtension.DisposeObject(ref mStartPoint); GeometryExtension.DisposeObject(ref mEndPoint); GeometryExtension.DisposeObject(ref mCenterLine); } base.Dispose(disposing); }
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); }
/// <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)); }
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); }
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)); }
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); }
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)); }
/// <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()); }
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); }
/// <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)); }
/// <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)); }
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); }
/// <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 }