Example #1
0
        //Methods
        private void GeomSurfGenerator(Autodesk.AutoCAD.DatabaseServices.Surface Surf)
        {
            Brep Br = new Brep(Surf);

            foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc in Br.Faces)
            {
                ExternalBoundedSurface[] ebSurfs = fc.GetSurfaceAsTrimmedNurbs();
                m_geomSurf = ebSurfs[0];
            }
            Br.Dispose();
        }
Example #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(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);
            }
        }
Example #3
0
        private Point2dCollection[] GetPointCollections(DbSurface offsetSurface, Point3d minPoint, Point3d maxPoint)
        {
            var countY      = (int)((maxPoint.Y - minPoint.Y) / StepY) + 1;
            var countX      = (int)((maxPoint.X - minPoint.X) / StepX1) + 1;
            var collections = new Point2dCollection[countY];

            Acad.SetLimitProgressor(countY);

            for (var i = 0; i < countY; i++)
            {
                Acad.ReportProgressor();
                var collection = new Point2dCollection();
                var dy         = i * StepY;

                for (var j = 0; j < countX; j++)
                {
                    var dx = j * StepX1;

                    offsetSurface.RayTest(minPoint + new Vector3d(dx, dy, 0), Vector3d.ZAxis, 0.0001, out SubentityId[] col, out DoubleCollection par);

                    if (par.Count == 1)
                    {
                        var point = new Point2d(dx, Math.Round(par[0], 2));
                        var ind   = collection.Count - 1;
                        if (ind > 0 && collection[ind - 1].GetVectorTo(collection[ind]).IsCodirectionalTo(collection[ind].GetVectorTo(point)))
                        {
                            collection[ind] = point;
                        }
                        else
                        {
                            collection.Add(point);
                        }
                    }
                }
                if (collection.Count > 1)
                {
                    collections[i] = collection;
                }
            }
            return(collections);
        }
Example #4
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);
        }
Example #5
0
        public static DBObjectCollection IntersectSurf(Autodesk.AutoCAD.DatabaseServices.Surface surf1, Autodesk.AutoCAD.DatabaseServices.Surface surf2)
        {
            Brep surfBrep1 = new Brep(surf1);
            Brep surfBrep2 = new Brep(surf2);
            SurfaceSurfaceIntersector ssi = new SurfaceSurfaceIntersector();

            DBObjectCollection dboCol = new DBObjectCollection();

            foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc1 in surfBrep1.Faces)
            {
                ExternalBoundedSurface[]          ebSurfs1 = fc1.GetSurfaceAsTrimmedNurbs();
                Autodesk.AutoCAD.Geometry.Surface sur1     = ebSurfs1[0];
                foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc2 in surfBrep2.Faces)
                {
                    ExternalBoundedSurface[]          ebSurfs2 = fc2.GetSurfaceAsTrimmedNurbs();
                    Autodesk.AutoCAD.Geometry.Surface sur2     = ebSurfs2[0];

                    ssi.Set(sur1, sur2);
                    if (ssi.NumResults < 1)
                    {
                        break;
                    }

                    for (int i = 0; i < ssi.NumResults; i++)
                    {
                        Curve3d c3d = ssi.IntersectCurve(i, true);
                        Curve   crv = GenCurve(c3d);
                        crv.SetDatabaseDefaults();
                        crv.Color = Color.FromRgb(255, 255, 255);
                        dboCol.Add(crv);

                        ////adding for now need instead to conver to single Spline
                        //BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite));
                        //btr.AppendEntity(crv);
                        //trans.AddNewlyCreatedDBObject(crv, true);
                    }
                }
            }
            return(dboCol);
        }
Example #6
0
        //aqcuired this information online, not sure how tall this surface is supposed to be or how to insert it into drawing
        //creates an extruded surface from an open polyline
        private ExtrudedSurface extrudeOpenPolyline(Polyline pPoly, Editor ed)
        {
            ExtrudedSurface extrSurf = new ExtrudedSurface();
            Face            face     = new Face(pPoly.StartPoint, pPoly.EndPoint, pPoly.EndPoint + new Vector3d(0, 0, 1000), pPoly.StartPoint + new Vector3d(0, 0, 1000), true, true, true, true);

            Autodesk.AutoCAD.DatabaseServices.Surface sweepEnt = new Autodesk.AutoCAD.DatabaseServices.Surface();
            sweepEnt.SetDatabaseDefaults();

            try
            { sweepEnt = Autodesk.AutoCAD.DatabaseServices.Surface.CreateFrom(face); }
            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {}

            SweepOptions sweepOpts = new SweepOptions();

            try
            { extrSurf.CreateExtrudedSurface(sweepEnt, (pPoly.EndPoint - pPoly.StartPoint).GetPerpendicularVector(), sweepOpts); }
            catch
            { ed.WriteMessage("\nFailed with CreateExtrudedSurface."); }

            return(extrSurf);
        }
