Exemplo n.º 1
0
        /// <summary>
        /// RealizeItems from the itemsToRealize enumerable upto the maxItemsToRealize limit.
        /// </summary>
        /// <param name="itemsToRealize">items to realize</param>
        /// <param name="realizedItems">Set of Realized Items</param>
        /// <param name="maxItemsToRealize">Max limit of items to realize</param>
        /// <returns>count of items realized.</returns>
        private int RealizeItems(IEnumerator <ISpatialItem> itemsToRealize, HashSet <ISpatialItem> realizedItems, int maxItemsToRealize)
        {
            int itemsRealized = 0;

            // This has to happen again because of the lazy throttling that can happen after RealizeOverride has returned.
            IVisualFactory f = VisualFactory ?? this.defaultFactory;

            f.BeginRealize();

            // Realize n items where n <= this.realizationQuantum.
            while (itemsRealized < maxItemsToRealize && itemsToRealize.MoveNext())
            {
                ISpatialItem item           = itemsToRealize.Current;
                Visual       realizedVisual = RealizeItem(item, false);

                if (realizedVisual != null)
                {
                    itemsRealized++;
                    realizedItems.Add(item);
                }
            }

            f.EndRealize();

            return(itemsRealized);
        }
Exemplo n.º 2
0
 void OnSelect(IVisualFactory factory)
 {
     if (s_OpenWindowCallback != null)
     {
         s_OpenWindowCallback(factory, Topic, RosMessageName);
     }
 }
 void OnPlayModeState(PlayModeStateChange state)
 {
     if (state == PlayModeStateChange.EnteredEditMode)
     {
         m_VisualFactory = null;
         m_Visual        = null;
     }
 }
 public VisualizationEditorWindow(IVisualFactory factory, string topic, string rosMessageName)
 {
     m_VisualFactory  = factory;
     m_Topic          = topic;
     m_RosMessageName = rosMessageName;
     SetFactory(factory);
     EditorApplication.playModeStateChanged += OnPlayModeState;
     titleContent = new GUIContent(m_Topic);
 }
Exemplo n.º 5
0
        public static IVisual GetVisual(string topic, string rosMessageName, MessageSubtopic subtopic)
        {
            IVisualFactory factory = VisualFactoryRegistry.GetVisualFactory(topic, rosMessageName, subtopic);

            if (factory == null)
            {
                return(null);
            }

            return(factory.GetOrCreateVisual(topic));
        }
        public static void RegisterTypeVisualizer(string rosMessageName, IVisualFactory visualFactory, int priority = 0, MessageSubtopic subtopic = MessageSubtopic.Default)
        {
            Dictionary <string, PrioritizedList <IVisualFactory> > factoriesTable = (subtopic != MessageSubtopic.Response) ? s_TypeVisualFactories : s_TypeResponseVisualFactories;
            PrioritizedList <IVisualFactory> currentEntry;

            if (!factoriesTable.TryGetValue(rosMessageName, out currentEntry))
            {
                currentEntry = new PrioritizedList <IVisualFactory>();
                currentEntry.Add(s_DefaultVisualFactory, int.MinValue);
                factoriesTable[rosMessageName] = currentEntry;
            }
            currentEntry.Add(visualFactory, priority);
        }
Exemplo n.º 7
0
        public IVisualFactory GetVisualFactory()
        {
            if (m_CachedRosMessageName != RosMessageName)
            {
                // if the topic has changed, discard our cached data
                m_VisualFactory            = null;
                m_NoVisualFactoryAvailable = false;
            }

            if (m_VisualFactory == null && !m_NoVisualFactoryAvailable)
            {
                SetVisualFactory(VisualFactoryRegistry.GetVisualFactory(Topic, RosMessageName, Subtopic));
            }
            return(m_VisualFactory);
        }
        public static void RegisterTopicVisualizer(string topic, IVisualFactory visualFactory, int priority = 0, MessageSubtopic subtopic = MessageSubtopic.Default)
        {
            if (topic == null)
            {
                Debug.Log("Registered null topic!");
            }
            Dictionary <string, PrioritizedList <IVisualFactory> > factoriesTable = (subtopic != MessageSubtopic.Response) ? s_TopicVisualFactories : s_TopicResponseVisualFactories;
            PrioritizedList <IVisualFactory> currentEntry;

            if (!factoriesTable.TryGetValue(topic, out currentEntry))
            {
                currentEntry          = new PrioritizedList <IVisualFactory>();
                factoriesTable[topic] = currentEntry;
            }
            currentEntry.Add(visualFactory, priority);
        }
Exemplo n.º 9
0
        public void SetVisualFactory(IVisualFactory visualFactory)
        {
            if (m_Visual != null)
            {
                m_Visual.SetDrawingEnabled(false);
            }
            m_Visual = null;

            m_VisualFactory        = visualFactory;
            m_CachedRosMessageName = RosMessageName;
            if (m_VisualFactory == null)
            {
                m_NoVisualFactoryAvailable = true;
            }

            SetVisualizing(m_IsVisualizingUI, m_IsVisualizingDrawing);
        }
