Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/15/10 14:34:18 (15 years ago)
Author:
epitzer
Message:

towards migration of ProgrammableOperator to HL 3.3 (#842)

Location:
trunk/sources/HeuristicLab.Operators.Programmable/3.3
Files:
1 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3

    • Property svn:ignore
      •  

        old new  
         1*.user
         2HeuristicLabOperatorsProgrammablePlugin.cs
        13bin
        24obj
        3 *.user
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/HeuristicLab.Operators.Programmable-3.3.csproj

    r2520 r2799  
    8585  </ItemGroup>
    8686  <ItemGroup>
     87    <None Include="HeuristicLabOperatorsProgrammablePlugin.cs.frame" />
    8788    <Compile Include="HeuristicLabOperatorsProgrammablePlugin.cs" />
    8889    <Compile Include="ProgrammableOperator.cs" />
     
    100101  </ItemGroup>
    101102  <ItemGroup>
     103    <ProjectReference Include="..\..\HeuristicLab.CodeEditor\3.2\HeuristicLab.CodeEditor-3.2.csproj">
     104      <Project>{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}</Project>
     105      <Name>HeuristicLab.CodeEditor-3.2</Name>
     106    </ProjectReference>
     107    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
     108      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
     109      <Name>HeuristicLab.Collections-3.3</Name>
     110    </ProjectReference>
    102111    <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">
    103112      <Project>{E226881D-315F-423D-B419-A766FE0D8685}</Project>
     
    153162set Outdir=$(Outdir)
    154163
    155 call PreBuildEvent.cmd</PreBuildEvent>
     164call PreBuildEvent.cmd
     165SubWCRev "%25ProjectDir%25\" "%25ProjectDir%25\HeuristicLabOperatorsProgrammablePlugin.cs.frame" "%25ProjectDir%25\HeuristicLabOperatorsProgrammablePlugin.cs"</PreBuildEvent>
    156166  </PropertyGroup>
    157167</Project>
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperator.cs

    r2526 r2799  
    3434using HeuristicLab.Data;
    3535using System.Data.Linq;
     36using System.Xml.XPath;
     37using HeuristicLab.PluginInfrastructure;
    3638using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3739
    3840namespace HeuristicLab.Operators.Programmable {
    39   public class ProgrammableOperator : OperatorBase {
     41
     42  public class ProgrammableOperator : Operator {
     43
     44    #region Fields & Properties
     45
    4046    private MethodInfo executeMethod;
    41 
     47    public CompilerErrorCollection CompileErrors { get; private set; }
     48    public string CompilationUnitCode { get; private set; }
     49   
    4250    [Storable]
    43     private string myDescription;
    44     public override string Description {
    45       get { return myDescription; }
    46     }
    47 
    48     [Storable]
    49     private string myCode;   
     51    private string code;
    5052    public string Code {
    51       get { return myCode; }
     53      get { return code; }
    5254      set {
    53         if (value != myCode) {
    54           myCode = value;
     55        if (value != code) {
     56          code = value;
    5557          executeMethod = null;
    5658          OnCodeChanged();
     
    6163    private object syncRoot = new object();
    6264
    63     public ProgrammableOperator() {
    64       myCode = "Result.Data = true;";
    65       myDescription = "An operator that can be programmed for arbitrary needs.";
    66       AddVariableInfo(new VariableInfo("Result", "A computed variable", typeof(BoolData), VariableKind.New | VariableKind.Out));
    67       executeMethod = null;
     65    private static object initLock = new object();
     66    private static Dictionary<string, List<Assembly>> defaultPluginDict;
     67    private static Dictionary<Assembly, bool> defaultAssemblyDict;
     68
     69    public readonly Dictionary<string, List<Assembly>> Plugins;
     70
     71    protected Dictionary<Assembly, bool> Assemblies;
     72
     73    [Storable]
     74    private IEnumerable<string> _persistedAssemblyNames {     
     75      get {       
     76        return Assemblies.Keys.Select(a => a.FullName);
     77      }
     78      set {
     79        var selectedAssemblyNames = new HashSet<string>(value);       
     80        foreach (var a in Assemblies.Keys.ToList()) {
     81          Assemblies[a] = selectedAssemblyNames.Contains(a.FullName);
     82        }     
     83      }
     84    }
     85
     86    public IEnumerable<Assembly> AvailableAssemblies {
     87      get { return Assemblies.Keys; }
     88    }
     89
     90    public IEnumerable<Assembly> SelectedAssemblies {
     91      get { return Assemblies.Where(kvp => kvp.Value).Select(kvp => kvp.Key); }
     92    }
     93
     94    [Storable]
     95    private HashSet<string> namespaces;
     96    public IEnumerable<string> Namespaces {
     97      get { return namespaces; }
     98    }
     99
     100    #endregion
     101
     102    #region Extended Accessors
     103
     104    public void SelectAssembly(Assembly a) {
     105      if (a != null && Assemblies.ContainsKey(a))
     106        Assemblies[a] = true;
     107    }
     108
     109    public void UnselectAssembly(Assembly a) {
     110      if (a != null && Assemblies.ContainsKey(a))
     111        Assemblies[a] = false;
     112    }
     113
     114    public void SelectNamespace(string ns) {
     115      namespaces.Add(ns);
     116    }
     117
     118    public void UnselectNamespace(string ns) {
     119      namespaces.Remove(ns);
    68120    }
    69121
    70122    public void SetDescription(string description) {
    71123      if (description == null)
    72         throw new NullReferenceException("description must not be null");
    73 
    74       if (description != myDescription) {
    75         myDescription = description;
    76         OnDescriptionChanged();
    77       }
    78     }
    79 
    80     public virtual void Compile() {
    81       CodeNamespace ns = new CodeNamespace("HeuristicLab.Operators.Programmable.CustomOperators");
    82       CodeTypeDeclaration typeDecl = new CodeTypeDeclaration("Operator");
    83       typeDecl.IsClass = true;
    84       typeDecl.TypeAttributes = TypeAttributes.Public;
    85 
    86       CodeMemberMethod method = new CodeMemberMethod();
    87       method.Name = "Execute";
    88       method.ReturnType = new CodeTypeReference(typeof(IOperation));
    89       method.Attributes = MemberAttributes.Public | MemberAttributes.Static;
    90       method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IOperator), "op"));
    91       method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IScope), "scope"));
    92       foreach (IVariableInfo info in VariableInfos)
    93         method.Parameters.Add(new CodeParameterDeclarationExpression(info.DataType, info.FormalName));
    94       string code = myCode + "\r\n" + "return null;";
    95       method.Statements.Add(new CodeSnippetStatement(code));
    96       typeDecl.Members.Add(method);
    97 
    98       ns.Types.Add(typeDecl);
    99       ns.Imports.Add(new CodeNamespaceImport("System"));
    100       ns.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));
    101       ns.Imports.Add(new CodeNamespaceImport("System.Text"));
    102       ns.Imports.Add(new CodeNamespaceImport("System.Linq"));
    103       ns.Imports.Add(new CodeNamespaceImport("System.Data.Linq"));
    104       ns.Imports.Add(new CodeNamespaceImport("HeuristicLab.Core"));
    105       foreach (IVariableInfo variableInfo in VariableInfos)
    106         ns.Imports.Add(new CodeNamespaceImport(variableInfo.DataType.Namespace));
    107 
    108       CodeCompileUnit unit = new CodeCompileUnit();
    109       unit.Namespaces.Add(ns);
     124        throw new NullReferenceException("description must not be null");           
     125      Description = description;             
     126    }
     127
     128    public IEnumerable<string> GetAllNamespaces(bool selectedAssembliesOnly) {
     129      var namespaces = new HashSet<string>();
     130      foreach (var a in Assemblies) {
     131        if (!selectedAssembliesOnly || a.Value) {
     132          foreach (var t in a.Key.GetTypes()) {
     133            if (t.IsPublic) {
     134              foreach (string ns in GetNamespaceHierachy(t.Namespace)) {
     135                namespaces.Add(ns);
     136              }
     137            }
     138          }
     139        }
     140      }
     141      return namespaces;
     142    }
     143
     144    private IEnumerable<string> GetNamespaceHierachy(string ns) {
     145      for (int i = ns.Length; i != -1; i = ns.LastIndexOf('.', i - 1)) {
     146        yield return ns.Substring(0, i);
     147      }
     148    }
     149
     150    #endregion
     151
     152    #region Construction & Initialization
     153
     154    public ProgrammableOperator() {     
     155      code = "";
     156      Description = "An operator that can be programmed for arbitrary needs.";
     157      executeMethod = null;
     158      ProgrammableOperator.StaticInitialize();
     159      Assemblies = defaultAssemblyDict;
     160      Plugins = defaultPluginDict;
     161      namespaces = new HashSet<string>(DiscoverNamespaces());
     162    }
     163
     164    private static void StaticInitialize() {
     165      lock (initLock) {
     166        if (defaultPluginDict != null || defaultAssemblyDict != null) return;
     167        defaultAssemblyDict = DiscoverAssemblies();
     168        defaultPluginDict = GroupAssemblies(defaultAssemblyDict.Keys);
     169      }
     170    }
     171
     172    private static Dictionary<string, List<Assembly>> GroupAssemblies(IEnumerable<Assembly> assemblies) {
     173      var plugins = new Dictionary<string, List<Assembly>>();
     174      var locationTable = assemblies.ToDictionary(a => a.Location, a => a);
     175      foreach (var plugin in ApplicationManager.Manager.Plugins) {
     176        var aList = new List<Assembly>();
     177        foreach (var aName in from file in plugin.Files
     178                              where file.Type == PluginFileType.Assembly
     179                              select file.Name) {
     180          Assembly a;
     181          locationTable.TryGetValue(aName, out a);
     182          if (a != null) {
     183            aList.Add(a);
     184            locationTable.Remove(aName);
     185          }
     186        }
     187        plugins[plugin.Name] = aList;
     188      }
     189      plugins["other"] = locationTable.Values.ToList();
     190      return plugins;
     191    }
     192
     193    protected static List<Assembly> defaultAssemblies = new List<Assembly>() {     
     194      typeof(System.Linq.Enumerable).Assembly,  // add reference to version 3.5 of System.dll
     195      typeof(System.Collections.Generic.List<>).Assembly,
     196      typeof(System.Text.StringBuilder).Assembly,     
     197      typeof(System.Data.Linq.DataContext).Assembly,
     198      typeof(HeuristicLab.Core.Item).Assembly,     
     199      typeof(HeuristicLab.Data.IntData).Assembly,           
     200    };
     201
     202    protected static Dictionary<Assembly, bool> DiscoverAssemblies() {
     203      var assemblies = new Dictionary<Assembly, bool>();
     204      foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
     205        try {
     206          if (File.Exists(a.Location)) {
     207            assemblies.Add(a, false);
     208          }
     209        }
     210        catch (NotSupportedException) {
     211          // NotSupportedException is thrown while accessing
     212          // the Location property of the anonymously hosted
     213          // dynamic methods assembly, which is related to
     214          // LINQ queries
     215        }
     216      }
     217      foreach (var a in defaultAssemblies) {
     218        if (assemblies.ContainsKey(a)) {
     219          assemblies[a] = true;
     220        } else {
     221          assemblies.Add(a, true);
     222        }
     223      }
     224      return assemblies;
     225    }
     226
     227    protected static List<string> DiscoverNamespaces() {
     228      return new List<string>() {
     229        "System",
     230        "System.Collections.Generic",
     231        "System.Text",
     232        "System.Linq",
     233        "System.Data.Linq",
     234        "HeuristicLab.Core",
     235        "HeuristicLab.Data",
     236      };
     237    }
     238
     239    #endregion
     240
     241    #region Compilation
     242
     243    private static CSharpCodeProvider codeProvider =
     244      new CSharpCodeProvider(
     245        new Dictionary<string, string>() {
     246          { "CompilerVersion", "v3.5" },  // support C# 3.0 syntax
     247        });
     248
     249    private CompilerResults DoCompile() {
    110250      CompilerParameters parameters = new CompilerParameters();
    111251      parameters.GenerateExecutable = false;
    112252      parameters.GenerateInMemory = true;
    113253      parameters.IncludeDebugInformation = false;
    114       Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
    115       foreach (Assembly loadedAssembly in loadedAssemblies)
    116         parameters.ReferencedAssemblies.Add(loadedAssembly.Location);
    117       parameters.ReferencedAssemblies.Add(typeof(Enumerable).Assembly.Location); // add reference to version 3.5 of System.dll
    118       parameters.ReferencedAssemblies.Add(typeof(DataContext).Assembly.Location); // add reference System.Data.Linq.Dll
    119       CodeDomProvider provider = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });  // support C# 3.0 syntax
    120       CompilerResults results = provider.CompileAssemblyFromDom(parameters, unit);
    121 
     254      parameters.ReferencedAssemblies.AddRange(SelectedAssemblies.Select(a => a.Location).ToArray());
     255      var unit = CreateCompilationUnit();
     256      var writer = new StringWriter();
     257      codeProvider.GenerateCodeFromCompileUnit(
     258        unit,
     259        writer,
     260        new CodeGeneratorOptions() {
     261          BracingStyle = "C",
     262          ElseOnClosing = true,
     263          IndentString = "  ",
     264        });
     265      CompilationUnitCode = writer.ToString();
     266      return codeProvider.CompileAssemblyFromDom(parameters, unit);
     267    }
     268
     269    public virtual void Compile() {
     270      var results = DoCompile();
    122271      executeMethod = null;
    123272      if (results.Errors.HasErrors) {
    124         StringWriter writer = new StringWriter();
    125         CodeGeneratorOptions options = new CodeGeneratorOptions();
    126         options.BlankLinesBetweenMembers = false;
    127         options.ElseOnClosing = true;
    128         options.IndentString = "  ";
    129         provider.GenerateCodeFromCompileUnit(unit, writer, options);
    130         writer.Flush();
    131         string[] source = writer.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.None);
    132         StringBuilder builder = new StringBuilder();
    133         for (int i = 0; i < source.Length; i++)
    134           builder.AppendLine((i + 3).ToString("###") + "     " + source[i]);
    135         builder.AppendLine();
    136         builder.AppendLine();
    137         builder.AppendLine();
     273        CompileErrors = results.Errors;
     274        StringBuilder sb = new StringBuilder();
    138275        foreach (CompilerError error in results.Errors) {
    139           builder.Append("Line " + error.Line.ToString());
    140           builder.Append(", Column " + error.Column.ToString());
    141           builder.AppendLine(": " + error.ErrorText);
    142         }
    143         throw new Exception("Compile Errors:\n\n" + builder.ToString());
     276          sb.Append(error.Line).Append(':')
     277            .Append(error.Column).Append(": ")
     278            .AppendLine(error.ErrorText);
     279        }
     280        throw new Exception(string.Format(
     281          "Compilation of \"{0}\" failed:{1}{2}",
     282          Name, Environment.NewLine,
     283          sb.ToString()));
    144284      } else {
     285        CompileErrors = null;
    145286        Assembly assembly = results.CompiledAssembly;
    146287        Type[] types = assembly.GetTypes();
     
    149290    }
    150291
    151     public override IItem Clone(ICloner cloner) {
    152       ProgrammableOperator clone = (ProgrammableOperator)base.Clone(cloner);
    153       clone.myDescription = Description;
    154       clone.myCode = Code;
    155       clone.executeMethod = executeMethod;
    156       return clone;
    157     }
    158 
    159     public override IOperation Apply(IScope scope) {
     292    private CodeCompileUnit CreateCompilationUnit() {
     293      CodeNamespace ns = new CodeNamespace("HeuristicLab.Operators.Programmable.CustomOperators");
     294      ns.Types.Add(CreateType());
     295      ns.Imports.AddRange(
     296        GetSelectedAndValidNamespaces()
     297        .Select(n => new CodeNamespaceImport(n))
     298        .ToArray());
     299      CodeCompileUnit unit = new CodeCompileUnit();
     300      unit.Namespaces.Add(ns);
     301      return unit;
     302    }
     303
     304    public IEnumerable<string> GetSelectedAndValidNamespaces() {
     305      var possibleNamespaces = new HashSet<string>(GetAllNamespaces(true));
     306      foreach (var ns in Namespaces)
     307        if (possibleNamespaces.Contains(ns))
     308          yield return ns;
     309    }
     310
     311    public static readonly Regex SafeTypeNameCharRegex = new Regex("[_a-zA-Z0-9]+");
     312    public static readonly Regex SafeTypeNameRegex = new Regex("[_a-zA-Z][_a-zA-Z0-9]*");
     313
     314    public string CompiledTypeName {
     315      get {
     316        var sb = new StringBuilder();
     317        foreach (string s in SafeTypeNameCharRegex.Matches(Name).Cast<Match>().Select(m => m.Value)) {
     318          sb.Append(s);
     319        }
     320        return SafeTypeNameRegex.Match(sb.ToString()).Value;
     321      }
     322    }
     323
     324    private CodeTypeDeclaration CreateType() {
     325      CodeTypeDeclaration typeDecl = new CodeTypeDeclaration(CompiledTypeName) {
     326        IsClass = true,
     327        TypeAttributes = TypeAttributes.Public,
     328      };
     329      typeDecl.Members.Add(CreateMethod());
     330      return typeDecl;
     331    }
     332
     333    public string Signature {
     334      get {
     335        var sb = new StringBuilder()
     336        .Append("public static IOperation Execute(IOperator op, IScope scope");       
     337        foreach (IParameter param in Parameters) {
     338          sb.Append(String.Format(", {0} {1}", param.DataType.Name, param.Name));
     339        }       
     340        return sb.Append(")").ToString();
     341      }
     342    }
     343
     344    private static Regex lineSplitter = new Regex(@"\r\n|\r|\n");
     345
     346    private CodeMemberMethod CreateMethod() {
     347      CodeMemberMethod method = new CodeMemberMethod();
     348      method.Name = "Execute";
     349      method.ReturnType = new CodeTypeReference(typeof(HeuristicLab.Core.IExecutionSequence));
     350      method.Attributes = MemberAttributes.Public | MemberAttributes.Static;
     351      method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IOperator), "op"));
     352//      method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IScope), "scope"));
     353      foreach (var param in Parameters)
     354        method.Parameters.Add(new CodeParameterDeclarationExpression(param.DataType, param.Name));
     355      string[] codeLines = lineSplitter.Split(code);
     356      for (int i = 0; i < codeLines.Length; i++) {
     357        codeLines[i] = string.Format("#line {0} \"ProgrammableOperator\"{1}{2}", i + 1, "\r\n", codeLines[i]);
     358      }
     359      method.Statements.Add(new CodeSnippetStatement(
     360        string.Join("\r\n", codeLines) +
     361        "\r\nreturn null;"));
     362      return method;
     363    }
     364
     365    #endregion
     366
     367    #region HeuristicLab interfaces
     368   
     369    public override IExecutionSequence Apply() {
    160370      lock (syncRoot) {
    161371        if (executeMethod == null) {
     
    164374      }
    165375
    166       // collect parameters
    167       object[] parameters = new object[VariableInfos.Count + 2];
    168       parameters[0] = this;
    169       parameters[1] = scope;
    170       int i = 2;
    171       foreach (IVariableInfo info in VariableInfos) {
    172         if ((info.Kind & VariableKind.New) == VariableKind.New) {
    173           parameters[i] = GetVariableValue(info.FormalName, scope, false, false);
    174           if (parameters[i] == null) {
    175             IItem value = (IItem)Activator.CreateInstance(info.DataType);
    176             if (info.Local) {
    177               AddVariable(new Variable(info.ActualName, value));
    178             } else {
    179               scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), value));
    180             }
    181             parameters[i] = value;
    182           }
    183         } else
    184           parameters[i] = GetVariableValue(info.FormalName, scope, true);
    185         i++;
    186       }
    187 
    188       return (IOperation)executeMethod.Invoke(null, parameters);
    189     }
    190 
    191     public event EventHandler DescriptionChanged;
    192     protected virtual void OnDescriptionChanged() {
    193       if (DescriptionChanged != null)
    194         DescriptionChanged(this, new EventArgs());
    195     }
     376      var parameters = new List<object>() { this };     
     377      parameters.AddRange(Parameters.Select(p => (object)p.ActualValue));
     378      return (IExecutionSequence)executeMethod.Invoke(null, parameters.ToArray());
     379    }
     380   
    196381    public event EventHandler CodeChanged;
    197382    protected virtual void OnCodeChanged() {
     
    199384        CodeChanged(this, new EventArgs());
    200385    }
     386
     387    #endregion
     388
     389    #region Cloning       
     390
     391    public override IDeepCloneable Clone(Cloner cloner) {
     392      ProgrammableOperator clone = (ProgrammableOperator)base.Clone(cloner);
     393      clone.Description = Description;
     394      clone.code = Code;
     395      clone.executeMethod = executeMethod;
     396      clone.Assemblies = Assemblies.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
     397      clone.namespaces = namespaces;
     398      clone.CompilationUnitCode = CompilationUnitCode;
     399      clone.CompileErrors = CompileErrors;
     400      return clone;
     401    }
     402   
     403    #endregion
     404   
    201405  }
    202406}
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperatorView.Designer.cs

    r2524 r2799  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProgrammableOperatorView));
     47      System.Windows.Forms.SplitContainer splitContainer1;
     48      System.Windows.Forms.SplitContainer splitContainer2;
     49      System.Windows.Forms.GroupBox groupBox1;
     50      System.Windows.Forms.GroupBox groupBox2;
     51      this.assembliesTreeView = new System.Windows.Forms.TreeView();
     52      this.groupBox3 = new System.Windows.Forms.GroupBox();
     53      this.showCodeButton = new System.Windows.Forms.Button();
     54      this.codeEditor = new HeuristicLab.CodeEditor.CodeEditor();
     55      this.compileButton = new System.Windows.Forms.Button();
    4856      this.tabControl = new System.Windows.Forms.TabControl();
    4957      this.codeTabPage = new System.Windows.Forms.TabPage();
    50       this.infoTextBox = new System.Windows.Forms.TextBox();
    51       this.compileButton = new System.Windows.Forms.Button();
    52       this.codeTextBox = new System.Windows.Forms.TextBox();
    5358      this.variableInfosTabPage = new System.Windows.Forms.TabPage();
    5459      this.removeVariableInfoButton = new System.Windows.Forms.Button();
    5560      this.addVariableInfoButton = new System.Windows.Forms.Button();
    56       this.operatorBaseVariableInfosView = new HeuristicLab.Core.Views.OperatorBaseVariableInfosView();
     61      //this.operatorBaseVariableInfosView = new HeuristicLab.Core.OperatorBaseVariableInfosView();
    5762      this.variablesTabPage = new System.Windows.Forms.TabPage();
    58       this.operatorBaseVariablesView = new HeuristicLab.Core.Views.OperatorBaseVariablesView();
     63      //this.operatorBaseVariablesView = new HeuristicLab.Core.OperatorBaseVariablesView();
     64      this.constraintsTabPage = new System.Windows.Forms.TabPage();
     65      //this.constrainedItemBaseView = new HeuristicLab.Core.ConstrainedItemBaseView();
    5966      this.descriptionTabPage = new System.Windows.Forms.TabPage();
    60       this.descriptionTextBox = new System.Windows.Forms.TextBox();
     67      //this.descriptionTextBox = new System.Windows.Forms.TextBox();
     68      this.namespacesTreeView = new System.Windows.Forms.TreeView();
     69      splitContainer1 = new System.Windows.Forms.SplitContainer();
     70      splitContainer2 = new System.Windows.Forms.SplitContainer();
     71      groupBox1 = new System.Windows.Forms.GroupBox();
     72      groupBox2 = new System.Windows.Forms.GroupBox();
     73      splitContainer1.Panel1.SuspendLayout();
     74      splitContainer1.Panel2.SuspendLayout();
     75      splitContainer1.SuspendLayout();
     76      splitContainer2.Panel1.SuspendLayout();
     77      splitContainer2.Panel2.SuspendLayout();
     78      splitContainer2.SuspendLayout();
     79      groupBox1.SuspendLayout();
     80      groupBox2.SuspendLayout();
     81      this.groupBox3.SuspendLayout();
    6182      this.tabControl.SuspendLayout();
    6283      this.codeTabPage.SuspendLayout();
    6384      this.variableInfosTabPage.SuspendLayout();
    6485      this.variablesTabPage.SuspendLayout();
     86      this.constraintsTabPage.SuspendLayout();
    6587      this.descriptionTabPage.SuspendLayout();
    6688      this.SuspendLayout();
     89      //
     90      // splitContainer1
     91      //
     92      splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
     93      splitContainer1.Location = new System.Drawing.Point(3, 3);
     94      splitContainer1.Name = "splitContainer1";
     95      splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
     96      //
     97      // splitContainer1.Panel1
     98      //
     99      splitContainer1.Panel1.Controls.Add(splitContainer2);
     100      //
     101      // splitContainer1.Panel2
     102      //
     103      splitContainer1.Panel2.Controls.Add(this.groupBox3);
     104      splitContainer1.Size = new System.Drawing.Size(693, 457);
     105      splitContainer1.SplitterDistance = 85;
     106      splitContainer1.TabIndex = 6;
     107      //
     108      // splitContainer2
     109      //
     110      splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
     111      splitContainer2.Location = new System.Drawing.Point(0, 0);
     112      splitContainer2.Name = "splitContainer2";
     113      //
     114      // splitContainer2.Panel1
     115      //
     116      splitContainer2.Panel1.Controls.Add(groupBox1);
     117      //
     118      // splitContainer2.Panel2
     119      //
     120      splitContainer2.Panel2.Controls.Add(groupBox2);
     121      splitContainer2.Size = new System.Drawing.Size(693, 85);
     122      splitContainer2.SplitterDistance = 340;
     123      splitContainer2.TabIndex = 2;
     124      //
     125      // groupBox1
     126      //
     127      groupBox1.Controls.Add(this.assembliesTreeView);
     128      groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
     129      groupBox1.Location = new System.Drawing.Point(0, 0);
     130      groupBox1.Name = "groupBox1";
     131      groupBox1.Size = new System.Drawing.Size(340, 85);
     132      groupBox1.TabIndex = 0;
     133      groupBox1.TabStop = false;
     134      groupBox1.Text = "Assemblies";
     135      //
     136      // assembliesTreeView
     137      //
     138      this.assembliesTreeView.CheckBoxes = true;
     139      this.assembliesTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
     140      this.assembliesTreeView.Location = new System.Drawing.Point(3, 16);
     141      this.assembliesTreeView.Name = "assembliesTreeView";
     142      this.assembliesTreeView.Size = new System.Drawing.Size(334, 66);
     143      this.assembliesTreeView.TabIndex = 1;
     144      this.assembliesTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.assembliesTreeView_AfterCheck);
     145      //
     146      // groupBox2
     147      //
     148      groupBox2.Controls.Add(this.namespacesTreeView);
     149      groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
     150      groupBox2.Location = new System.Drawing.Point(0, 0);
     151      groupBox2.Name = "groupBox2";
     152      groupBox2.Size = new System.Drawing.Size(349, 85);
     153      groupBox2.TabIndex = 0;
     154      groupBox2.TabStop = false;
     155      groupBox2.Text = "Namespaces";
     156      //
     157      // namespacesTreeView
     158      //
     159      this.namespacesTreeView.CheckBoxes = true;
     160      this.namespacesTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
     161      this.namespacesTreeView.Location = new System.Drawing.Point(3, 16);
     162      this.namespacesTreeView.Name = "namespacesTreeView";
     163      this.namespacesTreeView.PathSeparator = ".";
     164      this.namespacesTreeView.Size = new System.Drawing.Size(343, 66);
     165      this.namespacesTreeView.TabIndex = 2;
     166      this.namespacesTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.namespacesTreeView_AfterCheck);
     167      //
     168      // groupBox3
     169      //
     170      this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     171                  | System.Windows.Forms.AnchorStyles.Left)
     172                  | System.Windows.Forms.AnchorStyles.Right)));
     173      this.groupBox3.Controls.Add(this.showCodeButton);
     174      this.groupBox3.Controls.Add(this.codeEditor);
     175      this.groupBox3.Controls.Add(this.compileButton);
     176      this.groupBox3.Location = new System.Drawing.Point(3, 2);
     177      this.groupBox3.Name = "groupBox3";
     178      this.groupBox3.Size = new System.Drawing.Size(687, 363);
     179      this.groupBox3.TabIndex = 7;
     180      this.groupBox3.TabStop = false;
     181      this.groupBox3.Text = "Code";
     182      //
     183      // showCodeButton
     184      //
     185      this.showCodeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     186      this.showCodeButton.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
     187      this.showCodeButton.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ControlDark;
     188      this.showCodeButton.FlatAppearance.MouseOverBackColor = System.Drawing.SystemColors.GradientActiveCaption;
     189      this.showCodeButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
     190      this.showCodeButton.Location = new System.Drawing.Point(467, 333);
     191      this.showCodeButton.Name = "showCodeButton";
     192      this.showCodeButton.Size = new System.Drawing.Size(133, 23);
     193      this.showCodeButton.TabIndex = 4;
     194      this.showCodeButton.Text = "Show Generated Code";
     195      this.showCodeButton.UseVisualStyleBackColor = true;
     196      this.showCodeButton.Click += new System.EventHandler(this.showCodeButton_Click);
     197      //
     198      // compileButton
     199      //
     200      this.compileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     201      this.compileButton.Location = new System.Drawing.Point(606, 334);
     202      this.compileButton.Name = "compileButton";
     203      this.compileButton.Size = new System.Drawing.Size(75, 23);
     204      this.compileButton.TabIndex = 3;
     205      this.compileButton.Text = "&Compile";
     206      this.compileButton.UseVisualStyleBackColor = true;
     207      this.compileButton.Click += new System.EventHandler(this.compileButton_Click);
    67208      //
    68209      // tabControl
     
    71212      this.tabControl.Controls.Add(this.variableInfosTabPage);
    72213      this.tabControl.Controls.Add(this.variablesTabPage);
     214      this.tabControl.Controls.Add(this.constraintsTabPage);
    73215      this.tabControl.Controls.Add(this.descriptionTabPage);
    74216      this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
     
    76218      this.tabControl.Name = "tabControl";
    77219      this.tabControl.SelectedIndex = 0;
    78       this.tabControl.Size = new System.Drawing.Size(435, 351);
     220      this.tabControl.Size = new System.Drawing.Size(707, 489);
    79221      this.tabControl.TabIndex = 0;
    80222      //
    81223      // codeTabPage
    82224      //
    83       this.codeTabPage.Controls.Add(this.infoTextBox);
    84       this.codeTabPage.Controls.Add(this.compileButton);
    85       this.codeTabPage.Controls.Add(this.codeTextBox);
     225      this.codeTabPage.Controls.Add(splitContainer1);
    86226      this.codeTabPage.Location = new System.Drawing.Point(4, 22);
    87227      this.codeTabPage.Name = "codeTabPage";
    88228      this.codeTabPage.Padding = new System.Windows.Forms.Padding(3);
    89       this.codeTabPage.Size = new System.Drawing.Size(427, 325);
     229      this.codeTabPage.Size = new System.Drawing.Size(699, 463);
    90230      this.codeTabPage.TabIndex = 5;
    91231      this.codeTabPage.Text = "Code";
    92232      this.codeTabPage.UseVisualStyleBackColor = true;
    93233      //
    94       // infoTextBox
    95       //
    96       this.infoTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
    97                   | System.Windows.Forms.AnchorStyles.Right)));
    98       this.infoTextBox.BackColor = System.Drawing.SystemColors.ControlLight;
    99       this.infoTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    100       this.infoTextBox.Location = new System.Drawing.Point(6, 253);
    101       this.infoTextBox.Multiline = true;
    102       this.infoTextBox.Name = "infoTextBox";
    103       this.infoTextBox.ReadOnly = true;
    104       this.infoTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
    105       this.infoTextBox.Size = new System.Drawing.Size(334, 66);
    106       this.infoTextBox.TabIndex = 2;
    107       this.infoTextBox.Text = resources.GetString("infoTextBox.Text");
    108       //
    109       // compileButton
    110       //
    111       this.compileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    112       this.compileButton.Location = new System.Drawing.Point(346, 296);
    113       this.compileButton.Name = "compileButton";
    114       this.compileButton.Size = new System.Drawing.Size(75, 23);
    115       this.compileButton.TabIndex = 1;
    116       this.compileButton.Text = "&Compile";
    117       this.compileButton.UseVisualStyleBackColor = true;
    118       this.compileButton.Click += new System.EventHandler(this.compileButton_Click);
    119       //
    120       // codeTextBox
    121       //
    122       this.codeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    123                   | System.Windows.Forms.AnchorStyles.Left)
    124                   | System.Windows.Forms.AnchorStyles.Right)));
    125       this.codeTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    126       this.codeTextBox.Location = new System.Drawing.Point(3, 3);
    127       this.codeTextBox.Multiline = true;
    128       this.codeTextBox.Name = "codeTextBox";
    129       this.codeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
    130       this.codeTextBox.Size = new System.Drawing.Size(421, 244);
    131       this.codeTextBox.TabIndex = 0;
    132       this.codeTextBox.Validated += new System.EventHandler(this.codeTextBox_Validated);
    133       //
    134234      // variableInfosTabPage
    135235      //
    136236      this.variableInfosTabPage.Controls.Add(this.removeVariableInfoButton);
    137237      this.variableInfosTabPage.Controls.Add(this.addVariableInfoButton);
    138       this.variableInfosTabPage.Controls.Add(this.operatorBaseVariableInfosView);
     238      //this.variableInfosTabPage.Controls.Add(this.operatorBaseVariableInfosView);
    139239      this.variableInfosTabPage.Location = new System.Drawing.Point(4, 22);
    140240      this.variableInfosTabPage.Name = "variableInfosTabPage";
    141241      this.variableInfosTabPage.Padding = new System.Windows.Forms.Padding(3);
    142       this.variableInfosTabPage.Size = new System.Drawing.Size(427, 325);
     242      this.variableInfosTabPage.Size = new System.Drawing.Size(699, 463);
    143243      this.variableInfosTabPage.TabIndex = 1;
    144244      this.variableInfosTabPage.Text = "Variable Infos";
     
    149249      this.removeVariableInfoButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    150250      this.removeVariableInfoButton.Enabled = false;
    151       this.removeVariableInfoButton.Location = new System.Drawing.Point(84, 299);
     251      this.removeVariableInfoButton.Location = new System.Drawing.Point(87, 434);
    152252      this.removeVariableInfoButton.Name = "removeVariableInfoButton";
    153253      this.removeVariableInfoButton.Size = new System.Drawing.Size(75, 23);
     
    155255      this.removeVariableInfoButton.Text = "&Remove";
    156256      this.removeVariableInfoButton.UseVisualStyleBackColor = true;
    157       this.removeVariableInfoButton.Click += new System.EventHandler(this.removeVariableInfoButton_Click);
     257      //this.removeVariableInfoButton.Click += new System.EventHandler(this.removeVariableInfoButton_Click);
    158258      //
    159259      // addVariableInfoButton
    160260      //
    161261      this.addVariableInfoButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    162       this.addVariableInfoButton.Location = new System.Drawing.Point(3, 299);
     262      this.addVariableInfoButton.Location = new System.Drawing.Point(6, 434);
    163263      this.addVariableInfoButton.Name = "addVariableInfoButton";
    164264      this.addVariableInfoButton.Size = new System.Drawing.Size(75, 23);
     
    166266      this.addVariableInfoButton.Text = "&Add...";
    167267      this.addVariableInfoButton.UseVisualStyleBackColor = true;
    168       this.addVariableInfoButton.Click += new System.EventHandler(this.addVariableInfoButton_Click);
     268      ///this.addVariableInfoButton.Click += new System.EventHandler(this.addVariableInfoButton_Click);
    169269      //
    170270      // operatorBaseVariableInfosView
    171271      //
    172       this.operatorBaseVariableInfosView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     272      /*this.operatorBaseVariableInfosView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    173273                  | System.Windows.Forms.AnchorStyles.Left)
    174274                  | System.Windows.Forms.AnchorStyles.Right)));
     
    177277      this.operatorBaseVariableInfosView.Name = "operatorBaseVariableInfosView";
    178278      this.operatorBaseVariableInfosView.Operator = null;
    179       this.operatorBaseVariableInfosView.Size = new System.Drawing.Size(421, 290);
     279      this.operatorBaseVariableInfosView.Size = new System.Drawing.Size(690, 425);
    180280      this.operatorBaseVariableInfosView.TabIndex = 0;
    181281      this.operatorBaseVariableInfosView.SelectedVariableInfosChanged += new System.EventHandler(this.operatorBaseVariableInfosView_SelectedVariableInfosChanged);
     282       */
    182283      //
    183284      // variablesTabPage
    184285      //
    185       this.variablesTabPage.Controls.Add(this.operatorBaseVariablesView);
     286      //this.variablesTabPage.Controls.Add(this.operatorBaseVariablesView);
    186287      this.variablesTabPage.Location = new System.Drawing.Point(4, 22);
    187288      this.variablesTabPage.Name = "variablesTabPage";
    188289      this.variablesTabPage.Padding = new System.Windows.Forms.Padding(3);
    189       this.variablesTabPage.Size = new System.Drawing.Size(427, 325);
     290      this.variablesTabPage.Size = new System.Drawing.Size(699, 463);
    190291      this.variablesTabPage.TabIndex = 2;
    191292      this.variablesTabPage.Text = "Local Variables";
     
    194295      // operatorBaseVariablesView
    195296      //
    196       this.operatorBaseVariablesView.Caption = "Operator";
     297      /*this.operatorBaseVariablesView.Caption = "Operator";
    197298      this.operatorBaseVariablesView.Dock = System.Windows.Forms.DockStyle.Fill;
    198299      this.operatorBaseVariablesView.Location = new System.Drawing.Point(3, 3);
    199300      this.operatorBaseVariablesView.Name = "operatorBaseVariablesView";
    200301      this.operatorBaseVariablesView.Operator = null;
    201       this.operatorBaseVariablesView.Size = new System.Drawing.Size(421, 319);
    202       this.operatorBaseVariablesView.TabIndex = 0;
     302      this.operatorBaseVariablesView.Size = new System.Drawing.Size(693, 457);
     303      this.operatorBaseVariablesView.TabIndex = 0; */
     304      //
     305      // constraintsTabPage
     306      //
     307      //this.constraintsTabPage.Controls.Add(this.constrainedItemBaseView);
     308      this.constraintsTabPage.Location = new System.Drawing.Point(4, 22);
     309      this.constraintsTabPage.Name = "constraintsTabPage";
     310      this.constraintsTabPage.Padding = new System.Windows.Forms.Padding(3);
     311      this.constraintsTabPage.Size = new System.Drawing.Size(699, 463);
     312      this.constraintsTabPage.TabIndex = 3;
     313      this.constraintsTabPage.Text = "Constraints";
     314      this.constraintsTabPage.UseVisualStyleBackColor = true;
     315      //
     316      // constrainedItemBaseView
     317      //
     318      /*this.constrainedItemBaseView.Caption = "Constrained Item";
     319      this.constrainedItemBaseView.ConstrainedItem = null;
     320      this.constrainedItemBaseView.Dock = System.Windows.Forms.DockStyle.Fill;
     321      this.constrainedItemBaseView.Location = new System.Drawing.Point(3, 3);
     322      this.constrainedItemBaseView.Name = "constrainedItemBaseView";
     323      this.constrainedItemBaseView.Size = new System.Drawing.Size(693, 457);
     324      this.constrainedItemBaseView.TabIndex = 0; */
    203325      //
    204326      // descriptionTabPage
     
    208330      this.descriptionTabPage.Name = "descriptionTabPage";
    209331      this.descriptionTabPage.Padding = new System.Windows.Forms.Padding(3);
    210       this.descriptionTabPage.Size = new System.Drawing.Size(427, 325);
     332      this.descriptionTabPage.Size = new System.Drawing.Size(699, 463);
    211333      this.descriptionTabPage.TabIndex = 4;
    212334      this.descriptionTabPage.Text = "Description";
     
    215337      // descriptionTextBox
    216338      //
    217       this.descriptionTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
     339      /*this.descriptionTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
    218340      this.descriptionTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    219341      this.descriptionTextBox.Location = new System.Drawing.Point(3, 3);
     
    221343      this.descriptionTextBox.Name = "descriptionTextBox";
    222344      this.descriptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
    223       this.descriptionTextBox.Size = new System.Drawing.Size(421, 319);
     345      this.descriptionTextBox.Size = new System.Drawing.Size(693, 457);
    224346      this.descriptionTextBox.TabIndex = 0;
    225       this.descriptionTextBox.Validated += new System.EventHandler(this.descriptionTextBox_Validated);
     347      this.descriptionTextBox.Validated += new System.EventHandler(this.descriptionTextBox_Validated); */
     348      //
     349      // codeEditor
     350      //
     351      this.codeEditor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     352                  | System.Windows.Forms.AnchorStyles.Left)
     353                  | System.Windows.Forms.AnchorStyles.Right)));
     354      this.codeEditor.Location = new System.Drawing.Point(6, 19);
     355      this.codeEditor.Name = "codeEditor";
     356      this.codeEditor.Prefix = "using System;\r\nusing HeuristicLab.Common.Resources;\r\n\r\npublic class Operator {\r\n " +
     357          " public static void Apply(int arg) {";
     358      this.codeEditor.Size = new System.Drawing.Size(675, 309);
     359      this.codeEditor.Suffix = "\n    return null;\n  }\n}";
     360      this.codeEditor.TabIndex = 0;
     361      this.codeEditor.UserCode = "\n\n\n";
     362      this.codeEditor.TextEditorValidated += new System.EventHandler(this.codeEditor_Validated);
    226363      //
    227364      // ProgrammableOperatorView
     
    231368      this.Controls.Add(this.tabControl);
    232369      this.Name = "ProgrammableOperatorView";
    233       this.Size = new System.Drawing.Size(435, 351);
     370      this.Size = new System.Drawing.Size(707, 489);
     371      splitContainer1.Panel1.ResumeLayout(false);
     372      splitContainer1.Panel2.ResumeLayout(false);
     373      splitContainer1.ResumeLayout(false);
     374      splitContainer2.Panel1.ResumeLayout(false);
     375      splitContainer2.Panel2.ResumeLayout(false);
     376      splitContainer2.ResumeLayout(false);
     377      groupBox1.ResumeLayout(false);
     378      groupBox2.ResumeLayout(false);
     379      this.groupBox3.ResumeLayout(false);
    234380      this.tabControl.ResumeLayout(false);
    235381      this.codeTabPage.ResumeLayout(false);
    236       this.codeTabPage.PerformLayout();
    237382      this.variableInfosTabPage.ResumeLayout(false);
    238383      this.variablesTabPage.ResumeLayout(false);
     384      this.constraintsTabPage.ResumeLayout(false);
    239385      this.descriptionTabPage.ResumeLayout(false);
    240386      this.descriptionTabPage.PerformLayout();
     
    247393    private System.Windows.Forms.TabControl tabControl;
    248394    private System.Windows.Forms.TabPage codeTabPage;
    249     private System.Windows.Forms.TextBox codeTextBox;
    250395    private System.Windows.Forms.TabPage variableInfosTabPage;
    251     private HeuristicLab.Core.Views.OperatorBaseVariableInfosView operatorBaseVariableInfosView;
     396    //private HeuristicLab.Core.OperatorBaseVariableInfosView operatorBaseVariableInfosView;
    252397    private System.Windows.Forms.TabPage variablesTabPage;
    253     private HeuristicLab.Core.Views.OperatorBaseVariablesView operatorBaseVariablesView;
     398    //private HeuristicLab.Core.OperatorBaseVariablesView operatorBaseVariablesView;
     399    private System.Windows.Forms.TabPage constraintsTabPage;
     400    //private HeuristicLab.Core.ConstrainedItemBaseView constrainedItemBaseView;
    254401    private System.Windows.Forms.TabPage descriptionTabPage;
    255402    private System.Windows.Forms.TextBox descriptionTextBox;
    256     private System.Windows.Forms.Button compileButton;
    257403    private System.Windows.Forms.Button removeVariableInfoButton;
    258404    private System.Windows.Forms.Button addVariableInfoButton;
    259     private System.Windows.Forms.TextBox infoTextBox;
     405    private System.Windows.Forms.TreeView assembliesTreeView;
     406    private System.Windows.Forms.TreeView namespacesTreeView;
     407    private System.Windows.Forms.GroupBox groupBox3;
     408    private HeuristicLab.CodeEditor.CodeEditor codeEditor;
     409    private System.Windows.Forms.Button compileButton;
     410    private System.Windows.Forms.Button showCodeButton;
     411
    260412
    261413  }
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperatorView.cs

    r2546 r2799  
    2626using System.Data;
    2727using System.Text;
     28using System.Linq;
    2829using System.Windows.Forms;
    2930using HeuristicLab.Core;
    3031using HeuristicLab.Operators;
     32using System.CodeDom.Compiler;
     33using System.Reflection;
     34using HeuristicLab.CodeEditor;
    3135using HeuristicLab.Core.Views;
    32 using HeuristicLab.MainForm;
    3336
    3437namespace HeuristicLab.Operators.Programmable {
    35   [Content(typeof(ProgrammableOperator), true)]
    36   public partial class ProgrammableOperatorView : ItemViewBase {
     38
     39  public partial class ProgrammableOperatorView : NamedItemView {
     40
    3741    public ProgrammableOperator ProgrammableOperator {
    38       get { return (ProgrammableOperator)Item; }
    39       set { base.Item = value; }
     42      get { return (ProgrammableOperator)base.Content; }
     43      set { base.Content = (NamedItem)value; }
    4044    }
    4145
     
    4347      InitializeComponent();
    4448    }
     49
    4550    public ProgrammableOperatorView(ProgrammableOperator programmableOperator)
    4651      : this() {
     
    4853    }
    4954
    50     protected override void RemoveItemEvents() {
    51       operatorBaseVariableInfosView.Operator = null;
    52       operatorBaseVariablesView.Operator = null;
     55    protected override void DeregisterContentEvents() {     
     56      //operatorBaseVariableInfosView.Operator = null;
     57      //operatorBaseVariablesView.Operator = null;
     58      //constrainedItemBaseView.ConstrainedItem = null;
    5359      ProgrammableOperator.CodeChanged -= new EventHandler(ProgrammableOperator_CodeChanged);
    5460      ProgrammableOperator.DescriptionChanged -= new EventHandler(ProgrammableOperator_DescriptionChanged);
    55       base.RemoveItemEvents();
    56     }
    57 
    58     protected override void AddItemEvents() {
    59       base.AddItemEvents();
    60       operatorBaseVariableInfosView.Operator = ProgrammableOperator;
    61       operatorBaseVariablesView.Operator = ProgrammableOperator;
     61      base.DeregisterContentEvents();           
     62    }
     63
     64
     65    protected override void RegisterContentEvents() {
     66      base.RegisterContentEvents();
     67      //operatorBaseVariableInfosView.Operator = ProgrammableOperator;
     68      //operatorBaseVariablesView.Operator = ProgrammableOperator;
     69      //constrainedItemBaseView.ConstrainedItem = ProgrammableOperator;
    6270      ProgrammableOperator.CodeChanged += new EventHandler(ProgrammableOperator_CodeChanged);
    6371      ProgrammableOperator.DescriptionChanged += new EventHandler(ProgrammableOperator_DescriptionChanged);
    6472    }
    6573
    66     protected override void UpdateControls() {
    67       base.UpdateControls();
     74
     75    protected override void OnContentChanged() {
     76      base.OnContentChanged();   
    6877      if (ProgrammableOperator == null) {
    69         codeTextBox.Text = "";
    70         codeTextBox.Enabled = false;
     78        codeEditor.Text = "";
     79        codeEditor.Enabled = false;
    7180        addVariableInfoButton.Enabled = false;
    7281        removeVariableInfoButton.Enabled = false;
    7382        descriptionTextBox.Text = "";
    7483        descriptionTextBox.Enabled = false;
    75       } else {
    76         codeTextBox.Text = ProgrammableOperator.Code;
    77         codeTextBox.Enabled = true;
     84        codeEditor.Prefix = @"using System
     85
     86public class Operator {
     87  public static IOperation Execute(IOperator op, IScope scope, parameters ...) {
     88";
     89        codeEditor.Suffix = @"
     90    return null;
     91  }
     92}";
     93        assembliesTreeView.Nodes.Clear();
     94      } else {
     95        codeEditor.Enabled = true;
    7896        addVariableInfoButton.Enabled = true;
    79         removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
     97        //removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
    8098        descriptionTextBox.Text = ProgrammableOperator.Description;
    8199        descriptionTextBox.Enabled = true;
    82       }
    83     }
    84 
     100        codeEditor.Prefix = GetGeneratedPrefix();
     101        codeEditor.Suffix = @"
     102    return null;
     103  }
     104}";
     105        codeEditor.UserCode = ProgrammableOperator.Code;
     106        if (codeEditor.UserCode == "")
     107          codeEditor.UserCode = "\n\n\n";
     108        InitializeAssemblyList();
     109        InitializeNamespacesList();
     110        foreach (var a in ProgrammableOperator.SelectedAssemblies) {
     111          codeEditor.AddAssembly(a);
     112        }
     113        codeEditor.ScrollAfterPrefix();
     114      }
     115    }
     116
     117
     118    private string GetGeneratedPrefix() {
     119      StringBuilder prefix = new StringBuilder();
     120      foreach (var ns in ProgrammableOperator.GetSelectedAndValidNamespaces()) {
     121        prefix.Append("using ").Append(ns).AppendLine(";");
     122      }
     123      prefix.AppendLine();
     124      prefix.Append("public class ").Append(ProgrammableOperator.CompiledTypeName).AppendLine(" {");
     125      prefix.Append("  ").Append(ProgrammableOperator.Signature).AppendLine(" {");
     126      return prefix.ToString();
     127    }
     128
     129    private void codeEditor_Validated(object sender, EventArgs e) {
     130      ProgrammableOperator.Code = codeEditor.UserCode;
     131    }
     132   
     133    /*
    85134    private void operatorBaseVariableInfosView_SelectedVariableInfosChanged(object sender, EventArgs e) {
    86135      removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
    87136    }
    88 
    89     #region Validated Events
    90     private void codeTextBox_Validated(object sender, EventArgs e) {
    91       ProgrammableOperator.Code = codeTextBox.Text;
    92     }
     137   
    93138    private void descriptionTextBox_Validated(object sender, EventArgs e) {
    94139      ProgrammableOperator.SetDescription(descriptionTextBox.Text);
    95140    }
    96     #endregion
    97 
    98     #region Click Events
    99     private void compileButton_Click(object sender, EventArgs e) {
    100       try {
    101         ProgrammableOperator.Compile();
    102         MessageBox.Show("Compilation successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
    103       }
    104       catch (Exception ex) {
    105         HeuristicLab.Core.Views.Auxiliary.ShowErrorMessageBox(ex);
    106       }
    107     }
     141
    108142    private void addVariableInfoButton_Click(object sender, EventArgs e) {
    109143      AddVariableInfoDialog dialog = new AddVariableInfoDialog();
    110144      if (dialog.ShowDialog(this) == DialogResult.OK) {
    111         if (ProgrammableOperator.GetVariableInfo(dialog.VariableInfo.FormalName) != null)
    112           HeuristicLab.Core.Views.Auxiliary.ShowErrorMessageBox("A variable info with the same formal name already exists.");
    113         else
     145        if (ProgrammableOperator.GetVariableInfo(dialog.VariableInfo.FormalName) != null) {
     146          Auxiliary.ShowErrorMessageBox("A variable info with the same formal name already exists.");
     147        } else {
    114148          ProgrammableOperator.AddVariableInfo(dialog.VariableInfo);
     149          Recompile();
     150        }
    115151      }
    116152      dialog.Dispose();
    117153    }
     154
    118155    private void removeVariableInfoButton_Click(object sender, EventArgs e) {
    119156      IVariableInfo[] selected = new IVariableInfo[operatorBaseVariableInfosView.SelectedVariableInfos.Count];
     
    121158      for (int i = 0; i < selected.Length; i++)
    122159        ProgrammableOperator.RemoveVariableInfo(selected[i].FormalName);
    123     }
    124     #endregion
     160      Recompile();
     161    } */
     162
     163    private void Recompile() {
     164      this.Enabled = false;
     165      try {
     166        ProgrammableOperator.Compile();
     167        MessageBox.Show("Compilation successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
     168      } catch (Exception ex) {
     169        Auxiliary.ShowErrorMessageBox(ex);
     170      }
     171      OnContentChanged();
     172      codeEditor.ShowCompileErrors(ProgrammableOperator.CompileErrors, "ProgrammableOperator");
     173      this.Enabled = true;
     174    }
     175
     176    private void compileButton_Click(object sender, EventArgs e) {
     177      Recompile();
     178    }
    125179
    126180    #region ProgrammableOperator Events
    127181    private void ProgrammableOperator_CodeChanged(object sender, EventArgs e) {
    128       codeTextBox.Text = ProgrammableOperator.Code;
     182      codeEditor.Text = ProgrammableOperator.Code;
    129183    }
    130184    private void ProgrammableOperator_DescriptionChanged(object sender, EventArgs e) {
     
    132186    }
    133187    #endregion
     188
     189    private void assembliesTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
     190      if (initializing)
     191        return;
     192      Assembly a = e.Node.Tag as Assembly;
     193      if (a == null && e.Node.Nodes.Count > 0) {
     194        foreach (TreeNode n in e.Node.Nodes)
     195          n.Checked = e.Node.Checked;
     196        return;
     197      } else {
     198        if (e.Node.Checked) {
     199          ProgrammableOperator.SelectAssembly(a);
     200          codeEditor.AddAssembly(a);
     201        } else {
     202          ProgrammableOperator.UnselectAssembly(a);
     203          codeEditor.RemoveAssembly(a);
     204        }
     205      }
     206      InitializeNamespacesList();
     207      codeEditor.Prefix = GetGeneratedPrefix();
     208    }
     209
     210    private bool initializing = false;
     211    private void InitializeAssemblyList() {
     212      initializing = true;
     213      assembliesTreeView.Enabled = false;
     214      namespacesTreeView.Enabled = false;
     215      assembliesTreeView.BeginUpdate();
     216      assembliesTreeView.Nodes.Clear();
     217      var selectedAssemblies = new HashSet<Assembly>(ProgrammableOperator.SelectedAssemblies);
     218      foreach (var p in ProgrammableOperator.Plugins) {
     219        var node = assembliesTreeView.Nodes.Add(p.Key);
     220        node.Tag = p;
     221        foreach (var a in p.Value) {
     222          var aNode = node.Nodes.Add(a.GetName().Name);
     223          aNode.Tag = a;
     224          if (selectedAssemblies.Contains(a))
     225            aNode.Checked = true;
     226        }
     227        if (node.Nodes.Count == 1 && node.Nodes[0].Name == node.Nodes[0].Name) {
     228          node.Tag = node.Nodes[0].Tag;
     229          node.Nodes.Clear();
     230        } else if (node.Nodes.Count > 0 && node.Nodes.Cast<TreeNode>().All(n => n.Checked)) {
     231          node.Checked = true;
     232        }
     233      }
     234      assembliesTreeView.EndUpdate();
     235      assembliesTreeView.Enabled = true;
     236      namespacesTreeView.Enabled = true;
     237      initializing = false;
     238    }
     239
     240    private void InitializeNamespacesList() {
     241      initializing = true;
     242      namespacesTreeView.Enabled = false;
     243      namespacesTreeView.BeginUpdate();
     244      TreeNode oldTree = new TreeNode("root");
     245      CloneTreeNodeCollection(oldTree, namespacesTreeView.Nodes);
     246      namespacesTreeView.Nodes.Clear();
     247      var selectedNamespaces = new HashSet<string>(ProgrammableOperator.Namespaces);
     248      foreach (var ns in ProgrammableOperator.GetAllNamespaces(true))
     249        AddNamespace(namespacesTreeView.Nodes, ns, selectedNamespaces.Contains(ns), oldTree);
     250      codeEditor.Prefix = GetGeneratedPrefix();
     251      namespacesTreeView.EndUpdate();
     252      namespacesTreeView.Enabled = true;
     253      initializing = false;
     254    }
     255
     256    private void CloneTreeNodeCollection(TreeNode root, TreeNodeCollection nodes) {
     257      foreach (TreeNode n in nodes) {
     258        TreeNode newNode = root.Nodes.Add(n.Text, n.Text);
     259        newNode.Checked = n.Checked;
     260        CloneTreeNodeCollection(newNode, n.Nodes);
     261        if (n.IsExpanded)
     262          newNode.Expand();
     263      }
     264    }
     265
     266    private bool AddNamespace(TreeNodeCollection parentNodes, string ns, bool isSelected, TreeNode oldTree) {
     267      int dotIndex = ns.IndexOf('.');
     268      string prefix = ns;
     269      if (dotIndex != -1)
     270        prefix = ns.Substring(0, dotIndex);
     271      TreeNode node = GetOrCreateNode(parentNodes, prefix);
     272      TreeNode oldNode = MaybeGetNode(oldTree, prefix);
     273      bool isNew = oldNode == null;
     274      if (dotIndex != -1 && dotIndex + 1 < ns.Length) {
     275        isNew = AddNamespace(node.Nodes, ns.Substring(dotIndex + 1, ns.Length - (dotIndex + 1)), isSelected, oldNode);
     276      } else {
     277        node.Checked = isSelected;
     278      }
     279      if (isNew || oldNode != null && oldNode.IsExpanded)
     280        node.Expand();
     281      if (isNew)
     282        namespacesTreeView.SelectedNode = node;
     283      return isNew;
     284    }
     285
     286    private static TreeNode MaybeGetNode(TreeNode parentNode, string key) {
     287      if (parentNode == null)
     288        return null;
     289      if (parentNode.Nodes.ContainsKey(key))
     290        return parentNode.Nodes[key];
     291      return null;
     292    }
     293
     294    private static TreeNode GetOrCreateNode(TreeNodeCollection parentNodes, string key) {
     295      TreeNode node = null;
     296      if (parentNodes.ContainsKey(key)) {
     297        node = parentNodes[key];
     298      } else {
     299        node = parentNodes.Add(key, key);
     300      }
     301      return node;
     302    }
     303
     304    private void namespacesTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
     305      if (initializing)
     306        return;
     307      if (e.Node.Checked) {
     308        ProgrammableOperator.SelectNamespace(e.Node.FullPath);
     309      } else {
     310        ProgrammableOperator.UnselectNamespace(e.Node.FullPath);
     311      }
     312      codeEditor.Prefix = GetGeneratedPrefix();
     313    }
     314
     315    private void showCodeButton_Click(object sender, EventArgs e) {
     316      new CodeViewer(ProgrammableOperator.CompilationUnitCode).ShowDialog(this);
     317    }
     318
     319
    134320  }
    135321}
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperatorView.resx

    r1530 r2799  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </resheader>
    120   <data name="infoTextBox.Text" xml:space="preserve">
    121     <value>All variables corresponding to declared variable infos can be accessed directly using their formal names. Additionally there are two special variables: "op" referring to the programmable operator itself (this) and "scope" referring to the scope the operator is applied on.</value>
    122   </data>
     120  <metadata name="splitContainer1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     121    <value>False</value>
     122  </metadata>
     123  <metadata name="splitContainer2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     124    <value>False</value>
     125  </metadata>
     126  <metadata name="groupBox1.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     127    <value>False</value>
     128  </metadata>
     129  <metadata name="groupBox2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     130    <value>False</value>
     131  </metadata>
    123132</root>
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/Properties/AssemblyInfo.frame

    r1872 r2799  
    3333[assembly: AssemblyCompany("")]
    3434[assembly: AssemblyProduct("HeuristicLab")]
    35 [assembly: AssemblyCopyright("(c) 2002-2008 HEAL")]
     35[assembly: AssemblyCopyright("(c) 2002-2010 HEAL")]
    3636[assembly: AssemblyTrademark("")]
    3737[assembly: AssemblyCulture("")]
Note: See TracChangeset for help on using the changeset viewer.