/**
 * SphericalLib.BinWriter
 * 
 * SphericalLib is a .NET library to deal with geometry on the unit sphere.
 * It is intented to be used for complex survey footprint descriptions in
 * standalone applications as well as in web services and perhaps Yukon.
 * 
 * Written by Tamas Budavari (budavari@pha.jhu.edu)
 * See bottom of file for revision history
 * 
 * Current revision:
 *   ID:          $Id: BinWriter.cs,v 1.1.1.1 2006/11/14 02:56:39 gupchup Exp $
 *   Revision:    $Revision: 1.1.1.1 $
 *   Date:        $Date: 2006/11/14 02:56:39 $
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Spherical;

namespace Spherical.IO
{
    /// <summary>
    /// [DEPRICATED] Class implements methods to write in binary format 
    /// the objects of the SphericalLib library.
    /// </summary>
    [CLSCompliant(true)]
    public class BinWriter 
    {
        private BinaryWriter writer;

        /// <summary>
        /// Create binary writer from filename
        /// </summary>
        /// <param name="path"></param>
        public BinWriter(string path)
        {
            FileStream output = new FileStream(path, FileMode.Create);
            writer = new BinaryWriter(output);
        }

        /// <summary>
        /// Create binary writer from stream
        /// </summary>
        /// <param name="output"></param>
        public BinWriter(Stream output)
        {
            writer = new BinaryWriter(output);
        }


        /// <summary>
        /// Write out a point
        /// </summary>
        /// <param name="c"></param>
        public void Write(Cartesian c)
        {
            writer.Write(c.X);
            writer.Write(c.Y);
            writer.Write(c.Z);
        }

        /// <summary>
        /// Write out a halfspace
        /// </summary>
        /// <param name="h"></param>
        public void Write(Halfspace h)
        {
            this.Write(h.Vector);
            writer.Write(h.Cos0);
        }

        /// <summary>
        /// Write out an arc
        /// </summary>
        /// <param name="a"></param>
        public void Write(Arc a)
        {
            this.Write(a.Point1);
            this.Write(a.Point2);
            this.Write(a.Circle);
        }

        /// <summary>
        /// Write out a patch
        /// </summary>
        /// <param name="p"></param>
        public void Write(Patch p)
        {
            writer.Write((byte)'P');
            writer.Write(p.ArcList.Count);
            foreach (Arc a in p.ArcList)
                this.Write(a);
        }

        /// <summary>
        /// Write out a convex
        /// </summary>
        /// <param name="c"></param>
        public void Write(Convex c)
        {
            writer.Write((byte)'C');
            writer.Write(c.HalfspaceList.Count);
            foreach (Halfspace h in c.HalfspaceList)
                this.Write(h);
            if (c.Simplified)
            {
                writer.Write((byte)'S');
                writer.Write(c.Area.Value);
                writer.Write((byte)'L');
                writer.Write(c.PatchList.Count);
                foreach (Patch p in c.PatchList)
                    this.Write(p);
            }
            else
            {
                writer.Write((byte)'N');
            }
        }

        /// <summary>
        /// Write out a region
        /// </summary>
        /// <param name="r"></param>
        public void Write(Region r)
        {
            writer.Write((byte)'R');
            writer.Write(r.ConvexList.Count);
            foreach (Convex c in r.ConvexList)
                this.Write(c);
        }

        /// <summary>
        /// Close writer
        /// </summary>
        public void Close()
        {
            writer.Close();
        }

        /// <summary>
        /// Revision from CVS
        /// </summary>
        public static string Revision
        {
            get { return "$Revision: 1.1.1.1 $"; }
        }
    }
}

#region Revision History
/* Revision History

        $Log: BinWriter.cs,v $
        Revision 1.1.1.1  2006/11/14 02:56:39  gupchup
        no message

        Revision 1.4  2006/05/23 13:21:10  budavari
        New binary IO via BinaryFormatter

        Revision 1.3  2006/04/19 16:52:13  budavari
        EVerything is now CLS compliant

        Revision 1.2  2006/03/21 22:06:53  budavari
        Binary IO upgraded to full

        Revision 1.1  2006/02/28 16:36:59  budavari
        Module has IO related classes

        Revision 1.1  2006/01/24 15:56:05  budavari
        Re-structured directory layout to accommodate more projects

        Revision 1.1  2005/12/14 22:35:33  budavari
        Binary IO classes

*/
#endregion