public void BuildProcessing(CableCommandGenerator generator) { var offsetDistance = TechProcess.ToolThickness / 2 + Delta; var dbObject = AcadObjects.First().ObjectId.QOpenForRead(); if (AcadObjects.Count == 2) { var matrix = Matrix3d.Displacement(Vector3d.ZAxis * offsetDistance); var railCurves = AcadObjects.Select(p => (Curve)p.ObjectId.QOpenForRead <Curve>().GetTransformedCopy(matrix)) .Select(p => new Line(p.StartPoint, p.EndPoint)).ToArray(); if (railCurves[0].StartPoint.GetVectorTo(railCurves[0].EndPoint).GetAngleTo(railCurves[1].StartPoint.GetVectorTo(railCurves[1].EndPoint)) > Math.PI / 2) { railCurves[1].ReverseCurve(); } if (IsRevereseDirection) { railCurves[0].ReverseCurve(); railCurves[1].ReverseCurve(); } var points = new List <Point3d[]>(); if (Approach > 0) { points.Add(railCurves.Select(p => p.StartPoint.GetExtendedPoint(p.EndPoint, Approach)).ToArray()); } //if (Approach < 0) // zStart += Approach; points.Add(railCurves.Select(p => p.StartPoint).ToArray()); points.Add(railCurves.Select(p => Departure >= 0 ? p.EndPoint : p.GetPointAtDist(p.Length + Departure)).ToArray()); if (Departure > 0) { points.Add(railCurves.Select(p => p.EndPoint.GetExtendedPoint(p.StartPoint, Departure)).ToArray()); } generator.GCommand(0, points[0][0], points[0][1], IsRevereseAngle); for (int i = 1; i < points.Count; i++) { generator.GCommand(1, points[i][0], points[i][1]); } return; } if (dbObject is Line rail) { var matrix = Matrix3d.Displacement(Vector3d.ZAxis * offsetDistance); rail = (Line)rail.GetTransformedCopy(matrix); //if (railCurves[0].StartPoint.GetVectorTo(railCurves[0].EndPoint).GetAngleTo(railCurves[1].StartPoint.GetVectorTo(railCurves[1].EndPoint)) > Math.PI / 2) // railCurves[1].ReverseCurve(); var points = new List <Point3d>(); if (Approach > 0) { points.Add(rail.StartPoint.GetExtendedPoint(rail.EndPoint, Approach)); } //if (Approach < 0) // zStart += Approach; points.Add(rail.StartPoint); points.Add(rail.EndPoint); if (Departure > 0) { points.Add(rail.EndPoint.GetExtendedPoint(rail.StartPoint, Departure)); } foreach (var point in points) { var line = new Line3d(point, rail.Delta.GetPerpendicularVector()); if (point == points[0]) { generator.GCommand(0, line); } else { generator.GCommand(1, line); } } return; } var surface = dbObject as DbSurface; if (dbObject is Region region) { var planeSurface = new PlaneSurface(); planeSurface.CreateFromRegion(region); surface = planeSurface; } surface.GeometricExtents.GetCenter(); var basePoint = surface.GeometricExtents.GetCenter(); if (IsRevereseOffset) { offsetDistance *= -1; } var offsetSurface = DbSurface.CreateOffsetSurface(surface, offsetDistance); var basePointOffset = offsetSurface.GeometricExtents.GetCenter(); //if (curves[0] is Region r) //{ // curves.Clear(); // r.Explode(curves); //} //var plane = offsetSurface.GetPlane(); var curves = new DBObjectCollection(); offsetSurface.Explode(curves); var pts = curves.Cast <Curve>().SelectMany(p => p.GetStartEndPoints()).OrderBy(x => x.Z).ToList(); var maxPoint = pts.Last(); var minPoint = pts.First(); if (maxPoint.Z - minPoint.Z < 10) // горизонтальная { var matrix = Matrix3d.Displacement(Vector3d.ZAxis * offsetDistance); var railCurvesAll = curves.Cast <Curve>().ToList(); var railCurves = new Curve[2]; var rc = railCurvesAll.Where(p => p.HasPoint(maxPoint)).OrderBy(p => p.Length()); railCurves[0] = Across ? rc.First() : rc.Last(); railCurves[1] = railCurvesAll.Where(p => !p.HasPoint(railCurves[0].StartPoint) && !p.HasPoint(railCurves[0].EndPoint)).First(); if (railCurves[0].StartPoint.GetVectorTo(railCurves[0].EndPoint).GetAngleTo(railCurves[1].StartPoint.GetVectorTo(railCurves[1].EndPoint)) > Math.PI / 2) { railCurves[1].ReverseCurve(); } if (IsRevereseDirection) { railCurves[0].ReverseCurve(); railCurves[1].ReverseCurve(); } var points = new List <Point3d[]>(); if (Approach > 0) { points.Add(railCurves.Select(p => p.StartPoint.GetExtendedPoint(p.EndPoint, Approach)).ToArray()); } points.Add(railCurves.Select(p => Approach >= 0 ? p.StartPoint : p.GetPointAtDist(-Approach)).ToArray()); points.Add(railCurves.Select(p => p.EndPoint).ToArray()); if (Departure > 0) { points.Add(railCurves.Select(p => p.EndPoint.GetExtendedPoint(p.StartPoint, Departure)).ToArray()); } generator.GCommand(0, points[0][0], points[0][1], IsRevereseAngle); for (int i = 1; i < points.Count; i++) { generator.GCommand(1, points[i][0], points[i][1]); } return; } var baseCurves = curves.Cast <Curve>().Where(p => p.HasPoint(maxPoint)).ToArray(); var plane = new Plane(maxPoint, baseCurves[0].EndPoint - baseCurves[0].StartPoint, baseCurves[1].EndPoint - baseCurves[1].StartPoint); var zStart = pts.Last().Z; var zEnd = pts.First().Z; var zPos = new List <double>(); if (Approach > 0) { zPos.Add(zStart + Approach); } if (Approach < 0) { zStart += Approach; } zPos.Add(zStart); if (Departure < 0) { zEnd -= Departure; } zPos.Add(zEnd); if (Departure > 0) { zPos.Add(zEnd - Departure); } foreach (var z in zPos) { var line = plane.IntersectWith(new Plane(new Point3d(0, 0, z), Vector3d.ZAxis)); var u = line.GetDistanceTo(new Point3d(TechProcess.OriginX, TechProcess.OriginY, z)); if (z == zPos[0]) { //var angle = line.Direction.ToVector2d().MinusPiToPiAngleTo(Vector2d.YAxis); //generator.GCommandAngle(line.Direction.ToVector2d(), S); //generator.GCommand(0, u); //generator.GCommand(0, u, z); generator.GCommand(0, line, IsRevereseAngle); } else { generator.GCommand(1, line); //generator.GCommand(1, u, z, CuttingFeed); } } }
public void BuildProcessing(CableCommandGenerator generator) { //var dbObject = ProcessingArea.ObjectId.QOpenForRead(); var surface = AcadObjects.First().ObjectId.QOpenForRead <DbSurface>(); var offsetDistance = TechProcess.ToolThickness / 2 + Delta; if (IsRevereseOffset) { offsetDistance *= -1; } //var offsetSurface = DbSurface.CreateOffsetSurface(surface, offsetDistance); var collection = new DBObjectCollection(); surface.Explode(collection); var curves = collection.Cast <Curve>().ToList(); var vertex = curves.SelectMany(p => p.GetStartEndPoints()).OrderBy(p => p.Z).ToList(); var maxPoint = vertex.Last(); var minPoint = vertex.First(); var maxCurves = curves.FindAll(p => p.HasPoint(maxPoint)); var minCurves = curves.FindAll(p => p.HasPoint(minPoint)); //var rail1s = new List<Curve> //{ // maxCurves[0], // minCurves.Single(p => p.HasPoint(maxCurves[0].StartPoint) || p.HasPoint(maxCurves[0].EndPoint)) //}; //var rail2s = new List<Curve> //{ // maxCurves[1], // minCurves.Single(p => p != rail1s[1]) //}; //var rail1 = ((Spline)maxCurves[0]).ToPolyline(); // GetRail(maxPoint, maxCurves[0], minCurves.Single(p => p.HasPoint(maxCurves[0].StartPoint) || p.HasPoint(maxCurves[0].EndPoint))); //var rail2 = ((Spline)maxCurves[1]).ToPolyline(); // GetRail(maxPoint, maxCurves[1], minCurves.Single(p => p.HasPoint(maxCurves[1].StartPoint) || p.HasPoint(maxCurves[1].EndPoint))); var rail1 = new Rail(maxPoint, maxCurves[0], curves); var rail2 = new Rail(maxPoint, maxCurves[1], curves); //var length1 = rail1.GetDistanceAtParameter(rail1.EndParam); //var length2 = rail2.GetDistanceAtParameter(rail2.EndParam); //double dist1 = 0; //double dist2 = 0; double step = 2; generator.Feed = CuttingFeed; generator.S = S; generator.Center = new Point2d(TechProcess.OriginX, TechProcess.OriginY); while (!rail1.IsEnd && !rail2.IsEnd) { var pt1 = rail1.Step(step); var pt2 = rail2.Step(step); if (pt2.Z - pt1.Z > 2) { rail2.StepToZ(pt1.Z, 0.1); } else if (pt1.Z - pt2.Z > 2) { rail1.StepToZ(pt2.Z, 0.1); } //dist1 += step; //if (dist1 >= length1) // break; //var pt1 = rail1.GetPointAtDist(dist1); //dist2 += step; //if (dist2 >= length2) // break; //var pt2 = rail2.GetPointAtDist(dist2); //if (pt1.Z < pt2.Z) //{ // var dist = dist2; // var pt = pt2; // while(dist < length2 && pt.Z > pt1.Z) // { // dist2 = dist; // pt2 = pt; // dist += step; // pt = rail2.GetPointAtDist(dist); // } // if (dist < length2 && pt1.Z - pt.Z < pt2.Z - pt1.Z) // { // dist2 = dist; // pt2 = pt; // } //} //else //{ // var dist = dist1; // var pt = pt1; // while (dist < length1 && pt.Z > pt2.Z) // { // dist1 = dist; // pt1 = pt; // dist += step; // pt = rail1.GetPointAtDist(dist); // } // if (dist < length1 && pt2.Z - pt.Z < pt1.Z - pt2.Z) // { // dist1 = dist; // pt1 = pt; // } //} generator.GCommand(1, rail1.Point, rail2.Point); } }