Example #7
0
 //Constructors
 public SurfGeomConstruct(Autodesk.AutoCAD.DatabaseServices.Surface Surf)
 {
     GeomSurfGenerator(Surf);
 }
Example #8
0
        public void drawSpring()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            //??ask about gauge of spring back vs seat
            //seat 8 gauge .1285"
            //back 12 gauge .0808"

            #region get ends of spring to get total distance
            //ask user for points for spring to exist
            PromptPointOptions ppo = new PromptPointOptions("First end of spring:");
            PromptPointResult  ppr = ed.GetPoint(ppo);
            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }
            Point3d startPoint = ppr.Value;

            ppo.Message = "Second end of spring";
            ppr         = ed.GetPoint(ppo);
            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }

            //calculate distance from chosen points
            #endregion
            double totalLength = startPoint.DistanceTo(ppr.Value);

            #region get spring Type (length)
            //given total length, calculate ideal spring length which is total minus some percentage
            double theorySpgLength = (Math.Round(.9 * totalLength * 2)) / 2;
            //find the nearest spring length that is less than or equal to total length(springs tend to come in 1/2" increments)
            //compare to list of spring lengths in stock **(eventually get springs from SQL)

            //present any springs withen an accaptable margin of diviation (maybe 8%)??
            //if none are easily exceptable but might work within a special circumstance, present that with warning (10%)??
            //if none are accaptable at all, then give different warning and end command (user will need to move spring rail or order diff springs)

            //**idealy replace with a user dialoge to choose from springs in system
            //ask user for spring length desired(may prompt with options from list) based on orignal distance
            PromptDoubleOptions pdo = new PromptDoubleOptions("Enter spring length:");
            //needs to pull these dynamically***************
            pdo.Keywords.Add(theorySpgLength.ToString());
            pdo.Keywords.Add((theorySpgLength - .5).ToString());
            PromptDoubleResult pdr = ed.GetDouble(pdo);
            if (pdr.Status != PromptStatus.OK)
            {
                return;
            }
            #endregion
            double springLength = pdr.Value;

            #region Create top view of spring
            //1 Calculate rungs
            //spring length / average gap
            int    rungCount = Convert.ToInt32(springLength / .875);//guessing at the avg rung gap for starters
            double rungGap   = totalLength / rungCount;
            double rungWidth = 2 - rungGap;
            //springs tend to be approx 2" wide
            //rung widths are 2" - rung gap (the two radii of bends)

            //add all parts to object collection then convert to polyline
            DBObjectCollection springParts = new DBObjectCollection();
            //construct first rung (has hooked end)
            springParts = createEnd(springParts, startPoint, rungGap, rungWidth, true, true);

            //construct rungs/bends in middle
            //and bends on alternating runs
            for (int i = 0; i < rungCount; i++)
            {
                Line rung = new Line(
                    new Point3d(startPoint.X - rungWidth / 2, startPoint.Y + i * rungGap, startPoint.Z),
                    new Point3d(startPoint.X + rungWidth / 2, startPoint.Y + i * rungGap, startPoint.Z));
                //add rungs except for either end
                if (i != 0 && i != rungCount)
                {
                    springParts.Add(rung);
                }

                //add bends to either side depending on if it is an even or odd rung
                if (i % 2 == 0)
                {
                    //even
                    Arc leftBend = new Arc(new Point3d(startPoint.X - 1 + rungGap / 2, startPoint.Y + rungGap * i + rungGap / 2, startPoint.Z), rungGap / 2, Math.PI / 2, 3 * Math.PI / 2);
                    springParts.Add(leftBend);
                }
                else
                {
                    //odd
                    Arc rightBend = new Arc(new Point3d(startPoint.X + 1 - rungGap / 2, startPoint.Y + rungGap * i + rungGap / 2, startPoint.Z), rungGap / 2, 3 * Math.PI / 2, Math.PI / 2);
                    springParts.Add(rightBend);
                }
            }

            //construct end
            //if rungCount is even it opens same as first
            bool secondOpen = true;
            if (rungCount % 2 == 0)
            {
                secondOpen = false;
            }
            springParts = createEnd(springParts, new Point3d(startPoint.X, startPoint.Y + totalLength, startPoint.Z), rungGap, rungWidth, secondOpen, false);

            ////just for testing **
            //using (Transaction trans = db.TransactionManager.StartTransaction())
            //{
            //    BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
            //    BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
            //    foreach (DBObject dbo in springParts)
            //    {
            //        Entity ent = dbo as Entity;
            //        btr.AppendEntity(ent);
            //        trans.AddNewlyCreatedDBObject(ent, true);
            //    }

            //    trans.Commit();
            //}

            Polyline pLine = BuildPLine.drawPolyLine(springParts);

            //move spring polyline to the correct Z coordinate, converting to a polyline cuts off z coords leaving it at 0****
            //***************************
            #endregion

            #region create side view (crown)
            //need to account for creating arc along different plane
            //arc is start point, and then total length vertical from first point (same plane) *we'll rotate later
            //for now all springs will use same crown, need a formula later and need an element that accounts for flat vs curly springs
            //create arc flat along same plane as spring polyline, then rotate it??
            Arc     crown    = new Arc();
            Point3d startArc = new Point3d(startPoint.X - 2, startPoint.Y, startPoint.Z);
            Point3d endArc   = new Point3d(startArc.X, startArc.Y + totalLength, startArc.Z);
            Point3d arcMid   = new Point3d(startArc.X - 1.5, startArc.Y + (totalLength / 2), startArc.Z);

            //assuming crown is 1.5 until we derive a diff system
            //radius = height/2 + width^2/height(8)
            crown.Radius = .75 + (Math.Pow(startArc.DistanceTo(endArc), 2) / 12);

            //given that we always will have our arc aligned vertically center is easter to calculate
            crown.Center = new Point3d(arcMid.X + crown.Radius, arcMid.Y, arcMid.Z);

            Matrix3d ocs2wcs = Matrix3d.PlaneToWorld(crown.Normal);
            Plane    plane   = new Plane(ocs2wcs.CoordinateSystem3d.Origin, ocs2wcs.CoordinateSystem3d.Xaxis, ocs2wcs.CoordinateSystem3d.Yaxis);

            //need start and end angles
            //double startAngle = tanAngle(arcCenter, startArc);
            //double endAngle = tanAngle(arcCenter, endArc);
            crown.EndAngle   = (startArc - crown.Center).AngleOnPlane(plane);
            crown.StartAngle = (endArc - crown.Center).AngleOnPlane(plane);

            //Arc crown = new Arc(arcCenter,radius,startAngle,endAngle);

            // Rotate the 3D solid 30 degrees around the axis that is defined by the points
            Vector3d turnArc = crown.StartPoint.GetVectorTo(crown.EndPoint);
            crown.TransformBy(Matrix3d.Rotation(3 * (Math.PI / 2), turnArc, crown.StartPoint));

            #endregion

            //convert collection to polyline
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable       bt  = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                //Have to have both views inserted to turn into extruded surface
                btr.AppendEntity(pLine);
                tr.AddNewlyCreatedDBObject(pLine, true);
                btr.AppendEntity(crown);
                tr.AddNewlyCreatedDBObject(crown, true);

                #region Extrude surfaces from open curves, polylines
                //extrude two shapes
                Profile3d    profileCrown  = new Profile3d(crown);
                Profile3d    profileSpring = new Profile3d(pLine);
                Vector3d     polylineDir   = new Vector3d(0, 0, 4);
                Vector3d     crownDir      = (crown.StartPoint).GetVectorTo(new Point3d(crown.StartPoint.X + 4, crown.StartPoint.Y, crown.StartPoint.Z));
                SweepOptions sweepOp       = new SweepOptions();

                //need a different vector for crown
                ObjectId surfaceId = Autodesk.AutoCAD.DatabaseServices.Surface.CreateExtrudedSurface(
                    profileCrown, crownDir, sweepOp, true);
                ObjectId surfaceSpringId = Autodesk.AutoCAD.DatabaseServices.Surface.CreateExtrudedSurface(
                    profileSpring, polylineDir, sweepOp, true);

                //remove original lines
                pLine.Erase(true);
                crown.Erase(true);
                #endregion

                //intersect both regions(observe how extrusions work with ucs)
                Autodesk.AutoCAD.DatabaseServices.Surface crownEnt  = tr.GetObject(surfaceId, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Surface;
                Autodesk.AutoCAD.DatabaseServices.Surface springEnt = tr.GetObject(surfaceSpringId, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Surface;
                //convert both surfaces to nurbs
                //the polyline extrusion creates many surfaces in nurb form, loop through intersections creating splines and lines
                springParts = Intersect_Surfaces.IntersectSurf(crownEnt, springEnt);
                //delete surfaces
                crownEnt.Erase(true);
                springEnt.Erase(true);

                //join intersection pieces as spline (maynot be possible)
                //convert collection of splines/lines to single 3Dspline
                Spline springSpline = Intersect_Surfaces.mergeSpline(springParts);
                btr.AppendEntity(springSpline);
                tr.AddNewlyCreatedDBObject(springSpline, true);

                //loft along spline
                try
                {
                    //create circle to to sweep
                    Circle wireGauge = new Circle();
                    wireGauge.Center = springSpline.StartPoint;
                    wireGauge.Radius = .06425;//diameter .1285
                    //Entity sweepEnt = tr.GetObject();

                    Curve pathEnt = tr.GetObject(springSpline.Id, OpenMode.ForRead) as Curve;
                    //Curve pathEnt = tr.GetObject(pLine.Id, OpenMode.ForRead) as Curve;
                    if (wireGauge == null || pathEnt == null)
                    {
                        ed.WriteMessage("\nProblem getting spline made");
                        return;
                    }

                    //builder object to create sweepoptions
                    SweepOptionsBuilder sob = new SweepOptionsBuilder();

                    //align the entity to sweep to the path
                    sob.Align = SweepOptionsAlignOption.AlignSweepEntityToPath;

                    //the base point is the start of the path
                    sob.BasePoint = pathEnt.StartPoint;

                    //the profile will rotate to follow the path
                    sob.Bank = true;

                    Entity  ent;
                    Solid3d sol = new Solid3d();
                    sol.CreateSweptSolid(wireGauge, pathEnt, sob.ToSweepOptions());
                    ent = sol;

                    //and add it to the modelspace
                    btr.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);
                }
                catch { }

                //re-align spring to first points chosen by user
                tr.Commit();
            }
        }
