コード例 #1
0
        public void Cleanup()
        {
            _vertices.Clear();

            foreach (DBObject obj in _created)
            {
                obj.Dispose();
            }
            _created.Clear();
        }
コード例 #2
0
        public void AddPolylines()
        {
            ClearTransients();

            // Dispose of the database objects

            foreach (DBObject obj in _lines)
            {
                obj.Dispose();
            }
            _lines.Clear();

            // Create a true database-resident 3D polyline
            // (and let it be green)

            if (_vertices.Count > 1)
            {
                var btr =
                    (BlockTableRecord)_tr.GetObject(
                        _doc.Database.CurrentSpaceId,
                        OpenMode.ForWrite
                        );

                var pl =
                    new Polyline3d(
                        Poly3dType.SimplePoly, _vertices, false
                        );
                pl.ColorIndex = 3;

                btr.AppendEntity(pl);
                _tr.AddNewlyCreatedDBObject(pl, true);
            }
            _vertices.Clear();
        }
コード例 #3
0
ファイル: TransientSample.cs プロジェクト: 15831944/Git
        //dispose all the DBpoints
        static void DisposePointArray()
        {
            int nLength = TGpoints.Count;

            if (nLength > 0)
            {
                int nIndex = 1;
                while (nIndex < nLength)
                {
                    TGpoints[nIndex].Dispose();
                    nIndex++;
                }

                //erase the parent
                TGpoints[0].Dispose();
            }

            TGpoints.Clear();
        }
コード例 #4
0
        public static void ExplodeProfile(Autodesk.AutoCAD.DatabaseServices.Entity ent, List <Autodesk.AutoCAD.DatabaseServices.DBObject> entities)
        {
            var objs = new DBObjectCollection();

            if (ent != null)
            {
                ent.Explode(objs);
                var block = objs[0] as Autodesk.AutoCAD.DatabaseServices.Entity;
                objs.Clear();
                block.Explode(objs);

                foreach (Autodesk.AutoCAD.DatabaseServices.Entity obj in objs)
                {
                    entities.Add(obj);
                }
            }
        }
