Пример #1
0
 public Elbow() : base()
 {
     position         = new AcadGeo.Point3d();
     branch_positions = new AcadGeo.Point3d[2];
     radius           = 0.0;
     angle            = AcadFuncs.kPI * 0.5;
 }
Пример #2
0
        static public List <ObjectId> EntsInsideWindow(AcadGeo.Point3d low_pnt, AcadGeo.Point3d hi_pnt)
        {
            using (AcadApp.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    PromptSelectionResult prmpt_ret = AcadFuncs.GetEditor().SelectCrossingWindow(low_pnt, hi_pnt);
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return(new List <ObjectId>());
                    }

                    tr.Commit();
                    if (null != prmpt_ret.Value)
                    {
                        return(prmpt_ret.Value.GetObjectIds().ToList());
                    }
                    else
                    {
                        return(new List <ObjectId>());
                    }
                }
            }
        }
Пример #3
0
 public PathInfo(AcadDB.Entity r, AcadDB.Entity sr, AcadDB.Entity p, AcadGeo.Point3d sp)
 {
     region         = r;
     sub_region     = sr;
     path           = p;
     start_position = sp;
 }
Пример #4
0
        protected override List <PathInfo> GetSweptPath()
        {
            AcadGeo.Point3d       center  = CalculateCenter();
            AcadGeo.Vector3d      ref_vec = AcadFuncs.GetVec(CalculateBranchPos(position, branch_positions[0], radius, angle), center);
            AcadGeo.CircularArc3d arc     = new AcadGeo.CircularArc3d(
                center, NormalVec(), ref_vec, radius,
                GetStartAngle(position, center, ref_vec, NormalVec()), GetEndAngle(position, center, ref_vec, NormalVec()));

            AcadFuncs.AddNewEnt(AcadDB.Arc.CreateFromGeCurve(arc));

            List <PathInfo> ents = new List <PathInfo>();

            AcadGeo.Point3d bp = CalculateBranchPos(position,
                                                    profile.NormalVector.GetNormal().IsParallelTo(AcadFuncs.GetVec(position, branch_positions[1])) ? branch_positions[1] : branch_positions[0],
                                                    radius, angle);

            profile.BasePoint = bp;
            ents.Add(new PathInfo(profile.GetRegions().First(), profile.GetSubRegions().First(), AcadDB.Arc.CreateFromGeCurve(arc), bp));

            //{
            //	var regs = profile.GetRegions();
            //	AcadFuncs.AddNewEnt(regs[0]);
            //}

            return(ents);
        }
Пример #5
0
        private void Connect(AcadGeo.Point3d fp, AcadGeo.Point3d sp)
        {
            Node fn = FindNode(fp);

            if (null == fn)
            {
                fn = new Node(fp);
                routers.AddVertex(fn);
            }

            Node sn = FindNode(sp);

            if (null == sn)
            {
                sn = new Node(sp);
                routers.AddVertex(sn);
            }

            if (routers.ContainsEdge(fn, sn))
            {
                return;
            }

            Connection conn = new Connection(fn, sn);

            routers.AddEdge(conn);
            fn.Connections.Add(conn);
            sn.Connections.Add(conn);
        }
Пример #6
0
 public static AcadGeo.Point3d GetMidPoint(AcadGeo.Point3d pos1, AcadGeo.Point3d pos2)
 {
     return(new AcadGeo.Point3d(
                0.5 * (pos1.X + pos2.X),
                0.5 * (pos1.Y + pos2.Y),
                0.5 * (pos1.Z + pos2.Z)));
 }
Пример #7
0
 public SteelShapeB()
 {
     number_steel = 0;
     diameter     = 0;
     start_point  = AcadGeo.Point3d.Origin;
     end_point    = AcadGeo.Point3d.Origin;
 }
Пример #8
0
 public static AcadGeo.Vector3d GetVec(AcadGeo.Point3d pos1, AcadGeo.Point3d pos2)
 {
     return(new AcadGeo.Vector3d(
                pos1.X - pos2.X,
                pos1.Y - pos2.Y,
                pos1.Z - pos2.Z).GetNormal());
 }
Пример #9
0
        public static bool GetPoint(ref AcadGeo.Point3d val, string message, AcadGeo.Point3d bp)
        {
            AcadApp.DocumentManager.MdiActiveDocument.Window.Focus();
            using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (AcadDB.Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    AcadEd.PromptPointOptions prmpt_pnt = new AcadEd.PromptPointOptions(message);
                    prmpt_pnt.UseBasePoint = true;
                    prmpt_pnt.BasePoint    = bp;
                    AcadEd.PromptPointResult prmpt_ret = AcadFuncs.GetEditor().GetPoint(prmpt_pnt);
                    if (AcadEd.PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return(false);
                    }

                    val = prmpt_ret.Value;
                    tr.Commit();
                }
            }

            return(true);
        }
