Example #1
0
        public static HatchModel Hatch2Model(Hatch dbText)
        {
            HatchModel dbModel = new HatchModel();

            int cont = dbText.NumberOfLoops;

            for (int i = 0; i < cont; i++)
            {
                dbModel.loopPoints.Add(i, new ColorAndPointItemModel());
                HatchLoop loop = dbText.GetLoopAt(i);

                ColorAndPointItemModel cpModel = new ColorAndPointItemModel();
                if (i == 0)
                {
                    cpModel.Color = dbText.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(dbText.LayerId) : System.Drawing.ColorTranslator.ToHtml(dbText.Color.ColorValue);
                }
                else
                {
                    cpModel.Color = "#FFFFFF";
                    //  cpModel.ZIndex = "1";
                }

                //if (loop.Polyline.Count == 3)
                //{
                //}

                if (loop.IsPolyline && loop.Polyline.Count > 3)
                {
                    for (int j = 0; j < loop.Polyline.Count - 1; j++)
                    {
                        BulgeVertex vertex  = loop.Polyline[j];
                        BulgeVertex vertex1 = loop.Polyline[j + 1];
                        if (vertex.Bulge != 0)
                        {
                            cpModel.loopPoints.AddRange(MethodCommand.GetArcPointsByBulge(vertex.Vertex, vertex1.Vertex, vertex.Bulge));
                        }
                        else
                        {
                            cpModel.loopPoints.Add(Point2d2Pointf(vertex.Vertex));
                        }
                    }


                    if (dbText.NumberOfHatchLines > 0)
                    {
                        Line2dCollection cl = dbText.GetHatchLinesData();
                    } //foreach (Line2d itemi in )
                      //{

                    //}
                }
                else
                {
                    Curve2dCollection col_cur2d = loop.Curves;
                    foreach (Curve2d item in col_cur2d)
                    {
                        Point2d[] M_point2d = item.GetSamplePoints(20);
                        foreach (Point2d point in M_point2d)
                        {
                            cpModel.loopPoints.Add(Point2d2Pointf(point));
                        }
                    }
                }

                if (cpModel.loopPoints[0] != cpModel.loopPoints[cpModel.loopPoints.Count - 1])
                {
                    cpModel.loopPoints.Add(cpModel.loopPoints[0]);
                }
                dbModel.loopPoints[i] = cpModel;
            }

            for (int i = 0; i < dbModel.loopPoints.Count; i++)
            {
                for (int j = 0; j < dbModel.loopPoints.Count; j++)
                {
                    if (i != j)
                    {
                        if (MethodCommand.PointsAllInPoints(dbModel.loopPoints[j].loopPoints, dbModel.loopPoints[i].loopPoints))
                        {
                            dbModel.loopPoints[j].ZIndex = "2";
                        }
                    }
                }
            }
            try
            {
                dbModel.Area = dbText.Area;
            }
            catch
            { }
            //   dbModel.Color =
            return(dbModel);
        }
Example #2
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 #3
0
        public static HatchModel Hatch2Model(Hatch dbText, AttributeModel atModel)
        {
            HatchModel dbModel = new HatchModel();

            try
            {
                dbModel.Area = dbText.Area;
            }
            catch
            { }

            int    cont  = dbText.NumberOfLoops;
            string color = "";

            for (int i = 0; i < cont; i++)
            {
                dbModel.loopPoints.Add(i, new ColorAndPointItemModel());
                HatchLoop loop = dbText.GetLoopAt(i);

                ColorAndPointItemModel cpModel = new ColorAndPointItemModel();
                if (i == 0)
                {
                    color = cpModel.Color = dbText.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(dbText.LayerId) : System.Drawing.ColorTranslator.ToHtml(dbText.Color.ColorValue);
                }
                else
                {
                    cpModel.Color = "#FFFFFF";
                    //  cpModel.ZIndex = "1";
                }
                if (loop.IsPolyline)
                {
                    for (int j = 0; j < loop.Polyline.Count - 1; j++)
                    {
                        BulgeVertex vertex  = loop.Polyline[j];
                        BulgeVertex vertex1 = loop.Polyline[j + 1];
                        if (vertex.Bulge != 0)
                        {
                            cpModel.loopPoints.AddRange(MethodCommand.GetArcPointsByBulge(vertex.Vertex, vertex1.Vertex, vertex.Bulge));
                        }
                        else
                        {
                            cpModel.loopPoints.Add(Point2d2Pointf(vertex.Vertex));
                        }
                    }


                    if (dbText.NumberOfHatchLines > 0)
                    {
                        Line2dCollection cl = dbText.GetHatchLinesData();
                    } //foreach (Line2d itemi in )
                      //{

                    //}
                }
                else
                {
                    Curve2dCollection col_cur2d = loop.Curves;
                    foreach (Curve2d item in col_cur2d)
                    {
                        Point2d[] M_point2d = item.GetSamplePoints(20);
                        foreach (Point2d point in M_point2d)
                        {
                            cpModel.loopPoints.Add(Point2d2Pointf(point));
                        }
                    }
                }

                if (cpModel.loopPoints[0] != cpModel.loopPoints[cpModel.loopPoints.Count - 1])
                {
                    cpModel.loopPoints.Add(cpModel.loopPoints[0]);
                }
                cpModel.attItemList = new List <AttributeItemModel>();
                foreach (AttributeItemModel item in atModel.attributeItems)
                {
                    string attValue = "";

                    switch (item.AtItemType)
                    {
                    case AttributeItemType.Area:
                        attValue = dbModel.Area.ToString();
                        break;

                    case AttributeItemType.TxtHeight:

                        break;

                    case AttributeItemType.Color:
                        attValue = color;
                        break;

                    case AttributeItemType.Content:

                        break;

                    case AttributeItemType.LayerName:
                        attValue = dbText.Layer;
                        break;

                    case AttributeItemType.LineScale:
                        attValue = dbText.LinetypeScale.ToString();
                        break;

                    case AttributeItemType.LineType:
                        attValue = GetLayerLineTypeByID(dbText);
                        break;

                    case AttributeItemType.Overallwidth:
                        break;

                    case AttributeItemType.TotalArea:
                        attValue = dbModel.Area.ToString();
                        break;
                    }
                    if (!string.IsNullOrEmpty(attValue))
                    {
                        item.AtValue = attValue;
                        cpModel.attItemList.Add(item);
                    }
                    else
                    {
                    }
                }
                dbModel.loopPoints[i] = cpModel;
            }

            for (int i = 0; i < dbModel.loopPoints.Count; i++)
            {
                for (int j = 0; j < dbModel.loopPoints.Count; j++)
                {
                    if (i != j)
                    {
                        if (MethodCommand.PointsAllInPoints(dbModel.loopPoints[j].loopPoints, dbModel.loopPoints[i].loopPoints))
                        {
                            dbModel.loopPoints[j].ZIndex = "2";
                        }
                    }
                }
            }

            //   dbModel.Color =
            return(dbModel);
        }