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 TestEmpty() { Map map = new Map(); var resolver = map.Read(); ICollection<Symbol> allSymbols = map.AllSymbols; resolver.Dispose(); Assert.That( allSymbols.Count == 0 ); }
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 (); }
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 (); }
// 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; }
// 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); } } }