private vdBlock CreateBlock(BlockData blkData) { vdBlock block = vDraw.ActiveDocument.Blocks.FindName(blkData.Name); if (block != null) { //MessageBox.Show("存在同名块: " + blkData.Name + " 跳过!"); return(null); } block = vDraw.ActiveDocument.Blocks.Add(blkData.Name); if (block == null) { //MessageBox.Show("添加块: " + blkData.Name + " 失败! 跳过!"); return(null); } foreach (MeshData mesh in blkData.Meshs) { AddMeshToEntities(block.Entities, mesh); } foreach (InsertData ins in blkData.Inserts) { AddInsertToEntities(block.Entities, ins); } if (blkData.IsPipe) { var ptStart = new gPoint(blkData.PipeInfo.PtStart.X, blkData.PipeInfo.PtStart.Y, blkData.PipeInfo.PtStart.Z); ptStart = ptStart * Tools.Ft2MmScale; var ptEnd = new gPoint(blkData.PipeInfo.PtEnd.X, blkData.PipeInfo.PtEnd.Y, blkData.PipeInfo.PtEnd.Z); ptEnd = ptEnd * Tools.Ft2MmScale; AddPipeToEntities(block.Entities, blkData.PipeInfo.Diameter * Tools.Ft2MmScale, ptStart, ptEnd, blkData.PipeInfo.MaterialName); if (!blkData.DictProperties.ContainsKey("PipeInfo")) { var pipeProps = new List <PropertyData> { new PropertyData { GroupName = "PipeInfo", Name = "PipeStartPoint", Value = ptStart.ToSplitString() }, new PropertyData { GroupName = "PipeInfo", Name = "PipeEndPoint", Value = ptEnd.ToSplitString() }, new PropertyData { GroupName = "PipeInfo", Name = "PipeDiameter", Value = (blkData.PipeInfo.Diameter * Tools.Ft2MmScale).ToString() } }; blkData.DictProperties.Add("PipeInfo", pipeProps); } } AddXPropertiesToEntity(blkData.DictProperties, block); block.Update(); return(block); }
string GetBlkMd5(vdBlock vdb) { SortedList <string, string> ss = new SortedList <string, string>(); //Dictionary<string, string> dics = new Dictionary<string, string>(); foreach (vdFigure vdf in vdb.Entities) { if (vdf is vdPolyface) { vdPolyface vdp = vdf as vdPolyface; string str1 = Polyface2string(vdp); if (!ss.ContainsKey(str1)) { ss.Add(str1, str1); } } } StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> s in ss) { sb.AppendLine(s.Key); } string str2 = GetMD5HashFromString(sb.ToString()); return(str2); }
private void MoveProperty() { List <string> list1 = new List <string> { "工序编码", "合约类型编码1", "合约类型编码2", "合约类型代码1", "合约类型代码2", "清单编码", //"结构材质", "类型名称" }; foreach (vdFigure vdl in this.vDraw.ActiveDocument.ActiveLayOut.Entities) { if (vdl is vdInsert) { vdInsert vdi = vdl as vdInsert; vdBlock vdb = vdi.Block; foreach (string str in list1) { var prop = GetFigurePropByName(vdb, str); if (prop != null) { vdi.Props += str + "=" + prop + "\r\n"; } } vdb.Props = string.Empty; } } }
/// <summary> /// This button adds the selected block from the library to the current Document. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void butAddMain_Click(object sender, EventArgs e) { string selectedname = (string)listBlocks.SelectedItem; if (selectedname != null && selectedname != "") { vdBlock blk = mdoc.Blocks.FindName(selectedname); if (blk != null) { DialogResult res = MessageBox.Show("A block already exists in the document with this name do you want to ovewrite?", "Info", MessageBoxButtons.YesNo); if (res == DialogResult.No) { return; } } vdBlock blkFromLibrary = vectorDrawBaseControl1.ActiveDocument.Blocks.FindName(selectedname); if (blkFromLibrary != null) { vdBlock blkTogo = new vdBlock(); blkTogo.SetUnRegisterDocument(mdoc); blkTogo.setDocumentDefaults(); blkTogo.MatchProperties(blkFromLibrary, mdoc); mdoc.Blocks.AddItem(blkTogo); LoadMainBlocks(0, blkTogo.Name); } else { MessageBox.Show("An error occured", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// This button removes the selected block from the library's blocks. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void butRemoveBlock_Click(object sender, EventArgs e) { string selectedname = (string)listBlocks.SelectedItem; if (selectedname != null && selectedname != "") { vdBlock blk = vectorDrawBaseControl1.ActiveDocument.Blocks.FindName(selectedname); if (blk != null) { DrawPreview(null); vectorDrawBaseControl1.ActiveDocument.Blocks.RemoveItem(blk); this.butSave.Enabled = true; } LoadLibraryBlocks(null); } }
/// <summary> /// Initializes the dialog. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditCreateBlock_Load(object sender, EventArgs e) { vdFramedControl1.BaseControl.ActiveDocument.New(); if (mblk == null) { textName.Text = ""; butAddInsertionPoint.Enabled = true; } else { textName.Text = mblk.Name; butAddInsertionPoint.Enabled = false; vdBlock block = new vdBlock(); block.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); block.setDocumentDefaults(); block.MatchProperties(mblk, vdFramedControl1.BaseControl.ActiveDocument); vdFramedControl1.BaseControl.ActiveDocument.Blocks.AddItem(block); vdInsert ins = new vdInsert(); ins.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); ins.setDocumentDefaults(); ins.Block = block; vdFramedControl1.BaseControl.ActiveDocument.Model.Entities.AddItem(ins); vdFramedControl1.BaseControl.ActiveDocument.CommandAction.CmdExplode(ins); ins.Deleted = true; vdPoint pt = new vdPoint(); pt.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); pt.setDocumentDefaults(); pt.InsertionPoint = new gPoint(); pt.PenColor.SystemColor = Color.Red; pt.Label = "VD_TMP_ORIGIN"; vdFramedControl1.BaseControl.ActiveDocument.Model.Entities.AddItem(pt); vdFramedControl1.BaseControl.ActiveDocument.CommandAction.Zoom("E", 0, 0); vdFramedControl1.BaseControl.ActiveDocument.CommandAction.Zoom("S", 0.95, 0); vdFramedControl1.BaseControl.ActiveDocument.Redraw(true); } vdFramedControl1.BaseControl.ActiveDocument.OnUndoStoreValue += new vdDocument.UndoStoreValueEventHandler(ActiveDocument_OnUndoStoreValue); //LOAD EditBlocksCOMMANDS / EditBlocksMENU vdFramedControl1.UnLoadCommands(); vdFramedControl1.UnLoadMenu(); vdFramedControl1.LoadCommands(GetResourcesPath(), "BlockLibraryCommands.txt"); vdFramedControl1.LoadMenu(GetResourcesPath(), "BlockLibraryMenu.txt"); vdFramedControl1.ShowMenu(true); }
/// <summary> /// 处理车位编号 /// </summary> /// <returns></returns> void ProCarNum(vdDocument doc, string PropName, double width, double height) { 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) { //删除原来的文字 vdBlock vdb = vdi.Block; for (int i = vdb.Entities.Count - 1; i >= 0; i--) { if (vdb.Entities[i] is vdText) { vdb.Entities.RemoveAt(i); } } //文字样式 vdTextstyle vdts = doc.TextStyles.FindName("车位编号"); if (vdts == null) { vdts = new vdTextstyle(doc); vdts.Height = height / 5.0; } //字体 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; Box bb = vdb.BoundingBox(); vdt.InsertionPoint = new gPoint(bb.MidPoint.x, bb.Min.y + height / 2.0, bb.Min.z); vdb.Entities.Add(vdt); } } } }
/// <summary> /// This button opens the other form(EditCreateBlock.cs) in order to Create a new block to the library. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void butCreateBlock_Click(object sender, EventArgs e) { EditCreateBlock frm = new EditCreateBlock(); frm.InitializeDialog(null, vectorDrawBaseControl1.ActiveDocument); frm.ShowDialog(this); vdBlock exported = frm.ExportedBlock; if (exported != null) { this.butSave.Enabled = true; vdBlock blk = new vdBlock(); blk.SetUnRegisterDocument(vectorDrawBaseControl1.ActiveDocument); blk.setDocumentDefaults(); blk.MatchProperties(exported, vectorDrawBaseControl1.ActiveDocument); vectorDrawBaseControl1.ActiveDocument.Blocks.AddItem(blk); LoadLibraryBlocks(exported.Name); DrawPreview(exported.Name); } }
/// <summary> /// Closes the dialog with an ok return message. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void butOk_Click(object sender, EventArgs e) { if (textName.Text == "") { MessageBox.Show("Please set a name for the block!!!", "", MessageBoxButtons.OK, MessageBoxIcon.Question); ExportedBlock = null; return; } bool OriginExists = false; ExportedBlock = new vdBlock(); ExportedBlock.SetUnRegisterDocument(mDoc); ExportedBlock.setDocumentDefaults(); foreach (vdFigure var in vdFramedControl1.BaseControl.ActiveDocument.Model.Entities) { if (var.Deleted) { continue; } if (var is vdPoint && var.Label == "VD_TMP_ORIGIN") { vdPoint vdPt = var as vdPoint; gPoint pt = vdFramedControl1.BaseControl.ActiveDocument.User2WorldMatrix.Transform(vdPt.InsertionPoint); ExportedBlock.Origin = new gPoint(pt); OriginExists = true; } else { ExportedBlock.Entities.AddItem(var.Clone(mDoc) as vdFigure); } } if (!OriginExists) { MessageBox.Show("Please set an Origin Point for the block!!!", "", MessageBoxButtons.OK, MessageBoxIcon.Question); ExportedBlock = null; return; } ExportedBlock.Name = textName.Text; this.DialogResult = DialogResult.OK; this.Close(); }
private vdBlock GetSphereBlk() { vdBlock blk = vDraw.ActiveDocument.Blocks.FindName("_PointMark"); if (blk == null) { vDraw.ActiveDocument.ActivePenColor.ColorIndex = 9; vDraw.ActiveDocument.CommandAction.CmdSphere(new gPoint(0, 0, 0), 1.0, 10, 10); vdFigure vdf = vDraw.ActiveDocument.ActiveLayOut.Entities.Last; if (vdf is vdPolyface) { (vdf as vdPolyface).SmoothAngle = 30; blk = new vdBlock(vDraw.ActiveDocument, "_PointMark"); blk.Entities.Add(vdf.Clone(vDraw.ActiveDocument)); vDraw.ActiveDocument.Blocks.Add(blk); vdf.Deleted = true; return(blk); } return(null); } return(blk); }
/// <summary> /// This button opens the other form(EditCreateBlock.cs) in order to edit the selected block from the library. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void butEdit_Click(object sender, EventArgs e) { string selectedname = (string)listBlocks.SelectedItem; if (selectedname != null && selectedname != "") { vdBlock blk = vectorDrawBaseControl1.ActiveDocument.Blocks.FindName(selectedname); if (blk != null) { EditCreateBlock frm = new EditCreateBlock(); frm.InitializeDialog(blk, vectorDrawBaseControl1.ActiveDocument); frm.ShowDialog(this); vdBlock exported = frm.ExportedBlock; if (exported != null) { this.butSave.Enabled = true; blk.MatchProperties(exported, vectorDrawBaseControl1.ActiveDocument); LoadLibraryBlocks(exported.Name); DrawPreview(exported.Name); } } } }
/// <summary> /// This method is called before showing this dialog in order to initialize important variables. /// </summary> /// <param name="blk">The block to be edited or null if a new block is going to be created.</param> /// <param name="doc">A vdDocument object needed for initial values.</param> public void InitializeDialog(vdBlock blk, vdDocument doc) { mDoc = doc; mblk = blk; }
/// <summary> /// Closes the dialog with a cancel return message. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void butCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; ExportedBlock = null; this.Close(); }
/// <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); //处理车位编号 }