/// <summary>
        /// 旧的合并方法,已经弃用
        /// </summary>
        /// <param name="v"></param>
        /// <param name="p"></param>
        public static void Merge1(VectorDrawBaseControl v, FormProgress p)
        {
            p.Text = "合并面片...";
            int ii    = 0;
            int count = v.ActiveDocument.Blocks.Count;

            vdArray <vdBlock> blocks = new vdArray <vdBlock>();

            foreach (vdBlock vdb in v.ActiveDocument.Blocks)
            {
                if (vdb.Entities.Count == 0)
                {
                    blocks.AddItem(vdb);
                }

                int percent = (int)((++ii * 1.0 / count) * 100);

                p.SetProgress(percent);

                Dictionary <string, vdPolyface> layFaces = new Dictionary <string, vdPolyface>();
                Dictionary <int, int>           ids      = new Dictionary <int, int>();
                foreach (vdFigure vdf in vdb.Entities)
                {
                    if (vdf is vdPolyface)
                    {
                        vdPolyface vdp = vdf as vdPolyface;

                        if (!layFaces.ContainsKey(vdp.Layer.Name))
                        {
                            layFaces.Add(vdp.Layer.Name, vdp);
                            ids.Add(vdp.Id, vdp.Id);
                        }
                        else
                        {
                            layFaces[vdp.Layer.Name].MergePolyface1(vdp);
                        }
                    }
                }
                for (int i = vdb.Entities.Count - 1; i >= 0; i--)
                {
                    vdFigure vdf = vdb.Entities[i];
                    if (vdf is vdPolyface && ids.ContainsKey(vdf.Id))
                    {
                        vdPolyface vdp1 = vdf as vdPolyface;
                        if (vdp1.FaceList.Count > 0)
                        {
                            vdp1.ClearVerticies();
                        }
                        else
                        {
                            vdb.Entities.RemoveItem(vdf);
                            vdf.Dispose();
                            vdf = null;
                        }
                    }
                    else if (vdf is vdPolyface)
                    {
                        vdb.Entities.RemoveItem(vdf);
                        vdf.Dispose();
                        vdf = null;
                    }
                }
            }
            foreach (vdBlock vdb in blocks)
            {
                v.ActiveDocument.Blocks.RemoveItem(vdb);
                vdb.Dispose();
                //vdb = null;
            }
            GC.Collect();
        }
        public static void Merge(VectorDrawBaseControl v, FormProgress p)
        {
            p.Text = "合并面片...";

            int ii    = 0;
            int count = v.ActiveDocument.Blocks.Count;
            vdArray <vdBlock> blocks = new vdArray <vdBlock>();
            bool LargeNum            = false;

            foreach (vdBlock vdb in v.ActiveDocument.Blocks)
            {
                if (vdb.Entities.Count == 0)
                {
                    blocks.AddItem(vdb);
                }
                ii++;
                int value = (ii * 100) / count;
                Dictionary <string, vdPolyface> layFaces = new Dictionary <string, vdPolyface>();
                Dictionary <int, int>           ids      = new Dictionary <int, int>();
                int icount = 0;

                p.SetProgress(value);

                //if (vdb.Entities.Count > 5000)
                //{
                //    LargeNum = true;
                //}
                //else
                //{
                //    LargeNum = false;
                //}

                foreach (vdFigure vdf in vdb.Entities)
                {
                    if (vdf is vdPolyface)
                    {
                        vdPolyface vdp = vdf as vdPolyface;

                        if (!layFaces.ContainsKey(vdp.Layer.Name))
                        {
                            layFaces.Add(vdp.Layer.Name, vdp);
                            ids.Add(vdp.Id, vdp.Id);
                        }
                        else
                        {
                            layFaces[vdp.Layer.Name].MergePolyface1(vdp);
                        }

                        //if (LargeNum)
                        //{
                        //    icount++;
                        //}
                    }
                }

                icount = 0;
                for (int i = vdb.Entities.Count - 1; i >= 0; i--)
                {
                    vdFigure vdf = vdb.Entities[i];
                    if (vdf is vdPolyface && ids.ContainsKey(vdf.Id))
                    {
                        vdPolyface vdp1 = vdf as vdPolyface;
                        if (vdp1.FaceList.Count > 0)
                        {
                            vdp1.ClearVerticies1();
                        }
                        else
                        {
                            vdb.Entities.RemoveItem(vdf);
                            vdf.Dispose();
                            vdf = null;
                        }
                    }
                    else if (vdf is vdPolyface)
                    {
                        vdb.Entities.RemoveItem(vdf);
                        vdf.Dispose();
                        vdf = null;
                    }

                    //if (LargeNum)
                    //{
                    //    icount++;
                    //}
                }

                //vdb.Update();
            }
            foreach (vdBlock vdb in blocks)
            {
                v.ActiveDocument.Blocks.RemoveItem(vdb);
                vdb.Dispose();
                //vdb = null;
            }


            GC.Collect();
        }
Beispiel #3
0
        public void BeginConvert()
        {
            if (ExportSetting.SystemSetting.IsExportTextureFile)
            {
                ProcessMaterialMapFile();
            }

            // 特别指非bim格式
            if (ExportSetting.SystemSetting.IsUserDefineFormat)
            {
                var ser = new ModelSerializeEntity
                {
                    Blocks    = DictBlocks,
                    Materials = Materials,
                    Levels    = Levels
                };

                if (File.Exists(ExportSetting.SystemSetting.ExportFilePath))
                {
                    File.Delete(ExportSetting.SystemSetting.ExportFilePath);
                }


                if (ExportSetting.SystemSetting.FileType == SystemSetting.FileTypeEnum.bfa)
                {
                    var str = JsonConvert.SerializeObject(ser);
                    File.WriteAllText(ExportSetting.SystemSetting.ExportFilePath, str);
                }
                else
                {
                    using (FileStream fs = File.OpenWrite(ExportSetting.SystemSetting.ExportFilePath))
                    {
                        if (IsZipFile)
                        {
                            MemoryStream ms = new MemoryStream();
                            ProtoBuf.Serializer.Serialize(ms, ser);

                            var buffer = ms.ToArray();
                            var compressedzipStream = new DeflateStream(fs, CompressionMode.Compress, true);
                            compressedzipStream.Write(buffer, 0, buffer.Length);
                            compressedzipStream.Close();
                        }
                        else
                        {
                            ProtoBuf.Serializer.Serialize(fs, ser);
                        }
                    }
                }
            }
            // 指bim格式
            else
            {
                InitRenderProperty();

                if (m_formProgress == null || m_formProgress.IsDisposed)
                {
                    m_formProgress = new FormProgress();
                }

                m_formProgress.Show(this.WndParent);

                if (this.ExportSetting.SystemSetting.IsExportRebar)
                {
                    AddRebarData();
                }
                else
                {
                    InitMaterialLayersAandImages();
                    InitEntityInModelBlock();
                    AddGridPolyline();
                    AddLevelData();

                    if (ExportSetting.SystemSetting.IsOptimizeCylinderFace)
                    {
                        m_formProgress.Text = "正在优化数据...";
                        ReduceTris.CRevit2vdl redTri = new ReduceTris.CRevit2vdl
                        {
                            FamilySketchDictionary     = this.FamilySketchDictionary,
                            InstanceLocationDictionary = this.InstanceLocationCurveDictionary
                        };
                        redTri.Convert(vDraw.ActiveDocument, m_formProgress.progressBar);
                    }

                    if (this.ExportSetting.SystemSetting.IsMergeFace)
                    {
                        MergeFace.Merge(vDraw, m_formProgress);
                    }

                    if (this.ExportSetting != null && this.ExportSetting.ParkingExportSetting.PropertyName.Length > 0)
                    {
                        ReplaceParkingNumber replaceNumber = new ReplaceParkingNumber(vDraw);
                        replaceNumber.Setting = this.ExportSetting.ParkingExportSetting;
                        replaceNumber.ReplaceText();
                    }
                }

                vDraw.ActiveDocument.ActiveLayOut.Entities.Sort(new CompareMethod());

                if (this.ExportSetting.SystemSetting.IsMoveBlkXpropertyToInsert)
                {
                    MoveProperty();
                }

                RemoveEmptyFigure();

                vDraw.Progress     += vDraw_Progress;
                m_formProgress.Text = "正在保存";
                bool bResult = vDraw.ActiveDocument.SaveAs(ExportSetting.SystemSetting.ExportFilePath);
                m_formProgress?.Close();
                vDraw.Progress -= vDraw_Progress;
            }
        }