Example #9
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);
                }
            }
        }
Example #10
0
        public void ImportUit3ds()
        {
            // Verkrijg document en database
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            acCurDb.Surfu = 0;
            acCurDb.Surfv = 0;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open de block-tabel
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                // Open de Model space om in te schrijven
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                //Bestand openen om binair te lezen
                binReader = new BinaryReader(File.Open(@"C:/3DGISBuffer.dat", FileMode.Open));

                //Loop door objecten
                int aantalobjecten = binReader.ReadInt32();
                for (int i = 0; i < aantalobjecten; i++)
                {
                    Point3dCollection vertarray = new Point3dCollection();
                    Int32Collection   facearray = new Int32Collection();

                    // Maak een subdivision-mesh aan
                    SubDMesh sdm = new SubDMesh();
                    sdm.SetDatabaseDefaults();

                    // Voeg het object toe aan de block-tabel
                    acBlkTblRec.AppendEntity(sdm);
                    acTrans.AddNewlyCreatedDBObject(sdm, true);

                    //objectkleur lezen
                    byte kleur_r = binReader.ReadByte();
                    byte kleur_g = binReader.ReadByte();
                    byte kleur_b = binReader.ReadByte();

                    //solidvlag lezen
                    Boolean solidvlag = LeesBoolean();

                    // Vertexarray vullen met vertices
                    Point3dCollection acPts3dPFMesh = new Point3dCollection();
                    Int32             nvts          = binReader.ReadInt32();

                    for (int j = 1; j <= nvts; j++)
                    {
                        Single nX = binReader.ReadSingle();
                        Single nY = binReader.ReadSingle();
                        Single nZ = binReader.ReadSingle();
                        vertarray.Add(new Point3d(nX, nY, nZ));
                    }

                    //Facearray vullen met faces
                    int nfcs = binReader.ReadInt32();
                    for (int j = 1; j <= nfcs; j++)
                    {
                        int fc1 = binReader.ReadInt32();
                        int fc2 = binReader.ReadInt32();
                        int fc3 = binReader.ReadInt32();

                        facearray.Add(3);
                        facearray.Add(fc1 - 1);
                        facearray.Add(fc2 - 1);
                        facearray.Add(fc3 - 1);
                    }

                    //Vertex- en facearray toevoegen aan mesh, smoothlevel 0
                    sdm.SetSubDMesh(vertarray, facearray, 0);

                    Entity pMijnObj = null;
                    if (solidvlag)
                    {
                        Autodesk.AutoCAD.DatabaseServices.Solid3d pSolid = sdm.ConvertToSolid(false, false);
                        pMijnObj = (Entity)pSolid;
                    }
                    else
                    {
                        Autodesk.AutoCAD.DatabaseServices.Surface pSurface = sdm.ConvertToSurface(false, false);
                        pMijnObj = (Entity)pSurface;
                    }
                    acBlkTblRec.AppendEntity(pMijnObj);
                    acTrans.AddNewlyCreatedDBObject(pMijnObj, true);

                    //Verwijder mesh
                    sdm.Erase();


                    // Schrijf objectnaam naar Xrecord in de entity-dictionary van de surface
                    SaveXRecord(pMijnObj, LeesAttributen(), "GISData", acTrans);

                    //kleur van het object updaten
                    pMijnObj.Color = Color.FromRgb(kleur_r, kleur_g, kleur_b);
                }//einde for-loop

                // Schrijf het object naar de AutoCAD-database en sluit binReader
                acTrans.Commit();
                binReader.Close();
            } //einde using transaction
        }     //einde method