private bool GetOrMakeLayer(string layerName, AcadDb.Transaction tr, out string cleanName)
        {
            cleanName = Utils.RemoveInvalidChars(layerName);
            try
            {
                AcadDb.LayerTable lyrTbl = tr.GetObject(Doc.Database.LayerTableId, AcadDb.OpenMode.ForRead) as AcadDb.LayerTable;
                if (lyrTbl.Has(cleanName))
                {
                    return(true);
                }
                else
                {
                    lyrTbl.UpgradeOpen();
                    var _layer = new AcadDb.LayerTableRecord();

                    // Assign the layer properties
                    _layer.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByColor, 7); // white
                    _layer.Name  = cleanName;

                    // Append the new layer to the layer table and the transaction
                    lyrTbl.Add(_layer);
                    tr.AddNewlyCreatedDBObject(_layer, true);
                }
            }
            catch { return(false); }
            return(true);
        }
Esempio n. 2
0
        private static void AddText(Gem.Point2d pnt, string layer, string str)
        {
            App.Document acDoc   = App.Application.DocumentManager.MdiActiveDocument;
            Db.Database  acCurDb = acDoc.Database;

            // старт транзакции
            using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                // Открытие таблицы Блоков для чтения
                Db.BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, Db.OpenMode.ForRead) as Db.BlockTable;

                // Открытие записи таблицы Блоков пространства Модели для записи
                Db.BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[Db.BlockTableRecord.ModelSpace],
                                                                    Db.OpenMode.ForWrite) as Db.BlockTableRecord;

                Db.MText acMText = new Db.MText();
                acMText.SetDatabaseDefaults();
                acMText.Location = new Gem.Point3d(pnt.X, pnt.Y, 0);
                acMText.Contents = str;
                acMText.Height   = SettingsParser.getInstance()._Scale.Coord;
                acMText.Color    = Autodesk.AutoCAD.Colors.
                                   Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByLayer, 256);
                acMText.Layer = layer;
                acMText.SetDatabaseDefaults();
                // Добавление нового объекта в запись таблицы блоков и в транзакцию
                acBlkTblRec.AppendEntity(acMText);
                acTrans.AddNewlyCreatedDBObject(acMText, true);
                // Сохранение нового объекта в базе данных
                acTrans.Commit();
            }
        }
Esempio n. 3
0
        private static void AddCircle(Gem.Point2d pnt, string layer)
        {
            App.Document acDoc   = App.Application.DocumentManager.MdiActiveDocument;
            Db.Database  acCurDb = acDoc.Database;

            // старт транзакции
            using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                // Открытие таблицы Блоков для чтения
                Db.BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                           Db.OpenMode.ForRead) as Db.BlockTable;

                // Открытие записи таблицы Блоков пространства Модели для записи
                Db.BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[Db.BlockTableRecord.ModelSpace],
                                                                    Db.OpenMode.ForWrite) as Db.BlockTableRecord;

                Db.Circle acCircle = new Db.Circle();
                acCircle.SetDatabaseDefaults();
                acCircle.Center = new Gem.Point3d(pnt.X, pnt.Y, 0);
                acCircle.Radius = SettingsParser.getInstance()._Scale.Circle;
                acCircle.Layer  = layer;
                // Добавление нового объекта в запись таблицы блоков и в транзакцию
                acBlkTblRec.AppendEntity(acCircle);
                acTrans.AddNewlyCreatedDBObject(acCircle, true);
                // Сохранение нового объекта в базе данных
                acTrans.Commit();
            }
        }
