private void AddParameter_Click(object sender, RoutedEventArgs e)
        {
            LayerChainItem selectedLayer = ChainListBox.SelectedItem as LayerChainItem;

            if (selectedLayer != null)
            {
                if (selectedLayer.ParameterKeys.Contains("libraries"))
                {
                    int index = selectedLayer.ParameterKeys.IndexOf("libraries");
                    selectedLayer.ParameterKeys.RemoveAt(index);
                    selectedLayer.ParameterValues.RemoveAt(index);
                }


                selectedLayer.ParameterKeys.Add("libraries");

                if (!Libraries.Contains(LibraryBox.Text))
                {
                    Libraries.Add(LibraryBox.Text);
                }


                selectedLayer.ParameterValues.Add(new List <string>(Libraries));



                if (ParameterAdded != null)
                {
                    ParameterAdded(this, new LibraryAddedOrRemovedEventArgs(true, selectedLayer, LibraryBox.Text));
                }
            }
        }
        public void SetLayerChainItems(PrefabInterpretationLogic logic)
        {
            if (logic is LayerInterpretationLogic)
            {
                LayerInterpretationLogic            layerLog   = logic as LayerInterpretationLogic;
                List <string>                       layernames = new List <string>();
                List <Dictionary <string, object> > parameters = new List <Dictionary <string, object> >();

                ChainLoader.GetLayerNamesAndParameters(layerLog.LayerDirectory, layernames, parameters);


                LayerChainItems = new ObservableCollection <LayerChainItem>();
                if (layerLog.Layers != null)
                {
                    for (int i = 0; i < layernames.Count; i++)
                    {
                        LayerChainItem item = new LayerChainItem();
                        item.Name     = System.IO.Path.GetFileNameWithoutExtension(layernames[i]);
                        item.FullPath = layernames[i];
                        foreach (string key in parameters[i].Keys)
                        {
                            string val = parameters[i][key] as string;
                            if (val != null)
                            {
                                item.ParameterKeys.Add(key);
                                item.ParameterValues.Add(val);
                            }
                        }

                        LayerChainItems.Add(item);
                    }
                }

                //List<string> dirs = new List<string>();
                //dirs.Add(layerLog.LayerDirectory);
                //var alllayers = ChainLoader.GetAllLayerNames(dirs);

                //AllLayers = new ObservableCollection<LayerChainItem>();

                //foreach (string layer in alllayers)
                //{
                //    LayerChainItem item = new LayerChainItem();
                //    item.Name = System.IO.Path.GetFileNameWithoutExtension(layer);
                //    string path = System.IO.Path.GetDirectoryName(layer);

                //    if (System.IO.Path.Equals(path, layerLog.LayerDirectory))
                //    {
                //        item.FullPath = item.Name;
                //    }else
                //         item.FullPath = layer;

                //    AllLayers.Add(item);

                //}
            }
            else
            {
                Visibility = System.Windows.Visibility.Collapsed;
            }
        }
        private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListBox        parent = sender as ListBox;
            LayerChainItem data   = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as LayerChainItem;

            if (data != null)
            {
                Process.Start(data.FullPath);
            }
        }
 private void ChainListBox_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Pressed)
     {
         ListBox        parent = sender as ListBox;
         LayerChainItem data   = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as LayerChainItem;
         if (data != null)
         {
             DragDrop.DoDragDrop(parent, data, DragDropEffects.Move);
         }
     }
 }
        private void ChainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Parameters = new BindingList <ParameterKeyValuePair>();
            LayerChainItem item = ChainListBox.SelectedItem as LayerChainItem;

            if (item != null)
            {
                for (int i = 0; i < item.ParameterKeys.Count; i++)
                {
                    Parameters.Add(new ParameterKeyValuePair(item.ParameterKeys[i], item.ParameterValues[i].ToString()));
                }
            }
        }
        private void DeleteLayer_Click(object sender, RoutedEventArgs e)
        {
            Button         b    = sender as Button;
            LayerChainItem item = b.DataContext as LayerChainItem;

            LayerChainItems.Remove(item);


            if (LayerDeleted != null)
            {
                LayerDeleted(this, e);
            }
        }
        private void DeleteParameters_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            ParameterKeyValuePair param         = button.DataContext as ParameterKeyValuePair;
            LayerChainItem        selectedLayer = ChainListBox.SelectedItem as LayerChainItem;

            int index = selectedLayer.ParameterKeys.IndexOf(param.Key.Value);

            selectedLayer.ParameterKeys.RemoveAt(index);
            selectedLayer.ParameterValues.RemoveAt(index);

            Parameters.Remove(param);

            if (ParameterRemoved != null)
            {
                ParameterRemoved(this, new ParameterAddedOrRemovedEventArgs(false, selectedLayer, param));
            }
        }
        private void listBox1_Drop(object sender, DragEventArgs e)
        {
            ListBox        parent = sender as ListBox;
            LayerChainItem data   = e.Data.GetData(typeof(LayerChainItem)) as LayerChainItem;
            LayerChainItem objectToPlaceBefore = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as LayerChainItem;

            if (data != null && objectToPlaceBefore != null && data != objectToPlaceBefore)
            {
                int index = LayerChainItems.IndexOf(objectToPlaceBefore);
                LayerChainItems.Remove(data);
                LayerChainItems.Insert(index, data);
                this.ChainListBox.SelectedItem = data;

                if (LayerMoved != null)
                {
                    LayerMoved(this, e);
                }
            }
        }
        private void ChainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Libraries = new ObservableCollection <string>();
            LayerChainItem item = ChainListBox.SelectedItem as LayerChainItem;

            if (item != null)
            {
                if (item.ParameterKeys.Contains("libraries"))
                {
                    int index = item.ParameterKeys.IndexOf("libraries");

                    IEnumerable <string> libs = item.ParameterValues[index] as IEnumerable <string>;

                    foreach (string lib in libs)
                    {
                        Libraries.Add(lib);
                    }
                }
            }
        }
