Beispiel #1
0
        void unitsConverted(PlotPaperUnit prevUnits, PlotPaperUnit plotPaperUnits)
        {
            double dCoeff = 0;

            if (plotPaperUnits == PlotPaperUnit.Millimeters && prevUnits == PlotPaperUnit.Inches)
            {
                dCoeff = 25.4;
            }
            else if (plotPaperUnits == PlotPaperUnit.Inches && prevUnits == PlotPaperUnit.Millimeters)
            {
                dCoeff = 1.0 / 25.4;
            }
            else
            {
                return;
            }

            bool bStandardScale = m_plotStg.UseStandardScale;

            if (bStandardScale)
            {
                double dStandardScale = m_plotStg.StdScale;
                if (dStandardScale != 0) // skip Fit to paper
                {
                    m_plotSettingVal.SetCustomPrintScale(m_plotStg, new CustomScale(dStandardScale, 1.0 / dCoeff));
                }
            }
            else
            {
                CustomScale cs = m_plotStg.CustomPrintScale;
                m_plotSettingVal.SetCustomPrintScale(m_plotStg, new CustomScale(cs.Numerator, cs.Denominator / dCoeff));
            }
        }
Beispiel #2
0
        private void CustomizeScale(BubbleMapDashboardItem map)
        {
            CustomScale   customScale = new CustomScale();
            List <double> rangeStops  = new List <double>();

            customScale.IsPercent = false;

            rangeStops.Add(20);
            rangeStops.Add(200);
            rangeStops.Add(500);
            rangeStops.Add(2000);
            customScale.RangeStops.AddRange(rangeStops);

            map.ColorScale = customScale;
        }
        public Form1()
        {
            InitializeComponent();
            // Loads a dashboard that contains a choropleth map with the default palette.
            Dashboard dashboard = new Dashboard();

            dashboard.LoadFromXml(@"..\..\Data\Dashboard.xml");

            // Gets the ValueMap object that provides data for coloring map shapes.
            ChoroplethMapDashboardItem map = (ChoroplethMapDashboardItem)dashboard.Items[0];
            ValueMap populationMap         = (ValueMap)map.Maps[0];

            // Creates CustomPalette and CustomScale objects.
            CustomPalette customPalette = new CustomPalette();
            CustomScale   customScale   = new CustomScale();

            // Creates lists of custom colors and range stops.
            List <Color>  customColors = new List <Color>();
            List <double> rangeStops   = new List <double>();

            // Specifies that the absolute scale is used to define a set of colors.
            customScale.IsPercent = false;

            // Specifies custom colors and corresponding range stops.
            customColors.Add(Color.LightBlue);  rangeStops.Add(100000);
            customColors.Add(Color.SkyBlue);    rangeStops.Add(1000000);
            customColors.Add(Color.LightCoral); rangeStops.Add(10000000);
            customColors.Add(Color.Tomato);     rangeStops.Add(100000000);
            customColors.Add(Color.Maroon);     rangeStops.Add(1000000000);

            // Adds custom colors and range stops to a custom palette and corresponding custom scale.
            customPalette.Colors.AddRange(customColors);
            customScale.RangeStops.AddRange(rangeStops);

            // Specifies a custom palette and scale for the ValueMap object.
            populationMap.Palette = customPalette;
            populationMap.Scale   = customScale;

            // Sets the customized dashboard as a currently opened dashboard.
            dashboardViewer1.Dashboard = dashboard;
        }
