Beispiel #1
0
        public void CNC_bends(StreamWriter outf, WorkClasses.Node node, double L, double Lp, double Ls, double R, double toolR, double gabaritX, double gabaritY, double gabaritZ)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            quaternion tempNodeNormal = node.GetNodesNormalsByNoFictiveBends(ref container);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable acBlkTbl;
                acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                UCS ucs = node.CreateNodeUCS(L, ref container);
                UCS Ucs = node.CreateNodeUCS(L + Lp + Ls, ref container);

                int counter = 0;
                for (int i = 0; i < node.Bends_Numers_Array.Count; i++)
                {
                    WorkClasses.Bend b = container.Bends[node.Bends_Numers_Array[i]];
                    if (b.IsFictive())
                    {
                        continue;
                    }
                    outf.WriteLine(String.Format("(BAR {0} - PRYT NOMER {1})", counter + 1, b.Numer + 1));
                    outf.WriteLine();

                    //---------------------
                    quaternion bendNormal    = b.Normal - b.MidPoint;
                    plane      gabaritTOP    = new plane(ucs.ToACS(new quaternion(0, 10, 0, gabaritZ / 2.0)), ucs.ToACS(new quaternion(0, 100, 0, gabaritZ / 2.0)), ucs.ToACS(new quaternion(0, 0, 10, gabaritZ / 2.0)));
                    plane      gabaritBottom = new plane(ucs.ToACS(new quaternion(0, 10, 0, -gabaritZ / 2.0)), ucs.ToACS(new quaternion(0, 100, 0, -gabaritZ / 2.0)), ucs.ToACS(new quaternion(0, 0, 10, -gabaritZ / 2.0)));
                    quaternion Q1            = gabaritTOP.IntersectWithVector((b.MidPoint + b.Start) / 2.0, (b.MidPoint + b.Start) / 2.0 + bendNormal);
                    quaternion Q2            = gabaritTOP.IntersectWithVector(b.MidPoint, b.Normal);
                    Q1 = ucs.FromACS(Q1);
                    Q2 = ucs.FromACS(Q2);
                    complex cQ1     = new complex(Q1.GetX(), Q1.GetY());
                    complex cQ2     = new complex(Q2.GetX(), Q2.GetY());
                    matrix  Int_Mat = Common.IntersectCircleAndLine(R, cQ1, cQ2);
                    if (Int_Mat.GetAt(0, 4) < 0) /*ERRROR*/ return {
                        ;
                    }
                    complex    iP1       = new complex(Int_Mat.GetAt(0, 0), Int_Mat.GetAt(0, 1));
                    complex    iP2       = new complex(Int_Mat.GetAt(0, 2), Int_Mat.GetAt(0, 3));
                    complex    iP        = ((cQ2 - iP1).abs() < (cQ2 - iP2).abs()) ? iP1 : iP2;
                    quaternion iQ        = ucs.ToACS(new quaternion(0.0, iP.real(), iP.imag(), gabaritZ / 2.0));
                    quaternion cenTOP    = iQ;// gabaritTOP.IntersectWithVector(iQ, iQ + bendNormal);
                    quaternion cenBottom = gabaritBottom.IntersectWithVector(iQ, iQ + bendNormal);
                    Q2 = ucs.ToACS(Q2);
                    quaternion outTOP = Q2 - iQ; quaternion inTOP = iQ - Q2;
                    outTOP /= outTOP.abs(); inTOP /= inTOP.abs();
                    outTOP *= toolR; inTOP *= toolR;
                    outTOP  = iQ + outTOP; inTOP = iQ + inTOP;

                    // MessageBox.Show(String.Format("{0},{1},{2}\n{3},{4},{5}\n{6},{7},{8}",
                    //iQ.GetX(), iQ.GetY(), iQ.GetZ(), cenTOP.GetX(), cenTOP.GetY(), cenTOP.GetZ(), cenBottom.GetX(), cenBottom.GetY(), cenBottom.GetZ()));
                    //--------------------------
                    double     gabaritR   = Math.Sqrt(gabaritX * gabaritX / 4.0 + gabaritY * gabaritY / 4.0);
                    matrix     gabaritMat = Common.IntersectCircleAndLine(gabaritR, cQ1, cQ2);
                    complex    gabaritP1  = new complex(gabaritMat.GetAt(0, 0), gabaritMat.GetAt(0, 1));
                    complex    gabaritP2  = new complex(gabaritMat.GetAt(0, 2), gabaritMat.GetAt(0, 3));
                    complex    gabaritP   = ((cQ2 - gabaritP1).abs() < (cQ2 - gabaritP2).abs()) ? gabaritP1 : gabaritP2;
                    quaternion gabaritQ   = ucs.ToACS(new quaternion(0.0, gabaritP.real(), gabaritP.imag(), gabaritZ / 2.0));
                    //---------------------

                    bool bp = ((node.Position - b.Start).abs() < (node.Position - b.End).abs()) ? true : false;//kой край на реброто е във възела
                    Pair <quaternion, quaternion> bendAxe = (bp == true) ?
                                                            new Pair <quaternion, quaternion>(ucs.FromACS(b.Start), ucs.FromACS(b.End)) :
                                                            new Pair <quaternion, quaternion>(ucs.FromACS(b.End), ucs.FromACS(b.Start));

                    Pair <quaternion, quaternion> pa = new Pair <quaternion, quaternion>(ucs.FromACS(b.MidPoint), ucs.FromACS(b.Normal));
                    quaternion ucsOriginDescriptor   = new quaternion();
                    cenTOP   = ucs.FromACS(cenTOP); cenBottom = ucs.FromACS(cenBottom); inTOP = ucs.FromACS(inTOP); outTOP = ucs.FromACS(outTOP);
                    gabaritQ = ucs.FromACS(gabaritQ);
                    //  double test = Math.Sqrt(cenTOP.GetX() * cenTOP.GetX() + cenTOP.GetY() * cenTOP.GetY());
                    // MessageBox.Show(test.ToString());


                    double baseAng = 0.0;
                    if (((b.Normal - b.MidPoint) / (tempNodeNormal - node.Position)).absV() < Constants.zero_dist)
                    {
                        outf.WriteLine(String.Format("#110={0:f4}(ALPHA-OS C)", 0.0));
                        outf.WriteLine(String.Format("#111 = {0:f4} (BETHA-OS B)", 0.0));
                        outf.WriteLine(String.Format("#112 = {0:f4} (DELTA X-G52 X)", 0.0));
                        outf.WriteLine(String.Format("#113 = {0:f4} (DELTA Z-G52 X)", 0.0));

                        Pair <complex, complex> benAxeXY = new Pair <complex, complex>(
                            new complex(bendAxe.First.GetX(), bendAxe.First.GetY()), new complex(bendAxe.Second.GetX(), bendAxe.Second.GetY()));
                        matrix Int_M    = Common.IntersectCircleAndLine(R, benAxeXY.First, benAxeXY.Second);
                        double baseAng2 = (benAxeXY.Second - benAxeXY.First).arg();
                        if (baseAng2 > Math.PI)
                        {
                            baseAng2 = baseAng2 - 2 * Math.PI;
                        }

                        outf.WriteLine(String.Format("#114 = {0:f4} (GAMMA R-G68)", baseAng2 * 180.0 / Math.PI));

                        outf.WriteLine(String.Format("#115 = {0:f4} (OBRABOTKA NAD Z=0)", gabaritZ / 2.0 + 5.0));
                        outf.WriteLine(String.Format("#116 = {0:f4} (OBRABOTKA POD Z=0)", -gabaritZ / 2.0 - 2.0));
                    }
                    else
                    {
                        quaternion nB1 = ucs.FromACS(b.Normal);
                        quaternion nB2 = ucs.FromACS(b.MidPoint);
                        complex    cN1 = new complex(nB1.GetX(), nB1.GetY());
                        complex    cN2 = new complex(nB2.GetX(), nB2.GetY());
                        line2d     projectTo_ucsXY_Line = new line2d(cN1, cN2);

                        complex normalTo_projectTo_ucsXY_Line = new complex(projectTo_ucsXY_Line.A, projectTo_ucsXY_Line.B);
                        normalTo_projectTo_ucsXY_Line /= normalTo_projectTo_ucsXY_Line.abs();
                        normalTo_projectTo_ucsXY_Line *= -1.0;

                        baseAng = normalTo_projectTo_ucsXY_Line.arg();
                        if (baseAng > Math.PI)
                        {
                            baseAng = baseAng - 2 * Math.PI;
                        }

                        outf.WriteLine(String.Format("#110={0:f4}(ALPHA-OS C)", -((-baseAng + Math.PI / 2.0) * 180.0 / Math.PI)));

                        pa.First.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        pa.Second.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);

                        bendAxe.First.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        bendAxe.Second.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);

                        ucsOriginDescriptor.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);

                        cenTOP.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        cenBottom.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        inTOP.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        outTOP.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);
                        gabaritQ.set_rotateAroundAxe(new quaternion(0, 0, 0, 100.0), -baseAng + Math.PI / 2.0);

                        pa                  = new Pair <quaternion, quaternion>(ucs.ToACS(pa.First), ucs.ToACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(ucs.ToACS(bendAxe.First), ucs.ToACS(bendAxe.Second));
                        ucsOriginDescriptor = ucs.ToACS(ucsOriginDescriptor);
                        cenTOP              = ucs.ToACS(cenTOP); cenBottom = ucs.ToACS(cenBottom); inTOP = ucs.ToACS(inTOP); outTOP = ucs.ToACS(outTOP);
                        gabaritQ            = ucs.ToACS(gabaritQ);

                        pa                  = new Pair <quaternion, quaternion>(Ucs.FromACS(pa.First), Ucs.FromACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(Ucs.FromACS(bendAxe.First), Ucs.FromACS(bendAxe.Second));
                        ucsOriginDescriptor = Ucs.FromACS(ucsOriginDescriptor);
                        cenTOP              = Ucs.FromACS(cenTOP); cenBottom = Ucs.FromACS(cenBottom); inTOP = Ucs.FromACS(inTOP); outTOP = Ucs.FromACS(outTOP);
                        gabaritQ            = Ucs.FromACS(gabaritQ);

                        quaternion normal = (pa.Second - pa.First) * 1000.0;
                        pa = new Pair <quaternion, quaternion>(pa.First, pa.First + normal);
                        double k = (pa.Second.GetX() < pa.First.GetX()) ? 1.0 : -1.0;

                        double ang = (pa.Second - pa.First).angTo(new quaternion(0, 0, 0, 100));
                        ang *= k;
                        outf.WriteLine(String.Format("#111 = {0:f4} (BETHA-OS B)", ang * 180.0 / Math.PI));

                        pa.First.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        pa.Second.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);

                        bendAxe.First.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        bendAxe.Second.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);

                        ucsOriginDescriptor.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);

                        cenTOP.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        cenBottom.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        inTOP.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        outTOP.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);
                        gabaritQ.set_rotateAroundAxe(new quaternion(0, 0, 100.0, 0.0), ang);

                        pa                  = new Pair <quaternion, quaternion>(Ucs.ToACS(pa.First), Ucs.ToACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(Ucs.ToACS(bendAxe.First), Ucs.ToACS(bendAxe.Second));
                        ucsOriginDescriptor = Ucs.ToACS(ucsOriginDescriptor);
                        cenTOP              = Ucs.ToACS(cenTOP); cenBottom = Ucs.ToACS(cenBottom); inTOP = Ucs.ToACS(inTOP); outTOP = Ucs.ToACS(outTOP);
                        gabaritQ            = Ucs.ToACS(gabaritQ);

                        pa                  = new Pair <quaternion, quaternion>(ucs.FromACS(pa.First), ucs.FromACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(ucs.FromACS(bendAxe.First), ucs.FromACS(bendAxe.Second));
                        ucsOriginDescriptor = ucs.FromACS(ucsOriginDescriptor);
                        cenTOP              = ucs.FromACS(cenTOP); cenBottom = ucs.FromACS(cenBottom); inTOP = ucs.FromACS(inTOP); outTOP = ucs.FromACS(outTOP);
                        gabaritQ            = ucs.FromACS(gabaritQ);
                        outf.WriteLine(String.Format("#112 = {0:f4} (DELTA X-G52 X)", ucsOriginDescriptor.GetX()));
                        outf.WriteLine(String.Format("#113 = {0:f4} (DELTA Z-G52 X)", ucsOriginDescriptor.GetZ()));
                        double backX = ucsOriginDescriptor.GetX();
                        double backZ = ucsOriginDescriptor.GetZ();

                        quaternion moveQ = new quaternion(0, -backX, 0.0, -backZ);
                        pa                   = new Pair <quaternion, quaternion>(pa.First + moveQ, pa.Second + moveQ);
                        bendAxe              = new Pair <quaternion, quaternion>(bendAxe.First + moveQ, bendAxe.Second + moveQ);
                        ucsOriginDescriptor += moveQ;
                        cenTOP              += moveQ; cenBottom += moveQ; inTOP += moveQ; outTOP += moveQ;
                        gabaritQ            += moveQ;

                        Pair <complex, complex> benAxeXY = new Pair <complex, complex>(
                            new complex(bendAxe.First.GetX(), bendAxe.First.GetY()), new complex(bendAxe.Second.GetX(), bendAxe.Second.GetY()));
                        matrix Int_M = Common.IntersectCircleAndLine(R, benAxeXY.First, benAxeXY.Second);

                        complex Int_P1   = new complex(Int_M.GetAt(0, 0), Int_M.GetAt(0, 1));
                        complex Int_P2   = new complex(Int_M.GetAt(0, 2), Int_M.GetAt(0, 3));
                        complex Int_P    = ((benAxeXY.Second - Int_P1).abs() < (benAxeXY.Second - Int_P2).abs()) ? Int_P1 : Int_P2;
                        double  baseAng2 = (benAxeXY.Second - benAxeXY.First).arg();
                        if (baseAng2 > Math.PI)
                        {
                            baseAng2 = baseAng2 - 2 * Math.PI;
                        }

                        outf.WriteLine(String.Format("#114 = {0:f4} (GAMMA R-G68)", baseAng2 * 180.0 / Math.PI));

                        //----------------------
                        pa                  = new Pair <quaternion, quaternion>(ucs.ToACS(pa.First), ucs.ToACS(pa.Second));
                        bendAxe             = new Pair <quaternion, quaternion>(ucs.ToACS(bendAxe.First), ucs.ToACS(bendAxe.Second));
                        ucsOriginDescriptor = ucs.ToACS(ucsOriginDescriptor);
                        cenTOP              = ucs.ToACS(cenTOP); cenBottom = ucs.ToACS(cenBottom); inTOP = ucs.ToACS(inTOP); outTOP = ucs.ToACS(outTOP);
                        gabaritQ            = ucs.ToACS(gabaritQ);
                        quaternion gabaritB = gabaritQ + cenBottom - cenTOP;
                        quaternion inBottom = inTOP + cenBottom - cenTOP;

                        double positiveZ = (ucs.FromACS(gabaritQ).GetZ() > ucs.FromACS(inTOP).GetZ()) ? ucs.FromACS(gabaritQ).GetZ() + 5.0 : ucs.FromACS(inTOP).GetZ() + 5.0;
                        double negativeZ = (ucs.FromACS(gabaritB).GetZ() < ucs.FromACS(inBottom).GetZ()) ? ucs.FromACS(gabaritB).GetZ() - 2.0 : ucs.FromACS(inBottom).GetZ() - 2.0;

                        outf.WriteLine(String.Format("#115 = {0:f4} (OBRABOTKA NAD Z=0)", positiveZ));
                        outf.WriteLine(String.Format("#116 = {0:f4} (OBRABOTKA POD Z=0)", negativeZ));

                        #region draw test1

                        /*
                         * Line LL = new Line((Point3d)pa.First, (Point3d)pa.Second);
                         * LL.ColorIndex = 1;
                         * acBlkTblRec.AppendEntity(LL);
                         * tr.AddNewlyCreatedDBObject(LL, true);
                         *
                         * Line LLL = new Line((Point3d)inTOP, (Point3d)outTOP);
                         * LLL.ColorIndex = 1;
                         * acBlkTblRec.AppendEntity(LLL);
                         * tr.AddNewlyCreatedDBObject(LLL, true);
                         *
                         *
                         * Line LLLL = new Line((Point3d)cenTOP, (Point3d)cenBottom);
                         * LLLL.ColorIndex = 1;
                         * acBlkTblRec.AppendEntity(LLLL);
                         * tr.AddNewlyCreatedDBObject(LLLL, true);
                         *
                         * Line LLLLL = new Line((Point3d)bendAxe.First, (Point3d)bendAxe.Second);
                         * LLLLL.ColorIndex = 1;
                         * acBlkTblRec.AppendEntity(LLLLL);
                         * tr.AddNewlyCreatedDBObject(LLLLL, true);
                         *
                         * Line PP = new Line((Point3d)outTOP, (Point3d)gabaritQ);
                         * PP.ColorIndex = 2;
                         * acBlkTblRec.AppendEntity(PP);
                         * tr.AddNewlyCreatedDBObject(PP, true);
                         *
                         * Line PPP = new Line((Point3d)gabaritB, (Point3d)gabaritQ);
                         * PPP.ColorIndex = 2;
                         * acBlkTblRec.AppendEntity(PPP);
                         * tr.AddNewlyCreatedDBObject(PPP, true);
                         *
                         * Line PPPP = new Line((Point3d)inBottom, (Point3d)inTOP);
                         * PPPP.ColorIndex = 2;
                         * acBlkTblRec.AppendEntity(PPPP);
                         * tr.AddNewlyCreatedDBObject(PPPP, true);
                         */
                        #endregion
                    }

                    outf.WriteLine("G65P1401");
                    outf.WriteLine("M1");
                    outf.WriteLine();

                    counter++;
                }

                //outf.WriteLine(String.Format("G43{0}", G43H));
                tr.Commit();
                Application.DocumentManager.MdiActiveDocument.Editor.UpdateScreen();
            }
