Пример #1
0
        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);
        }
Пример #2
0
        private void AddPoints(AcDb.ObjectId idBorderParcel)
        {
            AcDb.ResultBuffer xData = new AcDb.ResultBuffer();
            int dxfCode;

            AcDb.TypedValue typedValue;

            dxfCode    = (int)AcDb.DxfCode.ExtendedDataRegAppName;
            typedValue = new AcDb.TypedValue(dxfCode, "Точки межі");
            xData.Add(typedValue);

            int iCurNumberPoint = 0;

            Dictionary <string, string> tags = new Dictionary <string, string>();

            foreach (AcGe.Point2d point in this.Parcel.Points)
            {
                iCurNumberPoint += 1;
                tags.Clear();
                tags.Add("NUMBER", "");
                AcDb.ObjectId idPoint = ServiceBlockElements.InsertBlock
                                        (
                    settingsDrawing.Plan.Point.NameBlock,
                    new AcGe.Point3d(point.X, point.Y, 0.0),
                    this.SettingsForm.ScaleDrawing,
                    0,
                    ServiceCAD.CreateLayer(settingsDrawing.Plan.Point.Layer),
                    tags
                                        );

                //dxfCode = (int)DxfCode.ExtendedDataHandle;
                dxfCode    = (int)AcDb.DxfCode.ExtendedDataAsciiString;
                typedValue = new AcDb.TypedValue(dxfCode, point.ToString());
                xData.Add(typedValue);
            }
            if (!idBorderParcel.Equals(AcDb.ObjectId.Null))
            {
                ServiceCAD.SetXData(idBorderParcel, xData);
            }
        }
Пример #3
0
        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");
            }
        }
Пример #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();
            }
        }