Beispiel #4
0
        void PrintPage(object sender, PrintPageEventArgs ev)
        {
            if (m_pPrinterDevice != null)
            {
                using (DBObject pVpObj = Aux.active_viewport_id(database).GetObject(OpenMode.ForWrite))
                {
                    using (AbstractViewportData pAV = new AbstractViewportData(pVpObj))
                    {
                        Teigha.GraphicsSystem.View pGSView = pAV.GsView;

                        PrintDocument prDoc = (PrintDocument)sender;

                        // Get printer paper info
                        Double dPrinterWidth  = ev.PageBounds.Width;
                        Double dPrinterHeight = ev.PageBounds.Height;
                        Double dLogPixelX     = ev.PageSettings.PrinterResolution.X; //dot per inch
                        Double dLogPixelY     = ev.PageSettings.PrinterResolution.Y; //dot per inch
                        Double kMmPerInch     = 25.4;
                        Double kMmPerHInch    = 0.254;
                        Double koeffX         = dLogPixelX / kMmPerInch;
                        Double koeffY         = dLogPixelY / kMmPerInch;

                        Layout  pLayout      = (Layout)m_pPrinterDevice.LayoutId.GetObject(OpenMode.ForRead);
                        Boolean bScaledToFit = pLayout.UseStandardScale && (StdScaleType.ScaleToFit == pLayout.StdScaleType);
                        Boolean bCentered    = pLayout.PlotCentered;
                        Boolean bMetric      = (pLayout.PlotPaperUnits != PlotPaperUnit.Inches);
                        Boolean bPrintLW     = pLayout.PrintLineweights || pLayout.ShowPlotStyles;

                        Point2d offsets = pLayout.PlotOrigin; // in mm

                        Extents2d ex2d          = pLayout.PlotPaperMargins;
                        Double    dLeftMargin   = ex2d.MinPoint.X; // in mm
                        Double    dRightMargin  = ex2d.MaxPoint.X; // in mm
                        Double    dTopMargin    = ex2d.MinPoint.Y; // in mm
                        Double    dBottomMargin = ex2d.MaxPoint.Y; // in mm
                        PlotType  plotType      = pLayout.PlotType;

                        PlotRotation plotRotation = pLayout.PlotRotation;
                        if (plotRotation == PlotRotation.Degrees090 || plotRotation == PlotRotation.Degrees270)
                        {
                            plotRotation = (plotRotation == PlotRotation.Degrees090) ? PlotRotation.Degrees270 : PlotRotation.Degrees090;
                        }

                        switch (plotRotation)
                        {
                        case PlotRotation.Degrees090:
                            Swap <Double>(dTopMargin, dRightMargin);
                            Swap <Double>(dBottomMargin, dLeftMargin);
                            Swap <Double>(dBottomMargin, dTopMargin);
                            Swap <Double>(dTopMargin, dRightMargin);
                            offsets = new Point2d(-offsets.X, -offsets.Y);
                            break;

                        case PlotRotation.Degrees180:
                            Swap <Double>(dRightMargin, dLeftMargin);
                            offsets = new Point2d(-offsets.X, -offsets.Y);
                            break;

                        case PlotRotation.Degrees270:
                            Swap <Double>(dTopMargin, dRightMargin);
                            Swap <Double>(dBottomMargin, dLeftMargin);
                            Swap <Double>(dBottomMargin, dTopMargin);
                            offsets = new Point2d(offsets.X, offsets.Y);
                            break;
                        }

                        // Get scale factor
                        double factor;
                        if (pLayout.UseStandardScale)
                        {
                            factor = pLayout.StdScale;
                        }
                        else
                        {
                            CustomScale scale = pLayout.CustomPrintScale;
                            factor = scale.Numerator / scale.Denominator;
                        }

                        // Calculate paper drawable area using margins from layout (in mm).
                        Double drx1 = (ev.MarginBounds.Left * kMmPerHInch + dLeftMargin);                  // in mm
                        Double drx2 = (ev.MarginBounds.Width * kMmPerHInch - dLeftMargin - dRightMargin);  // in mm
                        Double dry1 = (ev.MarginBounds.Top * kMmPerHInch + dTopMargin);                    // in mm
                        Double dry2 = (ev.MarginBounds.Height * kMmPerHInch - dTopMargin - dBottomMargin); // in mm

                        Boolean        bType           = (plotType == PlotType.Display || plotType == PlotType.Layout);
                        AbstractViewPE pAbstractViewPE = new AbstractViewPE(bType ? pViewDr : pGSView);

                        // set LineWeight scale factor for model space
                        if (bPrintLW && database.TileMode)
                        {
                            Teigha.GraphicsSystem.View pTo = m_pPrinterDevice.ViewAt(0);
                            pTo.LineweightToDcScale = Math.Max(dLogPixelX, dLogPixelY) / kMmPerInch * 0.01;
                        }

                        Point3d  viewTarget     = pAbstractViewPE.Target;
                        Point3d  viewportCenter = pAbstractViewPE.Target;      // in plotPaperUnits
                        Boolean  isPerspective  = pAbstractViewPE.IsPerspective;
                        Double   viewportH      = pAbstractViewPE.FieldHeight; // in plotPaperUnits
                        Double   viewportW      = pAbstractViewPE.FieldWidth;  // in plotPaperUnits
                        Vector3d viewDir        = pAbstractViewPE.Direction;   // in plotPaperUnits
                        Vector3d upV            = pAbstractViewPE.UpVector;    // in plotPaperUnits
                        Matrix3d eyeToWorld     = pAbstractViewPE.EyeToWorld;
                        Matrix3d WorldToeye     = pAbstractViewPE.WorldToEye;

                        Boolean isPlanView = viewDir.GetNormal().Equals(Vector3d.ZAxis);
                        Point3d oldTarget  = viewTarget;

                        Double fieldWidth = viewportW, fieldHeight = viewportH;

                        if (plotType == PlotType.Display)
                        {
                            viewTarget  = viewportCenter;
                            fieldWidth  = viewportW;
                            fieldHeight = viewportH;
                        }
                        else if (plotType == PlotType.Extents || (plotType == PlotType.Limits && !isPlanView))
                        {
                            BoundBlock3d extents = new BoundBlock3d();
                            if (pAbstractViewPE.GetViewExtents(extents)) // pIter also skip 'off layers'
                            {
                                extents.TransformBy(eyeToWorld);
                                viewTarget = (extents.GetMinimumPoint() + extents.GetMaximumPoint().GetAsVector()) / 2.0;
                                extents.TransformBy(WorldToeye);

                                fieldWidth  = Math.Abs(extents.GetMaximumPoint().X - extents.GetMinimumPoint().X);
                                fieldHeight = Math.Abs(extents.GetMaximumPoint().Y - extents.GetMinimumPoint().Y);
                            }
                        }
                        else if (plotType == PlotType.View)
                        {
                            viewTarget  = viewportCenter;
                            fieldWidth  = viewportW;
                            fieldHeight = viewportH;
                        }
                        else if (plotType == PlotType.Limits)
                        {
                            fieldWidth  = (drx2 - drx1) / factor; // drx in mm -> fieldWidth in mm
                            fieldHeight = (dry2 - dry1) / factor;

                            viewTarget = new Point3d(fieldWidth / 2.0 - offsets.X / factor, fieldHeight / 2.0 - offsets.Y / factor, 0); // in mm
                            if (!bMetric)
                            {
                                viewTarget  /= kMmPerInch; // must be in plotpaper units
                                fieldWidth  /= kMmPerInch;
                                fieldHeight /= kMmPerInch;
                            }

                            bCentered = bScaledToFit = false; // kLayout doesn't support pIter.
                        }

                        if (plotType != PlotType.View)
                        {
                            viewTarget = viewTarget.OrthoProject(new Plane(oldTarget, viewDir));
                        }

                        pGSView.SetView(viewTarget + viewDir, viewTarget, upV, fieldWidth, fieldHeight, isPerspective ? Teigha.GraphicsSystem.Projection.Perspective : Teigha.GraphicsSystem.Projection.Parallel);

                        if (!bMetric)
                        {
                            fieldWidth  *= kMmPerInch;
                            fieldHeight *= kMmPerInch;
                        }

                        if (bScaledToFit)
                        {
                            factor = Math.Min((drx2 - drx1) / fieldWidth, (dry2 - dry1) / fieldHeight);
                        }

                        if (bCentered) // Offset also can be incorectly saved.
                        {
                            offsets = new Point2d(((drx2 - drx1) - fieldWidth * factor) / 2.0,
                                                  ((dry2 - dry1) - fieldHeight * factor) / 2.0);

                            if (plotRotation == PlotRotation.Degrees090 || plotRotation == PlotRotation.Degrees180)
                            {
                                offsets = new Point2d(-offsets.X, -offsets.Y);
                            }
                        }

                        pGSView.Viewport = new Extents2d(0, 0, 1, 1);

                        // Calculate viewport rect in printer units
                        //int x1 = (int)((offsets.X + drx1) * koeffX);
                        //int x2 = (int)((offsets.X + drx2) * koeffX);
                        //int y1 = (int)((-offsets.Y + dry1) * koeffY);
                        //int y2 = (int)((-offsets.Y + dry2) * koeffY);
                        int x1 = (int)(drx1 * koeffX);
                        int x2 = (int)(drx2 * koeffX);
                        int y1 = (int)(dry1 * koeffY);
                        int y2 = (int)(dry2 * koeffY);

                        Rectangle viewportRect = new Rectangle(x1, y1, x2, y2);
                        m_pPrinterDevice.OnSize(viewportRect);
                        if (m_pPrinterDevice.UnderlyingDevice.Properties.Contains("WindowHDC"))
                        {
                            m_pPrinterDevice.UnderlyingDevice.Properties.AtPut("WindowHDC", new RxVariant((Int32)ev.Graphics.GetHdc()));
                        }
                        m_pPrinterDevice.Update();

                        pAbstractViewPE.Dispose();
                        pLayout.Dispose();
                    }
                }
            }
        }
