Esempio n. 1
0
        private DbSurface CreateOffsetSurface()
        {
            DbSurface unionSurface = null;

            foreach (var dBObject in TechProcess.ProcessingArea.Select(p => p.ObjectId.QOpenForRead()))
            {
                DbSurface surface;
                switch (dBObject)
                {
                case DbSurface sf:
                    surface = sf.Clone() as DbSurface;
                    break;

                case Region region:
                    surface = new PlaneSurface();
                    ((PlaneSurface)surface).CreateFromRegion(region);
                    break;

                default:
                    throw new Exception(ErrorStatus.NotImplementedYet, $"Объект типа {dBObject.GetType()} не может быть обработан (1)");
                }
                if (unionSurface == null)
                {
                    unionSurface = surface;
                }
                else
                {
                    var res = unionSurface.BooleanUnion(surface);
                    if (res != null)
                    {
                        unionSurface.Dispose();
                        unionSurface = res;
                    }
                    surface.Dispose();
                }
            }
            if (Delta == 0)
            {
                return(unionSurface);
            }

            try
            {
                var offsetSurface = DbSurface.CreateOffsetSurface(unionSurface, Delta) as DbSurface;
                unionSurface.Dispose();
                return(offsetSurface);
            }
            catch
            {
                unionSurface.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * Delta));
                return(unionSurface);
            }
        }
Esempio n. 2
0
        private DbSurface CreateOffsetSurface()
        {
            DbSurface unionSurface = null;

            foreach (var dBObject in TechProcess.ProcessingArea.Select(p => p.ObjectId.QOpenForRead()))
            {
                DbSurface surface;
                switch (dBObject)
                {
                case DbSurface sf:
                    surface = sf.Clone() as DbSurface;
                    break;

                case Region region:
                    surface = new PlaneSurface();
                    ((PlaneSurface)surface).CreateFromRegion(region);
                    break;

                default:
                    throw new Exception($"Объект типа {dBObject.GetType()} не может быть обработан (1)");
                }
                if (unionSurface == null)
                {
                    unionSurface = surface;
                }
                else
                {
                    var res = unionSurface.BooleanUnion(surface);
                    if (res != null)
                    {
                        unionSurface.Dispose();
                        unionSurface = res;
                    }
                    surface.Dispose();
                }
            }
            var offsetSurface = DbSurface.CreateOffsetSurface(unionSurface, Delta) as DbSurface;

            unionSurface.Dispose();
            return(offsetSurface);
        }
Esempio n. 3
0
        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);
                }
            }
        }