Added BlockFormatter, updated string construction for ColoredObject (More to follow)

This commit is contained in:
Mike Smith 2016-02-07 11:00:27 -08:00
parent 60286df583
commit f585e017c2
11 changed files with 210 additions and 5 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.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>{E1010464-A816-4F86-AE22-8465C27723C4}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OSCADSharp.ConsoleTests</RootNamespace>
<AssemblyName>OSCADSharp.ConsoleTests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OSCADSharp\OSCADSharp.csproj">
<Project>{e420ce17-2f13-4abc-87d7-c9744df39d3d}</Project>
<Name>OSCADSharp</Name>
</ProjectReference>
</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>

View File

@ -0,0 +1,27 @@
using OSCADSharp.Solids;
using OSCADSharp.Transforms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.ConsoleTests
{
class Program
{
static void Main(string[] args)
{
Cube cube = new Cube() {
Size = new Vector3(5, 5, 5),
Center = true
};
ColoredObject co = new ColoredObject(cube, "Red");
var evenMoreColors = new ColoredObject(co, "Blue", .5);
Console.WriteLine(evenMoreColors.ToString());
Console.ReadKey();
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OSCADSharp.ConsoleTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OSCADSharp.ConsoleTests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e1010464-a816-4f86-ae22-8465c27723c4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSCADSharp", "OSCADSharp\OSCADSharp.csproj", "{E420CE17-2F13-4ABC-87D7-C9744DF39D3D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSCADSharp.ConsoleTests", "OSCADSharp.ConsoleTests\OSCADSharp.ConsoleTests.csproj", "{E1010464-A816-4F86-AE22-8465C27723C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{E420CE17-2F13-4ABC-87D7-C9744DF39D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E420CE17-2F13-4ABC-87D7-C9744DF39D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E420CE17-2F13-4ABC-87D7-C9744DF39D3D}.Release|Any CPU.Build.0 = Release|Any CPU
{E1010464-A816-4F86-AE22-8465C27723C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1010464-A816-4F86-AE22-8465C27723C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1010464-A816-4F86-AE22-8465C27723C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1010464-A816-4F86-AE22-8465C27723C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp
{
/// <summary>
/// A class that creates blocks of curly-braced script with the
/// specified level of indentation
/// </summary>
internal class BlockFormatter
{
private string outerCode;
private string innerCode;
private string indentationAmount = " ";
internal BlockFormatter(string outerCode, string innerCode)
{
this.outerCode = outerCode;
this.innerCode = innerCode;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(outerCode);
sb.AppendLine("{");
using (StringReader reader = new StringReader(this.innerCode))
{
string line;
while ((line = reader.ReadLine()) != null)
{
sb.Append(this.indentationAmount);
sb.Append(line);
sb.Append(Environment.NewLine);
}
}
sb.AppendLine("}");
return sb.ToString();
}
}
}

View File

@ -40,6 +40,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BlockFormatter.cs" />
<Compile Include="OSCADObject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Solids\Cube.cs" />

View File

@ -9,7 +9,7 @@ namespace OSCADSharp.Solids
/// <summary>
/// A Cube geometry
/// </summary>
public class Cube
public class Cube : OSCADObject
{
#region Attributes
/// <summary>

View File

@ -9,7 +9,7 @@ namespace OSCADSharp.Solids
/// <summary>
/// A Cylinder geometry
/// </summary>
public class Cylinder
public class Cylinder : OSCADObject
{
#region Attributes
/// <summary>

View File

@ -9,7 +9,7 @@ namespace OSCADSharp.Solids
/// <summary>
/// A Sphere geometry
/// </summary>
public class Sphere
public class Sphere : OSCADObject
{
#region Attributes
/// <summary>

View File

@ -9,16 +9,33 @@ namespace OSCADSharp.Transforms
/// <summary>
/// An object that has color and/or opacity applied to it
/// </summary>
public class ColoredObject
public class ColoredObject : OSCADObject
{
#region Attributes
public string Color { get; set; } = "Yellow";
public double Opacity { get; set; } = 1.0;
#endregion
private OSCADObject obj;
/// <summary>
/// Creates a colorized object
/// </summary>
/// <param name="obj">The object(s) to which color will be applied</param>
/// <param name="Color">The string-wise name of the color to be applied</param>
/// <param name="opacity">Opacity from 0.0 to 1.0 </param>
public ColoredObject(OSCADObject obj, string Color = "Yellow", double opacity = 1.0)
{
this.obj = obj;
this.Color = Color;
this.Opacity = opacity;
}
public override string ToString()
{
return String.Format("color(\"{0}\", {1})", this.Color, this.Opacity);
string colorCommand = String.Format("color(\"{0}\", {1})", this.Color, this.Opacity);
var formatter = new BlockFormatter(colorCommand, this.obj.ToString());
return formatter.ToString();
}
}
}