Changeset 2701


Ignore:
Timestamp:
01/28/10 16:43:36 (10 years ago)
Author:
gkronber
Message:

Repaired FunctionLibraryEditor. #748 (FunctionLibraryView is empty)

Location:
trunk/sources/HeuristicLab.GP/3.3
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP/3.3/FunctionLibrary.cs

    r2222 r2701  
    4242      if (!functions.Contains(fun)) {
    4343        functions.Add(fun);
     44        fun.Changed += new EventHandler(fun_Changed);
    4445        OnChanged();
    4546      }
     
    4849    public void RemoveFunction(IFunction fun) {
    4950      functions.Remove(fun);
     51      fun.Changed -= new EventHandler(fun_Changed);
    5052
    5153      // remove the operator from the allowed sub-functions of all functions
     
    5557        }
    5658      }
     59      OnChanged();
     60    }
     61
     62    void fun_Changed(object sender, EventArgs e) {
    5763      OnChanged();
    5864    }
  • trunk/sources/HeuristicLab.GP/3.3/FunctionLibraryEditor.Designer.cs

    r2222 r2701  
    4747      this.tabControl = new System.Windows.Forms.TabControl();
    4848      this.functionsTabPage = new System.Windows.Forms.TabPage();
     49      this.splitContainer = new System.Windows.Forms.SplitContainer();
     50      this.availableFunctionsGroupBox = new System.Windows.Forms.GroupBox();
     51      this.functionsListView = new System.Windows.Forms.ListView();
     52      this.removeButton = new System.Windows.Forms.Button();
     53      this.addButton = new System.Windows.Forms.Button();
     54      this.functionDetailsGroupBox = new System.Windows.Forms.GroupBox();
     55      this.functionDetailsPanel = new System.Windows.Forms.Panel();
     56      this.functionsComboBox = new System.Windows.Forms.ComboBox();
    4957      this.initializationTabPage = new System.Windows.Forms.TabPage();
    5058      this.initSplitContainer = new System.Windows.Forms.SplitContainer();
     
    5563      this.mutationListView = new System.Windows.Forms.ListView();
    5664      this.mutationVariableView = new HeuristicLab.Core.VariableView();
    57       this.addButton = new System.Windows.Forms.Button();
    58       this.removeButton = new System.Windows.Forms.Button();
    59       this.functionsListView = new System.Windows.Forms.ListView();
    6065      this.tabControl.SuspendLayout();
    6166      this.functionsTabPage.SuspendLayout();
     67      this.splitContainer.Panel1.SuspendLayout();
     68      this.splitContainer.Panel2.SuspendLayout();
     69      this.splitContainer.SuspendLayout();
     70      this.availableFunctionsGroupBox.SuspendLayout();
     71      this.functionDetailsGroupBox.SuspendLayout();
    6272      this.initializationTabPage.SuspendLayout();
    6373      this.initSplitContainer.Panel1.SuspendLayout();
     
    8494      // functionsTabPage
    8595      //
    86       this.functionsTabPage.Controls.Add(this.functionsListView);
    87       this.functionsTabPage.Controls.Add(this.removeButton);
    88       this.functionsTabPage.Controls.Add(this.addButton);
     96      this.functionsTabPage.Controls.Add(this.splitContainer);
    8997      this.functionsTabPage.Location = new System.Drawing.Point(4, 22);
    9098      this.functionsTabPage.Name = "functionsTabPage";
     
    94102      this.functionsTabPage.Text = "Functions";
    95103      this.functionsTabPage.UseVisualStyleBackColor = true;
     104      //
     105      // splitContainer
     106      //
     107      this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
     108      this.splitContainer.Location = new System.Drawing.Point(3, 3);
     109      this.splitContainer.Name = "splitContainer";
     110      //
     111      // splitContainer.Panel1
     112      //
     113      this.splitContainer.Panel1.Controls.Add(this.availableFunctionsGroupBox);
     114      //
     115      // splitContainer.Panel2
     116      //
     117      this.splitContainer.Panel2.Controls.Add(this.functionDetailsGroupBox);
     118      this.splitContainer.Size = new System.Drawing.Size(663, 529);
     119      this.splitContainer.SplitterDistance = 230;
     120      this.splitContainer.TabIndex = 4;
     121      //
     122      // availableFunctionsGroupBox
     123      //
     124      this.availableFunctionsGroupBox.Controls.Add(this.functionsListView);
     125      this.availableFunctionsGroupBox.Controls.Add(this.removeButton);
     126      this.availableFunctionsGroupBox.Controls.Add(this.addButton);
     127      this.availableFunctionsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     128      this.availableFunctionsGroupBox.Location = new System.Drawing.Point(0, 0);
     129      this.availableFunctionsGroupBox.Name = "availableFunctionsGroupBox";
     130      this.availableFunctionsGroupBox.Size = new System.Drawing.Size(230, 529);
     131      this.availableFunctionsGroupBox.TabIndex = 5;
     132      this.availableFunctionsGroupBox.TabStop = false;
     133      this.availableFunctionsGroupBox.Text = "Available functions:";
     134      //
     135      // functionsListView
     136      //
     137      this.functionsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     138                  | System.Windows.Forms.AnchorStyles.Left)
     139                  | System.Windows.Forms.AnchorStyles.Right)));
     140      this.functionsListView.Location = new System.Drawing.Point(6, 19);
     141      this.functionsListView.MultiSelect = false;
     142      this.functionsListView.Name = "functionsListView";
     143      this.functionsListView.Size = new System.Drawing.Size(218, 475);
     144      this.functionsListView.TabIndex = 3;
     145      this.functionsListView.UseCompatibleStateImageBehavior = false;
     146      this.functionsListView.View = System.Windows.Forms.View.List;
     147      this.functionsListView.SelectedIndexChanged += new System.EventHandler(this.functionsListView_SelectedIndexChanged);
     148      this.functionsListView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.functionsListView_ItemDrag);
     149      //
     150      // removeButton
     151      //
     152      this.removeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     153      this.removeButton.Location = new System.Drawing.Point(87, 500);
     154      this.removeButton.Name = "removeButton";
     155      this.removeButton.Size = new System.Drawing.Size(75, 23);
     156      this.removeButton.TabIndex = 2;
     157      this.removeButton.Text = "Remove";
     158      this.removeButton.UseVisualStyleBackColor = true;
     159      this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
     160      //
     161      // addButton
     162      //
     163      this.addButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     164      this.addButton.Location = new System.Drawing.Point(6, 500);
     165      this.addButton.Name = "addButton";
     166      this.addButton.Size = new System.Drawing.Size(75, 23);
     167      this.addButton.TabIndex = 1;
     168      this.addButton.Text = "Add...";
     169      this.addButton.UseVisualStyleBackColor = true;
     170      this.addButton.Click += new System.EventHandler(this.addButton_Click);
     171      //
     172      // functionDetailsGroupBox
     173      //
     174      this.functionDetailsGroupBox.Controls.Add(this.functionDetailsPanel);
     175      this.functionDetailsGroupBox.Controls.Add(this.functionsComboBox);
     176      this.functionDetailsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     177      this.functionDetailsGroupBox.Location = new System.Drawing.Point(0, 0);
     178      this.functionDetailsGroupBox.Name = "functionDetailsGroupBox";
     179      this.functionDetailsGroupBox.Size = new System.Drawing.Size(429, 529);
     180      this.functionDetailsGroupBox.TabIndex = 8;
     181      this.functionDetailsGroupBox.TabStop = false;
     182      this.functionDetailsGroupBox.Text = "Function details:";
     183      //
     184      // functionDetailsPanel
     185      //
     186      this.functionDetailsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     187                  | System.Windows.Forms.AnchorStyles.Left)
     188                  | System.Windows.Forms.AnchorStyles.Right)));
     189      this.functionDetailsPanel.Location = new System.Drawing.Point(6, 46);
     190      this.functionDetailsPanel.Name = "functionDetailsPanel";
     191      this.functionDetailsPanel.Size = new System.Drawing.Size(417, 477);
     192      this.functionDetailsPanel.TabIndex = 7;
     193      //
     194      // functionsComboBox
     195      //
     196      this.functionsComboBox.FormattingEnabled = true;
     197      this.functionsComboBox.Location = new System.Drawing.Point(6, 19);
     198      this.functionsComboBox.Name = "functionsComboBox";
     199      this.functionsComboBox.Size = new System.Drawing.Size(178, 21);
     200      this.functionsComboBox.TabIndex = 0;
     201      this.functionsComboBox.SelectedIndexChanged += new System.EventHandler(this.functionsComboBox_SelectedIndexChanged);
    96202      //
    97203      // initializationTabPage
     
    194300      this.mutationVariableView.Variable = null;
    195301      //
    196       // addButton
    197       //
    198       this.addButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    199       this.addButton.Location = new System.Drawing.Point(6, 506);
    200       this.addButton.Name = "addButton";
    201       this.addButton.Size = new System.Drawing.Size(75, 23);
    202       this.addButton.TabIndex = 1;
    203       this.addButton.Text = "Add...";
    204       this.addButton.UseVisualStyleBackColor = true;
    205       this.addButton.Click += new System.EventHandler(this.addButton_Click);
    206       //
    207       // removeButton
    208       //
    209       this.removeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    210       this.removeButton.Location = new System.Drawing.Point(87, 506);
    211       this.removeButton.Name = "removeButton";
    212       this.removeButton.Size = new System.Drawing.Size(75, 23);
    213       this.removeButton.TabIndex = 2;
    214       this.removeButton.Text = "Remove";
    215       this.removeButton.UseVisualStyleBackColor = true;
    216       this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
    217       //
    218       // functionsListView
    219       //
    220       this.functionsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    221                   | System.Windows.Forms.AnchorStyles.Left)
    222                   | System.Windows.Forms.AnchorStyles.Right)));
    223       this.functionsListView.Location = new System.Drawing.Point(3, 6);
    224       this.functionsListView.Name = "functionsListView";
    225       this.functionsListView.Size = new System.Drawing.Size(660, 494);
    226       this.functionsListView.TabIndex = 3;
    227       this.functionsListView.UseCompatibleStateImageBehavior = false;
    228       this.functionsListView.SelectedIndexChanged += new System.EventHandler(this.functionsListView_SelectedIndexChanged);
    229       //
    230302      // FunctionLibraryEditor
    231303      //
     
    237309      this.tabControl.ResumeLayout(false);
    238310      this.functionsTabPage.ResumeLayout(false);
     311      this.splitContainer.Panel1.ResumeLayout(false);
     312      this.splitContainer.Panel2.ResumeLayout(false);
     313      this.splitContainer.ResumeLayout(false);
     314      this.availableFunctionsGroupBox.ResumeLayout(false);
     315      this.functionDetailsGroupBox.ResumeLayout(false);
    239316      this.initializationTabPage.ResumeLayout(false);
    240317      this.initSplitContainer.Panel1.ResumeLayout(false);
     
    264341    private System.Windows.Forms.Button addButton;
    265342    private System.Windows.Forms.ListView functionsListView;
     343    private System.Windows.Forms.SplitContainer splitContainer;
     344    private System.Windows.Forms.Panel functionDetailsPanel;
     345    private System.Windows.Forms.ComboBox functionsComboBox;
     346    private System.Windows.Forms.GroupBox availableFunctionsGroupBox;
     347    private System.Windows.Forms.GroupBox functionDetailsGroupBox;
    266348  }
    267349}
  • trunk/sources/HeuristicLab.GP/3.3/FunctionLibraryEditor.cs

    r2222 r2701  
    4848    protected override void UpdateControls() {
    4949      base.UpdateControls();
     50      functionsListView.Clear();
     51      functionsComboBox.Items.Clear();
    5052      foreach (IFunction fun in FunctionLibrary.Functions) {
     53        functionsListView.Items.Add(CreateListViewItem(fun));
     54        functionsComboBox.Items.Add(fun);
    5155        if (fun.Manipulator != null) {
    5256          mutationListView.Items.Add(CreateListViewItem(fun));
     
    8286      if (chooseFunctionDialog.ShowDialog(this) == DialogResult.OK) {
    8387        FunctionLibrary.AddFunction((IFunction)chooseFunctionDialog.Item);
    84         functionsListView.Items.Add(CreateListViewItem((IFunction)chooseFunctionDialog.Item));
    85         functionsListView.Sort();
    8688      }
    8789    }
     
    8991    private void removeButton_Click(object sender, EventArgs e) {
    9092      // delete from the end of the list
    91       IEnumerable<int> removeIndices = functionsListView.SelectedIndices.OfType<int>().OrderBy(x => 1.0 / x);
     93      List<int> removeIndices = functionsListView.SelectedIndices.OfType<int>().OrderBy(x => 1.0 / x).ToList();
    9294      foreach (int selectedIndex in removeIndices) {
    93         FunctionLibrary.RemoveFunction((IFunction)functionsListView.Items[selectedIndex].Tag);
    94         functionsListView.Items.RemoveAt(selectedIndex);
     95        FunctionLibrary.RemoveFunction((IFunction)functionsListView.Items[selectedIndex].Tag);       
    9596      }
    9697    }
    9798
    9899    private void functionsListView_SelectedIndexChanged(object sender, EventArgs e) {
    99       removeButton.Enabled = functionsListView.SelectedIndices.Count > 0;
     100      if (functionsListView.SelectedIndices.Count > 0) {
     101        removeButton.Enabled = true;
     102      } else {
     103        removeButton.Enabled = false;
     104      }
    100105    }
    101106
     
    107112      return item;
    108113    }
     114
     115    private void functionsListView_ItemDrag(object sender, ItemDragEventArgs e) {
     116      ListViewItem item = (ListViewItem)e.Item;
     117      IFunction fun = (IFunction)item.Tag;
     118      DataObject data = new DataObject();
     119      data.SetData("IFunction", fun);
     120      data.SetData("DragSource", functionsListView);
     121      DoDragDrop(data, DragDropEffects.Link);
     122    }
     123
     124    private void functionsComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     125      if (functionsComboBox.SelectedItem != null) {
     126        IFunction selectedFun = (IFunction)functionsComboBox.SelectedItem;
     127        Control funView = (Control)selectedFun.CreateView();
     128        funView.Dock = DockStyle.Fill;
     129        functionDetailsPanel.Controls.Clear();
     130        functionDetailsPanel.Controls.Add(funView);
     131      }
     132    }
    109133  }
    110134}
  • trunk/sources/HeuristicLab.GP/3.3/HeuristicLab.GP-3.3.csproj

    r2629 r2701  
    8383  <ItemGroup>
    8484    <Compile Include="BaseClasses\BinaryFunction.cs" />
     85    <Compile Include="BaseClasses\Function.cs" />
    8586    <Compile Include="BaseClasses\FunctionLibraryInjectorBase.cs" />
     87    <Compile Include="BaseClasses\FunctionTree.cs" />
    8688    <Compile Include="BaseClasses\TerminalTreeNode.cs" />
    87     <Compile Include="BaseClasses\FunctionBase.cs" />
    88     <Compile Include="BaseClasses\FunctionTreeBase.cs" />
    8989    <Compile Include="BaseClasses\Terminal.cs" />
    9090    <Compile Include="BaseClasses\UnaryFunction.cs" />
     91    <Compile Include="FunctionView.cs">
     92      <SubType>UserControl</SubType>
     93    </Compile>
     94    <Compile Include="FunctionView.Designer.cs">
     95      <DependentUpon>FunctionView.cs</DependentUpon>
     96    </Compile>
    9197    <Compile Include="GeneticProgrammingModelView.cs">
    9298      <SubType>UserControl</SubType>
     
    132138  </ItemGroup>
    133139  <ItemGroup>
     140    <EmbeddedResource Include="FunctionView.resx">
     141      <DependentUpon>FunctionView.cs</DependentUpon>
     142    </EmbeddedResource>
    134143    <EmbeddedResource Include="GeneticProgrammingModelView.resx">
    135144      <DependentUpon>GeneticProgrammingModelView.cs</DependentUpon>
Note: See TracChangeset for help on using the changeset viewer.