示例#1
0
文件: TestLoad.cs 项目: jonc/carto
 public void GetContourPath()
 {
     var map = new Map ();
     int version = InputOutput.ReadFile ("/Users/jon/Downloads/poolsbrook2011.ocd", map);
     var releaser = map.Read ();
     foreach (var sym in map.AllSymbols) {
         if (sym.Definition.OcadID == 101000 || sym.Definition.OcadID == 102000) {
             LineSymbol contour = (LineSymbol)sym;
             var kinds = contour.Path.PointKinds;
             foreach (var point in contour.Path.Points) {
                 Console.WriteLine (point);
             }
             Console.WriteLine (" --- ");
             foreach (var kind in kinds) {
                 Console.WriteLine (kind);
             }
             Console.WriteLine (" --- ");
             foreach (var point in contour.Path.FlattenedPoints) {
                 Console.WriteLine (point);
             }
             break;
         }
     }
     releaser.Dispose ();
 }
示例#2
0
文件: Test.cs 项目: jonc/carto
 public void AddASymbol()
 {
     Map map = new Map();
     var resolver = map.Write();
     Glyph glyph = new Glyph();
     resolver.Dispose();
 }
示例#3
0
文件: AppState.cs 项目: jonc/carto
        public void OpenMapFile(string filename)
        {
            Map map = new Map();
            InputOutput.ReadFile(filename, map);

            CreateMapViewer();
            mapViewer.Map = map;
        }
示例#4
0
文件: Test.cs 项目: jonc/carto
 public void TestEmpty()
 {
     Map map = new Map();
     var resolver = map.Read();
     ICollection<Symbol> allSymbols = map.AllSymbols;
     resolver.Dispose();
     Assert.That( allSymbols.Count == 0 );
 }
示例#5
0
文件: TestLoad.cs 项目: jonc/carto
 public void TestPoolsbrookWrite()
 {
     Map map = new Map ();
     int version = InputOutput.ReadFile ("/Users/jon/Downloads/poolsbrook2011.ocd", map);
     InputOutput.WriteFile ("/Users/jon/testWrite.ocd", map, 9);
     Map map2 = new Map ();
     version = InputOutput.ReadFile ("/Users/jon/testWrite.ocd", map2);
     Assert.AreEqual (9, version);
 }
示例#6
0
文件: TestLoad.cs 项目: jonc/carto
 public void TestPoolsbrookLoad()
 {
     Map map = new Map ();
     int version = InputOutput.ReadFile ("/Users/jon/Downloads/poolsbrook2011.ocd", map);
     Assert.AreEqual (8, version);
     Map.ReadReleaser releaser = map.Read ();
     Console.WriteLine (map.Template.absoluteFileName);
     Console.WriteLine (map.Bounds);
     releaser.Dispose ();
 }
示例#7
0
文件: InputOutput.cs 项目: jonc/carto
 // Read a file into the given map. Returns the file format
 // of the file.
 public static int ReadFile(string filename, Map map)
 {
     // Determine the file type, and open it up.
     using (Stream stm = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
         if (OcadImport.IsOcadFile(stm)) {
             OcadImport importer = new OcadImport(map);
             int format = importer.ReadOcadFile(stm, filename);
             return format;
         }
         else {
             // CONSIDER: do something more useful here
             throw new ApplicationException("File is not an OCAD file");
         }
     }
 }
示例#8
0
文件: TestLoad.cs 项目: jonc/carto
 public void TestGetContours()
 {
     Map map = new Map ();
     int version = InputOutput.ReadFile ("/Users/jon/Downloads/poolsbrook2011.ocd", map);
     var releaser = map.Read ();
     foreach (Symbol sym in map.AllSymbols) {
         if (sym.Definition.OcadID == 101000 || sym.Definition.OcadID == 102000) {
             Console.WriteLine (sym.Definition.Name + " " + sym.GetType ().ToString ());
             Console.WriteLine (sym.BoundingBox);
             LineSymbol contour = (LineSymbol)sym;
             if (contour.Path.IsClosedCurve) {
                 Console.WriteLine (contour.Path.Area ());
             } else {
                 Console.WriteLine ("Not Closed");
             }
         }
     }
     releaser.Dispose ();
 }
