private int getPolylineCount(ObjectId[] objectId_0) { int num = 0; if (objectId_0 != null) { using (Transaction transaction = this.database_0.TransactionManager.StartTransaction()) { for (int i = 0; i < objectId_0.Length; i++) { DBObject @object = transaction.GetObject(objectId_0[i], (OpenMode)0); Polyline2d polyline2d = @object as Polyline2d; Polyline polyline = @object as Polyline; Polyline3d polyline3d = @object as Polyline3d; if (polyline2d != null) { if (!polyline2d.Closed) { throw new ArgumentException("At least one boundary polyline is not closed.\n"); } double num2 = 0.0; List <Edge> list = Conversions.ToCeometricEdgeList(polyline2d); for (int j = 0; j < list.Count; j++) { num2 += list[j].Length; } double distanceAtParameter = polyline2d.GetDistanceAtParameter(polyline2d.EndParam); if (!Global.AlmostEquals(num2, distanceAtParameter)) { throw new System.Exception("At least one boundary polyline contains curved segments. Decurve the polyline first.\n"); } num++; } else if (polyline != null) { if (!polyline.Closed) { throw new ArgumentException("At least one boundary polyline is not closed.\n"); } if (!polyline.IsOnlyLines) { throw new System.Exception("At least one boundary polyline contains curved segments. Decurve the polyline first.\n"); } num++; } else { if (!(polyline3d != null)) { throw new ArgumentException("Invalid polyline object: " + @object.Handle.ToString() + "\nObject type: " + @object.GetType().ToString()); } if (!polyline3d.Closed) { throw new ArgumentException("At least one boundary polyline is not closed.\n"); } double num3 = 0.0; List <Edge> list2 = Conversions.ToCeometricEdgeList(polyline3d); for (int k = 0; k < list2.Count; k++) { num3 += list2[k].Length; } double distanceAtParameter2 = polyline3d.GetDistanceAtParameter(polyline3d.EndParam); if (!Global.AlmostEquals(num3, distanceAtParameter2)) { throw new System.Exception("At least one boundary polyline contains curved segments. Decurve the polyline first.\n"); } num++; } } } } return(num); }
public void UserInterface() { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; this.messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(this.messageFilter); try { PointSet pointSet = new PointSet(); ObjectId[] objectIDs = CommandLineQuerries.GetObjectIDs(CommandLineQuerries.EntityType.POINT, "Select triangulation points", false); if (objectIDs != null) { string text = " triangulation point"; if (objectIDs.Length > 1) { text += "s"; } editor.WriteMessage(objectIDs.Length + text + " selected."); pointSet.Add2(Conversions.ToCeometricPointSet2(objectIDs)); } else { editor.WriteMessage("No triangulation points selected.\n"); } List <Constraint> list = new List <Constraint>(); ObjectId[] objectIDs2 = CommandLineQuerries.GetObjectIDs(CommandLineQuerries.EntityType.LINE, "Select constraints (lines)", false); if (objectIDs2 != null) { string text2 = " constraint"; if (objectIDs2.Length > 1) { text2 += "s"; } editor.WriteMessage(objectIDs2.Length + text2 + " selected."); List <Edge> list2 = Conversions.ToCeometricEdgeList(objectIDs2); for (int i = 0; i < list2.Count; i++) { list.Add(new Constraint(list2[i], Constraint.ConstraintType.Constraint)); } } else { editor.WriteMessage("No constraints selected.\n"); } if (pointSet.Count == 0 && list.Count == 0) { throw new ArgumentException("No triangulation points nor constraints."); } List <Constraint> bo = new List <Constraint>(); int plCount = 0; ObjectId[] objectIDs3 = CommandLineQuerries.GetObjectIDs(CommandLineQuerries.EntityType.PLINES, "Select boundaries (polylines)", false); if (objectIDs3 != null) { string text3 = " boundary"; if (objectIDs3.Length > 1) { text3 += "s"; } editor.WriteMessage(objectIDs3.Length + text3 + " selected."); plCount = this.getPolylineCount(objectIDs3); List <Edge> list4 = Conversions.ToCeometricEdgeList(objectIDs3); for (int j = 0; j < list4.Count; j++) { bo.Add(new Constraint(list4[j], Constraint.ConstraintType.Boundary)); } } else { editor.WriteMessage("No boundaries selected.\n"); } if (list.Count > 0) { Triangulate.int_0 = CommandLineQuerries.SpecifyInteger("Maximum feasible constraint violations", Triangulate.int_0, 0, 2147483647, false, true); } editor.WriteMessage("\nInitial triangulation:"); editor.WriteMessage("\n----------------------"); editor.WriteMessage("\nInitial triangulation points : " + pointSet.Count); editor.WriteMessage("\nInitial constraints : " + list.Count); editor.WriteMessage("\nNumber of boundary regions : " + plCount); editor.WriteMessage("\nInitial boundary segments : " + bo.Count); editor.WriteMessage("\n"); this.TriangulateInternal(pointSet, list, bo, null); } catch (System.Exception ex) { editor.WriteMessage("\n" + ex.Message); } finally { try { this.progressMeter_0.Stop(); } catch (System.Exception ex) { Console.WriteLine("feef"); } try { this.pane_0.Text = (""); this.pane_0.Visible = (false); Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.Update(); Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.Panes.Remove(this.pane_0); } catch (System.Exception ex) { Console.WriteLine("efefe"); } System.Windows.Forms.Application.DoEvents(); } }
public void Reconstruct(ObjectId[] objectId_0) { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; List <Edge> list = Conversions.ToCeometricAcDbEdgeList(objectId_0); List <List <Edge> > list2 = new List <List <Edge> >(); if (CMD_ReconstructSurface.string_0 == "L") { list2 = this.method_0(list); } else { list2.Add(list); } ProgressMeter progressMeter = new ProgressMeter(); try { for (int i = 0; i < list2.Count; i++) { List <Edge> list3 = list2[i]; SurfaceReconstruction surfaceReconstruction = new SurfaceReconstruction(list3); surfaceReconstruction.ReconstructSurface(progressMeter, CMD_ReconstructSurface.int_0); List <SurfaceReconstruction.Tri> tris = surfaceReconstruction.Tris; List <SurfaceReconstruction.Quad> quads = surfaceReconstruction.Quads; 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); string str = "0"; if (CMD_ReconstructSurface.string_1 == "A" || CMD_ReconstructSurface.string_1 == "T") { for (int j = 0; j < tris.Count; j++) { Face acadFace = surfaceReconstruction.GetAcadFace(tris[j]); if (CMD_ReconstructSurface.string_0 == "L") { acadFace.SetPropertiesFrom(list3[0].AcDbLine); } blockTableRecord.AppendEntity(acadFace); transaction.AddNewlyCreatedDBObject(acadFace, true); } } if (CMD_ReconstructSurface.string_1 == "A" || CMD_ReconstructSurface.string_1 == "Q") { for (int k = 0; k < quads.Count; k++) { Face acadFace2 = surfaceReconstruction.GetAcadFace(quads[k]); if (CMD_ReconstructSurface.string_0 == "L") { acadFace2.SetPropertiesFrom(list3[0].AcDbLine); } blockTableRecord.AppendEntity(acadFace2); transaction.AddNewlyCreatedDBObject(acadFace2, true); } } if (tris.Count > 0) { str = DBManager.GetLayerName(list3[0].AcDbLine.LayerId); } if (quads.Count > 0) { str = DBManager.GetLayerName(list3[0].AcDbLine.LayerId); } if (CMD_ReconstructSurface.string_0 == "C") { str = DBManager.CurrentLayerName(); } transaction.Commit(); editor.WriteMessage("\n"); editor.WriteMessage("\nLayer : " + str); editor.WriteMessage("\nNumber of edges : " + list3.Count); editor.WriteMessage("\nNumber of triangular faces created: " + tris.Count); editor.WriteMessage("\nNumber of quad faces created : " + quads.Count); } } } catch (System.Exception ex) { progressMeter.Stop(); throw; } }