Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6693


Ignore:
Timestamp:
09/01/11 15:51:30 (13 years ago)
Author:
epitzer
Message:

Integrate functionality of RunCollectionModificationEvaluator directly into RunCollection and its view. (#1622)

This update includes a modified RunCollectionModificationEvaluator that automatic migrates all modifies into the RunCollection.

Location:
trunk/sources
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r6673 r6693  
    128128      <DependentUpon>BatchRunView.cs</DependentUpon>
    129129    </Compile>
     130    <Compile Include="RunCollectionModifierListView.cs">
     131      <SubType>UserControl</SubType>
     132    </Compile>
     133    <Compile Include="RunCollectionModifierListView.Designer.cs">
     134      <DependentUpon>RunCollectionModifierListView.cs</DependentUpon>
     135    </Compile>
    130136    <Compile Include="RunCollectionContentConstraintView.cs">
    131137      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.Designer.cs

    r5744 r6693  
    6565      this.constraintPage = new System.Windows.Forms.TabPage();
    6666      this.runCollectionConstraintCollectionView = new HeuristicLab.Optimization.Views.RunCollectionConstraintCollectionView();
     67      this.modifiersPage = new System.Windows.Forms.TabPage();
     68      this.runCollectionModifiersListView = new HeuristicLab.Optimization.Views.RunCollectionModifiersListView();
    6769      this.splitContainer.Panel1.SuspendLayout();
    6870      this.splitContainer.Panel2.SuspendLayout();
     
    7476      this.runPage.SuspendLayout();
    7577      this.constraintPage.SuspendLayout();
     78      this.modifiersPage.SuspendLayout();
    7679      this.SuspendLayout();
    7780      //
     
    235238      this.tabControl.Controls.Add(this.runPage);
    236239      this.tabControl.Controls.Add(this.constraintPage);
     240      this.tabControl.Controls.Add(this.modifiersPage);
    237241      this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
    238242      this.tabControl.Location = new System.Drawing.Point(0, 0);
     
    274278      this.runCollectionConstraintCollectionView.Size = new System.Drawing.Size(518, 351);
    275279      this.runCollectionConstraintCollectionView.TabIndex = 0;
     280      //
     281      // modifiersPage
     282      //
     283      this.modifiersPage.Controls.Add(this.runCollectionModifiersListView);
     284      this.modifiersPage.Location = new System.Drawing.Point(4, 22);
     285      this.modifiersPage.Name = "modifiersPage";
     286      this.modifiersPage.Padding = new System.Windows.Forms.Padding(3);
     287      this.modifiersPage.Size = new System.Drawing.Size(524, 357);
     288      this.modifiersPage.TabIndex = 2;
     289      this.modifiersPage.Text = "Modification";
     290      this.modifiersPage.UseVisualStyleBackColor = true;
     291      //
     292      // runCollectionModifiersListView
     293      //
     294      this.runCollectionModifiersListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     295            | System.Windows.Forms.AnchorStyles.Left)
     296            | System.Windows.Forms.AnchorStyles.Right)));
     297      this.runCollectionModifiersListView.Caption = "Modifier View";
     298      this.runCollectionModifiersListView.Content = null;
     299      this.runCollectionModifiersListView.Location = new System.Drawing.Point(3, 6);
     300      this.runCollectionModifiersListView.Name = "runCollectionModifiersListView";
     301      this.runCollectionModifiersListView.ReadOnly = false;
     302      this.runCollectionModifiersListView.Size = new System.Drawing.Size(515, 345);
     303      this.runCollectionModifiersListView.TabIndex = 0;
    276304      //
    277305      // RunCollectionView
     
    291319      this.runPage.ResumeLayout(false);
    292320      this.constraintPage.ResumeLayout(false);
     321      this.modifiersPage.ResumeLayout(false);
    293322      this.ResumeLayout(false);
    294323
     
    314343    private Button clearButton;
    315344    private CheckBox showDetailsCheckBox;
     345    private TabPage modifiersPage;
     346    private RunCollectionModifiersListView runCollectionModifiersListView;
    316347  }
    317348}
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r6664 r6693  
    5858      itemsGroupBox.Text = "Runs";
    5959      itemListViewItemMapping = new Dictionary<IRun, List<ListViewItem>>();
     60      runCollectionModifiersListView.Evaluator = EvaluateModifications;
    6061    }
    6162
     
    9899        }
    99100      }
    100       var modifierMenuItem = new ToolStripMenuItem();
    101       modifierMenuItem.Text = "Modify RunCollection";
    102       modifierMenuItem.Click += ModifierMenuItem_OnClick;
    103       analyzeRunsToolStripDropDownButton.DropDownItems.Add(modifierMenuItem);
    104101    }
    105102
     
    122119          runCollectionConstraintCollectionView.Content = RunCollection.Constraints;
    123120          runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
     121          if (!tabControl.TabPages.Contains(modifiersPage))
     122            tabControl.TabPages.Add(modifiersPage);
     123          runCollectionModifiersListView.Content = RunCollection.Modifiers;
    124124        }
    125125        foreach (IRun item in Content) {
     
    134134        if (tabControl.TabPages.Contains(constraintPage))
    135135          tabControl.TabPages.Remove(constraintPage);
     136        if (tabControl.TabPages.Contains(modifiersPage))
     137          tabControl.TabPages.Remove(modifiersPage);
    136138      }
    137139    }
     
    340342      }
    341343    }
    342     private void ModifierMenuItem_OnClick(object sender, EventArgs args) {
    343       var modifier = new RunCollectionModificationEvaluator();
    344       modifier.RunCollection.AddRange(Content.Select(r => (IRun)r.Clone()));
    345       MainFormManager.MainForm.ShowContent(modifier);
    346     }
    347344    private void removeButton_Click(object sender, EventArgs e) {
    348345      if (itemsListView.SelectedItems.Count > 0) {
     
    357354    #endregion
    358355
    359     #region CheckBox Events
     356    #region Control Events
    360357    private void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
    361358      if (showDetailsCheckBox.Checked) {
     
    368365      }
    369366    }
     367    private void EvaluateModifications() {
     368      if (RunCollection == null)
     369        return;
     370      ReadOnly = true;
     371      try {
     372        RunCollection.Modify();
     373      } finally {
     374        ReadOnly = false;
     375      }
     376    }
    370377    #endregion
    371378
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r5445 r6693  
    5151
    5252      constraints = new RunCollectionConstraintCollection(original.constraints.Select(x => cloner.Clone(x)));
     53      modifiers = new CheckedItemList<IRunCollectionModifier>(original.modifiers.Select(cloner.Clone));
    5354      foreach (IRunCollectionConstraint constraint in constraints)
    5455        constraint.ConstrainedValue = this;
     
    6768      dataTypes = new Dictionary<string, HashSet<Type>>();
    6869      constraints = new RunCollectionConstraintCollection();
     70      modifiers = new CheckedItemList<IRunCollectionModifier>();
    6971      RegisterConstraintsEvents();
    7072    }
     
    8385      get { return constraints; }
    8486    }
     87
     88    [Storable]
     89    private CheckedItemList<IRunCollectionModifier> modifiers;
     90    public CheckedItemList<IRunCollectionModifier> Modifiers {
     91      get { return modifiers; }
     92    }
     93
    8594
    8695    private bool updateOfRunsInProgress;
     
    98107    private void AfterDeserialization() {
    99108      if (constraints == null) constraints = new RunCollectionConstraintCollection();
     109      if (modifiers == null) modifiers = new CheckedItemList<IRunCollectionModifier>();
    100110      RegisterConstraintsEvents();
    101111      RegisterConstraintEvents(constraints);
     
    393403    }
    394404    #endregion
     405
     406    #region Modification
     407    public void Modify() {
     408      UpdateOfRunsInProgress = true;
     409      var runs = this.ToList();
     410      var selectedRuns = runs.Where(r => r.Visible).ToList();
     411      int nSelected = selectedRuns.Count;
     412      if (nSelected > 0) {
     413        foreach (var modifier in Modifiers.CheckedItems)
     414          modifier.Value.Modify(selectedRuns);
     415        if (nSelected != selectedRuns.Count || HaveDifferentOrder(selectedRuns, runs.Where(r => r.Visible))) {
     416          Clear();
     417          AddRange(ReplaceVisibleRuns(runs, selectedRuns));
     418        } else if (runs.Count > 0) {
     419          OnCollectionReset(this, runs);
     420        }
     421      }
     422      UpdateOfRunsInProgress = false;
     423    }
     424
     425    private static IEnumerable<IRun> ReplaceVisibleRuns(IEnumerable<IRun> runs, IEnumerable<IRun> visibleRuns) {
     426      var newRuns = new List<IRun>();
     427      var runIt = runs.GetEnumerator();
     428      var visibleRunIt = visibleRuns.GetEnumerator();
     429      while (runIt.MoveNext()) {
     430        if (runIt.Current != null && !runIt.Current.Visible)
     431          newRuns.Add(runIt.Current);
     432        else if (visibleRunIt.MoveNext())
     433          newRuns.Add(visibleRunIt.Current);
     434      }
     435      while (visibleRunIt.MoveNext())
     436        newRuns.Add(visibleRunIt.Current);
     437      return newRuns;
     438    }
     439
     440    private static bool HaveDifferentOrder(IEnumerable<IRun> l1, IEnumerable<IRun> l2) {
     441      return l1.Zip(l2, (r1, r2) => r1 != r2).Any();
     442    }
     443    #endregion
    395444  }
    396445}
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionModificationEvaluator.cs

    r6677 r6693  
    4848    #endregion
    4949
     50    [StorableHook(HookType.AfterDeserialization)]
     51    private void AfterDeserialization() {
     52      if (RunCollection != null && RunCollection.Modifiers != null) {
     53        RunCollection.Modifiers.AddRange(Modifiers);
     54        foreach (var modifier in RunCollection.Modifiers) {
     55          RunCollection.Modifiers.SetItemCheckedState(modifier, Modifiers.ItemChecked(modifier));
     56        }
     57        Modifiers.Clear();
     58      }
     59    }
     60
    5061    public void Evaluate() {
    5162      RunCollection.UpdateOfRunsInProgress = true;
    52       var runs = RunCollection.Select((r, i) => new {Run = r, r.Visible, Index = i}).ToList();
     63      var runs = RunCollection.Select((r, i) => new { Run = r, r.Visible, Index = i }).ToList();
    5364      var visibleRuns = runs.Where(r => r.Visible).Select(r => r.Run).ToList();
    5465      int n = visibleRuns.Count;
     
    7384        RunCollection.AddRange(newRuns);
    7485      } else if (runs.Count > 0) { // force update
    75         var run = (IRun) runs[0].Run.Clone();
     86        var run = (IRun)runs[0].Run.Clone();
    7687        RunCollection.Add(run);
    7788        RunCollection.Remove(run);
Note: See TracChangeset for help on using the changeset viewer.