Esempio n. 4
0
        public static ACADDB.Region AddRegion(ACADDB.ObjectId acadObjectId)
        {
            ACADDB.Region returnvalue = null;
            // Get the current document and database
            Document acDoc = Application.DocumentManager.MdiActiveDocument;

            ACADDB.Database acCurDb = acDoc.Database;

            // Start a transaction
            using (ACADDB.Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                ACADDB.BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             ACADDB.OpenMode.ForRead) as ACADDB.BlockTable;

                // Open the Block table record Model space for write
                ACADDB.BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[ACADDB.BlockTableRecord.ModelSpace],
                                                ACADDB.OpenMode.ForWrite) as ACADDB.BlockTableRecord;

                ACADDB.Polyline polyline = acTrans.GetObject(acadObjectId,
                                                             ACADDB.OpenMode.ForRead) as ACADDB.Polyline;
                if (polyline != null)

                {
                    ACADDB.DBObjectCollection acDBObjColl = new ACADDB.DBObjectCollection();
                    acDBObjColl.Add((ACADDB.DBObject)polyline.AcadObject);

                    // Calculate the regions based on each closed loop
                    ACADDB.DBObjectCollection myRegionColl = new ACADDB.DBObjectCollection();
                    myRegionColl = ACADDB.Region.CreateFromCurves(acDBObjColl);
                    ACADDB.Region acRegion = myRegionColl[0] as ACADDB.Region;
                    returnvalue = acRegion;
                    // Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acRegion);
                    acTrans.AddNewlyCreatedDBObject(acRegion, true);

                    // Dispose
                }

                // Save the new object to the database
                acTrans.Commit();
            }
            return(returnvalue);
        }
Esempio n. 5
0
        private static void AddMLeader(Gem.Point2d pnt, Gem.Vector3d otstup,
                                       double scale, string layer,
                                       string mleaderStyleName, string str)
        {
            SettingsParser settings = SettingsParser.getInstance();

            App.Document acDoc   = App.Application.DocumentManager.MdiActiveDocument;
            Db.Database  acCurDb = acDoc.Database;
            using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                Db.BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                           Db.OpenMode.ForRead) as Db.BlockTable;
                Db.BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[Db.BlockTableRecord.ModelSpace],
                                                                    Db.OpenMode.ForWrite) as Db.BlockTableRecord;
                Db.MLeader acML = new Db.MLeader();
                acML.SetDatabaseDefaults();
                acML.Layer        = layer;
                acML.MLeaderStyle = CheckLocalRepository.GetIDbyName <Db.MLeaderStyle>(acCurDb, mleaderStyleName);
                acML.ContentType  = Db.ContentType.MTextContent;
                Db.MText mText = new Db.MText();
                mText.SetDatabaseDefaults();
                mText.Contents           = str;
                mText.TextHeight         = scale;
                mText.BackgroundFill     = settings.MTextMask;
                mText.UseBackgroundColor = settings.MTextMask;


                if (settings.MTextMask)
                {
                    mText.BackgroundScaleFactor = settings.MTextMaskKoefficient;
                }

                mText.Location = (new Gem.Point3d(pnt.X, pnt.Y, 0) + otstup);
                acML.MText     = mText;
                int idx = acML.AddLeaderLine(new Gem.Point3d(pnt.X, pnt.Y, 0));

                acML.Scale = 1;


                acBlkTblRec.AppendEntity(acML);
                acTrans.AddNewlyCreatedDBObject(acML, true);
                acTrans.Commit();
            }
        }
Esempio n. 6
0
        static public void AddNewEnt(AcadDB.Entity ent)
        {
            AcadDB.Database db = GetActiveDB();

            using (AcadDB.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcadDB.BlockTableRecord model_space = GetModelSpace(tr);
                if (null == model_space)
                {
                    return;
                }

                model_space.UpgradeOpen();
                model_space.AppendEntity(ent);

                tr.AddNewlyCreatedDBObject(ent, true);

                tr.Commit();
            }
        }
Esempio n. 7
0
        public void CreateNotification()
        {
            using (AcadDb.Transaction tr = AcadFuncs.GetActiveDb().TransactionManager.StartTransaction())
            {
                AcadDb.Polyline pl = new AcadDb.Polyline();
                pl.AddVertexAt(0, new AcadGeo.Point2d(0.0, 0.0), 0.0, 0.0, 0.0);
                pl.AddVertexAt(1, new AcadGeo.Point2d(10.0, 0.0), 0.0, 0.0, 0.0);

                AcadDb.BlockTableRecord model_space = AcadFuncs.GetModelSpace(tr);

                model_space.UpgradeOpen();
                model_space.AppendEntity(pl);
                tr.AddNewlyCreatedDBObject(pl, true);

                pl.ObjectClosed += new AcadDb.ObjectClosedEventHandler(ClosedHandler);
                //pl.Modified += new EventHandler(ModifiedHandler);
                curr_pl = pl;

                tr.Commit();
            }
        }
