private List <_Area_v2> getBoxAreas(List <_Db.BlockReference> blocks) { List <_Area_v2> parse = new List <_Area_v2>(); foreach (_Db.BlockReference block in blocks) { _Db.Extents3d blockExtents = block.GeometricExtents; _Area_v2 area = new _Area_v2(block.Id, blockExtents.MinPoint, blockExtents.MaxPoint); parse.Add(area); } parse = parse.OrderBy(o => o.Start.X).ToList(); return(parse); }
private void AddRbToRetCol(List <_AcDb.ObjectId> Ret, _AcDb.TransactionManager tm, _AcDb.ObjectId elFG) { _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); _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"), new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName, _RaumblockName) }); _AcEd.PromptSelectionResult res = null; res = ed.SelectCrossingWindow(minExt, maxExt, filter); if (res.Status != _AcEd.PromptStatus.OK) { // todo: logging: lot4net? return; } #if BRX_APP _AcEd.SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { _AcDb.ObjectId[] idArray = ss.GetObjectIds(); for (int i = 0; i < idArray.Length; i++) { _AcDb.ObjectId oid = idArray[i]; using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false)) { using (_AcDb.Entity entElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false) as _AcDb.Entity) { if (pEntity is _AcDb.BlockReference) { _AcDb.BlockReference br = pEntity as _AcDb.BlockReference; if (AreaEngine.InPoly(br.Position, entElFG)) { Ret.Add(oid); } } } } } } }
/// <summary> /// Sets the view in a viewport to contain the specified model extents. /// </summary> /// <param name="ext">The extents of the content to fit the viewport.</param> /// <param name="fac">Optional factor to provide padding.</param> public static void FitContentToViewport( this _AcDb.Viewport vp, _AcDb.Extents3d ext, double fac = 1.0 ) { // Let's zoom to just larger than the extents vp.ViewCenter = (ext.MinPoint + ((ext.MaxPoint - ext.MinPoint) * 0.5)).Strip(); // Get the dimensions of our view from the database extents var hgt = ext.MaxPoint.Y - ext.MinPoint.Y; var wid = ext.MaxPoint.X - ext.MinPoint.X; // We'll compare with the aspect ratio of the viewport itself // (which is derived from the page size) var aspect = vp.Width / vp.Height; // If our content is wider than the aspect ratio, make sure we // set the proposed height to be larger to accommodate the // content if (wid / hgt > aspect) { hgt = wid / aspect; } // Set the height so we're exactly at the extents vp.ViewHeight = hgt; // Set a custom scale to zoom out slightly (could also // vp.ViewHeight *= 1.1, for instance) vp.CustomScale *= fac; }
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; } }
private void ZoomToFlaechenGrenzen() { log.DebugFormat(CultureInfo.CurrentCulture, "Zoom auf Flächengrenzen"); if (_FlaechenGrenzen.Count == 0) { return; } double MinX, MinY, MaxX, MaxY; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcDb.TransactionManager tm = db.TransactionManager; _AcDb.Transaction myT = tm.StartTransaction(); try { _AcDb.Extents3d ext = GetExtents(tm, _FlaechenGrenzen[0]); MinX = ext.MinPoint.X; MinY = ext.MinPoint.Y; MaxX = ext.MaxPoint.X; MaxY = ext.MaxPoint.Y; for (int i = 1; i < _FlaechenGrenzen.Count; i++) { _AcDb.ObjectId oid = _FlaechenGrenzen[i]; ext = GetExtents(tm, oid); if (ext.MinPoint.X < MinX) { MinX = ext.MinPoint.X; } if (ext.MinPoint.Y < MinY) { MinY = ext.MinPoint.Y; } if (ext.MaxPoint.X > MaxX) { MaxX = ext.MaxPoint.X; } if (ext.MaxPoint.Y > MaxY) { MaxY = ext.MaxPoint.Y; } } //Globs.Zoom( new Point3d(MinX, MinY, 0.0), new Point3d(MaxX, MaxY, 0.0),new Point3d(), 1.0); //Globs.ZoomWin3(ed, new Point3d(MinX, MinY, 0.0), new Point3d(MaxX, MaxY, 0.0)); //Globs.ZoomWin2(ed, new Point3d(MinX, MinY, 0.0), new Point3d(MaxX, MaxY, 0.0)); myT.Commit(); } finally { myT.Dispose(); } // Rauszoomen, sonst werden Blöcken nicht gefunden, die außerhalb der Flächengrenzen liegen. MinX -= ABSTANDTEXT; MinY -= ABSTANDTEXT; MaxX += ABSTANDTEXT; MaxY += ABSTANDTEXT; Globs.Zoom(new _AcGe.Point3d(MinX, MinY, 0.0), new _AcGe.Point3d(MaxX, MaxY, 0.0), new _AcGe.Point3d(), 1.0); }