Пример #10
0
 public Tee() : base()
 {
     position             = new AcadGeo.Point3d();
     main_branch_position = new AcadGeo.Point3d();
     branch_position      = new AcadGeo.Point3d();
     radius = 0.0;
 }
Пример #11
0
 public InfoSteel2()
 {
     number    = 0;
     content   = "";
     position  = AcadGeo.Point3d.Origin;
     steel_pos = new List <AcadGeo.Point3d>();
 }
Пример #12
0
 public JigSpline(Spline ent)
     : base(ent)
 {
     Entity.SetDatabaseDefaults();
     Entity.TransformBy(ucs);
     mLastVertex = ent.GetFitPointAt(2);
 }
Пример #13
0
        private static Acad.Vector3d FindTriangleCenter(Autodesk.AutoCAD.Geometry.Point3d p1, Autodesk.AutoCAD.Geometry.Point3d p2, Autodesk.AutoCAD.Geometry.Point3d p3, Autodesk.AutoCAD.Geometry.Vector3d norm)
        {
            var centerX = (p1.X + p2.X + p3.X) / 3;
            var centerY = (p1.Y + p2.Y + p3.Y) / 3;
            var centerZ = FinalZCoordAcad(norm, p1, new Autodesk.AutoCAD.Geometry.Vector3d(centerX, centerY, 0));

            return(new Acad.Vector3d(centerX, centerY, centerZ));
        }
Пример #14
0
        public List <AcadDB.Entity> DrawMiddleBeam(AcadGeo.Point3d ins_pnt)
        {
            List <AcadDB.Entity> ents = new List <AcadDB.Entity>();

            ents.AddRange(DrawBoundBeam(ins_pnt));

            return(ents);
        }
Пример #15
0
 public static void Transform(ngeometry.VectorGeometry.Point p, Autodesk.AutoCAD.Geometry.Matrix3d matrix)
 {
     Autodesk.AutoCAD.Geometry.Point3d p3d = new Point3d(p.X, p.Y, p.Z);
     Autodesk.AutoCAD.Geometry.Point3d r   = p3d.TransformBy(matrix);
     p.X = r.X;
     p.Y = r.Y;
     p.Z = r.Z;
 }
