forked from hezihertz/PachydermAcoustic_Rhinoceros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pach_RunSim_Command.cs
140 lines (127 loc) · 6.01 KB
/
Pach_RunSim_Command.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//'Pachyderm-Acoustic: Geometrical Acoustics for Rhinoceros (GPL) by Arthur van der Harten
//'
//'This file is part of Pachyderm-Acoustic.
//'
//'Copyright (c) 2008-2015, Arthur van der Harten
//'Pachyderm-Acoustic is free software; you can redistribute it and/or modify
//'it under the terms of the GNU General Public License as published
//'by the Free Software Foundation; either version 3 of the License, or
//'(at your option) any later version.
//'Pachyderm-Acoustic is distributed in the hope that it will be useful,
//'but WITHOUT ANY WARRANTY; without even the implied warranty of
//'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//'GNU General Public License for more details.
//'
//'You should have received a copy of the GNU General Public
//'License along with Pachyderm-Acoustic; if not, write to the Free Software
//'Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
using Rhino.Commands;
using System.Collections.Generic;
using System;
namespace Pachyderm_Acoustic
{
namespace UI
{
///<summary>C:\Users\User\Desktop\DEV\PachydermAcoustic_Rhinoceros\Pach_RunSim_Command.cs
/// A Rhino.NET plug-in can contain as many MRhinoCommand derived classes as it wants.
/// DO NOT create an instance of this class (this is the responsibility of Rhino.NET.)
/// </summary>
///
[System.Runtime.InteropServices.Guid("D3381146-DC13-44bb-8382-741669B9C66E")]
[Rhino.Commands.CommandStyle(Rhino.Commands.Style.Hidden)]
public class Pach_RunSim_Command : Command
{
///<summary>
/// Rhino tracks commands by their unique ID. Every command must have a unique id.
/// The Guid created by the project wizard is unique. You can create more Guids using
/// the "Create Guid" tool in the Tools menu.
///</summary>
///<returns>The id for this command</returns>
public Pach_RunSim_Command()
{
// Rhino only creates one instance of each command class defined in a
// plug-in, so it is safe to store a refence in a static property.
Instance = this;
}
///<summary>The only instance of this command.</summary>
public static Pach_RunSim_Command Instance
{
get;
private set;
}
///<returns>The command name as it appears on the Rhino command line</returns>
public override string EnglishName
{
get
{
return "Run_Simulation";
}
}
public Simulation_Type Sim = null;
public Result CommandResult = Result.Nothing;
private bool CancelCalc = false;
public System.Threading.CountdownEvent CD = new System.Threading.CountdownEvent(0);
///<summary> This gets called when when the user runs this command.</summary>
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
{
if (Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem != Rhino.UnitSystem.Meters)
{
System.Windows.Forms.MessageBox.Show("At this point in development, Pachyderm supports documents in meters only. Please set the document units to meters, and run the calculation again.\n(A quick way to get to the document units control is to type 'units' into the command prompt.)");
CommandResult = Result.Cancel;
return CommandResult;
}
////In order to deal with latency in memory, a thread sleep of 1 second is inserted...
//System.Threading.Thread.Sleep(1000);
//////////////////////////////////////////////////////////////////////////////////////
Rhino.RhinoApp.EscapeKeyPressed += Escape;
CancelCalc = false;
CommandResult = Result.Success;
Rhino.ApplicationSettings.FileSettings.AutoSaveEnabled = false;
if (Sim != null)
{
Sim.Begin();
Rhino.RhinoApp.SetCommandPrompt(string.Format("Initiating {0} Calculation...", Sim.Sim_Type()));
do
{
if (CancelCalc)
{
Sim.Abort_Calculation();
CommandResult = Result.Cancel;
Rhino.ApplicationSettings.FileSettings.AutoSaveEnabled = true;
return CommandResult;
}
if (Sim.ThreadState() != System.Threading.ThreadState.Running)
{
break;
}
System.Threading.Thread.Sleep(3000);
Rhino.RhinoApp.SetCommandPrompt(Sim.ProgressMsg());
} while (true);
Sim.Combine_ThreadLocal_Results();
do
{
System.Threading.Thread.Sleep(3000);
if (Sim.ThreadState() != System.Threading.ThreadState.Running)
{
break;
}
Rhino.RhinoApp.SetCommandPrompt(Sim.ProgressMsg());
} while (true);
}
Rhino.ApplicationSettings.FileSettings.AutoSaveEnabled = true;
//System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.Interactive;
Rhino.RhinoDoc.ActiveDoc.Views.RedrawEnabled = true;
return CommandResult;
}
private void Escape(object sender, System.EventArgs e)
{
CancelCalc = true;
}
public void Reset()
{
Sim = null;
CommandResult = Result.Nothing;
}
}
}
}