private void AddAreaAndPerimetr() { AcDb.Polyline2d borderParcel = ServiceSimpleElements.CreatePolyline2d(this.Parcel.Points, true); AcDb.MText oMText = new AcDb.MText(); oMText.TextHeight = 2.5 * this.SettingsForm.ScaleDrawing; oMText.Attachment = AcDb.AttachmentPoint.MiddleCenter; if (SettingsForm.DisplayArea && SettingsForm.UnitArea) { oMText.Contents = borderParcel.Area.ToString("Площа ділянки: S=0.00") + " кв.м"; } else if (SettingsForm.DisplayArea && !SettingsForm.UnitArea) { oMText.Contents = (borderParcel.Area / 10000).ToString("Всього: 0.0000") + " га"; } if (SettingsForm.DisplayPerimeter) { oMText.Contents = oMText.Contents + "\n" + borderParcel.Length.ToString("Периметр: 0.00") + " м"; } if (SettingsForm.DisplayArea || SettingsForm.UnitArea) { oMText.Contents = oMText.Contents.Replace(',', '.'); } ServiceSimpleElements.ManualInsertMText(oMText); }
private AcDb.ObjectId AddBorders() { AcDb.Polyline2d borderParcel = ServiceSimpleElements.CreatePolyline2d(this.Parcel.Points, true); borderParcel.LayerId = ServiceCAD.CreateLayer(settingsDrawing.Plan.FillParcel.Layer); AcDb.ObjectId idBorderParcel = ServiceCAD.InsertObject(borderParcel); AcDb.ResultBuffer xData = new AcDb.ResultBuffer(); int dxfCode; AcDb.TypedValue typedValue; dxfCode = (int)AcDb.DxfCode.ExtendedDataRegAppName; typedValue = new AcDb.TypedValue(dxfCode, "Земельна ділянка"); xData.Add(typedValue); foreach (LandInfo infoValue in this.Parcel.Info) { dxfCode = (int)AcDb.DxfCode.ExtendedDataAsciiString; typedValue = new AcDb.TypedValue(dxfCode, "<" + infoValue.Key + "> " + infoValue.Value); xData.Add(typedValue); } ServiceCAD.SetXData(idBorderParcel, xData); return(idBorderParcel); }
public static AcDb.Polyline2d CreatePolyline2d(AcGe.Point2dCollection points, bool isClosed) { AcDb.Polyline2d polyLine2d = new AcDb.Polyline2d(); AcDb.Vertex2d vertex; foreach (AcGe.Point2d point in points) { vertex = new AcDb.Vertex2d(new AcGe.Point3d(point.X, point.Y, 0), 0, 0, 0, 0); polyLine2d.AppendVertex(vertex); polyLine2d.Closed = isClosed; } return(polyLine2d); }
private static bool PolyInPoly(_AcDb.TransactionManager tm, _AcDb.ObjectId oid, _AcDb.ObjectId elFG) { using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false)) { using (_AcDb.DBObject pElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false)) { if (pEntity is _AcDb.Polyline2d) { _AcDb.Polyline2d oldPolyline = (_AcDb.Polyline2d)pEntity; foreach (_AcDb.ObjectId Vertex2d in oldPolyline) { using (_AcDb.DBObject dbobj = tm.GetObject(Vertex2d, _AcDb.OpenMode.ForRead, false)) { _AcDb.Vertex2d vertex = dbobj as _AcDb.Vertex2d; if (vertex == null) { string msg = string.Format(CultureInfo.CurrentCulture, "Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", oldPolyline.Handle.ToString(), dbobj.GetType().ToString()); throw new InvalidOperationException(string.Format(msg)); } _AcGe.Point3d vertexPoint = oldPolyline.VertexPosition(vertex); if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG)) { return(false); } } } return(true); } else if (pEntity is _AcDb.Polyline3d) { _AcDb.Polyline3d poly3d = (_AcDb.Polyline3d)pEntity; foreach (_AcDb.ObjectId Vertex3d in poly3d) { using (_AcDb.DBObject dbobj = tm.GetObject(Vertex3d, _AcDb.OpenMode.ForRead, false)) { _AcDb.PolylineVertex3d vertex = dbobj as _AcDb.PolylineVertex3d; if (vertex == null) { string msg = string.Format(CultureInfo.CurrentCulture, "3D-Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", poly3d.Handle.ToString(), dbobj.GetType().ToString()); throw new InvalidOperationException(string.Format(msg)); } _AcGe.Point3d vertexPoint = vertex.Position; if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG)) { return(false); } } } return(true); } else if (pEntity is _AcDb.Polyline) { _AcDb.Polyline poly = pEntity as _AcDb.Polyline; for (int i = 0; i < poly.NumberOfVertices; i++) { _AcGe.Point3d vertexPoint = poly.GetPoint3dAt(i); if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG)) { return(false); } } return(true); } } } return(false); }
private void AddFills() { Dictionary <string, HatchPolygon> listMissingHatch = new Dictionary <string, HatchPolygon>(); // // Parcel // if (SettingsForm.DisplayFillParcel) { AcDb.Polyline2d borderParcel = ServiceSimpleElements.CreatePolyline2d(this.Parcel.Points, true); AcDb.ObjectId idBorderParcel = ServiceCAD.InsertObject(borderParcel); AcDb.Hatch borderParcelHatch = ServiceSimpleElements.CreateHatch(idBorderParcel, true); HatchPolygon hatchParcel = HatchPolygon.GetHatchParcel(); if (hatchParcel != null) { borderParcelHatch.LayerId = ServiceCAD.CreateLayer(settingsDrawing.Plan.FillParcel.Layer); borderParcelHatch.ColorIndex = hatchParcel.ColorIndex; borderParcelHatch.SetHatchPattern(hatchParcel.Pattern.Type, hatchParcel.Pattern.Name); borderParcelHatch.PatternAngle = hatchParcel.Pattern.Angle; borderParcelHatch.PatternSpace = hatchParcel.Pattern.Space; AcDb.ObjectId idborderParcelHatch = ServiceCAD.InsertObject(borderParcelHatch); } else { try { listMissingHatch.Add("Parcel", new HatchPolygon("Parcel", "", 0, PatternHatch.DEFAULT)); CurrentCAD.Editor.WriteMessage("\n<!> Незнайдено штриховка Parcel;"); } catch { } } } // // Lands // AcDb.Polyline2d borderLand; AcDb.ObjectId idLand; AcDb.Hatch hatchLand; AcDb.ObjectId idHatchLand; if (SettingsForm.DisplayFillLand) { foreach (LandPolygon poligon in this.Parcel.Lands) { borderLand = ServiceSimpleElements.CreatePolyline2d(poligon.Points, true); borderLand.LayerId = ServiceCAD.CreateLayer(settingsDrawing.Plan.FillLand.Layer); idLand = ServiceCAD.InsertObject(borderLand); hatchLand = ServiceSimpleElements.CreateHatch(idLand, false); HatchPolygon hatch = HatchPolygon.GetHatchLand(poligon); if (hatch != null) { hatchLand.LayerId = ServiceCAD.CreateLayer(settingsDrawing.Plan.FillLand.Layer); hatchLand.ColorIndex = hatch.ColorIndex; hatchLand.SetHatchPattern(hatch.Pattern.Type, hatch.Pattern.Name); hatchLand.PatternAngle = hatch.Pattern.Angle; hatchLand.PatternSpace = hatch.Pattern.Space; idHatchLand = ServiceCAD.InsertObject(hatchLand); } else { string type = "000.00"; try { type = poligon.FindInfo("CC").Value; } catch { string ci = "*"; string cn = "*"; try { LandInfo infoCI = poligon.FindInfo("CI"); ci = infoCI.Value; } catch { } try { LandInfo infoCN = poligon.FindInfo("CN"); cn = infoCN.Value; } catch { } CurrentCAD.Editor.WriteMessage ("\n<!> Незнайдено поле CC угіддя CI = {0}, CN = {1};", ci, cn); } try { listMissingHatch.Add(type, new HatchPolygon(type, "", 0, PatternHatch.DEFAULT)); CurrentCAD.Editor.WriteMessage ("\n<!> Незнайдено CC = {0};", poligon.FindInfo("CC").Value ); } catch { } } } } // // Limiting // if (SettingsForm.DisplayFillLimiting) { foreach (LandPolygon poligon in this.Parcel.Limiting) { borderLand = ServiceSimpleElements.CreatePolyline2d(poligon.Points, true); borderLand.LayerId = ServiceCAD.CreateLayer(settingsDrawing.Plan.FillLimiting.Layer); idLand = ServiceCAD.InsertObject(borderLand); hatchLand = ServiceSimpleElements.CreateHatch(idLand, false); HatchPolygon hatchLimiting = HatchPolygon.GetHatchLimiting(poligon); if (hatchLimiting != null) { hatchLand.LayerId = ServiceCAD.CreateLayer(settingsDrawing.Plan.FillLimiting.Layer); hatchLand.ColorIndex = hatchLimiting.ColorIndex; hatchLand.SetHatchPattern(hatchLimiting.Pattern.Type, hatchLimiting.Pattern.Name); hatchLand.PatternAngle = hatchLimiting.Pattern.Angle; hatchLand.PatternSpace = hatchLimiting.Pattern.Space; idHatchLand = ServiceCAD.InsertObject(hatchLand); } else { string type = poligon.FindInfo("OK").Value; string name = poligon.FindInfo("OX").Value; try { listMissingHatch.Add((type + name), new HatchPolygon(type, name, 0, PatternHatch.DEFAULT)); CurrentCAD.Editor.WriteMessage ("\n<!> Незнайдено OK = {0}, OX = {1};", poligon.FindInfo("OK").Value, poligon.FindInfo("OX").Value ); } catch { } } } } if (listMissingHatch.Count > 0) { List <HatchPolygon> listForXml = new List <HatchPolygon>(); foreach (KeyValuePair <string, HatchPolygon> hp in listMissingHatch) { listForXml.Add(hp.Value); } listMissingHatch.Clear(); CurrentCAD.Editor.WriteMessage("\n\n<!> Побудова плана ділянки\n<!> Не визначено штриховку: \n"); CurrentCAD.Editor.WriteMessage(ServiceXml.GetStringXml <List <HatchPolygon> >(listForXml)); CurrentCAD.Editor.WriteMessage("\n<!>\n"); } }
/// <summary> /// Створює коллекцію текстових обектів значень данних таблиці обмежень земельної ділянки. /// </summary> /// <param name="parcel">Ділянка, що є вихідною для таблиці.</param> /// <param name="settingTable">Налаштування таблиці.</param> /// <returns> /// Повертає <see cref="T:AcDb.DBObjectCollection"/>, що містить текстові значення данний таблиці обмежень земельної ділянки. /// </returns> internal static AcDb.DBObjectCollection GetDataTableLimiting(LandParcel parcel, SettingTable settingTable) { AcDb.DBObjectCollection objects = new AcDb.DBObjectCollection(); AcDb.MText valueMText; AcGe.Point3d insertPoint; AcDb.Line lineRows; LandPolygon polygonLimiting; double steepRow = settingTable.TextHeight * 6; double heightTable = settingTable.GetHeightCapTable() * -1; List <HatchPolygon> listMissingHatch = new List <HatchPolygon>(); for (int index = 0; index < parcel.Limiting.Count; index++) { polygonLimiting = parcel.Limiting.ToArray()[index]; double colWidth = 0; if (index > 0) { lineRows = new AcDb.Line( new AcGe.Point3d(0, heightTable, 0), new AcGe.Point3d(settingTable.GetWidthTable(), heightTable, 0)); objects.Add(lineRows); } heightTable -= steepRow; foreach (ColumnTable col in settingTable.Columns) { colWidth += col.Width; insertPoint = new AcGe.Point3d(); insertPoint = new AcGe.Point3d(colWidth - col.Width / 2, (heightTable + steepRow / 2), 0); valueMText = new AcDb.MText(); valueMText.Width = col.Width * 0.9; valueMText.TextHeight = settingTable.TextHeight; valueMText.LineSpaceDistance = settingTable.TextHeight * 1.5; valueMText.Attachment = AcDb.AttachmentPoint.MiddleCenter; valueMText.Location = insertPoint; if (col.Format.IndexOf("LegendLimiting") > -1) { AcGe.Point2dCollection pointsHatch = new AcGe.Point2dCollection(new AcGe.Point2d[] { new AcGe.Point2d(insertPoint.X - col.Width / 2 + 2, heightTable + steepRow - 2), new AcGe.Point2d(insertPoint.X - col.Width / 2 + 2, heightTable + 2), new AcGe.Point2d(insertPoint.X - col.Width / 2 + col.Width - 2, heightTable + 2), new AcGe.Point2d(insertPoint.X - col.Width / 2 + col.Width - 2, heightTable + steepRow - 2) }); AcDb.Polyline2d polylineLimiting = ServiceSimpleElements.CreatePolyline2d(pointsHatch, true); AcDb.Hatch hatch = ServiceSimpleElements.CreateHatch(ServiceCAD.InsertObject(polylineLimiting), true); HatchPolygon hatchLimiting = HatchPolygon.GetHatchLimiting(polygonLimiting); if (hatchLimiting != null) { hatch.ColorIndex = hatchLimiting.ColorIndex; hatch.SetHatchPattern(AcDb.HatchPatternType.UserDefined, hatchLimiting.Pattern.Name); hatch.PatternAngle = hatchLimiting.Pattern.Angle; hatch.PatternSpace = hatchLimiting.Pattern.Space; } else { string type = polygonLimiting.FindInfo("OK").Value; string name = polygonLimiting.FindInfo("OX").Value; listMissingHatch.Add(new HatchPolygon(type, name, 0, PatternHatch.DEFAULT)); } objects.Add(hatch); polylineLimiting = ServiceSimpleElements.CreatePolyline2d(pointsHatch, true); objects.Add(polylineLimiting); } else if (col.Format.IndexOf("CodeLimiting") > -1) { valueMText.Contents = polygonLimiting.FindInfo("OK").Value; objects.Add(valueMText); } else if (col.Format.IndexOf("NameLimiting") > -1) { valueMText.Contents = polygonLimiting.FindInfo("OX").Value; objects.Add(valueMText); } else if (col.Format.IndexOf("LegalActsLimiting") > -1) { valueMText.Contents = polygonLimiting.FindInfo("OD").Value; objects.Add(valueMText); } else if (col.Format.IndexOf("AreaLimiting") > -1) { double area = Convert.ToDouble(polygonLimiting.FindInfo("AO").Value.Replace(".", ",")); valueMText.Contents = (area / 10000).ToString("0.0000").Replace(",", ".");; objects.Add(valueMText); } } } if (listMissingHatch.Count > 0) { CurrentCAD.Editor.WriteMessage("\n\nПобудова таблиці омеженнь\n Не визначено штриховку: \n"); CurrentCAD.Editor.WriteMessage(ServiceXml.GetStringXml <List <HatchPolygon> >(listMissingHatch)); } return(objects); }
private static bool PolyInPoly(_AcDb.Transaction tm, _AcDb.Entity inner, _AcDb.Entity outer) { if (inner == outer) { return(false); } if (!OverlapExtents(inner, outer)) { return(false); } NrOfOverlaps++; if (inner is _AcDb.Polyline) { _AcDb.Polyline poly = inner as _AcDb.Polyline; for (int i = 0; i < poly.NumberOfVertices; i++) { _AcGe.Point3d vertexPoint = poly.GetPoint3dAt(i); if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer)) { return(false); } } return(true); } else if (inner is _AcDb.Polyline2d) { _AcDb.Polyline2d oldPolyline = (_AcDb.Polyline2d)inner; foreach (_AcDb.ObjectId Vertex2d in oldPolyline) { using (_AcDb.DBObject dbobj = tm.GetObject(Vertex2d, _AcDb.OpenMode.ForRead, false)) { _AcDb.Vertex2d vertex = dbobj as _AcDb.Vertex2d; if (vertex == null) { string msg = string.Format(CultureInfo.CurrentCulture, "Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", oldPolyline.Handle.ToString(), dbobj.GetType().ToString()); throw new InvalidOperationException(string.Format(msg)); } _AcGe.Point3d vertexPoint = oldPolyline.VertexPosition(vertex); if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer)) { return(false); } } } return(true); } else if (inner is _AcDb.Polyline3d) { _AcDb.Polyline3d poly3d = (_AcDb.Polyline3d)inner; foreach (_AcDb.ObjectId Vertex3d in poly3d) { using (_AcDb.DBObject dbobj = tm.GetObject(Vertex3d, _AcDb.OpenMode.ForRead, false)) { _AcDb.PolylineVertex3d vertex = dbobj as _AcDb.PolylineVertex3d; if (vertex == null) { string msg = string.Format(CultureInfo.CurrentCulture, "3D-Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", poly3d.Handle.ToString(), dbobj.GetType().ToString()); throw new InvalidOperationException(string.Format(msg)); } _AcGe.Point3d vertexPoint = vertex.Position; if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)outer)) { return(false); } } } return(true); } throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unknown entitytype '{0}'!", inner.GetType().Name)); }