public override void Start()
        {
            base.Start();

            if (m_Topic == "")
            {
                VisualFactoryRegistry.RegisterTypeVisualizer <MarkerArrayMsg>(this, Priority);
            }
        }
Exemplo n.º 2
0
 void ShowOptionsMenu(Rect position)
 {
     UnityEditor.GenericMenu menu = new UnityEditor.GenericMenu();
     foreach (IVisualFactory factory in VisualFactoryRegistry.GetAllVisualFactories(Topic, RosMessageName))
     {
         bool isSelected = GetVisualFactory() == factory;
         menu.AddItem(new GUIContent(isSelected? factory.Name + " (main)": factory.Name), false, () => OnSelect(factory));
     }
     menu.DropDown(position);
 }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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));
        }
        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();
            }
        }