示例#1
0
        // Set the map file used to draw.
        public void SetMapFile(MapType newMapType, string newFilename)
        {
            this.mapType  = newMapType;
            this.filename = newFilename;
            this.bitmap   = null;
            this.map      = null;

            if (newMapType == MapType.None)
            {
                map        = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                bitmap     = null;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.OCAD)
            {
                map        = new Map(MapUtil.TextMetricsProvider, new GDIPlus_FileLoader(Path.GetDirectoryName(newFilename)));
                mapVersion = InputOutput.ReadFile(newFilename, map);
                bitmap     = null;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.Bitmap)
            {
                map        = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                Bitmap bm = (Bitmap)Image.FromFile(newFilename);
                bitmap     = new GDIPlus_Bitmap(bm);
                bitmapDpi  = bm.HorizontalResolution;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.PDF)
            {
                string errorText;
                map        = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                Size bitmapSize;
                pdfMapFile = MapUtil.ValidatePdf(newFilename, out bitmapDpi, out bitmapSize, out errorText);
                if (pdfMapFile == null)
                {
                    this.mapType = MapType.None;
                    bitmap       = null;
                }
                else
                {
                    Bitmap bm = (Bitmap)Image.FromFile(pdfMapFile.PngFileName);
                    bitmap = new GDIPlus_Bitmap(bm);
                }
            }
            else
            {
                Debug.Fail("bad maptype");
            }

            UpdateDimmedBitmap();
            RaiseChanged(null);        // redraw everything.
        }
示例#2
0
        // The map file name has been updated.
        void UpdateMapFile()
        {
            if (mapFile == null || mapFile == "")
            {
                // No map file.
                errorDisplayPanel.Visible = false;
                panelScaleDpi.Visible     = false;
            }
            else
            {
                // Validate the map file.
                string     errorMessageText;
                float      dpi, mapScale;
                Size       bitmapSize;
                RectangleF mapBounds;
                bool       ok = MapUtil.ValidateMapFile(mapFile, out mapScale, out dpi, out bitmapSize, out mapBounds, out mapType, out errorMessageText);
                if (ok)
                {
                    if (mapType == MapType.OCAD)
                    {
                        panelScaleDpi.Visible     = false;
                        errorDisplayPanel.Visible = false;
                        textBoxScale.Text         = mapScale.ToString();
                    }
                    else if (mapType == MapType.Bitmap)
                    {
                        panelScaleDpi.Visible     = true;
                        errorDisplayPanel.Visible = false;
                        labelDpi.Visible          = labelDpi2.Visible = textBoxDpi.Visible = true;
                        textBoxDpi.Text           = dpi.ToString();
                    }
                    else if (mapType == MapType.PDF)
                    {
                        panelScaleDpi.Visible     = true;
                        errorDisplayPanel.Visible = false;
                        labelDpi.Visible          = labelDpi2.Visible = textBoxDpi.Visible = false;
                    }
                    else
                    {
                        Debug.Fail("unexpected map type.");
                    }
                }
                else
                {
                    errorMessage.Text         = errorMessageText;
                    panelScaleDpi.Visible     = false;
                    errorDisplayPanel.Visible = true;
                }
            }

            mapFileNameTextBox.Text = mapFile;
            UpdateOKButton();
        }
示例#3
0
        void NewEventPaperSize_Load(object sender, EventArgs e)
        {
            containingWizard = (NewEventWizard)Parent;

            RectangleF printArea       = containingWizard.mapBounds;
            float      printScaleRatio = containingWizard.DefaultPrintScale / containingWizard.MapScale;

            // Set the default page setting from the map size and print scale.
            int  pageWidth, pageHeight, pageMargin;
            bool landscape;

            MapUtil.GetDefaultPageSize(printArea, printScaleRatio, out pageWidth, out pageHeight, out pageMargin, out landscape);
            paperSizeControl.PaperSize  = new System.Drawing.Printing.PaperSize("", pageWidth, pageHeight);
            paperSizeControl.MarginSize = pageMargin;
            paperSizeControl.Landscape  = landscape;
        }