Exemple #10
0
        private void AddParameter_Click(object sender, RoutedEventArgs e)
        {
            ParameterKeyValuePair param         = new ParameterKeyValuePair(KeyBox.Text, ValueBox.Text);
            LayerChainItem        selectedLayer = ChainListBox.SelectedItem as LayerChainItem;

            if (selectedLayer.ParameterKeys.Contains(KeyBox.Text))
            {
                int index = selectedLayer.ParameterKeys.IndexOf(KeyBox.Text);
                selectedLayer.ParameterKeys.RemoveAt(index);
                selectedLayer.ParameterValues.RemoveAt(index);
            }
            selectedLayer.ParameterKeys.Add(KeyBox.Text);
            selectedLayer.ParameterValues.Add(ValueBox.Text);

            Parameters.Add(param);

            if (ParameterAdded != null)
            {
                ParameterAdded(this, new ParameterAddedOrRemovedEventArgs(true, selectedLayer, param));
            }
        }
        private void DeleteParameters_Click(object sender, RoutedEventArgs e)
        {
            Button         button        = sender as Button;
            string         lib           = button.DataContext as string;
            LayerChainItem selectedLayer = ChainListBox.SelectedItem as LayerChainItem;

            Libraries.Remove(lib);
            int index = selectedLayer.ParameterKeys.IndexOf("libraries");
            var libs  = selectedLayer.ParameterValues[index] as List <string>;

            libs.Remove(lib);

            if (libs.Count == 0)
            {
                selectedLayer.ParameterKeys.RemoveAt(index);
                selectedLayer.ParameterValues.RemoveAt(index);
            }
            if (ParameterRemoved != null)
            {
                ParameterRemoved(this, new LibraryAddedOrRemovedEventArgs(false, selectedLayer, lib));
            }
        }
Exemple #12
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (AddLayerComboBox.SelectedIndex >= 0)
            {
                LayerChainItem chainitem = AllLayers[AddLayerComboBox.SelectedIndex];

                LayerChainItem cpy = new LayerChainItem();
                cpy.Name     = chainitem.Name;
                cpy.FullPath = chainitem.FullPath;

                LayerChainItems.Add(cpy);

                if (LayerAdded != null)
                {
                    LayerAdded(this, e);
                }
            }
            else
            {
                AddLayerComboBox.Text = "Add a Layer";
            }
        }
        private void AddLayerButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "Python Files, Dlls, Directories | *.py; *.dll";
            ofd.Multiselect = true;
            if (ofd.ShowDialog().Value)
            {
                foreach (string filename in ofd.FileNames)
                {
                    LayerChainItem item = new LayerChainItem();
                    item.Name         = System.IO.Path.GetFileName(filename);
                    item.FullPath     = System.IO.Path.GetFullPath(filename);
                    item.RelativePath = GetRelativePath(item.FullPath, System.IO.Path.GetFullPath(_layerInterpretLogic.LayerDirectory));
                    LayerChainItems.Add(item);
                }

                if (LayerAdded != null)
                {
                    LayerAdded(this, e);
                }
            }
        }
Exemple #14
0
 public ParameterAddedOrRemovedEventArgs(bool added, LayerChainItem layer, ParameterKeyValuePair parameter)
 {
     Added = added;
     Layer = layer;
     Parameter = parameter;
 }
Exemple #15
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (AddLayerComboBox.SelectedIndex >= 0)
            {
                LayerChainItem chainitem = AllLayers[AddLayerComboBox.SelectedIndex];

                LayerChainItem cpy = new LayerChainItem();
                cpy.Name = chainitem.Name;
                cpy.FullPath = chainitem.FullPath;

                LayerChainItems.Add(cpy);

                if (LayerAdded != null)
                    LayerAdded(this, e);
            }
            else
                AddLayerComboBox.Text = "Add a Layer";
        }
