12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- using System.Diagnostics;
-
- using GrxCAD.Geometry;
- using GrxCAD.DatabaseServices;
- using GrxCAD.ApplicationServices;
- using GrxCAD.EditorInput;
-
-
-
- namespace HCTools
- {
- public struct Contourpoint
- {
- public double x;
- public double y;
- public double z;
- public ObjectId objID;
- }
-
- /// <summary>
- /// 记录闭合等高线高程和距高程点距离
- /// 包含高程和距离
- /// </summary>
- public struct closecontour
- {
- public double elevation;
- public double interval;
- }
-
- /// <summary>
- /// 判断点线是否有矛盾
- /// </summary>
- class ChPLContradiction
- {
- public static int blc;//比例尺
- public static string sqx;//首曲线
- public static string jqx;//计曲线
- public const int looptimes = 5;//循环查找次数
- public static string elevationLayer;//高程点图层名
- public int leng;//查找距离
- int temp;
-
- public int windowwidth;//当前可视范围
- public int windowheight;
-
-
- //存放所有高程点数组
- public List<Contourpoint> pointarrlist = new List<Contourpoint>();
-
- //存放有问题的高程点数组
- public List<Contourpoint> errorpointarrlist = new List<Contourpoint>();
-
- //存放无法识别点数组
- public List<Contourpoint> unrecognize = new List<Contourpoint>();
-
- //存放搜索到的等高线用于判断是否重复
- public List<Polyline> plltemp = new List<Polyline>();
- public List<Polyline2d> pll2dtemp = new List<Polyline2d>();
-
-
- /// <summary>
- /// 检测点线矛盾,并画圆标记出错误点
- /// </summary>
-
- public void contourch()
- {
- Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
-
- //清空各数组
- pointarrlist.Clear();
- errorpointarrlist.Clear();
-
-
- double flagradius = 4.0 * blc / 1000;//画圆标记半径
- leng = Convert.ToInt32(flagradius + 8);//确定搜索距离
- temp = leng;
- windowwidth = 30 * 4 * blc / 1000;//确定可视范围
- windowheight = 30 * 4 * blc / 1000;
-
-
- selectcontourpoint(elevationLayer);//选出高程点
- if (pointarrlist.Count == 0)
- {
- return;
- }
-
-
- //开始计时
- Stopwatch watch = new Stopwatch();
- watch.Start();
-
- LayerControl layerscontrol = new LayerControl();
- string layname = "点线矛盾标记图层";
- if (layerscontrol.haslayername(layname) == false)
- {
- colorgb col = new colorgb(255, 0, 0);
- layerscontrol.creatlayer(layname, col);
- }
- layname = "点线矛盾高程点图层";
- if (layerscontrol.haslayername(layname) == false)
- {
- colorgb col = new colorgb(255, 255, 0);
- layerscontrol.creatlayer(layname, col);
- layerscontrol.movelayertofront(layname);
- }
- layname = "无法识别";
- if (layerscontrol.haslayername(layname) == false)
- {
- colorgb colo = new colorgb(0, 255, 0);
- layerscontrol.creatlayer(layname, colo);
- }
-
- //遍历各高程点,检测是否高程值有错误
- for (int i = 0; i < pointarrlist.Count; i++)
- {
- Contourpoint p = pointarrlist[i];
- check(p);
- }
-
- Database database = HostApplicationServices.WorkingDatabase;
-
-
- //遍历各错误高程点,画圆标记出
- for (int i = 0; i < errorpointarrlist.Count; i++)
- {
- Contourpoint p = errorpointarrlist[i];
- double x = p.x;
- double y = p.y;
- double z = p.z;
- ObjectId id = p.objID;
-
- using (Transaction acTrans = database.TransactionManager.StartTransaction())
- {
- ViewTableRecord currview = editor.GetCurrentView();
- currview.CenterPoint = new Point2d(x, y);
- currview.ViewDirection = new Vector3d(0, 0, 1);
- currview.Width = windowwidth;
- currview.Height = windowheight;
- editor.SetCurrentView(currview);
- acTrans.Commit();
- }
-
- Transaction traction = database.TransactionManager.StartTransaction();
- DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- BlockTable blocktable = traction.GetObject(database.BlockTableId,
- OpenMode.ForWrite) as BlockTable;
- makeflag(errorpointarrlist[i].x, errorpointarrlist[i].y, 0, flagradius, 1);
- Entity entity = (Entity)traction.GetObject(id, OpenMode.ForWrite);
- entity.Layer = "点线矛盾高程点图层";
-
-
- //ViewTableRecord currview = editor.GetCurrentView();
- //currview.CenterPoint = new Point2d(x, y);
- //currview.ViewDirection = new Vector3d(0, 0, 1);
- //currview.Width = windowwidth;
- //currview.Height = windowheight;
- //editor.SetCurrentView(currview);
-
- Point3d p1 = new Point3d(p.x - 4 * blc / 2000, p.y - 4 * blc / 2000, 0);
- Point3d p2 = new Point3d(p.x + 4 * blc / 2000, p.y + 4 * blc / 2000, 0);
- TypedValue[] typedvalue = new TypedValue[2];
-
- typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, elevationLayer), 1);
-
- SelectionFilter filter = new SelectionFilter(typedvalue);
- PromptSelectionResult psr = editor.SelectCrossingWindow(p1, p2, filter);
-
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet set = psr.Value;
- ObjectId[] objs = new ObjectId[set.Count];
- objs = set.GetObjectIds();
- for (int ii = 0; ii < objs.Length; ii++)
- {
- Entity Text = (Entity)traction.GetObject(objs[ii], OpenMode.ForWrite);
-
- DBText T = (DBText)Text;
-
- double T_Value = Convert.ToDouble(T.TextString);
-
- if (T_Value == z)
- {
- T.Layer = "点线矛盾高程点图层";
-
- }
- }
- }
- traction.Commit();
- documentlock.Dispose();
- }
-
-
-
-
- for (int i = 0; i < unrecognize.Count; i++)
- {
- makeflag(unrecognize[i].x, unrecognize[i].y, 0, flagradius, 2);
- }
-
-
-
-
-
- //耗时
- watch.Stop();
- long times = watch.ElapsedMilliseconds;
-
- //editor.Regen();
- //editor.UpdateScreen();
-
- editor.WriteMessage("\n" + "耗时:" + times.ToString() + "毫秒");
- editor.WriteMessage("\n" + "检测到错误高程点" + errorpointarrlist.Count.ToString());
- editor.WriteMessage("\n" + "检测到无法识别点" + unrecognize.Count.ToString());
- editor.WriteMessage("\n");
-
-
-
- }
-
-
-
- /// <summary>
- /// 在错误高程点处画圆标记
- /// </summary>
- /// <param name="radius">圆的半径</param>
- public void makeflag(double x, double y, double z, double radius, int type)
- {
- Database database = HostApplicationServices.WorkingDatabase;
- DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- Transaction traction = database.TransactionManager.StartTransaction();
- try
- {
- BlockTable blocktable;
- blocktable = traction.GetObject(database.BlockTableId,
- OpenMode.ForWrite) as BlockTable;
-
- BlockTableRecord blocktablerecord;
- blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
-
-
- Circle circ = new Circle();
- if (type == 1)
- {
- circ.Layer = "点线矛盾标记图层";
- }
- else if (type == 2)
- {
- circ.Layer = "无法识别";
- }
-
- circ.Center = new Point3d(x, y, z);
- circ.Radius = radius;
- circ.Normal = new Vector3d(0, 0, 1);
- circ.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(circ);
- traction.AddNewlyCreatedDBObject(circ, true);
- traction.Commit();
- }
- catch (GrxCAD.Runtime.Exception)
- {
- traction.Abort();
- }
- finally
- {
- doclock.Dispose();
- traction.Dispose();
- }
-
- }
-
-
-
- /// <summary>
- /// 选出所有高程点,并取出其x,y,z坐标
- /// </summary>
- /// <param name="layername">高程点图层名</param>
- public void selectcontourpoint(string layername)
- {
- Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database database = HostApplicationServices.WorkingDatabase;
-
- // 获得当前文档的编辑器
- Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- // 创建一个 TypedValue 数组,用于定义过滤条件
- TypedValue[] typedvalue = new TypedValue[1];
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, layername), 0);
- // 赋值过滤条件给 SelectionFilter 对象
- SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
- // 要求在图形区域中手动选择对象
- PromptSelectionResult psr = editor.GetSelection(selectionfilter);
- //自动选择图像区域全部对象
- //PromptSelectionResult psr = editor.SelectAll(selectionfilter);
-
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet selectionset = psr.Value;
- ObjectId[] obj = new ObjectId[selectionset.Count];
- obj = selectionset.GetObjectIds();
-
-
- for (int i = 0; i < obj.Length; i++)
- {
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
- ObjectId objid = obj[i];
-
- //找到实体,取出高程点的x,y,z
- Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead);
-
- if (entity is BlockReference)
- {
- BlockReference blockreference = (BlockReference)entity;
- Contourpoint cp = new Contourpoint();
-
- cp.x = Math.Round(blockreference.Position.X, 4, MidpointRounding.AwayFromZero);
- cp.y = Math.Round(blockreference.Position.Y, 4, MidpointRounding.AwayFromZero);
- cp.z = Math.Round(blockreference.Position.Z, 4, MidpointRounding.AwayFromZero);
- cp.objID = objid;
- pointarrlist.Add(cp);
- }
- traction.Commit();
- }
- }
- editor.WriteMessage("\n" + "选中高程点数量:" + pointarrlist.Count.ToString());
- }
- }
-
-
-
- /// <summary>
- /// 检查是否错误
- /// </summary>
- public void check(Contourpoint p)
- {
- double x = Math.Round(p.x, 4, MidpointRounding.AwayFromZero);
- double y = Math.Round(p.y, 4, MidpointRounding.AwayFromZero);
- double z = Math.Round(p.z, 4, MidpointRounding.AwayFromZero);
-
- List<double> toplist = calculatevalue(x, y, z, 1);
- List<double> belowlist = calculatevalue(x, y, z, 3);
-
-
-
- //点在上下两条等高线中间情况
-
- if ((toplist.Count > 0) && (belowlist.Count > 0))
- {
- //1.一般情况
- #region 一般情况
- if (toplist[0] > belowlist[belowlist.Count - 1])
- {
- //高程值上大小小
- if (z >= toplist[0] || z <= belowlist[belowlist.Count - 1])
- {
- errorpointarrlist.Add(p);
- return;
- }
- else
- return;
- }
- //高程值上小下大
- if (toplist[toplist.Count - 1] < belowlist[0])
- {
- if (z >= belowlist[0] || z <= toplist[toplist.Count - 1])
- {
- errorpointarrlist.Add(p);
- return;
- }
- else
- return;
-
- }
-
-
-
-
- #endregion
-
- //点在左右半包围情况,上下高程相等,要么是最大,要么是最小,进行左右搜索比较
- //2.半包围一般情况
- #region 半包围一般情况
- if ((toplist[0] == belowlist[0]) || (toplist[toplist.Count - 1] == belowlist[belowlist.Count - 1]))
- {
- List<double> rightlist = calculatevalue(x, y, z, 4);
- List<double> leftlist = calculatevalue(x, y, z, 2);
-
-
- if ((rightlist.Count > 0) && (leftlist.Count > 0))
- {
-
- //高程值右大左小
- if (rightlist[0] > leftlist[leftlist.Count - 1])
- {
- if ((z >= rightlist[0]) || (z <= leftlist[leftlist.Count - 1]))
- {
- errorpointarrlist.Add(p);
- return;
- }
- else
- return;
- }
- //高程值右小左大
- if (leftlist[0] > rightlist[rightlist.Count - 1])
- {
- if ((z >= leftlist[0]) || (z <= rightlist[rightlist.Count - 1]))
- {
- errorpointarrlist.Add(p);
- return;
- }
- else
- return;
- }
- #endregion
- //3.大半包围或闭合情况,即上下左右高程值相等
- #region 四面闭合
- if ((rightlist[0] == leftlist[0]) || (rightlist[rightlist.Count - 1] == leftlist[leftlist.Count - 1]))
- {
- //ArrayList closecontourlist = new ArrayList();
- List<closecontour> closecontourlist = new List<closecontour>();
- closecontourlist = closecontourcheck(p, 1);
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 3);
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 2);
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 4);
- if (closecontourlist.Count < 2)
- {
- unrecognize.Add(p);
- return;
- }
- }
- }
- }
-
-
-
- //存储高程值计算等高距
- List<double> ele = new List<double>();
- if (closecontourlist.Count >= 2)
- {
- double minidistance = closecontourlist[0].interval;
- double contour = closecontourlist[0].elevation;
- ele.Add(contour);
-
- for (int i = 1; i < closecontourlist.Count; i++)
- {
- if (closecontourlist[i].interval < minidistance)
- {
- minidistance = closecontourlist[i].interval;
- contour = closecontourlist[i].elevation;
- }
- ele.Add(closecontourlist[i].elevation);
-
- }
- //从小到大排序
- ele.Sort();
- //等高距
- double contourinterval = ele[1] - ele[0];
-
-
- //中间高程最小
- if (contour == ele[0])
- {
- if ((z - ele[0] >= 0) || ((ele[0] - contourinterval) - z >= 0))
- //if ((z > ele[0]) || z < (ele[0] - contourinterval))
- {
- errorpointarrlist.Add(p);
- return;
- }
- else
- return;
- }
- //中间高程最大
- if (contour == ele[ele.Count - 1])
- {
- if ((z - (ele[ele.Count - 1] + contourinterval) >= 0) || ele[ele.Count - 1] - z >= 0)
- //if (z > (ele[ele.Count - 1] + contourinterval) || z < ele[ele.Count - 1])
- {
- errorpointarrlist.Add(p);
- return;
- }
- else
- return;
- }
- }
-
- }
- #endregion
- }
-
- //4.上下左、上下右三方闭合
- #region 上下左、上下右三方闭合
- else
- {
- List<closecontour> closecontourlist = new List<closecontour>();
- //找出等高线条数大于2的方向进行搜索
-
- if (toplist.Count >= 2)
- {
- closecontourlist = closecontourcheck(p, 1);
- }
- else if (belowlist.Count >= 2)
- {
- closecontourlist = closecontourcheck(p, 3);
- }
- else if (leftlist.Count >= 2)
- {
- closecontourlist = closecontourcheck(p, 4);
- }
- else
- closecontourlist = closecontourcheck(p, 2);
-
-
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 3);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 1);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 4);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 2);
- }
-
- if (closecontourlist.Count >= 2)
- {
- compareelevation(p, closecontourlist);
- return;
- }
- else
- {
- unrecognize.Add(p);
- }
-
- }
- #endregion
-
- }
- }
-
- //上下方向没有搜索两条等高线,则向左右方向搜索
- if (toplist.Count == 0 || belowlist.Count == 0)
- {
- checkleftright(p);
- }
-
- }
-
-
-
- /// <summary>
- /// 比较高程点值和该高程点左右等高线高程
- /// </summary>
- public void checkleftright(Contourpoint p)
- {
- double x = Math.Round(p.x, 4, MidpointRounding.AwayFromZero);
- double y = Math.Round(p.y, 4, MidpointRounding.AwayFromZero);
- double z = Math.Round(p.z, 4, MidpointRounding.AwayFromZero);
-
- List<double> rightlist = calculatevalue(x, y, z, 4);
- List<double> leftlist = calculatevalue(x, y, z, 2);
- //
- if (rightlist.Count > 0 && leftlist.Count > 0)
- {
- //右大左小
- if (rightlist[0] > leftlist[leftlist.Count - 1])
- {
- if (z > rightlist[0] || z < leftlist[leftlist.Count - 1])
- {
- errorpointarrlist.Add(p);
- return;
- }
- }
- //右小左大
- if (leftlist[0] > rightlist[rightlist.Count - 1])
- {
- if (z > leftlist[0] || z < rightlist[rightlist.Count - 1])
- {
- errorpointarrlist.Add(p);
- return;
- }
- }
-
- //左右相等,左右上、或者左右下三方闭合
- if ((leftlist[0] == rightlist[0]) || (leftlist[leftlist.Count - 1] == rightlist[rightlist.Count - 1]))
- {
- List<double> toplist = calculatevalue(x, y, z, 1);
- List<double> belowlist = calculatevalue(x, y, z, 3);
- #region
- //ArrayList closecontourlist = new ArrayList();
- List<closecontour> closecontourlist = new List<closecontour>();
- //找出等高线条数大于2的方向进行搜索
-
- if (leftlist.Count >= 2)
- {
- closecontourlist = closecontourcheck(p, 2);
- }
- else if (rightlist.Count >= 2)
- {
- closecontourlist = closecontourcheck(p, 4);
- }
- else if (toplist.Count >= 2)
- {
- closecontourlist = closecontourcheck(p, 1);
- }
- else
- closecontourlist = closecontourcheck(p, 3);
-
-
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 2);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 4);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 1);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 3);
- }
-
- if (closecontourlist.Count >= 2)
- {
- compareelevation(p, closecontourlist);
- return;
- }
- else
- {
- unrecognize.Add(p);
- return;
- }
-
- #endregion
-
- }
-
-
- }
- //边缘情况
- else
- {
- List<double> toplist = calculatevalue(x, y, z, 1);
- List<double> belowlist = calculatevalue(x, y, z, 3);
- //ArrayList closecontourlist = new ArrayList();
- List<closecontour> closecontourlist = new List<closecontour>();
- //找出等高线条数大于1的方向进行搜索
-
- if (leftlist.Count >= 1)
- {
- closecontourlist = closecontourcheck(p, 2);
- }
- else if (rightlist.Count >= 1)
- {
- closecontourlist = closecontourcheck(p, 4);
- }
- else if (toplist.Count >= 1)
- {
- closecontourlist = closecontourcheck(p, 1);
- }
- else
- closecontourlist = closecontourcheck(p, 3);
-
-
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 2);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 4);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 1);
- }
- if (closecontourlist.Count < 2)
- {
- closecontourlist = closecontourcheck(p, 3);
- }
-
- if (closecontourlist.Count >= 2)
- {
- compareelevation(p, closecontourlist);
- return;
- }
- else
- {
- unrecognize.Add(p);
- return;
- }
-
-
-
- }
-
- }
-
-
- /// <summary>
- /// 从高程点向上搜索,找到上的等高线,并取得其高程值
- /// </summary>
- /// <param name="direction">搜索方向,上、下、左、右分别为1、3、2、4</param>
- /// <returns>以数组List(double)形式从小到大排序之后返回搜索到的各等高线高程</returns>
- public List<double> calculatevalue(double x, double y, double z, int direction)
- {
-
- Database database = HostApplicationServices.WorkingDatabase;
- Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
-
-
- Point3dCollection ptcoll = new Point3dCollection();
- List<double> elevation = new List<double>();
- try
- {
- //ViewTableRecord currview = editor.GetCurrentView();
- //currview.CenterPoint = new Point2d(x, y);
- //currview.ViewDirection = new Vector3d(0, 0, 1);
- //currview.Width = windowwidth;
- //currview.Height = windowheight;
- //editor.SetCurrentView(currview);
-
-
- double high = y;
- double width = x;
- bool flag = true;
- int times = 0;
- PromptSelectionResult pselectresult;
- Point3d p1, p2;
- while (flag)
- {
- times++;
- if (times > looptimes)
- {
- leng = temp;
- break;
- }
-
- leng = leng * times;
-
- if (direction == 1)
- {
- high += leng;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(x, high, 0);
- }
- else if (direction == 3)
- {
- high -= leng;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(x, high, 0);
- }
- else if (direction == 2)
- {
- width -= leng;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(width, y, 0);
- }
- else
- {
- width += leng;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(width, y, 0);
- }
- ptcoll.Add(p1);
- ptcoll.Add(p2);
-
-
- string filttext = sqx + "," + jqx;
- TypedValue[] filterlist = new TypedValue[1]
- {
- new TypedValue((int)DxfCode.LayerName,filttext)
- };
- //filterelist.SetValue(new TypedValue((int)DxfCode.LayerName, "8110,8120"),0);
- // 赋值过滤条件给 SelectionFilter 对象
- SelectionFilter filter = new SelectionFilter(filterlist);
-
-
- dynamic acadApp = Application.AcadApplication;
- acadApp.ZoomExtents();
- pselectresult = editor.SelectFence(ptcoll, filter);
- acadApp.ZoomPrevious();
-
- if (pselectresult.Status == PromptStatus.OK)
- {
- SelectionSet selectionset = pselectresult.Value;
- ObjectId[] obj = new ObjectId[selectionset.Count];
- obj = selectionset.GetObjectIds();
-
- DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- for (int i = 0; i < obj.Length; i++)
- {
- Transaction traction = database.TransactionManager.StartTransaction();
-
- BlockTable blocktable = traction.GetObject(database.BlockTableId,
- OpenMode.ForWrite) as BlockTable;
-
-
- BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
- ObjectId objid = obj[i];
- Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead);
-
- if (entity is Polyline)
- {
- Polyline pline = (Polyline)entity;
- double ele = pline.Elevation;
- elevation.Add(ele);
- plltemp.Add(pline);
- }
- if (entity is Polyline2d)
- {
- Polyline2d pline2d = (Polyline2d)entity;
- double ele = pline2d.Elevation;
- elevation.Add(ele);
- pll2dtemp.Add(pline2d);
- }
- traction.Commit();
- traction.Dispose();
- }
- doclock.Dispose();
- }
- ptcoll.Clear();
- if (elevation.Count > 0)
- {
- leng = temp;
- flag = false;
- //Line line = new Line(p1, p2);
- //line.SetDatabaseDefaults();
- //blocktablerecord.AppendEntity(line);
- //traction.AddNewlyCreatedDBObject(line, true);
- }
-
-
- }
- elevation.Sort();
- return elevation;
- }
-
- catch (GrxCAD.Runtime.Exception ex)
- {
- string str = ex.ToString();
- Application.ShowAlertDialog(str);
- return elevation;
-
- }
- //finally
- //{
-
- //}
-
- }
-
-
- /// <summary>
- /// 上下方向搜索距离高程点距离最近的等高线的高程和距离
- /// </summary>
- /// <param name="direction">搜索方向,1、2、3、4分别代表上、下、左、右</param>
- /// <returns>以list返回闭合等高线结构体数组</returns>
- public List<closecontour> closecontourcheck(Contourpoint p, int direction)
- {
- double x = p.x;
- double y = p.y;
- double z = p.z;
- Database database = HostApplicationServices.WorkingDatabase;
- Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- List<closecontour> arrlist = new List<closecontour>();
-
- double high = y;
- double width = x;
- bool flag = true;
- int times = 0;
- PromptSelectionResult pselectresult;
- Point3d p1, p2;
-
- while (flag)
- {
- //清空上一次选中的不足两个的对象
- arrlist.Clear();
-
- times++;
- if (times > looptimes)
- {
- leng = temp;
- break;
- }
-
- leng = leng * times;
-
- //向上搜索
- if (direction == 1)
- {
- high += leng;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(x + 0.001, high, 0);
- }
- //向下搜索
- else if (direction == 3)
- {
- high -= leng;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(x + 0.001, high, 0);
- }
- //向左搜索
- else if (direction == 2)
- {
- width -= leng;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(width, y + 0.001, 0);
- }
- //向右搜索
- else
- {
- width += leng;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(width, y + 0.001, 0);
- }
-
- string filttext = sqx + "," + jqx;
- TypedValue[] filterlist = new TypedValue[1]
- {
- new TypedValue((int)DxfCode.LayerName,filttext)
- };
- SelectionFilter filter = new SelectionFilter(filterlist);
-
- dynamic acadApp = Application.AcadApplication;
- acadApp.ZoomExtents();
- pselectresult = editor.SelectCrossingWindow(p1, p2, filter);
- acadApp.ZoomPrevious();
-
- if (pselectresult.Status == PromptStatus.OK)
- {
- SelectionSet selectionset = pselectresult.Value;
- ObjectId[] obj = new ObjectId[selectionset.Count];
- obj = selectionset.GetObjectIds();
- for (int i = 0; i < obj.Length; i++)
- {
- if (obj.Length < 2)
- break;
-
- DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
-
- BlockTable blocktable = traction.GetObject(database.BlockTableId,OpenMode.ForWrite) as BlockTable;
- BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
- //else
- //{
- // Line line = new Line(p1, p2);
- // line.SetDatabaseDefaults();
- // blocktablerecord.AppendEntity(line);
- // traction.AddNewlyCreatedDBObject(line, true);
- //}
-
- ObjectId objid = obj[i];
- Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead);
-
- if (entity is Polyline)
- {
- Polyline pline = (Polyline)entity;
-
- Point3d pt = pline.GetClosestPointTo(new Point3d(x, y, z), new Vector3d(0, 0, 1), false);
- double distance = System.Math.Sqrt((pt.X - x) * (pt.X - x) + (pt.Y - y) * (pt.Y - y));
- double elev = pline.Elevation;
-
- closecontour cc = new closecontour();
- cc.elevation = elev;
- cc.interval = distance;
- arrlist.Add(cc);
-
-
- //Line line = new Line(new Point3d(x, y, z), new Point3d(p.X, p.Y, p.Z));
- //line.SetDatabaseDefaults();
- //blocktablerecord.AppendEntity(line);
- //traction.AddNewlyCreatedDBObject(line, true);
-
-
- }
- if (entity is Polyline2d)
- {
- Polyline2d pline2d = (Polyline2d)entity;
-
- Point3d pt = pline2d.GetClosestPointTo(new Point3d(x, y, z), new Vector3d(0, 0, 1), false);
- double distance = System.Math.Sqrt((pt.X - x) * (pt.X - x) + (pt.Y - y) * (pt.Y - y));
- double elev = pline2d.Elevation;
-
- closecontour cc = new closecontour();
- cc.elevation = elev;
- cc.interval = distance;
- arrlist.Add(cc);
-
-
-
- //Line line = new Line(new Point3d(x, y, z), new Point3d(p.X, p.Y, p.Z));
- //line.SetDatabaseDefaults();
- //blocktablerecord.AppendEntity(line);
- //traction.AddNewlyCreatedDBObject(line, true);
-
- }
- traction.Commit();
- }
- doclock.Dispose();
- }
- if (arrlist.Count >= 2)
- {
- flag = false;
- }
- }
- }
- return arrlist;
- }
-
-
-
-
- /// <summary>
- /// 在闭合等高线处,根据高程点周围等高线高程变化趋势。判断高程点的高程范围
- /// </summary>
- /// <param name="arrlist">高程点周围等高线高程</param>
- public void compareelevation(Contourpoint p, List<closecontour> arrlist)
- {
- double x = p.x;
- double y = p.y;
- double z = p.z;
-
- //存储高程值计算等高距
- List<double> ele = new List<double>();
- if (arrlist.Count >= 2)
- {
-
- double minidistance = arrlist[0].interval;
- double contour = arrlist[0].elevation;
- ele.Add(contour);
- for (int i = 1; i < arrlist.Count; i++)
- {
- if (arrlist[i].interval < minidistance)
- {
- minidistance = arrlist[i].interval;
- contour = arrlist[i].elevation;
- }
- ele.Add(arrlist[i].elevation);
- }
-
-
- //从小到大排序
- ele.Sort();
- //等高距
- double contourinterval = ele[1] - ele[0];
-
- //中间高程最小
- if (contour == ele[0])
- {
- if (z > ele[0] || z < (ele[0] - contourinterval))
- {
- errorpointarrlist.Add(p);
- return;
- }
- else
- return;
- }
- //中间高程最大
- if (contour == ele[ele.Count - 1])
- {
- if (z > (ele[ele.Count - 1] + contourinterval) || z < ele[ele.Count - 1])
- {
- errorpointarrlist.Add(p);
- return;
- }
- else
- return;
- }
- }
- }
-
-
-
-
-
-
- }
- }
|