Skip to content

Commit 4121eb3

Browse files
committed
Added error display
1 parent de09729 commit 4121eb3

File tree

4 files changed

+68
-50
lines changed

4 files changed

+68
-50
lines changed

Examples/LinearExtrude.cs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var rootUnion = new MatterHackers.Csg.Operations.Union("root");
2+
rootUnion.Add(new LinearExtrude(new double[] {0, 10, 10, 10, 0, 0}, 10,new Alignment(), 0 ));
3+
return rootUnion;

Examples/Rotate.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var rootUnion = new MatterHackers.Csg.Operations.Union("root");
2+
3+
4+
for (int i = 0; i != 10; i++)
5+
6+
{
7+
rootUnion.Add(new Rotate(new BoxPrimitive(18, i, 14), 10 * i, 10, 10));
8+
}
9+
10+
11+
return rootUnion;
12+

Examples/snippet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
rootUnion.Add(new Translate(new BoxPrimitive(18, i, 14),10*i,10,10));
1616

17-
RenderCsgToGl.Render(rootUnion);
17+
return rootUnion;

OpenCSharpCad/MainWindow.cs

+52-49
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
using System;
2-
using MatterHackers.Agg;
1+
using MatterHackers.Agg;
32
using MatterHackers.Agg.OpenGlGui;
43
using MatterHackers.Agg.UI;
5-
using MatterHackers.VectorMath;
6-
7-
using System.CodeDom.Compiler;
8-
using System.Text;
9-
using System.Diagnostics;
10-
using System.IO;
11-
using System.Globalization;
12-
using MatterHackers.PolygonMesh.Processors;
13-
using MatterHackers.Agg.Image;
14-
using MatterHackers.Agg.VertexSource;
15-
using System.Dynamic;
16-
using System.Collections.Generic;
174
using MatterHackers.Csg;
185
using MatterHackers.Csg.Processors;
196
using MatterHackers.RenderOpenGl;
7+
using System;
8+
using System.CodeDom.Compiler;
9+
using System.Collections.Generic;
10+
using System.Diagnostics;
11+
using System.Dynamic;
12+
using System.Globalization;
13+
using System.IO;
14+
using System.Text;
2015

