Example #1
0
        private LayerModel GetRealLayer(Document doc, PromptSelectionResult ProSset, string layerName)
        {
            ObjectIdCollection    ids     = new ObjectIdCollection();
            LayerModel            lyModel = new LayerModel();
            List <BlockInfoModel> list    = new List <BlockInfoModel>();


            TypedValue[] filList = new TypedValue[1] {
                new TypedValue((int)DxfCode.LayerName, layerName)
            };
            SelectionFilter sfilter   = new SelectionFilter(filList);
            LayoutManager   layoutMgr = LayoutManager.Current;

            string ss = layoutMgr.CurrentLayout;

            ProSset = doc.Editor.SelectAll(sfilter);
            //  List<ObjectId> idss=  GetEntitiesInModelSpace();
            Database db = doc.Database;
            List <BlockReference> blockTableRecords = new List <BlockReference>();

            if (ProSset.Status == PromptStatus.OK)
            {
                lyModel.pointFs = new Dictionary <int, List <object> >();
                using (Transaction tran = db.TransactionManager.StartTransaction())
                {
                    SelectionSet sst = ProSset.Value;

                    ObjectId[] oids = sst.GetObjectIds();

                    int           ad = 0;
                    List <string> aa = new List <string>();

                    LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
                    foreach (ObjectId layerId in lt)
                    {
                        LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead);
                        if (ltr.Name == layerName)
                        {
                            lyModel.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue);
                        }
                    }

                    int i = 0;
                    foreach (ObjectId lengGemo in oids)
                    {
                        DBObject       ob      = tran.GetObject(lengGemo, OpenMode.ForRead);
                        BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob);
                        if (plModel != null)
                        {
                            List <object> obj = new List <object>()
                            {
                                plModel
                            };
                            lyModel.pointFs.Add(i, obj);
                            i++;
                        }
                    }
                }
            }
            return(lyModel);
        }
Example #2
0
        public override void GetAllAttributeInfo(T model)
        {
            foreach (AttributeModel am in model.attributes)
            {
                foreach (string layerName in GetRealLayer(am.LayerName))
                {
                    model.selectedLayerList.Add(layerName);
                    LayerModel lyModel = new LayerModel();
                    lyModel.IsHaveAttribute = true;
                    List <BlockInfoModel> list = new List <BlockInfoModel>();
                    lyModel.Name = layerName;
                    Document           doc = Application.DocumentManager.MdiActiveDocument;
                    ObjectIdCollection ids = new ObjectIdCollection();

                    PromptSelectionResult ProSset = null;
                    TypedValue[]          filList = new TypedValue[1] {
                        new TypedValue((int)DxfCode.LayerName, layerName)
                    };
                    SelectionFilter sfilter   = new SelectionFilter(filList);
                    LayoutManager   layoutMgr = LayoutManager.Current;

                    string ss = layoutMgr.CurrentLayout;
                    ProSset = doc.Editor.SelectAll(sfilter);
                    //  List<ObjectId> idss=  GetEntitiesInModelSpace();
                    Database db = doc.Database;
                    List <BlockReference> blockTableRecords = new List <BlockReference>();
                    if (ProSset.Status == PromptStatus.OK)
                    {
                        lyModel.pointFs = new Dictionary <int, List <object> >();
                        using (Transaction tran = db.TransactionManager.StartTransaction())
                        {
                            SelectionSet sst = ProSset.Value;

                            ObjectId[] oids = sst.GetObjectIds();

                            int           ad = 0;
                            List <string> aa = new List <string>();

                            LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
                            foreach (ObjectId layerId in lt)
                            {
                                LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead);
                                if (ltr.Name == layerName)
                                {
                                    lyModel.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue);
                                }
                            }

                            int i = 0;
                            foreach (ObjectId lengGemo in oids)
                            {
                                DBObject       ob      = tran.GetObject(lengGemo, OpenMode.ForRead);
                                BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob, am);
                                if (plModel != null)
                                {
                                    List <object> obj = new List <object>()
                                    {
                                        plModel
                                    };
                                    lyModel.pointFs.Add(i, obj);
                                    i++;
                                }
                            }
                        }
                        if (model.allLines == null)
                        {
                            model.allLines = new List <LayerModel>();
                        }
                        model.allLines.Add(lyModel);
                    }
                }
            }
        }
