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();
            }
Exemple #2
0
            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;
            }