Beispiel #5
0
        void FillScaleValues(bool bFillCombo)
        {
            if (bFillCombo)
            {
                comboBoxPlotScale.Items.Clear();
                foreach (String strScaleVal in pPlotScaleValues)
                {
                    comboBoxPlotScale.Items.Add(strScaleVal);
                }
            }

            StdScaleType sst = m_plotStg.StdScaleType;

            if (m_plotStg.UseStandardScale && sst != StdScaleType.ScaleToFit && sst >= 0 && sst <= StdScaleType.StdScale1000To1)
            {
                comboBoxPlotScale.SelectedItem = pPlotScaleValues[(int)sst];
            }
            else
            {
                comboBoxPlotScale.SelectedItem = "Custom";
            }

            bool isModel      = isModelSpacePageSetup();
            bool isLayoutMode = m_plotStg.PlotType == PlotType.Layout;

            bool bTmp = m_plotStg.UseStandardScale && !isLayoutMode && (sst == StdScaleType.ScaleToFit);

            if (checkBoxPlotScaleFitToPaper.Checked != bTmp)
            {
                checkBoxPlotScaleFitToPaper.Checked = bTmp;
            }
            checkBoxScaleLineweights.Checked = m_plotStg.ScaleLineweights;

            if (isLayoutMode)
            {
                checkBoxPlotScaleFitToPaper.Checked = checkBoxCenterPlot.Checked = false;
            }

            checkBoxScaleLineweights.Enabled    = !isModel;
            checkBoxPlotScaleFitToPaper.Enabled = !isLayoutMode;
            checkBoxCenterPlot.Enabled          = !isLayoutMode;

            comboBoxPlotScale.Enabled           = !checkBoxPlotScaleFitToPaper.Checked;
            textBoxPlotScalePaperUint.Enabled   = !checkBoxPlotScaleFitToPaper.Checked;
            textBoxPlotScaleDrawingUint.Enabled = !checkBoxPlotScaleFitToPaper.Checked;

            if (m_plotStg.UseStandardScale && !checkBoxPlotScaleFitToPaper.Checked)
            {
                textBoxPlotScalePaperUint.Text   = (plotScaleSetting[(int)sst].m_dRealWorldUnits).ToString();
                textBoxPlotScaleDrawingUint.Text = (plotScaleSetting[(int)sst].m_dDrawingUnits).ToString();
            }
            else
            {
                CustomScale cs = m_plotStg.CustomPrintScale;
                textBoxPlotScalePaperUint.Text   = (cs.Numerator).ToString();
                textBoxPlotScaleDrawingUint.Text = (cs.Denominator).ToString();
            }

            FillMMInches();
            textBoxPlotScaleDrawingUintText.Text = unitsInfo.getTextByValue(double.Parse(textBoxPlotScaleDrawingUint.Text), unitsScale[3]);
        }
        public static void ChangePlotSetting(string borderSize)
        {
            string      mediaName;
            CustomScale cmScale;

            switch (borderSize)
            {
            case "AE":
                mediaName = "ARCH_E1_(30.00_x_42.00_Inches)";
                cmScale   = new CustomScale(1, 1.037);
                break;

            case "B":
                mediaName = "ANSI_expand_B_(11.00_x_17.00_Inches)";
                cmScale   = new CustomScale(1, 1.037);
                break;

            case "C":
                mediaName = "ARCH_expand_C_(18.00_x_24.00_Inches)";
                cmScale   = new CustomScale(1, 1.037);
                break;

            case "D":
                mediaName = "ARCH_expand_D_(24.00_x_36.00_Inches)";
                cmScale   = new CustomScale(1, 1);
                break;

            case "E":
                mediaName = "ARCH_E_(36.00_x_48.00_Inches)";
                cmScale   = new CustomScale(1, 1.032);
                break;

            case "F":
                mediaName = "ARCH_E1_(30.00_x_42.00_Inches)";
                cmScale   = new CustomScale(1, 1.037);
                break;

            default:
                mediaName = "ARCH_expand_D_(24.00_x_36.00_Inches)";
                cmScale   = new CustomScale(1, 1);
                break;
            }

            // Get the current document and database, and start a transaction
            Document acDoc   = Acad.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Reference the Layout Manager
                var acLayoutMgr = LayoutManager.Current;

                // Get the current layout and output its name in the Command Line window
                var acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout),
                                                 OpenMode.ForRead) as Layout;

                // Get the PlotInfo from the layout
                PlotInfo acPlInfo = new PlotInfo();
                if (acLayout != null)
                {
                    acPlInfo.Layout = acLayout.ObjectId;

                    // Get a copy of the PlotSettings from the layout
                    PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
                    acPlSet.CopyFrom(acLayout);

                    // Update the PlotConfigurationName property of the PlotSettings object
                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                    acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3", mediaName);
                    acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);

                    acPlSetVdr.SetPlotCentered(acPlSet, true);
                    acPlSetVdr.SetCustomPrintScale(acPlSet, cmScale);


                    // Update the layout
                    acLayout.UpgradeOpen();
                    acLayout.CopyFrom(acPlSet);

                    // Output the name of the new device assigned to the layout
                    acDoc.Editor.WriteMessage("\nNew device name: " + acLayout.PlotConfigurationName);
                }

                //regen the current view
                Acad.DocumentManager.MdiActiveDocument.Editor.Regen();

                //zoom to the extents of the drawing
                acDoc.SendStringToExecute("._zoom _all ", true, false, false);

                // Save the new objects to the database
                acTrans.Commit();
            }
        }
Beispiel #7
0
        private void OnScaleSelected(object sender, SelectionChangedEventArgs e)
        {
            ModifyBtn.IsEnabled = true;
            _customComments.ToList().ForEach(item => item.Clear());
            _customLabels.ToList().ForEach(item => item.Content = "");
            bool readFlag;
            var  selectedItem = ScaleLBox.SelectedItem?.ToString();

            ScaleTBox.Text = selectedItem;

            // Searches the scale in config file, if found retireves it and displays
            using (var customScale = new CustomScale(selectedItem))
            {
                if (customScale == null)
                {
                    return;
                }
                readFlag = customScale.ReadCustomScaleConfigFile();
                if (readFlag)
                {
                    var count = 0;
                    customScale.Score.Reverse().ToList().ForEach(item =>
                    {
                        _customLabels[count].Content = item;
                        count++;
                    });


                    count = 0;
                    customScale.ScoreComment.Reverse().ToList().ForEach(item =>
                    {
                        _customComments[count].Text = item;
                        count++;
                    });
                }
            }

            // If scale is not found, it retrieves from in-memory
            if (readFlag == false)
            {
                _customScalePropertiesList.ToList().ForEach(item =>
                {
                    var count = 0;
                    if (item.ScaleName == selectedItem)
                    {
                        item.CustomComments.ToList().ForEach(comment =>
                        {
                            _customComments[count].Text = comment;
                            count++;
                        });
                        count = 0;
                        item.CustomScaleLabels.ToList().ForEach(labels =>
                        {
                            _customLabels[count].Content = labels;
                            count++;
                        });
                    }
                });
            }


            SetRangeButtons();

            _customComments.ToList().ForEach(item =>
            {
                if (item.Text == "")
                {
                    item.IsEnabled = false;
                }
                else
                {
                    item.IsEnabled = true;
                }
            });
        }