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; } }
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 { CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(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(IO2.string_2)) { streamWriter.WriteLine(string.Concat(new object[] { "C ", IO2.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(IO2.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 ", IO2.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 ", IO2.string_2, ".\nIncrease the column width and/or decrease the number of decimal digits." })); } FileInfo fileInfo = new FileInfo(IO2.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_2() { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; string value = IO2.AutoDetermineDelimiter(IO2.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(IO2.string_3)) { while (streamReader.Peek() >= 0) { streamReader.ReadLine(); num++; } } ProgressMeter progressMeter = new ProgressMeter(); progressMeter.SetLimit(num); progressMeter.Start("Reading 3df file"); try { CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(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(IO2.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 { CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(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 " + IO2.string_0 + "..."); Serializer.Serialize(IO2.string_0, entityList); editor.WriteMessage("OK\n"); } 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 Colorize(MyDB2 mydb, List <System.Drawing.Color> cl) { TEDictionary ted = mydb.TEDicList[mydb.Resolution]; AssistContourDic assistContourDic = mydb.assistContourDics[mydb.Resolution]; 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); try { double num = 1.7976931348623157E+308; double num2 = -1.7976931348623157E+308; string formatFromLUPREC = DBManager.GetFormatFromLUPREC(); string a; double range = ted.maxMaxZ - ted.minCZ; double sec = range / cl.Count; progressMeter.SetLimit(assistContourDic.elevations.Count); progressMeter.Start("Colorizing property"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord arg_3D7_0 = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); int i = 0; while (i < assistContourDic.elevations.Count) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } int colorIndex; double elevation = assistContourDic.elevations[i]; List <BASE.PLine> pls = assistContourDic.plines[i]; colorIndex = (int)Math.Floor((elevation - ted.minCZ) / sec); if (colorIndex >= cl.Count) { colorIndex = cl.Count - 1; } //Face face = (Face)transaction.GetObject(triList[i].AcDbFace.ObjectId, (OpenMode)1); for (int j = 0; j < pls.Count; j++) { PointSet ps = pls[j].GetVertices(); if (ps.Count <= 2) { continue; } Region h = MyRegion.NewRegion(ps[1]); if (h != null) { h.Color = Autodesk.AutoCAD.Colors.Color.FromColor(cl[colorIndex]); } } i++; continue; } transaction.Commit(); } progressMeter.Stop(); return; throw new System.Exception("Invalid target property"); } catch (System.Exception ex) { progressMeter.Stop(); editor.WriteMessage("\n" + ex.Message); } }
private void method_0(string string_5) { 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(); ASCIISTL aSCIISTL = new ASCIISTL(); aSCIISTL.Read(string_5); editor.WriteMessage("\nSTL solid name : " + aSCIISTL.SolidName); editor.WriteMessage("\nNumber of triangles read : " + aSCIISTL.NumberOfTrianglesRead.ToString()); editor.WriteMessage("\nNumber of degenerate triangles: " + aSCIISTL.NumberOfDegenerateTriangles.ToString()); editor.WriteMessage("\nHas negative coordinates : " + aSCIISTL.HasNegativeCoordinates.ToString()); editor.WriteMessage("\nInconsistent facet normals : " + aSCIISTL.HasInconsitentNormals.ToString()); editor.WriteMessage("\n"); ObjectId layerId = DBManager.CurrentLayerId(); bool flag = false; string a; if ((a = CMD_STL.string_0) != null) { if (!(a == "S")) { if (!(a == "N")) { if (a == "C") { layerId = DBManager.CurrentLayerId(); } } else { string text = "0"; text = CommandLineQuerries.SpecifyLayerName(text); layerId = DBManager.CreateLayer(text, 7, false, ref flag); } } else { if (aSCIISTL.SolidName.Trim() == "") { aSCIISTL.SolidName = "Unnamed_solid"; } if (!DBManager.ValidateName(aSCIISTL.SolidName)) { return; } layerId = DBManager.CreateLayer(aSCIISTL.SolidName, 256, false, ref flag); editor.WriteMessage("Solid inserted on layer " + aSCIISTL.SolidName); } } 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); progressMeter.SetLimit(aSCIISTL.NumberOfTrianglesRead); progressMeter.Start("Writing database"); for (int i = 0; i < aSCIISTL.Triangles.Count; i++) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } Point3d point3d = new Point3d(aSCIISTL.Triangles[i].Vertex1.X, aSCIISTL.Triangles[i].Vertex1.Y, aSCIISTL.Triangles[i].Vertex1.Z); Point3d point3d2 = new Point3d(aSCIISTL.Triangles[i].Vertex2.X, aSCIISTL.Triangles[i].Vertex2.Y, aSCIISTL.Triangles[i].Vertex2.Z); Point3d point3d3 = new Point3d(aSCIISTL.Triangles[i].Vertex3.X, aSCIISTL.Triangles[i].Vertex3.Y, aSCIISTL.Triangles[i].Vertex3.Z); Face face = new Face(point3d, point3d2, point3d3, true, true, true, true); face.LayerId = (layerId); blockTableRecord.AppendEntity(face); transaction.AddNewlyCreatedDBObject(face, true); } transaction.Commit(); progressMeter.Stop(); } }
internal void genContour2(ObjectId[] objectId_0, CoordinateSystem coordinateSystem_0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); CoordinateSystem coordinateSystem = CoordinateSystem.Global(); try { if (objectId_0 == null) { throw new ArgumentException("No faces selected."); } string layerName = UserCmd.contourLNPrefix + cmd.mydb.Resolution; string assistLayerName = "contour_assist_" + cmd.mydb.Resolution; ObjectId layerId = LayerUtil.CreateLayer(layerName, 127, true, false); ObjectId assistLayerId = LayerUtil.CreateLayer(assistLayerName, 127, true, false); int num = DBManager.SetEpsilon(); int num2 = (int)Convert.ToInt16(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("LUPREC").ToString()); num = Math.Min(num2 + 2, num); List <Triangle> list = Conversions.ToCeometricCADDataTriangleList(objectId_0); if (coordinateSystem_0 != coordinateSystem) { Triangle.TransformCoordinates(list, coordinateSystem, coordinateSystem_0); } else { coordinateSystem_0 = null; } int limit = (int)(Math.Abs(ContourLineComputation.endElevation - ContourLineComputation.startElevation) / ContourLineComputation.spacing); progressMeter.SetLimit(limit); progressMeter.Start("Computing contours"); int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; int num7 = 0; double maxZ = cmd.mydb.TEDicList[cmd.mydb.Resolution].maxMaxZ; double elevation = ContourLineComputation.startElevation; Plane plane = new Plane(new ngeometry.VectorGeometry.Point(0.0, 0.0, elevation), new Vector3d(0.0, 0.0, 1.0)); cmd.mydb.assistContourDics[cmd.mydb.Resolution] = new AssistContourDic(); while (elevation <= ContourLineComputation.endElevation) { if (elevation >= maxZ) { break; } progressMeter.MeterProgress(); messageFilter.CheckMessageFilter(); List <Edge> interEdgeList = this.getInterSection2(list, plane, num3, ref num5, ref num4); if (interEdgeList.Count <= 0) { editor.WriteMessage("\nNo contours at elevation : " + elevation.ToString()); } else { Autodesk.AutoCAD.Geometry.Plane plane1 = new Autodesk.AutoCAD.Geometry.Plane(new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0), new Autodesk.AutoCAD.Geometry.Vector3d(0, 0, 1)); Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal); TransformUtil.Transform(interEdgeList, prjMat1); List <Polyline3d> pline3ds = new List <Polyline3d>(); List <PLine> pllist = DBManager.WritePlinesInDataBase2(interEdgeList, coordinateSystem_0, num, false, layerId, Color.White, pline3ds); cmd.contColorize.addContour(pline3ds, elevation); num6 += pllist.Count; double assistElevation = elevation + spacing / 2; if (assistElevation >= maxZ) { assistElevation = elevation + (maxZ - elevation) / 2; } genAssistContour(list, plane, coordinateSystem_0, assistLayerId, assistElevation, num, num3); num7 += interEdgeList.Count; } elevation += ContourLineComputation.spacing; plane.Point.Z = elevation; num3++; } editor.WriteMessage("\nFailed intersections : " + num5); editor.WriteMessage("\nDegenerate intersections : " + num4); editor.WriteMessage("\nTotal number of segments : " + num7); editor.WriteMessage("\nTotal number of polylines: " + num6); progressMeter.Stop(); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }
private void method_1(ObjectId[] objectId_0, double double_1, ref int int_1, ref int int_2, ref int int_3) { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor arg_15_0 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); progressMeter.SetLimit(objectId_0.Length); progressMeter.Start("Simplifying polylines"); try { 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); for (int i = 0; i < objectId_0.Length; i++) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 10); DBObject @object = transaction.GetObject(objectId_0[i], (OpenMode)1); bool flag = false; Polyline polyline = @object as Polyline; if (polyline != null) { flag = polyline.Closed; } Polyline2d polyline2d = @object as Polyline2d; if (polyline2d != null) { flag = polyline2d.Closed; } Polyline3d polyline3d = @object as Polyline3d; if (polyline3d != null) { flag = polyline3d.Closed; } List <ngeometry.VectorGeometry.Point> p = PointGeneration.SubdividePolyline(@object, transaction, 0.0).ToList(); int_1 += Conversions.GetNumberOfPoyllineVertices(@object); List <ngeometry.VectorGeometry.Point> list = this.method_2(p, double_1); int_2 += list.Count; Point3dCollection point3dCollection = Conversions.ToPoint3dCollection(list); Polyline3d polyline3d2 = new Polyline3d(0, point3dCollection, flag); polyline3d2.SetPropertiesFrom((Entity)@object); if (PLine.string_2 == "N" & [email protected]) { @object.Erase(); } blockTableRecord.AppendEntity(polyline3d2); transaction.AddNewlyCreatedDBObject(polyline3d2, true); } catch (System.Exception ex) { int_3++; } } transaction.Commit(); } progressMeter.Stop(); } catch (System.Exception ex) { progressMeter.Stop(); throw ex; } }
public static void WriteListInDatabase <T>(List <T> entities, CoordinateSystem acutalCS, DBManager.EntityPropertiesAssignment propertyAssignmentMethod, ObjectId layerID, ObjectId blockID, string layerName) { if (entities != null && entities.Count != 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); List <Triangle> triList = new List <Triangle>(); try { blockID = SymbolUtilityServices.GetBlockModelSpaceId(workingDatabase); if (layerName != null) { layerID = LayerUtil.CreateLayer(layerName, 127, false); } else { layerID = ObjectId.Null; } if (typeof(T) != typeof(Triangle)) { throw new NotImplementedException("Generic list type not supported: " + typeof(T).ToString()); } triList = (List <Triangle>)Convert.ChangeType(entities, typeof(List <Triangle>)); if (acutalCS != null) { Conversions.ToWCS(acutalCS, triList); } progressMeter.SetLimit(entities.Count); progressMeter.Start("Writing database"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { LayerTable layerTable = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0); BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockID, (OpenMode)1); for (int i = 0; i < entities.Count; i++) { Autodesk.AutoCAD.Colors.Color color = null; short colorIndex = 256; Point3d point3d3 = new Point3d(triList[i].Vertex1.X, triList[i].Vertex1.Y, triList[i].Vertex1.Z); Point3d point3d4 = new Point3d(triList[i].Vertex2.X, triList[i].Vertex2.Y, triList[i].Vertex2.Z); Point3d point3d5 = new Point3d(triList[i].Vertex3.X, triList[i].Vertex3.Y, triList[i].Vertex3.Z); Entity entity = new Autodesk.AutoCAD.DatabaseServices.Face(point3d3, point3d4, point3d5, true, true, true, true); if (layerID != ObjectId.Null) { entity.LayerId = (layerID); } if (color == null) { entity.ColorIndex = ((int)colorIndex); } else { entity.Color = (color); } blockTableRecord.AppendEntity(entity); transaction.AddNewlyCreatedDBObject(entity, true); progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 10000); } transaction.Commit(); } progressMeter.Stop(); editor.WriteMessage(Environment.NewLine + entities.Count.ToString() + " entities written to database."); editor.WriteMessage("\n"); editor.Regen(); return; } catch { progressMeter.Stop(); throw; } } throw new System.Exception("No entities written in database."); }
private void method_0(ObjectId[] objectId_0, ngeometry.VectorGeometry.Plane plane_0, int int_0) { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor arg_15_0 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); progressMeter.SetLimit(objectId_0.Length); progressMeter.Start("Slicing"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { try { BlockTable arg_5A_0 = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0); for (int i = 0; i < objectId_0.Length; i++) { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); Autodesk.AutoCAD.DatabaseServices.Line line = (Autodesk.AutoCAD.DatabaseServices.Line)transaction.GetObject(objectId_0[i], (OpenMode)0, true); Edge edge = Conversions.ToCeometricEdge(line); double value = edge.StartPoint.DistanceTo(plane_0); double value2 = edge.EndPoint.DistanceTo(plane_0); if (Math.Abs(value) < Global.AbsoluteEpsilon) { value = 0.0; } if (Math.Abs(value2) < Global.AbsoluteEpsilon) { value2 = 0.0; } int num = Math.Sign(value); int num2 = Math.Sign(value2); if (num == num2) { if (num != int_0 && int_0 != 0) { line.UpgradeOpen(); if (!line.IsErased) { line.Erase(); } } } else { Point point = plane_0.method_0(edge.ToLine()); if (!(point == null)) { line.UpgradeOpen(); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(line.BlockId, (OpenMode)1); Point3d point3d = new Point3d(edge.StartPoint.X, edge.StartPoint.Y, edge.StartPoint.Z); Point3d point3d2 = new Point3d(point.X, point.Y, point.Z); Point3d point3d3 = new Point3d(edge.EndPoint.X, edge.EndPoint.Y, edge.EndPoint.Z); if (int_0 == 0) { if (point3d != point3d2) { Autodesk.AutoCAD.DatabaseServices.Line line2 = new Autodesk.AutoCAD.DatabaseServices.Line(point3d, point3d2); line2.SetPropertiesFrom(line); blockTableRecord.AppendEntity(line2); transaction.AddNewlyCreatedDBObject(line2, true); } if (point3d2 != point3d3) { Autodesk.AutoCAD.DatabaseServices.Line line3 = new Autodesk.AutoCAD.DatabaseServices.Line(point3d2, point3d3); line3.SetPropertiesFrom(line); blockTableRecord.AppendEntity(line3); transaction.AddNewlyCreatedDBObject(line3, true); } } else if (Math.Sign(num) == int_0) { Autodesk.AutoCAD.DatabaseServices.Line line4 = new Autodesk.AutoCAD.DatabaseServices.Line(point3d, point3d2); line4.SetPropertiesFrom(line); blockTableRecord.AppendEntity(line4); transaction.AddNewlyCreatedDBObject(line4, true); } else if (Math.Sign(num2) == int_0) { Autodesk.AutoCAD.DatabaseServices.Line line5 = new Autodesk.AutoCAD.DatabaseServices.Line(point3d2, point3d3); line5.SetPropertiesFrom(line); blockTableRecord.AppendEntity(line5); transaction.AddNewlyCreatedDBObject(line5, true); } if (!line.IsErased) { line.Erase(); } } } } transaction.Commit(); progressMeter.Stop(); } catch (System.Exception ex) { progressMeter.Stop(); throw ex; } } }
private void method_1(ObjectId[] objectId_0, ngeometry.VectorGeometry.Plane plane_0, int int_0, bool bool_0, ref int int_1, ref int int_2, ref int int_3) { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor arg_15_0 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); DBManager.SetEpsilon(); List <ObjectId> list = new List <ObjectId>(); for (int i = 0; i < objectId_0.Length; i++) { list.Add(objectId_0[i]); } progressMeter.SetLimit(list.Count); progressMeter.Start("Slicing"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable arg_90_0 = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0); for (int j = 0; j < list.Count; j++) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)j, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } Face face = (Face)transaction.GetObject(list[j], (OpenMode)0, true); try { Point3d vertexAt = face.GetVertexAt(0); Point3d vertexAt2 = face.GetVertexAt(1); Point3d vertexAt3 = face.GetVertexAt(2); Point3d vertexAt4 = face.GetVertexAt(3); Point point = new Point(vertexAt.X, vertexAt.Y, vertexAt.Z); Point point2 = new Point(vertexAt2.X, vertexAt2.Y, vertexAt2.Z); Point point3 = new Point(vertexAt3.X, vertexAt3.Y, vertexAt3.Z); Point point4 = new Point(vertexAt4.X, vertexAt4.Y, vertexAt4.Z); double value = point.DistanceTo(plane_0); double value2 = point2.DistanceTo(plane_0); double value3 = point3.DistanceTo(plane_0); double value4 = point4.DistanceTo(plane_0); if (Math.Abs(value) < Global.AbsoluteEpsilon) { value = 0.0; } if (Math.Abs(value2) < Global.AbsoluteEpsilon) { value2 = 0.0; } if (Math.Abs(value3) < Global.AbsoluteEpsilon) { value3 = 0.0; } if (Math.Abs(value4) < Global.AbsoluteEpsilon) { value4 = 0.0; } int num = Math.Sign(value); int num2 = Math.Sign(value2); int num3 = Math.Sign(value3); int num4 = Math.Sign(value4); if (num == num2 && num2 == num3 && num3 == num4) { if (num == 0 && bool_0) { int_3++; } else if (num != int_0 && int_0 != 0) { face.UpgradeOpen(); if (!face.IsErased) { face.Erase(); } } else { int_3++; } } else if (point != point2 && point != point3 && point != point4 && point2 != point3 && point2 != point4 && point3 != point4) { BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(face.BlockId, (OpenMode)1); face.UpgradeOpen(); Face face2 = new Face(vertexAt, vertexAt2, vertexAt4, true, true, true, true); face2.SetPropertiesFrom(face); blockTableRecord.AppendEntity(face2); transaction.AddNewlyCreatedDBObject(face2, true); list.Add(face2.ObjectId); Face face3 = new Face(vertexAt2, vertexAt3, vertexAt4, true, true, true, true); face3.SetPropertiesFrom(face); blockTableRecord.AppendEntity(face3); transaction.AddNewlyCreatedDBObject(face3, true); list.Add(face3.ObjectId); if (!face.IsErased) { face.Erase(); } } else { Triangle triangle = new Triangle(); if (point != point2 && point != point3 && point2 != point3) { triangle = new Triangle(point, point2, point3); } else if (point != point2 && point != point4 && point2 != point4) { triangle = new Triangle(point, point2, point4); } else { if (!(point != point3) || !(point != point4) || !(point3 != point4)) { throw new ArithmeticException("Failed to construct triangle from 3d face."); } triangle = new Triangle(point, point3, point4); } List <Triangle> list2 = new List <Triangle>(); if (int_0 == 0) { list2 = triangle.Slice(plane_0, Triangle.SliceMethod.KeepBoth, bool_0); } else if (int_0 == 1) { list2 = triangle.Slice(plane_0, Triangle.SliceMethod.KeepAbove, bool_0); } else if (int_0 == -1) { list2 = triangle.Slice(plane_0, Triangle.SliceMethod.KeepBelow, bool_0); } BlockTableRecord blockTableRecord2 = (BlockTableRecord)transaction.GetObject(face.BlockId, (OpenMode)1); face.UpgradeOpen(); for (int k = 0; k < list2.Count; k++) { Triangle triangle2 = list2[k]; Point3d point3d = new Point3d(triangle2.Vertex1.X, triangle2.Vertex1.Y, triangle2.Vertex1.Z); Point3d point3d2 = new Point3d(triangle2.Vertex2.X, triangle2.Vertex2.Y, triangle2.Vertex2.Z); Point3d point3d3 = new Point3d(triangle2.Vertex3.X, triangle2.Vertex3.Y, triangle2.Vertex3.Z); Face face4 = new Face(point3d, point3d2, point3d3, true, true, true, true); face4.SetPropertiesFrom(face); blockTableRecord2.AppendEntity(face4); transaction.AddNewlyCreatedDBObject(face4, true); int_3++; } if (!face.IsErased) { face.Erase(); } int_1++; } } catch (System.Exception ex) { int_2++; } finally { face.Dispose(); } } transaction.Commit(); } progressMeter.Stop(); Global.ResumeEpsilon(); }
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); }
private void method_4() { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; string value = IO2.AutoDetermineDelimiter(IO2.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(IO2.string_4)) { while (streamReader.Peek() >= 0) { streamReader.ReadLine(); num++; } } ProgressMeter progressMeter = new ProgressMeter(); progressMeter.SetLimit(num); progressMeter.Start("Reading XYZ"); try { CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(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(IO2.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; } }
public static List <PLine> ConstructFromUnorderedSegments(List <Edge> unorderedEdges, int relevantDecimals, ref int numberOfPLines, ref int numberOfSegments, ref int zeroLength, bool writeDatabase, bool useProgressMeter, bool eliminateZeroLengthSegments) { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); List <PLine> list = new List <PLine>(); PLine.edgeVertexList = new EdgeVertexList(); if (useProgressMeter) { ProgressMeter arg_44_0 = progressMeter; int arg_44_1 = unorderedEdges.Count; //int arg_43_0 = unorderedEdges.Count; arg_44_0.SetLimit(arg_44_1); } if (useProgressMeter) { progressMeter.Start("Processing lines"); } List <PLine> result; try { //"0." + "".PadLeft(relevantDecimals, '0'); for (int i = 0; i < unorderedEdges.Count; i++) { if (useProgressMeter && i % 100 == 0) { progressMeter.MeterProgress(); } Edge edge = unorderedEdges[i]; edge.Round(relevantDecimals); PLine.edgeVertexList.Add(edge); } for (int j = 0; j < unorderedEdges.Count; j++) { if (useProgressMeter) { progressMeter.MeterProgress(); } messageFilter.CheckMessageFilter((long)j, 100); if (unorderedEdges[j].Status == Edge.EdgeStatus.NotDefined) { PLine pLine = new PLine(); pLine.caddata = unorderedEdges[j].CADData; List <Edge> list2 = PLine.smethod_0(unorderedEdges[j], pLine); pLine.AddRange(list2); pLine.Add(unorderedEdges[j]); unorderedEdges[j].Status = Edge.EdgeStatus.NotDefined; List <Edge> list3 = PLine.smethod_1(unorderedEdges[j], pLine); pLine.AddRange(list3); double num = Math.Pow(10.0, (double)(-(double)relevantDecimals)); int num2 = 0; if (pLine.Count == 1 && pLine[0].Length < num) { zeroLength++; num2++; if (eliminateZeroLengthSegments) { //goto IL_231; continue; } } else { for (int k = pLine.Count - 2; k >= 0; k--) { if (pLine[k].Length < num) { if (eliminateZeroLengthSegments) { pLine[k + 1].StartPoint = pLine[k].StartPoint; pLine.RemoveAt(k); } zeroLength++; num2++; } } } if (pLine.Count != 0) { List <PLine> pllist = PLine.splitSelfIntersectionPline(pLine); for (int ii = 0; ii < pllist.Count; ii++) { list.Add(pllist[ii]); if (writeDatabase) { PLine.WriteInDatabase(pllist[ii]); } } //list.Add(pLine); if (!eliminateZeroLengthSegments) { num2 = 0; } numberOfSegments += list2.Count + list3.Count - num2 + 1; numberOfPLines++; /*if (writeDatabase) * { * PLine.WriteInDatabase(pLine); * }*/ } } //IL_231:; } if (useProgressMeter) { progressMeter.Stop(); } result = list; } catch (System.Exception ex) { if (useProgressMeter) { progressMeter.Stop(); } throw; } return(result); }
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 { CoordinateTransformator2 coordinateTransformator = new CoordinateTransformator2(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(IO2.string_5)) { streamWriter.WriteLine(string.Concat(new object[] { "C ", IO2.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 ", IO2.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 ", IO2.string_5, ".\nIncrease the column width and/or decrease the number of decimal digits." })); } FileInfo fileInfo = new FileInfo(IO2.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; } }
internal void genContour(ObjectId[] objectId_0, CoordinateSystem coordinateSystem_0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); CoordinateSystem coordinateSystem = CoordinateSystem.Global(); try { if (objectId_0 == null) { throw new ArgumentException("No faces selected."); } int num = DBManager.SetEpsilon(); int num2 = (int)Convert.ToInt16(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("LUPREC").ToString()); num = Math.Min(num2 + 2, num); List <Triangle> list = Conversions.ToCeometricCADDataTriangleList(objectId_0); if (coordinateSystem_0 != coordinateSystem) { Triangle.TransformCoordinates(list, coordinateSystem, coordinateSystem_0); } else { coordinateSystem_0 = null; } int limit = (int)(Math.Abs(ContourLineComputation.endElevation - ContourLineComputation.startElevation) / ContourLineComputation.spacing); progressMeter.SetLimit(limit); progressMeter.Start("Computing contours"); int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; int num7 = 0; double num8 = ContourLineComputation.startElevation; Plane plane = new Plane(new ngeometry.VectorGeometry.Point(0.0, 0.0, ContourLineComputation.startElevation), new Vector3d(0.0, 0.0, 1.0)); while (num8 <= ContourLineComputation.endElevation) { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter(); List <Edge> interEdgeList = this.getInterSection(list, plane, num3, ref num5, ref num4); num6 += DBManager.WritePlinesInDataBase(interEdgeList, coordinateSystem_0, num, false); if (interEdgeList.Count == 0) { editor.WriteMessage("\nNo contours at elevation : " + num8.ToString()); } num7 += interEdgeList.Count; plane.Point.Z = num8; num8 += ContourLineComputation.spacing; num3++; } editor.WriteMessage("\nFailed intersections : " + num5); editor.WriteMessage("\nDegenerate intersections : " + num4); editor.WriteMessage("\nTotal number of segments : " + num7); editor.WriteMessage("\nTotal number of polylines: " + num6); progressMeter.Stop(); } catch (System.Exception ex) { progressMeter.Stop(); throw; } }