Esempio n. 1
0
        void OnIdle(object sender, IdlingEventArgs args)
        {
            // 1. Do Rhino pending OnIdle tasks
            if (rhinoCore.OnIdle())
            {
                args.SetRaiseWithoutDelay();
                return;
            }

            // Load this assembly as a Grasshopper assembly
            if (!LoadedAsGHA && PlugIn.GetPlugInInfo(new Guid(0xB45A29B1, 0x4343, 0x4035, 0x98, 0x9E, 0x04, 0x4E, 0x85, 0x80, 0xD9, 0xCF)).IsLoaded)
            {
                LoadedAsGHA = LoadGrasshopperComponents();
            }

            // Document dependant tasks need a document
            ActiveUIApplication = (sender as UIApplication);
            if (ActiveDBDocument != null)
            {
                // 1. Do all document read actions
                if (ProcessReadActions())
                {
                    args.SetRaiseWithoutDelay();
                    return;
                }

                // 2. Do all document write actions
                if (!ActiveDBDocument.IsReadOnly)
                {
                    ProcessWriteActions();
                }

                // 3. Refresh Active View if necesary
                bool regenComplete = DirectContext3DServer.RegenComplete();
                if (pendingRefreshActiveView || !regenComplete || GH.PreviewServer.PreviewChanged())
                {
                    pendingRefreshActiveView = false;

                    var RefreshTime = new Stopwatch();
                    RefreshTime.Start();
                    ActiveUIApplication.ActiveUIDocument.RefreshActiveView();
                    RefreshTime.Stop();
                    DirectContext3DServer.RegenThreshold = Math.Min(RefreshTime.ElapsedMilliseconds, 200);
                }

                if (!regenComplete)
                {
                    args.SetRaiseWithoutDelay();
                }
            }
        }
Esempio n. 2
0
        internal static bool ProcessIdleActions()
        {
            bool pendingIdleActions = false;

            // Document dependant tasks need a document
            if (ActiveDBDocument != null)
            {
                // 1. Do all document read actions
                if (ProcessReadActions())
                {
                    pendingIdleActions = true;
                }

                // 2. Do all document write actions
                if (!ActiveDBDocument.IsReadOnly)
                {
                    ProcessWriteActions();
                }

                // 3. Refresh Active View if necesary
                bool regenComplete = DirectContext3DServer.RegenComplete();
                if (isRefreshActiveViewPending || !regenComplete)
                {
                    isRefreshActiveViewPending = false;

                    var RefreshTime = new Stopwatch();
                    RefreshTime.Start();
                    ActiveUIApplication.ActiveUIDocument.RefreshActiveView();
                    RefreshTime.Stop();
                    DirectContext3DServer.RegenThreshold = Math.Max(RefreshTime.ElapsedMilliseconds / 3, 100);
                }

                if (!regenComplete)
                {
                    pendingIdleActions = true;
                }
            }

            // Non document dependant tasks
            lock (idlingActions)
            {
                while (idlingActions.Count > 0)
                {
                    try { idlingActions.Dequeue().Invoke(); }
                    catch (Exception e) { Debug.Fail(e.Source, e.Message); }
                }
            }

            return(pendingIdleActions);
        }
Esempio n. 3
0
        internal static bool ProcessIdleActions()
        {
            bool pendingIdleActions = false;

            // Document dependant tasks need a document
            if (ActiveDBDocument != null)
            {
                // 1. Do all document read actions
                if (ProcessReadActions())
                {
                    pendingIdleActions = true;
                }

                // 2. Do all document write actions
                if (!ActiveDBDocument.IsReadOnly)
                {
                    ProcessWriteActions();
                }

                // 3. Refresh Active View if necesary
                bool regenComplete = DirectContext3DServer.RegenComplete();
                if (isRefreshActiveViewPending || !regenComplete || GH.PreviewServer.PreviewChanged())
                {
                    isRefreshActiveViewPending = false;

                    var RefreshTime = new Stopwatch();
                    RefreshTime.Start();
                    ActiveUIApplication.ActiveUIDocument.RefreshActiveView();
                    RefreshTime.Stop();
                    DirectContext3DServer.RegenThreshold = Math.Max(RefreshTime.ElapsedMilliseconds / 3, 100);
                }

                if (!regenComplete)
                {
                    pendingIdleActions = true;
                }
            }

            return(pendingIdleActions);
        }