Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Allockse committed Mar 28, 2014
0 parents commit a784b86
Show file tree
Hide file tree
Showing 24 changed files with 778 additions and 0 deletions.
81 changes: 81 additions & 0 deletions PiaFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using System;
using System.IO;
using PiaNO.Serialization;

namespace PiaNO
{
public abstract class PiaFile
{
protected string _rawData;
public PiaHeader Header { get; private set; }

//protected abstract string _serialize();
//protected abstract void _deserialize();

protected virtual void Deserialize()
{
PiaSerializer.Deserialize(this, _rawData);
}
protected virtual Stream Serialize()
{
throw new NotImplementedException();
}

public void Read(string fileName)
{
if (string.IsNullOrEmpty(fileName))
throw new ArgumentNullException("fileName");

if (!File.Exists(fileName))
throw new FileNotFoundException("Plot file not found", fileName);

try
{
var piaStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
Read(piaStream);
}
catch (Exception)
{
throw;
}

}
public void Read(Stream stream)
{
try
{
var headerBytes = new Byte[60];
stream.Read(headerBytes, 0, headerBytes.Length);
var headerString = System.Text.Encoding.Default.GetString(headerBytes);
Header = new PiaHeader(headerString);

using (var zStream = new InflaterInputStream(stream))
{
var sr = new StreamReader(zStream);
_rawData = sr.ReadToEnd();
}

Deserialize();
}
catch (Exception)
{
throw;
}
finally
{
stream.Close();
stream.Dispose();
}
}

public void Write(string fileName)
{

}
public void Write(Stream stream)
{

}
}
}
37 changes: 37 additions & 0 deletions PiaHeader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace PiaNO
{
public class PiaHeader
{
private const string PIA_HEADER_FORMAT = @"PIAFILEVERSION_{0},{1}VER{2},compress\r\npmzlibcodec\255\255\255\255\255\255\255\000\255\255\255\000";
private string _rawData;

public double PIAVersion { get; private set; }
public short SubVersion { get; private set; }
public PiaType SubType { get; private set; }

public PiaHeader(string headerString)
{
_rawData = headerString;

var firstLine = headerString.Split()[0];
var headerArray = headerString.Split(new char[] { ',', '_'});
if (headerArray.Length < 4)
throw new ArgumentOutOfRangeException();

PIAVersion = Double.Parse(headerArray[1]);

var typeString = headerArray[2].Substring(0, 3);
SubType = (PiaType)Enum.Parse(typeof(PiaType), typeString);

var versionString = headerArray[2].Substring(3).ToUpper().Replace("VER", string.Empty);
SubVersion = Int16.Parse(versionString);
}

public override string ToString()
{
return string.Format(PIA_HEADER_FORMAT, PIAVersion, SubType, SubVersion);
}
}
}
70 changes: 70 additions & 0 deletions PiaNO.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{82883B8D-0C5F-4CDA-9706-160ADAEE5539}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PiaNO</RootNamespace>
<AssemblyName>PiaNO</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\PC3Composer\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Plot\ColorDependentPlotStyleTable.cs" />
<Compile Include="Plot\EndStyle.cs" />
<Compile Include="Plot\FillStyle.cs" />
<Compile Include="Plot\JoinStyle.cs" />
<Compile Include="PiaFile.cs" />
<Compile Include="PiaHeader.cs" />
<Compile Include="PiaType.cs" />
<Compile Include="Plot\Media.cs" />
<Compile Include="Plot\PlotterConfiguration.cs" />
<Compile Include="Plot\PlotStyle.cs" />
<Compile Include="Plot\PlotStyleTable.cs" />
<Compile Include="Plot\PlotterModelParameters.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\PiaSerializationReader.cs" />
<Compile Include="Serialization\PiaSerializer.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
14 changes: 14 additions & 0 deletions PiaType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PiaNO
{
public enum PiaType
{
PC3,
STB,
CTB
}
}
51 changes: 51 additions & 0 deletions Plot/ColorDependentPlotStyleTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PiaNO.Plot
{
public class ColorDependentPlotStyleTable : PlotStyleTable
{
public IList<string> AciTable { get; private set; }

public ColorDependentPlotStyleTable()
: base()
{
AciTable = new string[256];
for (int i = 0; i < AciTable.Count;)
AciTable[i] = "Color " + ++i;

_rebuildStyles();
}

protected ColorDependentPlotStyleTable(string rawData)
:base(rawData)
{

}

private void _rebuildStyles()
{
foreach (var name in AciTable)
{
var newStyle = new PlotStyle { Name = name };
InnerStyles.Add(newStyle);
}
}

public override void Add(PlotStyle item) { }
public override void Clear()
{
InnerStyles.Clear();
_rebuildStyles();
}
public override void Insert(int index, PlotStyle item) { }
public override bool Remove(PlotStyle item)
{
return false;
}
public override void RemoveAt(int index) { }

}
}
12 changes: 12 additions & 0 deletions Plot/EndStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

namespace PiaNO.Plot
{
public enum EndStyle
{
Butt = 0,
Square = 1,
Round = 2,
Diamond = 3,
FromObject = 4
}
}
17 changes: 17 additions & 0 deletions Plot/FillStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

namespace PiaNO.Plot
{
public enum FillStyle
{
Solid = 64,
Checkerboard = 65,
Crosshatch = 66,
Diamonds = 67,
HorizontalBars = 68,
SlantLeft = 69,
SlantRight = 70,
SquareDots = 71,
VerticalBars = 72,
FromObject = 73
}
}
12 changes: 12 additions & 0 deletions Plot/JoinStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

namespace PiaNO.Plot
{
public enum JoinStyle
{
Miter = 0,
Bevel = 1,
Round = 2,
Diamond = 3,
FromObject = 5
}
}
18 changes: 18 additions & 0 deletions Plot/Media.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PiaNO.Plot
{
public class Media
{
public long Abilities; // bitwise
public int CapsState; // bitwise?
public long UIOwner;
public double SizeMaxX { get; set; } // Some encoding here
public double SizeMaxY { get; set; } // ^


}
}
Loading

0 comments on commit a784b86

Please sign in to comment.