2116
namespace OpenSharpCAD
2217
{
@@ -31,6 +26,7 @@ public class MainWindow : SystemWindow
3126
private FlowLayoutWidget objectEditorList;
3227
private FlowLayoutWidget textSide;
3328
private TextEditWidget textEdit;
29+
private TextEditWidget outputEdit;
3430
//private Union rootUnion = new Union("root");
3531
dynamic classRef;
3632
private CsgObject previousRender;
@@ -53,21 +49,27 @@ public MainWindow() : base(1000, 1000)
5349
#region TextSide
5450
textSide = new FlowLayoutWidget(FlowDirection.TopToBottom);
5551

56-
5752
objectEditorView = new GuiWidget();
5853
objectEditorList = new FlowLayoutWidget();
59-
// objectEditorList.AddChild(new TextEditWidget("Text in box"));
54+
objectEditorList.AddChild(new TextEditWidget("Text in box"));
6055

61-
// objectEditorView.AddChild(objectEditorList);
56+
objectEditorView.AddChild(objectEditorList);
6257
objectEditorView.BackgroundColor = RGBA_Bytes.LightGray;
63-
// matterScriptEditor.LocalBounds = new RectangleDouble(0, 0, 200, 300);
64-
// textSide.AddChild(objectEditorView);
58+
//matterScriptEditor.LocalBounds = new RectangleDouble(0, 0, 200, 300);
59+
textSide.AddChild(objectEditorView);
6560
var code = new StringBuilder();
6661
code.AppendLine("var rootUnion = new MatterHackers.Csg.Operations.Union(\"root\");");
67-
//code.AppendLine("rootUnion.Add(new LinearExtrude(new double[] { 1.1, 2.2, 3.3, 6.3 }, 7));");
62+
code.AppendLine("//rootUnion.Add(new LinearExtrude(new double[] { 1.1, 2.2, 3.3, 6.3 }, 7));");
6863
code.AppendLine("rootUnion.Add(new Translate(new Cylinder(10, 40), 5, 10, 5));");
6964
code.AppendLine("rootUnion.Add(new BoxPrimitive(8, 20, 10));");
65+
66+
code.AppendLine("for (int i = 0; i != 10; i++)");
67+
code.AppendLine("{");
68+
code.AppendLine(" rootUnion.Add(new Translate(new BoxPrimitive(18, i, 14), 10 * i, 10+i, 10+i*i));");
69+
code.AppendLine("}");
70+
7071
code.AppendLine("return rootUnion;");
72+
7173
//code.AppendLine("MatterHackers.PolygonMesh.Mesh mesh = new MatterHackers.PolygonMesh.Mesh();");
7274
//code.AppendLine("var v0 = mesh.CreateVertex(new Vector3(1, 0, 1)); // V0");
7375
//code.AppendLine("var v1 = mesh.CreateVertex(new Vector3(1, 0, -1)); // V1");
@@ -88,6 +90,13 @@ public MainWindow() : base(1000, 1000)
8890
textEdit.Multiline = true;
8991
// hello.Text = code.ToString();
9092
textSide.AddChild(textEdit);
93+
94+
outputEdit = new TextEditWidget("Hello world!")
95+
{
96+
Multiline = true
97+
};
98+
outputEdit.AnchorAll();
99+
textSide.AddChild(outputEdit);
91100
textSide.AnchorAll();
92101
textEdit.AnchorAll();
93102
objectEditorList.AnchorAll();
@@ -188,16 +197,18 @@ private void Compile()
188197

189198
//-----------------
190199
// Create the class as usual
191-
sb.AppendLine("using System;");
192-
sb.AppendLine("using System.Windows.Forms;");
193-
sb.AppendLine("using System.Collections.Generic;");
194-
sb.AppendLine("using MatterHackers.PolygonMesh;");
200+
//sb.AppendLine("using System;");
201+
//sb.AppendLine("using System.Windows.Forms;");
202+
//sb.AppendLine("using System.Collections.Generic;");
203+
//sb.AppendLine("using MatterHackers.PolygonMesh;");
195204
sb.AppendLine("using MatterHackers.VectorMath; ");
196-
sb.AppendLine("using MatterHackers.Csg.Operations; ");
197-
sb.AppendLine("using MatterHackers.Csg; ");
198-
sb.AppendLine("using MatterHackers.Csg.Solids; ");
199-
sb.AppendLine("using MatterHackers.RenderOpenGl; ");
200-
sb.AppendLine("using MatterHackers.Agg;");
205+
206+
//sb.AppendLine("using MatterHackers.Csg.Operations;");
207+
sb.AppendLine("using MatterHackers.Csg;");
208+
sb.AppendLine("using MatterHackers.Csg.Solids;");
209+
////sb.AppendLine("using .Alignment;");
210+
//sb.AppendLine("using MatterHackers.RenderOpenGl;");
211+
//sb.AppendLine("using MatterHackers.Agg;");
201212
sb.AppendLine("using MatterHackers.Csg.Transform;");
202213

203214
// sb.AppendLine();
@@ -216,15 +227,6 @@ private void Compile()
216227
sb.AppendLine(" }");
217228
sb.AppendLine("}");
218229

219-
//if (rootUnion != null)
220-
//{
221-
// RenderCsgToGl.Render(rootUnion);
222-
//}
223-
////if (meshToRender != null)
224-
////{
225-
//// RenderMeshToGl.Render(meshToRender, RGBA_Bytes.Gray);
226-
////}
227-
228230
//-----------------
229231
// The finished code
230232
string classCode = sb.ToString();
@@ -233,8 +235,7 @@ private void Compile()
233235
// Dont need any extra assemblies
234236
try
235237
{
236-
//txtErrors.Clear();
237-
238+
outputEdit.Text = string.Empty;
238239
//------------
239240
// Pass the class code, the namespace of the class and the list of extra assemblies needed
240241
classRef = DynCode.CodeHelper.HelperFunction(classCode, "OpenSharpCadSnippet.RenderTest", new object[] { });
@@ -247,22 +248,21 @@ private void Compile()
247248

248249
foreach (CompilerError error in (CompilerErrorCollection)classRef)
249250
{
250-
sberror.AppendLine(string.Format("{0}:{1} {2} {3}", error.Line, error.Column, error.ErrorNumber, error.ErrorText));
251-
Debug.WriteLine("{0}:{1} {2} {3}", error.Line, error.Column, error.ErrorNumber, error.ErrorText);
251+
var err = string.Format("{0}:{1} {2} {3}", error.Line, error.Column, error.ErrorNumber, error.ErrorText);
252+
sberror.AppendLine(err);
253+
Debug.WriteLine(err);
254+
outputEdit.Text += err + "\n";
252255
}
253-
254-
// txtErrors.Text = sberror.ToString();
255-
256256
return;
257257
}
258258
}
259259
catch (Exception ex)
260260
{
261261
Debug.WriteLine(ex.Message);
262-
// If something very bad happened then throw it
263-
// MessageBox.Show(ex.Message);
262+
outputEdit.Text += ex.Message + "\n";
264263
throw;
265264
}
265+
266266
}
267267
private void glLightedView_DrawGlContent(object sender, EventArgs e)
268268
{
@@ -275,7 +275,6 @@ private void glLightedView_DrawGlContent(object sender, EventArgs e)
275275
CsgObject ren = classRef.Render();
276276
RenderCsgToGl.Render(ren);
277277
previousRender = ren;
278-
//OpenSCadOutput.Save(ren, "Ren.scad");
279278
}
280279
else
281280
{
@@ -285,7 +284,11 @@ private void glLightedView_DrawGlContent(object sender, EventArgs e)
285284
}
286285
}
287286
}
288-
catch (Exception) { }
287+
catch (Exception ex)
288+
{
289+
Debug.WriteLine(ex.Message);
290+
outputEdit.Text = ex.Message + "\n";
291+
}
289292
}
290293

291294
public static bool IsPropertyExist(dynamic settings, string name)

0 commit comments

Comments
 (0)