| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659 |
- using GrxCAD.ApplicationServices;
- using GrxCAD.DatabaseServices;
- using GrxCAD.EditorInput;
- using GrxCAD.Geometry;
- using GrxCAD.Runtime;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace Thumbnail
- {
- public class tkinfo
- {
- public Point3dCollection ptcoll; //图幅框节点
- public string tfh; //节点
- public ObjectId id; //图幅框id
- public ObjectId tfhid; //图幅号id
- }
-
- public class getThumbnail
- {
- public static double bl;
- public static string tc_tk;
- public static string tc_tfh;
- //public static int jtk;
-
- /// <summary>
- /// 替换接图框
- /// </summary>
- public void openDwg(String fileName, String insertpath, String savepath)
- {
- DirectoryInfo root = new DirectoryInfo(fileName);
- List<String> filename = new List<string>(); //文件名
- FileInfo[] files = root.GetFiles();
- foreach (FileInfo file in files)
- {
- if (!file.Name.Contains(".dwg"))
- continue;
- else
- filename.Add(file.Name);
- }
- for (int filenum = 0; filenum < filename.Count; filenum++)
- {
- string fileName2 = fileName + "\\" + filename[filenum];
- Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.Add(fileName2);
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- List<tkinfo> tf = new List<tkinfo>(); //与本图幅相交的图幅
- List<tkinfo> tkinfolist = new List<tkinfo>(); //存放图框坐标和图幅号
- //using (DocumentLock docLock = doc.LockDocument())
- //{
- Point3dCollection ptcoll = new Point3dCollection();
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE"),
- new TypedValue((int)DxfCode.LayerName,"9800")
- };
- SelectionFilter filter = new SelectionFilter(value);
- PromptSelectionResult psr = ed.SelectAll(filter);
- //获取9800图层中最长的四条线,它们的交点即为内图框角点
- if (psr.Status == PromptStatus.OK)
- {
- ObjectIdCollection pllcoll = new ObjectIdCollection();
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll1 = new ObjectIdCollection(ss.GetObjectIds());
- double searchlength = 250 * bl + 5.75 * bl * 2;
- if(bl==10)
- searchlength = 2595;
- for (int i = 0; i < idcoll1.Count; i++)
- {
- using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
- {
- Entity ent = trans.GetObject(idcoll1[i], OpenMode.ForRead) as Entity;
- if (ent is Polyline)
- {
- Polyline pll = (Polyline)ent;
- if (pll.Length == searchlength & pll.Closed == false)
- pllcoll.Add(idcoll1[i]);
- }
- if (ent is Polyline2d)
- {
- Polyline2d pll = (Polyline2d)ent;
- if (pll.Length == searchlength & pll.Closed == false)
- pllcoll.Add(idcoll1[i]);
- }
- trans.Commit();
- }
- }
- getIntersectpts(pllcoll, doc, ptcoll);
- }
- sortpts(ptcoll);
- deletetc(doc, ptcoll);
-
- copytoCurrent(doc, insertpath, true);
- getTKinfo(doc, tkinfolist);//获取图框信息
- getIntersecttk(tkinfolist, ptcoll, tf);
- move(doc, tkinfolist, tf, ptcoll);
- deletetk(doc, tkinfolist, tf);
- ObjectId HZ = createTextStyle(doc);
- draw(doc, ptcoll, tf, HZ);
- if (tf.Count == 0 || tf == null)
- {
- for (int i = 0; i < tkinfolist.Count; i++)
- {
- using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- Point3dCollection pts = new Point3dCollection();
- Entity ent1 = tran.GetObject(tkinfolist[i].id, OpenMode.ForWrite) as Entity;
- Entity ent2 = tran.GetObject(tkinfolist[i].tfhid, OpenMode.ForWrite) as Entity;
- ent1.Erase();
- ent2.Erase();
- if (i == tkinfolist.Count - 1)
- {
- LayerTable layerTable = tran.GetObject(doc.Database.LayerTableId, OpenMode.ForWrite) as LayerTable;
- LayerTableRecord layer = tran.GetObject(layerTable[tc_tfh], OpenMode.ForWrite) as LayerTableRecord;
- layer.Erase(true);
- if (tc_tfh != tc_tk)
- {
- layer = tran.GetObject(layerTable[tc_tk], OpenMode.ForWrite) as LayerTableRecord;
- layer.Erase(true); // 删除图层
- }
- }
- tran.Commit();
- }
- }
- }
- dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- acadApp.ZoomExtents();
- doc.Database.SaveAs(savepath + "\\" + filename[filenum], true, DwgVersion.AC1024, doc.Database.SecurityParameters);
- doc.CloseAndDiscard();
- }
- MessageBox.Show("替换完成");
- }
-
- /// <summary>
- /// 获取图框信息
- /// </summary>
- private void getTKinfo(Document doc, List<tkinfo> tkinfolist)
- {
- //获取图框和图幅号
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,tc_tk),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE")
- };
- SelectionFilter filter = new SelectionFilter(value);
- PromptSelectionResult psr = ed.SelectAll(filter);
- TypedValue[] value_text = new TypedValue[]
- {
- new TypedValue((int)DxfCode.Start,"Text"),
- new TypedValue((int)DxfCode.LayerName,tc_tfh)
- };
- SelectionFilter filter_text = new SelectionFilter(value_text);
- PromptSelectionResult psr_text = ed.SelectAll(filter_text);
- if (psr.Status == PromptStatus.OK && psr_text.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- SelectionSet ss_text = psr_text.Value;
- ObjectIdCollection idcoll_text = new ObjectIdCollection(ss_text.GetObjectIds());
- for (int i = 0; i < idcoll.Count; i++)
- {
- int j = 0;
- int flag = 0;
- while (idcoll_text.Count != 0)
- {
- using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
- {
- Point3dCollection ptcoll = new Point3dCollection();
- Entity ent = tran.GetObject(idcoll[i], OpenMode.ForRead) as Entity;
- if (ent is Polyline)
- {
- Polyline pll = tran.GetObject(idcoll[i], OpenMode.ForRead) as Polyline;
- pll.GetStretchPoints(ptcoll);
- }
- if (ent is Polyline2d)
- {
- Polyline2d pll = tran.GetObject(idcoll[i], OpenMode.ForRead) as Polyline2d;
- pll.GetStretchPoints(ptcoll);
- }
- DBText text = tran.GetObject(idcoll_text[j], OpenMode.ForRead) as DBText;
- //获取框线角点并将其按特定顺序排列
- List<double> X = new List<double>();
- List<double> Y = new List<double>();
- for (int ii = 0; ii < 4; ii++)
- {
- if (!X.Contains(ptcoll[ii].X))
- X.Add(ptcoll[ii].X);
- if (!Y.Contains(ptcoll[ii].Y))
- Y.Add(ptcoll[ii].Y);
- }
- if (X[1] < X[0])
- {
- Double temp = X[0];
- X[0] = X[1];
- X[1] = temp;
- }
- if (Y[1] < Y[0])
- {
- Double temp = Y[0];
- Y[0] = Y[1];
- Y[1] = temp;
- }
- tkinfo pt = new tkinfo();
- pt.ptcoll = ptcoll;
- pt.id = idcoll[i];
- pt.tfhid = idcoll_text[j];
- //获取图幅号坐标
- double x = text.Position.X;
- double y = text.Position.Y;
- //判断图框对应图幅号
- if (x > X[0] && y > Y[0] && x < X[1] && y > Y[0] &&
- x < X[1] && y < Y[1] && x > X[0] && y < Y[1])
- {
- String tfh = text.TextString;
- pt.tfh = tfh;
- idcoll_text.RemoveAt(j);
- tkinfolist.Add(pt);
- flag = 1;
- }
- tran.Commit();
- if (flag == 1)
- break;
- }
- j = j + 1;
- }
- }
- }
- }
-
- /// <summary>
- /// 将分幅图加入当前视图
- /// </summary>
- private void copytoCurrent(Document doc, String insertpath, bool explode)
- {
- ObjectIdCollection idsToClone = new ObjectIdCollection();
- ObjectId btrId;
- //using (DocumentLock docTargetLock = doc.LockDocument())
- //{
- using (Transaction trTarget = doc.TransactionManager.StartTransaction())
- {
- LayerTable layerTable = trTarget.GetObject(doc.Database.LayerTableId, OpenMode.ForRead) as LayerTable;
- ObjectId layerId = layerTable["0"];
- doc.Database.Clayer = layerId;
- var targetBlockTable = trTarget.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
- var targetModelSpace = trTarget.GetObject(targetBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
- btrId = targetModelSpace.ObjectId;
- trTarget.Commit();
- }
- using (var sourceDb = new Database(false, true))
- {
- sourceDb.ReadDwgFile(insertpath, FileOpenMode.OpenForReadAndAllShare, false, null);
- using (Transaction trSource = sourceDb.TransactionManager.StartTransaction())
- {
- var modelSpaceSource = trSource.GetObject(
- SymbolUtilityServices.GetBlockModelSpaceId(sourceDb),
- OpenMode.ForRead) as BlockTableRecord;
-
- foreach (ObjectId objId in modelSpaceSource)
- {
- var entity = trSource.GetObject(objId, OpenMode.ForRead) as Entity;
- if (entity != null && (entity.Layer == tc_tk || entity.Layer == tc_tfh))
- idsToClone.Add(objId);
- }
- using (var mapping = new IdMapping())
- sourceDb.WblockCloneObjects(idsToClone, btrId, mapping, DuplicateRecordCloning.Replace, false);
- trSource.Commit();
- }
- }
-
- //}
- }
-
-
- /// <summary>
- /// 获取内图框四个角点
- /// </summary>
- private void getIntersectpts(ObjectIdCollection pllcoll, Document doc, Point3dCollection ptcoll)
- {
- using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
- {
- for (int k = 0; k < pllcoll.Count - 1; k++)
- {
- Point3dCollection intersectpt = new Point3dCollection();
- for (int kk = k + 1; kk < pllcoll.Count; kk++)
- {
- Entity ent1 = trans.GetObject(pllcoll[k], OpenMode.ForRead) as Entity;
- Entity ent2 = trans.GetObject(pllcoll[kk], OpenMode.ForRead) as Entity;
- if (ent1 is Polyline && ent2 is Polyline)
- {
- Polyline pll1 = (Polyline)ent1;
- Polyline pll2 = (Polyline)ent2;
- pll1.IntersectWith(pll2, Intersect.OnBothOperands, intersectpt, IntPtr.Zero, IntPtr.Zero);
- //foreach (Point3d pt in intersectpt)
- //{
- // if (pt == pll1.StartPoint || pt == pll1.EndPoint ||pt = pll2.StartPoint || pt == pll2.EndPoint)
- // intersectpt.Remove(pt);
- //}
- }
- if (ent1 is Polyline2d && ent2 is Polyline2d)
- {
- Polyline2d pll1 = (Polyline2d)ent1;
- Polyline2d pll2 = (Polyline2d)ent2;
- pll1.IntersectWith(pll2, Intersect.OnBothOperands, intersectpt, IntPtr.Zero, IntPtr.Zero);
- }
-
- if (intersectpt.Count != 0)
- {
- for (int kkk = 0; kkk < intersectpt.Count; kkk++)
- {
- if (ptcoll.Contains(intersectpt[kkk]))
- continue;
- else
- ptcoll.Add(intersectpt[kkk]);
- }
- }
- }
- }
- trans.Commit();
- }
- }
-
- /// <summary>
- /// 获取与当前图幅相交的图框
- /// </summary>
- private void getIntersecttk(List<tkinfo> tkinfolist, Point3dCollection ptcoll, List<tkinfo> tf)
- {
- //ObjectIdCollection ids= new ObjectIdCollection();
- for (int j = 0; j < tkinfolist.Count; j++)
- {
- //找出tkinfolist中的此图幅
- if (tkinfolist[j].ptcoll.Contains(ptcoll[0]) && tkinfolist[j].ptcoll.Contains(ptcoll[1]) &&
- tkinfolist[j].ptcoll.Contains(ptcoll[2]) && tkinfolist[j].ptcoll.Contains(ptcoll[3]))
- {
- sortpts(tkinfolist[j].ptcoll);
- double plusnum = Math.Abs(tkinfolist[j].ptcoll[0].X - tkinfolist[j].ptcoll[2].X);
- //创建扩大一倍的窗口搜索相交图幅
- Point3d pt1 = new Point3d(tkinfolist[j].ptcoll[0].X - plusnum, tkinfolist[j].ptcoll[0].Y - plusnum, 0);
- Point3d pt2 = new Point3d(tkinfolist[j].ptcoll[2].X + plusnum, tkinfolist[j].ptcoll[2].Y + plusnum, 0);
-
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,tc_tk)
- };
- SelectionFilter filter = new SelectionFilter(value);
-
- dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- acadApp.ZoomExtents();
- //使用找出的图幅号内框线交点进行相交选择以选出与此图幅相交的其他图幅
- //PromptSelectionResult psr = ed.SelectCrossingPolygon(tkinfolist[j].ptcoll, filter);
- //ViewTableRecord view = ed.GetCurrentView();
- //view.Width = Math.Abs(3* (ptcoll[0].X - ptcoll[1].X));
- //view.Height = Math.Abs(3 * (ptcoll[0].Y - ptcoll[2].Y));
- //view.CenterPoint = new Point2d(
- // ptcoll[0].X + Math.Abs((ptcoll[0].X - ptcoll[1].X)) / 2,
- // ptcoll[0].Y + Math.Abs((ptcoll[0].Y - ptcoll[2].Y)) / 2
- //);
- //ed.SetCurrentView(view);
- PromptSelectionResult psr = ed.SelectCrossingWindow(pt1, pt2, filter);
- acadApp.ZoomPrevious();
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- for (int i = 0; i < idcoll.Count; i++)
- {
- if (idcoll[i] != tkinfolist[j].id)
- {
- //ids.Add(idcoll[i]);
- for (int ii = 0; ii < tkinfolist.Count; ii++)
- {
- if (idcoll[i] == tkinfolist[ii].id)
- {
- //获取相交图幅的相应信息
- foreach (Point3d temppt in tkinfolist[ii].ptcoll)
- {
- //筛选窗口内图幅
- if (Math.Round(temppt.X, 4) > Math.Round(pt1.X, 4) &&
- Math.Round(temppt.X, 4) < Math.Round(pt2.X, 4) &&
- Math.Round(temppt.Y, 4) > Math.Round(pt1.Y, 4) &&
- Math.Round(temppt.Y, 4) < Math.Round(pt2.Y, 4))
- {
- tkinfo pt = new tkinfo();
- pt.id = tkinfolist[ii].id;
- pt.ptcoll = tkinfolist[ii].ptcoll;
- pt.tfh = tkinfolist[ii].tfh;
- pt.tfhid = tkinfolist[ii].tfhid;
- tf.Add(pt);
- break;
- }
- }
- }
- }
- }
- }
- }
- break;
- }
- }
- }
-
- /// <summary>
- /// 将图框移动到接图框位置
- /// </summary>
- private void move(Document doc, List<tkinfo> tkinfolist, List<tkinfo> tf, Point3dCollection ptcoll)
- {
- Point3d Frompt = new Point3d(ptcoll[0].X - (261.5 * bl - 5.75 * bl * 2), ptcoll[0].Y - (261.5 * bl - 5.75 * bl * 2), 0);//基点
- Point3d Topt = new Point3d(ptcoll[3].X, ptcoll[3].Y + 5.75 * bl + 1.75 * bl, 0);//目标点
- if(bl==10)
- {
- Frompt = new Point3d(ptcoll[0].X - 2500, ptcoll[0].Y - 2500, 0);
- Topt = new Point3d(ptcoll[3].X, ptcoll[3].Y + 48.75 + 15, 0);
- }
- for (int i = 0; i < tf.Count; i++)
- {
- for (int j = 0; j < tkinfolist.Count; j++)
- {
- if (tf[i].id == tkinfolist[j].id)
- {
- using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
- {
- Entity ent = trans.GetObject(tkinfolist[j].id, OpenMode.ForWrite) as Entity;
- DBText text = trans.GetObject(tkinfolist[j].tfhid, OpenMode.ForWrite) as DBText;
- String txt = text.TextString;
- //使输出图幅号为三位数
- if (txt[0].ToString() == "0")
- {
- if (txt[1].ToString() == "0")
- {
- text.TextString = txt[2].ToString();
- }
- else
- {
- text.TextString = txt[1].ToString() + txt[2].ToString();
- }
- }
- Double scalenum = (22.5 * bl / 3) / (261.5 * bl - 5.75 * bl * 2);//缩放比
- Vector3d acVec3d = Frompt.GetVectorTo(Topt);
- Matrix3d mt = Matrix3d.Scaling(scalenum, Topt);
- if (ent is Polyline)
- {
- Polyline pll = (Polyline)ent;
- pll.TransformBy(Matrix3d.Displacement(acVec3d));
- pll.TransformBy(mt);
- }
- if (ent is Polyline2d)
- {
- Polyline2d pll = (Polyline2d)ent;
- pll.TransformBy(Matrix3d.Displacement(acVec3d));
- pll.TransformBy(mt);
- }
- text.TransformBy(Matrix3d.Displacement(acVec3d));
- text.TransformBy(mt);
- Matrix3d mt1 = Matrix3d.Scaling(3, new Point3d(text.AlignmentPoint.X, text.AlignmentPoint.Y, 0));
- text.TransformBy(mt1);
- trans.Commit();
- }
- }
- }
- }
- }
-
- /// <summary>
- /// 删除9800图层
- /// </summary>
- private void deletetc(Document doc, Point3dCollection ptcoll)
- {
- Editor ed = doc.Editor;
- TypedValue[] value_tfk = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800")
- };
- SelectionFilter filter_tfk = new SelectionFilter(value_tfk);
- Point3d pt1 = new Point3d(ptcoll[3].X, ptcoll[3].Y + 5.75 * bl + 1.75 * bl, 0);
- Point3d pt2 = new Point3d(ptcoll[3].X + 22.5 * bl, ptcoll[3].Y + (5.5 + 0.5 + 1.5) * bl + 12 * bl + 10, 0);
- if (bl == 10)
- {
- pt1 = new Point3d(ptcoll[3].X, ptcoll[3].Y + 50, 0);
- pt2 = new Point3d(ptcoll[3].X + 22.5 * bl, ptcoll[3].Y + 47.5 + 1.25 + 15 + 12 * bl, 0);
- }
- //dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- //acadApp.ZoomExtents();
- //using (DocumentLock docTargetLock = doc.LockDocument())
- //{
- using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
- {
- ViewTableRecord view = ed.GetCurrentView();
- view.Width = 22.5 * bl + 1;
- view.Height = 12 * bl + 1;
- view.CenterPoint = new Point2d(
- pt1.X + Math.Abs((pt1.X - pt2.X)) / 2,
- pt1.Y + Math.Abs((pt2.Y - 10 - pt1.Y)) / 2
- );
- ed.SetCurrentView(view);
- tr.Commit();
- }
- //}
- PromptSelectionResult psr_tfk = ed.SelectCrossingWindow(pt1, pt2, filter_tfk);
- //acadApp.ZoomPrevious();
- if (psr_tfk.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr_tfk.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- for (int i = 0; i < idcoll.Count; i++)
- {
- //using (DocumentLock docTargetLock = doc.LockDocument())
- //{
- using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
- {
- Entity ent = trans.GetObject(idcoll[i], OpenMode.ForWrite) as Entity;
- ent.Erase();
- trans.Commit();
- }
- }
- }
- //}
- }
-
- /// <summary>
- /// 删除除了相交图框以外的图框和相应图幅号
- /// </summary>
- private void deletetk(Document doc, List<tkinfo> tkinfolist, List<tkinfo> tf)
- {
- ObjectIdCollection deleteid = new ObjectIdCollection();
- ObjectIdCollection deletetfhid = new ObjectIdCollection();
- ObjectIdCollection tfid = new ObjectIdCollection();
- for (int i = 0; i < tf.Count; i++)
- {
- tfid.Add(tf[i].id);
- }
- for (int i = 0; i < tf.Count; i++)
- {
- for (int j = 0; j < tkinfolist.Count; j++)
- {
- if (tf[i].id != tkinfolist[j].id)
- {
- if (!deleteid.Contains(tkinfolist[j].id) && !tfid.Contains(tkinfolist[j].id))
- {
- deleteid.Add(tkinfolist[j].id);
- deletetfhid.Add(tkinfolist[j].tfhid);
- }
- }
- }
- }
- for (int k = 0; k < deleteid.Count; k++)
- {
- using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
- {
- Entity ent = trans.GetObject(deleteid[k], OpenMode.ForWrite) as Entity;
- DBText text = trans.GetObject(deletetfhid[k], OpenMode.ForWrite) as DBText;
- ent.Erase();
- text.Erase();
- trans.Commit();
- }
- }
- }
-
- /// <summary>
- /// 点排序
- /// </summary>
- private void sortpts(Point3dCollection ptcoll)
- {
- List<double> x = new List<double>();
- List<double> y = new List<double>();
- for (int i = 0; i < 4; i++)
- {
- if (!x.Contains(ptcoll[i].X))
- x.Add(ptcoll[i].X);
- if (!y.Contains(ptcoll[i].Y))
- y.Add(ptcoll[i].Y);
- }
- if (x[0] > x[1])
- {
- double temp = x[0];
- x[0] = x[1];
- x[1] = temp;
- }
- if (y[0] > y[1])
- {
- double temp = y[0];
- y[0] = y[1];
- y[1] = temp;
- }
- ptcoll[0] = new Point3d(x[0], y[0], 0); //左下
- ptcoll[1] = new Point3d(x[1], y[0], 0); //右下
- ptcoll[2] = new Point3d(x[1], y[1], 0); //右上
- ptcoll[3] = new Point3d(x[0], y[1], 0); //左上
- }
-
- /// <summary>
- /// 绘制接图表
- /// </summary>
- private void draw(Document doc, Point3dCollection ptcoll, List<tkinfo> tf, ObjectId HZ)
- {
- Point2d p1 = new Point2d();
- Point2d p2 = new Point2d();
- double x = ptcoll[3].X;
- double y = ptcoll[3].Y;
- double dist_l = 22.5 * bl / 3; //长
- double dist_w = 12 * bl / 3; //宽
- double dist_nw = 5.75 * bl; //内外框距离
- double dist_w2jt = 1.75 * bl; //外框到接图表距离
- double dist_tc = Math.Sqrt((0.5 * bl) * (0.5 * bl) * 2);
- double dist_tc1 = 0.404 * bl;
- if (bl == 10)
- {
- dist_nw = 48.75; //内外框距离
- dist_w2jt = 15; //外框到接图表距离
- dist_tc = 7;
- dist_tc1 = 0.349;
- }
- List<tkinfo> zj_x = new List<tkinfo>();//只有x方向中间错位的图框
- List<tkinfo> zj_y = new List<tkinfo>();//只有y方向中间错位的图框
- //double cw_x = -9999;//错位图框左下角x坐标
- //double cw_y = -9999;//错位图框左下角y坐标
- Point3dCollection cw_x = new Point3dCollection();//x方向错位图框左下角点
- Point3dCollection cw_y = new Point3dCollection();//y方向错位图框左下角点
- List<Polyline> x_addline = new List<Polyline>();
- List<Polyline> y_addline = new List<Polyline>();
-
- using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- //长
- Polyline pll1 = new Polyline();
- p1 = new Point2d(x, y + dist_nw + dist_w2jt);
- p2 = new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt);
- pll1.AddVertexAt(0, p1, 0, 0, 0);
- pll1.AddVertexAt(1, p2, 0, 0, 0);
- pll1.Layer = "9800";
- pll1.Linetype = "Bylayer";
- pll1.SetDatabaseDefaults();
- btr.AppendEntity(pll1);
- trans.AddNewlyCreatedDBObject(pll1, true);
- for (int i = 1; i < 4; i++)
- {
- Point3d targetPt = new Point3d(x, y + dist_nw + dist_w2jt + dist_w * i, 0);
- Point3d FromPt = new Point3d(x, y + dist_nw + dist_w2jt, 0);
- Vector3d acVec3d = FromPt.GetVectorTo(targetPt);
- Matrix3d mt = Matrix3d.Displacement(acVec3d);
- Entity entCopy = pll1.GetTransformedCopy(mt);
- btr.AppendEntity(entCopy);
- trans.AddNewlyCreatedDBObject(entCopy, true);
- }
- //宽
- Polyline pll2 = new Polyline();
- p1 = new Point2d(x, y + dist_nw + dist_w2jt);
- p2 = new Point2d(x, y + dist_nw + dist_w2jt + dist_w * 3);
- pll2.AddVertexAt(0, p1, 0, 0, 0);
- pll2.AddVertexAt(1, p2, 0, 0, 0);
- pll2.Layer = "9800";
- pll2.Linetype = "Bylayer";
- pll2.SetDatabaseDefaults();
- btr.AppendEntity(pll2);
- trans.AddNewlyCreatedDBObject(pll2, true);
- for (int i = 1; i < 4; i++)
- {
- Point3d targetPt = new Point3d(x + dist_l * i, y + dist_nw + dist_w2jt, 0);
- Point3d FromPt = new Point3d(x, y + dist_nw + dist_w2jt, 0);
- Vector3d acVec3d = FromPt.GetVectorTo(targetPt);
- Matrix3d mt = Matrix3d.Displacement(acVec3d);
- Entity entCopy = pll2.GetTransformedCopy(mt);
- btr.AppendEntity(entCopy);
- trans.AddNewlyCreatedDBObject(entCopy, true);
- }
- //中间
- double xx = x + dist_l;
- double yy = y + dist_nw + dist_w2jt + dist_w * 2;
- Point3dCollection coll = new Point3dCollection();
- coll.Add(new Point3d(xx, yy, 0));
- coll.Add(new Point3d(xx, yy - dist_w, 0));
- coll.Add(new Point3d(xx + dist_l, yy - dist_w, 0));
- coll.Add(new Point3d(xx + dist_l, yy, 0));
- coll.Add(new Point3d(xx, yy, 0));
- Polyline2d line2d = new Polyline2d(Poly2dType.SimplePoly, coll, 0, false, 0, 0, null);
- line2d.SetDatabaseDefaults();
- btr.AppendEntity(line2d);
- trans.AddNewlyCreatedDBObject(line2d, true);
- xx = xx + dist_tc1;
- for (int i = 0; i < 16; i++)
- {
- Line l = new Line();
- l.StartPoint = new Point3d(xx + 22.5 * bl, yy + 22.5 * bl, 0);
- l.EndPoint = new Point3d(xx - 22.5 * bl, yy - 22.5 * bl, 0);
- l.SetDatabaseDefaults();
- btr.AppendEntity(l);
- trans.AddNewlyCreatedDBObject(l, true);
- Point3dCollection IP = new Point3dCollection();
-
- l.IntersectWith(line2d, Intersect.ExtendThis, IP, IntPtr.Zero, IntPtr.Zero);
- Polyline pll3 = new Polyline();
- pll3.AddVertexAt(0, new Point2d(IP[0].X, IP[0].Y), 0, 0, 0);
- pll3.AddVertexAt(1, new Point2d(IP[1].X, IP[1].Y), 0, 0, 0);
- pll3.Layer = "9800";
- pll3.Linetype = "Bylayer";
- pll3.SetDatabaseDefaults();
- btr.AppendEntity(pll3);
- trans.AddNewlyCreatedDBObject(pll3, true);
- xx = xx + dist_tc;
- l.Erase();
- }
- line2d.Erase();
-
- //using (ViewTableRecord view = doc.Editor.GetCurrentView())
- //{
- // view.Width = Math.Abs(ptcoll[1].X - ptcoll[0].X);
- // view.Height = Math.Abs(ptcoll[1].X - ptcoll[0].X) + 60 * bl;
- // view.CenterPoint = new Point2d(
- // ptcoll[0].X + Math.Abs(ptcoll[1].X - ptcoll[0].X) / 2,
- // ptcoll[0].Y + Math.Abs(ptcoll[2].Y - ptcoll[0].Y) / 2
- // );
- // doc.Editor.SetCurrentView(view);
- //}
- //doc.Editor.Regen();
- trans.Commit();
- }
- //相交图幅
- for (int i = 0; i < tf.Count; i++)
- {
- using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- Point3dCollection pts = new Point3dCollection();
- Polyline pll = tran.GetObject(tf[i].id, OpenMode.ForWrite) as Polyline;
- double bc = pll.Length / 4.0; //边长
- pll.GetStretchPoints(pts);
- sortpts(pts);
- double x_check = Math.Abs(Math.Round(pts[0].X - ptcoll[3].X, 5));
- double y_check = Math.Abs(Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5));
- double num_x = Math.Round(Math.Floor(x_check / bc), 3);
- double num_y = Math.Round(Math.Floor(y_check / bc), 3);
- double y_plus = (y_check % bc) * (dist_w / bc);
-
- //x、y方向都错位
- if (x_check % bc != 0 && y_check % bc != 0)
- {
- double y_plus_up = (Math.Abs(Math.Round(pts[1].Y - y - dist_nw - dist_w2jt, 5)) % bc) * (dist_w / bc);
- double y_plus_down = (Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5)) / bc * dist_w;
- //左上上
- if (pts[0].X < x && y_check / bc > 2)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- //判断宽度和高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_width = Math.Abs(pts[1].X - x);
- double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
- if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
- tfh_height > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
- Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
- }
-
- //左上下
- else if (pts[0].X < x && Math.Round(y_check / bc, 2) < 2 && Math.Round(y_check / bc, 2) > 1)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- Polyline pll_ad2 = new Polyline();
- pll_ad2.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad2.Layer = "9800";
- pll_ad2.Linetype = "Bylayer";
- pll_ad2.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad2);
- tran.AddNewlyCreatedDBObject(pll_ad2, true);
- //判断宽度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_width = Math.Abs(pts[1].X - x);
- if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + dist_w * 1.5 + y_plus;
- Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
-
- Point3dCollection ptscoll = new Point3dCollection();
- ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
- ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2, 0));
- Point3d bk = new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 2, 0);
- sele_dele(ptscoll, ed, tran, x, bk, btr);
- }
-
- //左下下
- if (pts[0].X < x && y_plus_down < 0)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- //判断宽度和高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_width = Math.Abs(pts[1].X - x);
- double tfh_height = (dist_w - y_plus);
- if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
- tfh_height > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
- Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
- }
-
- //左下上
- else if (pts[0].X < x && y_plus_down < dist_w && y_plus_down > 0)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- Polyline pll_ad2 = new Polyline();
- pll_ad2.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad2.Layer = "9800";
- pll_ad2.Linetype = "Bylayer";
- pll_ad2.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad2);
- tran.AddNewlyCreatedDBObject(pll_ad2, true);
- //判断宽度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_width = Math.Abs(pts[1].X - x);
- if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + y_plus + dist_w / 2;
- Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
-
- Point3dCollection ptscoll = new Point3dCollection();
- ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
- ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w, 0));
- Point3d bk = new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w, 0);
- sele_dele(ptscoll, ed, tran, x, bk, btr);
- }
-
- //右上上
- if (pts[0].X > x + dist_l * 2 && y_check / bc > 2)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- //判断宽度和高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
- double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
- if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
- tfh_height > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
- double tfh_y = y + dist_nw + dist_w2jt + dist_w * 2 + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
- Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
- }
-
- //右上下
- else if (pts[0].X > x + dist_l * 2 && Math.Round(y_check / bc, 2) < 2 && Math.Round(y_check / bc, 2) > 1)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- Polyline pll_ad2 = new Polyline();
- pll_ad2.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad2.Layer = "9800";
- pll_ad2.Linetype = "Bylayer";
- pll_ad2.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad2);
- tran.AddNewlyCreatedDBObject(pll_ad2, true);
- //判断宽度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
- if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
- double tfh_y = y + dist_nw + dist_w2jt + dist_w * 1.5 + y_plus;
- Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
-
- Point3dCollection ptscoll = new Point3dCollection();
- ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
- ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2, 0));
- Point3d bk = new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2, 0);
- sele_dele(ptscoll, ed, tran, x + dist_l * 3, bk, btr);
- }
-
- //右下下
- if (pts[0].X > x + dist_l * 2 && y_plus_down < 0)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- //判断宽度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
- double tfh_height = (dist_w - y_plus);
- if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
- tfh_height > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
- double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
- Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
- }
-
- //右下上
- else if (pts[0].X > x + dist_l * 2 && y_plus_down < dist_w && y_plus_down > 0)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- Polyline pll_ad2 = new Polyline();
- pll_ad2.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
- pll_ad2.Layer = "9800";
- pll_ad2.Linetype = "Bylayer";
- pll_ad2.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad2);
- tran.AddNewlyCreatedDBObject(pll_ad2, true);
- //判断宽度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
- if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
- double tfh_y = y + dist_nw + dist_w2jt + y_plus + dist_w / 2;
- Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
-
- Point3dCollection ptscoll = new Point3dCollection();
- ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
- ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w, 0));
- Point3d bk = new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w, 0);
- sele_dele(ptscoll, ed, tran, x + dist_l * 3, bk, btr);
- }
-
- //中上左
- if (pts[0].X > x && pts[1].X < x + dist_l * 2 && y_check / bc > 2)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- Polyline pll_ad2 = new Polyline();
- pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad2.Layer = "9800";
- pll_ad2.Linetype = "Bylayer";
- pll_ad2.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad2);
- tran.AddNewlyCreatedDBObject(pll_ad2, true);
- //判断宽度和高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
- if (tfh_height > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
- Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
- }
-
- //中上右
- if (pts[0].X > x + dist_l && pts[1].X < x + dist_l * 3 && y_check / bc > 2)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- Polyline pll_ad2 = new Polyline();
- pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad2.Layer = "9800";
- pll_ad2.Linetype = "Bylayer";
- pll_ad2.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad2);
- tran.AddNewlyCreatedDBObject(pll_ad2, true);
- //判断宽度和高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
- if (tfh_height > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
- Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
- }
-
- //中下左
- if (pts[0].X > x && pts[1].X < x + dist_l * 2 && y_plus_down < 0)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- Polyline pll_ad2 = new Polyline();
- pll_ad2.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
- pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad2.Layer = "9800";
- pll_ad2.Linetype = "Bylayer";
- pll_ad2.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad2);
- tran.AddNewlyCreatedDBObject(pll_ad2, true);
- //判断宽度和高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_height = (dist_w - y_plus);
- if (tfh_height > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
- Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
- }
-
- //中下右
- if (pts[0].X > x + dist_l && pts[1].X < x + dist_l * 3 && y_plus_down < 0)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- Polyline pll_ad1 = new Polyline();
- pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad1.Layer = "9800";
- pll_ad1.Linetype = "Bylayer";
- pll_ad1.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad1);
- tran.AddNewlyCreatedDBObject(pll_ad1, true);
- Polyline pll_ad2 = new Polyline();
- pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
- pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
- pll_ad2.Layer = "9800";
- pll_ad2.Linetype = "Bylayer";
- pll_ad2.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad2);
- tran.AddNewlyCreatedDBObject(pll_ad2, true);
- //判断宽度和高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数
- int ws = tfh_temp.TextString.Length;
- double tfh_height = (dist_w - y_plus);
- if (tfh_height > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
- Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- tfh_temp.Erase();
- }
- }
-
-
- //x方向错位
- else if (x_check % bc != 0)
- {
- //选择y方向竖线删除
- Point3dCollection ptscoll = new Point3dCollection();
- ptscoll.Add(new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
- ptscoll.Add(new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter filter = new SelectionFilter(value);
- //dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- //acadApp.ZoomExtents();
- PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
- //判断选中多条线段后情况
- if (idcoll.Count > 1)
- {
- Polyline temp1 = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
- Polyline temp2 = tran.GetObject(idcoll[1], OpenMode.ForWrite) as Polyline;
- if (temp1.Length > temp2.Length)
- {
- pll_delete = temp1;
- }
- else
- {
- pll_delete = temp2;
- }
- }
- //有相交但超出左范围
- if (pll_delete.StartPoint.X == x)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- x_addline.Add(pll_ad);
- //判断宽度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数判断是否需要保留
- int ws = tfh_temp.TextString.Length;
- if (Math.Abs(pts[1].X - x) > ws * bl + (ws - 1) * (0.25 * bl))
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号x坐标计算
- //double tfh_x = Math.Round(x + (pts[1].X - x) / 2);
- double tfh_x = x + (pts[1].X - x) / 2;
- Point3d Topt_temp = new Point3d(tfh_x, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- {
- tfh_temp.Erase();
- }
-
- //删除接图表内左竖线
- Point3dCollection deleteptscoll = new Point3dCollection();
- deleteptscoll.Add(new Point3d(x + dist_l, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
- deleteptscoll.Add(new Point3d(x + dist_l + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
- TypedValue[] deletevalue = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter deletefilter = new SelectionFilter(deletevalue);
- //acadApp.ZoomExtents();
- PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
- //acadApp.ZoomPrevious();
- if (deletepsr.Status == PromptStatus.OK)
- {
- SelectionSet deletess = deletepsr.Value;
- ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
- Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- if (num_y == 0)
- {
- pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w, 0));
- obj = deletepll.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
- pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- deletepll.Erase();
- }
- else
- {
- pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num_y, 0));
- obj = deletepll.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
- pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- deletepll.Erase();
- }
- }
-
- }
- //有相交但超出右范围
- else if (pll_delete.StartPoint.X == x + dist_l * 3)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- x_addline.Add(pll_ad);
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- int ws = tfh_temp.TextString.Length;//计算图幅号位数判断是否需要保留
- if (Math.Abs(x + dist_l * 3 - pts[0].X) > ws * bl + (ws - 1) * (0.25 * bl))
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号x坐标计算
- //double tfh_x = Math.Round(x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2);
- double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
- Point3d Topt_temp = new Point3d(tfh_x, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- {
- tfh_temp.Erase();
- }
-
- //删除接图表内右竖线
- Point3dCollection deleteptscoll = new Point3dCollection();
- deleteptscoll.Add(new Point3d(x + dist_l * 2, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
- deleteptscoll.Add(new Point3d(x + dist_l * 2 + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
- TypedValue[] deletevalue = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter deletefilter = new SelectionFilter(deletevalue);
- //acadApp.ZoomExtents();
- PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
- //acadApp.ZoomPrevious();
- if (deletepsr.Status == PromptStatus.OK)
- {
- SelectionSet deletess = deletepsr.Value;
- ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
- Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- if (num_y == 0)
- {
- pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w, 0));
- obj = deletepll.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
- pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- deletepll.Erase();
- }
- else
- {
- pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num_y, 0));
- obj = deletepll.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
- pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- deletepll.Erase();
- }
- }
- }
- else
- {
- //if (cw_x != pts[0].Y)
- //{
- // zj_x.Add(tf[i]);
- // flag_x = 1;
- // cw_x = pts[0].Y;
- //}
- //else if (cw_x == pts[0].Y && flag_x == 1)
- //{
- // zj_x.RemoveAt(zj_x.Count - 1);
- // flag_x = 0;
- //}
-
- //if (cw_x.Count != 0)
- //{
- // int flag = 0;
- // int cf = 0;
- // for (int ii = 0; ii < cw_x.Count; ii++)
- // {
- // if (cw_x[ii].Y != pts[0].Y)
- // flag = 1;
- // else
- // {
- // flag = 0;
- // cf = ii;
- // }
- // }
- // if(flag == 1)
- // {
- // zj_x.Add(tf[i]);
- // cw_x.Add(pts[0]);
- // }
- // else
- // {
- // zj_x.RemoveAt(cf);
- // cw_x.RemoveAt(cf);
- // }
- //}
- //else
- //{
- // zj_x.Add(tf[i]);
- // cw_x.Add(pts[0]);
- //}
- cw_x.Add(pts[0]);
- zj_x.Add(tf[i]);
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- if (pll_delete.Length != 12 * bl / 3)
- {
- pt_break.Add(new Point3d(pll_delete.StartPoint.X, y + dist_nw
- + dist_w2jt + ((num_y + 2) / 2) * dist_w, 0));
- obj = pll_delete.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.Length < pll_delete2.Length)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else if (pll_delete1.Length == pll_delete2.Length)
- {
- if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
- pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt ||
- pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
- pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- }
- pll_delete.Erase();
- Polyline pll_cg = new Polyline();
- pll_cg.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
- //pll_cg.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
- //pll_cg.AddVertexAt(2, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
- pll_cg.AddVertexAt(1, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
- //pll_cg.AddVertexAt(4, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
- Polyline pll_cg_1 = new Polyline();
- pll_cg_1.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
- pll_cg_1.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
- pll_cg.Layer = "9800";
- pll_cg.Linetype = "Bylayer";
- pll_cg.SetDatabaseDefaults();
- btr.AppendEntity(pll_cg);
- tran.AddNewlyCreatedDBObject(pll_cg, true);
- pll_cg_1.Layer = "9800";
- pll_cg_1.Linetype = "Bylayer";
- pll_cg_1.SetDatabaseDefaults();
- btr.AppendEntity(pll_cg_1);
- tran.AddNewlyCreatedDBObject(pll_cg_1, true);
- x_addline.Add(pll_cg);
- x_addline.Add(pll_cg_1);
- DBText tfh = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh.AlignmentPoint = tfh.Position;
- Point3d Frompt = new Point3d(tfh.AlignmentPoint.X, tfh.AlignmentPoint.Y, tfh.AlignmentPoint.Z);
- Point3d Topt = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh.AlignmentPoint.Z);
- Vector3d acVec3d = Frompt.GetVectorTo(Topt);
- tfh.TransformBy(Matrix3d.Displacement(acVec3d));
- tfh.Layer = "9800";
- tfh.ColorIndex = 4;
- tfh.Height = 1.25 * bl;
- tfh.TextStyleId = HZ;
- if (bl > 4) tfh.WidthFactor = 0.75;
- }
- }
- }
-
-
- //y方向错位
- else if (y_check % bc != 0)
- {
- double y_plus1 = (Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5) / bc) * dist_w;
- double y_plus2 = (Math.Round(pts[2].Y - y - dist_nw - dist_w2jt, 5) / bc) * dist_w;
- if (y_plus1 < 0)
- y_plus1 = 0;
- Point3dCollection ptscoll = new Point3dCollection();
- ptscoll.Add(new Point3d(x + dist_l * num_x + 0.01, y + dist_nw + dist_w2jt + y_plus1, 0));
- ptscoll.Add(new Point3d(x + dist_l * num_x + 0.01, y + dist_nw + dist_w2jt + y_plus2, 0));
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter filter = new SelectionFilter(value);
- //dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- //acadApp.ZoomExtents();
- PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
- //acadApp.ZoomPrevious();
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
- if (idcoll.Count > 1)
- {
- Polyline temp1 = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
- Polyline temp2 = tran.GetObject(idcoll[1], OpenMode.ForWrite) as Polyline;
- if (temp1.Length > temp2.Length)
- {
- pll_delete = temp1;
- }
- else
- {
- pll_delete = temp2;
- }
- }
- //有相交但超出上方
- if (pll_delete.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(x + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(x + dist_l * (num_x + 1), y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- y_addline.Add(pll_ad);
- //判断高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数判断是否需要保留
- int ws = tfh_temp.TextString.Length;
- if (Math.Abs((dist_w * (3 - num_y) - y_plus)) > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
- Point3d Topt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- {
- tfh_temp.Erase();
- }
-
- //删除接图表内上横线
- Point3dCollection deleteptscoll = new Point3dCollection();
- deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * 2, 0));
- deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
- TypedValue[] deletevalue = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter deletefilter = new SelectionFilter(deletevalue);
- //acadApp.ZoomExtents();
- PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
- //acadApp.ZoomPrevious();
- if (deletepsr.Status == PromptStatus.OK)
- {
- SelectionSet deletess = deletepsr.Value;
- ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
- Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- if (num_x == 0)
- {
- pt_break.Add(new Point3d(x + dist_l, deletepll.StartPoint.Y, 0));
- obj = deletepll.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.X == x ||
- pll_delete1.EndPoint.Y == x)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- deletepll.Erase();
- }
- else
- {
- pt_break.Add(new Point3d(x + dist_l * 2, deletepll.StartPoint.Y, 0));
- obj = deletepll.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.Y == x + dist_l * 3 ||
- pll_delete1.EndPoint.Y == x + dist_l * 3)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- deletepll.Erase();
- }
- }
-
- }
- //有相交但超出下方
- else if (pll_delete.StartPoint.Y == y + dist_nw + dist_w2jt)
- {
- Polyline pll_ad = new Polyline();
- pll_ad.AddVertexAt(0, new Point2d(x + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w - y_plus)), 0, 0, 0);
- pll_ad.AddVertexAt(1, new Point2d(x + dist_l * (num_x + 1), y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w - y_plus)), 0, 0, 0);
- pll_ad.Layer = "9800";
- pll_ad.Linetype = "Bylayer";
- pll_ad.SetDatabaseDefaults();
- btr.AppendEntity(pll_ad);
- tran.AddNewlyCreatedDBObject(pll_ad, true);
- y_addline.Add(pll_ad);
- //判断高度能否放下文字
- DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh_temp.TextStyleId = HZ;
- if (bl > 4) tfh_temp.WidthFactor = 0.75;
- tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh_temp.AlignmentPoint = tfh_temp.Position;
- //计算图幅号位数判断是否需要保留
- int ws = tfh_temp.TextString.Length;
- if (dist_w - y_plus > 1.25 * bl)
- {
- Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
- //图幅号y坐标计算
- double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
- Point3d Topt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_y, tfh_temp.AlignmentPoint.Z);
- Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
- tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
- tfh_temp.Layer = "9800";
- tfh_temp.ColorIndex = 4;
- tfh_temp.Height = 1.25 * bl;
- }
- else
- {
- tfh_temp.Erase();
- }
-
- //删除接图表内下横线
- Point3dCollection deleteptscoll = new Point3dCollection();
- deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w, 0));
- deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
- TypedValue[] deletevalue = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter deletefilter = new SelectionFilter(deletevalue);
- //acadApp.ZoomExtents();
- PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
- //acadApp.ZoomPrevious();
- if (deletepsr.Status == PromptStatus.OK)
- {
- SelectionSet deletess = deletepsr.Value;
- ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
- Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- if (num_x == 0)
- {
- pt_break.Add(new Point3d(x + dist_l, deletepll.StartPoint.Y, 0));
- obj = deletepll.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.X == x ||
- pll_delete1.EndPoint.Y == x)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- deletepll.Erase();
- }
- else
- {
- pt_break.Add(new Point3d(x + dist_l * 2, deletepll.StartPoint.Y, 0));
- obj = deletepll.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.Y == x + dist_l * 3 ||
- pll_delete1.EndPoint.Y == x + dist_l * 3)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- deletepll.Erase();
- }
- }
-
- }
- else
- {
- //if (cw_y != pts[0].X)
- //{
- // zj_y.Add(tf[i]);
- // flag_y = 1;
- // cw_y = pts[0].X;
- //}
- //else if (cw_y == pts[0].X && flag_y == 1)
- //{
- // zj_y.RemoveAt(zj_y.Count - 1);
- // flag_y = 0;
- //}
-
- //if (cw_y.Count != 0)
- //{
- // int flag = 0;
- // int cf = 0;
- // for (int ii = 0; ii < cw_y.Count; ii++)
- // {
- // if (cw_y[ii].X != pts[0].X)
- // flag = 1;
- // else
- // {
- // flag = 0;
- // cf = ii;
- // }
- // }
- // if (flag == 1)
- // {
- // zj_y.Add(tf[i]);
- // cw_y.Add(pts[0]);
- // }
- // else
- // {
- // zj_y.RemoveAt(cf);
- // cw_y.RemoveAt(cf);
- // }
- //}
- //else
- //{
- // zj_y.Add(tf[i]);
- // cw_y.Add(pts[0]);
- //}
-
- cw_y.Add(pts[0]);
- zj_y.Add(tf[i]);
- if (pll_delete.Length != 22.5 * bl / 3)
- {
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- pt_break.Add(new Point3d(x + (((num_x + 2) / 2) * dist_l), y + dist_nw
- + dist_w2jt + (num_y + 1) * dist_w, 0));
- obj = pll_delete.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.Length < pll_delete2.Length)
- {
-
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else if (pll_delete1.Length == pll_delete2.Length)
- {
- if (pll_delete1.StartPoint.X == x || pll_delete1.EndPoint.X == x ||
- pll_delete1.EndPoint.X == x + dist_l * 3 || pll_delete1.StartPoint.X == x + dist_l * 3)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- }
- pll_delete.Erase();
- Polyline pll_cg_1 = new Polyline();
- pll_cg_1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_cg_1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- Polyline pll_cg_2 = new Polyline();
- pll_cg_2.AddVertexAt(0, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
- pll_cg_2.AddVertexAt(1, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
- //pll_cg.AddVertexAt(2, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
- //pll_cg_1.AddVertexAt(3, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
- //pll_cg.AddVertexAt(4, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
- pll_cg_1.Layer = "9800";
- pll_cg_1.Linetype = "Bylayer";
- pll_cg_1.SetDatabaseDefaults();
- btr.AppendEntity(pll_cg_1);
- tran.AddNewlyCreatedDBObject(pll_cg_1, true);
- pll_cg_2.Layer = "9800";
- pll_cg_2.Linetype = "Bylayer";
- pll_cg_2.SetDatabaseDefaults();
- btr.AppendEntity(pll_cg_2);
- tran.AddNewlyCreatedDBObject(pll_cg_2, true);
- y_addline.Add(pll_cg_1);
- y_addline.Add(pll_cg_2);
- DBText tfh = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh.AlignmentPoint = tfh.Position;
- Point3d Frompt = new Point3d(tfh.AlignmentPoint.X, tfh.AlignmentPoint.Y, tfh.AlignmentPoint.Z);
- Point3d Topt = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + dist_w / 2, tfh.AlignmentPoint.Z);
- Vector3d acVec3d = Frompt.GetVectorTo(Topt);
- tfh.TransformBy(Matrix3d.Displacement(acVec3d));
- tfh.Layer = "9800";
- tfh.ColorIndex = 4;
- tfh.Height = 1.25 * bl;
- tfh.TextStyleId = HZ;
- if (bl > 4) tfh.WidthFactor = 0.75;
- }
- }
- }
-
-
- else
- {
- DBText tfh1 = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
- tfh1.HorizontalMode = TextHorizontalMode.TextCenter;
- tfh1.VerticalMode = TextVerticalMode.TextVerticalMid;
- tfh1.AlignmentPoint = tfh1.Position;
- Point3d Frompt1 = new Point3d(tfh1.AlignmentPoint.X, tfh1.AlignmentPoint.Y, tfh1.AlignmentPoint.Z);
- Point3d Topt1 = new Point3d(x + dist_l * num_x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh1.AlignmentPoint.Z);
- Vector3d acVec3d1 = Frompt1.GetVectorTo(Topt1);
- tfh1.TransformBy(Matrix3d.Displacement(acVec3d1));
- tfh1.Layer = "9800";
- tfh1.ColorIndex = 4;
- tfh1.Height = 1.25 * bl;
- tfh1.TextStyleId = HZ;
- if (bl > 4) tfh1.WidthFactor = 0.75;
- }
- //pll.Erase();
- tran.Commit();
- }
- }
-
- List<int> delex = new List<int>();//不需要删除对应竖线的x方向错位框
- List<int> deley = new List<int>();//不需要删除对应横线的y方向错位框
-
- //如果同一列中有两个y方向错位图框,由于在y方向错位时已经进行了对应横线的
- //删除,所以将序号加入列表中,不需要再删除。
- for (int i = 0; i < zj_y.Count - 1; i++)
- {
- for (int ii = i + 1; ii < zj_y.Count; ii++)
- {
- if (cw_y[i].X == cw_y[ii].X)
- {
- deley.Add(i);
- deley.Add(ii);
- }
- }
- }
-
- //如果同一行中有两个x方向错位图框,由于在x方向错位时已经进行了对应竖线的
- //删除,所以将序号加入列表中,不需要再删除。
- for (int i = 0; i < zj_x.Count - 1; i++)
- {
- for (int ii = i + 1; ii < zj_x.Count; ii++)
- {
- if (cw_x[i].Y == cw_x[ii].Y)
- {
- delex.Add(i);
- delex.Add(ii);
- }
- }
- }
-
-
- //如果同时有x方向错位和y方向错位且在同一个角,不需要再删除
- for (int i = 0; i < zj_x.Count; i++)
- {
- for (int ii = 0; ii < zj_y.Count; ii++)
- {
- if (Math.Abs(cw_x[i].X - cw_y[ii].X) > dist_l &&
- Math.Abs(cw_x[i].Y - cw_y[ii].Y) > dist_l &&
- !delex.Contains(i))
- delex.Add(i);
- else if (Math.Abs(cw_x[i].X - cw_y[ii].X) < dist_l &&
- !deley.Contains(ii))
- deley.Add(ii);
- else if (Math.Abs(cw_x[i].Y - cw_y[ii].Y) < dist_l &&
- !delex.Contains(i))
- delex.Add(i);
- }
- }
-
- if (zj_x.Count != 0)
- {
- delecentrol(doc, x, y, dist_l, dist_w, dist_nw, dist_w2jt, zj_x, delex, ptcoll, 0);
- }
- if (zj_y.Count != 0)
- {
- delecentrol(doc, x, y, dist_l, dist_w, dist_nw, dist_w2jt, zj_y, deley, ptcoll, 1);
- }
-
- //删除图框
- for (int i = 0; i < tf.Count; i++)
- {
- using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- Point3dCollection pts = new Point3dCollection();
- Polyline pll = tran.GetObject(tf[i].id, OpenMode.ForWrite) as Polyline;
- pll.Erase();
-
- if (i == tf.Count - 1)
- {
- LayerTable layerTable = tran.GetObject(doc.Database.LayerTableId, OpenMode.ForWrite) as LayerTable;
- LayerTableRecord layer = tran.GetObject(layerTable[tc_tfh], OpenMode.ForWrite) as LayerTableRecord;
- layer.Erase(true);
- if (tc_tfh != tc_tk)
- {
- layer = tran.GetObject(layerTable[tc_tk], OpenMode.ForWrite) as LayerTableRecord;
- layer.Erase(true); // 删除图层
- }
- }
- tran.Commit();
- }
- }
-
- if (x_addline.Count != 0)
- {
- for (int i = 0; i < x_addline.Count; i++)
- {
- Polyline pl = x_addline[i];
- if (pl.StartPoint.X == pl.EndPoint.X)
- ifneedaddline(pl, doc, dist_l, 0);
- else
- ifneedaddline(pl, doc, dist_w, 1);
- }
- }
- }
-
-
- /// <summary>
- /// x、y方向错位竖\横线删除
- /// </summary>
- private void delecentrol(Document doc, double x, double y, double dist_l, double dist_w,
- double dist_nw, double dist_w2jt, List<tkinfo> tk, List<int> deleindex, Point3dCollection ptcoll, int index)
- {
- //x方向错位竖线删除
- if (index == 0)
- {
- for (int i = 0; i < tk.Count; i++)
- {
- if (deleindex.Contains(i))
- continue;
- using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- Point3dCollection pts = new Point3dCollection();
- Polyline pll = tran.GetObject(tk[i].id, OpenMode.ForWrite) as Polyline;
- double bc = pll.Length / 4.0; //边长
- pll.GetStretchPoints(pts);
- sortpts(pts);
- double x_check = Math.Round(pts[0].X - ptcoll[3].X, 5);
- double y_check = Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5);
- double num_x = Math.Round(Math.Floor(x_check / bc), 3);
- double num_y = Math.Round(Math.Floor(y_check / bc), 3);
- Point3dCollection ptscoll = new Point3dCollection();
- //右错位
- if (pts[0].X > x + dist_l)
- {
- ptscoll.Add(new Point3d(x + dist_l, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
- ptscoll.Add(new Point3d(x + dist_l + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
- }
- //左错位
- else
- {
- ptscoll.Add(new Point3d(x + dist_l * 2, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
- ptscoll.Add(new Point3d(x + dist_l * 2 + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
- }
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter filter = new SelectionFilter(value);
- dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- acadApp.ZoomExtents();
- PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
- acadApp.ZoomPrevious();
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- int num = 0;
- if (num_y / 2 == 0)
- num = 1;
- else if (num_y / 2 == 1)
- num = 2;
- pt_break.Add(new Point3d(pll_delete.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num, 0));
- obj = pll_delete.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (num == 1 && pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
- num == 1 && pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- pll_delete.Erase();
- }
- tran.Commit();
- }
- }
- }
- //y方向错位横线删除
- if (index == 1)
- {
- for (int i = 0; i < tk.Count; i++)
- {
- if (deleindex.Contains(i))
- continue;
- using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- Point3dCollection pts = new Point3dCollection();
- Polyline pll = tran.GetObject(tk[i].id, OpenMode.ForWrite) as Polyline;
- double bc = pll.Length / 4.0; //边长
- pll.GetStretchPoints(pts);
- sortpts(pts);
- double x_check = Math.Round(pts[0].X - ptcoll[3].X, 5);
- double y_check = Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5);
- double num_x = Math.Round(Math.Floor(x_check / bc), 3);
- double num_y = Math.Round(Math.Floor(y_check / bc), 3);
- double y_plus = (y_check % bc) * (dist_w / bc);
- Point3dCollection ptscoll = new Point3dCollection();
- //下错位
- if (y + dist_nw + dist_w2jt + dist_w * num_y + y_plus < y + dist_nw + dist_w2jt + dist_w)
- {
- ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w * 2, 0));
- ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
- }
- //上错位
- else
- {
- ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w, 0));
- ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
- }
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter filter = new SelectionFilter(value);
- dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- acadApp.ZoomExtents();
- PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
- acadApp.ZoomPrevious();
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- int num = 0;
- if (num_x / 2 == 0)
- num = 1;
- else if (num_x / 2 == 1)
- num = 2;
- pt_break.Add(new Point3d(x + dist_l * num, pll_delete.StartPoint.Y, 0));
- obj = pll_delete.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (num == 1 && pll_delete1.StartPoint.X == x ||
- num == 1 && pll_delete1.EndPoint.X == x)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- pll_delete.Erase();
- }
- tran.Commit();
- }
- }
- }
- }
-
-
- /// <summary>
- /// x、y方向都错位时删除对应方向的竖\横线
- /// </summary>
- private void sele_dele(Point3dCollection ptscoll, Editor ed, Transaction tran, double by, Point3d bk, BlockTableRecord btr)
- {
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter filter = new SelectionFilter(value);
- dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- acadApp.ZoomExtents();
- PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
- acadApp.ZoomPrevious();
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
- Point3dCollection pt_break = new Point3dCollection();
- DBObjectCollection obj = new DBObjectCollection();
- pt_break.Add(bk);
- obj = pll_delete.GetSplitCurves(pt_break);
- Polyline pll_delete1 = obj[0] as Polyline;
- Polyline pll_delete2 = obj[1] as Polyline;
- if (pll_delete1.StartPoint.X == by ||
- pll_delete1.EndPoint.X == by)
- {
- pll_delete2.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete2);
- tran.AddNewlyCreatedDBObject(pll_delete2, true);
- }
- else
- {
- pll_delete1.SetDatabaseDefaults();
- btr.AppendEntity(pll_delete1);
- tran.AddNewlyCreatedDBObject(pll_delete1, true);
- }
- pll_delete.Erase();
- }
- }
-
-
- private void ifneedaddline(Polyline pl, Document doc, double length,int index)
- {
- bool flag1 = false;
- bool flag2 = false;
- length = length + 0.1;
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- if (index == 0)
- {
- double y = Math.Min(pl.StartPoint.Y, pl.EndPoint.Y) + Math.Abs(pl.StartPoint.Y - pl.EndPoint.Y) / 2;
- Point3dCollection ptcol1 = new Point3dCollection();
- ptcol1.Add(new Point3d(pl.StartPoint.X, y, 0));
- ptcol1.Add(new Point3d(pl.StartPoint.X + length, y, 0));
- Point3dCollection ptcol2 = new Point3dCollection();
- ptcol2.Add(new Point3d(pl.StartPoint.X, y, 0));
- ptcol2.Add(new Point3d(pl.StartPoint.X - length, y, 0));
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter filter = new SelectionFilter(value);
- PromptSelectionResult psr1 = ed.SelectFence(ptcol1, filter);
- PromptSelectionResult psr2 = ed.SelectFence(ptcol2, filter);
- ObjectIdCollection idcoll1 = new ObjectIdCollection();
- ObjectIdCollection idcoll2 = new ObjectIdCollection();
- if (psr1.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr1.Value;
- idcoll1 = new ObjectIdCollection(ss.GetObjectIds());
- }
- if (psr2.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr2.Value;
- idcoll2 = new ObjectIdCollection(ss.GetObjectIds());
- }
- using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- for (int i = 0; i < idcoll1.Count; i++)
- {
- Polyline neighbpl = tran.GetObject(idcoll1[i], OpenMode.ForRead) as Polyline;
- if (Math.Round(neighbpl.StartPoint.X, 4) == Math.Round(neighbpl.EndPoint.X, 4)&& idcoll1[i]!=pl.ObjectId)
- {
- flag1 = true;
- break;
- }
- }
- if(flag1==false)
- {
- Polyline ad_pl1 = new Polyline();
- ad_pl1.AddVertexAt(0, new Point2d(pl.StartPoint.X + length, pl.StartPoint.Y), 0, 0, 0);
- ad_pl1.AddVertexAt(1, new Point2d(pl.StartPoint.X + length, pl.EndPoint.Y), 0, 0, 0);
- ad_pl1.Layer = "9800";
- ad_pl1.Linetype = "Bylayer";
- ad_pl1.SetDatabaseDefaults();
- btr.AppendEntity(ad_pl1);
- tran.AddNewlyCreatedDBObject(ad_pl1, true);
- }
- for (int i = 0; i < idcoll2.Count; i++)
- {
- Polyline neighbpl = tran.GetObject(idcoll2[i], OpenMode.ForRead) as Polyline;
- if (Math.Round(neighbpl.StartPoint.X, 4) == Math.Round(neighbpl.EndPoint.X, 4) && idcoll2[i] != pl.ObjectId)
- {
- flag2 = true;
- break;
- }
- }
- if (flag2==false)
- {
- Polyline ad_pl2 = new Polyline();
- ad_pl2.AddVertexAt(0, new Point2d(pl.StartPoint.X - length, pl.StartPoint.Y), 0, 0, 0);
- ad_pl2.AddVertexAt(1, new Point2d(pl.StartPoint.X - length, pl.EndPoint.Y), 0, 0, 0);
- ad_pl2.Layer = "9800";
- ad_pl2.Linetype = "Bylayer";
- ad_pl2.SetDatabaseDefaults();
- btr.AppendEntity(ad_pl2);
- tran.AddNewlyCreatedDBObject(ad_pl2, true);
- }
- tran.Commit();
- }
- }
- if (index == 1)
- {
- double x = Math.Min(pl.StartPoint.X, pl.EndPoint.X) + Math.Abs(pl.StartPoint.X - pl.EndPoint.X) / 2;
- Point3dCollection ptcol1 = new Point3dCollection();
- ptcol1.Add(new Point3d(x, pl.StartPoint.Y, 0));
- ptcol1.Add(new Point3d(x, pl.StartPoint.Y + length, 0));
- Point3dCollection ptcol2 = new Point3dCollection();
- ptcol2.Add(new Point3d(x, pl.StartPoint.Y, 0));
- ptcol2.Add(new Point3d(x, pl.StartPoint.Y - length, 0));
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,"9800"),
- new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
- };
- SelectionFilter filter = new SelectionFilter(value);
- PromptSelectionResult psr1 = ed.SelectFence(ptcol1, filter);
- PromptSelectionResult psr2 = ed.SelectFence(ptcol2, filter);
- ObjectIdCollection idcoll1 = new ObjectIdCollection();
- ObjectIdCollection idcoll2 = new ObjectIdCollection();
- if (psr1.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr1.Value;
- idcoll1 = new ObjectIdCollection(ss.GetObjectIds());
- }
- if (psr2.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr2.Value;
- idcoll2 = new ObjectIdCollection(ss.GetObjectIds());
- }
- using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- for (int i = 0; i < idcoll1.Count; i++)
- {
- Polyline neighbpl = tran.GetObject(idcoll1[i], OpenMode.ForRead) as Polyline;
- if (Math.Round(neighbpl.StartPoint.Y, 4) == Math.Round(neighbpl.EndPoint.Y, 4) && idcoll1[i] != pl.ObjectId)
- {
- flag1 = true;
- break;
- }
- }
- if (flag1 == false)
- {
- Polyline ad_pl1 = new Polyline();
- ad_pl1.AddVertexAt(0, new Point2d(pl.StartPoint.X, pl.StartPoint.Y + length), 0, 0, 0);
- ad_pl1.AddVertexAt(1, new Point2d(pl.EndPoint.X, pl.EndPoint.Y + length), 0, 0, 0);
- ad_pl1.Layer = "9800";
- ad_pl1.Linetype = "Bylayer";
- ad_pl1.SetDatabaseDefaults();
- btr.AppendEntity(ad_pl1);
- tran.AddNewlyCreatedDBObject(ad_pl1, true);
- }
- for (int i = 0; i < idcoll2.Count; i++)
- {
- Polyline neighbpl = tran.GetObject(idcoll2[i], OpenMode.ForRead) as Polyline;
- if (Math.Round(neighbpl.StartPoint.Y, 4) == Math.Round(neighbpl.EndPoint.Y, 4) && idcoll2[i] != pl.ObjectId)
- {
- flag2 = true;
- break;
- }
- }
- if (flag2 == false)
- {
- Polyline ad_pl2 = new Polyline();
- ad_pl2.AddVertexAt(0, new Point2d(pl.StartPoint.X, pl.StartPoint.Y - length), 0, 0, 0);
- ad_pl2.AddVertexAt(1, new Point2d(pl.StartPoint.X, pl.EndPoint.Y - length), 0, 0, 0);
- ad_pl2.Layer = "9800";
- ad_pl2.Linetype = "Bylayer";
- ad_pl2.SetDatabaseDefaults();
- btr.AppendEntity(ad_pl2);
- tran.AddNewlyCreatedDBObject(ad_pl2, true);
- }
- tran.Commit();
- }
-
- }
- }
-
-
-
- public ObjectId createTextStyle(Document doc)
- {
- Database database = doc.Database;
- ObjectId textstyleID = new ObjectId();
- string stylename = "HZ";
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
- TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
-
- if (styletable.Has(stylename) == false)
- {
- TextStyleTableRecord R1 = new TextStyleTableRecord();
- R1.Name = stylename;
- //R1.FileName = "方正细等线简体";
- R1.FileName = "rs.shx";
- R1.BigFontFileName = "hztxt.shx";
- R1.ObliquingAngle = 0;
- R1.XScale = 1;
- //textstyleID = styletable.Add(R1);
- traction.AddNewlyCreatedDBObject(R1, true);
- //database.TextStyleId = textstyleID;
- }
- traction.Commit();
- }
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
- TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
- TextStyleTableRecord record = traction.GetObject(styletable[stylename], OpenMode.ForRead) as TextStyleTableRecord;
- textstyleID = record.ObjectId;
- traction.Commit();
- }
- return textstyleID;
- }
- }
- }
-
|