Esempio n. 8
0
        //[Autodesk.AutoCAD.Runtime.CommandMethod("pline")]
        public void Polyline()
        {
            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    PromptSelectionResult sel = Editor.SelectPrevious(); //SelectImplied(); //
                    Curve ProcessCurve        = trans.GetObject(sel.Value[0].ObjectId, OpenMode.ForRead) as Curve;
                    Editor.WriteMessage(ProcessCurve.ToString());

                    Curve toolpathCurve = ProcessCurve.GetOffsetCurves(50)[0] as Curve;  // TODO расчет OffsetCurves + ModifiedEventHandler

                    BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                    BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;

                    toolpathCurve.LayerId = GetProcessLayer(trans);
                    BlkTblRec.AppendEntity(toolpathCurve);
                    trans.AddNewlyCreatedDBObject(toolpathCurve, true);
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }
        /// <summary>
        /// insert signatures
        /// </summary>
        /// <param name="dwgPath"></param>
        /// <param name="dwgNameList"></param>
        public void InsertSign(string dwgPath, List <string> dwgNameList)
        {
            AdeskAppSvr.Document doc = AdeskAppSvr.Application.DocumentManager.MdiActiveDocument;
            this.Hide();
            AdeskDBSvr.Database         CurrDB          = doc.Database;//current database
            AdeskEdIn.Editor            ed              = doc.Editor;
            AdeskEdIn.PromptPointResult prPointRes_Base = ed.GetPoint(new AdeskEdIn.PromptPointOptions("选择插入的基点"));
            AdeskEdIn.PromptPointResult prPointRes_opp  = ed.GetPoint(new AdeskEdIn.PromptPointOptions("选择基点的对角点"));
            //In order to make the signs look nicely , calculate the base point and its opposite point
            AdeskGeo.Point3d P_base = CalPoint(prPointRes_Base.Value, prPointRes_opp.Value, 0.1);
            AdeskGeo.Point3d P_opp  = CalPoint(prPointRes_Base.Value, prPointRes_opp.Value, 0.9);
            //sign's width and height
            double SignWidth  = P_opp.X - P_base.X;
            double SignHeight = P_opp.Y - P_base.Y;
            //distance between each other
            double distanceW = prPointRes_opp.Value.X - prPointRes_Base.Value.X;
            double distanceH = prPointRes_opp.Value.Y - prPointRes_Base.Value.Y;
            //scale of signature. 36 is the width of sign, and 17 is the height. you should adjust them in your condition.
            double scaleWidth  = SignWidth / 36;
            double scaleHeight = SignHeight / 17;
            //today
            string date = System.DateTime.Today.ToLocalTime().ToString().Split(' ')[0];

            try
            {
                for (int i = 0; i < dwgNameList.Count; i++)
                {
                    using (AdeskDBSvr.Database tmpdb = new AdeskDBSvr.Database(false, false))
                    {
                        //read drawing
                        tmpdb.ReadDwgFile(dwgPath + dwgNameList[i], FileShare.Read, true, null);
                        //insert it as a new block
                        AdeskDBSvr.ObjectId idBTR = CurrDB.Insert(this.ICCardList[i], tmpdb, false);

                        using (AdeskDBSvr.Transaction trans = CurrDB.TransactionManager.StartTransaction())
                        {
                            AdeskDBSvr.BlockTable       bt  = (AdeskDBSvr.BlockTable)trans.GetObject(CurrDB.BlockTableId, AdeskDBSvr.OpenMode.ForRead);
                            AdeskDBSvr.BlockTableRecord btr = (AdeskDBSvr.BlockTableRecord)trans.GetObject(bt[AdeskDBSvr.BlockTableRecord.ModelSpace], AdeskDBSvr.OpenMode.ForWrite);
                            //insert point
                            AdeskGeo.Point3d inPt = new AdeskGeo.Point3d(P_base.X, P_base.Y - i * distanceH, P_base.Z);

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

                            TextStyleTBRec.Font = new AdeskGra.FontDescriptor("宋体", true, false, 0, 0);
                            TextStyleTB.Add(TextStyleTBRec);
                            trans.AddNewlyCreatedDBObject(TextStyleTBRec, true);
                            //trans.Commit();

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

                            try
                            {
                                //create a ref to the block
                                using (AdeskDBSvr.BlockReference bref = new AdeskDBSvr.BlockReference(inPt, idBTR))
                                {
                                    bref.ScaleFactors = new AdeskGeo.Scale3d(scaleWidth, scaleHeight, 1.0);
                                    btr.AppendEntity(bref);
                                    trans.AddNewlyCreatedDBObject(bref, true);
                                }
                                trans.Commit();
                            }
                            catch (System.Exception err)
                            {
                                MessageBox.Show("one: " + err.Message);
                            }
                        }
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception err)
            {
                MessageBox.Show("insert: " + err.Message);
            }
            this.Show();
        }
Esempio n. 10
0
        public void ConstructToolpathObject(ProcessObject obj)
        {
            if (obj.Side == SideType.None)
            {
                return;
            }
            if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Ravelli)
            {
                ConstructToolpathObjectRavelli(obj);
                return;
            }
            if (obj.ObjectType == ObjectType.Arc && (
                    (obj.ProcessArc.StartAngle < cPI2 && obj.ProcessArc.EndAngle > cPI2) ||
                    (obj.ProcessArc.StartAngle < cPI + cPI2 && (obj.ProcessArc.EndAngle > cPI + cPI2 || obj.ProcessArc.EndAngle < obj.ProcessArc.StartAngle))))
            {
                Application.ShowAlertDialog("Обработка дуги невозможна - дуга пересекает угол 90 или 270 градусов. Текущие углы: начальный " +
                                            (180 / cPI * obj.ProcessArc.StartAngle).ToString() + ", конечный " + (180 / cPI * obj.ProcessArc.EndAngle).ToString());
                //Application.ShowAlertDialog($"Обработка дуги {obj} невозможна - дуга пересекает угол 90 или 270 градусов. Текущие углы: начальный {180 / cPI * obj.ProcessArc.StartAngle}, конечный {180 / cPI * obj.ProcessArc.EndAngle}");
                return;
            }
            double s = Math.Sqrt(obj.DepthAll * (obj.Diameter - obj.DepthAll)) + ExactlyIncrease;

            if ((obj.IsBeginExactly || obj.IsEndExactly) && (obj.Length <= s))
            {
                Application.ShowAlertDialog("Обработка объекта " + obj.ToString() + " невозможна вследствие слишком малой длины");
                return;
            }
            Curve toolpathCurve = obj.ProcessCurve.GetOffsetCurves(GetOffsetValue(obj))[0] as Curve;  // TODO расчет OffsetCurves + ModifiedEventHandler

            switch (obj.ObjectType)
            {
            case ObjectType.Line:

                if (obj.IsBeginExactly)
                {
                    toolpathCurve.StartPoint = toolpathCurve.GetPointAtDist(s);
                }
                if (obj.IsEndExactly)
                {
                    toolpathCurve.EndPoint = toolpathCurve.GetPointAtDist((toolpathCurve as Line).Length - s);
                }
                break;

            case ObjectType.Arc:

                if (obj.IsBeginExactly)
                {
                    (toolpathCurve as Arc).StartAngle = obj.ProcessArc.StartAngle + s / obj.ProcessArc.Radius;
                }
                if (obj.IsEndExactly)
                {
                    (toolpathCurve as Arc).EndAngle = obj.ProcessArc.EndAngle - s / obj.ProcessArc.Radius;
                }
                break;
            }
            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    if (obj.ToolpathCurve == null)  // TODO удаление объекта
                    {
                        BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                        BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;

                        toolpathCurve.LayerId = GetProcessLayer(trans);
                        BlkTblRec.AppendEntity(toolpathCurve);
                        trans.AddNewlyCreatedDBObject(toolpathCurve, true);
                        toolpathCurve.Erased += new ObjectErasedEventHandler(ToolpathCurveErasedEventHandler);
                        obj.ToolpathCurve     = toolpathCurve;
                    }
                    else
                    {
                        trans.GetObject(obj.ToolpathCurve.ObjectId, AcDb.OpenMode.ForWrite);
                        switch (obj.ObjectType)
                        {                                   // TODO копия объекта
                        case ObjectType.Line:
                            obj.ToolpathCurve.StartPoint = toolpathCurve.StartPoint;
                            obj.ToolpathCurve.EndPoint   = toolpathCurve.EndPoint;
                            break;

                        case ObjectType.Arc:
                            (obj.ToolpathCurve as Arc).Center     = (toolpathCurve as Arc).Center;
                            (obj.ToolpathCurve as Arc).Radius     = (toolpathCurve as Arc).Radius;
                            (obj.ToolpathCurve as Arc).StartAngle = (toolpathCurve as Arc).StartAngle;
                            (obj.ToolpathCurve as Arc).EndAngle   = (toolpathCurve as Arc).EndAngle;
                            break;
                        }
                    }
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }
        private void StreamExplodeSample()
        {
            // intro message
            Editor editor = GetEditor();

            editor.WriteMessage("* StreamExplode *\n");
            editor.WriteMessage("StreamExplode converts all entities to AutoCAD primitive entities.\n");
            editor.WriteMessage("Pick an object in the current drawing. The object you picked will be packaged to an anonymous block and finally referenced in the current space. The block-referenced object will be overlapping with the original one.\n");

            // pick a object to be exploded
            ObjectId id = PickObject(typeof(Entity), false);

            if (id.IsNull)
            {
                editor.WriteMessage("No object is picked\n");
                return;
            }

            Database           db            = GetDatabase();
            DBObjectCollection objects       = new DBObjectCollection();
            StreamExplode      streamExplode = new StreamExplode(db, objects);

            streamExplode.IsVisualExplode = true;
            streamExplode.SetForBoundarySearch(false);

            TransactionManager tm = db.TransactionManager;

            using (Transaction trans = tm.StartTransaction())
            {
                Entity ent = trans.GetObject(id, OpenMode.ForRead) as Entity;

                streamExplode.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans);
                streamExplode.PushEntity(ent);
                streamExplode.PushProperties(ent);

                streamExplode.Stream(ent);
                streamExplode.PackageExplodedEntities();

                streamExplode.PopProperties();
                streamExplode.PopEntity();
                streamExplode.PopDisplayParameters();

                trans.Commit();
            }

            BlockReference blockRef = null;

            foreach (DBObject obj in objects)
            {
                if (obj.GetType() == typeof(BlockReference))
                {
                    blockRef = obj as BlockReference;
                }
            }

            if (blockRef == null)
            {
                return;
            }

            blockRef.Position = Point3d.Origin;

            using (Transaction trans = tm.StartTransaction())
            {
                BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                btr.AppendEntity(blockRef);
                trans.AddNewlyCreatedDBObject(blockRef, true);
                trans.Commit();
            }
        }
