private void SaveDataToolStripMenuItem_Click(object sender, EventArgs e) { PachydermAc_PlugIn plugin = PachydermAc_PlugIn.Instance; System.Windows.Forms.SaveFileDialog sf = new System.Windows.Forms.SaveFileDialog(); sf.DefaultExt = ".pccm"; sf.AddExtension = true; sf.Filter = "Pachyderm Custom Map file (*.pccm)|*.pccm|" + "All Files|"; if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.IO.BinaryWriter sw = new System.IO.BinaryWriter(System.IO.File.Open(sf.FileName, System.IO.FileMode.Create)); //1. Date & Time (String) sw.Write(System.DateTime.Now.ToString()); //2. Plugin Version (String) sw.Write(plugin.Version); //3. Number of Parameter Meshes (int) sw.Write(Collection.Count); for (int t = 0; t < Collection.Count; t++) { //4. Title (string) sw.Write(Collection[t].Title); //5. Number of parameters/Vertices (int) int VertCt = Collection[t].Params.Length; sw.Write(Collection[t].Params.Length); //6. Write Parameter data (string) (double[VertCt]) sw.Write("Parameter Values"); for (int u = 0; u < VertCt; u++) { sw.Write(Collection[t].Params[u]); } //7. Write Vertex Locations (string) (double[VertCt][3]) sw.Write("Vertex Locations"); for (int u = 0; u < VertCt; u++) { //Write Vertex: (double) (double) (double) sw.Write(Collection[t].M.Vertices[u].X); sw.Write(Collection[t].M.Vertices[u].Y); sw.Write(Collection[t].M.Vertices[u].Z); } //8. Announce Mesh Faces (string) sw.Write("Mesh Faces"); for (int u = 0; u < Collection[t].M.Faces.Count; u++) { // Write mesh vertex indices: (int) (int) (int) (int) sw.Write((UInt32)Collection[t].M.Faces[u][0]); sw.Write((UInt32)Collection[t].M.Faces[u][1]); sw.Write((UInt32)Collection[t].M.Faces[u][2]); sw.Write((UInt32)Collection[t].M.Faces[u][3]); } } sw.Write("End_of_File"); sw.Close(); } }
/// <summary> /// Autopopulates the splash screen based on parameters set in the plugin base class. /// </summary> public Pach_Splash() { InitializeComponent(); PachydermAc_PlugIn p = PachydermAc_PlugIn.Instance; //Application info Version_box.Text = string.Format("Version: {0}", p.Version); Version_box.ForeColor = System.Drawing.Color.White; title_box.ForeColor = System.Drawing.Color.White; Copyright.ForeColor = System.Drawing.Color.White; Attribution.ForeColor = System.Drawing.Color.White; }
///<summary> This gets called when when the user runs this command.</summary> /// protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { string special = ""; Result CommandResult = Rhino.Input.RhinoGet.GetString("Enter a special condition code for Pachyderm simulations: (entering no code resets simulations to default)", true, ref special); PachydermAc_PlugIn.Instance.m_Obj_Page.OnActivate(true); PachydermAc_PlugIn P = PachydermAc_PlugIn.Instance; if (special == "" || special == null) { P.SpecialCode = ""; Rhino.RhinoApp.WriteLine("Code set to default"); } else { P.SpecialCode = special; Rhino.RhinoApp.WriteLine(string.Format("Code set to '{0}'", special)); } return(CommandResult); }
private void Calculate_Click(object sender, System.EventArgs e) { Pach_GetModel_Command Model = new Pach_GetModel_Command(); Source[] Source; if (PachydermAc_PlugIn.Instance.Source(out Source) && !object.ReferenceEquals(FileLocation.SelectedPath, "")) { Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation..."); } ParticleRays[] RTParticles = new ParticleRays[Source.Length]; Calculate.Enabled = false; PachydermAc_PlugIn plugin = PachydermAc_PlugIn.Instance; Scene Sc; if (PachydermAc_PlugIn.Instance.Geometry_Spec() == 0) { Sc = PachTools.Get_NURBS_Scene(0, (double)Air_Temp.Value, 0, 0, false); } else { Sc = PachTools.Get_Poly_Scene(0, (double)Air_Temp.Value, 0, 0, false); } for (int i = 0; i < Source.Length; i++) { if (Source != null) { List <Point3d> L = new List <Point3d>(); List <Rhino.Geometry.Point3d> L_RC = new List <Rhino.Geometry.Point3d>(); for (int j = 0; j < Source.Length; j++) { L.Add(Source[j].Origin()); L_RC.Add(new Rhino.Geometry.Point3d(Source[j].Origin().X, Source[j].Origin().Y, Source[j].Origin().Z)); } if (plugin.Geometry_Spec() == 0) { Sc.partition(L_RC, 15); RTParticles[i] = new ParticleRays(Source[i], Sc, (int)RT_Count.Value, CutOffLength()); } else if (plugin.Geometry_Spec() == 1) { Sc.partition(L, 15); RTParticles[i] = new ParticleRays(Source[i], Sc, (int)RT_Count.Value, CutOffLength()); } RTParticles[i].Begin(); } else { Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation..."); } Pachyderm_Acoustic.Visualization.Phonon P; if (ParticleChoice.SelectedIndex == 0) { P = new Tetrahedron(); } else if (ParticleChoice.SelectedIndex == 1) { P = new Icosahedron(); } else { P = new Geodesic_sphere(); } RenderParticles(RTParticles, (double)(Frame_Rate.Value * Seconds.Value), P); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); } Calculate.Enabled = true; }
private void Preview_Click(object sender, EventArgs e) { Loop.Enabled = false; ForwButton.Enabled = false; BackButton.Enabled = false; PachydermAc_PlugIn plugin = PachydermAc_PlugIn.Instance; if (PreviewDisplay != null) { PreviewDisplay.Enabled = false; } max = (int)(Frame_Rate.Value * Seconds.Value); Point3d[] SPT; if (!plugin.SourceOrigin(out SPT)) { Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation..."); return; } if (T != null && T.ThreadState == System.Threading.ThreadState.Running) { T.Abort(); } PreviewDisplay = null; Pach_GetModel_Command Model = Pach_GetModel_Command.Instance; if (object.ReferenceEquals(RoomSelection.SelectedItem, "Use Entire Model")) { Model.Rel_Humidity = 50; //(double)Rel_Humidity.Value; Model.Air_Temp = (double)Air_Temp.Value; Model.Atm_pressure = 1000; //(double)Air_Pressure.Value; Model.Atten_Choice = 0; //Atten_Method.SelectedIndex; Rhino.RhinoApp.RunScript("GetModel", false); } plugin.Source(out Source); if (MeshWave) { for (int i = 0; i < Source.Length; i++) { Source[i] = new GeodesicMeshSource(plugin.GetSourceSWL(i), Source[i].Origin(), (int)RT_Count.Value, i); } } ParticleRays[] RTParticles = new ParticleRays[Source.Length]; List <Point3d> L = new List <Point3d>(); for (int i = 0; i < Source.Length; i++) { L.Add(Source[i].Origin()); } for (int j = 0; j < Source.Length; j++) { if (plugin.Geometry_Spec() == 0) { Model.Ret_NURBS_Scene.partition(L); RTParticles[j] = new ParticleRays(Source[j], Model.Ret_NURBS_Scene, (int)RT_Count.Value, CutOffLength()); } else { Model.Ret_Mesh_Scene.partition(L); RTParticles[j] = new ParticleRays(Source[j], Model.Ret_Mesh_Scene, (int)RT_Count.Value, CutOffLength()); } RTParticles[j].Begin(); } PreviewDisplay = new WaveConduit(RTParticles, scale, new double[2] { (double)Param_Min.Value, (double)Param_Max.Value }, Model.Ret_Mesh_Scene); ForwButton.Enabled = true; BackButton.Enabled = true; Loop.Enabled = true; Loop.Text = "Stop"; FC = new ForCall(Forw_proc); System.Threading.ParameterizedThreadStart St = new System.Threading.ParameterizedThreadStart(delegate { LoopStart((int)(this.Frame_Rate.Value * Seconds.Value)); }); T = new System.Threading.Thread(St); T.Start(); }
public void Load_Doc(List <RhinoObject> Obj) { Objects = Obj; //Check to see if all objects have the same key values... if (Objects.Count != 0) { string Mode = Objects[0].Geometry.GetUserString("Acoustics_User"); if (!string.IsNullOrEmpty(Mode)) { //Check to see that all objects select materials the same way... foreach (RhinoObject obj in Objects) { string Mode2 = null; Mode2 = obj.Geometry.GetUserString("Acoustics_User"); if (!Mode.Equals(Mode2)) { this.User_Materials.Checked = false; this.Acoustics_Layer.Checked = false; //UpdateForm(); MaterialCode = null; return; } } //If the common method is user_materials if (Mode == "yes") { //Check to see if materials are all the same... string Code = Objects[0].Geometry.GetUserString("Acoustics"); this.User_Materials.Checked = true; this.Acoustics_Layer.Checked = false; string Code2 = null; foreach (RhinoObject obj in Objects) { Code2 = obj.Geometry.GetUserString("Acoustics"); if (!Code.Equals(Code2)) { //If not the same... this.User_Materials.Checked = true; this.Acoustics_Layer.Checked = false; //UpdateForm(); Clear(); return; } } //If they are the same... double[] Absorption = new double[8]; double[] Scattering = new double[8]; double[] Transparency = new double[8]; //TODO: Finalize Transparency this.User_Materials.Checked = true; this.Acoustics_Layer.Checked = false; //And if there is a predefined value... if (Code != null) { PachydermAc_PlugIn.DecodeAcoustics(Code, ref Absorption, ref Scattering, ref Transparency); MaterialCode = Code; Abs63.Value = (int)(Absorption[0] * 100); Abs125.Value = (int)(Absorption[1] * 100); Abs250.Value = (int)(Absorption[2] * 100); Abs500.Value = (int)(Absorption[3] * 100); Abs1k.Value = (int)(Absorption[4] * 100); Abs2k.Value = (int)(Absorption[5] * 100); Abs4k.Value = (int)(Absorption[6] * 100); Abs8k.Value = (int)(Absorption[7] * 100); Scat63v.Value = (int)(Scattering[0] * 100); Scat125v.Value = (int)(Scattering[1] * 100); Scat250v.Value = (int)(Scattering[2] * 100); Scat500v.Value = (int)(Scattering[3] * 100); Scat1kv.Value = (int)(Scattering[4] * 100); Scat2kv.Value = (int)(Scattering[5] * 100); Scat4kv.Value = (int)(Scattering[6] * 100); Scat8kv.Value = (int)(Scattering[7] * 100); Trans63v.Value = (int)(Transparency[0] * 100); Trans125v.Value = (int)(Transparency[1] * 100); Trans250v.Value = (int)(Transparency[2] * 100); Trans500v.Value = (int)(Transparency[3] * 100); Trans1kv.Value = (int)(Transparency[4] * 100); Trans2kv.Value = (int)(Transparency[5] * 100); Trans4kv.Value = (int)(Transparency[6] * 100); Trans8kv.Value = (int)(Transparency[7] * 100); //UpdateForm(); } else { Clear(); //UpdateForm(); } } else { //If the common method is by Layer... (Default) this.User_Materials.Checked = false; this.Acoustics_Layer.Checked = true; Clear(); //UpdateForm(); return; } } else { //By Default, Acoustics will be designated by layer this.User_Materials.Checked = false; this.Acoustics_Layer.Checked = true; Clear(); //UpdateForm(); } } UpdateForm(); }
public void UpdateForm() { if (Acoustics_Layer.Checked == true) { SettingsTable.Enabled = false; SettingsTable.Visible = false; } else if (User_Materials.Checked == true) { SettingsTable.Enabled = true; SettingsTable.Visible = true; } int[] Abs = new int[8]; int[] Sct = new int[8]; int[] Trn = new int[8]; Abs[0] = (int)Abs63.Value; Abs[1] = (int)Abs125.Value; Abs[2] = (int)Abs250.Value; Abs[3] = (int)Abs500.Value; Abs[4] = (int)Abs1k.Value; Abs[5] = (int)Abs2k.Value; Abs[6] = (int)Abs4k.Value; Abs[7] = (int)Abs8k.Value; Sct[0] = (int)Scat63v.Value; Sct[1] = (int)Scat125v.Value; Sct[2] = (int)Scat250v.Value; Sct[3] = (int)Scat500v.Value; Sct[4] = (int)Scat1kv.Value; Sct[5] = (int)Scat2kv.Value; Sct[6] = (int)Scat4kv.Value; Sct[7] = (int)Scat8kv.Value; int TrnDet = 0; Trn[0] = (int)Trans63v.Value; TrnDet += Trn[0]; Trn[1] = (int)Trans125v.Value; TrnDet += Trn[1]; Trn[2] = (int)Trans250v.Value; TrnDet += Trn[2]; Trn[3] = (int)Trans500v.Value; TrnDet += Trn[3]; Trn[4] = (int)Trans1kv.Value; TrnDet += Trn[4]; Trn[5] = (int)Trans2kv.Value; TrnDet += Trn[5]; Trn[6] = (int)Trans4kv.Value; TrnDet += Trn[6]; Trn[7] = (int)Trans8kv.Value; TrnDet += Trn[7]; if (TrnDet < 1) { Trn = new int[1]; } MaterialCode = PachydermAc_PlugIn.EncodeAcoustics(Abs, Sct, Trn); UpdateValues(); }
private void Calculate_Click(object sender, System.EventArgs e) { PachydermAc_PlugIn plugin = PachydermAc_PlugIn.Instance; string SavePath = null; if (plugin.Save_Results()) { SaveFileDialog sf = new System.Windows.Forms.SaveFileDialog(); sf.DefaultExt = ".pachm"; sf.AddExtension = true; sf.Filter = "Pachyderm Mapping Data File (*.pachm)|*.pachm|" + "All Files|"; if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { SavePath = sf.FileName; } } SourceList.Items.Clear(); Map = null; System.Threading.Thread.Sleep(500); PachydermAc_PlugIn p = PachydermAc_PlugIn.Instance; Pach_RunSim_Command command = Pach_RunSim_Command.Instance; if (!p.Source(out Source) || Rec_Srfs == null) { Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation..."); return; } Point3d[] SPT; plugin.SourceOrigin(out SPT); Calculate.Enabled = false; List <Point3d> P = new List <Point3d>(); P.AddRange(SPT); Polygon_Scene PScene = Utilities.PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked); if (!PScene.Complete) { Calculate.Enabled = true; return; } WC = new WaveConduit(c_scale, new double[] { Current_SPLMin, Current_SPLMax }); PScene.partition(P); Scene Flex_Scene; if (PachydermAc_PlugIn.Instance.Geometry_Spec() == 0) { RhCommon_Scene NScene = Utilities.PachTools.Get_NURBS_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked); if (!NScene.Complete) { return; } NScene.partition(P, plugin.VG_Domain()); Flex_Scene = NScene; } else { Flex_Scene = PScene; } Map = new PachMapReceiver[Source.Length]; for (int i = 0; i < Source.Length; i++) { Source[i].AppendPts(ref P); Map[i] = new PachMapReceiver(Rec_Srfs, Source[i], 1000, (double)Increment.Value * 0.01, Flex_Scene, (int)RT_Count.Value, (double)CO_TIME.Value, Disp_Audience.Checked, Sum_Time.Checked, DirectionalToggle.Checked, Rec_Vertex.Checked, Offset_Mesh.Checked); } for (int s_id = 0; s_id < Source.Length; s_id++) { command.Sim = new Direct_Sound(Source[s_id], Map[s_id], PScene, new int[8] { 0, 1, 2, 3, 4, 5, 6, 7 }); Rhino.RhinoApp.RunScript("Run_Simulation", false); Direct_Sound Direct_Data; if (command.CommandResult != Rhino.Commands.Result.Cancel) { Direct_Data = ((Direct_Sound)command.Sim); } else { Array.Resize(ref Source, s_id); Array.Resize(ref Map, s_id); command.Reset(); Calculate.Enabled = true; break; } command.Reset(); command.Sim = new SplitRayTracer(Source[s_id], Map[s_id], Flex_Scene, CutOffLength(), (int)RT_Count.Value, 0); Rhino.RhinoApp.RunScript("Run_Simulation", false); if (command.CommandResult == Rhino.Commands.Result.Success) { Map[s_id] = (PachMapReceiver)((SplitRayTracer)command.Sim).GetReceiver; } else { Array.Resize(ref Source, s_id); Array.Resize(ref Map, s_id); command.Reset(); Calculate.Enabled = true; break; } command.Reset(); Map[s_id].AddDirect(Direct_Data, Source[s_id]); } if (Source != null) { foreach (Source S in Source) { SourceList.Items.Add(String.Format("S{0}-", S.Source_ID()) + S.Type()); } if (SavePath != null) { Utilities.FileIO.Write_pachm(SavePath, ref Map); } } if (Map != null) { Create_Map(false); } Rhino.RhinoApp.WriteLine("Calculation has been completed. Have a nice day!"); /////// //for(int i = 0;i < 10000; i++) Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(((Source[0] as LineSource).D as LineSource.ANCON).Pt[i]); /////// Calculate.Enabled = true; }