14
14
using Rhino ;
15
15
using Rhino . NodeInCode ;
16
16
using GH_IO . Serialization ;
17
+ using System . Windows . Forms ;
17
18
18
19
// In order to load the result of this wizard, you will also need to
19
20
// add the output bin/ folder of this project to the list of loaded
@@ -38,16 +39,17 @@ public Ghost()
38
39
{
39
40
}
40
41
41
- protected bool complete = false ; //TODO: serialize these
42
+ protected bool complete = false ;
42
43
protected bool running = false ;
43
44
protected bool interrupt = false ;
44
- protected long comptime ;
45
- protected string [ ] workerwarnings = new string [ ] { } ;
45
+ protected bool trigger = false ;
46
46
47
+ protected string comptime ;
48
+ protected string [ ] workerwarnings = new string [ ] { } ;
47
49
protected bool reparams = false ;
48
50
protected ComponentFunctionInfo trgtcomp ;
49
51
protected IGH_DocumentObject srcobj ;
50
- protected Guid srcobj_id = Guid . Empty ;
52
+ protected Guid srcobj_id = Guid . Empty ; // for IO only
51
53
protected object [ ] evaluated ;
52
54
53
55
/// <summary>
@@ -102,12 +104,13 @@ protected void GhostEval(object[] prms)
102
104
if ( prms . Length == 0 || trgtcomp == null )
103
105
{
104
106
complete = true && ! interrupt ;
105
- lock ( locker ) comptime = 0 ;
107
+ lock ( locker ) comptime = " 0ms" ;
106
108
}
107
109
else if ( running )
108
110
{
109
111
// shouldn't ever be here!
110
112
complete = false ;
113
+ lock ( locker ) workerwarnings = new string [ ] { "Somehow a second ghost tried to start a task. It's been stopped." , } ;
111
114
return ; //skip invoke recompute
112
115
}
113
116
else
@@ -125,13 +128,49 @@ protected void GhostEval(object[] prms)
125
128
ticker . Stop ( ) ;
126
129
lock ( locker )
127
130
{
128
- comptime = ticker . ElapsedMilliseconds ;
131
+ comptime = WatchParse ( ticker ) ;
129
132
evaluated = results ;
130
133
}
131
134
}
132
135
RhinoApp . InvokeOnUiThread ( new Action < bool > ( ExpireSolution ) , new object [ ] { true , } ) ;
133
136
}
134
-
137
+ /// <summary>
138
+ /// parse the stopwatch ellapsed time
139
+ /// </summary>
140
+ /// <param name="w">stop watch object</param>
141
+ /// <returns>legible string of the time span</returns>
142
+ protected string WatchParse ( Stopwatch w )
143
+ {
144
+ if ( w . ElapsedMilliseconds < 1000 )
145
+ return string . Format ( " {0}ms" , w . ElapsedMilliseconds ) ;
146
+ else
147
+ {
148
+ var h = w . Elapsed . Hours ;
149
+ var m = w . Elapsed . Minutes ;
150
+ var s = w . Elapsed . Seconds ;
151
+ var ms = w . Elapsed . Milliseconds ;
152
+ return string . Format ( " {0}{1}{2}" ,
153
+ h == 0 ? "" : h . ToString ( ) + "hrs " ,
154
+ m == 0 ? "" : m . ToString ( ) + "mins " ,
155
+ s == 0 ? "" : ( s + ms / 1000.0 ) . ToString ( ) + "secs"
156
+ ) ;
157
+ }
158
+ }
159
+
160
+ private void OnUnblock ( object s , EventArgs e )
161
+ {
162
+ trigger = ! trigger ;
163
+ }
164
+ public override void AppendAdditionalMenuItems ( ToolStripDropDown menu )
165
+ {
166
+ base . AppendAdditionalMenuItems ( menu ) ;
167
+ try
168
+ {
169
+ ToolStripMenuItem recomp = menu . Items . Add ( "Unblock recompute queueing" , null , OnUnblock ) as ToolStripMenuItem ;
170
+ recomp . Checked = trigger ;
171
+ }
172
+ catch { }
173
+ }
135
174
136
175
/// <summary>
137
176
/// Registers all the input parameters for this component.
@@ -243,7 +282,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
243
282
complete = false ; // sets up next solution
244
283
Message = "Finished" ;
245
284
consoletxt += string . Format (
246
- comptime == 0 ? "\n (that thing computed instantly...you really needed me here?)" : "\n (latest solution took {0}ms )" ,
285
+ comptime == " 0ms" ? "\n (that thing computed instantly...you really needed me here?)" : "\n (latest solution took{0})" ,
247
286
comptime ) ;
248
287
try { consoletxt += "\n Runtime warnings >>>\n " + string . Join ( "\n " , workerwarnings ) ; }
249
288
catch ( ArgumentNullException ) { }
@@ -252,8 +291,13 @@ protected override void SolveInstance(IGH_DataAccess DA)
252
291
else if ( running && ! complete )
253
292
{
254
293
Message = "Computing" ;
255
- interrupt = true ;
256
- consoletxt += "\n (interruption detected\n solution will restart once current task finishes)" ;
294
+ if ( trigger )
295
+ {
296
+ interrupt = true ;
297
+ consoletxt += "\n (interruption detected\n solution will restart once current task finishes)" ;
298
+ }
299
+ else
300
+ consoletxt += "\n (interruption not handled\n unblock queueing in context menu if needed)" ;
257
301
}
258
302
else
259
303
{
@@ -280,7 +324,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
280
324
}
281
325
if ( evaluated [ i - 1 ] is IGH_DataTree outtree )
282
326
DA . SetDataTree ( i , outtree ) ;
283
- else
327
+ else if ( ! running )
284
328
AddRuntimeMessage ( GH_RuntimeMessageLevel . Error , " internal error: worker output data mismatch" ) ;
285
329
}
286
330
}
@@ -299,7 +343,7 @@ public bool CanInsertParameter(GH_ParameterSide side, int i)
299
343
{
300
344
if ( side == GH_ParameterSide . Input && i <= comp . Params . Input . Count && i == Params . Input . Count )
301
345
return true ;
302
- else if ( side == GH_ParameterSide . Output && i <= comp . Params . Input . Count && i == Params . Output . Count )
346
+ else if ( side == GH_ParameterSide . Output && i <= comp . Params . Output . Count && i == Params . Output . Count )
303
347
return true ;
304
348
else
305
349
return false ;
0 commit comments