Esempio n. 12
0
        public void CreateLayout()
        {
            using (AcadDb.Transaction tr = AcadFuncs.GetActiveDb().TransactionManager.StartTransaction())
            {
                AcadDb.LayoutManager layout_man = AcadDb.LayoutManager.Current;
                AcadDb.ObjectId      layout_id  = layout_man.CreateLayout("My_Layout");
                layout_man.SetCurrentLayoutId(layout_id);

                AcadDb.Layout layout = tr.GetObject(layout_id, AcadDb.OpenMode.ForRead) as AcadDb.Layout;
                if (null == layout)
                {
                    return;
                }

                AcadDb.BlockTableRecord blk_tbl_rcd = tr.GetObject(layout.BlockTableRecordId, AcadDb.OpenMode.ForRead)
                                                      as AcadDb.BlockTableRecord;
                if (null == blk_tbl_rcd)
                {
                    return;
                }

                AcadDb.ObjectIdCollection vp_ids = layout.GetViewports();
                AcadDb.Viewport           vp     = null;

                foreach (AcadDb.ObjectId vp_id in vp_ids)
                {
                    AcadDb.Viewport vp2 = tr.GetObject(vp_id, AcadDb.OpenMode.ForWrite) as AcadDb.Viewport;
                    if (null != vp2 && 2 == vp2.Number)
                    {
                        vp = vp2;
                        break;
                    }
                }

                if (null == vp)
                {
                    vp = new AcadDb.Viewport();
                    blk_tbl_rcd.UpgradeOpen();
                    blk_tbl_rcd.AppendEntity(vp);
                    tr.AddNewlyCreatedDBObject(vp, true);
                    vp.On     = true;
                    vp.GridOn = true;
                }

                vp.ViewCenter = new AcadGeo.Point2d(0.0, 0.0);
                double scale = 0;
                {
                    AcadEd.PromptDoubleOptions prmpt_pnt = new AcadEd.PromptDoubleOptions("Nhập scale:");
                    AcadEd.PromptDoubleResult  prmpt_ret = AcadFuncs.GetEditor().GetDouble(prmpt_pnt);
                    if (AcadEd.PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return;
                    }

                    scale = prmpt_ret.Value;
                }
                vp.CustomScale = scale;
                vp.Locked      = true;

                tr.Commit();
            }
        }