コード例 #5
0
        // draw the 3-D drawing
        // nFlag: dimension control
        private void DrawSolidProfile(Plate pl, Point3d p0, int nFlag)
        {
            // Create Container for the curve, the region (face)
            DBObjectCollection curves = new DBObjectCollection();
            // - Collection for the regions
            DBObjectCollection regions = new DBObjectCollection();

            // Solid3d objects
            Solid3d plateSolid = new Solid3d();
            Solid3d rectHole   = new Solid3d();            // Rectangular Hole in the Center

            Point3d[] pt = new Point3d[26];                // geometry helpers
            Line[]    ln = new Line[26];                   // database objects

            // create points
            pt[0]  = p0;
            pt[1]  = new Point3d(p0.X + (pl.dW - pl.R1), p0.Y, p0.Z);
            pt[2]  = new Point3d(p0.X + pl.dW, pl.R1, p0.Z);
            pt[3]  = new Point3d(pt[1].X, pt[2].Y, p0.Z);
            pt[4]  = new Point3d(pt[3].X, pt[3].Y + pl.L9, p0.Z);
            pt[5]  = new Point3d(pt[4].X + pl.L2, pt[4].Y + pl.L8, p0.Z);
            pt[6]  = new Point3d(pt[5].X, pt[5].Y + pl.L7, p0.Z);
            pt[7]  = new Point3d(pt[4].X, pt[6].Y + pl.L6, p0.Z);
            pt[8]  = new Point3d(pt[7].X, pt[7].Y + pl.L5, p0.Z);
            pt[9]  = new Point3d(p0.X + pl.L3, pt[8].Y + pl.L4, p0.Z);
            pt[10] = new Point3d(p0.X, pt[9].Y, p0.Z);

            // symmetry - create points on negative x-axis
            int k = 9;

            for (int i = 11; i < 20; i++)
            {
                pt[i] = new Point3d(-pt[k].X, pt[k].Y, pt[k].Z);
                k--;
            }

            // create lines and store them into the database
            for (int i = 0; i < 20; i++)
            {
                if (i != 1 & i != 18)
                {
                    ln[i]            = new Line(pt[i], pt[(i + 1)]);
                    ln[i].ColorIndex = pl.nColor[CONTOUR];      // 0:index
                    curves.Add(ln[i]);
                }
                else if (i == 1)
                {
                    double st_angle0  = 270 * (Math.PI / 180);
                    double end_angle0 = 0;

                    Arc a0 = new Arc(pt[3], pl.R1, st_angle0, end_angle0);
                    a0.ColorIndex = pl.nColor[CONTOUR];      // 0:index
                    curves.Add(a0);
                }
                else if (i == 18)
                {
                    double st_angle1  = 180 * (Math.PI / 180);
                    double end_angle1 = 270 * (Math.PI / 180);

                    Arc a1 = new Arc(pt[17], pl.R1, st_angle1, end_angle1);
                    a1.ColorIndex = pl.nColor[CONTOUR];      // 0:index
                    curves.Add(a1);
                }
                else
                {
                    continue;
                }
            }

            // Create the Region from the curves
            regions = Region.CreateFromCurves(curves);
            plateSolid.ColorIndex = pl.nColor[CONTOUR];

            // Create the plate without the hole
            plateSolid.Extrude((Region)regions[0], pl.dT, 0.0);

            // draw points for centre hole
            curves.Clear();

            pt[20] = new Point3d(p0.X + pl.R2, pt[3].Y + pl.R2, 0.0);
            pt[21] = new Point3d(pt[20].X, pt[7].Y - pl.R2, 0.0);
            pt[22] = new Point3d(-pt[20].X, pt[7].Y - pl.R2, 0.0);
            pt[23] = new Point3d(-(p0.X + pl.R2), pt[3].Y + pl.R2, 0.0);
            pt[24] = new Point3d(p0.X, pt[20].Y, 0.0);
            pt[25] = new Point3d(p0.X, pt[21].Y, 0.0);

            // draw lines for centre hole
            for (int i = 20; i < 24; i++)
            {
                if (i != 21 & i != 23)
                {
                    ln[i]            = new Line(pt[i], pt[(i + 1)]);
                    ln[i].ColorIndex = pl.nColor[CONTOUR];      // 0:index
                    curves.Add(ln[i]);
                }
                else if (i == 21)
                {
                    double st_angle2  = 0;
                    double end_angle2 = 180 * (Math.PI / 180);

                    Arc a2 = new Arc(pt[25], pl.R2, st_angle2, end_angle2);
                    a2.ColorIndex = pl.nColor[CONTOUR];      // 0:index
                    curves.Add(a2);
                }
                else if (i == 23)
                {
                    double st_angle3  = 180 * (Math.PI / 180);
                    double end_angle3 = 0;

                    Arc a3 = new Arc(pt[24], pl.R2, st_angle3, end_angle3);
                    a3.ColorIndex = pl.nColor[CONTOUR];      // 0:index
                    curves.Add(a3);
                }
                else
                {
                    continue;
                }
            }

            // Create the Region from the curves (Rectangular Hole)
            regions = Region.CreateFromCurves(curves);
            rectHole.Extrude((Region)regions[0], pl.dT, 0.0);
            rectHole.ColorIndex = pl.nColor[HIDDEN];

            // Substract the Hole Solid from the Rectangle
            plateSolid.BooleanOperation(BooleanOperationType.BoolSubtract, rectHole);

            // Add Solids into the Database
            AcTrans.Add(plateSolid);
        }
コード例 #6
0
        public static Polyline3d ExtractBorders(this Autodesk.Civil.DatabaseServices.TinVolumeSurface surface)
        {
            var defBoundaries = surface.GetBoundariesDefinitions();

            if (defBoundaries.Count() > 0)
            {
                return(defBoundaries.Last());
            }
            else
            {
                bool displayBoundariesChanged = false;
                Autodesk.Civil.DatabaseServices.Styles.SurfaceStyle style = surface.StyleId.GetObjectForRead <Autodesk.Civil.DatabaseServices.Styles.SurfaceStyle>();
                var displayStyle = style.GetDisplayStylePlan(Autodesk.Civil.DatabaseServices.Styles.SurfaceDisplayStyleType.Boundary);
                if (!displayStyle.Visible)
                {
                    style.UpgradeOpen();
                    displayStyle.Visible = true;
                    style.DowngradeOpen();
                    displayBoundariesChanged = true;
                }

                Polyline3d         res    = null;
                DBObjectCollection dbcoll = new DBObjectCollection();
                surface.Explode(dbcoll);
                foreach (var dbobj in dbcoll)
                {
                    if (dbobj is BlockReference)
                    {
                        dbcoll.Clear();
                        ((BlockReference)dbobj).Explode(dbcoll);
                        List <Polyline3d> lines = new List <Polyline3d>();
                        foreach (var ent in dbcoll)
                        {
                            if (ent is Polyline3d)
                            {
                                Polyline3d pline = ent as Polyline3d;
                                if (pline.Closed)
                                {
                                    lines.Add(pline);
                                }
                            }
                        }



                        //lines.Sort((l1, l2) => Comparer<double>.Default.Compare(l1.Area, l2.Area));
                        res = lines.LastOrDefault();
                        break;
                    }
                }

                if (displayBoundariesChanged)
                {
                    style.UpgradeOpen();
                    displayStyle.Visible = false;
                    style.DowngradeOpen();
                }

                return(res);
            }
        }
