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(); }
/// <summary> /// 替换字体 /// </summary> /// <param name="vdbs"></param> private void ReplaceText(vdBlocks vdbs, vdDocument doc, double width, double height, string PropName) { //doc.Purge(); Dictionary <string, string> BlksMap = new Dictionary <string, string>(); Dictionary <string, string> BlksMapTmp = new Dictionary <string, string>(); //删除车位编号 foreach (vdFigure vdf in doc.ActiveLayOut.Entities) { if (vdf is vdInsert) { vdInsert vdi = vdf as vdInsert; vdXProperty vdx = vdi.XProperties.FindName(PropName); if (vdx != null) { string strName = vdx.PropValue.ToString(); vdBlock vdb = vdi.Block; Box box = vdb.BoundingBox(); Box textbox = new Box(new gPoint(box.MidPoint.x - width / 2.0, box.Min.y), new gPoint(box.MidPoint.x + width / 2.0, box.Min.y + height)); vdArray <vdFigure> vda = new vdArray <vdFigure>(); foreach (vdFigure vdff in vdb.Entities) { if (vdff is vdPolyface) { if (vdff.BoundingBox.BoxInBox(textbox)) { vda.AddItem(vdff); } } } Box b = new Box(); foreach (vdFigure vdf1 in vda) { b.AddBox(vdf1.BoundingBox); vdb.Entities.RemoveItem(vdf1); } //文字样式 vdTextstyle vdts = doc.TextStyles.FindName("车位编号"); if (vdts == null) { vdts = new vdTextstyle(doc); vdts.Name = "车位编号"; vdts.Height = b.Height; //MessageBox.Show(b.Height.ToString()); doc.TextStyles.Add(vdts); } //文字 vdText vdt = new vdText(doc); vdt.Style = vdts; vdt.TextString = vdx.PropValue.ToString(); vdt.HorJustify = VectorDraw.Professional.Constants.VdConstHorJust.VdTextHorCenter; vdt.VerJustify = VectorDraw.Professional.Constants.VdConstVerJust.VdTextVerCen; vdt.InsertionPoint = b.MidPoint; vdb.Entities.AddItem(vdt); vdf.Invalidate(); vdf.Update(); string ssss = GetBlkMd5(vdi.Block); if (!BlksMap.ContainsKey(vdi.Block.Name)) { BlksMap.Add(vdi.Block.Name, ssss); } else { MessageBox.Show("可能存在重复编号的车位,请仔细查看!"); } } } } //查找md5的计数 Dictionary <string, int> md5count = new Dictionary <string, int>(); foreach (KeyValuePair <string, string> kv in BlksMap) { if (!md5count.ContainsKey(kv.Value)) { md5count.Add(kv.Value, 1); } else { md5count[kv.Value]++; } } foreach (KeyValuePair <string, string> kv in BlksMap) { if (md5count[kv.Value] > 1) { vdBlock vdb2 = doc.Blocks.FindName(kv.Value); vdBlock vdb = doc.Blocks.FindName(kv.Key); if (vdb2 == null) //md5码的块不存在的话 { if (vdb != null) { vdBlock vdb1 = vdb.Clone(doc) as vdBlock; for (int i = vdb1.Entities.Count - 1; i >= 0; i--) { if (vdb1.Entities[i] is vdText) { vdb1.Entities.RemoveItem(vdb1.Entities[i]); } } vdb1.Name = kv.Value; doc.Blocks.Add(vdb1); } } //原来的内容作为一个块,加进去 for (int i = vdb.Entities.Count - 1; i >= 0; i--) { if (!(vdb.Entities[i] is vdText)) { vdb.Entities.RemoveItem(vdb.Entities[i]); } } //vdb.Entities.RemoveAll(); vdInsert vdi = new vdInsert(doc); vdi.Block = doc.Blocks.FindName(kv.Value); // vdb.Entities.Add(vdi); //将字体加上去 vdb.Update(); } } //ProCarNum(doc, PropName, width, height); //处理车位编号 }
/// <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(); }
void BaseControl_vdMouseDown(MouseEventArgs e, ref bool cancel) { Childform frm = this.ActiveMdiChild as Childform; if (frm == null) { return; } if (e.Button != MouseButtons.Left) { return; } if (frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveActions == null) { return; } if (frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveActions.Count > 1) { return; } if (frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveAction is VectorDraw.Professional.CommandActions.ActionLine) { return; } vdSelection GripEntities = GetGripsCollection(); gPoint p1 = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.World2Pixelmatrix.Transform(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveAction.MouseLocation); gPoint p1viewCS = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.CurrentMatrix.Transform(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveAction.MouseLocation); Point location = new Point((int)p1.x, (int)p1.y); #region Grip Move Code if (System.Windows.Forms.Control.ModifierKeys == Keys.None) { Box box = new Box(); box.AddPoint(p1viewCS); box.AddWidth(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.GlobalProperties.GripSize * frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.PixelSize / 2.0d); vdSelection selset = new vdSelection(); vdArray <Int32Array> indexesArray = new vdArray <Int32Array>(); gPoint pt = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.Document.World2UserMatrix.Transform(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.OverAllActiveAction.MouseLocation); foreach (vdFigure fig in GripEntities) { Int32Array indexes = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.getGripIndexes(fig, box); if (indexes.Count != 0) { selset.AddItem(fig, false, vdSelection.AddItemCheck.Nochecking); indexesArray.AddItem(indexes); } } if (selset.Count > 0) { VectorDraw.Professional.ActionUtilities.CmdMoveGripPoints MoveGrips = new VectorDraw.Professional.ActionUtilities.CmdMoveGripPoints(pt, frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut, selset, indexesArray); frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActionAdd(MoveGrips); VectorDraw.Actions.StatusCode ret = MoveGrips.WaitToFinish(); cancel = true; return; } } #endregion #region One by One implementation vdFigure Fig = null; Fig = frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.GetEntityFromPoint(location, frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.GlobalProperties.PickSize, false, vdDocument.LockLayerMethodEnum.EnableGetObjectGrip); frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.Document.LockLayerMethodStack.Push(vdDocument.LockLayerMethodEnum.DisableAll | ((frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.Document.LockLayerMethod & vdDocument.LockLayerMethodEnum.EnableGetObjectGrip) != 0 ? vdDocument.LockLayerMethodEnum.EnableAddToSelections : 0)); bool bShift = ((System.Windows.Forms.Control.ModifierKeys & Keys.Shift) == Keys.Shift); if (Fig != null) { ClearAllGrips(GripEntities); GripEntities.AddItem(Fig, true, vdSelection.AddItemCheck.RemoveInVisibleEntities); if (cancel) { Fig.ShowGrips = false; } else { Fig.ShowGrips = true; } frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.RefreshGraphicsControl(frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.ActiveActionRender.control); // DrawGrips(GripEntities); } frm.vdScrollableControl1.BaseControl.ActiveDocument.ActiveLayOut.Document.LockLayerMethodStack.Pop(); #endregion }