Added LinearExtrudedObject, Text3D

This commit is contained in:
Mike Smith 2016-02-09 23:54:22 -08:00
parent a3435a24e7
commit b5d2160006
3 changed files with 82 additions and 10 deletions

View File

@ -40,6 +40,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Transforms\LinearExtrudedObject.cs" />
<Compile Include="Scripting\BlockFormatter.cs" /> <Compile Include="Scripting\BlockFormatter.cs" />
<Compile Include="Scripting\BlockStatementObject.cs" /> <Compile Include="Scripting\BlockStatementObject.cs" />
<Compile Include="Booleans\Difference.cs" /> <Compile Include="Booleans\Difference.cs" />

View File

@ -20,20 +20,20 @@ namespace OSCADSharp
/// The generated text will have approximately an ascent of the given value (height above the baseline). Default is 10. /// The generated text will have approximately an ascent of the given value (height above the baseline). Default is 10.
/// Note that specific fonts will vary somewhat and may not fill the size specified exactly, usually slightly smaller. /// Note that specific fonts will vary somewhat and may not fill the size specified exactly, usually slightly smaller.
/// </summary> /// </summary>
public uint Size { get; set; } public uint? Size { get; set; } = null;
/// <summary> /// <summary>
/// The name of the font that should be used. This is not the name of the font file, /// The name of the font that should be used. This is not the name of the font file,
/// but the logical font name (internally handled by the fontconfig library). This can also include a style parameter, see below. /// but the logical font name (internally handled by the fontconfig library). This can also include a style parameter, see below.
/// A list of installed fonts & styles can be obtained using the font list dialog (Help -> Font List). /// A list of installed fonts & styles can be obtained using the font list dialog (Help -> Font List).
/// </summary> /// </summary>
public string Font { get; set; } public string Font { get; set; } = null;
/// <summary> /// <summary>
/// The horizontal alignment for the text. Possible values are "left", "center" and "right". Default is "left". /// The horizontal alignment for the text. Possible values are "left", "center" and "right". Default is "left".
/// </summary> /// </summary>
/// TODO: Implement alignments /// TODO: Implement alignments
public string HorizontalAlignment { get; set; } //public string HorizontalAlignment { get; set; }
/// <summary> /// <summary>
/// The vertical alignment for the text. Possible values are "top", "center", "baseline" and "bottom". Default is "baseline". /// The vertical alignment for the text. Possible values are "top", "center", "baseline" and "bottom". Default is "baseline".
@ -44,7 +44,7 @@ namespace OSCADSharp
/// <summary> /// <summary>
/// Factor to increase/decrease the character spacing. The default value of 1 will result in the normal spacing for the font, giving a value greater than 1 will cause the letters to be spaced further apart. /// Factor to increase/decrease the character spacing. The default value of 1 will result in the normal spacing for the font, giving a value greater than 1 will cause the letters to be spaced further apart.
/// </summary> /// </summary>
public uint Spacing { get; set; } public uint? Spacing { get; set; } = null;
/// <summary> /// <summary>
/// Direction of the text flow. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), "ttb" (top-to-bottom) and "btt" (bottom-to-top). Default is "ltr". /// Direction of the text flow. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), "ttb" (top-to-bottom) and "btt" (bottom-to-top). Default is "ltr".
@ -55,22 +55,38 @@ namespace OSCADSharp
/// The language of the text. Default is "en". /// The language of the text. Default is "en".
/// </summary> /// </summary>
public string Language { get; set; } public string Language { get; set; }
/// <summary> /// <summary>
/// Used for subdividing the curved path segments provided by freetype /// Used for subdividing the curved path segments provided by freetype
/// ($fn in OpenSCAD) /// ($fn in OpenSCAD)
/// </summary> /// </summary>
public int Resolution { get; set; } = 0; /// TODO: Implement Resolution
// public int? Resolution { get; set; } = 0;
/// <summary>
/// The script of the text. Default is "latin".
/// </summary>
/// TODO: Implement Script
// public string Script { get; set; }
public override OSCADObject Clone() public override OSCADObject Clone()
{ {
throw new NotImplementedException(); return new Text3D()
{
Text = this.Text,
Size = this.Size,
Font = this.Font,
Spacing = this.Spacing,
TextDirection = this.TextDirection,
Language = this.Language
};
} }
private void appendValueIfExists(string name, string value, StringBuilder sb) private void appendIfValueNotNullOrEmpty(string name, string value, StringBuilder sb)
{ {
if(!String.IsNullOrEmpty(value)) if(!String.IsNullOrEmpty(value))
{ {
sb.Append(", ");
sb.Append(name); sb.Append(name);
sb.Append("="); sb.Append("=");
sb.Append(value); sb.Append(value);
@ -85,10 +101,15 @@ namespace OSCADSharp
sb.Append(this.Text); sb.Append(this.Text);
sb.Append("\""); sb.Append("\"");
appendValueIfExists("font", this.Font, sb); appendIfValueNotNullOrEmpty("size", this.Size?.ToString(), sb);
appendIfValueNotNullOrEmpty("font", this.Font, sb);
appendIfValueNotNullOrEmpty("spacing", this.Spacing?.ToString(), sb);
appendIfValueNotNullOrEmpty("direction", this.TextDirection?.ToString(), sb);
appendIfValueNotNullOrEmpty("language", this.Language?.ToString(), sb);
sb.Append(");"); sb.Append(");");
return base.ToString(); return sb.ToString();
} }
} }
} }

View File

@ -0,0 +1,50 @@
using OSCADSharp.Scripting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.Transforms
{
/// <summary>
/// Linear Extrusion is a modeling operation that takes a 2D polygon as input and extends it in the third dimension. This way a 3D shape is created.
///
/// This is a limited subset of the capabilities
/// </summary>
internal class LinearExtrudedObject : OSCADObject
{
/// <summary>
/// Height to extrude to
/// </summary>
public double Height { get; set; } = 1.0;
private OSCADObject obj;
//TODO: Possibly implement everything else?
//linear_extrude(height = fanwidth, center = true, convexity = 10, twist = -fanrot, slices = 20, scale = 1.0) {...}
/// <summary>
/// An object that will be extruded from 2d to 3d
/// </summary>
/// <param name="obj"></param>
/// <param name="height"></param>
public LinearExtrudedObject(OSCADObject obj, double height)
{
this.obj = obj;
this.Height = height;
}
public override OSCADObject Clone()
{
return new LinearExtrudedObject(this.obj, this.Height);
}
public override string ToString()
{
string extrudeCommand = String.Format("linear_extrude(height = {0})", this.Height.ToString());
var formatter = new BlockFormatter(extrudeCommand, this.obj.ToString());
return formatter.ToString();
}
}
}