Пример #1
0
        /*************************************/
        /**** Public Methods              ****/
        /*************************************/

        public static void ShowEvents(GH_ActiveObject component, List <Event> events, bool clearShownEvents = true)
        {
            if (events.Count > 0)
            {
                List <string> errors   = events.Where(x => x.Type == EventType.Error).Select(x => x.Message).ToList();
                List <string> warnings = events.Where(x => x.Type == EventType.Warning).Select(x => x.Message).ToList();
                List <string> notes    = events.Where(x => x.Type == EventType.Note).Select(x => x.Message).ToList();

                // Re-process preexisting messages
                errors.AddRange(component.RuntimeMessages(GH_RuntimeMessageLevel.Error));
                warnings.AddRange(component.RuntimeMessages(GH_RuntimeMessageLevel.Warning));
                notes.AddRange(component.RuntimeMessages(GH_RuntimeMessageLevel.Remark));
                notes.AddRange(component.RuntimeMessages(GH_RuntimeMessageLevel.Blank));
                component.ClearRuntimeMessages();

                foreach (string message in errors)
                {
                    component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);
                }

                foreach (string message in warnings)
                {
                    component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message);
                }

                //If any warnings or errors have been added, then add the message as a blank.
                //This is to ensure the colour of the component gets the appropriate colour.
                //(A bug in GH ranks remarks higher than warning and errors, keeping the component grey when it should be orange/red)
                //Solution to use 'Blank' warning level, which generally does not do anything on the component.
                if (errors.Count() > 0 || warnings.Count() > 0)
                {
                    foreach (string message in notes)
                    {
                        component.AddBlankNoteMessage(message);
                    }
                }
                else
                {
                    foreach (string message in notes)
                    {
                        component.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, message);
                    }
                }

                if (clearShownEvents)
                {
                    Engine.Base.Compute.ClearCurrentEvents();
                }
            }
        }