示例#9
0
文件: Map.cs 项目: jonc/carto
 public ReadReleaser(Map map)
 {
     this.map = map;
 }
示例#10
0
文件: OcadImport.cs 项目: jonc/carto
        int version; // OCAD version being read

        #endregion Fields

        #region Constructors

        public OcadImport(Map map)
        {
            this.map = map;
        }
示例#11
0
文件: InputOutput.cs 项目: jonc/carto
 public static void WriteFile(string filename, Map map, int format)
 {
     OcadExport o = new OcadExport();
     o.WriteMap(map, filename, format, true);
 }
示例#12
0
        // Verifies a test file. Returns true on success, false on failure. In the failure case,
        // a difference bitmap is written out.
        static bool VerifyTestFile(string filename, bool testLightenedColor, bool roundtripToOcadFile, int minOcadVersion, int maxOcadVersion)
        {
            string pngFileName;
            string mapFileName;
            string geodeFileName;
            string ocadFileName;
            string directoryName;
            string newBitmapName;
            RectangleF mapArea;
            int bmWidth, bmHeight;

            // Read the test file, and get the other file names and the area.
            using (StreamReader reader = new StreamReader(filename)) {
                mapFileName = reader.ReadLine();
                pngFileName = reader.ReadLine();
                float left, right, top, bottom;
                string area = reader.ReadLine();
                string[] coords = area.Split(',');
                left = float.Parse(coords[0]); bottom = float.Parse(coords[1]); right = float.Parse(coords[2]); top = float.Parse(coords[3]);
                mapArea = new RectangleF(left, top, right - left, bottom - top);
                string sizeLine = reader.ReadLine();
                coords = sizeLine.Split(',');
                bmWidth = int.Parse(coords[0]);
                bmHeight = int.Parse(coords[1]);
            }

            // Convert to absolute paths.
            directoryName = Path.GetDirectoryName(filename);
            mapFileName = Path.Combine(directoryName, mapFileName);
            pngFileName = Path.Combine(directoryName, pngFileName);
            geodeFileName = Path.Combine(directoryName,
                                         Path.GetFileNameWithoutExtension(mapFileName) + "_temp.geode");
            ocadFileName = Path.Combine(directoryName,
                                         Path.GetFileNameWithoutExtension(mapFileName) + "_temp.ocd");
            newBitmapName = Path.Combine(directoryName,
                                        Path.GetFileNameWithoutExtension(pngFileName) + "_new.png");

            File.Delete(geodeFileName);
            File.Delete(ocadFileName);
            File.Delete(newBitmapName);

            // Create and open the map file.
            Map map = new Map();
            InputOutput.ReadFile(mapFileName, map);

            // Draw into a new bitmap.
            BitmapSource bitmapNew = RenderBitmap(map, bmWidth, bmHeight, mapArea);
            WritePng(bitmapNew, newBitmapName);
            TestUtil.CompareBitmapBaseline(newBitmapName, pngFileName);

            if (testLightenedColor) {
                using (map.Write()) {
                    ColorMatrix colorMatrix = new ColorMatrix(new float[][] {
                           new float[] {0.4F,  0,  0,  0, 0},
                           new float[] {0,  0.4F,  0,  0, 0},
                           new float[] {0,  0,  0.4F,  0, 0},
                           new float[] {0,  0,  0,  1, 0},
                           new float[] {0.6F, 0.6F, 0.6F, 0, 1}
                    });
                    map.ColorMatrix = colorMatrix;
                }

                string lightenedPngFileName = Path.Combine(Path.GetDirectoryName(pngFileName), Path.GetFileNameWithoutExtension(pngFileName) + "_light.png");
                BitmapSource bitmapLight = RenderBitmap(map, bmWidth, bmHeight, mapArea);
                WritePng(bitmapLight, newBitmapName);
                TestUtil.CompareBitmapBaseline(newBitmapName, lightenedPngFileName);
            }

            if (roundtripToOcadFile) {
                for (int version = minOcadVersion; version <= maxOcadVersion; ++version) {
                    // Save and load to a temp file name.
                    InputOutput.WriteFile(ocadFileName, map, version);

                    // Create and open the map file.
                    map = new Map();
                    InputOutput.ReadFile(ocadFileName, map);

                    // Draw into a new bitmap.
                    bitmapNew = RenderBitmap(map, bmWidth, bmHeight, mapArea);
                    WritePng(bitmapNew, newBitmapName);
                    TestUtil.CompareBitmapBaseline(newBitmapName, pngFileName);

                    File.Delete(ocadFileName);
                }
            }

            return true;
        }