Example #3
0
        public void GetAttributeIndex(T model, string layerName)
        {
            if (model != null)
            {
                LayerModel lm  = new LayerModel();
                Document   doc = Application.DocumentManager.MdiActiveDocument;
                Database   db  = doc.Database;

                ObjectIdCollection ids = new ObjectIdCollection();
                lm.Name = layerName;

                PromptSelectionResult ProSset = null;
                TypedValue[]          filList = new TypedValue[1] {
                    new TypedValue((int)DxfCode.LayerName, layerName)
                };
                SelectionFilter sfilter = new SelectionFilter(filList);

                ProSset = doc.Editor.SelectAll(sfilter);
                if (ProSset.Status == PromptStatus.OK)
                {
                    using (Transaction tran = db.TransactionManager.StartTransaction())
                    {
                        SelectionSet sst  = ProSset.Value;
                        ObjectId[]   oids = sst.GetObjectIds();

                        // 去重
                        List <string> numsAll = new List <string>();

                        // 增加用地大类
                        List <string> nums = new List <string>();

                        LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
                        foreach (ObjectId layerId in lt)
                        {
                            LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead);
                            if (ltr.Name == layerName)
                            {
                                lm.Color = ColorTranslator.ToHtml(ltr.Color.ColorValue);
                            }
                        }

                        foreach (ObjectId lengGemo in oids)
                        {
                            DBObject            ob             = tran.GetObject(lengGemo, OpenMode.ForRead);
                            PointsPlanItemModel pointsPlanItem = new PointsPlanItemModel();
                            List <PointF>       pfs            = new List <PointF>();

                            //if (ob is Hatch)
                            //{
                            //    Hatch h = ob as Hatch;
                            //    int count = h.NumberOfLoops;

                            //    for (int i = 0; i < count; i++)
                            //    {
                            //        HatchLoop loop = h.GetLoopAt(i);

                            //        if (loop.IsPolyline)
                            //        {
                            //            foreach (BulgeVertex pt in loop.Polyline)
                            //            {
                            //                pfs.Add(new PointF((float)pt.Vertex.X, (float)pt.Vertex.Y));
                            //            }
                            //        }
                            //        else
                            //        {
                            //            foreach (Curve2d item in loop.Curves)
                            //            {
                            //                Point2d[] M_point2d = item.GetSamplePoints(20);
                            //                foreach (Point2d pt in M_point2d)
                            //                {
                            //                    pfs.Add(new PointF((float)pt.X, (float)pt.Y));
                            //                }
                            //            }
                            //        }
                            //    }

                            //    pointsPlanItem.Num = MethodCommand.GetAttrIndex(pfs);

                            //    if (pointsPlanItem.Num == null)
                            //    {

                            //    }
                            //}

                            if (ob is MText)
                            {
                                MText h = ob as MText;
                                pointsPlanItem.Num = h.Text;
                            }

                            if (ob is DBText)
                            {
                                DBText h = ob as DBText;
                                pointsPlanItem.Num = h.TextString;
                            }

                            if (pointsPlanItem.Num != null && !numsAll.Contains(pointsPlanItem.Num))
                            {
                                numsAll.Add(pointsPlanItem.Num);

                                BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob);
                                pointsPlanItem.Geom = plModel;

                                if (lm.modelItemList == null)
                                {
                                    lm.modelItemList = new List <object>();
                                }

                                PointsPlanItemModel pointsPlanItem2 = new PointsPlanItemModel();
                                string firstLetter = pointsPlanItem.Num.Substring(0, 1);

                                if (!nums.Contains(firstLetter))
                                {
                                    nums.Add(firstLetter);

                                    pointsPlanItem2.Num  = firstLetter;
                                    pointsPlanItem2.Geom = pointsPlanItem.Geom;
                                    lm.modelItemList.Add(pointsPlanItem2);
                                }

                                lm.modelItemList.Add(pointsPlanItem);
                            }
                        }
                    }


                    if (model.allLines == null)
                    {
                        model.allLines = new List <LayerModel>();
                    }
                    model.allLines.Add(lm);
                }
            }
        }