Exemplo n.º 10
0
        public void TickleZoomables(bool visibleOnly)
        {
            double         scale   = canvas.Scale;
            IVisualFactory factory = canvas.VisualFactory;

            factory.BeginRealize();

            // todo: timeslice this work (throttle it)
            IEnumerable <ISpatialItem> query = null;

            if (visibleOnly)
            {
                query = canvas.Items.GetItemsIntersecting(canvas.ActualViewbox);
            }
            else
            {
                query = canvas.Items;
            }
            foreach (ISpatialItem item in query)
            {
                Visual visual = canvas.VisualFromItem(item);
                if (visual == null && !canvas.IsPaused)
                {
                    visual = canvas.RealizeItem(item, false);
                }
                if (visual != null)
                {
                    TickleZoomable(scale, visual);
                    // see if there are any adorners on the visual that also need to be scaled
                    var layer = AdornerLayer.GetAdornerLayer(visual);
                    if (layer != null)
                    {
                        var adorners = layer.GetAdorners(visual as UIElement);
                        if (adorners != null)
                        {
                            foreach (var zoomableAdorner in adorners.OfType <ISemanticZoomable>())
                            {
                                TickleZoomable(scale, zoomableAdorner);
                            }
                        }
                    }
                }
            }

            factory.EndRealize();
        }
        public static IEnumerable <IVisualFactory> GetAllVisualFactories(string topic, string rosMessageName)
        {
            PrioritizedList <IVisualFactory> result;
            IEnumerable <IVisualFactory>     topicVisualizers = null;

            if (topic != null)
            {
                s_TopicVisualFactories.TryGetValue(topic, out result);
                if (result != null)
                {
                    topicVisualizers = result.All;
                }
            }

            IEnumerable <IVisualFactory> typeVisualizers = null;

            if (rosMessageName != null)
            {
                s_TypeVisualFactories.TryGetValue(rosMessageName, out result);
                if (result != null)
                {
                    typeVisualizers = result.All;
                }
                else if (MessageRegistry.GetDeserializeFunction(rosMessageName) != null)
                {
                    typeVisualizers = new IVisualFactory[] { s_DefaultVisualFactory }
                }
                ;
            }

            if (topicVisualizers == null)
            {
                return(typeVisualizers);
            }

            if (typeVisualizers != null)
            {
                return(topicVisualizers.Concat(typeVisualizers));
            }
            else
            {
                return(topicVisualizers);
            }
        }
    }