Esempio n. 13
0
        private void ConstructPlaneToolpath(ProcessObject obj)
        {
            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                    BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;
                    if (obj.ProcessActions != null)
                    {
                        obj.ProcessActions.ForEach(p => trans.GetObject(p.Toolpath.ObjectId, OpenMode.ForWrite).Erase());
                    }

                    obj.ProcessActions = new List <ProcessAction>();
                    var layerId  = GetProcessLayer(trans);
                    var tanAngle = Math.Tan(obj.VerticalAngle);

                    double angleStart = 0;
                    double angleEnd   = 0;
                    if (obj.ObjectType == ObjectType.Arc)
                    {
                        angleStart = CalcAngle(obj, (obj.ProcessCurve as Arc).StartAngle);
                        angleEnd   = CalcAngle(obj, (obj.ProcessCurve as Arc).EndAngle);
                    }
                    var sign     = obj.Side == SideType.Left ^ obj.ObjectType == ObjectType.Arc ? -1 : 1;
                    var tCurve0  = GetDisplacementCopy(obj.ProcessCurve, -ProcessOptions.Thickness);
                    var tCurve   = GetOffsetCopy(tCurve0, -sign * obj.Depth);
                    var tCurve01 = tCurve;
                    var isStart  = true;
                    var point    = tCurve.StartPoint;
                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Опускание",
                        Toolpath = new Line(new Point3d(point.X, point.Y, ProcessOptions.ZSafety), point),
                        Point    = point,
                        Angle    = isStart ? angleStart : angleEnd,
                    });
                    var point0 = point;
                    var d      = 0;
                    do
                    {
                        d += obj.Depth;
                        if (d > obj.DepthAll)
                        {
                            d = obj.DepthAll;
                        }
                        tCurve = GetOffsetCopy(tCurve0, sign * d);
                        point  = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                        obj.ProcessActions.Add(new ProcessAction
                        {
                            Command  = "Заглубление",
                            Toolpath = new Line(point0, point),
                            Point    = point,
                            Angle    = isStart ? angleStart : angleEnd
                        });
                        isStart = !isStart;
                        point0  = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                        obj.ProcessActions.Add(new ProcessAction
                        {
                            Command     = "Рез",
                            Toolpath    = tCurve,
                            Point       = point0,
                            Angle       = isStart ? angleStart : angleEnd,
                            IsClockwise = isStart
                        });
                    }while (d < obj.DepthAll);
                    point = isStart ? tCurve01.StartPoint : tCurve01.EndPoint;
                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Отвод",
                        Toolpath = new Line(point0, point),
                        Point    = point,
                        Angle    = isStart ? angleStart : angleEnd
                    });
                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Подъем",
                        Toolpath = new Line(point, new Point3d(point.X, point.Y, ProcessOptions.ZSafety)),
                        Point    = new Point3d(point.X, point.Y, ProcessOptions.ZSafety),
                        Angle    = isStart ? angleStart : angleEnd
                    });

                    obj.ProcessActions.ForEach(p =>
                    {
                        p.Toolpath.LayerId = layerId;
                        BlkTblRec.AppendEntity(p.Toolpath);
                        trans.AddNewlyCreatedDBObject(p.Toolpath, true);
                        p.Toolpath.Erased += new ObjectErasedEventHandler(ToolpathCurveErasedEventHandlerRavelli);
                    });
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }
Esempio n. 14
0
        private void Намечание(ProcessObject obj, double s)
        {
            if (!(obj is ProcessObjectLine))
            {
                return;
            }
            double  h;
            Point3d pointC;

            if (obj.IsBeginExactly && obj.IsEndExactly)
            {
                var l = obj.Length - 2 * ExactlyIncrease;
                h      = (obj.Diameter - Math.Sqrt(obj.Diameter * obj.Diameter - l * l)) / 2;
                pointC = obj.ProcessCurve.GetPointAtParameter(obj.ProcessCurve.EndParam / 2);
            }
            else
            {
                h      = obj.DepthAll;
                pointC = obj.ProcessCurve.StartPoint + obj.ProcessCurve.GetFirstDerivative(0).GetNormal() * (obj.IsBeginExactly ? s : obj.Length - s);
            }

            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                    BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;
                    if (obj.ProcessActions != null)
                    {
                        obj.ProcessActions.ForEach(p => trans.GetObject(p.Toolpath.ObjectId, OpenMode.ForWrite).Erase());
                    }

                    obj.ProcessActions = new List <ProcessAction>();
                    var layerId = GetProcessLayer(trans);

                    var point0 = new Point3d(pointC.X, pointC.Y, ProcessOptions.ZSafety);
                    var point1 = new Point3d(pointC.X, pointC.Y, -h);

                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Заглубление",
                        Toolpath = new Line(point0, point1),
                        Point    = point1
                    });
                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Подъем",
                        Toolpath = new Line(point1, point0),
                        Point    = point0
                    });

                    obj.ProcessActions.ForEach(p =>
                    {
                        p.Toolpath.LayerId = layerId;
                        BlkTblRec.AppendEntity(p.Toolpath);
                        trans.AddNewlyCreatedDBObject(p.Toolpath, true);
                        p.Toolpath.Erased += new ObjectErasedEventHandler(ToolpathCurveErasedEventHandlerRavelli);
                    });
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }
Esempio n. 15
0
        public void ConstructToolpathObjectRavelli(ProcessObject obj)
        {
            if (obj.Side == SideType.None)
            {
                return;
            }
            if (obj.VerticalAngleDeg == 90)
            {
                ConstructPlaneToolpath(obj);
                return;
            }
            double s = Math.Sqrt(obj.DepthAll * (obj.Diameter - obj.DepthAll / Math.Cos(obj.VerticalAngle))) + ExactlyIncrease;

            if ((obj.IsBeginExactly || obj.IsEndExactly) && (obj.Length <= s) || (obj.IsBeginExactly && obj.IsEndExactly) && (obj.Length <= 2 * s))
            {
                Намечание(obj, s);
                return;
            }
            Curve toolpathCurve = GetOffsetCopy(obj.ProcessCurve, GetOffsetValueRavelli(obj));  // TODO расчет OffsetCurves + ModifiedEventHandler

            switch (obj.ObjectType)
            {
            case ObjectType.Line:

                if (obj.IsBeginExactly)
                {
                    toolpathCurve.StartPoint = toolpathCurve.GetPointAtDist(s);
                }
                if (obj.IsEndExactly)
                {
                    toolpathCurve.EndPoint = toolpathCurve.GetPointAtDist((toolpathCurve as Line).Length - s);
                }
                break;

            case ObjectType.Arc:

                if (obj.IsBeginExactly)
                {
                    (toolpathCurve as Arc).StartAngle = obj.ProcessArc.StartAngle + s / obj.ProcessArc.Radius;
                }
                if (obj.IsEndExactly)
                {
                    (toolpathCurve as Arc).EndAngle = obj.ProcessArc.EndAngle - s / obj.ProcessArc.Radius;
                }
                break;
            }
            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                    BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;
                    if (obj.ProcessActions != null)
                    {
                        obj.ProcessActions.ForEach(p => trans.GetObject(p.Toolpath.ObjectId, OpenMode.ForWrite).Erase());
                    }

                    obj.ProcessActions = new List <ProcessAction>();
                    var layerId  = GetProcessLayer(trans);
                    var tanAngle = Math.Tan(obj.VerticalAngle);

                    double angleStart = 0;
                    double angleEnd   = 0;
                    if (obj.ObjectType == ObjectType.Arc)
                    {
                        angleStart = CalcAngle(obj, (toolpathCurve as Arc).StartAngle);
                        angleEnd   = CalcAngle(obj, (toolpathCurve as Arc).EndAngle);
                    }
                    if (!obj.TopEdge)
                    {
                        s = (ProcessOptions.Thickness + ProcessOptions.ZSafety) * tanAngle;
                        var     sign    = obj.Side == SideType.Left ^ obj.ObjectType == ObjectType.Arc ? -1 : 1;
                        var     tCurve0 = GetDisplacementCopy(GetOffsetCopy(toolpathCurve, sign * s), ProcessOptions.ZSafety);
                        var     isStart = true;
                        var     point0  = tCurve0.StartPoint;
                        Point3d point;
                        int     d = 0;
                        if (obj.ObjectType == ObjectType.Arc)
                        {
                            d = -obj.Depth;
                        }

                        do
                        {
                            d += obj.Depth;
                            if (d > obj.DepthAll)
                            {
                                d = obj.DepthAll;
                            }
                            s = (ProcessOptions.Thickness - d) * tanAngle;
                            var tCurve = GetDisplacementCopy(GetOffsetCopy(toolpathCurve, sign * s), -d);
                            point = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                            obj.ProcessActions.Add(new ProcessAction
                            {
                                Command     = "Заглубление",
                                Toolpath    = new Line(point0, point),
                                Point       = point,
                                Angle       = isStart ? angleStart : angleEnd,
                                IsClockwise = isStart
                            });
                            isStart = !isStart;
                            point0  = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                            obj.ProcessActions.Add(new ProcessAction
                            {
                                Command     = "Рез",
                                Toolpath    = tCurve,
                                Point       = point0,
                                Angle       = isStart ? angleStart : angleEnd,
                                IsClockwise = isStart
                            });
                        }while (d < obj.DepthAll);
                        point = isStart ? tCurve0.StartPoint : tCurve0.EndPoint;
                        obj.ProcessActions.Add(new ProcessAction
                        {
                            Command     = "Подъем",
                            Toolpath    = new Line(point0, point),
                            Point       = point,
                            Angle       = isStart ? angleStart : angleEnd,
                            IsClockwise = isStart
                        });
                    }
                    else
                    {
                        s = ProcessOptions.ZSafety * tanAngle;
                        var     sign    = obj.Side == SideType.Left ^ obj.ObjectType == ObjectType.Arc ? -1 : 1;
                        var     tCurve0 = GetDisplacementCopy(GetOffsetCopy(toolpathCurve, sign * (-s)), ProcessOptions.ZSafety);
                        var     isStart = true;
                        var     point0  = tCurve0.StartPoint;
                        Point3d point;
                        int     d = 0;
                        if (obj.ObjectType == ObjectType.Arc)
                        {
                            d = -obj.Depth;
                        }
                        do
                        {
                            d += obj.Depth;
                            if (d > obj.DepthAll)
                            {
                                d = obj.DepthAll;
                            }
                            s = d * tanAngle;
                            var tCurve = GetDisplacementCopy(GetOffsetCopy(toolpathCurve, sign * s), -d);
                            point = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                            obj.ProcessActions.Add(new ProcessAction
                            {
                                Command     = "Заглубление",
                                Toolpath    = new Line(point0, point),
                                Point       = point,
                                Angle       = isStart ? angleStart : angleEnd,
                                IsClockwise = isStart
                            });
                            isStart = !isStart;
                            point0  = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                            obj.ProcessActions.Add(new ProcessAction
                            {
                                Command     = "Рез",
                                Toolpath    = tCurve,
                                Point       = point0,
                                Angle       = isStart ? angleStart : angleEnd,
                                IsClockwise = isStart
                            });
                        }while (d < obj.DepthAll);
                        point = isStart ? tCurve0.StartPoint : tCurve0.EndPoint;
                        obj.ProcessActions.Add(new ProcessAction
                        {
                            Command     = "Подъем",
                            Toolpath    = new Line(point0, point),
                            Point       = point,
                            Angle       = isStart ? angleStart : angleEnd,
                            IsClockwise = isStart
                        });
                    }

                    obj.ProcessActions.ForEach(p =>
                    {
                        p.Toolpath.LayerId = layerId;
                        BlkTblRec.AppendEntity(p.Toolpath);
                        trans.AddNewlyCreatedDBObject(p.Toolpath, true);
                        p.Toolpath.Erased += new ObjectErasedEventHandler(ToolpathCurveErasedEventHandlerRavelli);
                    });
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }