private void removeMapBehavior(ExtensionBehavior extensionBehavior)
        {
            if (MapApplication.Current == null && MapApplication.Current.Map != null)
            {
                return;
            }

            BehaviorCollection behaviors = Interaction.GetBehaviors(MapApplication.Current.Map);

            if (behaviors == null)
            {
                return;
            }

            Behavior <Map> mapBehavior = extensionBehavior.MapBehavior as Behavior <Map>;

            if (mapBehavior == null)
            {
                mapBehavior = BehaviorUtils.GetMapBehavior(extensionBehavior);
                extensionBehavior.MapBehavior = mapBehavior;
            }

            if (mapBehavior == null)
            {
                return;
            }

            behaviors.Remove(mapBehavior);

            if (View.Instance != null && View.Instance.ExtensionBehaviors != null && View.Instance.ExtensionBehaviors.Contains(extensionBehavior))
            {
                View.Instance.ExtensionBehaviors.Remove(extensionBehavior);
            }
        }
Example #2
0
        public static Behavior <Map> GetMapBehavior(ExtensionBehavior extensionBehavior)
        {
            if (extensionBehavior == null || string.IsNullOrEmpty(extensionBehavior.CommandValueId))
            {
                return(null);
            }

            if (extensionBehavior.MapBehavior != null)
            {
                return(extensionBehavior.MapBehavior as Behavior <Map>);
            }

            string[] splits = extensionBehavior.CommandValueId.Split(new char[] { ';' });
            if (splits == null || splits.Length < 2)
            {
                return(null);
            }

            string typeName     = splits[0].Replace("Type=", "");
            string assemblyName = splits[1].Replace("Assembly=", "");

            foreach (Behavior <Map> mapBehavior in View.Instance.ExtensionMapBehaviors)
            {
                if (mapBehavior == null)
                {
                    continue;
                }
                Type type = mapBehavior.GetType();
                if (type.FullName == typeName && type.Assembly.FullName == assemblyName)
                {
                    return(type.Assembly.CreateInstance(type.FullName) as Behavior <Map>);
                }
            }
            return(null);
        }
        public override void Execute(object parameter)
        {
            ExtensionBehavior mapBehavior = parameter as ExtensionBehavior;

            if (mapBehavior == null)
            {
                return;
            }

            if (View.Instance == null && ViewerApplicationControl.Instance.BehaviorsConfiguration == null)
            {
                return;
            }

            int pos = View.Instance.ExtensionBehaviors.IndexOf(mapBehavior);

            if (pos < 0 || pos >= View.Instance.ExtensionBehaviors.Count - 1)
            {
                return;
            }

            ExtensionBehavior selectedBehavior = View.Instance.ExtensionBehaviors[pos];

            if (selectedBehavior != null)
            {
                View.Instance.ExtensionBehaviors.Remove(selectedBehavior);
                View.Instance.ExtensionBehaviors.Insert(pos + 1, selectedBehavior);
            }
        }
        public override void Execute(object parameter)
        {
            ExtensionBehavior extensionBehavior = parameter as ExtensionBehavior;

            if (extensionBehavior == null)
            {
                return;
            }

            ISupportsConfiguration supportConfiguration = extensionBehavior.MapBehavior as ISupportsConfiguration;

            if (supportConfiguration != null)
            {
                try
                {
                    supportConfiguration.Configure();
                }
                catch (Exception ex)
                {
                    if (ViewerApplicationControl.Instance == null)
                    {
                        MessageBoxDialog.Show(LocalizableStrings.GetString("BehaviorConfigurationFailedDescription"), LocalizableStrings.GetString("BehaviorConfigurationFailed"), MessageBoxButton.OK);
                    }
                    else
                    {
                        NotificationPanel.Instance.AddNotification(LocalizableStrings.GetString("BehaviorConfigurationFailed"), LocalizableStrings.GetString("BehaviorConfigurationFailedDescription"), ex.ToString(), MessageType.Warning);
                    }
                }
            }
        }
        private void AddItemTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            ExtensionBehavior behavior        = null;
            TreeViewItem      selectedAddItem = AddItemTree.SelectedItem as TreeViewItem;

            // There has to be a selected add item and its parent cannot be the tree itself (which implies it is a child of
            // a category parent node) in which case the OK button can be enabled.
            if (selectedAddItem != null && selectedAddItem.Parent != AddItemTree)
            {
                ExtensionBehavior itemToAdd = selectedAddItem.Tag as ExtensionBehavior;
                if (itemToAdd != null)
                {
                    // Use the button base, but clone the button info object so that if the user edits the associated
                    // values in this copy, it will not alter the original values in the "Add Tools" treeview.
                    behavior             = new ExtensionBehavior();
                    behavior.BehaviorId  = Guid.NewGuid().ToString();
                    behavior.MapBehavior = Activator.CreateInstance(itemToAdd.MapBehavior.GetType()) as Behavior <Map>;
                    behavior.IsEnabled   = true;
                    behavior.Title       = itemToAdd.Title;
                }
            }
            SelectedItem = behavior;
            if (SelectedItemChanged != null)
            {
                SelectedItemChanged(this, EventArgs.Empty);
            }
        }
        public override void Execute(object parameter)
        {
            ExtensionBehavior mapBehavior = parameter as ExtensionBehavior;

            if (mapBehavior == null)
            {
                return;
            }

            if (View.Instance == null && View.Instance.ExtensionBehaviors == null)
            {
                return;
            }

            int pos = View.Instance.ExtensionBehaviors.IndexOf(mapBehavior);

            if (pos < 1)
            {
                return;
            }

            ExtensionBehavior selectedBehavior = View.Instance.ExtensionBehaviors[pos];

            if (selectedBehavior != null)
            {
                View.Instance.ExtensionBehaviors.Remove(selectedBehavior);
                View.Instance.ExtensionBehaviors.Insert(pos - 1, selectedBehavior);
            }
        }
        public List <ExtensionBehavior> GetAsExtensionBehaviors(ExtensionsDataManager dataManager)
        {
            List <ExtensionBehavior> list = new List <ExtensionBehavior>();

            try
            {
                foreach (BehaviorConfiguration beh in this)
                {
                    Behavior <Map> behavior = beh.ClassImplementation as System.Windows.Interactivity.Behavior <Map>;
                    if (behavior != null)
                    {
                        ExtensionBehavior extensionBehavior = new ExtensionBehavior();
                        extensionBehavior.Title       = ExtensionDisplayNameConverter.Convert(behavior);
                        extensionBehavior.MapBehavior = behavior;
                        extensionBehavior.IsEnabled   = beh.IsEnabled;
                        extensionBehavior.BehaviorId  = beh.Id;
                        extensionBehavior.Title       = beh.Title;
                        if (dataManager != null)
                        {
                            dataManager.SetExtensionDataForExtension(beh.Id, beh.ConfigData);
                        }

                        list.Add(extensionBehavior);
                    }
                }
            }
            catch { }
            return(list);
        }