示例#13
0
文件: OcadExport.cs 项目: jonc/carto
        // Write the given map to an OCAD file.
        //   version = 6,7,8 -- the OCAD version
        //   usedSavedOcadInfo utilizes symbol information that was saved away if this file was
        //     loaded from OCAD, for better round tripping. Setup structure information and
        //     symbol header information is always used.
        public void WriteMap(Map map, string filename, int version, bool useSavedOcadInfo)
        {
            using (map.Read()) {
                this.map = map;
                this.version = version;
                this.filename = filename;
                //this.useOcadSaved = useSavedOcadInfo;

                if (version < 6 || version > 9)
                    throw new ArgumentException("Bad version number", "version");

                OcadFileHeader fileHeader = new OcadFileHeader();

                using (writer = new BinaryWriter(new FileStream(filename, FileMode.Create, FileAccess.ReadWrite), Encoding.GetEncoding(1252))) {
                    fileHeader.OCADMark = 3245;

                    if (version == 6)
                        fileHeader.SectionMark = 0;
                    else if (version == 7)
                        fileHeader.SectionMark = 7;
                    else if (version == 8)
                        fileHeader.SectionMark = 2;
                    else
                        fileHeader.SectionMark = 0;

                    fileHeader.Version = (short) version;
                    fileHeader.Subversion = 0;
                    // other fields will be filled in later and re-written at the end

                    fileHeader.Write(writer);

                    if (version <= 8) {
                        WriteSymbolHeader();
                        fileHeader.SetupPos = WriteSetup(out fileHeader.SetupSize);
                    }

                    fileHeader.FirstSymBlk = WriteSymbols();
                    fileHeader.FirstIdxBlk = WriteObjects();

                    if (version >= 8)
                        fileHeader.FirstStIndexBlk = WriteStringParameters();

                    // rewrite the file header
                    writer.Seek(0, SeekOrigin.Begin);
                    fileHeader.Write(writer);
                }
            }
        }
示例#14
0
文件: SymDef.cs 项目: jonc/carto
 public override void SetMap(Map newMap)
 {
     base.SetMap(newMap);
 }
示例#15
0
文件: SymDef.cs 项目: jonc/carto
        public virtual void SetMap(Map newMap)
        {
            Debug.Assert(newMap != null);

            if (map != null && map != newMap)
                throw new MapUsageException("Cannot add SyMDef to a map; it is already part of another map.");
            map = newMap;
        }
示例#16
0
文件: Map.cs 项目: jonc/carto
 public WriteReleaser(Map map)
 {
     this.map = map;
 }
示例#17
0
文件: SymColor.cs 项目: jonc/carto
 internal void SetMap(Map newMap)
 {
     if (map != null && map != newMap)
         throw new MapUsageException("Color can't be added to a map; it is already part of another map.");
     map = newMap;
 }
示例#18
0
 public void CleanupTheMap()
 {
     releaser.Dispose();
     map = null;
 }
示例#19
0
文件: SymDef.cs 项目: jonc/carto
 public override void SetMap(Map newMap)
 {
     base.SetMap(newMap);
     glyph.CheckColors(newMap);
 }
示例#20
0
文件: Glyph.cs 项目: jonc/carto
 internal void CheckColors(Map map)
 {
     foreach (GlyphPart part in parts) {
         if (part.color.ContainingMap != map)
             throw new MapUsageException("Glyph contains colors that are not in the containing map");
     }
 }
