// Helper functions to zoom using different techniques // Zoom using a view object private static void ZoomWin( _AcEd.Editor ed, _AcGe.Point3d min, _AcGe.Point3d max ) { _AcGe.Point2d min2d = new _AcGe.Point2d(min.X, min.Y); _AcGe.Point2d max2d = new _AcGe.Point2d(max.X, max.Y); _AcDb.ViewTableRecord view = new _AcDb.ViewTableRecord(); view.CenterPoint = min2d + ((max2d - min2d) / 2.0); view.Height = max2d.Y - min2d.Y; view.Width = max2d.X - min2d.X; ed.SetCurrentView(view); }
public static List <NeighborsSegment> FindNeighborSegments ( List <NeighborsSegment> segments, AcGe.Point2d point ) { if (segments == null) { return(new List <NeighborsSegment>()); } try { return(segments.FindAll ( delegate(NeighborsSegment segment) { return segment.MediumPoint.Equals(point); } )); } catch (NullReferenceException) { return(new List <NeighborsSegment>()); } }
private void createX(_Db.BlockTableRecord btr, double radius, _Ge.Point3d ip) { _Ge.Point2d p1 = new _Ge.Point2d(ip.X - radius, ip.Y); _Ge.Point2d p2 = new _Ge.Point2d(ip.X + radius, ip.Y); _Ge.Point2d p3 = new _Ge.Point2d(ip.X, ip.Y - radius); _Ge.Point2d p4 = new _Ge.Point2d(ip.X, ip.Y + radius); using (_Db.Polyline poly = new _Db.Polyline()) { poly.AddVertexAt(0, p1, 0, 0, 0); poly.AddVertexAt(1, p2, 0, 0, 0); poly.ColorIndex = 2; btr.AppendEntity(poly); _c.trans.AddNewlyCreatedDBObject(poly, true); } using (_Db.Polyline poly = new _Db.Polyline()) { poly.AddVertexAt(0, p3, 0, 0, 0); poly.AddVertexAt(1, p4, 0, 0, 0); poly.ColorIndex = 2; btr.AppendEntity(poly); _c.trans.AddNewlyCreatedDBObject(poly, true); } }
public PolygonSegment JoinAdjoiningSegment(PolygonSegment segment) { if ( this.CompareSegments(segment).FrontPoint == CoincidencePoints.Coincides_With_Nothing && this.CompareSegments(segment).MediumPoint == CoincidencePoints.Coincides_With_Medium && this.CompareSegments(segment).BackPoint == CoincidencePoints.Coincides_With_Front ) { this.BackPoint = segment.BackPoint; } else if ( this.CompareSegments(segment).FrontPoint == CoincidencePoints.Coincides_With_Back && this.CompareSegments(segment).MediumPoint == CoincidencePoints.Coincides_With_Medium && this.CompareSegments(segment).BackPoint == CoincidencePoints.Coincides_With_Nothing ) { this.FrontPoint = segment.FrontPoint; } else { return(null); } return(this); }
private static double LengthPolylineBetweenPoints(AcGe.Point2dCollection polylinePoints, AcGe.Point2d startPoint, AcGe.Point2d endPoint) { int indexStart = polylinePoints.IndexOf(startPoint); int indexEnd = polylinePoints.IndexOf(endPoint); if (indexStart < 0 || indexEnd < 0) { return(double.NaN); } if (indexStart > indexEnd) { indexEnd = polylinePoints.IndexOf(startPoint); indexStart = polylinePoints.IndexOf(endPoint); } double length = 0; for (int i = indexStart; i < indexEnd; i++) { length += polylinePoints.ToArray()[i].GetDistanceTo(polylinePoints.ToArray()[i + 1]); } return(length); }
public static double GetDirAngle(AcGe.Point2d currentPoint, AcGe.Point2d frontPoint) { return(GetDirAngle( new AcGe.Point3d(new AcGe.Plane(), currentPoint), new AcGe.Point3d(new AcGe.Plane(), frontPoint) )); }
private void setViewportGeometry(_Db.Viewport vp, _Db.Extents2d ext, double fac = 1.0) { vp.Width = (ext.MaxPoint.X - ext.MinPoint.X) * fac; vp.Height = (ext.MaxPoint.Y - ext.MinPoint.Y) * fac; _Ge.Point2d gg = _Ge.Point2d.Origin + (ext.MaxPoint - ext.MinPoint) * 0.5; vp.CenterPoint = flatten(gg); }
private static List <LandPolygon> SortingNeighbors(LandPolygon parcel, List <LandPolygon> neighbors) { List <LandPolygon> sortedNeighbors = new List <LandPolygon>(); List <LandPolygon> temp = new List <LandPolygon>(); AcGe.Point2d point0 = AcGe.Point2d.Origin; foreach (AcGe.Point2d pointParcel in parcel.Points) { temp = neighbors.FindAll ( delegate(LandPolygon neighbor) { return(neighbor.Points.ToArray()[1].GetDistanceTo(pointParcel) == 0); } ); /* * if (temp.Count == 1) * { * sortedNeighbors.Add(temp.ToArray()[0]); * } * else */ if (temp.Count > 0) { temp.Sort ( delegate(LandPolygon polygon1, LandPolygon polygon2) { AcGe.Line2d line0 = new AcGe.Line2d(pointParcel, point0); AcGe.Point2d point1 = polygon1.Points.ToArray()[0]; AcGe.Line2d line1 = new AcGe.Line2d(pointParcel, point1); AcGe.Point2d point2 = polygon2.Points.ToArray()[0]; AcGe.Line2d line2 = new AcGe.Line2d(pointParcel, point2); double angle1 = line0.Direction.GetAngleTo(line1.Direction); double angle2 = line0.Direction.GetAngleTo(line2.Direction); return(angle1.CompareTo(angle2)); } ); foreach (LandPolygon polygon in temp) { sortedNeighbors.Add(polygon); } } point0 = pointParcel; } return(sortedNeighbors); }
public NeighborsSegment( AcGe.Point2d frontPoint, AcGe.Point2d mediumPoint, AcGe.Point2d backPoint, TypeNeighbor typeNeighbor ) : base(frontPoint, mediumPoint, backPoint) { this.TypeNeighbor = typeNeighbor; }
public List <PolygonSegment> GetPolygonSegmentsByMediumPoint(AcGe.Point2d mediumPoint) { List <PolygonSegment> polygonSegments = this.GetPolygonSegments(); return(polygonSegments.FindAll ( delegate(PolygonSegment segment) { return segment.MediumPoint.Equals(mediumPoint); } )); }
public bool IsCommonPoints(LandPolygon polygon) { AcGe.Point2d pnt; for (int i = 0; i < this.Points.Count; i++) { pnt = new AcGe.Point2d(); pnt = this.Points.ToArray()[i]; if (polygon.Points.Contains(pnt)) { return(true); } } return(false); }
private void AddLengthLine() { //AcDb.DBText oText; AcDb.MText oMText; AcDb.Line lineCur = null; AcDb.ObjectId idLineCur; AcGe.Point2d startPoint = this.Parcel.Points.ToArray()[this.Parcel.Points.Count - 1]; AcGe.Point3d midPoint; foreach (AcGe.Point2d endPoint in this.Parcel.Points) { midPoint = new AcGe.Point3d((endPoint.X + startPoint.X) / 2, (endPoint.Y + startPoint.Y) / 2, 0); lineCur = new AcDb.Line(new AcGe.Point3d(startPoint.X, startPoint.Y, 0), new AcGe.Point3d(endPoint.X, endPoint.Y, 0)); lineCur.ColorIndex = 222; lineCur.LineWeight = AcDb.LineWeight.LineWeight030; idLineCur = ServiceCAD.InsertObject(lineCur); ServiceCAD.ZoomCenter(midPoint, 1); /* * oText = new AcDb.DBText(); * oText.Height = 2 * this.SettingsForm.ScaleDrawing; * oText.TextString = startPoint.GetDistanceTo(endPoint).ToString("0.00").Replace(",","."); * //oText.Layer = settingsDrawing.Plan.LengthLine.Layer; * * ServiceCAD.ManualInsertText(oText); */ oMText = new AcDb.MText(); oMText.TextHeight = 2 * this.SettingsForm.ScaleDrawing; oMText.Attachment = AcDb.AttachmentPoint.MiddleCenter; //oMText.Layer = settingsDrawing.Plan.LengthLine.Layer; oMText.Contents = startPoint.GetDistanceTo(endPoint).ToString("0.00").Replace(",", "."); ServiceCAD.ZoomCenter(midPoint, 1); ServiceSimpleElements.ManualInsertMText(oMText); ServiceCAD.DeleteObject(idLineCur); startPoint = endPoint; } }
public static Dictionary <LandPolygon, TypeContour> GetContours(LandPolygon polygon) { List <PolygonSegment> allSegments = polygon.GetPolygonSegments(); List <NeighborsSegment> segments = new List <NeighborsSegment>(); foreach (PolygonSegment segment in allSegments) { segments.Add(new NeighborsSegment(segment, TypeNeighbor.Undefined)); } segments = ServiceNeighborsSegments.JoinAdjoiningSegments(segments, true); Dictionary <LandPolygon, TypeContour> contours = new Dictionary <LandPolygon, TypeContour>(); NeighborsSegment curSegment; AcGe.Point2d backPoint = segments[0].MediumPoint; LandPolygon contour = new LandPolygon(polygon.Info); while (segments.Count > 0) { List <NeighborsSegment> findSegments = ServiceNeighborsSegments.FindNeighborSegments(segments, backPoint); if (findSegments.Count > 0) { curSegment = findSegments[0]; contour.Points.Add(curSegment.MediumPoint); backPoint = curSegment.FrontPoint; segments.Remove(segments.Find(f => f.Equals(curSegment))); } else { backPoint = segments[0].MediumPoint; contours.Add(contour, TypeContour.Internal); contour = new LandPolygon(polygon.Info); } } contours.Add(contour, TypeContour.Internal); return(contours); }
private static List <_AcGe.Point2d> GetLwPoints(_AcDb.ObjectId objectId) { var pts = new List <_AcGe.Point2d>(); _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; using (var trans = doc.TransactionManager.StartTransaction()) { var lwp = (_AcDb.Polyline)trans.GetObject(objectId, _AcDb.OpenMode.ForRead); int vn = lwp.NumberOfVertices; for (int i = 0; i < vn; i++) { _AcGe.Point2d pt = lwp.GetPoint2dAt(i); pts.Add(pt); } trans.Commit(); } return(pts); }
public static void BuildingOrthogonalPolylines() { try { AcDb.Database db = CurrentCAD.Database; jigger = new OrthogonalPolylinesJig(); AcEd.PromptResult jigRes; do { jigRes = CurrentCAD.Editor.Drag(jigger); if (jigRes.Status == AcEd.PromptStatus.OK) { jigger.allVertexes.Add(jigger.lastVertex); } } while (jigRes.Status == AcEd.PromptStatus.OK); using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); Teigha.DatabaseServices.Polyline ent = new Teigha.DatabaseServices.Polyline(); ent.SetDatabaseDefaults(); for (int i = 0; i < jigger.allVertexes.Count; i++) { AcGe.Point3d pt3d = jigger.allVertexes[i]; AcGe.Point2d pt2d = new AcGe.Point2d(pt3d.X, pt3d.Y); ent.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid); } ent.TransformBy(jigger.UCS); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); tr.Commit(); } } catch (System.Exception ex) { CurrentCAD.Editor.WriteMessage(ex.ToString()); } }
/// <summary> /// Reverses the order of the X and Y properties of a Point2d. /// </summary> /// <param name="flip">Boolean indicating whether to reverse or not.</param> /// <returns>The original Point2d or the reversed version.</returns> public static _AcGe.Point2d Swap(this _AcGe.Point2d pt, bool flip = true) { return(flip ? new _AcGe.Point2d(pt.Y, pt.X) : pt); }
public static void Zoom(AcGe.Point3d pMin, AcGe.Point3d pMax, AcGe.Point3d pCenter, double dFactor) { int nCurVport = System.Convert.ToInt32(AcApp.GetSystemVariable("CVPORT")); if (db.TileMode == true) { if (pMin.Equals(new AcGe.Point3d()) == true && pMax.Equals(new AcGe.Point3d()) == true) { pMin = db.Extmin; pMax = db.Extmax; } } else { // Check to see if Paper space is current if (nCurVport == 1) { // Get the extents of Paper space if (pMin.Equals(new AcGe.Point3d()) == true && pMax.Equals(new AcGe.Point3d()) == true) { pMin = db.Pextmin; pMax = db.Pextmax; } } else { // Get the extents of Model space if (pMin.Equals(new AcGe.Point3d()) == true && pMax.Equals(new AcGe.Point3d()) == true) { pMin = db.Extmin; pMax = db.Extmax; } } } using (AcDb.Transaction acTrans = db.TransactionManager.StartTransaction()) { using (AcDb.ViewTableRecord acView = ed.GetCurrentView()) { AcDb.Extents3d eExtents; AcGe.Matrix3d matWCS2DCS; matWCS2DCS = AcGe.Matrix3d.PlaneToWorld(acView.ViewDirection); matWCS2DCS = AcGe.Matrix3d.Displacement(acView.Target - AcGe.Point3d.Origin) * matWCS2DCS; matWCS2DCS = AcGe.Matrix3d.Rotation(-acView.ViewTwist, acView.ViewDirection, acView.Target) * matWCS2DCS; if (pCenter.DistanceTo(AcGe.Point3d.Origin) != 0) { pMin = new AcGe.Point3d(pCenter.X - (acView.Width / 2), pCenter.Y - (acView.Height / 2), 0); pMax = new AcGe.Point3d((acView.Width / 2) + pCenter.X, (acView.Height / 2) + pCenter.Y, 0); } using (AcDb.Line acLine = new AcDb.Line(pMin, pMax)) { eExtents = new AcDb.Extents3d(acLine.Bounds.Value.MinPoint, acLine.Bounds.Value.MaxPoint); } double dViewRatio; dViewRatio = (acView.Width / acView.Height); matWCS2DCS = matWCS2DCS.Inverse(); eExtents.TransformBy(matWCS2DCS); double dWidth; double dHeight; AcGe.Point2d pNewCentPt; if (pCenter.DistanceTo(AcGe.Point3d.Origin) != 0) { dWidth = acView.Width; dHeight = acView.Height; if (dFactor == 0) { pCenter = pCenter.TransformBy(matWCS2DCS); } pNewCentPt = new AcGe.Point2d(pCenter.X, pCenter.Y); } else { dWidth = eExtents.MaxPoint.X - eExtents.MinPoint.X; dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y; pNewCentPt = new AcGe.Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5), ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5)); } if (dWidth > (dHeight * dViewRatio)) { dHeight = dWidth / dViewRatio; } if (dFactor != 0) { acView.Height = dHeight * dFactor; acView.Width = dWidth * dFactor; } acView.CenterPoint = pNewCentPt; ed.SetCurrentView(acView); } acTrans.Commit(); } }
internal void DoIt(_AcAp.Document doc, string rbName, string fgLayer) { log.Debug("--------------------------"); _FlaechenGrenzen.Clear(); _Raumbloecke.Clear(); var _AreaEngine = new AreaEngine(); _AcGe.Matrix3d ucs = _AcGe.Matrix3d.Identity; try { ucs = doc.Editor.CurrentUserCoordinateSystem; doc.Editor.CurrentUserCoordinateSystem = _AcGe.Matrix3d.Identity; if (!string.IsNullOrEmpty(rbName)) { _RaumblockName = rbName; } if (!string.IsNullOrEmpty(fgLayer)) { _FgLayer = fgLayer; } _AreaEngine.SelectFgAndRb(_FlaechenGrenzen, _Raumbloecke, _FgLayer, _RaumblockName); if (_FlaechenGrenzen.Count == 0) { return; } // todo: läuft nicht synchron - wird dzt in lisp ausgeführt //Globs.SetWorldUCS(); ZoomToFlaechenGrenzen(); // init div int fehlerKeinRb = 0; int fehlerMehrRb = 0; int fehlerWertFalsch = 0; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcDb.TransactionManager tm = db.TransactionManager; _AcDb.Transaction myT = tm.StartTransaction(); try { _AcGe.Point2d lu = new _AcGe.Point2d(); _AcGe.Point2d ro = new _AcGe.Point2d(); for (int i = 0; i < _FlaechenGrenzen.Count; i++) { log.Debug("--------------------------"); double sumAF = 0; int rbInd = -1; _AcDb.ObjectId elFG = _FlaechenGrenzen[i]; log.DebugFormat("Flächengrenze {0}", elFG.Handle.ToString()); _AcDb.Extents3d ext = GetExtents(tm, elFG); _AcGe.Point3d minExt = new _AcGe.Point3d(ext.MinPoint.X - ABSTANDTEXT, ext.MinPoint.Y - ABSTANDTEXT, ext.MinPoint.Z); _AcGe.Point3d maxExt = new _AcGe.Point3d(ext.MaxPoint.X + ABSTANDTEXT, ext.MaxPoint.Y + ABSTANDTEXT, ext.MaxPoint.Z); List <_AcDb.ObjectId> rbsToIgnoreCol = GetFgAnz(minExt, maxExt, elFG); if (rbsToIgnoreCol.Count > 0) { string handles = string.Join(",", rbsToIgnoreCol.Select(x => x.Handle.ToString()).ToArray()); log.DebugFormat("Zu ignorierende Raumblöcke: {0}", handles); } // 'raumbloecke holen List <_AcDb.ObjectId> ssRB = selRB(minExt, maxExt); if (ssRB.Count > 0) { string handles = string.Join(",", ssRB.Select(x => x.Handle.ToString()).ToArray()); log.DebugFormat("Raumblöcke: {0}", handles); } int rbAnz = 0; // 'raumbloecke pruefen for (int rbCnt = 0; rbCnt < ssRB.Count; rbCnt++) { _AcDb.ObjectId rbBlock2 = ssRB[rbCnt]; // ' ignore rbs _AcDb.ObjectId found = rbsToIgnoreCol.FirstOrDefault(x => x.Equals(rbBlock2)); if (found != default(_AcDb.ObjectId)) { continue; } using (_AcDb.DBObject dbObj = tm.GetObject(rbBlock2, _AcDb.OpenMode.ForRead, false)) { _AcGe.Point3d rbEp = ((_AcDb.BlockReference)dbObj).Position; using (_AcDb.Entity elFGEnt = (_AcDb.Entity)tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false)) { if (AreaEngine.InPoly(rbEp, elFGEnt)) { log.DebugFormat("Raumblock {0} ist innerhalb der Flächengrenze.", rbBlock2.Handle.ToString()); if (_Raumbloecke.Contains(rbBlock2)) { _Raumbloecke.Remove(rbBlock2); } rbAnz++; rbInd = rbCnt; } else { log.DebugFormat("Außen liegender Raumblock {0} wird ignoriert.", rbBlock2.Handle.ToString()); } } } } if (rbAnz < 1) { log.WarnFormat("Kein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString()); //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG)); fehlerKeinRb++; } else if (rbAnz > 1) { log.WarnFormat("Mehr als ein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString()); //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG)); fehlerMehrRb++; } else { using (var tr = doc.TransactionManager.StartTransaction()) { var pt = Globs.GetLabelPoint(elFG); if (pt.HasValue) { var rblock = tr.GetObject(ssRB[rbInd], _AcDb.OpenMode.ForWrite) as _AcDb.BlockReference; var pos = rblock.GetCenter(); if (!pos.HasValue) { pos = rblock.Position; } _AcGe.Vector3d acVec3d = pos.Value.GetVectorTo(pt.Value); rblock.TransformBy(_AcGe.Matrix3d.Displacement(acVec3d)); ed.WriteMessage("\nCentroid is {0}", pt); } else { var poly = tr.GetObject(elFG, _AcDb.OpenMode.ForRead) as _AcDb.Polyline; string msg = string.Format(CultureInfo.CurrentCulture, "\nFläche {0}. Centroid liegt außerhalb.", poly.Handle.ToString()); ed.WriteMessage(msg); log.Warn(msg); } tr.Commit(); } } } //if (_Raumbloecke.Count > 0) //{ // List<object> insPoints = new List<object>(); // for (int i = 0; i < _Raumbloecke.Count; i++) // { // _AcIntCom.AcadBlockReference rbBlock = (_AcIntCom.AcadBlockReference)Globs.ObjectIdToAcadEntity(_Raumbloecke[i], tm); // insPoints.Add(rbBlock.InsertionPoint); // } // _AcCm.Color col = _AcCm.Color.FromRgb((byte)0, (byte)255, (byte)0); // Plan2Ext.Globs.InsertFehlerLines(insPoints, _LooseBlockLayer, 50, Math.PI * 1.25, col); //} if (fehlerKeinRb > 0 || fehlerMehrRb > 0 || fehlerWertFalsch > 0 || _Raumbloecke.Count > 0) { string msg = string.Format(CultureInfo.CurrentCulture, "Räume ohne Raumblock: {0}\nRäume mit mehr als einem Raumblock: {1}\nRäume mit falschem Wert in Raumblock: {2}\nRaumblöcke ohne entsprechende Flächengrenzen: {3}", fehlerKeinRb, fehlerMehrRb, fehlerWertFalsch, _Raumbloecke.Count); log.Debug(msg); _AcAp.Application.ShowAlertDialog(msg); } //If wucs = 0 Then // ThisDrawing.SendCommand "(command ""_.UCS"" ""_P"") " //End If myT.Commit(); } finally { myT.Dispose(); } } finally { doc.Editor.CurrentUserCoordinateSystem = ucs; } }
public PolygonSegment(AcGe.Point2d frontPoint, AcGe.Point2d mediumPoint, AcGe.Point2d backPoint) { this.FrontPoint = frontPoint; this.MediumPoint = mediumPoint; this.BackPoint = backPoint; }
public static void BuildingRectangle() { try { AcDb.Database db = CurrentCAD.Database; AcEd.Editor ed = CurrentCAD.Editor; AcEd.PromptKeywordOptions pko; AcEd.PromptPointOptions ppt; AcEd.PromptPointResult ppr; AcGe.Point3d basePoint; AcGe.Point3d diractionPoint; pko = new AcEd.PromptKeywordOptions("\nПобудова прямокутника"); pko.Keywords.Add("по Діагоналі"); pko.Keywords.Add("по Напрямку та діагоналі"); pko.Keywords.Add("по Ширині та висота"); pko.Keywords.Default = "по Ширині та висота"; pko.AllowNone = false; AcEd.PromptResult pkr = ed.GetKeywords(pko); if (pkr.Status != AcEd.PromptStatus.OK) { return; } MethodConstructingRectangle methodConstructing; if (pkr.StringResult == "Діагоналі") { methodConstructing = MethodConstructingRectangle.Diagonal; } else if (pkr.StringResult == "Напрямку") { methodConstructing = MethodConstructingRectangle.DirectionAndDiagonal; } else { methodConstructing = MethodConstructingRectangle.HeightAndWidth; } ppt = new AcEd.PromptPointOptions("\nВкажіть першу точку прямокутника:"); ppr = ed.GetPoint(ppt); if (ppr.Status != AcEd.PromptStatus.OK) { return; } basePoint = ppr.Value; if (methodConstructing == MethodConstructingRectangle.Diagonal) { diractionPoint = basePoint.Add(AcGe.Vector3d.XAxis); } else { ppt = new AcEd.PromptPointOptions("\n"); if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal) { ppt.Message = "\nВкажіть точку напрямку прямокутника:"; } else if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal) { ppt.Message = "\nВкажіть ширину прямокутника:"; } ppt.UseBasePoint = true; ppt.BasePoint = basePoint; ppr = ed.GetPoint(ppt); if (ppr.Status != AcEd.PromptStatus.OK) { return; } diractionPoint = ppr.Value; } jigger = new RectangleJig(methodConstructing, basePoint, diractionPoint); ed.Drag(jigger); using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); Teigha.DatabaseServices.Polyline ent = new Teigha.DatabaseServices.Polyline(); ent.SetDatabaseDefaults(); for (int i = 0; i < jigger.Corners.Count; i++) { AcGe.Point3d pt3d = jigger.Corners[i]; AcGe.Point2d pt2d = new AcGe.Point2d(pt3d.X, pt3d.Y); ent.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid); } ent.Closed = true; ent.TransformBy(jigger.UCS); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); tr.Commit(); } } catch (System.Exception ex) { CurrentCAD.Editor.WriteMessage(ex.ToString()); } }
public static LandPolygon ExtractNeighborByStartingSegment ( LandPolygon parcel, LandPolygon neighbor, NeighborsSegment startingSegment ) { List <NeighborsSegment> intermediateNeighborSegments = parcel.GetCommonNeighborSegmentsByType(neighbor, TypeNeighbor.Intermediate); List <NeighborsSegment> endingNeighborSegments = parcel.GetCommonNeighborSegmentsByType(neighbor, TypeNeighbor.Ending); AcGe.Point2d backPoint = AcGe.Point2d.Origin; List <NeighborsSegment> nextSegments; NeighborsSegment nextSegment = startingSegment; LandPolygon neighborLine = new LandPolygon(neighbor.Info, false); int index = intermediateNeighborSegments.Count + endingNeighborSegments.Count; while (index != -1) { if ( nextSegment.TypeNeighbor == TypeNeighbor.Starting && nextSegment.TypeNeighbor != TypeNeighbor.OnlyOnePoint_Outside ) { neighborLine.Points.Add(nextSegment.FrontPoint); neighborLine.Points.Add(nextSegment.MediumPoint); } neighborLine.Points.Add(nextSegment.BackPoint); backPoint = nextSegment.BackPoint; if ( nextSegment.TypeNeighbor == TypeNeighbor.Ending && nextSegment.TypeNeighbor != TypeNeighbor.OnlyOnePoint_Outside ) { break; } nextSegments = FindNeighborSegments(intermediateNeighborSegments, backPoint); if (nextSegments.Count == 0) { nextSegments = FindNeighborSegments(endingNeighborSegments, backPoint); if (nextSegments.Count == 0 && startingSegment.MediumPoint.Equals(backPoint)) { neighborLine.Points.Add(startingSegment.FrontPoint); } } if (nextSegments.Count == 1) { nextSegment = nextSegments[0]; } index--; } return(neighborLine); }
// DBText extensions ///<summary> /// Gets the bounds of a DBText object. ///</summary> ///<param name="fac">Optional multiplier to increase/reduce buffer.</param> ///<returns>A collection of points defining the text's extents.</returns> public static _AcGe.Point3dCollection ExtractBounds( this _AcDb.DBText txt, double fac = 1.0 ) { var pts = new _AcGe.Point3dCollection(); if (txt.Bounds.HasValue && txt.Visible) { // Create a straight version of the text object // and copy across all the relevant properties // (stopped copying AlignmentPoint, as it would // sometimes cause an eNotApplicable error) // We'll create the text at the WCS origin // with no rotation, so it's easier to use its // extents var txt2 = new _AcDb.DBText(); txt2.Normal = _AcGe.Vector3d.ZAxis; txt2.Position = _AcGe.Point3d.Origin; // Other properties are copied from the original txt2.TextString = txt.TextString; txt2.TextStyleId = txt.TextStyleId; txt2.LineWeight = txt.LineWeight; txt2.Thickness = txt2.Thickness; txt2.HorizontalMode = txt.HorizontalMode; txt2.VerticalMode = txt.VerticalMode; txt2.WidthFactor = txt.WidthFactor; txt2.Height = txt.Height; txt2.IsMirroredInX = txt2.IsMirroredInX; txt2.IsMirroredInY = txt2.IsMirroredInY; txt2.Oblique = txt.Oblique; // Get its bounds if it has them defined // (which it should, as the original did) if (txt2.Bounds.HasValue) { var maxPt = txt2.Bounds.Value.MaxPoint; // Only worry about this single case, for now _AcGe.Matrix3d mat = _AcGe.Matrix3d.Identity; if (txt.Justify == _AcDb.AttachmentPoint.MiddleCenter) { mat = _AcGe.Matrix3d.Displacement((_AcGe.Point3d.Origin - maxPt) * 0.5); } // Place all four corners of the bounding box // in an array double minX, minY, maxX, maxY; if (txt.Justify == _AcDb.AttachmentPoint.MiddleCenter) { minX = -maxPt.X * 0.5 * fac; maxX = maxPt.X * 0.5 * fac; minY = -maxPt.Y * 0.5 * fac; maxY = maxPt.Y * 0.5 * fac; } else { minX = 0; minY = 0; maxX = maxPt.X * fac; maxY = maxPt.Y * fac; } var bounds = new _AcGe.Point2d[] { new _AcGe.Point2d(minX, minY), new _AcGe.Point2d(minX, maxY), new _AcGe.Point2d(maxX, maxY), new _AcGe.Point2d(maxX, minY) }; // We're going to get each point's WCS coordinates // using the plane the text is on var pl = new _AcGe.Plane(txt.Position, txt.Normal); // Rotate each point and add its WCS location to the // collection foreach (_AcGe.Point2d pt in bounds) { pts.Add( pl.EvaluatePoint( pt.RotateBy(txt.Rotation, _AcGe.Point2d.Origin) ) ); } } } return(pts); }
private static double GetDistance(_AcGe.Point2d p1, _AcGe.Point2d p2) { return(Math.Sqrt(Math.Pow(p1.X - p2.X, 2.0) + Math.Pow(p1.Y - p2.Y, 2.0))); }
/// <summary> /// Pads a Point2d with a zero Z value, returning a Point3d. /// </summary> /// <param name="pt">The Point2d to pad.</param> /// <returns>The padded Point3d.</returns> public static _AcGe.Point3d Pad(this _AcGe.Point2d pt) { return(new _AcGe.Point3d(pt.X, pt.Y, 0)); }
private _Ge.Point3d flatten(_Ge.Point2d pt) { return(new _Ge.Point3d(pt.X, pt.Y, 0)); }
private _Ge.Point2d swapCoords(_Ge.Point2d pt, bool flip = true) { return(flip ? new _Ge.Point2d(pt.Y, pt.X) : pt); }
public List <LandPolygon> GetNeighborLines(LandPolygon polygon) { if (this.IsCommonPoints(polygon)) { List <LandPolygon> neighborLines = new List <LandPolygon>(); LandPolygon neighborLine = new LandPolygon(polygon.Info); List <NeighborsSegment> startingNeighborSegments = this.GetCommonNeighborSegmentsByType(polygon, TypeNeighbor.Starting); List <NeighborsSegment> endingNeighborSegments = this.GetCommonNeighborSegmentsByType(polygon, TypeNeighbor.Ending); List <NeighborsSegment> onlyOnePointOutsideNeighborSegments = this.GetCommonNeighborSegmentsByType(polygon, TypeNeighbor.OnlyOnePoint_Outside); List <NeighborsSegment> onlyOnePointInsideNeighborSegments = this.GetCommonNeighborSegmentsByType(polygon, TypeNeighbor.OnlyOnePoint_Inside); List <NeighborsSegment> intermediateNeighborSegments = this.GetCommonNeighborSegmentsByType(polygon, TypeNeighbor.Intermediate); if (this.Points.Count - intermediateNeighborSegments.Count == 0) { neighborLines.Add(polygon); } else { AcGe.Point2d backPoint = AcGe.Point2d.Origin; foreach (NeighborsSegment startingNeighborSegment in startingNeighborSegments) { neighborLines.Add ( ServiceNeighborsSegments .ExtractNeighborByStartingSegment (this, polygon, startingNeighborSegment) ); } AcGe.Point2d[] pointsOnlyOnePointOutside; foreach (NeighborsSegment onlyOnePointOutsideNeighborSegment in onlyOnePointOutsideNeighborSegments) { pointsOnlyOnePointOutside = new AcGe.Point2d[] { onlyOnePointOutsideNeighborSegment.FrontPoint, onlyOnePointOutsideNeighborSegment.MediumPoint, onlyOnePointOutsideNeighborSegment.BackPoint }; neighborLines.Add ( new LandPolygon ( polygon.Info, new AcGe.Point2dCollection(pointsOnlyOnePointOutside) ) ); } } return(neighborLines); } return(null); }
private List <G.Line> getGeometry() { List <G.Line> polys = new List <G.Line>(); _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions(); opts.MessageForAdding = "\nSelect Geometry: "; _Ed.PromptSelectionResult userSelection = _c.doc.Editor.GetSelection(opts); if (userSelection.Status != _Ed.PromptStatus.OK) { throw new DMTException("[ERROR] Geometry - cancelled"); } _Ed.SelectionSet selectionSet = userSelection.Value; foreach (_Ed.SelectedObject currentObject in selectionSet) { if (currentObject == null) { continue; } _Db.Entity currentEntity = _c.trans.GetObject(currentObject.ObjectId, _Db.OpenMode.ForRead) as _Db.Entity; if (currentEntity == null) { continue; } if (currentEntity is _Db.Polyline) { _Db.Polyline poly = _c.trans.GetObject(currentEntity.ObjectId, _Db.OpenMode.ForRead) as _Db.Polyline; int points = poly.NumberOfVertices; for (int i = 1; i < points; i++) { _Ge.Point2d p1 = poly.GetPoint2dAt(i - 1); _Ge.Point2d p2 = poly.GetPoint2dAt(i); G.Point new_p1 = new G.Point(p1.X, p1.Y); G.Point new_p2 = new G.Point(p2.X, p2.Y); if (new_p1 == new_p2) { continue; } G.Line line = new G.Line(new_p1, new_p2); if (!polys.Contains(line)) { polys.Add(line); } } if (poly.Closed) { _Ge.Point2d p1 = poly.GetPoint2dAt(points - 1); _Ge.Point2d p2 = poly.GetPoint2dAt(0); G.Point new_p1 = new G.Point(p1.X, p1.Y); G.Point new_p2 = new G.Point(p2.X, p2.Y); if (new_p1 == new_p2) { continue; } G.Line line = new G.Line(new_p1, new_p2); if (!polys.Contains(line)) { polys.Add(line); } } } } if (polys.Count < 3) { throw new DMTException("[ERROR] Geometry - less then 3"); } return(polys); }