public bool Source(out Environment.Source[] S)
            {
                S = new Environment.Source[0];
                if (Check_Special(ref S)) return true;
                //UI.Pach_Source_Object S_command = UI.Pach_Source_Object.Instance;
                //S_command = UI.Pach_Source_Object.Instance;
                System.Guid[] S_ID = SourceConduit.Instance.UUID.ToArray();
                S = new Environment.Source[S_ID.Length];
                for (int id = 0; id < S_ID.Length; id++)
                {
                    if (S_ID[id] == System.Guid.Empty || S_ID[id] == System.Guid.NewGuid()) break;
                    Rhino.DocObjects.RhinoObject Origin = Rhino.RhinoDoc.ActiveDoc.Objects.Find(S_ID[id]);

                    if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Point)
                    {
                        string S_Type = Origin.Geometry.GetUserString("SourceType");
                        string SWL = Origin.Geometry.GetUserString("SWL");
                        string D = Origin.Geometry.GetUserString("Delay");
                        double delay; if (D != "") delay = double.Parse(D)/1000; else delay = 0;

                        string Ph = Origin.Geometry.GetUserString("Phase");
                        double[] phase = new double[8];
                        if (Ph != "")
                        {
                            string[] phstr = Ph.Split(";"[0]);
                            for (int o = 0; o < 8; o++) phase[o] = double.Parse(phstr[o]);
                        }

                        double[] SWL_Values = Utilities.PachTools.DecodeSourcePower(SWL);
                        switch (S_Type)
                        {
                            case "":
                            case "0":
                                S[id] = new Environment.GeodesicSource(SWL_Values, phase, Origin.Geometry.GetBoundingBox(true).Min, delay, id);
                                break;
                            case "1":
                                S[id] = new Environment.RandomSource(SWL_Values, phase, Origin.Geometry.GetBoundingBox(true).Min, delay, id);
                                break;
                            case "2":
                                string Bands = Origin.Geometry.GetUserString("Bands");
                                string[] B = Bands.Split(';');
                                SourceConduit SC = SourceConduit.Instance;
                                S[id] = new Environment.SpeakerSource(SC.m_Balloons[id], SWL_Values, phase, Origin.Geometry.GetBoundingBox(true).Min, new int[] { int.Parse(B[0]), int.Parse(B[1]) }, delay, id);
                                break;
                        }
                    }
                    else if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Brep)
                    {
                        string SWL = Origin.Geometry.GetUserString("SWL");

                        string Ph = Origin.Geometry.GetUserString("Phase");
                        double[] phase = new double[8];
                        if (Ph != "")
                        {
                            string[] phstr = Ph.Split(";"[0]);
                            for (int o = 0; o < 8; o++) phase[o] = double.Parse(phstr[o]);
                        }              
          
                        S[id] = new Environment.SurfaceSource(new Brep[]{(Origin.Geometry as Brep)}, new List<string>{SWL}, 1, id, Environment.Source.Phase_Regime.Random); 
                    }
                    else if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Curve)
                    {
                        string SWL = Origin.Geometry.GetUserString("SWL");
                        
                        string Ph = Origin.Geometry.GetUserString("Phase");
                        double[] phase = new double[8];
                        if (Ph != "")
                        {
                            string[] phstr = Ph.Split(";"[0]);
                            for (int o = 0; o < 8; o++) phase[o] = double.Parse(phstr[o]);
                        }

                        S[id] = new Environment.LineSource(Origin.Geometry as Curve, SWL, 1, id, Environment.Source.Phase_Regime.Random);                         
                    }
                }
                if (S == null) return false;
                return true;
            }
            public bool Source(out Environment.Source[] S)
            {
                S = new Environment.Source[0];
                if (Check_Special(ref S))
                {
                    return(true);
                }
                //UI.Pach_Source_Object S_command = UI.Pach_Source_Object.Instance;
                //S_command = UI.Pach_Source_Object.Instance;
                System.Guid[] S_ID = SourceConduit.Instance.UUID.ToArray();
                S = new Environment.Source[S_ID.Length];
                for (int id = 0; id < S_ID.Length; id++)
                {
                    if (S_ID[id] == System.Guid.Empty || S_ID[id] == System.Guid.NewGuid())
                    {
                        break;
                    }
                    Rhino.DocObjects.RhinoObject Origin = Rhino.RhinoDoc.ActiveDoc.Objects.Find(S_ID[id]);

                    if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Point)
                    {
                        string S_Type = Origin.Geometry.GetUserString("SourceType");
                        string SWL    = Origin.Geometry.GetUserString("SWL");
                        string D      = Origin.Geometry.GetUserString("Delay");
                        double delay; if (D != "")
                        {
                            delay = double.Parse(D) / 1000;
                        }
                        else
                        {
                            delay = 0;
                        }

                        string   Ph    = Origin.Geometry.GetUserString("Phase");
                        double[] phase = new double[8];
                        if (Ph != "")
                        {
                            string[] phstr = Ph.Split(";"[0]);
                            for (int o = 0; o < 8; o++)
                            {
                                phase[o] = double.Parse(phstr[o]);
                            }
                        }

                        double[] SWL_Values = Utilities.PachTools.DecodeSourcePower(SWL);
                        switch (S_Type)
                        {
                        case "":
                        case "0":
                            S[id] = new Environment.GeodesicSource(SWL_Values, phase, Origin.Geometry.GetBoundingBox(true).Min, delay, id);
                            break;

                        case "1":
                            S[id] = new Environment.RandomSource(SWL_Values, phase, Origin.Geometry.GetBoundingBox(true).Min, delay, id);
                            break;

                        case "2":
                            string        Bands = Origin.Geometry.GetUserString("Bands");
                            string[]      B     = Bands.Split(';');
                            SourceConduit SC    = SourceConduit.Instance;
                            S[id] = new Environment.SpeakerSource(SC.m_Balloons[id], SWL_Values, phase, Origin.Geometry.GetBoundingBox(true).Min, new int[] { int.Parse(B[0]), int.Parse(B[1]) }, delay, id);
                            break;
                        }
                    }
                    else if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Brep)
                    {
                        string SWL = Origin.Geometry.GetUserString("SWL");

                        string   Ph    = Origin.Geometry.GetUserString("Phase");
                        double[] phase = new double[8];
                        if (Ph != "")
                        {
                            string[] phstr = Ph.Split(";"[0]);
                            for (int o = 0; o < 8; o++)
                            {
                                phase[o] = double.Parse(phstr[o]);
                            }
                        }

                        S[id] = new Environment.SurfaceSource(new Brep[] { (Origin.Geometry as Brep) }, new List <string> {
                            SWL
                        }, 1, id, Environment.Source.Phase_Regime.Random);
                    }
                    else if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Curve)
                    {
                        string SWL = Origin.Geometry.GetUserString("SWL");

                        string   Ph    = Origin.Geometry.GetUserString("Phase");
                        double[] phase = new double[8];
                        if (Ph != "")
                        {
                            string[] phstr = Ph.Split(";"[0]);
                            for (int o = 0; o < 8; o++)
                            {
                                phase[o] = double.Parse(phstr[o]);
                            }
                        }

                        S[id] = new Environment.LineSource(Origin.Geometry as Curve, SWL, 1, id, Environment.Source.Phase_Regime.Random);
                    }
                }
                if (S == null)
                {
                    return(false);
                }
                return(true);
            }