Exemplo n.º 1
0
 public LandBlockJig(AcDb.BlockReference br)
     : base(br)
 {
     _br  = br;
     _pos = _br.Position;
     AcEd.Editor             ed     = CurrentCAD.Editor;
     AcGe.CoordinateSystem3d ucs    = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
     AcGe.Matrix3d           ocsMat = AcGe.Matrix3d.WorldToPlane(new AcGe.Plane(AcGe.Point3d.Origin, ucs.Zaxis));
     _ucsRot = AcGe.Vector3d.XAxis.GetAngleTo(ucs.Xaxis.TransformBy(ocsMat), ucs.Zaxis);
     _rot    = _br.Rotation - _ucsRot;
 }
Exemplo n.º 2
0
 public BlockPlacementJig(AcDb.BlockReference br, Dictionary <string, string> tags)
     : base(br)
 {
     blockReference = br;
     position       = blockReference.Position;
     AcEd.Editor             ed     = CurrentCAD.Editor;
     AcGe.CoordinateSystem3d ucs    = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
     AcGe.Matrix3d           ocsMat = AcGe.Matrix3d.WorldToPlane(new AcGe.Plane(AcGe.Point3d.Origin, ucs.Zaxis));
     ucsRotation = AcGe.Vector3d.XAxis.GetAngleTo(ucs.Xaxis.TransformBy(ocsMat), ucs.Zaxis);
     rotation    = blockReference.Rotation - ucsRotation;
     this.tags   = tags;
     layerId     = blockReference.LayerId;
 }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        public static void AttachRasterImage(LandRasterImage landRastr)
        {
            AcEd.Editor ed = AcApp.DocumentManager.MdiActiveDocument.Editor;

            //bool bRasterDefCreated = false;

            AcDb.Database curDb = AcApp.DocumentManager.MdiActiveDocument.Database;

            using (AcDb.Transaction tr = curDb.TransactionManager.StartTransaction())
            {
                AcDb.RasterImageDef rasterDef;
                AcDb.ObjectId       imgDefId;
                AcDb.ObjectId       imgDctID = AcDb.RasterImageDef.GetImageDictionary(curDb);
                if (imgDctID.IsNull)
                {
                    imgDctID = AcDb.RasterImageDef.CreateImageDictionary(curDb);
                }

                AcDb.DBDictionary imgDict = (AcDb.DBDictionary)tr.GetObject(imgDctID, AcDb.OpenMode.ForRead);

                if (imgDict.Contains(landRastr.ImageName))
                {
                    imgDefId  = imgDict.GetAt(landRastr.ImageName);
                    rasterDef = (AcDb.RasterImageDef)tr.GetObject(imgDefId, AcDb.OpenMode.ForWrite);
                    if (rasterDef.IsLoaded)
                    {
                        //return;
                    }
                }
                else
                {
                    AcPApp.AcadApplication app    = AcApp.AcadApplication as AcPApp.AcadApplication;
                    AcPApp.AcadDocument    doc    = app.ActiveDocument;
                    AcPDb.AcadModelSpace   mSpace = doc.ModelSpace;
                    AcPDb.AcadRasterImage  ri     = mSpace.AddRaster(landRastr.FileName, landRastr.InsertPoint.ToArray(), 1000, 0);
                    ri.Name         = landRastr.ImageName;
                    ri.Transparency = true;
                    ServiceCAD.CreateLayer(landRastr.Layer);
                    ri.Layer       = landRastr.Layer;
                    ri.ImageHeight = 1000;
                    ri.ImageWidth  = 1000;

                    tr.Commit();
                    return;
                }

                AcDb.BlockTable blkTbl =
                    (AcDb.BlockTable)tr.GetObject(curDb.BlockTableId, AcDb.OpenMode.ForRead);

                AcDb.BlockTableRecord acBlkTblRec =
                    (AcDb.BlockTableRecord)tr.GetObject(blkTbl[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForWrite);

                using (AcDb.RasterImage rasterImage = new AcDb.RasterImage())
                {
                    rasterImage.ImageDefId = imgDefId;

                    AcGe.Vector3d width;
                    AcGe.Vector3d height;

                    AcGe.Matrix3d ucs  = ed.CurrentUserCoordinateSystem;
                    double        size = 1000;

                    width  = new AcGe.Vector3d(size, 0, 0);
                    height = new AcGe.Vector3d(0, size, 0);


                    AcGe.Point3d            insPt            = landRastr.InsertPoint;
                    AcGe.CoordinateSystem3d coordinateSystem = new AcGe.CoordinateSystem3d(insPt.TransformBy(ucs), width.TransformBy(ucs), height.TransformBy(ucs));
                    rasterImage.Orientation = coordinateSystem;
                    rasterImage.Rotation    = 0;
                    rasterImage.ShowImage   = true;

                    acBlkTblRec.AppendEntity(rasterImage);
                    tr.AddNewlyCreatedDBObject(rasterImage, true);

                    rasterImage.AssociateRasterDef(rasterDef);
                }
                tr.Commit();
            }
        }
Exemplo n.º 5
0
        // 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);
        }