public UserEventArgsOnePlProp(DbPolyline plineGetFromUser, bool correctlyGet, bool closedPl, int plVertexCount) { PlineGetFromUser = plineGetFromUser; CorrectlyGet = correctlyGet; ClosedPl = closedPl; PlVertexCount = plVertexCount; }
void getOnePlFromDwg() { try { // Выбор объекта, и проверка что это полилиния Multicad.McObjectId idSelected = McObjectManager.SelectObject("Выберите полилинию "); Multicad.McObject targetPl = idSelected.GetObject(); Polyline3d testPL = new Polyline3d(); if (targetPl is DbPolyline || Object.ReferenceEquals(targetPl.GetType(), testPL.GetType())) { this.plineGetFromUser = targetPl as DbPolyline; this.correctlyGet = true; } else { this.correctlyGet = false; return; } } catch (Exception ex) { MessageBox.Show("Ошибка: " + ex.Message); } }
public void renumerateVertex(int numStartVertex) { List <Point3d> getVert = new List <Point3d>(); getVert = this.listVertecs(plineGetFromUser); List <Point3d> setVert = new List <Point3d>(); for (int i = numStartVertex - 1, j = 0; i < getVert.Count; i++, j++) { setVert.Insert(j, getVert[i]); } for (int i = 0, j = setVert.Count; i < numStartVertex - 1; i++, j++) { setVert.Insert(j, getVert[i]); } Polyline3d plAfterRenumVert = new Polyline3d(setVert); DbPolyline plForWrite = new DbPolyline(); if (plineGetFromUser.Polyline.ClosedLogically == true) { plAfterRenumVert.SetClosed(true); } plForWrite = plAfterRenumVert; plForWrite.DbEntity.MatchProperties(plineGetFromUser.DbEntity, MatchPropEnum.All); //копирование свойств plineGetFromUser.DbEntity.Erase(); // удаляет исходную PL из чертежа plForWrite.DbEntity.AddToCurrentDocument(); }
public void reversPolyline() { List <Point3d> Vert = new List <Point3d>(); Vert = this.listVertecs(plineGetFromUser); if (this.Polyline.ClosedLogically == false) { Vert.Reverse(); } else if (this.closeAndDuplicateVertex == true) { Vert.Reverse(); } else { Vert.Reverse(1, Vert.Count - 1); } Polyline3d reversPL3d = new Polyline3d(Vert); if (plineGetFromUser.Polyline.ClosedLogically == true) { reversPL3d.SetClosed(true); } DbPolyline plForWrite = new DbPolyline(); plForWrite = reversPL3d; plForWrite.DbEntity.MatchProperties(plineGetFromUser.DbEntity, MatchPropEnum.All); //копирование свойств plineGetFromUser.DbEntity.Erase(); // удаляет исходную PL из чертежа plForWrite.DbEntity.AddToCurrentDocument(); }
public void deletDuplicatedVertexPolyline() { //на LINQ int i = this.listVertecs(plineGetFromUser).Select(CompareFactor => new { CompareFactor.X, CompareFactor.Y, CompareFactor.Z }).Count(); int j = this.listVertecs(plineGetFromUser).Select(CompareFactor => new { CompareFactor.X, CompareFactor.Y, CompareFactor.Z }).Distinct().Count(); if (i == j) { MessageBox.Show("У данной полилинии нет одинаковых/задвоенных вершин"); return; } var list = this.listVertecs(plineGetFromUser).Select(CompareFactor => new { CompareFactor.X, CompareFactor.Y, CompareFactor.Z }).Distinct(); List <Point3d> Vertex = new List <Point3d>(); foreach (var item in list) { Point3d PointForList = new Point3d(item.X, item.Y, item.Z); Vertex.Add(PointForList); } Polyline3d PL3dNonDuplicatePoints = new Polyline3d(Vertex); if (plineGetFromUser.Polyline.ClosedLogically == true) { PL3dNonDuplicatePoints.SetClosed(true); } plineGetFromUser.DbEntity.Erase(); plineGetFromUser = PL3dNonDuplicatePoints; plineGetFromUser.DbEntity.AddToCurrentDocument(); }
public void DrawFace() { DbCircle body = new DbCircle(); body.Center = new Point3d(200, 200, 0); body.Radius = 105; body.DbEntity.AddToCurrentDocument(); DbCircle eye1 = new DbCircle(); eye1.Center = new Point3d(150, 255, 0); eye1.Radius = 8; eye1.DbEntity.AddToCurrentDocument(); DbCircle pupil1 = new DbCircle(); pupil1.Center = new Point3d(148, 254, 0); pupil1.Radius = 2; pupil1.DbEntity.AddToCurrentDocument(); DbCircle eye2 = new DbCircle(); eye2.Center = new Point3d(250, 260, 0); eye2.Radius = 8; eye2.DbEntity.AddToCurrentDocument(); DbCircle pupil2 = new DbCircle(); pupil2.Center = new Point3d(252, 258, 0); pupil2.Radius = 2; pupil2.DbEntity.AddToCurrentDocument(); DbLine hand1 = new DbLine(); hand1.StartPoint = new Point3d(102, 239, 0); hand1.EndPoint = new Point3d(72, 183, 0); hand1.DbEntity.AddToCurrentDocument(); DbLine hand2 = new DbLine(); hand2.StartPoint = new Point3d(298, 236, 0); hand2.EndPoint = new Point3d(325, 192, 0); hand2.DbEntity.AddToCurrentDocument(); DbPolyline nose = new DbPolyline(); List <Point3d> nosePoints = new List <Point3d>() { new Point3d(171, 222, 0), new Point3d(198, 177, 0), new Point3d(231, 222, 0) }; nose.Polyline = new Polyline3d(nosePoints); nose.Polyline.SetClosed(false); nose.DbEntity.Transform(McDocumentsManager.GetActiveDoc().UCS); //change coordinates from UCS to WCS for BD nose.DbEntity.AddToCurrentDocument(); DbText spech = new DbText(); spech.Text = new TextGeom("Hello Habr!", new Point3d(310, 55, 0), Vector3d.XAxis, "Standard", 25); spech.DbEntity.AddToCurrentDocument(); }
public List <Point3d> listVertecs(DbPolyline plineItem) { List <Point3d> Vertices = new List <Point3d>(); // собираем все вершины в list for (int i1 = 0; i1 < plineItem.Polyline.Vertices.Count; i1++) { Point3d Vertex = new Point3d(); double Bulge; double startWidth; double endWidth; Vector3d nrm; plineItem.Polyline.Vertices.GetVertexAt((uint)i1, out Vertex, out Bulge, out startWidth, out endWidth, out nrm); Vertices.Add(Vertex); } return(Vertices); }
void PolylineProperties(DbPolyline plineItem) { if (plineItem.Polyline.ClosedLogically == true && (plineItem.Polyline.Vertices.First().Point.X == plineItem.Polyline.Vertices.Last().Point.X) && (plineItem.Polyline.Vertices.First().Point.Y == plineItem.Polyline.Vertices.Last().Point.Y) && (plineItem.Polyline.Vertices.First().Point.Z == plineItem.Polyline.Vertices.Last().Point.Z)) { this.closeAndDuplicateVertex = true; } else { this.closeAndDuplicateVertex = false; } }
public void DrawXThree() { Point3d _pntBase; Point3d _bufPnt; //prompts for installation point entry InputJig jig = new InputJig(); // Get the first box point from the jig InputResult res = jig.GetPoint("Select first point:"); //It works only if input was successful if (res.Result == InputResult.ResultCode.Normal) { // The base point is taken from the entry point (click with mouse) _pntBase = res.Point; //Draw the outline of the left half of the Christmas tree //Create base points for the polyline List <Point3d> leftPatrOfThreePoints = new List <Point3d>() { new Point3d(_pntBase.X, _pntBase.Y, 0), new Point3d(_pntBase.X - 125, _pntBase.Y - 154, 0), new Point3d(_pntBase.X - 31, _pntBase.Y - 137, 0), new Point3d(_pntBase.X - 181, _pntBase.Y - 287, 0), new Point3d(_pntBase.X - 31, _pntBase.Y - 253, 0), new Point3d(_pntBase.X - 242, _pntBase.Y - 400, 0), new Point3d(_pntBase.X - 37, _pntBase.Y - 400, 0), new Point3d(_pntBase.X - 37, _pntBase.Y - 454, 0), new Point3d(_pntBase.X, _pntBase.Y - 454, 0) }; //Create a polyline (geometry) Polyline3d leftPatrOfThree = new Polyline3d(leftPatrOfThreePoints); //Create a polyline object and place it on the drawing DbPolyline XThreeLeft = new DbPolyline(); XThreeLeft.Polyline = new Polyline3d(leftPatrOfThree); XThreeLeft.Polyline.SetClosed(false); XThreeLeft.DbEntity.Color = Color.Green; XThreeLeft.DbEntity.AddToCurrentDocument(); //The right part of the tree is obtained by mirroring the left DbPolyline XThreeRight = new DbPolyline(); XThreeRight.DbEntity.Color = Color.Green; XThreeRight.Polyline = (Polyline3d)XThreeLeft.Polyline.Mirror(new Plane3d(_pntBase, new Vector3d(10, 0, 0))); XThreeRight.DbEntity.AddToCurrentDocument(); //From the right and left sides we make a single contour for hatching DbPolyline XThreeR = new DbPolyline(); XThreeR.DbEntity.Color = Color.Green; XThreeR.Polyline = XThreeRight.Polyline.GetCopy() as Polyline3d; XThreeR.DbEntity.AddToCurrentDocument(); List <Point3d> hatchPoints = new List <Point3d>(); hatchPoints.AddRange(leftPatrOfThreePoints); hatchPoints.AddRange(XThreeR.Polyline.Points.Reverse().ToList()); Polyline3d hatchContur = new Polyline3d(hatchPoints); //We will create on the basis of a contour a hatch (geometry) with continuous filling Hatch hatch = new Hatch(hatchContur, 0, 10, true); hatch.PattType = PatternType.PreDefined; hatch.PatternName = "SOLID"; //Based on the geometry of the hatch, we create the document object, set its color properties - green DbGeometry dbhatch = new DbGeometry(); dbhatch.Geometry = new EntityGeometry(hatch); dbhatch.DbEntity.Color = Color.Green; dbhatch.DbEntity.AddToCurrentDocument(); // if you want you can try to draw balls with circles use // DrawThreeBalls(_pntBase); //Similarly, make a Christmas tree toy (octagon) //red _bufPnt = _pntBase.Subtract(new Vector3d(30, 95, 0)); DbPolyline dbOctoRed = DrawThreeOctogonPl(_bufPnt);//implicit dbOctoRed.DbEntity.AddToCurrentDocument(); Hatch hatchCirkRed = new Hatch(dbOctoRed.Polyline, 0, 1, false); hatchCirkRed.PattType = PatternType.PreDefined; hatchCirkRed.PatternName = "SOLID"; DbGeometry dbhatchCirkRed = new DbGeometry(); dbhatchCirkRed.Geometry = new EntityGeometry(hatchCirkRed); dbhatchCirkRed.DbEntity.Color = Color.Red; dbhatchCirkRed.DbEntity.AddToCurrentDocument(); //green _bufPnt = _pntBase.Subtract(new Vector3d(-40, 200, 0)); DbPolyline dbOctoGreen = DrawThreeOctogonPl(_bufPnt);//implicit dbOctoGreen.DbEntity.AddToCurrentDocument(); Hatch hatchCirkGreen = new Hatch(dbOctoGreen.Polyline, 0, 1, false); hatchCirkGreen.PattType = PatternType.PreDefined; hatchCirkGreen.PatternName = "SOLID"; DbGeometry dbhatchCirkGreen = new DbGeometry(); dbhatchCirkGreen.Geometry = new EntityGeometry(hatchCirkGreen); dbhatchCirkGreen.DbEntity.Color = Color.LightSeaGreen; dbhatchCirkGreen.DbEntity.AddToCurrentDocument(); //blue _bufPnt = _pntBase.Subtract(new Vector3d(-12, 350, 0)); DbPolyline dbOctoBlue = DrawThreeOctogonPl(_bufPnt);//implicit dbOctoBlue.DbEntity.AddToCurrentDocument(); Hatch hatchCirkBlue = new Hatch(dbOctoBlue.Polyline, 0, 1, false); hatchCirkBlue.PattType = PatternType.PreDefined; hatchCirkBlue.PatternName = "SOLID"; DbGeometry dbhatchCirkBlue = new DbGeometry(); dbhatchCirkBlue.Geometry = new EntityGeometry(hatchCirkBlue); dbhatchCirkBlue.DbEntity.Color = Color.Blue; dbhatchCirkBlue.DbEntity.AddToCurrentDocument(); //display the text with congratulations MessageBox.Show("I Wish You A Merry Christmas And Happy New Year!"); } }
public McTable vertexInTable(DbPolyline plineGetFromUser, string accuracyPoint) { List <Point3d> Vert = new List <Point3d>(); Vert = this.listVertecs(plineGetFromUser); // создаем таблицу McTable TablePoint = new McTable(); int rowCount = Vert.Count; int colCount = 4; TablePoint.Rows.AddRange(0, rowCount + 1); TablePoint.Columns.AddRange(0, colCount); // настройки таблицы по умолчанию TablePoint.DefaultCell.TextHeight = 2.5; TablePoint.DefaultCell.TextColor = System.Drawing.Color.Black; // наименование_столбцов TablePoint[0, 0].Value = "№_Point"; TablePoint[0, 1].Value = "X"; TablePoint[0, 2].Value = "Y"; TablePoint[0, 3].Value = "Z"; // учитываем систему координат McDocument doc = McDocument.WorkingDocument; Matrix3d matCurrent = doc.UCS; Matrix3d matUsc = matCurrent.Inverse(); //номера точек в ячейки и координата X,Y,Z for (int i = 0; i < Vert.Count; i++) { Point3d onePointAtList = new Point3d(); onePointAtList = Vert[i]; onePointAtList = onePointAtList.TransformBy(matUsc);// преобразуем в текущую систему координат int j = i + 1; // точность представления чисел в ячейках - получается из формы от пользователя switch (accuracyPoint) { case "0": TablePoint[j, 1].Precision = CellPrecisionEnum.Integer; TablePoint[j, 2].Precision = CellPrecisionEnum.Integer; TablePoint[j, 3].Precision = CellPrecisionEnum.Integer; break; case "0.0": TablePoint[j, 1].Precision = CellPrecisionEnum.Precision1; TablePoint[j, 2].Precision = CellPrecisionEnum.Precision1; TablePoint[j, 3].Precision = CellPrecisionEnum.Precision1; break; case "0.00": TablePoint[j, 1].Precision = CellPrecisionEnum.Precision2; TablePoint[j, 2].Precision = CellPrecisionEnum.Precision2; TablePoint[j, 3].Precision = CellPrecisionEnum.Precision2; break; case "0.000": TablePoint[j, 1].Precision = CellPrecisionEnum.Precision3; TablePoint[j, 2].Precision = CellPrecisionEnum.Precision3; TablePoint[j, 3].Precision = CellPrecisionEnum.Precision3; break; } //номера точек в ячейки и координата X,Y,Z TablePoint[j, 0].Type = CellFormatEnum.Number; TablePoint[j, 0].Value = j.ToString(); TablePoint[j, 1].Type = CellFormatEnum.Number; TablePoint[j, 1].Value = onePointAtList.X.ToString(); TablePoint[j, 2].Type = CellFormatEnum.Number; TablePoint[j, 2].Value = onePointAtList.Y.ToString(); TablePoint[j, 3].Type = CellFormatEnum.Number; TablePoint[j, 3].Value = onePointAtList.Z.ToString(); } return(TablePoint); }
public void fitPolyline(double tolerance, bool delSoursePL) { List <Point3d> Vert = new List <Point3d>(); List <Point3d> delVert = new List <Point3d>(); Vert = this.listVertecs(plineGetFromUser); if (this.closeAndDuplicateVertex == false && plineGetFromUser.Polyline.ClosedLogically == true) { for (uint i = 0; i < plineGetFromUser.Polyline.Segments.Count; i++) { Curve3d oneSegment = plineGetFromUser.Polyline.Segments.GetSegAt(i, true); int j = Convert.ToInt32(i); if (j == plineGetFromUser.Polyline.Segments.Count - 1 && oneSegment.Length(0, 1) < tolerance) // дописать логику. что делать если последний сегмент замкнутой поллинии короткий? { } else if (oneSegment.Length(0, 1) < tolerance) { delVert.Add(Vert[j + 1]); } } } else { for (uint i = 0; i < plineGetFromUser.Polyline.Segments.Count; i++) { Curve3d oneSegment = plineGetFromUser.Polyline.Segments.GetSegAt(i, true); int j = Convert.ToInt32(i); if (oneSegment.Length(0, 1) < tolerance) { delVert.Add(Vert[j + 1]); } } } List <Point3d> resultVertex = new List <Point3d>(); if (delVert.Count == 0) { MessageBox.Show("Коротких сегментов не найдено"); return; } else if (delVert.Count == Vert.Count - 1)// в случае если все сегменты меньше заданного значения -соединяем первую и последнюю точку { resultVertex.Add(plineGetFromUser.Polyline.Points.FirstPoint); resultVertex.Add(plineGetFromUser.Polyline.Points.LastPoint); } else { var result = Vert.Except(delVert);// на LINQ с помощью метода Except можно получить разность двух множеств foreach (var item in result) { Point3d PointForList = new Point3d(item.X, item.Y, item.Z); resultVertex.Add(PointForList); } } Polyline3d PL3dFited = new Polyline3d(resultVertex); if (plineGetFromUser.Polyline.ClosedLogically == true) { PL3dFited.SetClosed(true); } if (delSoursePL == true)// проверка удалять ли исходную Pl - чекбокс в форме { plineGetFromUser.DbEntity.Erase(); } plineGetFromUser = PL3dFited; plineGetFromUser.DbEntity.AddToCurrentDocument(); }
public HandlerPolyline(DbPolyline Pl) { plineGetFromUser = Pl; }
public void DrawFace() { //We draw half of face // Draw eye DbCircle eye = new DbCircle(); eye.Radius = 100; eye.Center = new Point3d(200, 500, 0); eye.DbEntity.AddToCurrentDocument(); //Draw nose DbLine nose = new DbLine(); nose.StartPoint = new Point3d(350, 400, 0); nose.EndPoint = new Point3d(350, 200, 0); nose.DbEntity.AddToCurrentDocument(); //Draw mouth DbPolyline mouth = new DbPolyline(); List <Point3d> mouthPoints = new List <Point3d>() { new Point3d(100, 150, 0), new Point3d(200, 100, 0), new Point3d(350, 100, 0) }; mouth.Polyline = new Polyline3d(mouthPoints); mouth.Polyline.SetClosed(false); mouth.DbEntity.Transform(McDocumentsManager.GetActiveDoc().UCS); //change coordinates from UCS to WCS for BD mouth.DbEntity.AddToCurrentDocument(); //draw mirror half the face (2nd half) DbCircle eye2 = new DbCircle(); eye2.Radius = 100; eye2.Center = new Point3d(500, 500, 0); eye2.DbEntity.AddToCurrentDocument(); DbPolyline mouth2 = new DbPolyline(); mouth2.Polyline = mouth.Polyline.Mirror(new Plane3d(new Point3d(350, 100, 0), new Vector3d(200, 0, 0))) as Polyline3d; mouth2.DbEntity.AddToCurrentDocument(); //Get notification in command line McContext.ShowNotification("You need to enter data into the console"); //Get uaser input InputJig editorInput = new InputJig(); string name = editorInput.GetText("Input your name and press Enter"); //Drawing face's text DbText spech = new DbText(); spech.Text = new TextGeom("Oh Master! Why I'm so ugly? Please remove me!", new Point3d(510, 15, 0), Vector3d.XAxis, "Standard", 15); spech.DbEntity.AddToCurrentDocument(); //Get windows message box MessageBox.Show("Congratulation " + name + " you did it! But look, it want, to say something to you..."); //Get popup help McContext.PopupNotification("Delete command has activated"); //Activate another command (Delete) McContext.ExecuteCommand("Delete"); }