Example #4
0
        public override void GetAllAttributeInfo(T model)
        {
            foreach (AttributeModel am in model.attributes)
            {
                foreach (string layerName in GetRealLayer(am.LayerName))
                {
                    // 需要发送的图层
                    if (layerName != null)
                    {
                        model.selectedLayerList.Add(layerName);
                    }

                    Document doc = Application.DocumentManager.MdiActiveDocument;
                    Database db  = doc.Database;

                    LayerModel lyModel = new LayerModel();
                    lyModel.IsHaveAttribute = true;
                    List <BlockInfoModel> list = new List <BlockInfoModel>();
                    lyModel.Name = layerName;
                    // Document doc = Application.DocumentManager.MdiActiveDocument;
                    ObjectIdCollection ids = new ObjectIdCollection();

                    PromptSelectionResult ProSset = null;
                    TypedValue[]          filList = new TypedValue[1] {
                        new TypedValue((int)DxfCode.LayerName, layerName)
                    };
                    SelectionFilter sfilter   = new SelectionFilter(filList);
                    LayoutManager   layoutMgr = LayoutManager.Current;

                    string ss = layoutMgr.CurrentLayout;
                    ProSset = doc.Editor.SelectAll(sfilter);
                    //  List<ObjectId> idss=  GetEntitiesInModelSpace();
                    //    Database db = doc.Database;
                    List <BlockReference> blockTableRecords = new List <BlockReference>();
                    if (ProSset.Status == PromptStatus.OK)
                    {
                        lyModel.pointFs = new Dictionary <int, List <object> >();
                        using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
                        {
                            SelectionSet sst = ProSset.Value;

                            ObjectId[] oids = sst.GetObjectIds();

                            int           ad = 0;
                            List <string> aa = new List <string>();

                            LayerTable lt = (LayerTable)doc.Database.LayerTableId.GetObject(OpenMode.ForRead);
                            foreach (ObjectId layerId in lt)
                            {
                                LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead);
                                if (ltr.Name == layerName)
                                {
                                    lyModel.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue);
                                }
                            }
                            double totalFamily = 0;
                            double totalPeople = 0;
                            int    i           = 0;

                            foreach (ObjectId lengGemo in oids)
                            {
                                DBObject       ob      = tran.GetObject(lengGemo, OpenMode.ForRead);
                                BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob, am);

                                foreach (DbTextModel dbTextModel in plModel.DbText)
                                {
                                    if (dbTextModel.attItemList != null && dbTextModel.attItemList.Count > 0)
                                    {
                                        foreach (AttributeItemModel attribute in dbTextModel.attItemList)
                                        {
                                            if (attribute.AtValue.Contains(":") || attribute.AtValue.Contains(":"))
                                            {
                                                string[] fmList = attribute.AtValue.Split(new char[2] {
                                                    ':', ':'
                                                });

                                                if (attribute.TargetName == "总户数")
                                                {
                                                    totalFamily += double.Parse(fmList[3]);
                                                }
                                                else if (attribute.TargetName == "总人数")
                                                {
                                                    totalPeople += double.Parse(System.Text.RegularExpressions.Regex.Replace(fmList[2].Replace("(", "").Replace(")", ""), @"[\u4e00-\u9fa5]", ""));
                                                }
                                            }
                                        }
                                    }
                                }


                                if (plModel != null)
                                {
                                    List <object> obj = new List <object>()
                                    {
                                        plModel
                                    };
                                    lyModel.pointFs.Add(i, obj);
                                    i++;
                                }
                            }
                            foreach (List <object> ptssItem in lyModel.pointFs.Values)
                            {
                                foreach (object ptsItem in ptssItem)
                                {
                                    BlockInfoModel tempBlock = new BlockInfoModel();
                                    if (ptsItem is BlockInfoModel)
                                    {
                                        for (int j = 0; j < (ptsItem as BlockInfoModel).DbText.Count; j++)
                                        {
                                            DbTextModel dbTextModel      = (ptsItem as BlockInfoModel).DbText[j];
                                            List <AttributeItemModel> kk = new List <AttributeItemModel>();
                                            if (dbTextModel.attItemList != null && dbTextModel.attItemList.Count > 0)
                                            {
                                                foreach (AttributeItemModel attribute in dbTextModel.attItemList)
                                                {
                                                    AttributeItemModel tempModel = attribute;
                                                    if (attribute.TargetName == "总户数")
                                                    {
                                                        tempModel         = attribute;
                                                        tempModel.AtValue = totalFamily.ToString();
                                                        kk.Add(tempModel);// dbTextModel.attItemList[attribute] = totalFamily.ToString();
                                                    }
                                                    else if (attribute.TargetName == "总人数")
                                                    {
                                                        tempModel         = attribute;
                                                        tempModel.AtValue = totalPeople.ToString();
                                                        kk.Add(tempModel);
                                                    }
                                                    else
                                                    {
                                                        kk.Add(attribute);
                                                    }
                                                }
                                            }
                                            dbTextModel.attItemList = kk;
                                        }
                                    }
                                }
                            }
                            if (model.allLines == null)
                            {
                                model.allLines = new List <LayerModel>();
                            }
                            model.allLines.Add(lyModel);
                        }
                    }
                }
            }
        }
