1
- using System ;
2
- using MatterHackers . Agg ;
1
+ using MatterHackers . Agg ;
3
2
using MatterHackers . Agg . OpenGlGui ;
4
3
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 ;
17
4
using MatterHackers . Csg ;
18
5
using MatterHackers . Csg . Processors ;
19
6
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 ;
20
15
21
16
namespace OpenSharpCAD
22
17
{
@@ -31,6 +26,7 @@ public class MainWindow : SystemWindow
31
26
private FlowLayoutWidget objectEditorList ;
32
27
private FlowLayoutWidget textSide ;
33
28
private TextEditWidget textEdit ;
29
+ private TextEditWidget outputEdit ;
34
30
//private Union rootUnion = new Union("root");
35
31
dynamic classRef ;
36
32
private CsgObject previousRender ;
@@ -53,21 +49,27 @@ public MainWindow() : base(1000, 1000)
53
49
#region TextSide
54
50
textSide = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
55
51
56
-
57
52
objectEditorView = new GuiWidget ( ) ;
58
53
objectEditorList = new FlowLayoutWidget ( ) ;
59
- // objectEditorList.AddChild(new TextEditWidget("Text in box"));
54
+ objectEditorList . AddChild ( new TextEditWidget ( "Text in box" ) ) ;
60
55
61
- // objectEditorView.AddChild(objectEditorList);
56
+ objectEditorView . AddChild ( objectEditorList ) ;
62
57
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 ) ;
65
60
var code = new StringBuilder ( ) ;
66
61
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));" ) ;
68
63
code . AppendLine ( "rootUnion.Add(new Translate(new Cylinder(10, 40), 5, 10, 5));" ) ;
69
64
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
+
70
71
code . AppendLine ( "return rootUnion;" ) ;
72
+
71
73
//code.AppendLine("MatterHackers.PolygonMesh.Mesh mesh = new MatterHackers.PolygonMesh.Mesh();");
72
74
//code.AppendLine("var v0 = mesh.CreateVertex(new Vector3(1, 0, 1)); // V0");
73
75
//code.AppendLine("var v1 = mesh.CreateVertex(new Vector3(1, 0, -1)); // V1");
@@ -88,6 +90,13 @@ public MainWindow() : base(1000, 1000)
88
90
textEdit . Multiline = true ;
89
91
// hello.Text = code.ToString();
90
92
textSide . AddChild ( textEdit ) ;
93
+
94
+ outputEdit = new TextEditWidget ( "Hello world!" )
95
+ {
96
+ Multiline = true
97
+ } ;
98
+ outputEdit . AnchorAll ( ) ;
99
+ textSide . AddChild ( outputEdit ) ;
91
100
textSide . AnchorAll ( ) ;
92
101
textEdit . AnchorAll ( ) ;
93
102
objectEditorList . AnchorAll ( ) ;
@@ -188,16 +197,18 @@ private void Compile()
188
197
189
198
//-----------------
190
199
// 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;");
195
204
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;");
201
212
sb . AppendLine ( "using MatterHackers.Csg.Transform;" ) ;
202
213
203
214
// sb.AppendLine();
@@ -216,15 +227,6 @@ private void Compile()
216
227
sb . AppendLine ( " }" ) ;
217
228
sb . AppendLine ( "}" ) ;
218
229
219
- //if (rootUnion != null)
220
- //{
221
- // RenderCsgToGl.Render(rootUnion);
222
- //}
223
- ////if (meshToRender != null)
224
- ////{
225
- //// RenderMeshToGl.Render(meshToRender, RGBA_Bytes.Gray);
226
- ////}
227
-
228
230
//-----------------
229
231
// The finished code
230
232
string classCode = sb . ToString ( ) ;
@@ -233,8 +235,7 @@ private void Compile()
233
235
// Dont need any extra assemblies
234
236
try
235
237
{
236
- //txtErrors.Clear();
237
-
238
+ outputEdit . Text = string . Empty ;
238
239
//------------
239
240
// Pass the class code, the namespace of the class and the list of extra assemblies needed
240
241
classRef = DynCode . CodeHelper . HelperFunction ( classCode , "OpenSharpCadSnippet.RenderTest" , new object [ ] { } ) ;
@@ -247,22 +248,21 @@ private void Compile()
247
248
248
249
foreach ( CompilerError error in ( CompilerErrorCollection ) classRef )
249
250
{
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 " ;
252
255
}
253
-
254
- // txtErrors.Text = sberror.ToString();
255
-
256
256
return ;
257
257
}
258
258
}
259
259
catch ( Exception ex )
260
260
{
261
261
Debug . WriteLine ( ex . Message ) ;
262
- // If something very bad happened then throw it
263
- // MessageBox.Show(ex.Message);
262
+ outputEdit . Text += ex . Message + "\n " ;
264
263
throw ;
265
264
}
265
+
266
266
}
267
267
private void glLightedView_DrawGlContent ( object sender , EventArgs e )
268
268
{
@@ -275,7 +275,6 @@ private void glLightedView_DrawGlContent(object sender, EventArgs e)
275
275
CsgObject ren = classRef . Render ( ) ;
276
276
RenderCsgToGl . Render ( ren ) ;
277
277
previousRender = ren ;
278
- //OpenSCadOutput.Save(ren, "Ren.scad");
279
278
}
280
279
else
281
280
{
@@ -285,7 +284,11 @@ private void glLightedView_DrawGlContent(object sender, EventArgs e)
285
284
}
286
285
}
287
286
}
288
- catch ( Exception ) { }
287
+ catch ( Exception ex )
288
+ {
289
+ Debug . WriteLine ( ex . Message ) ;
290
+ outputEdit . Text = ex . Message + "\n " ;
291
+ }
289
292
}
290
293
291
294
public static bool IsPropertyExist ( dynamic settings , string name )
0 commit comments