public SlopeLinesGenerator(Matrix3d ucs) : base(ucs) { if (_dataHost == null) { _dataHost = new MainMenu.HostProvider(this); } _ucs = Tools.GetAcadEditor().CurrentUserCoordinateSystem; _baseLine = null; _destinationLine = null; _regressBaseLine = null; _regressDestLine = null; _startPoint = Point3d.Origin; _endPoint = Point3d.Origin; _entitiesInMemory = new List <Entity>(); //_slopeMode = SlopeModes.OwnPerpendicular; _startPointComplete = false; _endPointComplete = false; _step = _dataHost.Read("step", 2.5d); _smallLineLength = _dataHost.Read("smallLineLength", 0.5d); _slopeMode = _dataHost.Read("slopeMode", SlopeModes.OwnPerpendicular); }
public PromptStatus PromptSlopeLineMode(string msg = "\nУкавите метод построения линий откоса") { PromptKeywordOptions pko = new PromptKeywordOptions(msg); pko.Keywords.Add(SlopeModes.OwnPerpendicular.ToString(), "ПРостойПЕРпендикуляр", "ПРостойПЕРпендикуляр", true, true); pko.Keywords.Add(SlopeModes.EqualStep.ToString(), "ЕКВивалентныйШаг", "ЕКВивалентныйШаг", true, true); pko.Keywords.Add(SlopeModes.BothPerpendicular.ToString(), "ПЕРпендикулярОтНиза", "ПЕРпендикулярОтНиза", true, true); pko.Keywords.Add(SlopeModes.RegressBoth.ToString(), "РЕГрессия", "РЕГрессия", true, true); pko.Keywords.Add("Exit", "ВЫХод", "ВЫХод", true, true); PromptResult pr = Tools.GetAcadEditor().GetKeywords(pko); if (pr.Status != PromptStatus.OK) { return(pr.Status); } if (pr.StringResult == "Exit") { return(PromptStatus.Cancel); } else if (pr.StringResult == SlopeModes.OwnPerpendicular.ToString()) { _slopeMode = SlopeModes.OwnPerpendicular; _dataHost.Write("slopeMode", _slopeMode); return(PromptStatus.OK); } else if (pr.StringResult == SlopeModes.EqualStep.ToString()) { _slopeMode = SlopeModes.EqualStep; _dataHost.Write("slopeMode", _slopeMode); return(PromptStatus.OK); } else if (pr.StringResult == SlopeModes.BothPerpendicular.ToString()) { _slopeMode = SlopeModes.BothPerpendicular; _dataHost.Write("slopeMode", _slopeMode); return(PromptStatus.OK); } else if (pr.StringResult == SlopeModes.RegressBoth.ToString()) { _slopeMode = SlopeModes.RegressBoth; _dataHost.Write("slopeMode", _slopeMode); return(PromptStatus.OK); } else { throw new ArgumentException(); } }
public List <Line> Calculate(SlopeModes slopeMode) { List <Line> slopeLines = new List <Line>(); Polyline basePline = _baseLine.ConvertToPolyline(); Polyline destPline = _destinationLine.ConvertToPolyline(); if (!_startPointComplete) { _startPoint = basePline.StartPoint; } if (!_endPointComplete) { _endPoint = _startPoint; } double startDist = 0; startDist = basePline.GetDistAtPoint(_startPoint); double endDist = startDist; try { endDist = basePline.GetDistAtPoint(_endPoint); } catch { } Vector3d startVector = _startPoint - destPline.StartPoint; Vector3d endVector = _endPoint - destPline.EndPoint; Point3d centralPoint = _startPoint.Add((_endPoint - _startPoint).MultiplyBy(0.5d)); if ((centralPoint - destPline.StartPoint).Length < startVector.Length && (centralPoint - destPline.EndPoint).Length < endVector.Length) { Vector3d buffVector = startVector; startVector = endVector; endVector = startVector; destPline = ((Polyline)destPline.Clone()); destPline.ReverseCurve(); } int sign = endDist >= startDist ? 1 : -1; double buffLength = startVector.Length + endVector.Length + basePline.Length + destPline.Length; int slopeNumber = 0; //for (double dist = startDist; dist <= endDist && dist <= basePline.Length; dist += _step) for (double dist = startDist; sign > 0 ? dist <= endDist : dist >= endDist; dist += _step * sign) { slopeNumber++; Point3d point = basePline.GetPointAtDist(dist); switch (slopeMode) { case SlopeModes.BothPerpendicular: { Point3d?destPoint = destPline.GetOrthoNormalPoint(point, null, true); if (destPoint.HasValue) { Line slope = new Line(point, destPoint.Value); //if ((dist-startDist +_step) % (_step*2d) < Tolerance.Global.EqualPoint) if (slopeNumber % 2d == 0d) { slope = new Line(slope.StartPoint, slope.StartPoint.Add((slope.EndPoint - slope.StartPoint).MultiplyBy(_smallLineLength))); } slopeLines.Add(slope); } break; } case SlopeModes.OwnPerpendicular: { Line line = new Line(point, point.Add(_baseLine.GetPerpendicularVector(point).MultiplyBy(buffLength))); Point3dCollection intersects = new Point3dCollection(); Point3d?destPoint = _getIntersectPoint(line, destPline); if (!destPoint.HasValue) { break; } Line slope = new Line(point, destPoint.Value); if (slopeNumber % 2d == 0d) { slope = new Line(slope.StartPoint, slope.StartPoint.Add((slope.EndPoint - slope.StartPoint).MultiplyBy(_smallLineLength))); } slopeLines.Add(slope); break; } case SlopeModes.EqualStep: { int count = Convert.ToInt32(Math.Floor(Math.Abs(endDist - startDist) / _step)); if (count == 0) { break; } Point3d?startDestPoint = destPline.GetOrthoNormalPoint(_startPoint, null, true); Point3d?endDestPoint = destPline.GetOrthoNormalPoint(point, null, true); if (!startDestPoint.HasValue) { startDestPoint = destPline.StartPoint; } if (!endDestPoint.HasValue) { endDestPoint = destPline.EndPoint; } double lengthFactor = destPline.Length / basePline.Length; double destDist = dist * lengthFactor; if (Math.Abs(destDist) <= Tolerance.Global.EqualPoint) { destDist = 0d; } if (Math.Abs(destDist - destPline.Length) <= Tolerance.Global.EqualPoint) { destDist = destPline.Length; } Point3d destPoint = destPline.GetPointAtDist(destDist); Line slope = new Line(point, destPoint); if (slopeNumber % 2d == 0d) { slope = new Line(slope.StartPoint, slope.StartPoint.Add((slope.EndPoint - slope.StartPoint).MultiplyBy(_smallLineLength))); } slopeLines.Add(slope); break; } case SlopeModes.RegressBoth: { Point3d?basePoint = _regressBaseLine.GetOrthoNormalPoint(point, null, true); if (basePoint.HasValue) { Point3d?destPoint = _regressDestLine.GetOrthoNormalPoint(basePoint.Value, null, true); if (destPoint.HasValue) { Line slope = new Line(basePoint.Value, destPoint.Value); basePoint = _getIntersectPoint(slope, basePline); if (basePoint.HasValue) { destPoint = _getIntersectPoint(slope, destPline); if (destPoint.HasValue) { slope = new Line(basePoint.Value, destPoint.Value); if (slopeNumber % 2d == 0d) { slope = new Line(slope.StartPoint, slope.StartPoint.Add((slope.EndPoint - slope.StartPoint).MultiplyBy(_smallLineLength))); } slopeLines.Add(slope); } } } } break; } } } return(slopeLines); }