Example #5
0
        public void GetAllLengedGemo(T model)
        {
            List <BlockInfoModel> list             = new List <BlockInfoModel>();
            List <Polyline>       allLengenPolyine = new List <Polyline>();
            Document           doc = Application.DocumentManager.MdiActiveDocument;
            ObjectIdCollection ids = new ObjectIdCollection();

            TypedValue[] filList = new TypedValue[1] {
                new TypedValue((int)DxfCode.LayerName, "图例")
            };

            PromptSelectionResult ProSset   = null;
            SelectionFilter       sfilter   = new SelectionFilter(filList);
            LayoutManager         layoutMgr = LayoutManager.Current;

            string ss = layoutMgr.CurrentLayout;

            ProSset = doc.Editor.SelectAll(sfilter);
            //  List<ObjectId> idss=  GetEntitiesInModelSpace();
            Database db = doc.Database;
            List <BlockReference> blockTableRecords = new List <BlockReference>();

            if (ProSset.Status == PromptStatus.OK)
            {
                using (Transaction tran = db.TransactionManager.StartTransaction())
                {
                    SelectionSet sst = ProSset.Value;

                    ObjectId[] oids = sst.GetObjectIds();

                    int           ad = 0;
                    List <string> aa = new List <string>();
                    LayerModel    lm = new LayerModel();
                    LayerTable    lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
                    foreach (ObjectId layerId in lt)
                    {
                        LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead);
                        if (ltr.Name == MethodCommand.LegendLayer)
                        {
                            lm.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue);
                        }
                    }
                    for (int i = 0; i < oids.Length; i++)
                    {
                        //  if (idss.Contains(oids[i]))
                        //  {
                        DBObject ob = tran.GetObject(oids[i], OpenMode.ForRead);
                        // if (!aa.Contains((ob as Polyline).BlockName)) { aa.Add((ob as Polyline).BlockName); }
                        if (ob is Polyline && (((ob as Polyline).BlockName.ToLower() == "*model_space" && UI.MainForm.isOnlyModel) || (!UI.MainForm.isOnlyModel)))
                        {
                            if (ob == null)
                            {
                            }
                            else
                            {
                                allLengenPolyine.Add((ob as Polyline));
                            }//  lengedList.Add(ob as Polyline);
                             //  model.LegendPoints.Add(ad, PolylineMethod.GetPolyLineInfoPt(ob as Polyline));
                             // ad++;
                        }
                        else if (ob is BlockReference && (((ob as BlockReference).BlockName.ToLower() == "*model_space" && UI.MainForm.isOnlyModel) || (!UI.MainForm.isOnlyModel)))
                        {
                            blockTableRecords.Add(ob as BlockReference);
                        }
                    }
                    Dictionary <int, List <Polyline> > plList = MethodCommand.FindMaxAreaPoline(allLengenPolyine);
                    model.LegendList = new List <LengedModel>();
                    this.lengedList  = plList[0];
                    foreach (Polyline polyline in plList[0])
                    {
                        LengedModel legm = new LengedModel();
                        legm.GemoModels = new List <BlockInfoModel>();

                        legm.BoxPointList = PolylineMethod.GetPolyLineInfoPt(polyline);
                        List <ObjectId> ois = GetCrossObjectIds(doc.Editor, polyline, sfilter, tran);

                        if (ois != null)
                        {
                            foreach (ObjectId lengGemo in ois)
                            {
                                DBObject       ob      = tran.GetObject(lengGemo, OpenMode.ForRead);
                                BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob);

                                if (plModel != null)
                                {
                                    if (plModel.Hatch != null)
                                    {
                                        HatchModel rem = new HatchModel();
                                        foreach (HatchModel hatchModel in plModel.Hatch)
                                        {
                                            if (polyline.Closed && hatchModel.Area.ToString("F2") == polyline.Area.ToString("F2"))
                                            {
                                                legm.BackGround = hatchModel.loopPoints.Count > 0? hatchModel.loopPoints[0].Color:"";
                                                rem             = hatchModel;
                                                break;
                                            }
                                        }
                                        plModel.Hatch.Remove(rem);
                                    }
                                    List <object> obj = new List <object>()
                                    {
                                        plModel
                                    };
                                    legm.GemoModels.Add(plModel);
                                }
                                //if (ob is Polyline && (ob as Polyline).BlockName.ToLower() == "*model_space")
                                //{
                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.PolyLine = AutoCad2ModelTools.Polyline2Model(ob as Polyline);
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is BlockReference && (ob as BlockReference).BlockName.ToLower() == "*model_space")
                                //{
                                //    legm.GemoModels.Add(BlockCommand.AnalysisEntryAndExitbr(ob as BlockReference));
                                //}
                                //else if (ob is DBText && (ob as DBText).BlockName.ToLower() == "*model_space")
                                //{

                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.DbText = AutoCad2ModelTools.DbText2Model(ob as DBText);
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is MText && (ob as MText).BlockName.ToLower() == "*model_space")
                                //{

                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.DbText = AutoCad2ModelTools.DbText2Model(ob as MText);
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is Hatch && (ob as Hatch).BlockName.ToLower() == "*model_space")
                                //{
                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.Hatch = AutoCad2ModelTools.Hatch2Model(ob as Hatch);
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is Circle && (ob as Circle).BlockName.ToLower() == "*model_space")
                                //{
                                //    BlockInfoModel plModel = new BlockInfoModel();
                                //    plModel.Circle.Add(AutoCad2ModelTools.Circle2Model(ob as Circle));
                                //    legm.GemoModels.Add(plModel);
                                //}
                                //else if (ob is Entity)
                                //{

                                //}
                            }
                        }
                        model.LegendList.Add(legm);
                    }
                }
            }
        }
