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 (); }
public void AddASymbol() { Map map = new Map(); var resolver = map.Write(); Glyph glyph = new Glyph(); resolver.Dispose(); }
public void OpenMapFile(string filename) { Map map = new Map(); InputOutput.ReadFile(filename, map); CreateMapViewer(); mapViewer.Map = map; }
public void TestEmpty() { Map map = new Map(); var resolver = map.Read(); ICollection<Symbol> allSymbols = map.AllSymbols; resolver.Dispose(); Assert.That( allSymbols.Count == 0 ); }
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); }
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 (); }
// 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"); } } }
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 (); }
public ReadReleaser(Map map) { this.map = map; }
int version; // OCAD version being read #endregion Fields #region Constructors public OcadImport(Map map) { this.map = map; }
public static void WriteFile(string filename, Map map, int format) { OcadExport o = new OcadExport(); o.WriteMap(map, filename, format, true); }
// 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; }
// 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); } } }
public override void SetMap(Map newMap) { base.SetMap(newMap); }
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; }
public WriteReleaser(Map map) { this.map = map; }
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; }
public void CleanupTheMap() { releaser.Dispose(); map = null; }
public override void SetMap(Map newMap) { base.SetMap(newMap); glyph.CheckColors(newMap); }
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"); } }
public override void SetMap(Map newMap) { base.SetMap(newMap); CheckColor(fillColor); if (hatchMode != 0) CheckColor(hatchColor); if (drawPattern) patternGlyph.CheckColors(map); }
// 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; }
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; } } }
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; }