Free cookie consent management tool by TermsFeed Policy Generator

Changeset 418 for trunk/sources


Ignore:
Timestamp:
08/01/08 16:50:58 (16 years ago)
Author:
gkronber
Message:

worked on #211 (Full operator-graphs are stored multiple times in the database even though most of it is static anyway)

  • added class OperatorLink that allows to create CombinedOperators in the DatabaseOperatorLibrary which use other operators from the library (not via a copy but via a link)
Location:
trunk/sources/HeuristicLab.CEDMA.Core
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/DatabaseOperatorLibrary.cs

    r417 r418  
    55using HeuristicLab.Core;
    66using HeuristicLab.CEDMA.DB.Interfaces;
     7using HeuristicLab.Operators;
    78
    89namespace HeuristicLab.CEDMA.Core {
     
    2930
    3031    public void Save() {
    31       Dictionary<IOperator, long> newKnownOperators = new Dictionary<IOperator,long>();
     32      Dictionary<IOperator, long> newKnownOperators = new Dictionary<IOperator, long>();
    3233      foreach(IOperator op in group.Operators) {
    3334        if(knownOperators.ContainsKey(op)) {
    3435          // update
    35           long id =knownOperators[op];
     36          long id = knownOperators[op];
    3637          Database.UpdateOperator(id, op.Name, PersistenceManager.SaveToGZip(op));
    3738          knownOperators.Remove(op);
     
    4748        Database.DeleteOperator(id);
    4849      }
    49      
     50
    5051      knownOperators = newKnownOperators;
    5152    }
     
    6263        group.AddOperator(op);
    6364      }
     65
     66      // patch all OperatorLinks
     67      foreach(IOperator op in group.Operators) {
     68        PatchLinks(op);
     69      }
     70    }
     71
     72    private void PatchLinks(IOperator op) {
     73      if(op is OperatorLink) {
     74        OperatorLink link = op as OperatorLink;
     75        link.Operator = FindOperator(link.Id);
     76      }
     77      else if(op is CombinedOperator) {
     78        CombinedOperator combinedOp = op as CombinedOperator;
     79        foreach(IOperator internalOp in combinedOp.OperatorGraph.Operators) {
     80          PatchLinks(internalOp);
     81        }
     82      }
     83    }
     84
     85    private IOperator FindOperator(long id) {
     86      foreach(KeyValuePair<IOperator, long> p in knownOperators) if(p.Value == id) return p.Key;
     87      return null;
    6488    }
    6589
     
    80104      return new DatabaseOperatorLibraryView(this);
    81105    }
     106
     107    internal long GetId(IOperator op) {
     108      return knownOperators[op];
     109    }
    82110  }
    83111}
  • trunk/sources/HeuristicLab.CEDMA.Core/DatabaseOperatorLibraryView.cs

    r417 r418  
    5656
    5757        int result = string.Compare(tx.Text, ty.Text);
    58         if (result == 0)
     58        if(result == 0)
    5959          result = tx.Index.CompareTo(ty.Index);
    6060        return result;
     
    6767      addOperatorButton.Enabled = false;
    6868      removeButton.Enabled = false;
    69       if (OperatorLibrary == null) {
     69      if(OperatorLibrary == null) {
    7070        Caption = "Operator Library";
    7171        operatorsGroupBox.Enabled = false;
     
    9898    }
    9999    private void RemoveTreeNode(TreeNode node) {
    100       if (node.Tag is IOperatorGroup) {
     100      if(node.Tag is IOperatorGroup) {
    101101        IOperatorGroup group = node.Tag as IOperatorGroup;
    102102        IOperatorGroup parent = node.Parent.Tag as IOperatorGroup;
    103103        parent.RemoveSubGroup(group);
    104       } else if (node.Tag is IOperator) {
     104      } else if(node.Tag is IOperator) {
    105105        IOperator op = node.Tag as IOperator;
    106106        IOperatorGroup group = node.Parent.Tag as IOperatorGroup;
     
    116116      operatorsTreeView.Focus();
    117117
    118       if (operatorsTreeView.SelectedNode != null) {
    119         if (operatorsTreeView.SelectedNode.Parent != null)
     118      if(operatorsTreeView.SelectedNode != null) {
     119        if(operatorsTreeView.SelectedNode.Parent != null)
    120120          removeButton.Enabled = true;
    121         if (operatorsTreeView.SelectedNode.Tag is IOperatorGroup) {
     121        if(operatorsTreeView.SelectedNode.Tag is IOperatorGroup) {
    122122          addOperatorButton.Enabled = true;
    123123        }
     
    133133
    134134      string name = e.Label;
    135       if (name != null) {
    136         if (e.Node.Tag is IOperatorGroup)
     135      if(name != null) {
     136        if(e.Node.Tag is IOperatorGroup)
    137137          ((IOperatorGroup)e.Node.Tag).Name = name;
    138         else if (e.Node.Tag is IOperator)
     138        else if(e.Node.Tag is IOperator)
    139139          ((IOperator)e.Node.Tag).Name = name;
    140140      }
    141141    }
    142142    private void operatorsTreeView_DoubleClick(object sender, EventArgs e) {
    143       if (operatorsTreeView.SelectedNode != null) {
     143      if(operatorsTreeView.SelectedNode != null) {
    144144        IOperator op = operatorsTreeView.SelectedNode.Tag as IOperator;
    145         if (op != null) {
     145        if(op != null) {
    146146          IView view = op.CreateView();
    147           if (view != null)
     147          if(view != null)
    148148            PluginManager.ControlManager.ShowControl(view);
    149149        }
     
    154154    #region Button Events
    155155    private void addOperatorButton_Click(object sender, EventArgs e) {
    156       if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
    157       if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
     156      if(chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
     157      if(chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
    158158        TreeNode node = operatorsTreeView.SelectedNode;
    159159        IOperatorGroup group = node.Tag as IOperatorGroup;
     
    173173    private void operatorsTreeView_KeyDown(object sender, KeyEventArgs e) {
    174174      TreeNode node = operatorsTreeView.SelectedNode;
    175       if ((e.KeyCode == Keys.Delete) && (node != null) && (node.Parent != null))
     175      if((e.KeyCode == Keys.Delete) && (node != null) && (node.Parent != null))
    176176        RemoveTreeNode(operatorsTreeView.SelectedNode);
    177       if ((e.KeyCode == Keys.F2) && (node != null))
     177      if((e.KeyCode == Keys.F2) && (node != null))
    178178        node.BeginEdit();
    179179    }
     
    183183    #region Mouse Events
    184184    private void operatorsTreeView_MouseDown(object sender, MouseEventArgs e) {
    185       if (e.Button != MouseButtons.Right) return;
     185      if(e.Button != MouseButtons.Right) return;
    186186      TreeNode clickedNode = operatorsTreeView.GetNodeAt(e.X, e.Y);
    187       if (clickedNode != null) {
     187      if(clickedNode != null) {
    188188        operatorsTreeView.SelectedNode = clickedNode;
    189189        operatorsTreeView.Refresh();
     
    196196      TreeNode node = (TreeNode)e.Item;
    197197      IOperator op = node.Tag as IOperator;
    198       if (op != null) {
     198      if(op != null) {
     199        long opId = ((DatabaseOperatorLibrary)OperatorLibrary).GetId(op);
     200        OperatorLink link = new OperatorLink(opId, op);
    199201        DataObject data = new DataObject();
    200         data.SetData("IOperator", op);
     202        data.SetData("IOperator", link);
    201203        data.SetData("DragSource", operatorsTreeView);
    202204        DoDragDrop(data, DragDropEffects.Copy);
     
    205207    private void operatorsTreeView_DragEnter(object sender, DragEventArgs e) {
    206208      e.Effect = DragDropEffects.None;
    207       if (e.Data.GetDataPresent("IOperator")) {
     209      if(e.Data.GetDataPresent("IOperator")) {
    208210        Point p = operatorsTreeView.PointToClient(new Point(e.X, e.Y));
    209211        TreeNode node = operatorsTreeView.GetNodeAt(p);
    210         if ((node != null) && (node.Tag is IOperatorGroup))
     212        if((node != null) && (node.Tag is IOperatorGroup))
    211213          e.Effect = DragDropEffects.Copy;
    212214      }
     
    214216    private void operatorsTreeView_DragOver(object sender, DragEventArgs e) {
    215217      e.Effect = DragDropEffects.None;
    216       if (e.Data.GetDataPresent("IOperator")) {
     218      if(e.Data.GetDataPresent("IOperator")) {
    217219        Point p = operatorsTreeView.PointToClient(new Point(e.X, e.Y));
    218220        TreeNode node = operatorsTreeView.GetNodeAt(p);
    219         if ((node != null) && (node.Tag is IOperatorGroup))
     221        if((node != null) && (node.Tag is IOperatorGroup))
    220222          e.Effect = DragDropEffects.Copy;
    221223      }
    222224    }
    223225    private void operatorsTreeView_DragDrop(object sender, DragEventArgs e) {
    224       if (e.Effect != DragDropEffects.None) {
    225         if (e.Data.GetDataPresent("IOperator")) {
     226      if(e.Effect != DragDropEffects.None) {
     227        if(e.Data.GetDataPresent("IOperator")) {
    226228          IOperator op = (IOperator)e.Data.GetData("IOperator");
    227229          Point p = operatorsTreeView.PointToClient(new Point(e.X, e.Y));
    228230          TreeNode node = operatorsTreeView.GetNodeAt(p);
    229           if (node != null) {
     231          if(node != null) {
    230232            op = (IOperator)op.Clone();
    231233
    232             while (op.SubOperators.Count > 0)
     234            while(op.SubOperators.Count > 0)
    233235              op.RemoveSubOperator(0);
    234236
  • trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj

    r417 r418  
    6969      <DependentUpon>DatabaseOperatorLibraryView.cs</DependentUpon>
    7070    </Compile>
     71    <Compile Include="OperatorLink.cs" />
    7172    <Compile Include="Result.cs" />
    7273    <Compile Include="IResult.cs" />
     
    100101      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    101102      <Name>HeuristicLab.Core</Name>
     103    </ProjectReference>
     104    <ProjectReference Include="..\HeuristicLab.Operators\HeuristicLab.Operators.csproj">
     105      <Project>{A9983BA2-B3B2-475E-8E2C-62050B71D1C5}</Project>
     106      <Name>HeuristicLab.Operators</Name>
    102107    </ProjectReference>
    103108    <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
  • trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLabCedmaCorePlugin.cs

    r403 r418  
    3030  [Dependency(Dependency = "HeuristicLab.Core")]
    3131  [Dependency(Dependency = "HeuristicLab.CEDMA.DB.Interfaces")]
     32  [Dependency(Dependency = "HeuristicLab.Operators")]
    3233  public class HeuristicLabCedmaCorePlugin : PluginBase {
    3334  }
Note: See TracChangeset for help on using the changeset viewer.