예제 #1
0
파일: Class2.cs 프로젝트: daqi5258/CKX2014
 protected override bool Update()
 {
     try
     {
         //_sol.ExtrudeAlongPath(_reg, new Line(_pt, new Point3d(_pt.X, _endPt.Y + 20, _pt.Z))  , 0);
         //_sol.Extrude(_reg, _dist, 0);
         _sol.CreateExtrudedSolid(_reg, _pt.GetVectorTo(_endPt), _swpOpts);
     }
     catch (System.Exception ex)
     {
         return(false);
     }
     return(true);
 }
        public static ObjectId CreateExtrusion(Point2d[] pts, Point3d destPt, Vector3d normal, WoodGrainAlignment grain)
        {
            ObjectId entId = ObjectId.Null;

            Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database db = activeDoc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                BlockTableRecord btr = null;
                if (String.IsNullOrEmpty(blockName))
                    btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                else
                {
                    if (bt.Has(blockName))
                        btr = tr.GetObject(bt[blockName], OpenMode.ForWrite) as BlockTableRecord;
                    else
                    {
                        btr = new BlockTableRecord();
                        btr.Name = blockName;
                        bt.UpgradeOpen();
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                    }
                }

                Solid3d extrudedSolid = new Solid3d();
                using (Autodesk.AutoCAD.DatabaseServices.Polyline outline = new Autodesk.AutoCAD.DatabaseServices.Polyline())
                {
                    outline.SetDatabaseDefaults();
                    outline.Normal = normal;

                    int cnt = 0;
                    foreach (Point2d pt in pts)
                    {
                        outline.AddVertexAt(cnt, pt, 0, 0, 0);
                        cnt++;
                    }
                    outline.Closed = true;

                    Extents3d exts = outline.GeometricExtents;
                    Point3d minPt = exts.MinPoint;
                    Point3d maxPt = exts.MaxPoint;

                    double p1 = maxPt.X - minPt.X;
                    double p2 = maxPt.Y - minPt.Y;
                    double p3 = maxPt.Z - minPt.Z;

                    double pmin = 0.0;
                    if (p1 == 0)
                    {
                        pmin = Math.Min(p2, p3);
                    }
                    if (p2 == 0)
                    {
                        pmin = Math.Min(p1, p3);
                    }
                    if (p3 == 0)
                    {
                        pmin = Math.Min(p1, p2);
                    }
                    double pmax = Math.Max(Math.Max(p1, p2), p3);

                    extrudedSolid.RecordHistory = true;

                    plyIndex++;

                    Vector3d heightVector = outline.Normal * t;

                    SweepOptions sweepOptions = new SweepOptions();

                    SweepOptionsBuilder builder = new SweepOptionsBuilder(sweepOptions);

                    extrudedSolid.CreateExtrudedSolid(outline, heightVector, sweepOptions);
                }

                entId = btr.AppendEntity(extrudedSolid);
                tr.AddNewlyCreatedDBObject(extrudedSolid, true);

                extrudedSolid.TransformBy(Matrix3d.Displacement(destPt.GetAsVector()));

                tr.Commit();
            }

            return entId;
        }
예제 #3
0
        public static ObjectId CreateExtrusion(Point2d[] pts, Point3d destPt, Vector3d normal, WoodGrainAlignment grain)
        {
            ObjectId entId = ObjectId.Null;

            Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database db        = activeDoc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                BlockTableRecord btr = null;
                if (String.IsNullOrEmpty(blockName))
                {
                    btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                }
                else
                {
                    if (bt.Has(blockName))
                    {
                        btr = tr.GetObject(bt[blockName], OpenMode.ForWrite) as BlockTableRecord;
                    }
                    else
                    {
                        btr      = new BlockTableRecord();
                        btr.Name = blockName;
                        bt.UpgradeOpen();
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                    }
                }

                Solid3d extrudedSolid = new Solid3d();
                using (Autodesk.AutoCAD.DatabaseServices.Polyline outline = new Autodesk.AutoCAD.DatabaseServices.Polyline())
                {
                    outline.SetDatabaseDefaults();
                    outline.Normal = normal;

                    int cnt = 0;
                    foreach (Point2d pt in pts)
                    {
                        outline.AddVertexAt(cnt, pt, 0, 0, 0);
                        cnt++;
                    }
                    outline.Closed = true;

                    Extents3d exts  = outline.GeometricExtents;
                    Point3d   minPt = exts.MinPoint;
                    Point3d   maxPt = exts.MaxPoint;

                    double p1 = maxPt.X - minPt.X;
                    double p2 = maxPt.Y - minPt.Y;
                    double p3 = maxPt.Z - minPt.Z;

                    double pmin = 0.0;
                    if (p1 == 0)
                    {
                        pmin = Math.Min(p2, p3);
                    }
                    if (p2 == 0)
                    {
                        pmin = Math.Min(p1, p3);
                    }
                    if (p3 == 0)
                    {
                        pmin = Math.Min(p1, p2);
                    }
                    double pmax = Math.Max(Math.Max(p1, p2), p3);

                    extrudedSolid.RecordHistory = true;

                    plyIndex++;

                    Vector3d heightVector = outline.Normal * t;

                    SweepOptions sweepOptions = new SweepOptions();

                    SweepOptionsBuilder builder = new SweepOptionsBuilder(sweepOptions);

                    extrudedSolid.CreateExtrudedSolid(outline, heightVector, sweepOptions);
                }

                entId = btr.AppendEntity(extrudedSolid);
                tr.AddNewlyCreatedDBObject(extrudedSolid, true);

                extrudedSolid.TransformBy(Matrix3d.Displacement(destPt.GetAsVector()));

                tr.Commit();
            }

            return(entId);
        }