Example #8
0
        void updateExtensionBehavior(string extension, ExtensionBehavior behavior)
        {
            // Update the current behavior
            if (extension == "all")
            {
                // special case for the 'all' extension; apply it to every extension present
                if (behavior == ExtensionBehavior.Require || behavior == ExtensionBehavior.Enable)
                {
                    Error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", "");
                    return;
                }
                else
                {
                    string[] keys = new string[mExtensionBehaviors.Keys.Count];
                    mExtensionBehaviors.Keys.CopyTo(keys, 0);
                    foreach (string key in keys)
                    {
                        mExtensionBehaviors[key] = behavior;
                    }
                }
            }
            else
            {
                // Do the update for this single extension
                ExtensionBehavior found;
                if (mExtensionBehaviors.TryGetValue(extension, out found))
                {
                    if (found == ExtensionBehavior.DisablePartial)
                    {
                        Warn(getCurrentLoc(), "extension is only partially supported:", "#extension", extension);
                    }
                    if (behavior == ExtensionBehavior.Enable || behavior == ExtensionBehavior.Require)
                    {
                        mIntermediate.addRequestedExtension(extension);
                    }
                    mExtensionBehaviors[extension] = behavior;
                }
                else
                {
                    switch (behavior)
                    {
                    case ExtensionBehavior.Require:
                        Error(getCurrentLoc(), "extension not supported:", "#extension", extension);
                        break;

                    case ExtensionBehavior.Enable:
                    case ExtensionBehavior.Warn:
                    case ExtensionBehavior.Disable:
                        Warn(getCurrentLoc(), "extension not supported:", "#extension", extension);
                        break;

                    default:
                        throw new InvalidOperationException("unexpected behavior");
                    }

                    return;
                }
            }
        }
        public override void Execute(object parameter)
        {
            ExtensionBehavior behavior = parameter as ExtensionBehavior;

            if (behavior == null)
            {
                return;
            }

            addRemoveMapBehavior(behavior);
        }
        private TreeViewItem createTreeViewNodeForToolButton(ExtensionBehavior behavior)
        {
            TreeViewItem node = new TreeViewItem()
            {
                Header = behavior.Title,
                Tag    = behavior,
                Style  = AddItemTree.ItemContainerStyle
            };

            return(node);
        }
        void ExtensionBehaviors_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null && e.NewItems.Count > 0)
            {
                selectedExtension = e.NewItems[0] as ExtensionBehavior;
            }

            if (ExtensionBehaviors.Count == 0)
            {
                selectedExtension = null;
            }

            if (MapBehaviorsDataGrid != null && selectedExtension != null)
            {
                MapBehaviorsDataGrid.SelectedItem = selectedExtension;
            }
        }
        public override bool CanExecute(object parameter)
        {
            ExtensionBehavior mapBehavior = parameter as ExtensionBehavior;

            if (mapBehavior == null)
            {
                return(false);
            }

            int pos = View.Instance.ExtensionBehaviors.IndexOf(mapBehavior);

            if (pos > -1 && pos < View.Instance.ExtensionBehaviors.Count - 1)
            {
                return(true);
            }

            return(false);
        }
        public override bool CanExecute(object parameter)
        {
            ExtensionBehavior extensionBehavior = parameter as ExtensionBehavior;

            if (extensionBehavior == null)
            {
                return(false);
            }

            ISupportsConfiguration supportConfiguration = extensionBehavior.MapBehavior as ISupportsConfiguration;

            if (supportConfiguration != null)
            {
                return(true);
            }

            return(false);
        }
        public override void Execute(object parameter)
        {
            ExtensionBehavior behavior = parameter as ExtensionBehavior;

            if (behavior == null)
            {
                return;
            }

            MessageBoxDialog.Show(LocalizableStrings.GetString("DeleteBehaviorCaption"), LocalizableStrings.GetString("DeleteBehaviorPrompt"), MessageBoxButton.OKCancel,
                                  new MessageBoxClosedEventHandler(delegate(object obj, MessageBoxClosedArgs args1)
            {
                if (args1.Result == MessageBoxResult.OK)
                {
                    // remove from map
                    removeMapBehavior(behavior);
                }
            }));
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            if (ExtensionBehaviors != null)
            {
                if (selectedExtension == null && ExtensionBehaviors.Count > 0)
                {
                    selectedExtension = ExtensionBehaviors[0];
                }

                ExtensionBehaviors.CollectionChanged -= ExtensionBehaviors_CollectionChanged;
                ExtensionBehaviors.CollectionChanged += ExtensionBehaviors_CollectionChanged;
            }
            MapBehaviorsDataGrid = GetTemplateChild("MapBehaviorsDataGrid") as System.Windows.Controls.DataGrid;
            if (MapBehaviorsDataGrid != null)
            {
                MapBehaviorsDataGrid.SelectedItem = selectedExtension;
                MapBehaviorsDataGrid.LoadingRow  -= MapBehaviorsDataGrid_LoadingRow;
                MapBehaviorsDataGrid.LoadingRow  += MapBehaviorsDataGrid_LoadingRow;
            }
        }
        private void addRemoveMapBehavior(ExtensionBehavior extensionBehavior)
        {
            if (MapApplication.Current == null && MapApplication.Current.Map != null)
            {
                return;
            }

            BehaviorCollection behaviors = Interaction.GetBehaviors(MapApplication.Current.Map);

            if (behaviors == null)
            {
                return;
            }

            Behavior <Map> mapBehavior = extensionBehavior.MapBehavior as Behavior <Map>;

            if (mapBehavior == null)
            {
                mapBehavior = BehaviorUtils.GetMapBehavior(extensionBehavior);
                extensionBehavior.MapBehavior = mapBehavior;
            }

            if (mapBehavior == null)
            {
                return;
            }

            if (extensionBehavior.IsEnabled)
            {
                if (!behaviors.Contains(mapBehavior))
                {
                    behaviors.Add(mapBehavior);
                }
            }
            else
            {
                behaviors.Remove(mapBehavior);
            }
        }
