Ejemplo n.º 1
0
        // pass a view style you want, the gs view will update to it
        public void ChangeViewStyleTo(VisualStyleType vs)
        {
            VisualStyle oldVs = mPreviewCtrl.mpView.VisualStyle;

            mPreviewCtrl.mpView.VisualStyle = new VisualStyle(vs);
            if (oldVs != null)
            {
                oldVs.Dispose();
            }
            EnumToolStripMenuItem.UpdateCheckedState(viewStyleToolStripMenuItem.DropDown.Items, vs);
            refreshView();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Установка визуального стиля текущему виду
        /// </summary>
        public static void SetActiveVisualStyle([NotNull] this Document doc, VisualStyleType style)
        {
            var db = doc.Database;
            var ed = doc.Editor;

            using (doc.LockDocument())
                using (var t = db.TransactionManager.StartTransaction())
                {
                    var vt   = (ViewportTable)db.ViewportTableId.GetObject(OpenMode.ForRead);
                    var vtr  = (ViewportTableRecord)vt["*Active"].GetObject(OpenMode.ForWrite);
                    var dict = (DBDictionary)db.VisualStyleDictionaryId.GetObject(OpenMode.ForRead);
                    vtr.VisualStyleId = dict.GetAt(GetStyleName(style));
                    t.Commit();
                    ed.UpdateTiledViewportsFromDatabase();
                }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Snapshots a block table record to a file.
        /// </summary>
        /// <param name="file">The file where the snapshot is taken.</param>
        /// <param name="blockname">The name of block.</param>
        /// <param name="vst">The Visual style of the block.</param>
        public static void Snapshot(this FileInfo file, string blockname, VisualStyleType vst)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;
            Manager  gsm = doc.GraphicsManager;
            int      vpn = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));
            View     gsv = gsm.GetCurrentAcGsView(vpn);

            using (View view = new View())
            {
                view.SetView(
                    gsv.Position,
                    gsv.Target,
                    gsv.UpVector,
                    gsv.FieldWidth,
                    gsv.FieldHeight);
            }
        }
Ejemplo n.º 4
0
 public VisualStyleUsing([NotNull] Document doc, VisualStyleType style)
 {
     previousStyle = doc.Database.GetActiveVisualStyle();
     doc.SetActiveVisualStyle(style);
     this.doc = doc;
 }
Ejemplo n.º 5
0
        public static void SnapshotToFile(
            string filename,
            VisualStyleType vst
            )
        {
            Document doc =
                Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            Manager gsm = doc.GraphicsManager;

            // Get some AutoCAD system variables
            int vpn =
                System.Convert.ToInt32(
                    Application.GetSystemVariable("CVPORT")
                    );

            using (View view = new View())
            {
                gsm.SetViewFromViewport(view, vpn);

                // Set the visual style to the one passed in
                view.VisualStyle = new VisualStyle(vst);
                Device dev =
                    gsm.CreateAutoCADOffScreenDevice(new GraphicsKernel());
                using (dev)
                {
                    dev.OnSize(new Size((int)gsm.DeviceIndependentDisplaySize.Height, (int)gsm.DeviceIndependentDisplaySize.Width));

                    // Set the render type and the background color
                    dev.DeviceRenderType = RendererType.Default;
                    dev.BackgroundColor  = Color.White;

                    // Add the view to the device and update it
                    dev.Add(view);
                    dev.Update();

                    using (Model model = gsm.CreateAutoCADModel(new GraphicsKernel()))
                    {
                        Transaction tr =
                            db.TransactionManager.StartTransaction();
                        using (tr)
                        {
                            // Add the modelspace to the view
                            // It's a container but also a drawable
                            BlockTable bt =
                                (BlockTable)tr.GetObject(
                                    db.BlockTableId,
                                    OpenMode.ForRead
                                    );
                            BlockTableRecord btr =
                                (BlockTableRecord)tr.GetObject(
                                    bt[BlockTableRecord.ModelSpace],
                                    OpenMode.ForRead
                                    );
                            view.Add(btr, model);
                            tr.Commit();
                        }

                        // Take the snapshot
                        Rectangle rect = new Rectangle
                                             (new System.Drawing.Point(
                                                 (int)view.ViewportExtents.MinPoint.X,
                                                 (int)view.ViewportExtents.MinPoint.Y),
                                             new Size((int)gsm.DeviceIndependentDisplaySize.Height,
                                                      (int)gsm.DeviceIndependentDisplaySize.Width)
                                             );
                        System.Threading.Thread.Sleep(1000);

                        using (Bitmap bitmap = view.GetSnapshot(rect))
                        {
                            System.Threading.Thread.Sleep(1000);

                            bitmap.Save(filename);

                            // Clean up
                            view.EraseAll();
                            dev.Erase(view);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static string GetStyleName(VisualStyleType style)
        {
            switch (style)
            {
            case VisualStyleType.Flat: return("Flat");

            case VisualStyleType.FlatWithEdges: return("FlatWithEdges");

            case VisualStyleType.Gouraud: return("Gouraud");

            case VisualStyleType.GouraudWithEdges: return("GouraudWithEdges");

            case VisualStyleType.Wireframe2D: return("2dWireframe");

            case VisualStyleType.Wireframe3D: return("3dWireframe");

            case VisualStyleType.Hidden: return("Hidden");

            case VisualStyleType.Basic: return("Basic");

            case VisualStyleType.Realistic: return("Realistic");

            case VisualStyleType.Conceptual: return("Conceptual");

            case VisualStyleType.Custom: return("Custom");

            case VisualStyleType.Dim: return("Dim");

            case VisualStyleType.Brighten: return("Brighten");

            case VisualStyleType.Thicken: return("Thicken");

            case VisualStyleType.LinePattern: return("Linepattern");

            case VisualStyleType.FacePattern: return("Facepattern");

            case VisualStyleType.ColorChange: return("ColorChange");

            case VisualStyleType.FaceOnly: return("FaceOnly");

            case VisualStyleType.EdgeOnly: return("EdgeOnly");

            case VisualStyleType.DisplayOnly: return("DisplayOnly");

            case VisualStyleType.JitterOff: return("JitterOff");

            case VisualStyleType.OverhangOff: return("OverhangOff");

            case VisualStyleType.EdgeColorOff: return("EdgeColorOff");

            case VisualStyleType.ShadesOfGray: return("ShadesOfGray");

            case VisualStyleType.Sketchy: return("Sketchy");

            case VisualStyleType.XRay: return("XRay");

            case VisualStyleType.ShadedWithEdges: return("ShadedWithEdges");

            case VisualStyleType.Shaded: return("Shaded");

            case VisualStyleType.EmptyStyle: return("EmptyStyle");

            default: throw new ArgumentOutOfRangeException(nameof(style), style, null);
            }
        }