예제 #4
0
        private ObjectId TrimPickUP(int nodeNumer, int TriangleNumer, double X, double angle)
        {
            //UtilityClasses.ConstantsAndSettings.DoubleGlass_h1
            //UtilityClasses.ConstantsAndSettings.DoubleGlass_h2
            //UtilityClasses.ConstantsAndSettings.Thickness_of_the_Glass
            #region basedata
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("\n");
            ed.WriteMessage(angle.ToString());

            var        node     = container.Nodes[nodeNumer];
            Triangle   TR       = container.Triangles[TriangleNumer];
            quaternion trNormal = TR.Normal.Second - TR.Normal.First;
            trNormal /= trNormal.abs();
            plane trPlane = new plane(TR.Nodes.First, TR.Nodes.Second, TR.Nodes.Third);


            Point3dCollection pColl = new Point3dCollection();
            IntegerCollection iCol1 = new IntegerCollection();
            IntegerCollection iCol2 = new IntegerCollection();



            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                if ((TR.upSolidHandle.First >= 0) && (TR.upSolidHandle.Second != null))
                {
                    try
                    {
                        Solid3d upSolid = tr.GetObject(GlobalFunctions.GetObjectId(TR.upSolidHandle.Second), OpenMode.ForWrite) as Solid3d;
                        upSolid.GetGripPoints(pColl, iCol1, iCol2);
                    }
                    catch { }
                }
            }


            Bend bend1 = container.Bends[TR.GetFirstBendNumer()];
            Bend bend2 = container.Bends[TR.GetSecondBendNumer()];
            Bend bend3 = container.Bends[TR.GetThirdBendNumer()];
            #endregion

            List <Bend> bends = new List <Bend>();
            if ((bend1.StartNodeNumer == nodeNumer) || (bend1.EndNodeNumer == nodeNumer))
            {
                bends.Add(bend1);
            }
            if ((bend2.StartNodeNumer == nodeNumer) || (bend2.EndNodeNumer == nodeNumer))
            {
                bends.Add(bend2);
            }
            if ((bend3.StartNodeNumer == nodeNumer) || (bend3.EndNodeNumer == nodeNumer))
            {
                bends.Add(bend3);
            }

            if (bends.Count != 2)
            {
                MessageBox.Show("Only two Bends are connected at one point !", "E R R O R");
                return(ObjectId.Null);
            }

            if (bends[0].IsFictive() || bends[1].IsFictive())
            {
                return(ObjectId.Null);
            }

            quaternion Q0 = node.Position;
            quaternion Q1 = (bends[0].Start + bends[0].End) / 2.0;
            quaternion Q2 = (bends[1].Start + bends[1].End) / 2.0;

            // coorinat systems for plane points calculate
            Q1 = Q1 - Q0; Q1 /= Q1.abs(); Q1 *= X; Q1 = Q0 + Q1;
            Q2 = Q2 - Q0; Q2 /= Q2.abs(); Q2 *= X; Q2 = Q0 + Q2;

            UCS ucs = new UCS(Q0, (Q1 + Q2) / 2.0, Q2);
            ucs = new UCS(Q0, ucs.ToACS(new quaternion(0, 0, 100, 0)), ucs.ToACS(new quaternion(0, 100, 0, 0)));

            #region UP glass

            double     dist = (node.Position - (quaternion)pColl[0]).abs();
            quaternion pick = new quaternion();

            foreach (Point3d p in pColl)
            {
                quaternion q = (quaternion)p;
                double     z = (node.Position - q).abs();

                if (z < dist)
                {
                    dist = z;
                    pick = new quaternion(0, p.X, p.Y, p.Z);
                }
            }
            pColl.Clear(); pColl.Dispose();
            iCol1.Clear();
            iCol1.Clear();
            #endregion


            ucs.o = pick;
            Q1    = pick + Q1 - Q0;
            Q2    = pick + Q2 - Q0;
            Q0    = pick;

            // UtilityClasses.GlobalFunctions.DrawLine((Point3d)Q0, new Point3d(), 1);

            quaternion t1 = (Q2 - Q1) * 2.0;
            quaternion t2 = (Q1 - Q2) * 2.0;
            Q1 = Q1 + t2;
            Q2 = Q2 + t1;

            Matrix3d mat = new Matrix3d(ucs.GetAutoCAD_Matrix3d());
            Q1 = ucs.FromACS(Q1);
            Q2 = ucs.FromACS(Q2);
            quaternion   Q3  = new quaternion(0, Q1.GetX(), -Q1.GetY(), Q1.GetZ());
            quaternion   Q4  = new quaternion(0, Q2.GetX(), -Q2.GetY(), Q2.GetZ());
            quaternion[] arr = { Q1, Q2, Q4, Q3, Q1 };
            ObjectId     obj = ObjectId.Null;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable       acBlkTbl    = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Polyline pol = GlobalFunctions.GetPoly(ref arr);
                //pol.TransformBy(Matrix3d.Displacement(new Point3d().GetVectorTo(new Point3d(0, 0, -100))));
                //pol.TransformBy(mat);

                //acBlkTblRec.AppendEntity(pol);
                //tr.AddNewlyCreatedDBObject(pol, true);

                try
                {
                    Solid3d sol = new Solid3d();
                    sol.CreateExtrudedSolid(pol, new Point3d(0, 0, 0).GetVectorTo(new Point3d(0, 0, 100)), new SweepOptions());
                    sol.TransformBy(Matrix3d.Displacement(new Point3d().GetVectorTo(new Point3d(0, 0, -50))));
                    sol.TransformBy(mat);
                    acBlkTblRec.AppendEntity(sol);
                    tr.AddNewlyCreatedDBObject(sol, true);
                    obj = sol.ObjectId;
                }
                catch { }

                tr.Commit();
            }

            /*
             * if (obj != ObjectId.Null)
             * {
             *  using (Transaction tr = db.TransactionManager.StartTransaction())
             *  {
             *
             *      Solid3d sol = tr.GetObject(obj, OpenMode.ForWrite) as Solid3d;
             *      Solid3d ent = tr.GetObject(UtilityClasses.GlobalFunctions.GetObjectId(TR.lowSolidHandle.Second), OpenMode.ForWrite) as Solid3d;
             *      ent.BooleanOperation(BooleanOperationType.BoolSubtract, sol);
             *
             *      tr.Commit();
             *  }
             * }*/



            // ed.WriteMessage("\n");
            // ed.WriteMessage(ucs.FromACS(Q0).ToString());
            // ed.WriteMessage("\n-----------------------------\n");

            return(obj);
        }