Example #6
0
        public void GetAllYDBMGemo(T model, string layerName)
        {
            if (model != null)
            {
                LayerModel lm  = new LayerModel();
                Document   doc = Application.DocumentManager.MdiActiveDocument;
                Database   db  = doc.Database;

                ObjectIdCollection ids = new ObjectIdCollection();
                lm.Name = layerName;

                PromptSelectionResult ProSset = null;
                TypedValue[]          filList = new TypedValue[1] {
                    new TypedValue((int)DxfCode.LayerName, layerName)
                };
                SelectionFilter sfilter = new SelectionFilter(filList);

                ProSset = doc.Editor.SelectAll(sfilter);
                if (ProSset.Status == PromptStatus.OK)
                {
                    using (Transaction tran = db.TransactionManager.StartTransaction())
                    {
                        SelectionSet sst  = ProSset.Value;
                        ObjectId[]   oids = sst.GetObjectIds();

                        LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
                        foreach (ObjectId layerId in lt)
                        {
                            LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead);
                            if (ltr.Name == layerName)
                            {
                                lm.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue);
                            }
                        }

                        foreach (ObjectId lengGemo in oids)
                        {
                            DBObject            ob             = tran.GetObject(lengGemo, OpenMode.ForRead);
                            PointsPlanItemModel pointsPlanItem = new PointsPlanItemModel();
                            if (ob is Polyline)
                            {
                                Polyline aPl = ob as Polyline;
                                // 读取分图则闭合多段线内的用地代码
                                List <PointF> pfs = new List <PointF>();
                                if (aPl.Closed is true)
                                {
                                    int vn2 = aPl.NumberOfVertices;  //lwp已知的多段线
                                    for (int J = 0; J < vn2; J++)
                                    {
                                        Point2d pt = aPl.GetPoint2dAt(J);
                                        PointF  pf = new PointF((float)pt.X, (float)pt.Y);
                                        pfs.Add(pf);
                                    }
                                }
                                pointsPlanItem.Num = MethodCommand.GetAttrIndex(pfs);
                            }

                            BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob);
                            pointsPlanItem.Geom = plModel;

                            if (lm.modelItemList == null)
                            {
                                lm.modelItemList = new List <object>();
                            }

                            lm.modelItemList.Add(pointsPlanItem);
                        }
                    }

                    if (model.allLines == null)
                    {
                        model.allLines = new List <LayerModel>();
                    }
                    model.allLines.Add(lm);
                }
            }
        }