Beispiel #2
0
        public void KojtoCAD_3D_SetExplicitNodeNormalByNodePosition()
        {
            if ((container != null) && (container.Bends.Count > 0) && (container.Nodes.Count > 0) && (container.Triangles.Count > 0))
            {
                Database db = HostApplicationServices.WorkingDatabase;
                Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

                Matrix3d old = ed.CurrentUserCoordinateSystem;
                ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

                try
                {
                    PromptPointResult  pPtRes;
                    PromptPointOptions pPtOpts = new PromptPointOptions("");

                    pPtOpts.Message = "\nEnter the Point of the Node: ";
                    pPtRes          = Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(pPtOpts);

                    if (pPtRes.Status == PromptStatus.OK)
                    {
                        quaternion       nq   = new quaternion(0, pPtRes.Value.X, pPtRes.Value.Y, pPtRes.Value.Z);
                        WorkClasses.Node Node = null;
                        foreach (WorkClasses.Node node in container.Nodes)
                        {
                            if (node == nq)
                            {
                                Node = node;
                                break;
                            }
                        }
                        if ((object)Node != null)
                        {
                            PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("");
                            pKeyOpts.Message = "\nEnter an option ";
                            pKeyOpts.Keywords.Add("Selection");
                            pKeyOpts.Keywords.Add("NodeCentroid");
                            pKeyOpts.Keywords.Default = "Selection";
                            pKeyOpts.AllowNone        = true;
                            PromptResult pKeyRes = Application.DocumentManager.MdiActiveDocument.Editor.GetKeywords(pKeyOpts);
                            if (pKeyRes.Status == PromptStatus.OK)
                            {
                                PromptDoubleOptions pDoubleOpts = new PromptDoubleOptions("");
                                pDoubleOpts.Message       = "\n Enter Explicit Length of the Normal: ";
                                pDoubleOpts.DefaultValue  = 1.0;
                                pDoubleOpts.AllowZero     = false;
                                pDoubleOpts.AllowNegative = false;

                                PromptDoubleResult pDoubleRes = Application.DocumentManager.MdiActiveDocument.Editor.GetDouble(pDoubleOpts);
                                if (pDoubleRes.Status == PromptStatus.OK)
                                {
                                    switch (pKeyRes.StringResult)
                                    {
                                    case "NodeCentroid":
                                        quaternion q = GetNodeCentroidByNoFictiveBendsMidPoints(Node.Numer);
                                        q  = ((q - Node.Position).angTo(Node.Normal - Node.Position) <= Math.PI / 2.0) ? q - Node.Position : Node.Position - q;
                                        q /= q.abs();
                                        q += Node.Position;
                                        Node.SetExplicitNormal(q);
                                        Node.ExplicitNormalLength = pDoubleRes.Value;
                                        break;

                                    case "Selection":
                                        PromptPointResult  pPtRes_;
                                        PromptPointOptions pPtOpts_ = new PromptPointOptions("");
                                        pPtOpts_.Message = "\nEnter the Direction Point of the Normal: ";
                                        pPtRes_          = Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(pPtOpts_);
                                        if (pPtRes_.Status == PromptStatus.OK)
                                        {
                                            quaternion Q = new quaternion(0, pPtRes_.Value.X, pPtRes_.Value.Y, pPtRes_.Value.Z);
                                            Q  = ((Q - Node.Position).angTo(Node.Normal - Node.Position) <= Math.PI / 2.0) ? Q - Node.Position : Node.Position - Q;
                                            Q /= Q.abs();
                                            Q += Node.Position;
                                            Node.SetExplicitNormal(Q);
                                            Node.ExplicitNormalLength = pDoubleRes.Value;
                                        }
                                        else
                                        {
                                            MessageBox.Show("\nPoint not found - E R R O R  !", "E R R O R - Selection Point", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                            ed.WriteMessage("\nPoint not found - E R R O R  !");
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("\nNode not found - E R R O R  !", "E R R O R - Selection Node", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            ed.WriteMessage("\nNode not found - E R R O R  !");
                        }
                    }
                }
                catch { }
                finally { ed.CurrentUserCoordinateSystem = old; }
            }
            else
            {
                MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
        public void KojtoCAD_3D_Restore_Bend_Normal_By_Selection()
        {
            if ((container != null) && (container.Bends.Count > 0) && (container.Nodes.Count > 0) && (container.Triangles.Count > 0))
            {
                Database db = HostApplicationServices.WorkingDatabase;
                Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

                Matrix3d old = ed.CurrentUserCoordinateSystem;
                ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

                try
                {
                    PromptPointResult  pPtRes;
                    PromptPointOptions pPtOpts = new PromptPointOptions("");

                    // Prompt for the first point
                    pPtOpts.Message = "\nEnter the first Point of the Bend: ";
                    pPtRes          = Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(pPtOpts);
                    if (pPtRes.Status == PromptStatus.OK)
                    {
                        Point3d ptFirst = pPtRes.Value;

                        pPtOpts.Message      = "\nEnter the second Point of the Bend: ";
                        pPtOpts.UseBasePoint = true;
                        pPtOpts.BasePoint    = ptFirst;
                        pPtRes = Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(pPtOpts);
                        if (pPtRes.Status == PromptStatus.OK)
                        {
                            Point3d ptSecond = pPtRes.Value;
                            if (ptSecond.DistanceTo(ptFirst) >= ConstantsAndSettings.MinBendLength)
                            {
                                Pair <quaternion, quaternion> pb = new Pair <quaternion, quaternion>(new quaternion(0, ptFirst.X, ptFirst.Y, ptFirst.Z), new quaternion(0, ptSecond.X, ptSecond.Y, ptSecond.Z));
                                WorkClasses.Bend TR = null;
                                foreach (WorkClasses.Bend bend in container.Bends)
                                {
                                    if (bend == pb)
                                    {
                                        TR = bend;
                                        break;
                                    }
                                }
                                //------------
                                if ((object)TR != null)
                                {
                                    quaternion m = TR.MidPoint;
                                    if ((object)TR.MidPoint == null)
                                    {
                                        m           = (TR.Start + TR.End) / 2.0;
                                        TR.MidPoint = m;
                                    }

                                    quaternion q1 = container.Triangles[TR.FirstTriangleNumer].Normal.Second - container.Triangles[TR.FirstTriangleNumer].Normal.First;
                                    quaternion q3 = m + q1;
                                    q1 /= q1.abs();
                                    if (TR.SecondTriangleNumer < 0)
                                    {
                                        if (ConstantsAndSettings.PerepherialBendsNormalDirection == 0)
                                        {
                                            TR.Normal = q3;
                                        }
                                        else
                                        {
                                            UCS  trUCS = new UCS(container.Triangles[TR.FirstTriangleNumer].Normal.First, TR.Start, TR.End);
                                            bool bSign = (trUCS.FromACS(container.Triangles[TR.FirstTriangleNumer].Normal.Second).GetZ() >= 0) ? true : false;
                                            if (!bSign)
                                            {
                                                trUCS = new UCS(container.Triangles[TR.FirstTriangleNumer].Normal.First, TR.End, TR.Start);
                                            }

                                            if (ConstantsAndSettings.PerepherialBendsNormalDirection == 1)
                                            {
                                                quaternion q2 = new quaternion(0, 0, 0, 1) + m;
                                                TR.Normal = q2;
                                                if (Math.Abs(trUCS.FromACS(q2).GetZ()) <= ConstantsAndSettings.MinDistBhetwenNodes)
                                                {
                                                    if ((container.Triangles[TR.FirstTriangleNumer].Normal.First - m).abs() < (container.Triangles[TR.FirstTriangleNumer].Normal.First - q2).abs())
                                                    {
                                                        TR.Normal = m + m - q2;
                                                    }
                                                }
                                                else
                                                if (trUCS.FromACS(m + (q2 - m) * 10000.0).GetZ() < 0.0)
                                                {
                                                    TR.Normal = m + m - q2;
                                                }
                                            }
                                            if (ConstantsAndSettings.PerepherialBendsNormalDirection == 2)
                                            {
                                                quaternion q2 = new quaternion(0, 0, 1, 0) + m;
                                                TR.Normal = q2;
                                                if (Math.Abs(trUCS.FromACS(q2).GetZ()) <= ConstantsAndSettings.MinDistBhetwenNodes)
                                                {
                                                    if ((container.Triangles[TR.FirstTriangleNumer].Normal.First - m).abs() < (container.Triangles[TR.FirstTriangleNumer].Normal.First - q2).abs())
                                                    {
                                                        TR.Normal = m + m - q2;
                                                    }
                                                }
                                                else
                                                if (trUCS.FromACS(m + (q2 - m) * 10000.0).GetZ() < 0.0)
                                                {
                                                    TR.Normal = m + m - q2;
                                                }
                                            }
                                            if (ConstantsAndSettings.PerepherialBendsNormalDirection == 3)
                                            {
                                                quaternion q2 = new quaternion(0, 1, 0, 0) + m;
                                                TR.Normal = q2;
                                                if (Math.Abs(trUCS.FromACS(q2).GetZ()) <= ConstantsAndSettings.MinDistBhetwenNodes)
                                                {
                                                    if ((container.Triangles[TR.FirstTriangleNumer].Normal.First - m).abs() < (container.Triangles[TR.FirstTriangleNumer].Normal.First - q2).abs())
                                                    {
                                                        TR.Normal = m + m - q2;
                                                    }
                                                }
                                                else
                                                if (trUCS.FromACS(m + (q2 - m) * 10000.0).GetZ() < 0.0)
                                                {
                                                    TR.Normal = m + m - q2;
                                                }
                                            }
                                        }

                                        quaternion bak = TR.Normal;
                                        UCS        ucs = TR.GetUCS();
                                        TR.Normal = ucs.ToACS(new quaternion(0, 0, 1.0, 0));
                                        if (double.IsNaN(TR.Normal.GetX()) || double.IsNaN(TR.Normal.GetY()) || double.IsNaN(TR.Normal.GetZ()))
                                        {
                                            TR.Normal = bak;
                                            string mess = string.Format("Bend Numer {0} Normal Error !", TR.Numer + 1);
                                            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(mess);
                                            MessageBox.Show(mess, "E R R O R");
                                        }
                                    }
                                    else
                                    {
                                        quaternion q2 = container.Triangles[TR.SecondTriangleNumer].Normal.Second - container.Triangles[TR.SecondTriangleNumer].Normal.First;
                                        q2 /= q2.abs();

                                        TR.Normal  = (q1 + q2) / 2.0;
                                        TR.Normal /= TR.Normal.abs();
                                        TR.Normal += m;
                                    }
                                }
                                //------------
                                else
                                {
                                    MessageBox.Show("\nBend not found - E R R O R  !", "E R R O R - Selection Bend", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    ed.WriteMessage("\nBend not found - E R R O R  !");
                                }
                            }
                            else
                            {
                                MessageBox.Show("\nDistance between selected Points is less - E R R O R  !", "E R R O R - Selection Bend", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                ed.WriteMessage("\nDistance between selected Points is less - E R R O R  !");
                            }
                        }
                    }
                }
                catch { }
                finally { ed.CurrentUserCoordinateSystem = old; }
            }
            else
            {
                MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #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);
        }
Beispiel #5
0
        public void KojtoCAD_3D_TrimPick_up_tr_()
        {
            if (container.Triangles.Count > 0)
            {
                Pair <int, PromptStatus> pa = GlobalFunctions.GetInt(1, "\ntriangle numer:");
                if ((pa.Second != PromptStatus.OK) || (pa.First < 1))
                {
                    return;
                }
                int      num = pa.First - 1;
                Triangle TR  = container.Triangles[num];

                Pair <int, PromptStatus> pa1 = GlobalFunctions.GetInt(1, "\nNode numer:");
                if ((pa1.Second != PromptStatus.OK) || (pa1.First < 1))
                {
                    return;
                }

                double x1 = 65.0;
                Pair <double, PromptStatus> pa2 = GlobalFunctions.GetDouble(x1, "\ndistance:");
                if (pa2.Second != PromptStatus.OK)
                {
                    return;
                }
                x1 = pa2.First;


                //foreach (WorkClasses.Triangle TR in container.Triangles)
                {
                    int[] nodes = TR.GetNodesNumers();

                    List <int> temp = new List <int>();
                    if (nodes[0] != (pa1.First - 1))
                    {
                        temp.Add(nodes[0]);
                    }
                    if (nodes[1] != (pa1.First - 1))
                    {
                        temp.Add(nodes[1]);
                    }
                    if (nodes[2] != (pa1.First - 1))
                    {
                        temp.Add(nodes[2]);
                    }
                    if (temp.Count != 2)
                    {
                        MessageBox.Show("Node E R R O R !", "E R R O R");
                        return;
                    }
                    //quaternion Q0 = container.Nodes[nodes[0]].Position;
                    quaternion Q0 = container.Nodes[pa1.First - 1].Position;
                    quaternion Q1 = container.Nodes[temp[0]].Position;
                    quaternion Q2 = container.Nodes[temp[1]].Position;

                    double[] angles       = new double[3];
                    double[] anglesDegree = new double[3];

                    angles[0] = (Q1 - Q0).angTo(Q2 - Q0); anglesDegree[0] = angles[0] * 180.0 / Math.PI;

                    List <ObjectId> ids = new List <ObjectId>();

                    ids.Add(TrimPickUP(pa1.First - 1, TR.GetNumer(), x1, anglesDegree[0]));

                    if (ids.Count > 0)
                    {
                        using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
                        {
                            Solid3d ent = tr.GetObject(GlobalFunctions.GetObjectId(TR.upSolidHandle.Second), OpenMode.ForWrite) as Solid3d;
                            try
                            {
                                Solid3d sol = tr.GetObject(ids[0], OpenMode.ForWrite) as Solid3d;
                                for (int i = 1; i < ids.Count; i++)
                                {
                                    Solid3d sol_i = tr.GetObject(ids[i], OpenMode.ForWrite) as Solid3d;
                                    sol.BooleanOperation(BooleanOperationType.BoolUnite, sol_i);
                                }

                                ent.BooleanOperation(BooleanOperationType.BoolSubtract, sol);
                            }
                            catch { }

                            tr.Commit();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #6
0
        public void KojtoCAD_3D_TrimPick_up_tr()
        {
            if (container.Triangles.Count > 0)
            {
                Pair <int, PromptStatus> pa = GlobalFunctions.GetInt(1, "\ntriangle numer:");
                if ((pa.Second != PromptStatus.OK) || (pa.First < 1))
                {
                    return;
                }
                int      num = pa.First - 1;
                Triangle TR  = container.Triangles[num];

                double x1 = 65.0;
                double x2 = 33.0;
                double x3 = 12.0;
                double x4 = 8.0;

                GetDistances(ref x1, ref x2, ref x3, ref x4);

                //foreach (WorkClasses.Triangle TR in container.Triangles)
                {
                    int[] nodes = TR.GetNodesNumers();

                    quaternion Q0 = container.Nodes[nodes[0]].Position;
                    quaternion Q1 = container.Nodes[nodes[1]].Position;
                    quaternion Q2 = container.Nodes[nodes[2]].Position;

                    double[] angles       = new double[3];
                    double[] anglesDegree = new double[3];

                    angles[0] = (Q1 - Q0).angTo(Q2 - Q0); anglesDegree[0] = angles[0] * 180.0 / Math.PI;
                    angles[1] = (Q0 - Q1).angTo(Q2 - Q1); anglesDegree[1] = angles[1] * 180.0 / Math.PI;
                    angles[2] = (Q0 - Q2).angTo(Q1 - Q2); anglesDegree[2] = angles[2] * 180.0 / Math.PI;

                    List <ObjectId> ids = new List <ObjectId>();

                    if (anglesDegree[0] <= 12.5)
                    {
                        ids.Add(TrimPickUP(nodes[0], TR.GetNumer(), x1, anglesDegree[0]));
                    }
                    if ((anglesDegree[0] > 12.5) && (anglesDegree[0] <= 20.0))
                    {
                        ids.Add(TrimPickUP(nodes[0], TR.GetNumer(), x2, anglesDegree[0]));
                    }
                    if ((anglesDegree[0] > 20.0) && (anglesDegree[0] <= 35.0))
                    {
                        ids.Add(TrimPickUP(nodes[0], TR.GetNumer(), x3, anglesDegree[0]));
                    }
                    if ((anglesDegree[0] > 35.0) && (anglesDegree[0] <= 45.0))
                    {
                        ids.Add(TrimPickUP(nodes[0], TR.GetNumer(), x4, anglesDegree[0]));
                    }

                    if (anglesDegree[1] <= 12.5)
                    {
                        ids.Add(TrimPickUP(nodes[1], TR.GetNumer(), x1, anglesDegree[1]));
                    }
                    if ((anglesDegree[1] > 12.5) && (anglesDegree[1] <= 20.0))
                    {
                        ids.Add(TrimPickUP(nodes[1], TR.GetNumer(), x2, anglesDegree[1]));
                    }
                    if ((anglesDegree[1] > 20.0) && (anglesDegree[1] <= 35.0))
                    {
                        ids.Add(TrimPickUP(nodes[1], TR.GetNumer(), x3, anglesDegree[1]));
                    }
                    if ((anglesDegree[1] > 35.0) && (anglesDegree[1] <= 45.0))
                    {
                        ids.Add(TrimPickUP(nodes[1], TR.GetNumer(), x4, anglesDegree[1]));
                    }

                    if (anglesDegree[2] <= 12.5)
                    {
                        ids.Add(TrimPickUP(nodes[2], TR.GetNumer(), x1, anglesDegree[2]));
                    }
                    if ((anglesDegree[2] > 12.5) && (anglesDegree[2] <= 20.0))
                    {
                        ids.Add(TrimPickUP(nodes[2], TR.GetNumer(), x2, anglesDegree[2]));
                    }
                    if ((anglesDegree[2] > 20.0) && (anglesDegree[2] <= 35.0))
                    {
                        ids.Add(TrimPickUP(nodes[2], TR.GetNumer(), x3, anglesDegree[2]));
                    }
                    if ((anglesDegree[2] > 35.0) && (anglesDegree[2] <= 45.0))
                    {
                        ids.Add(TrimPickUP(nodes[2], TR.GetNumer(), x4, anglesDegree[2]));
                    }


                    if (ids.Count > 0)
                    {
                        using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
                        {
                            Solid3d ent = tr.GetObject(GlobalFunctions.GetObjectId(TR.upSolidHandle.Second), OpenMode.ForWrite) as Solid3d;
                            try
                            {
                                Solid3d sol = tr.GetObject(ids[0], OpenMode.ForWrite) as Solid3d;
                                for (int i = 1; i < ids.Count; i++)
                                {
                                    Solid3d sol_i = tr.GetObject(ids[i], OpenMode.ForWrite) as Solid3d;
                                    sol.BooleanOperation(BooleanOperationType.BoolUnite, sol_i);
                                }

                                ent.BooleanOperation(BooleanOperationType.BoolSubtract, sol);
                            }
                            catch { }

                            tr.Commit();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }