public static void GetSheetProfileThickness(/*ObjectId aSheetProfilePolyObjectId , Point3d aPickedPoint*/) { using (var acTrans = _db.TransactionManager.StartTransaction()) { var tLine = (Line)acTrans.GetObject(_tLineId, OpenMode.ForWrite); _basePolyLine = (Polyline)acTrans.GetObject(_polylineId, OpenMode.ForWrite); tLine.Erase(); // Ed.Regen(); #region endmost_thickness_segment_search var buf = _num1; _num1 = _num2; _num2 = buf; var p1 = _basePolyLine.GetLineSegmentAt(_num1).EndPoint; var p2 = _basePolyLine.GetLineSegmentAt(_num1).StartPoint; var p3 = new Point3d((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2); var p4 = new Point3d(_ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.X + p3.X, _ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.Y + p3.Y, _ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.Z + p3.Z); var v3D = p3.GetVectorTo(p4); tLine = new Line(p1, p2); tLine.TransformBy(Matrix3d.Rotation(Math.PI / 4.0, v3D, p3)); tLine.SetDatabaseDefaults(); Draw(tLine, 2, acTrans); _ed.Regen(); _tLineId = tLine.ObjectId; // thickness = (BasePolyLine.GetLineSegment2dAt(NUM1)).Length; #endregion acTrans.Commit(); } _ed.Regen(); //return thickness; }
public void Unfold2DSheetProfileStart() { _ed = Application.DocumentManager.MdiActiveDocument.Editor; _db = Application.DocumentManager.MdiActiveDocument.Database; // Pick a polyline var polyOptions = new PromptEntityOptions("Pick a sheet profile :"); polyOptions.SetRejectMessage( "\nThis is not a generated sheet profile.\nSheet Profile is generated from a polyline with SHP command.\nCreate a sheet profile and try again."); polyOptions.AddAllowedClass(typeof(Polyline), true); var polyResult = _ed.GetEntity(polyOptions); if (polyResult.Status != PromptStatus.OK) { return; } var pickInsertionPoint = _ed.GetPoint(new PromptPointOptions("Pick insertion point.")); if (pickInsertionPoint.Status != PromptStatus.OK) { return; } _polylineId = polyResult.ObjectId; double thickness; using (var acTrans = _db.TransactionManager.StartTransaction()) { _basePolyLine = (Polyline)acTrans.GetObject(_polylineId, OpenMode.ForWrite); if ((CountOfArcs() + 2 != _basePolyLine.NumberOfVertices >> 1) || (CountOfArcs() % 2 > 0)) { CommandLineHelper.Command("._copy", _basePolyLine.ObjectId, "0,0", "\033", "0,0", "\033"); var acPts2D = new Point3dCollection(); for (var nCnt = 0; nCnt < _basePolyLine.NumberOfVertices; nCnt++) { acPts2D.Add(_basePolyLine.GetPoint3dAt(nCnt)); } for (var nCnt = 1; nCnt < acPts2D.Count; nCnt++) { var point1 = acPts2D[nCnt]; var point2 = acPts2D[nCnt - 1]; var dist = point1.DistanceTo(point2); if (dist < 0.001) { acPts2D.RemoveAt(nCnt); _basePolyLine.RemoveVertexAt(nCnt); nCnt--; } } for (var nCnt = 0; nCnt < acPts2D.Count; nCnt++) { var point1 = acPts2D[nCnt]; var point2 = acPts2D[nCnt + 1]; var bulge = _basePolyLine.GetBulgeAt(nCnt); if (bulge != 0) { var arc = _basePolyLine.GetArcSegmentAt(nCnt); var ppp = arc.Center; for (var nCnt1 = 1; nCnt1 < acPts2D.Count - 1; nCnt1++) { if (acPts2D[nCnt1].DistanceTo(ppp) < 0.01) { var c1 = new Complex(acPts2D[nCnt1].X, acPts2D[nCnt1].Y); var c2 = new Complex(acPts2D[nCnt1 - 1].X, acPts2D[nCnt1 - 1].Y); var c3 = new Complex(acPts2D[nCnt1 + 1].X, acPts2D[nCnt1 + 1].Y); var ml1 = new KLine2D(c1, c2); var ml2 = new KLine2D(c1, c3); var c4 = c1 - c2; c4 /= c4.abs(); c4 *= 0.1; var c5 = c1 - c3; c5 /= c5.abs(); c5 *= 0.1; var c6 = new Complex(point1.X, point1.Y); var c7 = new Complex(point2.X, point2.Y); var ml11 = new KLine2D((c1 - c3).real(), (c1 - c3).imag(), -(c1 - c3).real() * c6.real() - (c1 - c3).imag() * c6.imag()); var ml22 = new KLine2D((c1 - c2).real(), (c1 - c2).imag(), -(c1 - c2).real() * c7.real() - (c1 - c2).imag() * c7.imag()); var c55 = ml11.IntersectWitch(ml2); var c44 = ml22.IntersectWitch(ml1); //c6 -= c5; c7 -= c4; c6 -= c5 - c1 + c55; c7 -= c4 - c1 + c44; c4 = c1 - c4; c5 = c1 - c5; _basePolyLine.RemoveVertexAt(nCnt); _basePolyLine.AddVertexAt(nCnt, new Point2d(c6.real(), c6.imag()), bulge, 0, 0); _basePolyLine.RemoveVertexAt(nCnt + 1); _basePolyLine.AddVertexAt(nCnt + 1, new Point2d(c7.real(), c7.imag()), 0, 0, 0); _basePolyLine.RemoveVertexAt(nCnt1); _basePolyLine.AddVertexAt(nCnt1, new Point2d(c5.real(), c5.imag()), 0, 0, 0); _basePolyLine.AddVertexAt(nCnt1, new Point2d(c4.real(), c4.imag()), -bulge, 0, 0); acPts2D.Clear(); for (var nCnt2 = 0; nCnt2 < _basePolyLine.NumberOfVertices; nCnt2++) { acPts2D.Add(_basePolyLine.GetPoint3dAt(nCnt2)); } break; } } } } acTrans.Commit(); CommandLineHelper.Command("._u2d", _basePolyLine.ObjectId, pickInsertionPoint.Value); CommandLineHelper.Command("._erase", _basePolyLine.ObjectId, "\033"); return; // MessageBox.Show("Must have an even number of ARC segments !" , "ERROR:"); // return; } thickness = GetThickness(); if (thickness <= 0) { MessageBox.Show("PolyLine has only one segment or no ARC segment !", "ERROR:"); return; } if (_basePolyLine.Closed == false) { MessageBox.Show("The PolyLline is not closed !", "ERROR:"); return; } if (_basePolyLine.NumberOfVertices % 2 != 0) { MessageBox.Show("Must have an even number of segments !", "ERROR:"); return; } _pickPoint = pickInsertionPoint.Value; _cPickPoint = new Complex(_pickPoint.X, _pickPoint.Y); #region endmost_thickness_segment_search _num1 = -1; _num2 = -1; for (var i = 0; i < _basePolyLine.NumberOfVertices; i++) { var next = i < _basePolyLine.NumberOfVertices - 1 ? i + 1 : 0; var pre = i > 0 ? i - 1 : _basePolyLine.NumberOfVertices - 1; var seg = _basePolyLine.GetLineSegment2dAt(i); if (seg.Length - thickness < 0.000001) { var segPre = _basePolyLine.GetLineSegment2dAt(pre); var segNext = _basePolyLine.GetLineSegment2dAt(next); for (var j = next; j < _basePolyLine.NumberOfVertices; j++) { var seg1 = _basePolyLine.GetLineSegment2dAt(j); if (seg1.Length - thickness < 0.000001) { if (Math.Abs(seg.Length - seg1.Length) < 0.000001) { var cPre = new Complex(segPre.EndPoint.X, segPre.EndPoint.Y) - new Complex(segPre.StartPoint.X, segPre.StartPoint.Y); var cNext = new Complex(segNext.EndPoint.X, segNext.EndPoint.Y) - new Complex(segNext.StartPoint.X, segNext.StartPoint.Y); var ang = (cNext / cPre).arg(); if (Math.Abs(ang * 180 / Math.PI - 180) < 0.001) { if (_num1 == -1) { _num1 = i; _num2 = j; } else { if (Math.Abs(j - i) == _basePolyLine.NumberOfVertices / 2) { _num1 = i; _num2 = j; } } } } } } } } var p1 = _basePolyLine.GetLineSegmentAt(_num1).EndPoint; var p2 = _basePolyLine.GetLineSegmentAt(_num1).StartPoint; var p3 = new Point3d((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2); var p4 = new Point3d(_ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.X + p3.X, _ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.Y + p3.Y, _ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis.Z + p3.Z); var v3D = p3.GetVectorTo(p4); var tLine = new Line(p1, p2); tLine.TransformBy(Matrix3d.Rotation(Math.PI / 4.0, v3D, p3)); tLine.SetDatabaseDefaults(); Draw(tLine, 4, acTrans); _ed.Regen(); _tLineId = tLine.ObjectId; //thickness = (BasePolyLine.GetLineSegment2dAt(NUM1)).Length; #endregion acTrans.Commit(); } _unfoldPoints = new ArrayList(); _entityTemp = new List <ObjectId>(); Unfold2DForm = new Unfold2dForm(thickness); Unfold2DForm.U2D_PREPARE_REDRAW += PrepareRedraw; Unfold2DForm.ShowDialog(); Logger.Info(System.Reflection.MethodBase.GetCurrentMethod().Name); }