mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 13:38:33 +00:00
Added DefaultFileInvoker, updated FileInvoker, made OSCADObject return a fileInvoker from .ToFile
This commit is contained in:
parent
9305dcf5ec
commit
4474d43532
@ -26,7 +26,7 @@ namespace OSCADSharp.ConsoleTests
|
||||
//var topCorner = new Sphere().Translate(obj.Bounds().TopRight);
|
||||
//var botCorner = new Sphere().Translate(obj.Bounds().BottomLeft);
|
||||
|
||||
(obj + axisHelper).ToFile("test.scad");
|
||||
(obj + axisHelper).ToFile("test.scad").Open();
|
||||
|
||||
//Console.ReadKey();
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using OSCADSharp.Booleans;
|
||||
using OSCADSharp.Scripting;
|
||||
using OSCADSharp.Spatial;
|
||||
using OSCADSharp.Transforms;
|
||||
using System;
|
||||
@ -320,7 +321,7 @@ namespace OSCADSharp
|
||||
/// (This is just a shortcut for File.WriteAllLines)
|
||||
/// </summary>
|
||||
/// <param name="filePath">Path for the file to write. Including filename and (optionally) file extension</param>
|
||||
public void ToFile(string filePath)
|
||||
public IFileInvoker ToFile(string filePath)
|
||||
{
|
||||
string path = filePath;
|
||||
|
||||
@ -335,6 +336,8 @@ namespace OSCADSharp
|
||||
Settings.Globals.ToString(),
|
||||
this.ToString()
|
||||
});
|
||||
|
||||
return new DefaultFileInvoker(filePath);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Scripting\DefaultFileInvoker.cs" />
|
||||
<Compile Include="Scripting\DefaultFileWriter.cs" />
|
||||
<Compile Include="Scripting\IFileInvoker.cs" />
|
||||
<Compile Include="Scripting\IFileWriter.cs" />
|
||||
|
||||
28
OSCADSharp/OSCADSharp/Scripting/DefaultFileInvoker.cs
Normal file
28
OSCADSharp/OSCADSharp/Scripting/DefaultFileInvoker.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OSCADSharp.Scripting
|
||||
{
|
||||
internal class DefaultFileInvoker : IFileInvoker
|
||||
{
|
||||
private string filePath;
|
||||
public DefaultFileInvoker(string filePath)
|
||||
{
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public void CreateModel(string outputFile)
|
||||
{
|
||||
Process.Start(Settings.OpenSCADPath, String.Format("-o {0} {1}", outputFile, this.filePath));
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
Process.Start(Settings.OpenSCADPath, String.Format("{0}", this.filePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,15 +7,19 @@ using System.Threading.Tasks;
|
||||
namespace OSCADSharp.Scripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Opens a file
|
||||
/// Invokes OpenSCAD actions on output files
|
||||
/// </summary>
|
||||
public interface IFileInvoker
|
||||
{
|
||||
/// <summary>
|
||||
/// Opens the specified file
|
||||
/// Launches OpenSCAD with the specified file open
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the file to open</param>
|
||||
/// <param name="arguments">Command-line arguments to pass in</param>
|
||||
void Invoke(string path, string arguments = null);
|
||||
void Open();
|
||||
|
||||
/// <summary>
|
||||
/// Generates an STL from this file with the specified path/name
|
||||
/// </summary>
|
||||
/// <param name="outputFile"></param>
|
||||
void CreateModel(string outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,5 +28,11 @@ namespace OSCADSharp
|
||||
/// Used to write scripts to file
|
||||
/// </summary>
|
||||
public static IFileWriter FileWriter = new DefaultFileWriter();
|
||||
|
||||
/// <summary>
|
||||
/// Path to the OpenSCAD executable for file invocation
|
||||
/// (Default value is set the default install directory on Windows)
|
||||
/// </summary>
|
||||
public static string OpenSCADPath = @"C:\Program Files (x86)\OpenSCAD\openscad.exe";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user