Example #1
0
 private bool waitForRhinoFromQueue(out Rhino_Wrapper rhinoFromQueue, int tries, int delayEachTry)
 {
     rhinoFromQueue = null;
     MyLog("GHr id=" + id + " requesting new Rhino (before lock). Before rhino_requestors_Q.count=" + rhino_requestors_Q.Count);
     lock (GHR.requestors_locker)
     {
         MyLog("GHr id=" + id + " requesting new Rhino. Before rhino_requestors_Q.count=" + rhino_requestors_Q.Count);
         rhino_requestors_Q.Enqueue(id);
     }
     for (int i = 0; i < tries; i++)
     {
         lock (GHR.requestors_locker)
         {
             if (rhino_requestors_Q.Peek() == id)
             {
                 if (GHR.getRhinoFromQueue(out rhinoFromQueue))
                 {
                     rhino_requestors_Q.Dequeue();
                     MyLog("GHr id=" + id + " received new Rhino. After rhino_requestors_Q.count=" + rhino_requestors_Q.Count);
                     return true;
                 }
             }
         }
         Thread.Sleep(delayEachTry);
     }
     return false;
 }
Example #2
0
 public GHR(int id, Rhino_Wrapper rhino)
 {
     this.id = id;
     this.rhino_wrapper = rhino;
 }
Example #3
0
 public static bool pushRhinoIntoQueue(Rhino_Wrapper newRhino)
 {
     lock (locker)
     {
         spareRhinos.Enqueue(newRhino);
     }
     return true;
 }
Example #4
0
        public static bool startSingleRhino(bool visible, out Rhino_Wrapper newRhino)
        {
            newRhino = new Rhino_Wrapper();
            lock (GHR.locker)
            {
                Process[] procs_before = Process.GetProcessesByName("Rhino4");
                Console.WriteLine("Starting Rhino at " + DateTime.Now);
                newRhino.rhino_app = new Rhino5Application();
                newRhino.rhino_app.ReleaseWithoutClosing = 1;
                newRhino.rhino_app.Visible = visible ? 1 : 0;
                if (newRhino == null)
                {
                    Console.WriteLine("rhino == null");
                    return false;
                }
                for (int tries = 0; tries < 200; tries++)
                {
                    if (newRhino.rhino_app.IsInitialized() == 1)
                    {
                        break;
                    }
                    Thread.Sleep(100);
                }
                Process[] procs_after = Process.GetProcessesByName("Rhino4");
                List<int> pids_before = new List<int>();
                List<int> new_pids = new List<int>();
                foreach (Process p in procs_before) pids_before.Add(p.Id);
                foreach (Process p in procs_after)
                {
                    if (!pids_before.Contains(p.Id))
                    {
                        new_pids.Add(p.Id);
                    }
                }

                if (new_pids.Count != 1)
                {
                    Console.WriteLine("ERROR ! - (new_pids.Count != 1 =" + new_pids.Count);
                    Console.WriteLine("procs_before=:");
                    foreach (Process p in procs_before) Console.WriteLine(p.Id);
                    Console.WriteLine("procs_after=:");
                    foreach (Process p in procs_after) Console.WriteLine(p.Id);
                    return false;
                }
                else
                {
                    newRhino.rhino_pid = new_pids[0];
                }
            }

            Console.WriteLine("Starting Grasshopper at " + DateTime.Now);
            newRhino.rhino_app.RunScript("_Grasshopper", 0);
            Thread.Sleep(1000);

            newRhino.grasshopper = newRhino.rhino_app.GetPlugInObject("b45a29b1-4343-4035-989e-044e8580d9cf", "00000000-0000-0000-0000-000000000000") as dynamic;
            if (newRhino.grasshopper == null)
            {
                Console.WriteLine("ERROR!!: (grasshopper == null)");
                return false;
            }
            newRhino.grasshopper.HideEditor();

            return true;
        }
Example #5
0
 public static bool getRhinoFromQueue(out Rhino_Wrapper outRhino)
 {
     outRhino = null;
     lock (locker)
     {
         if (spareRhinos.Count == 0) return false;
         outRhino = spareRhinos.Dequeue();
         return true;
     }
 }