Exemple #16
0
        public void SetLayerChainItems(PrefabInterpretationLogic logic)
        {
            if (logic is LayerInterpretationLogic)
            {
                LayerInterpretationLogic layerLog = logic as LayerInterpretationLogic;
                List<string> layernames = new List<string>();
                List<Dictionary<string, object>> parameters = new List<Dictionary<string, object>>();

                ChainLoader.GetLayerNamesAndParameters(layerLog.LayerDirectory, layernames, parameters);

                
                LayerChainItems = new ObservableCollection<LayerChainItem>();
                if (layerLog.Layers != null)
                {
                    for (int i = 0; i < layernames.Count; i ++ )
                    {
                        LayerChainItem item = new LayerChainItem();
                        item.Name = System.IO.Path.GetFileNameWithoutExtension(layernames[i]);
                        item.FullPath = layernames[i];
                        foreach (string key in parameters[i].Keys)
                        {

                            string val = parameters[i][key] as string;
                            if (val != null)
                            {
                                item.ParameterKeys.Add(key);
                                item.ParameterValues.Add(val);

                            }
                        }

                        LayerChainItems.Add(item);
                    }
                }

                //List<string> dirs = new List<string>();
                //dirs.Add(layerLog.LayerDirectory);
                //var alllayers = ChainLoader.GetAllLayerNames(dirs);

                //AllLayers = new ObservableCollection<LayerChainItem>();

                //foreach (string layer in alllayers)
                //{
                //    LayerChainItem item = new LayerChainItem();
                //    item.Name = System.IO.Path.GetFileNameWithoutExtension(layer);
                //    string path = System.IO.Path.GetDirectoryName(layer);
                    
                //    if (System.IO.Path.Equals(path, layerLog.LayerDirectory))
                //    {
                //        item.FullPath = item.Name;
                //    }else
                //         item.FullPath = layer;

                //    AllLayers.Add(item);

                //}
            }
            else
            {
                Visibility = System.Windows.Visibility.Collapsed;
            }
        }
 public LibraryAddedOrRemovedEventArgs(bool added, LayerChainItem layer, string library)
 {
     Added = added;
     Layer = layer;
     Library = library;
 }
        private void AddLayerButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Python Files, Dlls, Directories | *.py; *.dll";
            ofd.Multiselect = true;
            if (ofd.ShowDialog().Value)
            {
                foreach (string filename in ofd.FileNames)
                {
                    LayerChainItem item = new LayerChainItem();
                    item.Name = System.IO.Path.GetFileName(filename);
                    item.FullPath = System.IO.Path.GetFullPath(filename);
                    item.RelativePath = GetRelativePath(item.FullPath, System.IO.Path.GetFullPath(_layerInterpretLogic.LayerDirectory));
                    LayerChainItems.Add(item);   
                }

                if (LayerAdded != null)
                    LayerAdded(this, e);
            }
        }
        public void SetLayerChainItems(PrefabInterpretationLogic logic)
        {
            LayerChainItems = new ObservableCollection<LayerChainItem>();

            if (logic is LayerInterpretationLogic)
            {
                LayerInterpretationLogic layerLog = logic as LayerInterpretationLogic;
                _layerInterpretLogic = layerLog;
                List<string> layernames = new List<string>();
                List<Dictionary<string, object>> parameters = new List<Dictionary<string, object>>();

                ChainLoader.GetLayerNamesAndParameters(layerLog.LayerDirectory, layernames, parameters);

                
                

                    for (int i = 0; i < layernames.Count; i ++ )
                    {
                        
                        LayerChainItem item = new LayerChainItem();
                        item.Name = System.IO.Path.GetFileName(layernames[i]);
                        item.RelativePath = layernames[i];

                        item.FullPath = System.IO.Path.GetFullPath(layerLog.LayerDirectory + "/" + layernames[i]);

                        foreach (string key in parameters[i].Keys)
                        {

                            object val = parameters[i][key];
                            if (val != null)
                            {
                                item.ParameterKeys.Add(key);
                                item.ParameterValues.Add(val);

                            }
                        }

                        LayerChainItems.Add(item);
                    }
                

                //List<string> dirs = new List<string>();
                //dirs.Add(layerLog.LayerDirectory);
                //var alllayers = ChainLoader.GetAllLayerNames(dirs);

                //AllLayers = new ObservableCollection<LayerChainItem>();

                //foreach (string layer in alllayers)
                //{
                //    LayerChainItem item = new LayerChainItem();
                //    item.Name = System.IO.Path.GetFileName(layer);
                //    string path = System.IO.Path.GetDirectoryName(layer);
                    
                //    if (System.IO.Path.Equals(path, layerLog.LayerDirectory))
                //    {
                //        item.RelativePath = item.Name;
                //    }else
                //         item.RelativePath = layer;

                //    item.FullPath = System.IO.Path.GetFullPath(layerLog.LayerDirectory + "/" + layer);

                //    AllLayers.Add(item);

                //}
            }
            else
            {
                LayerChainItem item = new LayerChainItem();
                item.Name = "prefab_identification_layers";
                item.RelativePath = "..\\prefab_identification_layers";
                item.FullPath =  System.IO.Path.GetFullPath(logic.LayerDirectory + "/" + item.RelativePath);
                item.DeleteButtonVisibility = System.Windows.Visibility.Collapsed;
                LayerChainItems.Add(item);
                
                item = new LayerChainItem();
                item.Name = "interpret_tree.py";
                item.RelativePath = "interpret_tree.py";
                item.FullPath =  System.IO.Path.GetFullPath(logic.LayerDirectory + "/" + item.RelativePath);
                item.DeleteButtonVisibility = System.Windows.Visibility.Collapsed;
                LayerChainItems.Add(item);

                AddLayerButton.Visibility = Visibility.Collapsed;
                LibrariesPanel.Visibility = Visibility.Collapsed;
            }
        }
        public void SetLayerChainItems(PrefabInterpretationLogic logic)
        {
            LayerChainItems = new ObservableCollection <LayerChainItem>();

            if (logic is LayerInterpretationLogic)
            {
                LayerInterpretationLogic layerLog = logic as LayerInterpretationLogic;
                _layerInterpretLogic = layerLog;
                List <string> layernames = new List <string>();
                List <Dictionary <string, object> > parameters = new List <Dictionary <string, object> >();

                ChainLoader.GetLayerNamesAndParameters(layerLog.LayerDirectory, layernames, parameters);



                for (int i = 0; i < layernames.Count; i++)
                {
                    LayerChainItem item = new LayerChainItem();
                    item.Name         = System.IO.Path.GetFileName(layernames[i]);
                    item.RelativePath = layernames[i];

                    item.FullPath = System.IO.Path.GetFullPath(layerLog.LayerDirectory + "/" + layernames[i]);

                    foreach (string key in parameters[i].Keys)
                    {
                        object val = parameters[i][key];
                        if (val != null)
                        {
                            item.ParameterKeys.Add(key);
                            item.ParameterValues.Add(val);
                        }
                    }

                    LayerChainItems.Add(item);
                }


                //List<string> dirs = new List<string>();
                //dirs.Add(layerLog.LayerDirectory);
                //var alllayers = ChainLoader.GetAllLayerNames(dirs);

                //AllLayers = new ObservableCollection<LayerChainItem>();

                //foreach (string layer in alllayers)
                //{
                //    LayerChainItem item = new LayerChainItem();
                //    item.Name = System.IO.Path.GetFileName(layer);
                //    string path = System.IO.Path.GetDirectoryName(layer);

                //    if (System.IO.Path.Equals(path, layerLog.LayerDirectory))
                //    {
                //        item.RelativePath = item.Name;
                //    }else
                //         item.RelativePath = layer;

                //    item.FullPath = System.IO.Path.GetFullPath(layerLog.LayerDirectory + "/" + layer);

                //    AllLayers.Add(item);

                //}
            }
            else
            {
                LayerChainItem item = new LayerChainItem();
                item.Name                   = "prefab_identification_layers";
                item.RelativePath           = "..\\prefab_identification_layers";
                item.FullPath               = System.IO.Path.GetFullPath(logic.LayerDirectory + "/" + item.RelativePath);
                item.DeleteButtonVisibility = System.Windows.Visibility.Collapsed;
                LayerChainItems.Add(item);

                item                        = new LayerChainItem();
                item.Name                   = "interpret_tree.py";
                item.RelativePath           = "interpret_tree.py";
                item.FullPath               = System.IO.Path.GetFullPath(logic.LayerDirectory + "/" + item.RelativePath);
                item.DeleteButtonVisibility = System.Windows.Visibility.Collapsed;
                LayerChainItems.Add(item);

                AddLayerButton.Visibility = Visibility.Collapsed;
                LibrariesPanel.Visibility = Visibility.Collapsed;
            }
        }
Exemple #21
0
 public ParameterAddedOrRemovedEventArgs(bool added, LayerChainItem layer, ParameterKeyValuePair parameter)
 {
     Added     = added;
     Layer     = layer;
     Parameter = parameter;
 }
 public LibraryAddedOrRemovedEventArgs(bool added, LayerChainItem layer, string library)
 {
     Added   = added;
     Layer   = layer;
     Library = library;
 }