Exemplo n.º 12
0
        public static IVisual GetVisual(string topic, MessageSubtopic subtopic = MessageSubtopic.Default)
        {
            RosTopicState topicState = ROSConnection.GetOrCreateInstance().GetTopic(topic);

            if (topicState != null && subtopic == MessageSubtopic.Response)
            {
                topicState = topicState.ServiceResponseTopic;
            }

            if (topicState == null)
            {
                return(null);
            }

            IVisualFactory factory = VisualFactoryRegistry.GetVisualFactory(topic, topicState.RosMessageName, subtopic);

            if (factory == null)
            {
                return(null);
            }

            return(factory.GetOrCreateVisual(topic));
        }
 public void SetFactory(IVisualFactory factory)
 {
     m_VisualFactory = factory;
     m_FactoryID     = factory.ID;
     m_Visual        = null;
 }
        private void OnGUI()
        {
            if (!EditorApplication.isPlaying)
            {
                GUILayout.Label("Waiting for play mode...");
                return;
            }

            if (m_Visual == null && EditorApplication.isPlaying)
            {
                if (m_FactoryID == null)
                {
                    GUIContent buttonContent = new GUIContent("Select Visualizer");
                    Rect       selectBtnRect = GUILayoutUtility.GetRect(buttonContent, EditorStyles.toolbarDropDown, GUILayout.ExpandWidth(false));
                    if (EditorGUI.DropdownButton(selectBtnRect, buttonContent, FocusType.Keyboard))
                    {
                        GenericMenu menu = new GenericMenu();
                        foreach (IVisualFactory factory in VisualFactoryRegistry.GetAllVisualFactories(m_Topic, m_RosMessageName))
                        {
                            menu.AddItem(new GUIContent(factory.Name), false, () => SetFactory(factory));
                        }
                        menu.DropDown(selectBtnRect);
                    }
                }
                else if (m_VisualFactory == null)
                {
                    foreach (IVisualFactory factory in VisualFactoryRegistry.GetAllVisualFactories(m_Topic, m_RosMessageName))
                    {
                        if (factory.ID == m_FactoryID)
                        {
                            m_VisualFactory = factory;
                        }
                    }
                    if (m_VisualFactory == null)
                    {
                        m_FactoryID = null;
                    }
                }

                if (m_VisualFactory != null)
                {
                    m_Visual = m_VisualFactory.GetOrCreateVisual(m_Topic);
                }
            }

            if (m_Visual != null)
            {
                GUILayout.BeginHorizontal(GUI.skin.box);
                EditorGUI.BeginDisabledGroup(m_VisualFactory == null || !m_VisualFactory.CanShowDrawing);
                bool drawingEnable = EditorGUILayout.ToggleLeft("Show 3d drawings", m_Visual.IsDrawingEnabled);
                EditorGUI.EndDisabledGroup();
                EditorGUI.BeginDisabledGroup(!(m_VisualFactory is Object));
                if (GUILayout.Button("Select in Editor"))
                {
                    Object factoryObject = (Object)m_VisualFactory;
                    Selection.activeObject = factoryObject;
                }
                EditorGUI.EndDisabledGroup();
                GUILayout.EndHorizontal();
                if (m_Visual.IsDrawingEnabled != drawingEnable)
                {
                    m_Visual.SetDrawingEnabled(drawingEnable);
                }

                m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos);
                m_Visual.OnGUI();
                GUILayout.EndScrollView();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Realizes and virtualizes items based on the current viewbox.
        /// </summary>
        /// <returns>An enumerator which allows this method to continue realization where it left off.</returns>
        private IEnumerator RealizeOverride()
        {
            IVisualFactory f = VisualFactory ?? this.defaultFactory;

            f.BeginRealize();
            IEnumerator <ISpatialItem> itemEnumerator = null;
            HashSet <ISpatialItem>     realizedItems  = new HashSet <ISpatialItem>();

            // RealizeItems
            if (this.Items != null)
            {
                IEnumerable <ISpatialItem> itemsToRealize = null;
                if (this.IsVirtualizing)
                {
                    // Only realize the items within our viewbox.
                    double scale   = Scale;
                    Rect   viewbox = ActualViewbox;

                    // Buffer the viewbox.
                    // This just seems to make things worse, especially when zoomed out a long way.
                    // A smarter algorithm would predict the direction we are moving and only prefetch those.
                    // viewbox.Inflate(viewbox.Width / 2, viewbox.Height / 2);

                    // Query the index for all items that intersect our viewbox.
                    // use ToList() because we can't leave the query to be lazy.
                    // by the time RealizeItems is called below the contents of the query
                    // may have mutated.
                    itemsToRealize = Items.GetItemsIntersecting(viewbox).ToList();
                }
                else
                {
                    // Get all items.
                    itemsToRealize = Items;
                }

                itemEnumerator = itemsToRealize.GetEnumerator();
                QuantizedWorkHandler realizeHandler = delegate(int realizationQuantum)
                {
                    return(this.RealizeItems(itemEnumerator, realizedItems, realizationQuantum));
                };

                while (this.SelfThrottlingWorker(ref this.realizationQuantum, realizeHandler))
                {
                    yield return(true);
                }

                // Raise VisualChildrenChanged only if new
                if (realizedItems.Count > 0)
                {
                    // Raise the VisualChildrenChanged event since all items are visible.
                    if (this.VisualChildrenChanged != null)
                    {
                        this.VisualChildrenChanged(this, EventArgs.Empty);
                    }
                }
            }

            // VirtualizeItems
            // Build a list of items to virtualize.
            IList <ISpatialItem> itemsToVirtualize = new List <ISpatialItem>(this.visualMap.Count);

            // Get any items that are no longer part of our result set.
            foreach (ISpatialItem item in this.visualMap.Keys)
            {
                if (!realizedItems.Contains(item))
                {
                    if (this.ShouldVirtualize(item))
                    {
                        itemsToVirtualize.Add(item);
                    }
                }
            }

            itemEnumerator = itemsToVirtualize.GetEnumerator();
            QuantizedWorkHandler virtualizingHandler = delegate(int virtualizationQuantum)
            {
                return(this.VirtualizeItems(itemEnumerator, virtualizationQuantum));
            };

            while (this.SelfThrottlingWorker(ref this.virtualizationQuantum, virtualizingHandler))
            {
                yield return(true);
            }

            f.EndRealize();
        }
        static void OpenWindow(IVisualFactory visualizer, string topic, string rosMessageName)
        {
            VisualizationEditorWindow window = new VisualizationEditorWindow(visualizer, topic, rosMessageName);

            window.Show();
        }
 public static void RegisterTypeVisualizer <MsgType>(IVisualFactory visualFactory, int priority = 0) where MsgType : Message
 {
     RegisterTypeVisualizer(MessageRegistry.GetRosMessageName <MsgType>(), visualFactory, priority, MessageRegistry.GetSubtopic <MsgType>());
 }