コード例 #7
0
ファイル: WeldingLine.cs プロジェクト: kojtoLtd/KojtoCAD
        public void WeldingLineStart()
        {
            #region Select welding mode
            var weldingModeOpts = new PromptKeywordOptions("\nWeld over points or object? ");
            weldingModeOpts.Keywords.Add("Points");
            weldingModeOpts.Keywords.Add("polYline");
            weldingModeOpts.Keywords.Add("Line");
            weldingModeOpts.Keywords.Add("Circle");
            weldingModeOpts.Keywords.Add("Arc");
            weldingModeOpts.Keywords.Add("Block");
            weldingModeOpts.Keywords.Default = "Points";

            var weldingModeRslt = _ed.GetKeywords(weldingModeOpts);
            // If the user pressed cancel - return with no error
            if (weldingModeRslt.Status != PromptStatus.OK)
            {
                return;
            }

            if (weldingModeRslt.StringResult == "Block")
            {
                ImportInsulationBlock();
                return;
            }

            var selectedObjectId = new ObjectId();
            // If the user selected Points mode
            if (weldingModeRslt.StringResult == "Points")
            {
                //Prompt the user for vertices
                _weldingVertices.Clear();
                _weldingVertices = GetPointsFromUser();
                if (_weldingVertices.Count < 1)
                {
                    return;
                }
            }
            // Else the user selected an Object mode from the list
            else
            {
                // Prompt for object
                var objectSelectionOpts = new PromptEntityOptions("\nSelect the object : ");
                objectSelectionOpts.SetRejectMessage("\nEntity is not of the predifined type :" + weldingModeRslt.StringResult);
                objectSelectionOpts.AddAllowedClass(typeof(Line), false);
                objectSelectionOpts.AddAllowedClass(typeof(Polyline), false);
                objectSelectionOpts.AddAllowedClass(typeof(Circle), false);
                objectSelectionOpts.AddAllowedClass(typeof(Arc), false);

                var objectSelectionRslt = _ed.GetEntity(objectSelectionOpts);
                // If the user pressed cancel - return with no error
                if (objectSelectionRslt.Status != PromptStatus.OK)
                {
                    return;
                }
                // else get the slected object id and type
                selectedObjectId = objectSelectionRslt.ObjectId;
            }
            #endregion

            #region Welding side selection

            // Prompt the user to select object side M for middle - draw on the middle of the line or Point - for side.
            var weldingSideOpts = new PromptKeywordOptions("\nPick side point or draw in the middle. ");
            weldingSideOpts.Keywords.Add("Side");
            weldingSideOpts.Keywords.Add("Middle ");
            weldingSideOpts.Keywords.Default = "Side";
            var weldingSideRslt = _ed.GetKeywords(weldingSideOpts);
            // If the user pressed cancel - return with no error
            if (weldingSideRslt.Status != PromptStatus.OK)
            {
                return;
            }

            // If tThe user selected 'Side'
            var sidePoint = new Point3d();
            if (weldingSideRslt.StringResult == "Side")
            {
                // Prompt the user to pick up a side point on the desired side.
                var sidePointOpts = new PromptPointOptions("\nPick side point : ");
                var sidePointRslt = _ed.GetPoint(sidePointOpts);
                // If the user pressed cancel - return with no error
                if (sidePointRslt.Status != PromptStatus.OK)
                {
                    return;
                }
                sidePoint = sidePointRslt.Value;
            }
            // Else If the user selected 'Middle'
            else if (weldingSideRslt.StringResult == "Middle")
            {
                sidePoint = new Point3d(0, 0, 0);
            }
            // else
            // Not supposed to end here, because the choise in the prompt is restricted to two options
            #endregion

            #region Welding arcs lenght and distance selection

            // Prompt the user to set welding arcs lenght
            var weldingArcsChordOpts = new PromptDoubleOptions("\nWelding arcs lenght : ")
            {
                UseDefaultValue = true,
                DefaultValue    = Settings.Default.WeldingArcsLenght
            };

            var weldingArcsChordRslt = _ed.GetDouble(weldingArcsChordOpts);
            // If the user pressed cancel - return with no error
            if (weldingArcsChordRslt.Status != PromptStatus.OK)
            {
                return;
            }
            if (weldingArcsChordRslt.Value <= 0)
            {
                _ed.WriteMessage("Lenght must be positive number.");
                return;
            }
            Settings.Default.WeldingArcsLenght = weldingArcsChordRslt.Value;
            //else
            // The choice is Ok and lenght is provided. Continue...

            // Prompt the user to set the distance between the welding arcs
            var weldingArcsDistanceOpts = new PromptDoubleOptions("\nSet the distance between the welding arcs : ")
            {
                UseDefaultValue = true,
                DefaultValue    = Settings.Default.WeldingArcsDistance
            };
            var weldingArcsOffsetRslt = _ed.GetDouble(weldingArcsDistanceOpts);
            // If the user pressed cancel - return with no error
            if (weldingArcsOffsetRslt.Status != PromptStatus.OK)
            {
                return;
            }
            if (weldingArcsOffsetRslt.Value <= 0)
            {
                _ed.WriteMessage("Distance must be positive number.");
            }
            Settings.Default.WeldingArcsDistance = weldingArcsOffsetRslt.Value;
            Settings.Default.Save();
            //else
            // The choice is Ok and distance is provided. Continue...
            #endregion

            #region Hand over the process to the specific drawing function
            _weldingArcs.Clear();

            switch (weldingModeRslt.StringResult)
            {
                #region Points
            case "Points":

                for (var i = 0; i < _weldingVertices.Count; i++)
                {
                    // слага ги в глобалната
                    _weldingVertices[i] = _weldingVertices[i].TransformBy(GeometryUtility.GetTransforMatrixToWcs());
                }
                using (var tr = _doc.Database.TransactionManager.StartTransaction())
                {
                    var sPt = new Point3d(sidePoint.X + 0.00001, sidePoint.Y + 0.00001, sidePoint.Z);
                    sPt = sPt.TransformBy(GeometryUtility.GetTransforMatrixToWcs());
                    // реперната точка и тя в глобалната

                    var tP1 = new Point3d(0, 0, 0);
                    var tP2 = new Point3d(_weldingVertices[1].X - _weldingVertices[0].X, _weldingVertices[1].Y - _weldingVertices[0].Y, _weldingVertices[1].Z - _weldingVertices[0].Z);
                    var tP3 = new Point3d(sPt.X - _weldingVertices[0].X, sPt.Y - _weldingVertices[0].Y, sPt.Z - _weldingVertices[0].Z);


                    var ucs = GeometryUtility.GetUcs(tP1, tP2, tP3, false);
                    for (var i = 0; i < _weldingVertices.Count; i++)
                    {
                        _weldingVertices[i] = _weldingVertices[i].TransformBy(ucs);
                    }
                    if (weldingSideRslt.StringResult == "Side")
                    {
                        sidePoint = sidePoint.TransformBy(_ed.CurrentUserCoordinateSystem);
                        sidePoint = sidePoint.TransformBy(ucs);
                    }

                    var oldUcs = _ed.CurrentUserCoordinateSystem;
                    _ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

                    _weldingArcs = BuildWeldingArcsOverPts(_weldingVertices,
                                                           sidePoint,
                                                           weldingArcsChordRslt.Value,
                                                           weldingArcsOffsetRslt.Value,
                                                           weldingArcsOffsetRslt.Value / 2);
                    DrawWeldingLine(_weldingArcs, tr);

                    _ed.CurrentUserCoordinateSystem = oldUcs;

                    foreach (Arc a in _weldingArcs)
                    {
                        a.TransformBy(ucs.Inverse());
                    }


                    tr.Commit();
                }
                break;
                #endregion

                #region Line
            case "Line":
                using (var tr = _doc.Database.TransactionManager.StartTransaction())
                {
                    _weldingVertices.Clear();

                    var ent  = tr.GetObject(selectedObjectId, OpenMode.ForRead) as Entity;                                                                     // Lishkov 07/07/2012
                    var name = ent.GetType().ToString();                                                                                                       // Lishkov 07/07/2012
                    if ((name.IndexOf("Line") < 0) || (name.IndexOf("Polyline") >= 0))
                    {
                        MessageBox.Show("Selection is not  Line !", "E R R O R"); break;
                    }                                                                                                                                             // Lishkov 07/07/2012

                    var weldingLine = (Line)tr.GetObject(selectedObjectId, OpenMode.ForWrite);

                    var sPt = new Point3d(sidePoint.X + 0.00001, sidePoint.Y + 0.00001, sidePoint.Z);
                    sPt = sPt.TransformBy(GeometryUtility.GetTransforMatrixToWcs());

                    var tP1 = new Point3d(0, 0, 0);
                    var tP2 = new Point3d(weldingLine.EndPoint.X - weldingLine.StartPoint.X, weldingLine.EndPoint.Y - weldingLine.StartPoint.Y, weldingLine.EndPoint.Z - weldingLine.StartPoint.Z);
                    var tP3 = new Point3d(sPt.X - weldingLine.StartPoint.X, sPt.Y - weldingLine.StartPoint.Y, sPt.Z - weldingLine.StartPoint.Z);

                    var ucs = GeometryUtility.GetUcs(tP1, tP2, tP3, false);
                    weldingLine.TransformBy(ucs);
                    if (weldingSideRslt.StringResult == "Side")
                    {
                        sidePoint = sidePoint.TransformBy(_ed.CurrentUserCoordinateSystem);
                        sidePoint = sidePoint.TransformBy(ucs);
                    }

                    var oldUcs = _ed.CurrentUserCoordinateSystem;
                    _ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

                    _weldingVertices.Add(weldingLine.StartPoint);
                    _weldingVertices.Add(weldingLine.EndPoint);

                    _weldingArcs = BuildWeldingArcsOverPts(_weldingVertices,
                                                           sidePoint,
                                                           weldingArcsChordRslt.Value,
                                                           weldingArcsOffsetRslt.Value,
                                                           weldingArcsOffsetRslt.Value / 2);
                    DrawWeldingLine(_weldingArcs, tr);

                    _ed.CurrentUserCoordinateSystem = oldUcs;

                    foreach (Arc a in _weldingArcs)
                    {
                        a.TransformBy(ucs.Inverse());
                    }

                    weldingLine.TransformBy(ucs.Inverse());


                    tr.Commit();
                }

                break;
                #endregion

                #region Polyline
            case "polYline":
            case "Polyline":
            case "polyline":

                using (var tr = _doc.Database.TransactionManager.StartTransaction())
                {
                    var weldingPoly = tr.GetObject(selectedObjectId, OpenMode.ForWrite) as Polyline;
                    if (weldingPoly == null)
                    {
                        MessageBox.Show("Selection is not  PolyLine !", "E R R O R");
                        break;
                    }

                    var temp  = new Point3dCollection();
                    var temp1 = new Point3dCollection();
                    DBObjectCollection acDbObjColl = null;     //acPoly.GetOffsetCurves(0.25);

                    var acBlkTbl    = tr.GetObject(_db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    var acBlkTblRec = (BlockTableRecord)tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    //офсетирано копие
                    acDbObjColl = weldingPoly.GetOffsetCurves(0.001);    //тестова на много малко разстояние от оригинала // Lishkov 07/07/2012
                    foreach (Entity acEnt in acDbObjColl)
                    {
                        // Add each offset object
                        acBlkTblRec.AppendEntity(acEnt);
                        tr.AddNewlyCreatedDBObject(acEnt, true);
                    }
                    Polyline weldingPolyOffset = null;
                    try
                    {
                        weldingPolyOffset = tr.GetObject(acDbObjColl[0].ObjectId, OpenMode.ForWrite) as Polyline;
                    }
                    catch { }
                    if (weldingPolyOffset != null)
                    {
                        //точките деления по двете полилинии
                        temp  = GeometryUtility.DividePoly(ref weldingPoly, weldingArcsOffsetRslt.Value);
                        temp1 = GeometryUtility.DividePoly(ref weldingPolyOffset, weldingArcsOffsetRslt.Value);

                        //проверка вярна ли е посоката на офсетиране
                        var tP    = sidePoint.TransformBy(GeometryUtility.GetTransforMatrixToWcs());
                        var dist1 = temp[0].DistanceTo(tP);
                        var dist2 = temp1[0].DistanceTo(tP);

                        foreach (Point3d p in temp)
                        {
                            if (p.DistanceTo(tP) < dist1)
                            {
                                dist1 = p.DistanceTo(tP);
                            }
                        }
                        foreach (Point3d p in temp1)
                        {
                            if (p.DistanceTo(tP) < dist2)
                            {
                                dist2 = p.DistanceTo(tP);
                            }
                        }

                        //ако не е вярна посоката на офсетиране
                        #region
                        if (dist1 < dist2)    //ако посоката е грешна изтриваме тестовата и правим в обратна поскока на зададеното разстояние
                        {
                            weldingPolyOffset.Erase();
                            acDbObjColl = weldingPoly.GetOffsetCurves(-weldingArcsChordRslt.Value);
                            foreach (Entity acEnt in acDbObjColl)
                            {
                                // Add each offset object
                                acBlkTblRec.AppendEntity(acEnt);
                                tr.AddNewlyCreatedDBObject(acEnt, true);
                            }
                            try
                            {
                                weldingPolyOffset = tr.GetObject(acDbObjColl[0].ObjectId, OpenMode.ForWrite) as Polyline;
                            }
                            catch
                            {
                                MessageBox.Show("Offset error", "E R R O R");
                                return;
                            }
                            temp1 = GeometryUtility.DividePoly(ref weldingPolyOffset, weldingArcsOffsetRslt.Value);
                        }
                        else     //ако посоката е вярна изтриваме тестовата и правим в същата поскока на зададеното разстояние // Lishkov 07/07/2012
                        {
                            weldingPolyOffset.Erase();
                            acDbObjColl = weldingPoly.GetOffsetCurves(weldingArcsChordRslt.Value);
                            foreach (Entity acEnt in acDbObjColl)
                            {
                                // Add each offset object
                                acBlkTblRec.AppendEntity(acEnt);
                                tr.AddNewlyCreatedDBObject(acEnt, true);
                            }
                            try
                            {
                                weldingPolyOffset = tr.GetObject(acDbObjColl[0].ObjectId, OpenMode.ForWrite) as Polyline;
                            }
                            catch
                            {
                                MessageBox.Show("Offset error", "E R R O R");
                                return;
                            }
                            temp1 = GeometryUtility.DividePoly(ref weldingPolyOffset, weldingArcsOffsetRslt.Value);
                        }
                        #endregion

                        //work
                        var oldUcs = _ed.CurrentUserCoordinateSystem;
                        _ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

                        for (var i = 0; i < temp.Count - 1; i++)
                        {
                            var tempP = temp1[0];
                            var oP    = temp1[0];
                            foreach (Point3d p in temp1)
                            {
                                if (temp[i].DistanceTo(p) < temp[i].DistanceTo(tempP))
                                {
                                    oP    = tempP;
                                    tempP = p;
                                }
                            }

                            var ucs = GeometryUtility.GetUcs(temp[i], temp[i + 1], tempP, true);

                            Arc acArc;
                            if (weldingSideRslt.StringResult != "Side")
                            {
                                acArc = new Arc(
                                    new Point3d(0, 0, 0),
                                    weldingArcsChordRslt.Value / 2,
                                    Math.PI / 2.0 + Math.PI,
                                    Math.PI / 2.0 + Math.PI + Math.PI
                                    );
                            }
                            else
                            {
                                // BricsCAD hack
                                acArc = new Arc(
                                    new Point3d(),
                                    weldingArcsChordRslt.Value / 2,
                                    Math.PI / 2.0 + Math.PI,
                                    Math.PI / 2.0 + Math.PI + Math.PI
                                    )
                                {
                                    Center = new Point3d(0, weldingArcsChordRslt.Value / 2, 0)
                                };
                            }

                            _weldingArcs.Add(acArc);
                            try
                            {
                                acArc.TransformBy(ucs);
                            }
                            catch
                            {
                                _weldingArcs.RemoveAt(_weldingArcs.Count - 1);
                                if (i > 0)
                                {
                                    var tP1 = new Point3d(0, 0, 0);
                                    var tP2 = new Point3d(temp[i].X - temp[i - 1].X, temp[i].Y - temp[i - 1].Y, temp[i].Z - temp[i - 1].Z);
                                    var tP3 = new Point3d(oP.X - temp[i - 1].X, oP.Y - temp[i - 1].Y, oP.Z - temp[i - 1].Z);

                                    ucs = GeometryUtility.GetUcs(tP1, tP2, tP3, true);
                                    try
                                    {
                                        _weldingArcs.Add(acArc);
                                        var lp1 = new Point3d(0, 0, 0);
                                        var lp2 = new Point3d(weldingArcsOffsetRslt.Value, 0, 0);
                                        var l   = new Line3d(acArc.StartPoint, acArc.EndPoint);
                                        acArc.TransformBy(Matrix3d.Displacement(lp1.GetVectorTo(lp2)));
                                        acArc.TransformBy(ucs);
                                        acArc.TransformBy(Matrix3d.Displacement(-temp[i - 1].GetVectorTo(Point3d.Origin)));
                                    }
                                    catch
                                    {
                                        _weldingArcs.RemoveAt(_weldingArcs.Count - 1);
                                    }
                                }
                            }
                            acArc.SetDatabaseDefaults();
                        }
                        if (!weldingPoly.Closed)
                        {
                            var acA   = (Arc)_weldingArcs[_weldingArcs.Count - 1];
                            var acArc = (Entity)acA.Clone();
                            acArc.TransformBy(Matrix3d.Displacement(temp[temp.Count - 2].GetVectorTo(temp[temp.Count - 1])));
                            _weldingArcs.Add(acArc);
                        }
                        weldingPolyOffset.Erase();
                        DrawWeldingLine(_weldingArcs, tr);
                        _ed.CurrentUserCoordinateSystem = oldUcs;
                    }
                    tr.Commit();
                }
                break;
                #endregion

                #region Circle
            case "Circle":
                // ElseIf the user picked up object of type 'arc' or 'circle'
                //    Call the function that makes welding over arc or circle.
                //    _Circle is an Arc with start angle of 0 and end angle of 360
                using (var tr = _doc.Database.TransactionManager.StartTransaction())
                {
                    var weldingCircle = tr.GetObject(selectedObjectId, OpenMode.ForRead) as Circle;
                    if (weldingCircle != null)
                    {
                        using (var T = _doc.Database.TransactionManager.StartTransaction())
                        {
                            var weldingLine = T.GetObject(selectedObjectId, OpenMode.ForWrite) as Circle;

                            var r = new Ray
                            {
                                BasePoint = weldingLine.Center,
                                UnitDir   = weldingLine.Center.GetVectorTo(weldingLine.StartPoint)
                            };

                            var pts = new Point3dCollection();
                            weldingLine.IntersectWith(r, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero);

                            var sPt = new Point3d(sidePoint.X + 0.00001, sidePoint.Y + 0.00001, sidePoint.Z);
                            sPt = sPt.TransformBy(GeometryUtility.GetTransforMatrixToWcs());
                            var ucs = GeometryUtility.GetUcs(weldingLine.Center, pts[0], sPt, false);
                            weldingLine.TransformBy(ucs);
                            if (weldingSideRslt.StringResult == "Side")
                            {
                                sidePoint = sidePoint.TransformBy(_ed.CurrentUserCoordinateSystem);
                                sidePoint = sidePoint.TransformBy(ucs);
                            }

                            var oldUcs = _ed.CurrentUserCoordinateSystem;
                            _ed.CurrentUserCoordinateSystem = Matrix3d.Identity;



                            var arcSide = GeometryUtility.SideOfPointToArc(weldingCircle.Center, weldingCircle.Radius, sidePoint);
                            var sAng    = -1 + weldingCircle.Center.DistanceTo(sidePoint) / weldingCircle.Radius;
                            _weldingArcs = BuildWeldingArcsOverArc(weldingCircle.Center,
                                                                   weldingCircle.Radius,
                                                                   0.0,
                                                                   2 * Math.PI,
                                                                   /* sAng ,  */
                                                                   weldingArcsChordRslt.Value,
                                                                   weldingArcsOffsetRslt.Value,
                                                                   0,
                                                                   arcSide);
                            DrawWeldingLine(_weldingArcs, T);

                            _ed.CurrentUserCoordinateSystem = oldUcs;
                            foreach (Arc a in _weldingArcs)
                            {
                                a.TransformBy(ucs.Inverse());
                            }
                            weldingLine.TransformBy(ucs.Inverse());

                            T.Commit();
                        }
                    }
                    else
                    {
                        MessageBox.Show("\nYou did not slected object of type Circle. Try again...");
                    }
                    tr.Commit();
                }
                break;
                #endregion

                #region Arc
            case "Arc":
                using (var tr = _doc.Database.TransactionManager.StartTransaction())
                {
                    var weldingArc = tr.GetObject(selectedObjectId, OpenMode.ForRead) as Arc;
                    if (weldingArc != null)
                    {
                        using (var T = _doc.Database.TransactionManager.StartTransaction())
                        {
                            var weldingLine = T.GetObject(selectedObjectId, OpenMode.ForWrite) as Arc;

                            var sPt = sidePoint.TransformBy(GeometryUtility.GetTransforMatrixToWcs());

                            var tP1 = new Point3d(0, 0, 0);
                            var tP2 = new Point3d(weldingLine.EndPoint.X - weldingLine.StartPoint.X, weldingLine.EndPoint.Y - weldingLine.StartPoint.Y, weldingLine.EndPoint.Z - weldingLine.StartPoint.Z);
                            var tP3 = new Point3d(sPt.X - weldingLine.StartPoint.X, sPt.Y - weldingLine.StartPoint.Y, sPt.Z - weldingLine.StartPoint.Z);

                            var ucs = GeometryUtility.GetUcs(tP1, tP2, tP3, false);
                            weldingLine.TransformBy(ucs);
                            if (weldingSideRslt.StringResult == "Side")
                            {
                                sidePoint = sidePoint.TransformBy(_ed.CurrentUserCoordinateSystem);
                                sidePoint = sidePoint.TransformBy(ucs);
                            }

                            var oldUcs = _ed.CurrentUserCoordinateSystem;
                            _ed.CurrentUserCoordinateSystem = Matrix3d.Identity;



                            var arcSide = GeometryUtility.SideOfPointToArc(weldingArc.Center, weldingArc.Radius, sidePoint);

                            var sAng = -1 + weldingArc.Center.DistanceTo(sidePoint) / weldingArc.Radius;

                            _weldingArcs = BuildWeldingArcsOverArc(weldingArc.Center,
                                                                   weldingArc.Radius,
                                                                   weldingArc.StartAngle,
                                                                   weldingArc.EndAngle,
                                                                   weldingArcsChordRslt.Value,
                                                                   weldingArcsOffsetRslt.Value,
                                                                   weldingArcsOffsetRslt.Value / 2,
                                                                   arcSide);

                            DrawWeldingLine(_weldingArcs, T);

                            _ed.CurrentUserCoordinateSystem = oldUcs;

                            foreach (Arc a in _weldingArcs)
                            {
                                a.TransformBy(ucs.Inverse());
                            }

                            weldingLine.TransformBy(ucs.Inverse());

                            T.Commit();
                        }
                    }
                    else
                    {
                        MessageBox.Show("\nYou did not slected object of type Arc. Try again...");
                    }
                    tr.Commit();
                }
                break;
                #endregion
            }
            #endregion
        }
コード例 #8
0
        public void MyCommand()
        {
            if (!this.ShowDialog())
            {
                return;
            }
            double            num1              = 1.0;
            double            num2              = 0.25;
            double            num3              = this.m * (double)this.z;
            double            da                = (2.0 * num1 + (double)this.z) * this.m;
            double            df                = ((double)this.z - 2.0 * num1 - 2.0 * num2) * this.m;
            double            db                = num3 * Math.Cos(this.a * Math.PI / 180.0);
            Point3d           point             = this.GetPoint();
            DateTime          now1              = DateTime.Now;
            Circle            circle1           = new Circle(point, Vector3d.get_ZAxis(), db / 2.0);
            Circle            cir1              = new Circle(point, Vector3d.get_ZAxis(), da / 2.0);
            Circle            circle2           = new Circle(point, Vector3d.get_ZAxis(), df / 2.0);
            Circle            pitchCircle       = new Circle(point, Vector3d.get_ZAxis(), num3 / 2.0);
            Point3dCollection point3dCollection = new Point3dCollection();
            Polyline3d        evolent1          = this.CreatEvolent(point, da, db, cir1);
            Polyline3d        evolent2          = this.MirrorEvolent(evolent1, pitchCircle, point);
            Arc  arc   = this.CreatArc(point, evolent1, evolent2);
            Line line1 = new Line(point, ((Curve)evolent1).get_StartPoint());
            Line line2 = new Line(point, ((Curve)evolent2).get_StartPoint());
            DBObjectCollection objectCollection1 = new DBObjectCollection();

            objectCollection1.Add((DBObject)evolent1);
            objectCollection1.Add((DBObject)evolent2);
            objectCollection1.Add((DBObject)line2);
            objectCollection1.Add((DBObject)line1);
            objectCollection1.Add((DBObject)arc);
            DBObjectCollection objectCollection2 = new DBObjectCollection();

            Entity[] entityArray = this.ArrayPolar((Entity)(Region.CreateFromCurves(objectCollection1).get_Item(0) as Region), point, this.z, 2.0 * Math.PI);
            objectCollection1.Clear();
            objectCollection1.Add((DBObject)circle2);
            Region region1 = Region.CreateFromCurves(objectCollection1).get_Item(0) as Region;

            foreach (Entity entity in entityArray)
            {
                Region region2 = entity as Region;
                if (DisposableWrapper.op_Inequality((DisposableWrapper)region2, (DisposableWrapper)null))
                {
                    region1.BooleanOperation((BooleanOperationType)0, region2);
                }
            }
            objectCollection1.Clear();
            Circle circle3 = new Circle(point, Vector3d.get_ZAxis(), 0.15 * (df - 10.0));

            objectCollection1.Add((DBObject)circle3);
            DBObjectCollection fromCurves = Region.CreateFromCurves(objectCollection1);

            region1.BooleanOperation((BooleanOperationType)2, fromCurves.get_Item(0) as Region);
            Solid3d solid3d = new Solid3d();

            solid3d.Extrude(region1, this.h, 0.0);
            solid3d.BooleanOperation((BooleanOperationType)2, this.NewBox(point, this.h, df));
            if (this.doDemo == "Y")
            {
                this.AddEntityToModelSpace((Entity)evolent1);
                this.AddEntityToModelSpace((Entity)evolent2);
                this.AddEntityToModelSpace((Entity)arc);
                this.AddEntityToModelSpace((Entity)line1);
                this.AddEntityToModelSpace((Entity)line2);
                this.AddEntityToModelSpace((Entity)(((RXObject)region1).Clone() as Region));
                Thread.Sleep(this.delay * 5);
            }
            this.ZoomToEntity((Entity)solid3d);
            this.AddEntityToModelSpace((Entity)solid3d);
            DateTime now2 = DateTime.Now;

            this.ed.WriteMessage("\n耗时{0}。", new object[1]
            {
                (object)this.Elapsed(now1, now2)
            });
        }