示例#4
0
        // Create a point symbol that can be used to put this symbol onto a map inside
        // a box of the given size (in mm).
        public PointSymDef CreateSymdef(Map map, SymColor color, float boxSize)
        {
            Glyph glyph = new Glyph();

            for (int i = 0; i < strokes.Length; ++i)
            {
                strokes[i].AddToMapGlyph(glyph, color, boxSize);
            }
            glyph.ConstructionComplete();

            // Find a free OCAD ID number.
            string symbolId = map.GetFreeSymbolId(800);

            // Create the symdef
            PointSymDef symdef;

            symdef = new PointSymDef("Description: " + this.GetName(Util.CurrentLangName()), symbolId, glyph, false);

            // Create the toolbox image.
            Bitmap bm = new Bitmap(24, 24);

            using (Graphics g = Graphics.FromImage(bm)) {
                g.Clear(Color.White);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                if (kind >= 'T')
                {
                    g.SetClip(new RectangleF(0, 0, bm.Width / 2, bm.Height));
                    Draw(g, Color.Black, new RectangleF(0, bm.Height / 3F, bm.Width * 8F / 3F, bm.Height / 3F));
                    g.SetClip(new RectangleF(bm.Width / 2, 0, bm.Width / 2, bm.Height));
                    Draw(g, Color.Black, new RectangleF(-bm.Width * 5F / 3F, bm.Height / 3F, bm.Width * 8F / 3F, bm.Height / 3F));
                }
                else
                {
                    Draw(g, Color.Black, new RectangleF(0, 0, bm.Width, bm.Height));
                }
            }
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(bm);

            // Add the symdef to the map.
            map.AddSymdef(symdef);

            return(symdef);
        }
示例#5
0
        // Render a course onto a map.
        public Map RenderToMap(MapRenderOptions mapRenderOptions)
        {
            // Create the map to render into.
            Map map = new Map(MapUtil.TextMetricsProvider, null);

            if (Count == 0)
            {
                return(map);
            }

            SymColor[] colors = new SymColor[LAYERCOUNT];

            using (map.Write()) {
                // Create dictionary for holding Symdef state
                Dictionary <object, SymDef>         dict         = new Dictionary <object, SymDef>();
                Dictionary <SpecialColor, SymColor> customColors = new Dictionary <SpecialColor, SymColor>();

                // Create white color and white-out symdef.
                SymColor   white     = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[KeyWhiteOut] = whiteArea;

                // Create layout symdef.
                ImageSymDef layoutSymDef = new ImageSymDef(SymLayer.Layout);
                map.AddSymdef(layoutSymDef);
                dict[KeyLayout] = layoutSymDef;

                // Create colors for the special colors.
                short customColorId = 61;
                foreach (CourseObj courseObject in this)
                {
                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Custom)
                    {
                        if (!customColors.ContainsKey(courseObject.CustomColor))
                        {
                            CmykColor cmyk = courseObject.CustomColor.CustomColor;
                            customColors.Add(courseObject.CustomColor, map.AddColor(string.Format("Color {0}", customColorId), customColorId,
                                                                                    cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black, false));
                            ++customColorId;
                        }
                    }
                }

                // Create colors for the regular colors in the correct order (lower on top).
                for (int layerIndex = LAYERCOUNT - 1; layerIndex >= 0; --layerIndex)
                {
                    if (colorName[layerIndex] != null)
                    {
                        // Create the symColor for rendering.
                        colors[layerIndex] = map.AddColor(colorName[layerIndex], ocadColorId[layerIndex],
                                                          colorC[layerIndex], colorM[layerIndex], colorY[layerIndex], colorK[layerIndex], colorOverprint[layerIndex]);
                    }
                }

                foreach (CourseObj courseObject in this)
                {
                    int layerIndex = (int)courseObject.layer;

                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Black)
                    {
                        layerIndex = (int)CourseLayer.Descriptions;
                    }

                    SymColor color = colors[layerIndex];

                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Custom)
                    {
                        color = customColors[courseObject.CustomColor];
                    }

                    courseObject.AddToMap(map, color, mapRenderOptions, dict);
                }
            }

            return(map);
        }