Example #17
0
        void updateExtensionBehavior(string extension, ExtensionBehavior behavior)
        {
            // Update the current behavior
            if (extension == "all")
            {
                // special case for the 'all' extension; apply it to every extension present
                if (behavior == ExtensionBehavior.Require || behavior == ExtensionBehavior.Enable) {
                    Error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", "");
                    return;
                }
                else
                {
                    string[] keys = new string[mExtensionBehaviors.Keys.Count];
                    mExtensionBehaviors.Keys.CopyTo (keys, 0);
                    foreach (string key in keys)
                    {
                        mExtensionBehaviors[key] = behavior;
                    }
                }
            }
            else
            {
                // Do the update for this single extension
                ExtensionBehavior found;
                if (mExtensionBehaviors.TryGetValue (extension, out found))
                {
                    if (found == ExtensionBehavior.DisablePartial)
                        Warn (getCurrentLoc (), "extension is only partially supported:", "#extension", extension);
                    if (behavior == ExtensionBehavior.Enable || behavior == ExtensionBehavior.Require)
                        mIntermediate.addRequestedExtension (extension);
                    mExtensionBehaviors[extension] = behavior;
                }
                else
                {
                    switch (behavior) {
                    case ExtensionBehavior.Require:
                        Error(getCurrentLoc(), "extension not supported:", "#extension", extension);
                        break;
                    case ExtensionBehavior.Enable:
                    case ExtensionBehavior.Warn:
                    case ExtensionBehavior.Disable:
                        Warn(getCurrentLoc(), "extension not supported:", "#extension", extension);
                        break;
                    default:
                        throw new InvalidOperationException("unexpected behavior");
                    }

                    return;
                }
            }
        }