Пример #16
0
        // This method helps to get correct "boundary box" for the regions which
        // created through the splines. Written by Alexander Rivilis.
        public static void GetVisualBoundary(this Db.Region region, double delta,
                                             ref Gm.Point2d minPoint, ref Gm.Point2d maxPoint)
        {
            using (Gm.BoundBlock3d boundBlk = new Gm.BoundBlock3d())
            {
                using (Br.Brep brep = new Br.Brep(region))
                {
                    foreach (Br.Edge edge in brep.Edges)
                    {
                        using (Gm.Curve3d curve = edge.Curve)
                        {
                            Gm.ExternalCurve3d curve3d = curve as Gm.ExternalCurve3d;

                            if (curve3d != null && curve3d.IsNurbCurve)
                            {
                                using (Gm.NurbCurve3d nurbCurve = curve3d.NativeCurve
                                                                  as Gm.NurbCurve3d)
                                {
                                    Gm.Interval interval = nurbCurve.GetInterval();
                                    for (double par = interval.LowerBound; par <=
                                         interval.UpperBound; par += (delta * 2.0))
                                    {
                                        Gm.Point3d p = nurbCurve.EvaluatePoint(par);
                                        if (!boundBlk.IsBox)
                                        {
                                            boundBlk.Set(p, p);
                                        }
                                        else
                                        {
                                            boundBlk.Extend(p);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (!boundBlk.IsBox)
                                {
                                    boundBlk.Set(edge.BoundBlock.GetMinimumPoint(),
                                                 edge.BoundBlock.GetMaximumPoint());
                                }
                                else
                                {
                                    boundBlk.Extend(edge.BoundBlock.GetMinimumPoint());
                                    boundBlk.Extend(edge.BoundBlock.GetMaximumPoint());
                                }
                            }
                        }
                    }
                }
                boundBlk.Swell(delta);

                minPoint = new Gm.Point2d(boundBlk.GetMinimumPoint().X,
                                          boundBlk.GetMinimumPoint().Y);
                maxPoint = new Gm.Point2d(boundBlk.GetMaximumPoint().X,
                                          boundBlk.GetMaximumPoint().Y);
            }
        }
Пример #17
0
        protected override List <PathInfo> GetSweptPath()
        {
            AcadGeo.Point3d       center  = CalculateCenter();
            AcadGeo.Vector3d      ref_vec = AcadFuncs.GetVec(CalculateBranchPos(position, main_branch_position, radius), center);
            AcadGeo.CircularArc3d arc     = new AcadGeo.CircularArc3d(
                center, NormalVec(), ref_vec, radius,
                GetStartAngle(position, center, ref_vec, NormalVec()), GetEndAngle(position, center, ref_vec, NormalVec()));

            //AcadFuncs.AddNewEnt(AcadDB.Arc.CreateFromGeCurve(arc));

            List <PathInfo> ents = new List <PathInfo>();

            AcadGeo.Point3d bp = CalculateBranchPos(position,
                                                    profile.NormalVector.GetNormal().IsParallelTo(ref_vec) ? branch_position : main_branch_position,
                                                    radius);

            profile.BasePoint = new AcadGeo.Point3d(bp.X, bp.Y, bp.Z);
            ents.Add(new PathInfo(profile.GetRegions().First(), profile.GetSubRegions().First(), AcadDB.Arc.CreateFromGeCurve(arc), bp));

            {
                AcadGeo.Plane         plane   = new AcadGeo.Plane(position, AcadFuncs.GetVec(position, branch_position));
                AcadGeo.CircularArc3d tmp_arc = new AcadGeo.CircularArc3d(
                    arc.Center, arc.Normal, arc.ReferenceVector, arc.Radius, arc.StartAngle, arc.EndAngle);
                tmp_arc.Mirror(plane);

                AcadGeo.Point3d tmp_bp = new AcadGeo.Point3d(bp.X, bp.Y, bp.Z);
                if (tmp_bp.IsEqualTo(CalculateBranchPos(position, branch_position, radius)))
                {
                    tmp_bp           += AcadFuncs.GetVec(position, branch_position) * radius * 2.0;
                    profile.BasePoint = tmp_bp;
                }
                //AcadFuncs.AddNewEnt(AcadDB.Arc.CreateFromGeCurve(tmp_arc));

                ents.Add(new PathInfo(profile.GetRegions().First(), profile.GetSubRegions().First(), AcadDB.Arc.CreateFromGeCurve(tmp_arc), tmp_bp));
            }

            {
                AcadGeo.Point3d tmp_pos     = CalculateBranchPos(position, branch_position, radius);
                AcadGeo.Point3d tmp_end_pos = tmp_pos + AcadFuncs.GetVec(position, branch_position) * radius * 2.0;

                AcadGeo.Point3d tmp_bp = new AcadGeo.Point3d(bp.X, bp.Y, bp.Z);
                if (tmp_bp.IsEqualTo(CalculateBranchPos(position, branch_position, radius)))
                {
                    profile.BasePoint = CalculateBranchPos(position, branch_position, radius);
                }
                else
                {
                    profile.BasePoint = new AcadGeo.Point3d(position.X, position.Y, position.Z);
                    profile.Rotate(AcadFuncs.GetVec(position, branch_position));
                    profile.BasePoint = CalculateBranchPos(position, branch_position, radius);
                }

                ents.Add(new PathInfo(profile.GetRegions().First(), profile.GetSubRegions().First(), new AcadDB.Line(tmp_pos, tmp_end_pos), tmp_bp));
            }


            return(ents);
        }
Пример #18
0
 public Profile(Profile p)
 {
     base_point    = p.base_point;
     width         = p.width;
     height        = p.height;
     thickness     = p.thickness;
     up_vector     = p.up_vector;
     normal_vector = p.normal_vector;
 }
Пример #19
0
 public Profile()
 {
     base_point    = new AcadGeo.Point3d();
     width         = 0.0;
     height        = 0.0;
     thickness     = 0.0;
     up_vector     = new AcadGeo.Vector3d();
     normal_vector = new AcadGeo.Vector3d();
 }
Пример #20
0
        private AcadGeo.Point3d CalculateCenter()
        {
            AcadGeo.Vector3d vec = AcadFuncs.GetVec(
                CalculateBranchPos(position, main_branch_position, radius),
                CalculateBranchPos(position, branch_position, radius));
            AcadGeo.Point3d pos   = position + AcadFuncs.GetVec(main_branch_position, position) * radius;
            AcadGeo.Plane   plane = new AcadGeo.Plane(pos, NormalVec().CrossProduct(vec));

            return(position.Mirror(plane));
        }
Пример #21
0
 public AcadGeo.Point3d ConnectedPos(AcadGeo.Point3d pos)
 {
     if (Source.Position.IsEqualTo(pos))
     {
         return(Target.Position);
     }
     else
     {
         return(Source.Position);
     }
 }
Пример #22
0
 private void AutoDetectParams(ref AcadGeo.Point3d bp, ref AcadGeo.Vector3d up_vec, ref AcadGeo.Vector3d norm)
 {
     foreach (var conn in routers.Edges)
     {
         if (ConnVec(conn).DotProduct(AcadGeo.Vector3d.ZAxis) < 0.0001)
         {
             bp     = conn.Source.Position;
             up_vec = AcadGeo.Vector3d.ZAxis;
             norm   = ConnVec(conn);
         }
     }
 }
Пример #23
0
        public static Point3dCollection GetOffsetTriangles(TinSurfaceTriangle tri, double offset)
        {
            var points = new Point3dCollection();

            try
            {
                Acad.Vector3d cenpointp3d = new Acad.Vector3d();
                Acad.Vector3d centerv1    = new Acad.Vector3d();
                Acad.Vector3d centerv2    = new Acad.Vector3d();
                Acad.Vector3d centerv3    = new Acad.Vector3d();

                var v1 = tri.Vertex1.Location;
                var v2 = tri.Vertex2.Location;
                var v3 = tri.Vertex3.Location;


                var vec1 = v1.GetVectorTo(v2);
                var vec2 = v1.GetVectorTo(v3);

                var norm = vec1.CrossProduct(vec2);
                var e1   = UnitVector3D(vec1);
                var e2   = UnitVector3D(vec2);


                var M = new Acad.Vector3d(norm.X, norm.Y, norm.Z + offset);

                cenpointp3d = FindTriangleCenter(v1, v2, v3, vec1.CrossProduct(vec2));

                centerv1 = new Acad.Vector3d(cenpointp3d.X + v1.X, cenpointp3d.Y + v1.Y, cenpointp3d.Z + v1.Z) / 2.0;
                centerv2 = new Acad.Vector3d(cenpointp3d.X + v2.X, cenpointp3d.Y + v2.Y, cenpointp3d.Z + v2.Z) / 2.0;
                centerv3 = new Acad.Vector3d(cenpointp3d.X + v3.X, cenpointp3d.Y + v3.Y, cenpointp3d.Z + v3.Z) / 2.0;

                var offsetcenterv1 = (centerv1.Add(M));
                var offsetcenterv2 = (centerv2.Add(M));
                var offsetcenterv3 = (centerv3.Add(M));

                var p1 = new Acad.Point3d(offsetcenterv1.X, offsetcenterv1.Y, offsetcenterv1.Z);
                var p2 = new Acad.Point3d(offsetcenterv2.X, offsetcenterv2.Y, offsetcenterv2.Z);
                var p3 = new Acad.Point3d(offsetcenterv3.X, offsetcenterv3.Y, offsetcenterv3.Z);


                points.Add(p1);
                points.Add(p2);
                points.Add(p3);
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine("Error: " + ex.Message);
            }

            return(points);
        }
Пример #24
0
        private Node FindNode(AcadGeo.Point3d pnt)
        {
            List <Node> nodes = routers.Vertices.ToList <Node>();

            foreach (Node node in nodes)
            {
                if (pnt.Equals(node.Position))
                {
                    return(node);
                }
            }
            return(null);
        }
Пример #25
0
        public List <AcadDB.Entity> Draw()
        {
            AcadGeo.Line3d xline = new AcadGeo.Line3d(position, AcadGeo.Vector3d.XAxis);

            List <AcadDB.Entity> ents = new List <AcadDB.Entity>();

            AcadGeo.Point3d pnt = new AcadGeo.Point3d(position.X, position.Y, position.Z);
            foreach (var sp in steel_pos)
            {
                AcadGeo.Line3d    steel_line       = new AcadGeo.Line3d(sp, new AcadGeo.Vector3d(Math.Sin(angle), Math.Cos(angle), 0.0));
                AcadGeo.Point3d[] intersected_pnts = xline.IntersectWith(steel_line);

                if (intersected_pnts.Length > 0)
                {
                    ents.Add(new AcadDB.Line(intersected_pnts[0], sp));
                    if (intersected_pnts[0].DistanceTo(position) > pnt.DistanceTo(position))
                    {
                        pnt = intersected_pnts[0];
                    }
                }
            }

            ents.Add(new AcadDB.Line(position, pnt));

            ents.Add(new AcadDB.Circle(position - AcadGeo.Vector3d.XAxis * cir_radius, AcadGeo.Vector3d.ZAxis, cir_radius));

            //draw value
            {
                AcadDB.DBText text = new AcadDB.DBText();
                text.TextString     = number.ToString();
                text.Justify        = AcadDB.AttachmentPoint.MiddleCenter;
                text.Height         = text_height;
                text.WidthFactor    = text_w_factor;
                text.AlignmentPoint = position - AcadGeo.Vector3d.XAxis * cir_radius;
                ents.Add(text);
            }

            //draw content
            {
                AcadDB.DBText text = new AcadDB.DBText();
                text.TextString     = content;
                text.Justify        = AcadDB.AttachmentPoint.BottomLeft;
                text.Height         = text_height;
                text.WidthFactor    = text_w_factor;
                text.AlignmentPoint = position + AcadGeo.Vector3d.XAxis * 10.0 + AcadGeo.Vector3d.YAxis * 10.0;
                ents.Add(text);
            }

            return(ents);
        }
Пример #26
0
        public List <AcadDB.Entity> Draw()
        {
            List <AcadDB.Entity> ents = new List <AcadDB.Entity>();

            if (0 == steel_pos.Count)
            {
                return(ents);
            }

            AcadGeo.Point3d tmp_line = steel_pos[0];
            foreach (var sp in steel_pos)
            {
                AcadDB.Line line = new AcadDB.Line();
                line.StartPoint = sp + length_line * AcadGeo.Vector3d.XAxis + length_line * AcadGeo.Vector3d.YAxis;
                line.EndPoint   = sp - length_line * AcadGeo.Vector3d.XAxis - length_line * AcadGeo.Vector3d.YAxis;
                ents.Add(line);

                if (position.DistanceTo(sp) > position.DistanceTo(tmp_line))
                {
                    tmp_line = sp;
                }
            }
            ents.Add(new AcadDB.Line(position, tmp_line));

            ents.Add(new AcadDB.Circle(position - AcadGeo.Vector3d.XAxis * cir_radius, AcadGeo.Vector3d.ZAxis, cir_radius));

            //Draw number
            {
                AcadDB.DBText text = new AcadDB.DBText();
                text.TextString     = number.ToString();
                text.Justify        = AcadDB.AttachmentPoint.MiddleCenter;
                text.Height         = text_height;
                text.WidthFactor    = text_w_factor;
                text.AlignmentPoint = position - AcadGeo.Vector3d.XAxis * cir_radius;
                ents.Add(text);
            }

            //draw content
            {
                AcadDB.DBText text = new AcadDB.DBText();
                text.TextString     = content;
                text.Justify        = AcadDB.AttachmentPoint.BottomLeft;
                text.Height         = text_height;
                text.WidthFactor    = text_w_factor;
                text.AlignmentPoint = position + AcadGeo.Vector3d.XAxis * 10.0 + AcadGeo.Vector3d.YAxis * 10.0;
                ents.Add(text);
            }

            return(ents);
        }
Пример #27
0
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            switch (mCurJigFactorIndex)
            {
            case 1:
                JigPromptPointOptions prOptions1 = new JigPromptPointOptions("\nBase point::");
                // Set properties such as UseBasePoint and BasePoint of the prompt options object if necessary here.
                prOptions1.UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.GovernedByUCSDetect;
                PromptPointResult prResult1 = prompts.AcquirePoint(prOptions1);
                if (prResult1.Status == PromptStatus.Cancel && prResult1.Status == PromptStatus.Error)
                {
                    return(SamplerStatus.Cancel);
                }

                if (prResult1.Value.Equals(mBasePoint))      //Use better comparison method if necessary.
                {
                    return(SamplerStatus.NoChange);
                }
                else
                {
                    mBasePoint = prResult1.Value;
                    return(SamplerStatus.OK);
                }

            case 2:
                JigPromptPointOptions prOptions2 = new JigPromptPointOptions("\nSecond point:");
                // Set properties such as UseBasePoint and BasePoint of the prompt options object if necessary here.
                prOptions2.UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.GovernedByUCSDetect;
                PromptPointResult prResult2 = prompts.AcquirePoint(prOptions2);
                if (prResult2.Status == PromptStatus.Cancel && prResult2.Status == PromptStatus.Error)
                {
                    return(SamplerStatus.Cancel);
                }

                if (prResult2.Value.Equals(mSecondPoint) || prResult2.Value.Equals(mBasePoint))
                {
                    return(SamplerStatus.NoChange);
                }
                else
                {
                    mSecondPoint = prResult2.Value;
                    return(SamplerStatus.OK);
                }

            default:
                break;
            }

            return(SamplerStatus.OK);
        }
Пример #28
0
        public List <AcadGeo.Point3d> QuerySteelPos()
        {
            AcadGeo.Point3d        ins_pnt   = start_point;
            List <AcadGeo.Point3d> steel_pos = new List <AcadGeo.Point3d>();
            double spacing = GetSpacing();

            for (int i = 0; i < number_steel; i++)
            {
                steel_pos.Add(ins_pnt);
                ins_pnt = ins_pnt + AcadGeo.Vector3d.XAxis * spacing;
            }

            return(steel_pos);
        }
Пример #29
0
        public List <AcadDB.Entity> DrawShapeA(AcadGeo.Point3d ins_pnt)
        {
            if (width < 2 * corner_rad || height < 2 * corner_rad)
            {
                throw new Autodesk.AutoCAD.Runtime.Exception(Autodesk.AutoCAD.Runtime.ErrorStatus.OK, "Failed");
            }

            List <AcadDB.Entity> ents = new List <AcadDB.Entity>();

            int inner_w = width - 2 * corner_rad;
            int inner_h = height - 2 * corner_rad;

            AcadGeo.Point3d up_ins_pnt = ins_pnt + AcadGeo.Vector3d.YAxis * 0.5 * height;
            ents.Add(new AcadDB.Line(up_ins_pnt + AcadGeo.Vector3d.XAxis * 0.5 * inner_w,
                                     up_ins_pnt - AcadGeo.Vector3d.XAxis * 0.5 * inner_w));

            AcadGeo.Point3d down_ins_pnt = ins_pnt - AcadGeo.Vector3d.YAxis * 0.5 * height;
            ents.Add(new AcadDB.Line(down_ins_pnt + AcadGeo.Vector3d.XAxis * 0.5 * inner_w,
                                     down_ins_pnt - AcadGeo.Vector3d.XAxis * 0.5 * inner_w));

            AcadGeo.Point3d right_ins_pnt = ins_pnt + AcadGeo.Vector3d.XAxis * 0.5 * width;
            ents.Add(new AcadDB.Line(right_ins_pnt + AcadGeo.Vector3d.YAxis * 0.5 * inner_h,
                                     right_ins_pnt - AcadGeo.Vector3d.YAxis * 0.5 * inner_h));

            AcadGeo.Point3d left_ins_pnt = ins_pnt - AcadGeo.Vector3d.XAxis * 0.5 * width;
            ents.Add(new AcadDB.Line(left_ins_pnt + AcadGeo.Vector3d.YAxis * 0.5 * inner_h,
                                     left_ins_pnt - AcadGeo.Vector3d.YAxis * 0.5 * inner_h));

            AcadGeo.Point3d corner_pnt1 = ins_pnt +
                                          AcadGeo.Vector3d.XAxis * (width * 0.5 - corner_rad) +
                                          AcadGeo.Vector3d.YAxis * (height * 0.5 - corner_rad);
            ents.Add(new AcadDB.Arc(corner_pnt1, AcadGeo.Vector3d.ZAxis, corner_rad, 0.0, PI * 0.5));

            AcadGeo.Point3d corner_pnt2 = ins_pnt -
                                          AcadGeo.Vector3d.XAxis * (width * 0.5 - corner_rad) +
                                          AcadGeo.Vector3d.YAxis * (height * 0.5 - corner_rad);
            ents.Add(new AcadDB.Arc(corner_pnt2, AcadGeo.Vector3d.ZAxis, corner_rad, PI * 0.5, PI));

            AcadGeo.Point3d corner_pnt3 = ins_pnt -
                                          AcadGeo.Vector3d.XAxis * (width * 0.5 - corner_rad) -
                                          AcadGeo.Vector3d.YAxis * (height * 0.5 - corner_rad);
            ents.Add(new AcadDB.Arc(corner_pnt3, AcadGeo.Vector3d.ZAxis, corner_rad, PI, PI * 1.5));

            AcadGeo.Point3d corner_pnt4 = ins_pnt +
                                          AcadGeo.Vector3d.XAxis * (width * 0.5 - corner_rad) -
                                          AcadGeo.Vector3d.YAxis * (height * 0.5 - corner_rad);
            ents.Add(new AcadDB.Arc(corner_pnt4, AcadGeo.Vector3d.ZAxis, corner_rad, PI * 1.5, PI * 2.0));

            return(ents);
        }
Пример #30
0
        public void BuildProfile()
        {
            //double width = 0.0;
            if (!AcadFuncs.GetDouble(ref width, "Nhập chiều rộng:"))
            {
                throw new Exception("Cancel process");
            }

            //double height = 0.0;
            if (!AcadFuncs.GetDouble(ref height, "Nhập chiều cao:"))
            {
                throw new Exception("Cancel process");
            }

            if (!AcadFuncs.GetDouble(ref thickness, "Nhập độ dày:"))
            {
                throw new Exception("Cancel process");
            }

            //AcadGeo.Point3d bp = new AcadGeo.Point3d();
            //while (true)
            //{
            //	if (!AcadFuncs.GetPoint(ref bp, "Chọn điểm bắt đầu:"))
            //		throw new Exception("Cancel process");

            //	if (null != FindNode(bp))
            //		break;
            //}

            //AcadGeo.Point3d vp = new AcadGeo.Point3d();
            //if (!AcadFuncs.GetPoint(ref vp, "Chọn hướng:", bp))
            //	throw new Exception("Cancel process");

            //AcadGeo.Point3d up = new AcadGeo.Point3d();
            //if (!AcadFuncs.GetPoint(ref up, "Chọn up:", bp))
            //	throw new Exception("Cancel process");

            AcadGeo.Point3d  bp     = new AcadGeo.Point3d();
            AcadGeo.Vector3d up_vec = new AcadGeo.Vector3d();
            AcadGeo.Vector3d norm   = new AcadGeo.Vector3d();
            AutoDetectParams(ref bp, ref up_vec, ref norm);

            profile.Width        = width;
            profile.Height       = height;
            profile.Thickness    = thickness;
            profile.BasePoint    = bp;
            profile.NormalVector = norm;
            profile.UpVector     = up_vec;
        }
        private void createImages(jsonAttribute eachatt, Transaction tr, ObjectId lyid)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor; 

            //produce the bitmap of the signature from base64 string
            string imgPath = "temp.png";
            try
            {
                //remove the header of the base64
                var base64str = eachatt.imgbase64.Replace("data:image/png;base64,", "");
                byte[] arr = Convert.FromBase64String(base64str);
                using (MemoryStream ms = new MemoryStream(arr))
                {
                    System.Drawing.Image streamImage = System.Drawing.Image.FromStream(ms);

                    streamImage.Save(imgPath, ImageFormat.Png);
                    
                } 

            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\nBase64StringToImage failed :" + ex.Message);
                return;
            }


            try
            {
                //get block table and model space
                Database db = HostApplicationServices.WorkingDatabase;
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord msBtr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                //get the position of this attribute
                string[] split = eachatt.position.Split(new Char[] { ',' });
                double posX = Convert.ToDouble(split[0]);
                double posY = Convert.ToDouble(split[1]);
                double posZ = Convert.ToDouble(split[2]);

                //get the range of this attribute
                double fieldheight = Convert.ToDouble(eachatt.height);
                double fieldwidth = Convert.ToDouble(eachatt.width_ratio) * fieldheight;
                double field_center_x = posX + fieldwidth / 2;
                double field_center_y = posY + fieldheight / 2;

                //read the signature image
                
                System.Drawing.Bitmap operateimage = new System.Drawing.Bitmap(imgPath); 
                
                System.Drawing.Color c;

                double maxX = 0, minX = operateimage.Width;
                double maxY = 0, minY = operateimage.Height;

                ed.WriteMessage("\nbegin create block def for image");
                ObjectId blkRecId = ObjectId.Null;

                using (BlockTableRecord signatureBlkDef = new BlockTableRecord())
                {
                    System.Guid guid = System.Guid.NewGuid();

                    //block definition name
                    signatureBlkDef.Name = "sigblk" + guid.ToString();
                    ArrayList ptArr = new ArrayList();

                    //each pixel color
                    for (int y = 0; y < operateimage.Height; y++)
                        for (int x = 0; x < operateimage.Width; x++)
                        {
                            c = operateimage.GetPixel(x, y);

                            if (c.R == 0 && c.G == 0 && c.B == 0 && c.A == 255)
                            {
                                Autodesk.AutoCAD.Geometry.Point3d pt = new Autodesk.AutoCAD.Geometry.Point3d(x, operateimage.Height - y, 0);

                                minY = y < minY ? y : minY;
                                maxY = y > maxY ? y : maxY;

                                minX = x < minX ? x : minX;
                                maxX = x > maxX ? x : maxX;

                                var sol =
                               new Solid(
                                 new Point3d(pt.X, pt.Y, 0),
                                 new Point3d(pt.X + 1, pt.Y, 0),
                                 new Point3d(pt.X, pt.Y + 1, 0),
                                 new Point3d(pt.X + 1, pt.Y + 1, 0)
                               );

                                //set the solid to the specific layer
                                sol.LayerId = lyid;
                                signatureBlkDef.AppendEntity(sol);
                            }
                        }

                    ed.WriteMessage("\ncreate and add block def");

                    signatureBlkDef.Origin = new Point3d((maxX + minX) / 2, operateimage.Height - (maxY + minY) / 2, 0);
                    bt.Add(signatureBlkDef);
                    tr.AddNewlyCreatedDBObject(signatureBlkDef, true);

                    //set the block definition to the specific layer
                    blkRecId = signatureBlkDef.Id;

                    ed.WriteMessage("\nend creating block def");
                }

                operateimage.Dispose();
                //scale the signature to fit the field along X, Y

                double blkscaleY = fieldheight / (maxY - minY) * 2;
                double blkscaleX = (maxX - minX) / (maxY - minY) * blkscaleY;

                ed.WriteMessage("\nto begin create block ref");

                using (BlockReference acBlkRef = new BlockReference(new Point3d(field_center_x, field_center_y, 0), blkRecId))
                {
                    acBlkRef.ScaleFactors = new Scale3d(blkscaleY, blkscaleY, 1);
                    acBlkRef.LayerId = lyid;
                    msBtr.AppendEntity(acBlkRef);
                    tr.AddNewlyCreatedDBObject(acBlkRef, true);
                }

                ed.WriteMessage("\nend of creating block ref");
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex){
                ed.WriteMessage("\nfailed to produce the image: " + ex.ToString());
            }

        }
Пример #32
0
        /// <summary>
        /// insert signatures
        /// </summary>
        /// <param name="dwgPath">Signature drawings' path</param>
        /// <param name="dwgNameList">Signature drawing list</param>
        public void InsertSign(string dwgPath, List<string> dwgNameList)
        {
            AdeskAppSvr.Document doc = AdeskAppSvr.Application.DocumentManager.MdiActiveDocument;
            AdeskDBSvr.Database CurrDB = doc.Database;
            AdeskEdIn.Editor ed = doc.Editor;
            AdeskEdIn.PromptPointResult prPointRes_Base = ed.GetPoint(new AdeskEdIn.PromptPointOptions("ѡ�����Ļ���"));
            AdeskEdIn.PromptPointResult prPointRes_opp = ed.GetPoint(new AdeskEdIn.PromptPointOptions("ѡ�����ĶԽǵ�"));
            //In order to make the signs look nicely , calculate the base point and its opposite point
            AdeskGeo.Point3d P_base = CalPoint(prPointRes_Base.Value, prPointRes_opp.Value, 0.1);
            AdeskGeo.Point3d P_opp = CalPoint(prPointRes_Base.Value, prPointRes_opp.Value, 0.9);
            //sign's width and height
            double SignWidth = P_opp.X - P_base.X;
            double SignHeight = P_opp.Y - P_base.Y;
            //distance between each other
            double distanceW = prPointRes_opp.Value.X - prPointRes_Base.Value.X;
            double distanceH = prPointRes_opp.Value.Y - prPointRes_Base.Value.Y;

            //current date
            string date = System.DateTime.Today.ToLocalTime().ToString().Split(' ')[0];

            try
            {
                for (int i = 0; i < dwgNameList.Count; i++)
                {
                    using (AdeskDBSvr.Database tmpdb = new AdeskDBSvr.Database(false, false))
                    {
                        //read drawing
                        tmpdb.ReadDwgFile(dwgPath + dwgNameList[i], FileShare.Read, true, null);
                        //insert Signature drawing as a new block into current drawing
                        AdeskDBSvr.ObjectId idBTR = CurrDB.Insert(this.ICCardList[i], tmpdb, false);
                        //scale of signature. 36 is the width of sign, and 17 is the height. you should adjust them in your condition.
                        double WidthOfSign;
                        double HeightOfSign;
                        double scaleWidth = SignWidth / 36;
                        double scaleHeight = SignHeight / 17;
                        using (AdeskDBSvr.Transaction trans = CurrDB.TransactionManager.StartTransaction())
                        {
                            AdeskDBSvr.BlockTable bt = (AdeskDBSvr.BlockTable)trans.GetObject(CurrDB.BlockTableId, AdeskDBSvr.OpenMode.ForRead);
                            AdeskDBSvr.BlockTableRecord btr = (AdeskDBSvr.BlockTableRecord)trans.GetObject(bt[AdeskDBSvr.BlockTableRecord.ModelSpace], AdeskDBSvr.OpenMode.ForWrite);

                            AdeskDBSvr.BlockTableRecord InBtr = (AdeskDBSvr.BlockTableRecord)trans.GetObject(idBTR, AdeskDBSvr.OpenMode.ForRead);
                            foreach (AdeskDBSvr.ObjectId tmpid in InBtr)
                            {
                                AdeskDBSvr.DBObject dbo = trans.GetObject(tmpid, AdeskDBSvr.OpenMode.ForRead);
                                if (dbo is AdeskDBSvr.Ole2Frame)
                                {
                                    AdeskDBSvr.Ole2Frame mOle = (AdeskDBSvr.Ole2Frame)dbo;
                                    WidthOfSign = mOle.WcsWidth;
                                    HeightOfSign = mOle.WcsHeight;
                                    scaleWidth = SignWidth / WidthOfSign;
                                    scaleHeight = SignHeight / HeightOfSign;
                                    break;
                                }
                            }

                            //insert point of each signature and date from top to bottom
                            AdeskGeo.Point3d inPt = new AdeskGeo.Point3d(P_base.X, P_base.Y - i * distanceH, P_base.Z);

                            #region signature date
                            //signature date
                            AdeskDBSvr.MText SignDate = new AdeskDBSvr.MText();
                            AdeskDBSvr.TextStyleTable TextStyleTB = (AdeskDBSvr.TextStyleTable)trans.GetObject(CurrDB.TextStyleTableId, AdeskDBSvr.OpenMode.ForWrite);
                            AdeskDBSvr.TextStyleTableRecord TextStyleTBRec = new AdeskDBSvr.TextStyleTableRecord();

                            TextStyleTBRec.Font = new AdeskGra.FontDescriptor("����", true, false, 0, 0);
                            TextStyleTB.Add(TextStyleTBRec);
                            trans.AddNewlyCreatedDBObject(TextStyleTBRec, true);
                            SignDate.TextStyle = TextStyleTBRec.Id;
                            SignDate.Contents = date;
                            SignDate.TextHeight = SignHeight / 2;
                            SignDate.Width = SignWidth / 3;
                            //date's location should fit the frame
                            SignDate.Location = new AdeskGeo.Point3d((inPt.X + distanceW), (inPt.Y + 1.5 * SignDate.TextHeight), inPt.Z);
                            btr.AppendEntity(SignDate);
                            trans.AddNewlyCreatedDBObject(SignDate, true);
                            #endregion

                            try
                            {
                                //create a ref to the block
                                using (AdeskDBSvr.BlockReference bref = new AdeskDBSvr.BlockReference(inPt, idBTR))
                                {
                                    bref.ScaleFactors = new AdeskGeo.Scale3d(scaleWidth, scaleHeight, 1.0);
                                    btr.AppendEntity(bref);
                                    trans.AddNewlyCreatedDBObject(bref, true);
                                }
                                trans.Commit();
                            }
                            catch (System.Exception err)
                            {
                                MessageBox.Show("one: " + err.Message);
                            }
                        }
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception err)
            {
                MessageBox.Show("insert: " + err.Message);
            }
        }