mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-22 10:48:27 +00:00
Added Variables class, Settings class, settings/header output in OSCADObject.ToFile
This commit is contained in:
parent
8506459939
commit
4532e7b20d
@ -14,6 +14,7 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Settings.Globals["$fn"] = 100;
|
||||||
var obj = new Sphere(30);
|
var obj = new Sphere(30);
|
||||||
|
|
||||||
var pos = obj.Position();
|
var pos = obj.Position();
|
||||||
|
|||||||
@ -329,7 +329,12 @@ namespace OSCADSharp
|
|||||||
path += ".scad";
|
path += ".scad";
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllLines(path, new string[] { this.ToString() });
|
File.WriteAllLines(path, new string[]
|
||||||
|
{
|
||||||
|
Settings.OSCADSharpHeader,
|
||||||
|
Settings.Globals.ToString(),
|
||||||
|
this.ToString()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@ -44,6 +44,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Ids.cs" />
|
<Compile Include="Ids.cs" />
|
||||||
<Compile Include="Scripting\StatementBuilder.cs" />
|
<Compile Include="Scripting\StatementBuilder.cs" />
|
||||||
|
<Compile Include="Settings.cs" />
|
||||||
<Compile Include="Sizes.cs" />
|
<Compile Include="Sizes.cs" />
|
||||||
<Compile Include="Spatial\Bounds.cs" />
|
<Compile Include="Spatial\Bounds.cs" />
|
||||||
<Compile Include="Spatial\Matrix.cs" />
|
<Compile Include="Spatial\Matrix.cs" />
|
||||||
@ -68,6 +69,7 @@
|
|||||||
<Compile Include="Transforms\ScaledObject.cs" />
|
<Compile Include="Transforms\ScaledObject.cs" />
|
||||||
<Compile Include="Transforms\TranslatedObject.cs" />
|
<Compile Include="Transforms\TranslatedObject.cs" />
|
||||||
<Compile Include="Spatial\Vector3.cs" />
|
<Compile Include="Spatial\Vector3.cs" />
|
||||||
|
<Compile Include="Scripting\Variables.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
67
OSCADSharp/OSCADSharp/Scripting/Variables.cs
Normal file
67
OSCADSharp/OSCADSharp/Scripting/Variables.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OSCADSharp.Scripting
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A collection of names/values for variables
|
||||||
|
/// </summary>
|
||||||
|
public sealed class Variables
|
||||||
|
{
|
||||||
|
private Dictionary<string, object> variables = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Assigns or gets a variable's value
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public object this[string name] // long is a 64-bit integer
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (variables.ContainsKey(name))
|
||||||
|
{
|
||||||
|
return variables[name];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
variables[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This class is intended for use in other externally-exposed classes,
|
||||||
|
/// as such its constructor is not public.
|
||||||
|
/// </summary>
|
||||||
|
internal Variables()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the string representation for all variables
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
foreach (var kvp in this.variables)
|
||||||
|
{
|
||||||
|
sb.Append(kvp.Key);
|
||||||
|
sb.Append(" = ");
|
||||||
|
sb.Append(kvp.Value);
|
||||||
|
sb.Append(";");
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
OSCADSharp/OSCADSharp/Settings.cs
Normal file
27
OSCADSharp/OSCADSharp/Settings.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using OSCADSharp.Scripting;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OSCADSharp
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Settings for OpenSCAD scripts
|
||||||
|
/// </summary>
|
||||||
|
public static class Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Code-gen header
|
||||||
|
/// </summary>
|
||||||
|
public static readonly string OSCADSharpHeader = String.Format("/*Code Generated using OSCADSharp on {0}. {1}{2}For more information, please visit https://github.com/Exolun/OSCADSharp */{3}",
|
||||||
|
DateTime.Now.ToString(), Environment.NewLine, Environment.NewLine, Environment.NewLine);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Global variables that can be assigned for output at the
|
||||||
|
/// top of OpenSCAD scripts
|
||||||
|
/// </summary>
|
||||||
|
public static Variables Globals = new Variables();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user