Exemplo n.º 1
0
 OcadSetup ReadSetup(OcadFileHeader fh)
 {
     OcadSetup setup = new OcadSetup();
     setup.Read(reader, fh.SetupPos, fh.SetupSize);
     return setup;
 }
Exemplo n.º 2
0
 // Get the template infomation about the setup struction into a TemplateInfo class.
 // Return null if no template is there.
 TemplateInfo ReadTemplateInfo(OcadSetup setup)
 {
     if (setup.TemplateEnabled != 0 && setup.TemplateFileName != null && setup.TemplateFileName.Length > 0) {
         // template name might be relative. Make it absolute.
         string absoluteFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(this.filename), setup.TemplateFileName));
         return new TemplateInfo(absoluteFileName, PointFromOcadCoord(setup.TempOffset), (float) setup.TempResol,
                                                  (float) (setup.rTempAng * 180.0 / Math.PI), setup.HideTemp == 0);
     }
     else {
         return null;
     }
 }
Exemplo n.º 3
0
        int WriteSetup(out int size)
        {
            int pos = (int) writer.Seek(0, SeekOrigin.Current);

            OcadSetup setup = map.OcadSetupStructure;

            if (setup == null) {
                // Default value if no existing setup structure.
                setup = new OcadSetup();
                setup.rGridDist = 10;
                setup.MapScale = 15000;
                if (version < 8)
                    setup.DraftScaleX = setup.DraftScaleY = setup.MapScale;
                setup.PrintScale = setup.MapScale;
                setup.Zoom = 4;
            }

            // Value to always set in the setup structure.
            setup.FileName = filename;
            setup.MapScale = map.MapScale;
            if (map.PrintScale != 0)
                setup.PrintScale = map.PrintScale;
            else
                setup.PrintScale = map.MapScale;

            if (map.PrintArea != RectangleF.Empty) {
                // note: bottom and top switched due to Y-positive coord system.
                setup.PrLowerLeft = OcadCoordFromPoint(new PointF(map.PrintArea.Left, map.PrintArea.Top));
                setup.PrUpperRight = OcadCoordFromPoint(new PointF(map.PrintArea.Right, map.PrintArea.Bottom));
            }

            // Set template for if version is <= 7. Parameter strings used for version 8 and above.
            TemplateInfo template = map.Template;
            if (template != null && version <= 7) {
                bool isOcadFile = false;
                try {
                    using (Stream stm = new FileStream(template.absoluteFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        isOcadFile = OcadImport.IsOcadFile(stm);
                    }
                }
                catch (IOException) {
                    // Couldn't read file, so use the extension to decide.
                    isOcadFile = Path.GetExtension(template.absoluteFileName) == ".ocd";
                }

                if (version == 7 && isOcadFile)
                    setup.TemplateEnabled = 2;
                else
                    setup.TemplateEnabled = 1;

                setup.DraftScaleX = setup.DraftScaleY = map.MapScale;
                setup.TemplateFileName = template.absoluteFileName;
                setup.TempOffset = OcadCoordFromPoint(template.centerPoint);
                setup.rTempAng = template.angle / 180.0 * Math.PI;
                setup.TempResol = (short) Math.Round(template.dpi);
                setup.HideTemp = (ushort) (template.visible ? 0 : 1);
            }

            setup.Write(writer, version);

            size = (int) writer.Seek(0, SeekOrigin.Current) - pos;
            return pos;
        }