示例#21
0
文件: SymDef.cs 项目: jonc/carto
 public override void SetMap(Map newMap)
 {
     base.SetMap(newMap);
     CheckColor(fillColor);
     if (hatchMode != 0)
         CheckColor(hatchColor);
     if (drawPattern)
         patternGlyph.CheckColors(map);
 }
示例#22
0
        // Render part of a map to a bitmap.
        static BitmapSource RenderBitmap(Map map, int bmWidth, int bmHeight, RectangleF mapArea)
        {
            // Calculate the transform matrix.
            Point midpoint = new Point(bmWidth / 2.0F, bmHeight / 2.0F);
            double scaleFactor = bmWidth / mapArea.Width;
            PointF centerPoint = new PointF((mapArea.Left + mapArea.Right) / 2, (mapArea.Top + mapArea.Bottom) / 2);
            Matrix matrix = Matrix.Identity;
            matrix.TranslatePrepend(midpoint.X, midpoint.Y);
            matrix.ScalePrepend(scaleFactor, -scaleFactor);  // y scale is negative to get to cartesian orientation.
            matrix.TranslatePrepend(-centerPoint.X, -centerPoint.Y);

            // Get the render options.
            RenderOptions renderOpts = new RenderOptions();
            renderOpts.usePatternBitmaps = false;
            renderOpts.minResolution = (float) (1 / scaleFactor);

            // Create a drawing of the map.
            DrawingVisual visual = new DrawingVisual();
            DrawingContext dc = visual.RenderOpen();

            // Clear the bitmap
            dc.DrawRectangle(Brushes.White, null, new Rect(-1, -1, bmWidth + 2, bmHeight + 2));  // clear background.

            // Transform to map coords.
            dc.PushTransform(new MatrixTransform(matrix));

            // Draw the map.
            using (map.Read())
                map.Draw(dc, mapArea, renderOpts);
            dc.Close();

            // Draw into a new bitmap.
            RenderTargetBitmap bitmapNew = new RenderTargetBitmap(bmWidth, bmHeight, 96.0, 96.0, PixelFormats.Pbgra32);
            bitmapNew.Render(visual);
            bitmapNew.Freeze();

            return bitmapNew;
        }
示例#23
0
文件: SymDef.cs 项目: jonc/carto
        public override void SetMap(Map newMap)
        {
            base.SetMap(newMap);
            CheckColor(lineColor);
            CheckColor(secondLineColor);
            CheckColor(doubleLines.doubleFillColor);
            CheckColor(doubleLines.doubleLeftColor);
            CheckColor(doubleLines.doubleRightColor);

            // compute the max thickness of this line.
            maxThickness = 0.0F;
            if (lineColor != null && thickness > maxThickness)
                maxThickness = thickness;
            if (lineColor != null && lineStyle == LineStyle.Mitered && thickness > maxMiteredThickness)
                maxMiteredThickness = thickness;

            if (secondLineColor != null && secondThickness > maxThickness)
                maxThickness = secondThickness;
            if (secondLineColor != null && secondLineStyle == LineStyle.Mitered && secondThickness > maxMiteredThickness)
                maxMiteredThickness = secondThickness;

            if (isDoubleLine) {
                float doubleThickness = (2 * Math.Max(doubleLines.doubleLeftWidth, doubleLines.doubleRightWidth) + doubleLines.doubleThick);
                if (doubleThickness > maxThickness)
                    maxThickness = doubleThickness;
                if (doubleThickness > maxMiteredThickness)
                    maxMiteredThickness = doubleThickness;
            }

            if (glyphs != null) {
                foreach (GlyphInfo glyphInfo in glyphs) {
                    float glyphRadius = glyphInfo.glyph.Radius;

                    if (glyphRadius * 2 > maxThickness)
                        maxThickness = glyphRadius * 2;
                    if (glyphInfo.location == GlyphLocation.Corners && glyphRadius * 2 > maxMiteredThickness)
                        maxMiteredThickness = glyphRadius * 2;
                }
            }
        }
示例#24
0
文件: Symbol.cs 项目: jonc/carto
 internal void SetMap(Map newMap)
 {
     if (map != null && newMap != null && map != newMap)
         throw new MapUsageException("Cannot add symbol to a map; it is already part of another map.");
     map = newMap;
 }