Example #18
0
        //
        // Change the current state of an extension's behavior.
        //
        internal void updateExtensionBehavior(int line, string extension, string behaviorString)
        {
            if (ExtensionCallback != null)
            {
                ExtensionCallback(line, extension, behaviorString);
            }

            // Translate from text string of extension's behavior to an enum.
            ExtensionBehavior behavior = ExtensionBehavior.Disable;

            if (behaviorString == "require")
            {
                behavior = ExtensionBehavior.Require;
            }
            else if (behaviorString == "enable")
            {
                behavior = ExtensionBehavior.Enable;
            }
            else if (behaviorString == "disable")
            {
                behavior = ExtensionBehavior.Disable;
            }
            else if (behaviorString == "warn")
            {
                behavior = ExtensionBehavior.Warn;
            }
            else
            {
                Error(getCurrentLoc(), "behavior not supported:", "#extension", behaviorString);
                return;
            }

            // update the requested extension
            updateExtensionBehavior(extension, behavior);

            // see if need to propagate to implicitly modified things
            if (extension == GL_ANDROID_extension_pack_es31a)
            {
                // to everything in AEP
                updateExtensionBehavior(line, GL_KHR_blend_equation_advanced, behaviorString);
                updateExtensionBehavior(line, GL_OES_sample_variables, behaviorString);
                updateExtensionBehavior(line, GL_OES_shader_image_atomic, behaviorString);
                updateExtensionBehavior(line, GL_OES_shader_multisample_interpolation, behaviorString);
                updateExtensionBehavior(line, GL_OES_texture_storage_multisample_2d_array, behaviorString);
                updateExtensionBehavior(line, GL_EXT_geometry_shader, behaviorString);
                updateExtensionBehavior(line, GL_EXT_gpu_shader5, behaviorString);
                updateExtensionBehavior(line, GL_EXT_primitive_bounding_box, behaviorString);
                updateExtensionBehavior(line, GL_EXT_shader_io_blocks, behaviorString);
                updateExtensionBehavior(line, GL_EXT_tessellation_shader, behaviorString);
                updateExtensionBehavior(line, GL_EXT_texture_buffer, behaviorString);
                updateExtensionBehavior(line, GL_EXT_texture_cube_map_array, behaviorString);
            }
            // geometry to io_blocks
            else if (extension == GL_EXT_geometry_shader)
            {
                updateExtensionBehavior(line, GL_EXT_shader_io_blocks, behaviorString);
            }
            else if (extension == GL_OES_geometry_shader)
            {
                updateExtensionBehavior(line, GL_OES_shader_io_blocks, behaviorString);
            }
            // tessellation to io_blocks
            else if (extension == GL_EXT_tessellation_shader)
            {
                updateExtensionBehavior(line, GL_EXT_shader_io_blocks, behaviorString);
            }
            else if (extension == GL_OES_tessellation_shader)
            {
                updateExtensionBehavior(line, GL_OES_shader_io_blocks, behaviorString);
            }
        }
        private void buildAddItemTree()
        {
            // Clear all items in the tree control then add those determined in the constructor
            AddItemTree.Items.Clear();

            if (addItems == null)
            {
                return;
            }

            // Process all elements of the item list, dynamically creating parent category nodes and attaching
            // child nodes to these parents.
            string       curCategory = null;
            TreeViewItem parent      = null;
            bool         isSelected  = false;

            foreach (AddBehaviorItem item in addItems)
            {
                // If the current category does not match the category of the current item then create a new category node
                if (String.Compare(curCategory, item.Category) != 0)
                {
                    // Make this parent node selected only if the current category value is null so that the top category is selected
                    // but none of the subsequent category nodes are selected.
                    isSelected = curCategory == null ? true : false;
                    TreeViewItem tvi = new TreeViewItem()
                    {
                        Name       = item.Category,
                        Header     = item.Category,
                        IsExpanded = true,
                        IsSelected = isSelected,
                    };
                    AddItemTree.Items.Add(tvi);

                    // Assign the item category as the "current" category and assign the newly created category node as the
                    // parent to which all subsequent items are added.
                    curCategory = item.Category;
                    parent      = tvi;
                }

                // Create an instance of the type
                Behavior <Map> behavior = Activator.CreateInstance(item.BehaviorType) as Behavior <Map>;

                // Create a button display info object in order to store all the associated data which is
                // bound to the tree control for proper rendering.
                ExtensionBehavior bdi = new ExtensionBehavior();
                bdi.BehaviorId  = Guid.NewGuid().ToString();
                bdi.Title       = item.Name;
                bdi.IsEnabled   = true;
                bdi.MapBehavior = behavior;

                // Convert the button into a tree view item and associate proper styles, etc.
                TreeViewItem child = createTreeViewNodeForToolButton(bdi);
                child.Name = item.Category + item.Name + item.BehaviorType.ToString();

                // Use item description (if any) for the tooltip
                if (!String.IsNullOrEmpty(item.Description))
                {
                    child.SetValue(ToolTipService.ToolTipProperty, item.Description);
                }

                // Add child to parent node
                parent.Items.Add(child);
            }
        }