12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307 |
- using GrxCAD.ApplicationServices;
- using GrxCAD.DatabaseServices;
- using GrxCAD.EditorInput;
- using GrxCAD.Geometry;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace HCTools
- {
- public partial class OutputbyTK_Form : Form
- {
- public OutputbyTK_Form()
- {
- InitializeComponent();
- }
-
- private void OutputbyTK_Form_Load(object sender, EventArgs e)
- {
- this.comboBox_tk.DropDownStyle = ComboBoxStyle.DropDownList;
- this.comboBox_num.DropDownStyle = ComboBoxStyle.DropDownList;
-
- //自动填充下拉框
- Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
- //存放所有图层名
- List<string> alllayername = new List<string>();
- LayerTable layertable = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable;
- foreach (ObjectId objid in layertable)
- {
- LayerTableRecord layertablerecord = traction.GetObject(objid, OpenMode.ForRead) as LayerTableRecord;
- alllayername.Add(layertablerecord.Name);
- }
-
- alllayername.Sort();
-
- for (int i = 0; i < alllayername.Count; i++)
- {
- this.comboBox_tk.Items.Add(alllayername[i]);
- this.comboBox_num.Items.Add(alllayername[i]);
- }
-
- if (alllayername.Contains("TK"))
- {
- int index = alllayername.IndexOf("TK");
- this.comboBox_tk.SelectedIndex = index;
- }
- traction.Commit();
- }
- }
-
- private void button_sele_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog open = new FolderBrowserDialog();
- open.Description = "请选择文件夹";
- if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- textBox_output.Text = open.SelectedPath;
- }
-
- private void button_ok_Click(object sender, EventArgs e)
- {
- if(comboBox_tk.Text=="")
- {
- MessageBox.Show("请选择分幅图框所在图层");
- return;
- }
- if (comboBox_num.Text == "")
- {
- MessageBox.Show("请选择分幅图号所在图层");
- return;
- }
- if (textBox_output.Text=="")
- {
- MessageBox.Show("请选择文件输出位置");
- return;
- }
- string lyr = comboBox_tk.SelectedItem.ToString();
- string output = textBox_output.Text.ToString();
- cutline(lyr, output);
- this.Close();
- }
-
- private void cutline(string lyr,string output)
- {
- dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
- acadApp.ZoomExtents();
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
-
- List<string> tfh = new List<string>();//图幅号
- List<Point3dCollection> ptcolls = new List<Point3dCollection>();//图幅框节点
- //List<Entity> tks = new List<Entity>();//图幅框
-
- //获取分幅图框
- TypedValue[] typedvalue = new TypedValue[2];
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, lyr), 0);
- typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Polyline,LWPolyline"), 1);
- SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
- PromptSelectionResult psr = ed.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++)
- {
- Database db = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- DBObjectCollection objcoll = new DBObjectCollection();//与图幅框相交的实体
- //获取图幅框信息和与图幅框相交的实体
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- Entity ent0 = tr.GetObject(obj[i], OpenMode.ForRead) as Entity;
-
- Point3dCollection pts = getpt(ent0);
- ptcolls.Add(pts);
-
- string num = "";
- //获取图幅号
- TypedValue[] typed_T = new TypedValue[2];
- typed_T.SetValue(new TypedValue((int)DxfCode.LayerName, comboBox_num.SelectedItem.ToString()), 0);
- typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 1);
- SelectionFilter filter_T = new SelectionFilter(typed_T);
- PromptSelectionResult psr_T = ed.SelectWindow(pts[0], pts[2], filter_T);
- if (psr_T.Status == PromptStatus.OK)
- {
- SelectionSet ss_T = psr_T.Value;
- ObjectId[] obj_T = new ObjectId[ss_T.Count];
- obj_T = ss_T.GetObjectIds();
- DBText T = tr.GetObject(obj_T[0], OpenMode.ForRead) as DBText;
- num = T.TextString.ToString();
- }
- tfh.Add(num);
-
- ViewTableRecord currview = ed.GetCurrentView();
- currview.CenterPoint = new Point2d((pts[2].X - pts[0].X) / 2 + pts[0].X,
- (pts[2].Y - pts[0].Y) / 2 + pts[0].Y);
- currview.ViewDirection = new Vector3d(0, 0, 1);
- currview.Width = pts[2].X - pts[0].X;
- currview.Height = pts[2].Y - pts[0].Y;
- ed.SetCurrentView(currview);
-
- PromptSelectionResult psr1 = ed.SelectCrossingPolygon(pts);
- if (psr1.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr1.Value;
- ObjectId[] objids = new ObjectId[ss.Count];
- objids = ss.GetObjectIds();
-
- for (int ii = 0; ii < objids.Length; ii++)
- {
- Entity ent = tr.GetObject(objids[ii], OpenMode.ForRead) as Entity;
- if (ent.Layer != lyr && ent.Layer != comboBox_num.Text)
- objcoll.Add(ent);
- }
- }
- tr.Commit();
- }
-
- //新建dwg
- string templatePath = "acad.dwt";
- DocumentCollection documentcoll = GrxCAD.ApplicationServices.Application.DocumentManager;
- Document document = documentcoll.Add(templatePath);
- Database newDb = document.Database;
- newDb.Ltscale = db.Ltscale;
-
- //复制图层
- using (Transaction traction = db.TransactionManager.StartTransaction())
- {
- //存放所有图层名
- List<string> alllayername = new List<string>();
- LayerTable layertable = traction.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
- foreach (ObjectId objid in layertable)
- {
- LayerTableRecord layertablerecord = traction.GetObject(objid, OpenMode.ForRead) as LayerTableRecord;
- alllayername.Add(layertablerecord.Name);
- }
- LayerControl layerscontrol = new LayerControl();
- for (int ii = 0; ii < alllayername.Count; ii++)
- {
- if (!layerscontrol.haslayername(alllayername[ii]) &&
- alllayername[ii] != lyr && alllayername[ii] != comboBox_num.SelectedItem.ToString())
- {
- //设置图层颜色
- LayerTable layerTable = traction.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
- LayerTableRecord layerRecord = traction.GetObject(layerTable[alllayername[ii]], OpenMode.ForRead) as LayerTableRecord;
- colorgb col = new colorgb(layerRecord.Color.Red, layerRecord.Color.Green, layerRecord.Color.Blue);
- layerscontrol.creatlayer(alllayername[ii], col);
- }
- }
- traction.Commit();
- }
-
- //复制与范围相交和在范围内的实体
- ObjectIdCollection ps2ids = new ObjectIdCollection();
- foreach (DBObject dbobj in objcoll)
- {
- ps2ids.Add(dbobj.ObjectId);
- }
- using (Transaction newtrans = newDb.TransactionManager.StartTransaction())
- {
- BlockTable targetBlockTable = newtrans.GetObject(newDb.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord targetModelSpace = newtrans.GetObject(targetBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
- using (IdMapping mapping = new IdMapping())
- db.WblockCloneObjects(ps2ids, targetModelSpace.ObjectId, mapping, DuplicateRecordCloning.Replace, false);
- newtrans.Commit();
- }
-
- //acadApp.ZoomExtents();
- //设置当前视图
- Editor edit = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- ViewTableRecord currview1 = ed.GetCurrentView();
- currview1.CenterPoint = new Point2d((ptcolls[i][2].X - ptcolls[i][0].X) / 2 + ptcolls[i][0].X,
- (ptcolls[i][2].Y - ptcolls[i][0].Y) / 2 + ptcolls[i][0].Y);
- //currview1.ViewDirection = new Vector3d(0, 0, 1);
- currview1.Width = ptcolls[i][2].X - ptcolls[i][0].X;
- currview1.Height = ptcolls[i][2].Y - ptcolls[i][0].Y;
- edit.SetCurrentView(currview1);
-
-
- //按图框范围框选实体,因为浩辰的选择有问题,所以还要全选,对比两个选择集中的实体,
- //将漏选范围外实体删除。
- PromptSelectionResult psr_intersect = edit.SelectCrossingPolygon(ptcolls[i]);
- PromptSelectionResult psr_all = edit.SelectAll();
- if (psr_intersect.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr_intersect.Value;
- SelectionSet ss_all = psr_all.Value;
- ObjectId[] objids = new ObjectId[ss.Count];
- ObjectId[] objids_all = new ObjectId[ss_all.Count];
- objids = ss.GetObjectIds();
- objids_all = ss_all.GetObjectIds();
- List<ObjectId> outside = new List<ObjectId>();
- foreach (ObjectId id in objids_all)
- {
- outside.Add(id);
- }
- using (Transaction newtr = newDb.TransactionManager.StartTransaction())
- {
- BlockTable newBt = newtr.GetObject(newDb.BlockTableId, OpenMode.ForWrite) as BlockTable;
- BlockTableRecord newBtr = newtr.GetObject(newBt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
-
- Polyline line = new Polyline();
-
- //画范围线
- for (int ct = 0; ct < ptcolls[i].Count; ct++)
- {
- line.AddVertexAt(ct, new Point2d(ptcolls[i][ct].X, ptcolls[i][ct].Y), 0, 0, 0);
- }
- line.AddVertexAt(4, new Point2d(ptcolls[i][0].X, ptcolls[i][0].Y), 0, 0, 0);
- line.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
- line.Layer = "0";
- line.SetDatabaseDefaults();
- newBtr.AppendEntity(line);
- newtr.AddNewlyCreatedDBObject(line, true);
-
- //遍历实体,裁剪与范围相交的实体
- for (int ii = 0; ii < objids.Length; ii++)
- {
- if (outside.Contains(objids[ii]))
- outside.Remove(objids[ii]);
- Entity ent = newtr.GetObject(objids[ii], OpenMode.ForWrite) as Entity;
- if (ent.Layer != lyr && ent.Layer != comboBox_num.Text.ToString())
- copyclip(ent, line, newtr, newBtr, ptcolls[i]);
- else
- ent.Erase();
- }
- if (outside.Count != 0)
- {
- foreach (ObjectId id in outside)
- {
- Entity ent_outside = newtr.GetObject(id, OpenMode.ForWrite) as Entity;
- ent_outside.Erase();
- }
- }
- line.Erase();
- newtr.Commit();
- }
- }
- else if(psr_intersect.Status == PromptStatus.Error &&
- psr_all.Status == PromptStatus.OK)
- {
- SelectionSet ss_all = psr_all.Value;
- ObjectId[] objids_all = new ObjectId[ss_all.Count];
- objids_all = ss_all.GetObjectIds();
- using (Transaction newtr = newDb.TransactionManager.StartTransaction())
- {
- foreach(ObjectId id in objids_all)
- {
- Entity ent = newtr.GetObject(id, OpenMode.ForWrite)as Entity;
- ent.Erase();
- }
- newtr.Commit();
- }
- }
- acadApp.ZoomExtents();
- //保存新DWG文件
- string newFilePath = output + "\\" + tfh[i] + ".dwg";
- newDb.SaveAs(newFilePath, true, DwgVersion.AC1021, newDb.SecurityParameters);
- newDb.Dispose();
- document.CloseAndDiscard();
- }
- }
- }
-
- /// <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(Math.Round(x[0], 3, MidpointRounding.AwayFromZero), Math.Round(y[0], 3, MidpointRounding.AwayFromZero), 0); //左下
- ptcoll[1] = new Point3d(Math.Round(x[1], 3, MidpointRounding.AwayFromZero), Math.Round(y[0], 3, MidpointRounding.AwayFromZero), 0); //右下
- ptcoll[2] = new Point3d(Math.Round(x[1], 3, MidpointRounding.AwayFromZero), Math.Round(y[1], 3, MidpointRounding.AwayFromZero), 0); //右上
- ptcoll[3] = new Point3d(Math.Round(x[0], 3, MidpointRounding.AwayFromZero), Math.Round(y[1], 3, MidpointRounding.AwayFromZero), 0); //左上
- }
-
-
- private void copyclip(Entity ent, Polyline pll, Transaction newtr,
- BlockTableRecord newBtr, Point3dCollection pts)
- {
- var plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
-
- //多段线、二维多段线
- if (ent is Polyline||ent is Polyline2d)
- {
- Polyline pll_clip = new Polyline();
- pll_clip.SetDatabaseDefaults();
- if (ent is Polyline2d)
- {
- Polyline2d pl2d = (Polyline2d)ent;
- int ptnum = 0;
- foreach (ObjectId vertexId in pl2d)
- {
- Vertex2d vtx = newtr.GetObject(vertexId, OpenMode.ForRead) as Vertex2d;
- Point2d point = new Point2d(pl2d.VertexPosition(vtx).X, pl2d.VertexPosition(vtx).Y); // 获取顶点坐标
- double bulge = vtx.Bulge; // 获取凸度
- pll_clip.AddVertexAt(ptnum, point, bulge, 0, 0);
- ptnum++;
- }
- pll_clip.Layer = pl2d.Layer;
- pll_clip.Color = pl2d.Color;
- pll_clip.Linetype = pl2d.Linetype;
- pll_clip.Elevation = pl2d.Elevation;
- pll_clip.Plinegen = pl2d.LinetypeGenerationOn;
- pll_clip.ConstantWidth = pl2d.ConstantWidth;
- }
- else
- pll_clip = (Polyline)ent;
-
- Point3dCollection Verptcoll = new Point3dCollection();
- for (int i = 0; i < pll_clip.NumberOfVertices; i++)
- {
- double p_x = Math.Round(pll_clip.GetPoint3dAt(i).X, 3);
- double p_y = Math.Round(pll_clip.GetPoint3dAt(i).Y, 3);
- if (pts[0].X < p_x && p_x < pts[1].X &&
- pts[0].Y < p_y && p_y < pts[2].Y)
- continue;
- else
- Verptcoll.Add(pll_clip.GetPoint3dAt(i));
- }
-
- Point3dCollection ptcoll = new Point3dCollection();
- pll_clip.IntersectWith(pll, Intersect.OnBothOperands, plane, ptcoll, IntPtr.Zero, IntPtr.Zero);
-
- if (Verptcoll.Count == pll_clip.NumberOfVertices &&
- ptcoll.Count==0)
- {
- ent.Erase();
- return;
- }
- Point3d pt1 = pll_clip.GetPoint3dAt(0);
- Point3d ptn = pll_clip.GetPoint3dAt(pll_clip.NumberOfVertices - 1);
-
- //非闭合
- if (pll_clip.Closed == false && pt1!=ptn)
- {
- if (ptcoll.Count != 0)
- {
- DBObjectCollection objcoll = pll_clip.GetSplitCurves(ptcoll);
- foreach (Object obj in objcoll)
- {
- Polyline pll_cut = (Polyline)obj;
- pll_cut.Plinegen = pll_clip.Plinegen;
- if (pllinsidetk(pll_cut, pts))
- {
- newBtr.AppendEntity(pll_cut);
- newtr.AddNewlyCreatedDBObject(pll_cut, true);
- }
- }
- ent.Erase();
- }
- }
-
-
- //闭合
- else
- {
- if (ptcoll.Count == 0)
- return;
- double ele = pll_clip.Elevation;
- pll_clip.Elevation = 0;
-
- // 将多段线转换为曲线集合
- DBObjectCollection curvesToClip = new DBObjectCollection();
- curvesToClip.Add(pll_clip);
-
- DBObjectCollection boundaryCurves = new DBObjectCollection();
- boundaryCurves.Add(pll);
-
- // 创建 Region
- DBObjectCollection regionsToClip = new DBObjectCollection();
- DBObjectCollection boundaryRegions = new DBObjectCollection();
-
- try
- {
- // 将多段线转换为 Region
- regionsToClip = GrxCAD.DatabaseServices.Region.CreateFromCurves(curvesToClip);
- boundaryRegions = GrxCAD.DatabaseServices.Region.CreateFromCurves(boundaryCurves);
- }
- catch (Exception ex)
- {
- GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n错误: {ex.Message}");
- }
-
- // 执行布尔运算(交集)
- int deleindex = 0;
- foreach (GrxCAD.DatabaseServices.Region region in regionsToClip)
- {
- foreach (GrxCAD.DatabaseServices.Region boundary in boundaryRegions)
- {
- region.BooleanOperation(BooleanOperationType.BoolIntersect, boundary);
- DBObjectCollection explodedCurves = new DBObjectCollection();
- region.Explode(explodedCurves);
- if (deleindex == 0 && explodedCurves.Count != 0)
- {
- pll_clip.Erase();
- deleindex = 1;
- }
- foreach (DBObject obj in explodedCurves)
- {
- if (obj is GrxCAD.DatabaseServices.Region)
- {
- GrxCAD.DatabaseServices.Region subregion = (GrxCAD.DatabaseServices.Region)obj;
- DBObjectCollection subexplodedCurves = new DBObjectCollection();
- subregion.Explode(subexplodedCurves);
- Polyline polyline = createpllfromregion(subexplodedCurves);
- polyline.Elevation = ele;
- polyline.Layer = pll_clip.Layer;
- polyline.Color = pll_clip.Color;
- polyline.Linetype = pll_clip.Linetype;
- polyline.Plinegen = pll_clip.Plinegen;
- polyline.ConstantWidth = polyline.ConstantWidth;
- newBtr.AppendEntity(polyline);
- newtr.AddNewlyCreatedDBObject(polyline, true);
- }
- else
- {
- Polyline polyline = createpllfromregion(explodedCurves);
- polyline.Elevation = ele;
- polyline.Layer = pll_clip.Layer;
- polyline.Color = pll_clip.Color;
- polyline.Linetype = pll_clip.Linetype;
- polyline.Plinegen = pll_clip.Plinegen;
- polyline.ConstantWidth = polyline.ConstantWidth;
- newBtr.AppendEntity(polyline);
- newtr.AddNewlyCreatedDBObject(polyline, true);
- break;
- }
-
- }
- }
- }
-
- }
- }
-
- //三维多段线
- else if(ent is Polyline3d)
- {
- Polyline3d poly3d = (Polyline3d)ent;
-
- //Point3dCollection Verptcoll = new Point3dCollection();
- //poly3d.GetStretchPoints(Verptcoll);
- //int num = 0;
- //for (int i = 0; i < Verptcoll.Count; i++)
- //{
- // double p_x = Math.Round(Verptcoll[i].X, 3);
- // double p_y = Math.Round(Verptcoll[i].Y, 3);
- // if (pts[0].X < p_x && p_x < pts[1].X &&
- // pts[0].Y < p_y && p_y < pts[2].Y)
- // continue;
- // else
- // num++;
- //}
- //if (num == Verptcoll.Count)
- //{
- // ent.Erase();
- // return;
- //}
-
- Point3dCollection ptcoll = new Point3dCollection();
- poly3d.IntersectWith(pll, Intersect.OnBothOperands, plane, ptcoll, IntPtr.Zero, IntPtr.Zero);
-
- if (ptcoll.Count != 0)
- {
- DBObjectCollection objcoll = poly3d.GetSplitCurves(ptcoll);
- for (int i = 0; i < objcoll.Count; i++)
- {
- Polyline3d ply3 = (Polyline3d)objcoll[i];
- double l_x = ply3.GetPointAtParameter(1).X;
- double l_y = ply3.GetPointAtParameter(1).Y;
- double l_sx = ply3.StartPoint.X;
- double l_sy = ply3.StartPoint.Y;
- double l_ex = ply3.EndPoint.X;
- double l_ey = ply3.EndPoint.Y;
- if (pts[0].X <= l_sx && l_sx <= pts[1].X &&
- pts[0].Y <= l_sy && l_sy <= pts[2].Y &&
- pts[0].X <= l_ex && l_ex <= pts[1].X &&
- pts[0].Y <= l_ey && l_ey <= pts[2].Y &&
- pts[0].X <= l_x && l_x <= pts[1].X &&
- pts[0].Y <= l_y && l_y <= pts[2].Y)
- {
- newBtr.AppendEntity(ply3);
- newtr.AddNewlyCreatedDBObject(ply3, true);
- }
- }
- if (ptcoll.Count > 0)
- ent.Erase();
- }
- }
-
- //直线
- else if (ent is Line)
- {
- Point3dCollection ptcoll = new Point3dCollection();
- Line ln = (Line)ent;
- double l_sx = Math.Round(ln.StartPoint.X, 3);
- double l_sy = Math.Round(ln.StartPoint.Y, 3);
- double l_ex = Math.Round(ln.EndPoint.X, 3);
- double l_ey = Math.Round(ln.EndPoint.Y, 3);
- if (pts[2].X <= l_sx && l_ex >= pts[2].X ||
- pts[2].Y <= l_sy && l_ey >= pts[2].Y ||
- pts[0].X >= l_ex && l_ex <= pts[0].X ||
- pts[0].Y >= l_ey && l_ey <= pts[0].Y)
- {
- ent.Erase();
- return;
- }
-
- ln.IntersectWith(pll, Intersect.OnBothOperands, plane, ptcoll, IntPtr.Zero, IntPtr.Zero);
-
- double l_x = ln.StartPoint.X;
- double l_y = ln.StartPoint.Y;
-
- Line line = new Line();
- line.SetDatabaseDefaults();
- line.Layer = ln.Layer;
- line.Color = ln.Color;
- line.Linetype = ln.Linetype;
- line.LineWeight = ln.LineWeight;
- if (ptcoll.Count == 1)
- {
- if (pts[0].X <= l_x && l_x <= pts[1].X &&
- pts[0].Y <= l_y && l_y <= pts[2].Y)
- {
- line.StartPoint = ln.StartPoint;
- line.EndPoint = ptcoll[0];
- newBtr.AppendEntity(line);
- newtr.AddNewlyCreatedDBObject(line, true);
- ln.Erase();
- }
- else
- {
- line.StartPoint = ptcoll[0];
- line.EndPoint = ln.EndPoint;
- newBtr.AppendEntity(line);
- newtr.AddNewlyCreatedDBObject(line, true);
- ln.Erase();
- }
- }
- else if (ptcoll.Count >= 2)
- {
- for (int i = 0; i < ptcoll.Count - 1; i++)
- {
- line.StartPoint = ptcoll[i];
- line.EndPoint = ptcoll[i + 1];
- newBtr.AppendEntity(line);
- newtr.AddNewlyCreatedDBObject(line, true);
- }
- ln.Erase();
- }
- }
-
- //图案填充
- else if (ent is Hatch)
- {
- Hatch hc = (Hatch)ent;
- DBObjectCollection boundaries = new DBObjectCollection();
- int num = 0;
- for (int i = 0; i < hc.NumberOfLoops; i++)
- {
- HatchLoop loop = hc.GetLoopAt(i);
- if (loop.Curves == null)
- {
- Polyline polyline = new Polyline();
-
- // 遍历顶点并添加
- for (int ii = 0; ii < loop.Polyline.Count; ii++)
- {
- BulgeVertex vertex = loop.Polyline[ii];
- polyline.AddVertexAt(i, vertex.Vertex, vertex.Bulge, 0, 0);
-
- double v_x = Math.Round(vertex.Vertex.X);
- double v_y = Math.Round(vertex.Vertex.Y);
- if (pts[0].X <= v_x || v_x <= pts[1].X &&
- pts[0].Y <= v_y || v_y <= pts[2].Y)
- num++;
- }
- polyline.Closed = true; // 闭合多段线
- boundaries.Add(polyline);
- }
- else
- {
- foreach(Curve curve in loop.Curves)
- {
- boundaries.Add(curve);
- }
- }
- }
- if (num == 0)
- return;
- // 创建面域
- DBObjectCollection regionsToClip = GrxCAD.DatabaseServices.Region.CreateFromCurves(boundaries);
-
- DBObjectCollection pllboundary = new DBObjectCollection();
- pllboundary.Add(pll);
- DBObjectCollection boundaryRegions = GrxCAD.DatabaseServices.Region.CreateFromCurves(pllboundary);
-
- foreach (GrxCAD.DatabaseServices.Region region in regionsToClip)
- {
- foreach (GrxCAD.DatabaseServices.Region boundary in boundaryRegions)
- {
- region.BooleanOperation(BooleanOperationType.BoolIntersect, boundary);
- DBObjectCollection explodedCurves = new DBObjectCollection();
- region.Explode(explodedCurves);
- int deleindex = 0;
- ObjectIdCollection boundaryIds = new ObjectIdCollection();
- foreach (DBObject obj in explodedCurves)
- {
- if (obj is GrxCAD.DatabaseServices.Region)
- {
- GrxCAD.DatabaseServices.Region subregion = (GrxCAD.DatabaseServices.Region)obj;
- DBObjectCollection subexplodedCurves = new DBObjectCollection();
- subregion.Explode(subexplodedCurves);
- Polyline regionpll = createpllfromregion(subexplodedCurves);
- newBtr.AppendEntity(regionpll);
- newtr.AddNewlyCreatedDBObject(regionpll, true);
- boundaryIds.Add(regionpll.ObjectId);
- }
- else
- {
- Polyline regionpll = createpllfromregion(explodedCurves);
- newBtr.AppendEntity(regionpll);
- newtr.AddNewlyCreatedDBObject(regionpll, true);
- boundaryIds.Add(regionpll.ObjectId);
- break;
- }
- }
- Hatch newHatch = new Hatch
- {
- PatternScale = hc.PatternScale,
- PatternAngle = hc.PatternAngle,
- HatchStyle = hc.HatchStyle,
- Color = hc.Color,
- Transparency = hc.Transparency,
- Layer = hc.Layer,
- Linetype = hc.Linetype,
- LinetypeScale = hc.LinetypeScale,
- LineWeight = hc.LineWeight,
- Associative = hc.Associative,
- HatchObjectType = hc.HatchObjectType
-
- };
- newHatch.AppendLoop(HatchLoopTypes.Default, boundaryIds);
- newBtr.AppendEntity(newHatch);
- newtr.AddNewlyCreatedDBObject(newHatch, true);
- string pname = hc.PatternName;
- newHatch.SetHatchPattern(hc.PatternType, pname);
- newHatch.EvaluateHatch(true);
- if (deleindex == 0 && explodedCurves.Count != 0)
- {
- hc.UpgradeOpen();
- hc.Erase();
- deleindex = 1;
- }
- for (int i =0;i<boundaryIds.Count;i++)
- {
- Polyline pll_dele = newtr.GetObject(boundaryIds[i], OpenMode.ForWrite) as Polyline;
- pll_dele.Erase();
- }
- }
- }
- }
-
- //块参照(不包括高程点)
- else if(ent is BlockReference)
- {
- BlockReference blkef = (BlockReference)ent;
- Point3d pt_min = blkef.Bounds.Value.MinPoint;
- Point3d pt_max = blkef.Bounds.Value.MaxPoint;
- Point3d basePoint = blkef.Position;
- if (ptintk(pt_min, pts) && ptintk(pt_max, pts))
- {
- ent.Erase();
- return;
- }
- if (blkef.Name == "GC200")
- return;
- if (Math.Round(pt_min.X,3) < pts[0].X)
- {
- double dist = Math.Abs(pts[0].X - Math.Round(pt_min.X, 3)) + 0.1;
- Point3d targetPoint = new Point3d(blkef.Position.X + dist, blkef.Position.Y, blkef.Position.Z);
- Vector3d moveVector = targetPoint - basePoint;
- Matrix3d transform = Matrix3d.Displacement(moveVector);
- blkef.TransformBy(transform);
- }
- else if (Math.Round(pt_min.Y, 3) < pts[0].Y)
- {
- double dist = Math.Abs(pts[0].Y - Math.Round(pt_min.Y, 3)) + 0.1;
- Point3d targetPoint = new Point3d(blkef.Position.X, blkef.Position.Y + dist, blkef.Position.Z);
- Vector3d moveVector = targetPoint - basePoint;
- Matrix3d transform = Matrix3d.Displacement(moveVector);
- blkef.TransformBy(transform);
- }
- else if (Math.Round(pt_max.X, 3) > pts[2].X)
- {
- double dist = Math.Abs(pts[2].X - Math.Round(pt_max.X, 3)) + 0.1;
- Point3d targetPoint = new Point3d(blkef.Position.X - dist, blkef.Position.Y, blkef.Position.Z);
- Vector3d moveVector = targetPoint - basePoint;
- Matrix3d transform = Matrix3d.Displacement(moveVector);
- blkef.TransformBy(transform);
- }
- else if (Math.Round(pt_max.Y, 3) > pts[2].Y)
- {
- double dist = Math.Abs(pts[2].Y - Math.Round(pt_max.Y, 3)) + 0.1;
- Point3d targetPoint = new Point3d(blkef.Position.X, blkef.Position.Y - dist, blkef.Position.Z);
- Vector3d moveVector = targetPoint - basePoint;
- Matrix3d transform = Matrix3d.Displacement(moveVector);
- blkef.TransformBy(transform);
- }
- }
-
- //文字
- else if(ent is DBText||ent is MText)
- {
- Point3d pt_min = ent.Bounds.Value.MinPoint;
- Point3d pt_max = ent.Bounds.Value.MaxPoint;
- Point3d basePoint = new Point3d();
- double pos_x = 0;
- double pos_y = 0;
- double pos_z = 0;
- if (ptintk(pt_min, pts) && ptintk(pt_max, pts))
- {
- ent.Erase();
- return;
- }
-
- if (ent is DBText)
- {
- DBText dbt = (DBText)ent;
- basePoint = dbt.Position;
- pos_x = dbt.Position.X;
- pos_y = dbt.Position.Y;
- pos_z = dbt.Position.Z;
- }
- if (ent is MText)
- {
- MText mt = (MText)ent;
- basePoint = mt.Location;
- pos_x = mt.Location.X;
- pos_y = mt.Location.Y;
- pos_z = mt.Location.Z;
- }
- else if (Math.Round(pt_min.X, 3) < pts[0].X)
- {
- double dist = Math.Abs(pts[0].X - Math.Round(pt_min.X, 3)) + 0.1;
- Point3d targetPoint = new Point3d(pos_x + dist, pos_y, pos_z);
- Vector3d moveVector = targetPoint - basePoint;
- Matrix3d transform = Matrix3d.Displacement(moveVector);
- ent.TransformBy(transform);
- }
- else if (Math.Round(pt_min.Y, 3) < pts[0].Y)
- {
- double dist = Math.Abs(pts[0].Y - Math.Round(pt_min.Y, 3)) + 0.1;
- Point3d targetPoint = new Point3d(pos_x, pos_y + dist, pos_z);
- Vector3d moveVector = targetPoint - basePoint;
- Matrix3d transform = Matrix3d.Displacement(moveVector);
- ent.TransformBy(transform);
- }
- else if (Math.Round(pt_max.X, 3) > pts[2].X)
- {
- double dist = Math.Abs(pts[2].X - Math.Round(pt_max.X, 3)) + 0.1;
- Point3d targetPoint = new Point3d(pos_x - dist, pos_y, pos_z);
- Vector3d moveVector = targetPoint - basePoint;
- Matrix3d transform = Matrix3d.Displacement(moveVector);
- ent.TransformBy(transform);
- }
- else if (Math.Round(pt_max.Y, 3) > pts[2].Y)
- {
- double dist = Math.Abs(pts[2].Y - Math.Round(pt_max.Y, 3)) + 0.1;
- Point3d targetPoint = new Point3d(pos_x, pos_y - dist, pos_z);
- Vector3d moveVector = targetPoint - basePoint;
- Matrix3d transform = Matrix3d.Displacement(moveVector);
- ent.TransformBy(transform);
- }
- }
-
- #region
- //二维多段线
- //else if (ent is Polyline2d)
- //{
- // Point3dCollection ptcoll = new Point3dCollection();
- // Polyline2d pll_clip = (Polyline2d)ent;
- // pll_clip.IntersectWith(pll, Intersect.OnBothOperands, plane, ptcoll, IntPtr.Zero, IntPtr.Zero);
-
- // //非闭合
- // if (pll_clip.Closed == false)
- // {
- // if(ptcoll.Count!=0)
- // {
- // DBObjectCollection objcoll = pll_clip.GetSplitCurves(ptcoll);
- // foreach (Object obj in objcoll)
- // {
- // Polyline2d pll_cut = (Polyline2d)obj;
- // if (pllinsidetk(pll_cut, pts))
- // {
- // newBtr.AppendEntity(pll_cut);
- // newtr.AddNewlyCreatedDBObject(pll_cut, true);
- // }
- // }
- // ent.Erase();
- // }
-
- // }
- // //闭合
- // else
- // {
- // double ele = pll_clip.Elevation;
- // pll_clip.Elevation = 0;
- // DBObjectCollection result = new DBObjectCollection();
-
- // // 将多段线转换为曲线集合
- // DBObjectCollection curvesToClip = new DBObjectCollection();
- // curvesToClip.Add(pll_clip);
-
- // DBObjectCollection boundaryCurves = new DBObjectCollection();
- // boundaryCurves.Add(pll);
-
- // // 创建 Region
- // DBObjectCollection regionsToClip = new DBObjectCollection();
- // DBObjectCollection boundaryRegions = new DBObjectCollection();
-
- // try
- // {
- // // 将多段线转换为 Region
- // regionsToClip = GrxCAD.DatabaseServices.Region.CreateFromCurves(curvesToClip);
- // boundaryRegions = GrxCAD.DatabaseServices.Region.CreateFromCurves(boundaryCurves);
- // }
- // catch (Exception ex)
- // {
- // GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n错误: {ex.Message}");
- // }
-
- // // 执行布尔运算(交集)
- // DBObjectCollection intersectionRegions = new DBObjectCollection();
- // foreach (GrxCAD.DatabaseServices.Region region in regionsToClip)
- // {
- // foreach (GrxCAD.DatabaseServices.Region boundary in boundaryRegions)
- // {
- // region.BooleanOperation(BooleanOperationType.BoolIntersect, boundary);
- // DBObjectCollection explodedCurves = new DBObjectCollection();
- // region.Explode(explodedCurves);
- // int flag = 0;
- // foreach (DBObject obj in explodedCurves)
- // {
- // if (obj is GrxCAD.DatabaseServices.Region)
- // {
- // flag = 1;
- // GrxCAD.DatabaseServices.Region subregion = (GrxCAD.DatabaseServices.Region)obj;
- // DBObjectCollection subexplodedCurves = new DBObjectCollection();
- // subregion.Explode(subexplodedCurves);
- // Polyline2d polyline = createpll2dfromregion(subexplodedCurves, pll_clip, newtr);
- // polyline.Elevation = ele;
- // newBtr.AppendEntity(polyline);
- // newtr.AddNewlyCreatedDBObject(polyline, true);
- // }
- // else
- // {
- // break;
- // }
-
- // }
- // if (flag == 0)
- // {
- // Polyline2d polyline = createpll2dfromregion(explodedCurves, pll_clip, newtr);
- // polyline.Elevation = ele;
- // newBtr.AppendEntity(polyline);
- // newtr.AddNewlyCreatedDBObject(polyline, true);
- // }
-
- // }
- // }
-
- // if (regionsToClip.Count != 0)
- // {
- // pll_clip.Erase();
- // }
- // }
- //}
- #endregion
-
- }
-
- public Polyline createpllfromregion(DBObjectCollection explodedCurves)
- {
- // 存储提取的线段
- List<Curve> curves = new List<Curve>();
- foreach (DBObject obj in explodedCurves)
- {
- if (obj is Curve curve)
- {
- curves.Add(curve);
- }
- }
-
- Polyline polyline = new Polyline();
- polyline.SetDatabaseDefaults();
- while (curves.Count > 0)
- {
- // 从第一条线段开始
- Curve currentCurve = curves[0];
- curves.RemoveAt(0);
-
- // 添加当前线段的起点和终点
- polyline.AddVertexAt(0, new Point2d(currentCurve.StartPoint.X, currentCurve.StartPoint.Y), 0, 0, 0);
- polyline.AddVertexAt(1, new Point2d(currentCurve.EndPoint.X, currentCurve.EndPoint.Y), 0, 0, 0);
-
- // 查找与当前线段相连的线段
- bool foundConnectedCurve;
- do
- {
- foundConnectedCurve = false;
-
- for (int i = 0; i < curves.Count; i++)
- {
- Curve nextCurve = curves[i];
-
- // 检查是否与当前线段的起点或终点相连
- if (nextCurve.StartPoint.IsEqualTo(polyline.GetPoint3dAt(polyline.NumberOfVertices - 1)))
- {
- // 添加到多段线的末尾
- polyline.AddVertexAt(polyline.NumberOfVertices, new Point2d(nextCurve.EndPoint.X, nextCurve.EndPoint.Y), 0, 0, 0);
- curves.RemoveAt(i);
- foundConnectedCurve = true;
- break;
- }
- else if (nextCurve.EndPoint.IsEqualTo(polyline.GetPoint3dAt(0)))
- {
- // 添加到多段线的开头
- polyline.AddVertexAt(0, new Point2d(nextCurve.StartPoint.X, nextCurve.StartPoint.Y), 0, 0, 0);
- curves.RemoveAt(i);
- foundConnectedCurve = true;
- break;
- }
- else if (nextCurve.EndPoint.IsEqualTo(polyline.GetPoint3dAt(polyline.NumberOfVertices - 1)))
- {
- // 添加到多段线的末尾
- polyline.AddVertexAt(polyline.NumberOfVertices, new Point2d(nextCurve.StartPoint.X, nextCurve.StartPoint.Y), 0, 0, 0);
- curves.RemoveAt(i);
- foundConnectedCurve = true;
- break;
- }
- else if (nextCurve.StartPoint.IsEqualTo(polyline.GetPoint3dAt(0)))
- {
- // 添加到多段线的开头
- polyline.AddVertexAt(0, new Point2d(nextCurve.EndPoint.X, nextCurve.EndPoint.Y), 0, 0, 0);
- curves.RemoveAt(i);
- foundConnectedCurve = true;
- break;
- }
- }
- } while (foundConnectedCurve);
-
- // 关闭多段线
- polyline.Closed = true;
- }
- return polyline;
- }
-
- public Polyline3d createpl3dfromregion(DBObjectCollection explodedCurves)
- {
- // 存储提取的线段
- List<Curve> curves = new List<Curve>();
- foreach (DBObject obj in explodedCurves)
- {
- if (obj is Curve curve)
- {
- curves.Add(curve);
- }
- }
-
- Polyline3d pl3d = new Polyline3d();
- pl3d.SetDatabaseDefaults();
- while (curves.Count > 0)
- {
- // 从第一条线段开始
- Curve currentCurve = curves[0];
- curves.RemoveAt(0);
-
- // 添加当前线段的起点和终点
- pl3d.AppendVertex(new PolylineVertex3d(currentCurve.StartPoint));
- pl3d.AppendVertex(new PolylineVertex3d(currentCurve.EndPoint));
-
- // 查找与当前线段相连的线段
- bool foundConnectedCurve;
- do
- {
- foundConnectedCurve = false;
-
- for (int i = 0; i < curves.Count; i++)
- {
- Curve nextCurve = curves[i];
-
- // 检查是否与当前线段的起点或终点相连
- if (nextCurve.StartPoint.IsEqualTo(pl3d.EndPoint))
- {
- // 添加到多段线的末尾
- pl3d.AppendVertex(new PolylineVertex3d(nextCurve.EndPoint));
- curves.RemoveAt(i);
- foundConnectedCurve = true;
- break;
- }
- else if (nextCurve.EndPoint.IsEqualTo(pl3d.StartPoint))
- {
- // 添加到多段线的开头
- pl3d.AppendVertex(new PolylineVertex3d(nextCurve.StartPoint));
- curves.RemoveAt(i);
- foundConnectedCurve = true;
- break;
- }
- else if (nextCurve.EndPoint.IsEqualTo(pl3d.EndPoint))
- {
- // 添加到多段线的末尾
- pl3d.AppendVertex(new PolylineVertex3d(nextCurve.StartPoint));
- curves.RemoveAt(i);
- foundConnectedCurve = true;
- break;
- }
- else if (nextCurve.StartPoint.IsEqualTo(pl3d.StartPoint))
- {
- // 添加到多段线的开头
- pl3d.AppendVertex(new PolylineVertex3d(nextCurve.EndPoint));
- curves.RemoveAt(i);
- foundConnectedCurve = true;
- break;
- }
- }
- } while (foundConnectedCurve);
-
- // 关闭多段线
- pl3d.Closed = true;
- }
- return pl3d;
- }
-
- private bool pllinsidetk(Entity ent, Point3dCollection pts)
- {
- bool inside = false;
- if (ent is Polyline)
- {
- Polyline pll = (Polyline)ent;
-
- double p_x = Math.Round(pll.GetPoint3dAt(1).X, 3);
- double p_y = Math.Round(pll.GetPoint3dAt(1).Y, 3);
- double sp_x = Math.Round(pll.StartPoint.X, 3);
- double sp_y = Math.Round(pll.StartPoint.Y, 3);
- double ep_x = Math.Round(pll.EndPoint.X, 3);
- double ep_y = Math.Round(pll.EndPoint.Y, 3);
- if (pts[0].X <= p_x && p_x <= pts[1].X &&
- pts[0].Y <= p_y && p_y <= pts[2].Y &&
- pts[0].X <= sp_x && sp_x <= pts[1].X &&
- pts[0].Y <= sp_y && sp_y <= pts[2].Y &&
- pts[0].X <= ep_x && ep_x <= pts[1].X &&
- pts[0].Y <= ep_y && ep_y <= pts[2].Y)
- inside = true;
- else
- inside = false;
- }
- if (ent is Polyline3d)
- {
- Polyline2d pll = (Polyline2d)ent;
-
- double p_x = Math.Round(pll.GetPointAtParameter(1).X, 3);
- double p_y = Math.Round(pll.GetPointAtParameter(1).Y, 3);
- double sp_x = Math.Round(pll.StartPoint.X, 3);
- double sp_y = Math.Round(pll.StartPoint.Y, 3);
- double ep_x = Math.Round(pll.EndPoint.X, 3);
- double ep_y = Math.Round(pll.EndPoint.Y, 3);
- if (pts[0].X <= p_x && p_x <= pts[1].X &&
- pts[0].Y <= p_y && p_y <= pts[2].Y &&
- pts[0].X <= sp_x && sp_x <= pts[1].X &&
- pts[0].Y <= sp_y && sp_y <= pts[2].Y &&
- pts[0].X <= ep_x && ep_x <= pts[1].X &&
- pts[0].Y <= ep_y && ep_y <= pts[2].Y)
- inside = true;
- else
- inside = false;
- }
- return inside;
- }
-
- private Point3dCollection getpt(Entity ent)
- {
- Point3dCollection ptcoll = new Point3dCollection();
- if (ent is Polyline)
- {
- Polyline pll = (Polyline)ent;
- //获取图框节点并排序
- int numVertices = pll.NumberOfVertices;
- for (int j = 0; j < numVertices; j++)
- {
- ptcoll.Add(pll.GetPoint3dAt(j));
- }
- sortpts(ptcoll);
- }
- else if(ent is Polyline2d)
- {
- Polyline2d pl2d = (Polyline2d)ent;
- pl2d.GetStretchPoints(ptcoll);
- sortpts(ptcoll);
- }
- else if(ent is Polyline3d)
- {
- Polyline3d pl3d = (Polyline3d)ent;
- pl3d.GetStretchPoints(ptcoll);
- sortpts(ptcoll);
- }
- return ptcoll;
- }
-
- private bool ptintk(Point3d pt,Point3dCollection pts)
- {
- bool inside;
- double x = Math.Round(pt.X, 3);
- double y = Math.Round(pt.Y, 3);
-
- if (pts[0].X < x && x < pts[2].X &&
- pts[0].Y < y && y < pts[2].Y)
- inside = false;
- else
- inside = true;
- return inside;
- }
- #region
- //private Polyline2d createpll2dfromregion(DBObjectCollection explodedCurves, Polyline2d pll_clip,
- // Transaction newtr)
- //{
- // // 存储提取的线段
- // List<Curve> curves = new List<Curve>();
- // foreach (DBObject obj in explodedCurves)
- // {
- // if (obj is Curve curve)
- // {
- // curves.Add(curve);
- // }
- // }
-
- // Polyline2d polyline = new Polyline2d();
- // polyline.SetDatabaseDefaults();
- // polyline.Layer = pll_clip.Layer;
- // polyline.Color = pll_clip.Color;
- // polyline.Linetype = pll_clip.Linetype;
- // polyline.LinetypeGenerationOn = pll_clip.LinetypeGenerationOn;
-
- // while (curves.Count > 0)
- // {
- // // 从第一条线段开始
- // Curve currentCurve = curves[0];
- // curves.RemoveAt(0);
-
- // // 添加当前线段的起点和终点
- // Vertex2d splitVtx1 = new Vertex2d();
- // splitVtx1.Position = currentCurve.StartPoint;
- // splitVtx1.Bulge = 0;
- // polyline.AppendVertex(splitVtx1);
- // Vertex2d splitVtx2 = new Vertex2d();
- // splitVtx2.Position = currentCurve.StartPoint;
- // splitVtx2.Bulge = 0;
- // polyline.AppendVertex(splitVtx2);
-
- // // 查找与当前线段相连的线段
- // bool foundConnectedCurve;
- // do
- // {
- // foundConnectedCurve = false;
-
- // for (int i = 0; i < curves.Count; i++)
- // {
- // Curve nextCurve = curves[i];
-
- // // 检查是否与当前线段的起点或终点相连
- // if (nextCurve.StartPoint.IsEqualTo(polyline.EndPoint))
- // {
- // // 添加到多段线的末尾
- // Vertex2d splitVtx = new Vertex2d();
- // splitVtx.Position = nextCurve.StartPoint;
- // splitVtx.Bulge = 0;
- // polyline.AppendVertex(splitVtx);
- // curves.RemoveAt(i);
- // foundConnectedCurve = true;
- // break;
- // }
- // else if (nextCurve.EndPoint.IsEqualTo(polyline.StartPoint))
- // {
- // // 添加到多段线的开头
- // Vertex2d firstVertex = new Vertex2d();
- // foreach (ObjectId vertexId in polyline)
- // {
- // firstVertex = newtr.GetObject(vertexId, OpenMode.ForRead) as Vertex2d;
- // break; // 获取第一个顶点后退出循环
- // }
- // Vertex2d splitVtx = new Vertex2d();
- // splitVtx.Position = nextCurve.EndPoint;
- // splitVtx.Bulge = 0;
- // polyline.InsertVertexAt(firstVertex.ObjectId, splitVtx);
- // curves.RemoveAt(i);
- // foundConnectedCurve = true;
- // break;
- // }
- // else if (nextCurve.EndPoint.IsEqualTo(polyline.EndPoint))
- // {
- // // 添加到多段线的末尾
- // Vertex2d splitVtx = new Vertex2d();
- // splitVtx.Position = nextCurve.EndPoint;
- // splitVtx.Bulge = 0;
- // polyline.AppendVertex(splitVtx);
- // curves.RemoveAt(i);
- // foundConnectedCurve = true;
- // break;
- // }
- // else if (nextCurve.StartPoint.IsEqualTo(polyline.StartPoint))
- // {
- // // 添加到多段线的开头
- // Vertex2d firstVertex = new Vertex2d();
- // foreach (ObjectId vertexId in polyline)
- // {
- // firstVertex = newtr.GetObject(vertexId, OpenMode.ForRead) as Vertex2d;
- // break; // 获取第一个顶点后退出循环
- // }
- // Vertex2d splitVtx = new Vertex2d();
- // splitVtx.Position = nextCurve.StartPoint;
- // splitVtx.Bulge = 0;
- // polyline.InsertVertexAt(firstVertex.ObjectId, splitVtx);
- // curves.RemoveAt(i);
- // foundConnectedCurve = true;
- // break;
- // }
- // }
- // } while (foundConnectedCurve);
-
- // // 关闭多段线
- // polyline.Closed = true;
- // }
- // return polyline;
- //}
- #endregion
-
-
- }
- }
|