private void method_0(ObjectId[] objectId_0) { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); try { progressMeter.SetLimit(objectId_0.Length + 1); if ((double)objectId_0.Length > 10000.0) { progressMeter.Start("Blurring points..."); } CoordinateSystem ceometricUcs = Conversions.GetCeometricUcs(); CoordinateSystem actualCS = CoordinateSystem.Global(); CoordinateTransformator coordinateTransformator = new CoordinateTransformator(actualCS, ceometricUcs); CoordinateTransformator inverseTransformation = coordinateTransformator.GetInverseTransformation(); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { for (int i = 0; i < objectId_0.Length; i++) { DBPoint dBPoint = (DBPoint)transaction.GetObject(objectId_0[i], (OpenMode)1, true); Point point = Conversions.ToCeometricPoint(dBPoint); coordinateTransformator.Transform(point); point.X += RandomGenerator.NextDouble(-PointBlurring.double_0, PointBlurring.double_0); point.Y += RandomGenerator.NextDouble(-PointBlurring.double_0, PointBlurring.double_0); inverseTransformation.Transform(point); Point3d position = new Point3d(point.X, point.Y, point.Z); dBPoint.Position = (position); progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } transaction.Commit(); progressMeter.Stop(); editor.WriteMessage(objectId_0.Length + " points blurred."); } } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
internal void method_0(ObjectId[] objectId_0, ObjectId[] objectId_1, CoordinateSystem coordinateSystem_0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); int num = 0; int num2 = 0; try { using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { progressMeter.SetLimit(objectId_0.Length + objectId_1.Length); if ((double)objectId_0.Length > 10000.0 || (double)objectId_1.Length > 10000.0) { progressMeter.Start("Interpolating..."); } DBManager.SetEpsilon(); CoordinateTransformator coordinateTransformator = new CoordinateTransformator(CoordinateSystem.Global(), coordinateSystem_0); CoordinateTransformator inverseTransformation = coordinateTransformator.GetInverseTransformation(); BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); ObjectId layerId = DBManager.CurrentLayerId(); List <IdPoint> list = new List <IdPoint>(); for (int i = 0; i < objectId_0.Length; i++) { DBPoint dbPoint = (DBPoint)transaction.GetObject(objectId_0[i], (OpenMode)1, true); IdPoint idPoint = new IdPoint(dbPoint); idPoint.IsValid = false; coordinateTransformator.Transform(idPoint.Point); idPoint.Point.Z = double.NaN; list.Add(idPoint); progressMeter.MeterProgress(); } list.Sort(); List <Triangle> list2 = Conversions.ToCeometricAcDbTriangleList(objectId_1); for (int j = 0; j < list2.Count; j++) { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)j, 1000); Triangle triangle = list2[j]; coordinateTransformator.Transform(triangle); double minimumX = triangle.MinimumX; double maximumX = triangle.MaximumX; double minimumY = triangle.MinimumY; double maximumY = triangle.MaximumY; int num3 = Math.Abs(list.BinarySearch(new IdPoint(new Point(minimumX, 0.0, 0.0), null))); int num4 = Math.Abs(list.BinarySearch(new IdPoint(new Point(maximumX, 0.0, 0.0), null))); num3 = Math.Max(num3 - 1, 0); num4 = Math.Min(num4 + 1, list.Count - 1); for (int k = num4; k >= num3; k--) { Point point = list[k].Point; if (point.X <= maximumX && point.X >= minimumX && point.Y <= maximumY && point.Y >= minimumY) { double num5 = Predicate.InTriangle2dExact(triangle.Vertex1, triangle.Vertex2, triangle.Vertex3, point); num5 = Predicate.Orientatation2dExact(triangle) * num5; if (num5 >= 0.0) { double num6 = PointProjection.smethod_0(triangle, point); if (double.IsNaN(num6)) { num++; } else { double x = point.X; double y = point.Y; if (point.Z != double.NaN) { if (PointProjection.string_5 == "H") { if (num6 < point.Z) { goto IL_3FC; } } else if (num6 > point.Z) { goto IL_3FC; } } point.Z = num6; inverseTransformation.Transform(ref x, ref y, ref num6); DBPoint dBPoint = new DBPoint(new Point3d(x, y, num6)); if (PointProjection.string_3 == "C") { dBPoint.LayerId = (layerId); } else if (PointProjection.string_3 == "F") { dBPoint.SetPropertiesFrom(triangle.AcDbFace); } else if (PointProjection.string_3 == "P") { dBPoint.SetPropertiesFrom(list[k].DBPoint); } list[k].IsValid = true; list[k].DBPoint2 = dBPoint; if (PointProjection.string_2 == "Y" & !list[k].DBPoint.IsErased) { list[k].DBPoint.Erase(); } } } } IL_3FC :; } } for (int l = 0; l < list.Count; l++) { if (list[l].IsValid) { blockTableRecord.AppendEntity(list[l].DBPoint2); transaction.AddNewlyCreatedDBObject(list[l].DBPoint2, true); num2++; } } transaction.Commit(); editor.WriteMessage("\nFailed interpolations : " + num); editor.WriteMessage("\nPoints outside surface: " + (objectId_0.Length - num2 - num).ToString()); editor.WriteMessage("\nInterpolated points : " + num2.ToString()); } progressMeter.Stop(); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
public static void smethod_0(ObjectId[] objectId_0, CoordinateSystem coordinateSystem_0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter value = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(value); try { using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { progressMeter.SetLimit(objectId_0.Length); if ((double)objectId_0.Length > 10000.0) { progressMeter.Start("Computing min. perimeter rectangle..."); } CoordinateTransformator coordinateTransformator = new CoordinateTransformator(CoordinateSystem.Global(), coordinateSystem_0); CoordinateTransformator inverseTransformation = coordinateTransformator.GetInverseTransformation(); BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); ObjectId layerId = DBManager.CurrentLayerId(); DBManager.CurrentLayerName(); PointSet pointSet = new PointSet(); for (int i = 0; i < objectId_0.Length; i++) { progressMeter.MeterProgress(); DBPoint dBPoint = (DBPoint)transaction.GetObject(objectId_0[i], (OpenMode)0, true); Point point = new Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z); coordinateTransformator.Transform(point); pointSet.Add(point); } ConvexHull2d convexHull2d = new ConvexHull2d(); convexHull2d.InitialPoints = pointSet; convexHull2d.ComputeHull(); PointSet vertices = convexHull2d.Vertices; double z = vertices[0].Z; for (int j = 0; j < vertices.Count; j++) { vertices[j].Z = z; } BoundingRectangle boundingRectangle = convexHull2d.MinimumPerimeterEnclosingRectangle(); PointSet vertices2 = boundingRectangle.GetVertices(); for (int k = 0; k < vertices2.Count; k++) { inverseTransformation.Transform(vertices2[k]); } Point3dCollection point3dCollection = Conversions.ToPoint3dCollection(vertices2.ToList()); Polyline3d polyline3d = new Polyline3d(0, point3dCollection, true); polyline3d.LayerId = (layerId); blockTableRecord.AppendEntity(polyline3d); transaction.AddNewlyCreatedDBObject(polyline3d, true); editor.WriteMessage("\nMinimum perimeter enclosing rectangle properties:"); editor.WriteMessage("\n-------------------------------------------------"); editor.WriteMessage("\nWidth : " + boundingRectangle.Width.ToString(DBManager.GetFormatFromLUPREC())); editor.WriteMessage("\nHeight : " + boundingRectangle.Length.ToString(DBManager.GetFormatFromLUPREC())); editor.WriteMessage("\nArea : " + (boundingRectangle.Length * boundingRectangle.Width).ToString(DBManager.GetFormatFromLUPREC())); editor.WriteMessage("\nPerimeter length: " + (2.0 * boundingRectangle.Length + 2.0 * boundingRectangle.Width).ToString(DBManager.GetFormatFromLUPREC())); transaction.Commit(); } progressMeter.Stop(); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
public void WriteXYZ(ObjectId[] pointIDs) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); ProgressMeter progressMeter = new ProgressMeter(); progressMeter.SetLimit(pointIDs.Length); progressMeter.Start("Writing XYZ"); try { CoordinateTransformator coordinateTransformator = new CoordinateTransformator(CoordinateSystem.Global(), Conversions.GetUCS()); int num = 0; int num2 = 0; string a = this.method_6(); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { using (StreamWriter streamWriter = new StreamWriter(IO.string_5)) { streamWriter.WriteLine(string.Concat(new object[] { "C ", IO.string_5, " generated ", DateTime.Now })); if (a == ",") { streamWriter.WriteLine("C Format: x, y, z,"); } if (a == ";") { streamWriter.WriteLine("C Format: x; y; z;"); } if (a == " ") { streamWriter.WriteLine("C Format: x y z"); } for (int i = 0; i < pointIDs.Length; i++) { DBPoint dBPoint = (DBPoint)transaction.GetObject(pointIDs[i], (OpenMode)0, true); ngeometry.VectorGeometry.Point point = new ngeometry.VectorGeometry.Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z); coordinateTransformator.Transform(point); string text = this.method_5(point, ref num); streamWriter.WriteLine(text.TrimEnd(new char[0])); progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 10000); num2++; } streamWriter.Flush(); } } progressMeter.Stop(); if (num > 0) { editor.WriteMessage(string.Concat(new object[] { Environment.NewLine, num, " conversion errors occurred writing ", IO.string_5, ". Increase the column width and/or decrease the number of decimal digits." })); Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Concat(new object[] { num, " conversion errors occurred writing ", IO.string_5, ".\nIncrease the column width and/or decrease the number of decimal digits." })); } FileInfo fileInfo = new FileInfo(IO.string_5); editor.WriteMessage(Environment.NewLine + "Output file name : " + fileInfo.FullName); editor.WriteMessage(Environment.NewLine + "Number of points written : " + num2.ToString()); editor.WriteMessage(Environment.NewLine + "Coordinate conversion errors: " + num.ToString()); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
private void method_3(ObjectId[] objectId_0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); ProgressMeter progressMeter = new ProgressMeter(); progressMeter.SetLimit(objectId_0.Length); progressMeter.Start("Writing 3df"); try { CoordinateTransformator coordinateTransformator = new CoordinateTransformator(CoordinateSystem.Global(), Conversions.GetUCS()); int num = 0; int num2 = 0; string text = this.method_6(); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { using (StreamWriter streamWriter = new StreamWriter(IO.string_2)) { streamWriter.WriteLine(string.Concat(new object[] { "C ", IO.string_2, " generated ", DateTime.Now })); if (text == ",") { streamWriter.WriteLine("C Format: Layer name, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4"); } if (text == ";") { streamWriter.WriteLine("C Format: Layer name; x1; y1; z1; x2; y2; z2; x3; y3; z3; x4; y4; z4"); } if (text == " ") { streamWriter.WriteLine("C Format: Layer name x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4"); } for (int i = 0; i < objectId_0.Length; i++) { Autodesk.AutoCAD.DatabaseServices.Face face = (Autodesk.AutoCAD.DatabaseServices.Face)transaction.GetObject(objectId_0[i], (OpenMode)0, true); Point3d vertexAt = face.GetVertexAt(0); Point3d vertexAt2 = face.GetVertexAt(1); Point3d vertexAt3 = face.GetVertexAt(2); Point3d vertexAt4 = face.GetVertexAt(3); ngeometry.VectorGeometry.Point point = new ngeometry.VectorGeometry.Point(vertexAt.X, vertexAt.Y, vertexAt.Z); ngeometry.VectorGeometry.Point point2 = new ngeometry.VectorGeometry.Point(vertexAt2.X, vertexAt2.Y, vertexAt2.Z); ngeometry.VectorGeometry.Point point3 = new ngeometry.VectorGeometry.Point(vertexAt3.X, vertexAt3.Y, vertexAt3.Z); ngeometry.VectorGeometry.Point point4 = new ngeometry.VectorGeometry.Point(vertexAt4.X, vertexAt4.Y, vertexAt4.Z); coordinateTransformator.Transform(point); coordinateTransformator.Transform(point2); coordinateTransformator.Transform(point3); coordinateTransformator.Transform(point4); string text2 = face.Layer.PadLeft(IO.int_0) + text; text2 += this.method_5(point, ref num); text2 += this.method_5(point2, ref num); text2 += this.method_5(point3, ref num); text2 += this.method_5(point4, ref num); streamWriter.WriteLine(text2.TrimEnd(new char[0])); progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 10000); num2++; } streamWriter.Flush(); } } progressMeter.Stop(); if (num > 0) { editor.WriteMessage(string.Concat(new object[] { Environment.NewLine, num, " conversion errors occurred writing ", IO.string_2, ". Increase the column width and/or decrease the number of decimal digits." })); Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Concat(new object[] { num, " conversion errors occurred writing ", IO.string_2, ".\nIncrease the column width and/or decrease the number of decimal digits." })); } FileInfo fileInfo = new FileInfo(IO.string_2); editor.WriteMessage(Environment.NewLine + "Output file name : " + fileInfo.FullName); editor.WriteMessage(Environment.NewLine + "Number of faces written : " + num2.ToString()); editor.WriteMessage(Environment.NewLine + "Coordinate conversion errors: " + num.ToString()); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
private void method_4() { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; string value = IO.AutoDetermineDelimiter(IO.string_4, false); char c = Convert.ToChar(value); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); int num = 0; using (StreamReader streamReader = new StreamReader(IO.string_4)) { while (streamReader.Peek() >= 0) { streamReader.ReadLine(); num++; } } ProgressMeter progressMeter = new ProgressMeter(); progressMeter.SetLimit(num); progressMeter.Start("Reading XYZ"); try { CoordinateTransformator coordinateTransformator = new CoordinateTransformator(Conversions.GetUCS(), CoordinateSystem.Global()); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { ObjectId layerId = DBManager.CurrentLayerId(); BlockTable arg_C3_0 = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0); ObjectId blockModelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(workingDatabase); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockModelSpaceId, (OpenMode)1); int num2 = 1; int num3 = 0; using (StreamReader streamReader2 = new StreamReader(IO.string_4)) { while (streamReader2.Peek() >= 0) { string text = streamReader2.ReadLine().Trim(); if (!text.StartsWith("C", true, null)) { try { string[] array = text.Split(new char[] { c }, StringSplitOptions.RemoveEmptyEntries); double num4 = Convert.ToDouble(array[0]); double num5 = Convert.ToDouble(array[1]); double num6 = 0.0; if (array.Length > 2) { num6 = Convert.ToDouble(array[2]); } coordinateTransformator.Transform(ref num4, ref num5, ref num6); Entity entity = new DBPoint(new Point3d(num4, num5, num6)); entity.LayerId = (layerId); entity.ColorIndex = (256); blockTableRecord.AppendEntity(entity); transaction.AddNewlyCreatedDBObject(entity, true); num3++; } catch (System.Exception ex) { if (text.Trim() == "") { text = "Empty line!"; } throw new FormatException(string.Concat(new string[] { "Invalid point data format in line ", num2.ToString(), ":", Environment.NewLine, text, Environment.NewLine })); } } num2++; progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)num2, 1000); } } transaction.Commit(); progressMeter.Stop(); editor.WriteMessage(string.Concat(new object[] { Environment.NewLine, num3, " points read", Environment.NewLine })); } DBManager.ZoomExtents(); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
private void method_2() { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; string value = IO.AutoDetermineDelimiter(IO.string_3, true); char c = Convert.ToChar(value); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); int num = 0; using (StreamReader streamReader = new StreamReader(IO.string_3)) { while (streamReader.Peek() >= 0) { streamReader.ReadLine(); num++; } } ProgressMeter progressMeter = new ProgressMeter(); progressMeter.SetLimit(num); progressMeter.Start("Reading 3df file"); try { CoordinateTransformator coordinateTransformator = new CoordinateTransformator(Conversions.GetUCS(), CoordinateSystem.Global()); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { LayerTable lt = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0); BlockTable arg_D1_0 = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0); ObjectId blockModelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(workingDatabase); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockModelSpaceId, (OpenMode)1); int num2 = 1; int num3 = 0; using (StreamReader streamReader2 = new StreamReader(IO.string_3)) { while (streamReader2.Peek() >= 0) { string text = streamReader2.ReadLine(); if (!text.StartsWith("C", true, null) && !(text == "")) { try { string[] array = text.Split(new char[] { c }, StringSplitOptions.RemoveEmptyEntries); string text2 = array[0].Trim(); if (!DBManager.ValidateName(text2)) { throw new System.Exception(string.Concat(new object[] { "Invalid layer name in line ", num2, ":\n", text })); } if (text2 == "") { text2 = "0"; } double num4 = Convert.ToDouble(array[1]); double num5 = Convert.ToDouble(array[2]); double num6 = Convert.ToDouble(array[3]); double num7 = Convert.ToDouble(array[4]); double num8 = Convert.ToDouble(array[5]); double num9 = Convert.ToDouble(array[6]); double num10 = Convert.ToDouble(array[7]); double num11 = Convert.ToDouble(array[8]); double num12 = Convert.ToDouble(array[9]); double num13 = Convert.ToDouble(array[10]); double num14 = Convert.ToDouble(array[11]); double num15 = Convert.ToDouble(array[12]); coordinateTransformator.Transform(ref num4, ref num5, ref num6); coordinateTransformator.Transform(ref num7, ref num8, ref num9); coordinateTransformator.Transform(ref num10, ref num11, ref num12); coordinateTransformator.Transform(ref num13, ref num14, ref num15); Point3d point3d = new Point3d(num4, num5, num6); //point3d..ctor(num4, num5, num6); Point3d point3d2 = new Point3d(num7, num8, num9); //point3d2..ctor(num7, num8, num9); Point3d point3d3 = new Point3d(num10, num11, num12); //point3d3..ctor(num10, num11, num12); Point3d point3d4 = new Point3d(num13, num14, num15); //point3d4..ctor(num13, num14, num15); Entity entity = new Autodesk.AutoCAD.DatabaseServices.Face(point3d, point3d2, point3d3, point3d4, true, true, true, true); entity.LayerId = (DBManager.GetLayerId(text2, 7, lt)); entity.ColorIndex = (256); blockTableRecord.AppendEntity(entity); transaction.AddNewlyCreatedDBObject(entity, true); num3++; } catch (System.Exception ex) { if (text.Trim() == "") { text = "Empty line!"; } throw new FormatException(string.Concat(new string[] { "Invalid format in line ", num2.ToString(), ":", Environment.NewLine, text, Environment.NewLine })); } } num2++; progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)num2, 1000); } } transaction.Commit(); progressMeter.Stop(); editor.WriteMessage(string.Concat(new object[] { Environment.NewLine, num3, " faces read.", Environment.NewLine })); } DBManager.ZoomExtents(); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
private void method_1(ObjectId[] objectId_0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; EntityList entityList = new EntityList(); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); ProgressMeter progressMeter = new ProgressMeter(); progressMeter.SetLimit(objectId_0.Length); progressMeter.Start("Serializing XML entities"); try { CoordinateTransformator coordinateTransformator = new CoordinateTransformator(CoordinateSystem.Global(), Conversions.GetUCS()); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { LayerTable arg_83_0 = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0); for (int i = 0; i < objectId_0.Length; i++) { messageFilter.CheckMessageFilter((long)i, 10000); progressMeter.MeterProgress(); Entity entity = (Entity)transaction.GetObject(objectId_0[i], (OpenMode)0); string name = ((LayerTableRecord)transaction.GetObject(entity.LayerId, (OpenMode)0)).Name; Autodesk.AutoCAD.DatabaseServices.Face face = entity as Autodesk.AutoCAD.DatabaseServices.Face; if (face != null) { Point3d vertexAt = face.GetVertexAt(0); Point3d vertexAt2 = face.GetVertexAt(1); Point3d vertexAt3 = face.GetVertexAt(2); Point3d vertexAt4 = face.GetVertexAt(3); global::TerrainComputeC.XML.Vertex v = new global::TerrainComputeC.XML.Vertex(vertexAt.X, vertexAt.Y, vertexAt.Z); global::TerrainComputeC.XML.Vertex v2 = new global::TerrainComputeC.XML.Vertex(vertexAt2.X, vertexAt2.Y, vertexAt2.Z); global::TerrainComputeC.XML.Vertex v3 = new global::TerrainComputeC.XML.Vertex(vertexAt3.X, vertexAt3.Y, vertexAt3.Z); global::TerrainComputeC.XML.Vertex v4 = new global::TerrainComputeC.XML.Vertex(vertexAt4.X, vertexAt4.Y, vertexAt4.Z); global::TerrainComputeC.XML.Face face2 = new global::TerrainComputeC.XML.Face(v, v2, v3, v4); face2.SetProperties(name, face.Color.ColorIndex); entityList.Faces.Add(face2); coordinateTransformator.Transform(face2); num4++; } else { DBPoint dBPoint = entity as DBPoint; if (dBPoint != null) { global::TerrainComputeC.XML.Point point = new global::TerrainComputeC.XML.Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z); point.SetProperties(name, dBPoint.Color.ColorIndex); entityList.Points.Add(point); coordinateTransformator.Transform(point); num++; } else { Autodesk.AutoCAD.DatabaseServices.Line line = entity as Autodesk.AutoCAD.DatabaseServices.Line; if (line != null) { Point3d startPoint = line.StartPoint; Point3d endPoint = line.EndPoint; global::TerrainComputeC.XML.Vertex startVertex = new global::TerrainComputeC.XML.Vertex(startPoint.X, startPoint.Y, startPoint.Z); global::TerrainComputeC.XML.Vertex endVertex = new global::TerrainComputeC.XML.Vertex(endPoint.X, endPoint.Y, endPoint.Z); global::TerrainComputeC.XML.Line line2 = new global::TerrainComputeC.XML.Line(startVertex, endVertex); line2.SetProperties(name, line.Color.ColorIndex); entityList.Lines.Add(line2); coordinateTransformator.Transform(line2); num2++; } else { Polyline polyline = entity as Polyline; Polyline2d polyline2d = entity as Polyline2d; Polyline3d polyline3d = entity as Polyline3d; if (polyline != null || polyline2d != null || polyline3d != null) { short colorIndex = 256; if (polyline != null) { colorIndex = polyline.Color.ColorIndex; } if (polyline2d != null) { colorIndex = polyline2d.Color.ColorIndex; } if (polyline3d != null) { colorIndex = polyline3d.Color.ColorIndex; } PointSet pointSet = PointGeneration.SubdividePolyline(entity, transaction, 0.0); List <global::TerrainComputeC.XML.Vertex> list = new List <global::TerrainComputeC.XML.Vertex>(); for (int j = 0; j < pointSet.Count; j++) { list.Add(new global::TerrainComputeC.XML.Vertex(pointSet[j].X, pointSet[j].Y, pointSet[j].Z)); } PolyLine polyLine = new PolyLine(list); polyLine.SetProperties(name, colorIndex); entityList.Polylines.Add(polyLine); coordinateTransformator.Transform(polyLine); num3++; } } } } } } progressMeter.Stop(); editor.WriteMessage("\nXML entity list created:"); editor.WriteMessage("\nNumber of points : " + entityList.Points.Count); editor.WriteMessage("\nNumber of lines : " + entityList.Lines.Count); editor.WriteMessage("\nNumber of polylines : " + entityList.Polylines.Count); editor.WriteMessage("\nNumber of faces : " + entityList.Faces.Count); editor.WriteMessage("\nTotal number of entities: " + entityList.Count); editor.WriteMessage("\nWriting xml file " + IO.string_0 + "..."); Serializer.Serialize(IO.string_0, entityList); editor.WriteMessage("OK\n"); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
private List <Edge> method_0(ObjectId[] objectId_0, ObjectId[] objectId_1, CoordinateSystem coordinateSystem_0, bool bool_0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); int num = 0; int num2 = 0; int num3 = 0; IdEdgeList idEdgeList = new IdEdgeList(); List <Edge> list = new List <Edge>(); int num4 = DBManager.SetEpsilon(); int num5 = (int)Convert.ToInt16(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("LUPREC").ToString()); num4 = Math.Min(num5 + 2, num4); double num6 = Math.Max(Math.Pow(10.0, (double)(-(double)num4)), Global.AbsoluteEpsilon); CoordinateTransformator coordinateTransformator = new CoordinateTransformator(CoordinateSystem.Global(), coordinateSystem_0); CoordinateTransformator inverseTransformation = coordinateTransformator.GetInverseTransformation(); List <Triangle> list2 = Conversions.ToCeometricAcDbTriangleList(objectId_1); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); ObjectId layerId = DBManager.CurrentLayerId(); DBManager.CurrentLayerName(); List <IdEdge> list3 = new List <IdEdge>(); double num7 = -1.7976931348623157E+308; for (int i = 0; i < objectId_0.Length; i++) { Autodesk.AutoCAD.DatabaseServices.Line line = (Autodesk.AutoCAD.DatabaseServices.Line)transaction.GetObject(objectId_0[i], (OpenMode)1, true); IdEdge idEdge = new IdEdge(line); if (LineProjection.string_0 == "Y" & !idEdge.Line.IsErased) { idEdge.Line.Erase(); } coordinateTransformator.Transform(idEdge.Edge); double num8 = idEdge.Edge.StartPoint.X - idEdge.Edge.EndPoint.X; double num9 = idEdge.Edge.StartPoint.Y - idEdge.Edge.EndPoint.Y; double num10 = Math.Sqrt(num8 * num8 + num9 * num9); if (Math.Abs(num8) > num7) { num7 = Math.Abs(num8); } if (num10 < Global.AbsoluteEpsilon) { num2++; } else { idEdge.SetMinMaxXY(); list3.Add(idEdge); } } list3.Sort(new CompareMin()); progressMeter.SetLimit(objectId_1.Length); if ((double)objectId_1.Length > 10000.0) { progressMeter.Start("Projecting lines..."); } try { for (int j = 0; j < list2.Count; j++) { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)j, 1000); Triangle triangle = list2[j]; coordinateTransformator.Transform(triangle); if (Math.Abs(triangle.NormalVector.Z) < Global.AbsoluteEpsilon) { num++; } else { double minimumX = triangle.MinimumX; double maximumX = triangle.MaximumX; double minimumY = triangle.MinimumY; double maximumY = triangle.MaximumY; IdEdge item = new IdEdge(new Edge(new Point(maximumX, minimumY, 0.0), new Point(maximumX + 1.0, minimumY, 0.0))); int num11 = list3.BinarySearch(item, new CompareMin()); if (num11 < 0) { num11 = ~num11; } IdEdge item2 = new IdEdge(new Edge(new Point(minimumX - num7, maximumY, 0.0), new Point(minimumX - num7 + 1.0, maximumY, 0.0))); int num12 = list3.BinarySearch(item2, new CompareMin()); if (num12 < 0) { num12 = ~num12; } try { for (int k = num12; k < num11; k++) { IdEdge idEdge2 = list3[k]; if (idEdge2.MinX <= maximumX && idEdge2.MinY <= maximumY && idEdge2.MaxX >= minimumX && idEdge2.MaxY >= minimumY) { Edge edge = idEdge2.Edge; double num13 = Predicate.InTriangle2dArbitraryExact(triangle.Vertex1, triangle.Vertex2, triangle.Vertex3, edge.StartPoint); double num14 = Predicate.InTriangle2dArbitraryExact(triangle.Vertex1, triangle.Vertex2, triangle.Vertex3, edge.EndPoint); Edge edge2 = new Edge(); if (!double.IsNaN(num14) && !double.IsNaN(num13)) { if (num14 == 1.0 && num13 == 1.0) { edge2 = edge; } else if (num13 == 1.0 && num14 == 0.0) { edge2 = edge; } else if (num13 == 0.0 && num14 == 1.0) { edge2 = edge; } else if (num13 == 0.0 && num14 == 0.0) { edge2 = edge; } else if (num13 == -1.0 && num14 == 1.0) { edge2 = this.method_1(edge, triangle, edge.EndPoint); } else if (num13 == 1.0 && num14 == -1.0) { edge2 = this.method_1(edge, triangle, edge.StartPoint); } else if (num13 == 0.0 && num14 == -1.0) { edge2 = this.method_2(edge, triangle, edge.StartPoint); } else if (num13 == -1.0 && num14 == 0.0) { edge2 = this.method_2(edge, triangle, edge.EndPoint); } else if (num13 == -1.0 && num14 == -1.0) { edge2 = this.method_3(edge, triangle); } if (!(edge2 == null)) { Edge edge3 = edge2.DeepCopy(); edge3.StartPoint.Z = PointProjection.smethod_0(triangle, edge3.StartPoint); edge3.EndPoint.Z = PointProjection.smethod_0(triangle, edge3.EndPoint); if (edge3.Length >= num6) { Edge edge4 = edge3.DeepCopy(); edge4.SwapSort(); edge4.StartPoint.X = (double)((float)edge4.StartPoint.X); edge4.StartPoint.Y = (double)((float)edge4.StartPoint.Y); edge4.StartPoint.Z = (double)((float)edge4.StartPoint.Z); edge4.EndPoint.X = (double)((float)edge4.EndPoint.X); edge4.EndPoint.Y = (double)((float)edge4.EndPoint.Y); edge4.EndPoint.Z = (double)((float)edge4.EndPoint.Z); if (!idEdgeList.ContainsKey(edge4)) { idEdgeList.Add(edge4, null); inverseTransformation.Transform(edge3); list.Add(edge3); if (bool_0) { Point3d point3d = new Point3d(edge3.StartPoint.X, edge3.StartPoint.Y, edge3.StartPoint.Z); //point3d..ctor(edge3.StartPoint.X, edge3.StartPoint.Y, edge3.StartPoint.Z); Point3d point3d2 = new Point3d(edge3.EndPoint.X, edge3.EndPoint.Y, edge3.EndPoint.Z); //point3d2..ctor(edge3.EndPoint.X, edge3.EndPoint.Y, edge3.EndPoint.Z); Autodesk.AutoCAD.DatabaseServices.Line line2 = new Autodesk.AutoCAD.DatabaseServices.Line(point3d, point3d2); if (LineProjection.string_1 == "C") { LayerTableRecord layerTableRecord = (LayerTableRecord)transaction.GetObject(triangle.AcDbFace.LayerId, (OpenMode)0); Color color = triangle.AcDbFace.Color; if (color.IsByLayer) { color = layerTableRecord.Color; } line2.SetPropertiesFrom(triangle.AcDbFace); line2.LayerId = (layerId); line2.Color = (color); } else if (LineProjection.string_1 == "F") { line2.SetPropertiesFrom(triangle.AcDbFace); } else if (LineProjection.string_1 == "L") { line2.SetPropertiesFrom(idEdge2.Line); } blockTableRecord.AppendEntity(line2); transaction.AddNewlyCreatedDBObject(line2, true); } } } } } } } } catch (System.Exception ex) { editor.WriteMessage("\n" + ex.Message); num3++; } } } } catch (System.Exception ex) { progressMeter.Stop(); throw; } transaction.Commit(); } progressMeter.Stop(); if (bool_0) { editor.WriteMessage("\nNumber of lines projected : " + idEdgeList.Count); editor.WriteMessage("\nNumber of failed faces : " + num3); editor.WriteMessage("\nFaces parallel to projection direction: " + num); editor.WriteMessage("\nLines parallel to projection direction: " + num2); } return(list); }
public static void ComputeMinEnclosingCircle(ObjectId[] idArray, CoordinateSystem actualCS) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter value = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(value); try { using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { progressMeter.SetLimit(idArray.Length); if ((double)idArray.Length > 10000.0) { progressMeter.Start("Computing min. enclosing circle..."); } CoordinateTransformator coordinateTransformator = new CoordinateTransformator(CoordinateSystem.Global(), actualCS); CoordinateTransformator inverseTransformation = coordinateTransformator.GetInverseTransformation(); BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); ObjectId layerId = DBManager.CurrentLayerId(); DBManager.CurrentLayerName(); PointSet pointSet = new PointSet(); for (int i = 0; i < idArray.Length; i++) { progressMeter.MeterProgress(); DBPoint dBPoint = (DBPoint)transaction.GetObject(idArray[i], (OpenMode)0, true); Point point = new Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z); coordinateTransformator.Transform(point); pointSet.Add(point); } ConvexHull2d convexHull2d = new ConvexHull2d(); convexHull2d.InitialPoints = pointSet; convexHull2d.ComputeHull(); PointSet vertices = convexHull2d.Vertices; double z = vertices[0].Z; for (int j = 0; j < vertices.Count; j++) { vertices[j].Z = z; } SmallestEnclosingCircle smallestEnclosingCircle = new SmallestEnclosingCircle(vertices); ngeometry.VectorGeometry.Circle circle = smallestEnclosingCircle.ComputeCircle(); Point center = circle.Center; Point point2 = circle.NormalVector.ToPoint(); inverseTransformation.Transform(center); inverseTransformation.Transform(point2); Autodesk.AutoCAD.DatabaseServices.Circle circle2 = new Autodesk.AutoCAD.DatabaseServices.Circle(new Autodesk.AutoCAD.Geometry.Point3d(center.X, center.Y, center.Z), new Autodesk.AutoCAD.Geometry.Vector3d(point2.X, point2.Y, point2.Z), circle.Radius); circle2.LayerId = (layerId); blockTableRecord.AppendEntity(circle2); transaction.AddNewlyCreatedDBObject(circle2, true); editor.WriteMessage("\nMinimum enclosing circle properties:"); editor.WriteMessage("\n------------------------------------"); editor.WriteMessage("\nRadius : " + circle.Radius.ToString(DBManager.GetFormatFromLUPREC())); editor.WriteMessage("\nArea : " + circle.Area.ToString(DBManager.GetFormatFromLUPREC())); editor.WriteMessage("\nPerimeter length: " + circle.Circumference.ToString(DBManager.GetFormatFromLUPREC())); transaction.Commit(); } progressMeter.Stop(); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
public static void Compute2dHull(ObjectId[] idArray, CoordinateSystem actualCS) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter value = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(value); try { using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { progressMeter.SetLimit(idArray.Length); if ((double)idArray.Length > 10000.0) { progressMeter.Start("Computing 2d hull..."); } CoordinateTransformator coordinateTransformator = new CoordinateTransformator(CoordinateSystem.Global(), actualCS); CoordinateTransformator inverseTransformation = coordinateTransformator.GetInverseTransformation(); BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); ObjectId layerId = DBManager.CurrentLayerId(); DBManager.CurrentLayerName(); PointSet pointSet = new PointSet(); for (int i = 0; i < idArray.Length; i++) { DBPoint dBPoint = (DBPoint)transaction.GetObject(idArray[i], (OpenMode)0, true); Point point = new Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z); coordinateTransformator.Transform(point); pointSet.Add(point); } ConvexHull2d convexHull2d = new ConvexHull2d(); convexHull2d.InitialPoints = pointSet; convexHull2d.ComputeHull(); PointSet vertices = convexHull2d.Vertices; double z = vertices[0].Z; for (int j = 0; j < vertices.Count; j++) { vertices[j].Z = z; } double areaXY = convexHull2d.AreaXY; for (int k = 0; k < vertices.Count; k++) { inverseTransformation.Transform(vertices[k]); } Point3dCollection point3dCollection = Conversions.ToPoint3dCollection(vertices.ToList()); Polyline3d polyline3d = new Polyline3d(0, point3dCollection, true); polyline3d.LayerId = (layerId); blockTableRecord.AppendEntity(polyline3d); transaction.AddNewlyCreatedDBObject(polyline3d, true); editor.WriteMessage("\n2d convex hull properties:"); editor.WriteMessage("\nNumber of vertices on hull : " + convexHull2d.Vertices.Count); editor.WriteMessage("\nHull perimeter length : " + convexHull2d.PerimeterLength.ToString(DBManager.GetFormatFromLUPREC())); editor.WriteMessage("\nEnclosed area in hull plane: " + areaXY.ToString(DBManager.GetFormatFromLUPREC())); transaction.Commit(); } progressMeter.Stop(); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }