Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17404


Ignore:
Timestamp:
01/20/20 16:36:05 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • fixed a bug in BaseConverter -> the range for percent values should be returned correctly now
  • fixed a bug in ConstrainedValueParameterConverter, ParameterizedItemConverter, ValueParameterConverter -> unsupported json items get filtered now
  • JCGenerator is now a dynamic class and can return all JsonItems for an IOptimizer now (instead of string only) + it is now possible to generate an template string with an IEnumerable<JsonItem>
  • added first version of an export dialog for JsonInterface
    • it is organized with a main view (for the dialog) and some user controls (for a better visualization of an JsonItem -> to reduce wrong user inputs)
    • the user controls inherit a base control, which organizes some base values of an JsonItem
Location:
branches/3026_IntegrationIntoSymSpace
Files:
24 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/FileManager.cs

    r17394 r17404  
    1313
    1414namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    15   internal  static class FileManager {
     15  internal static class FileManager {
    1616    private static SaveFileDialog saveFileDialog;
    1717    private static OpenFileDialog openFileDialog;
     18    private static ExportJsonDialog exportDialog = new ExportJsonDialog();
    1819
    1920    public static void ExportJsonTemplate() {
     
    2324      }
    2425    }
    25     public static void ExportJsonTemplate(IContentView view) { 
     26    public static void ExportJsonTemplate(IContentView view) {
    2627      // TODO: view to select free params, warning if no results are generated
     28     
     29
     30
    2731      IStorableContent content = view.Content as IStorableContent;
    2832      if (!view.Locked && content != null) {
     33        exportDialog.Content = content;
     34        exportDialog.ShowDialog();
     35        /*
    2936        if (saveFileDialog == null) {
    3037          saveFileDialog = new SaveFileDialog();
     
    4754          File.WriteAllText(saveFileDialog.FileName, JCGenerator.GenerateTemplate(alg));
    4855        }
     56        */
    4957      }
    5058    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/HeuristicLab.JsonInterface.OptimizerIntegration.csproj

    r17331 r17404  
    3838  </PropertyGroup>
    3939  <ItemGroup>
     40    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     41      <SpecificVersion>False</SpecificVersion>
     42      <HintPath>..\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
     43    </Reference>
     44    <Reference Include="HeuristicLab.Analysis.Views-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     45      <SpecificVersion>False</SpecificVersion>
     46      <HintPath>..\bin\HeuristicLab.Analysis.Views-3.3.dll</HintPath>
     47    </Reference>
     48    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     49      <SpecificVersion>False</SpecificVersion>
     50      <HintPath>..\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     51    </Reference>
     52    <Reference Include="HeuristicLab.Core.Views-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     53      <SpecificVersion>False</SpecificVersion>
     54      <HintPath>..\bin\HeuristicLab.Core.Views-3.3.dll</HintPath>
     55    </Reference>
     56    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     57      <SpecificVersion>False</SpecificVersion>
     58      <HintPath>..\bin\HeuristicLab.Data-3.3.dll</HintPath>
     59    </Reference>
     60    <Reference Include="HeuristicLab.Optimization.Views-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     61      <SpecificVersion>False</SpecificVersion>
     62      <HintPath>..\bin\HeuristicLab.Optimization.Views-3.3.dll</HintPath>
     63    </Reference>
    4064    <Reference Include="System" />
    4165    <Reference Include="System.Core" />
     66    <Reference Include="System.Drawing" />
    4267    <Reference Include="System.Windows.Forms" />
    4368    <Reference Include="System.Xml.Linq" />
     
    4974  </ItemGroup>
    5075  <ItemGroup>
     76    <Compile Include="Properties\Resources.Designer.cs">
     77      <AutoGen>True</AutoGen>
     78      <DesignTime>True</DesignTime>
     79      <DependentUpon>Resources.resx</DependentUpon>
     80    </Compile>
     81    <Compile Include="Shared\JsonItemBaseControl.cs">
     82      <SubType>UserControl</SubType>
     83    </Compile>
     84    <Compile Include="Shared\JsonItemBaseControl.Designer.cs">
     85      <DependentUpon>JsonItemBaseControl.cs</DependentUpon>
     86    </Compile>
     87    <Compile Include="Views\ExportJsonDialog.cs">
     88      <SubType>Form</SubType>
     89    </Compile>
     90    <Compile Include="Views\ExportJsonDialog.Designer.cs">
     91      <DependentUpon>ExportJsonDialog.cs</DependentUpon>
     92    </Compile>
    5193    <Compile Include="FileManager.cs" />
     94    <Compile Include="Views\JsonItemBoolControl.cs">
     95      <SubType>UserControl</SubType>
     96    </Compile>
     97    <Compile Include="Views\JsonItemBoolControl.Designer.cs">
     98      <DependentUpon>JsonItemBoolControl.cs</DependentUpon>
     99    </Compile>
     100    <Compile Include="Views\JsonItemRangeControl.cs">
     101      <SubType>UserControl</SubType>
     102    </Compile>
     103    <Compile Include="Views\JsonItemRangeControl.Designer.cs">
     104      <DependentUpon>JsonItemRangeControl.cs</DependentUpon>
     105    </Compile>
     106    <Compile Include="Views\JsonItemValueControl.cs">
     107      <SubType>UserControl</SubType>
     108    </Compile>
     109    <Compile Include="Views\JsonItemValueControl.Designer.cs">
     110      <DependentUpon>JsonItemValueControl.cs</DependentUpon>
     111    </Compile>
     112    <Compile Include="Views\JsonItemValidValuesControl.cs">
     113      <SubType>UserControl</SubType>
     114    </Compile>
     115    <Compile Include="Views\JsonItemValidValuesControl.Designer.cs">
     116      <DependentUpon>JsonItemValidValuesControl.cs</DependentUpon>
     117    </Compile>
     118    <Compile Include="ViewModels\JsonItemVM.cs" />
    52119    <Compile Include="MenuItems\ImportJsonTemplateMenuItem.cs" />
    53120    <Compile Include="MenuItems\ExportJsonTemplateMenuItem.cs" />
     
    93160    </ProjectReference>
    94161  </ItemGroup>
     162  <ItemGroup>
     163    <EmbeddedResource Include="Properties\Resources.resx">
     164      <Generator>ResXFileCodeGenerator</Generator>
     165      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     166    </EmbeddedResource>
     167    <EmbeddedResource Include="Shared\JsonItemBaseControl.resx">
     168      <DependentUpon>JsonItemBaseControl.cs</DependentUpon>
     169    </EmbeddedResource>
     170    <EmbeddedResource Include="Views\ExportJsonDialog.resx">
     171      <DependentUpon>ExportJsonDialog.cs</DependentUpon>
     172    </EmbeddedResource>
     173    <EmbeddedResource Include="Views\JsonItemBoolControl.resx">
     174      <DependentUpon>JsonItemBoolControl.cs</DependentUpon>
     175    </EmbeddedResource>
     176    <EmbeddedResource Include="Views\JsonItemRangeControl.resx">
     177      <DependentUpon>JsonItemRangeControl.cs</DependentUpon>
     178    </EmbeddedResource>
     179    <EmbeddedResource Include="Views\JsonItemValueControl.resx">
     180      <DependentUpon>JsonItemValueControl.cs</DependentUpon>
     181    </EmbeddedResource>
     182    <EmbeddedResource Include="Views\JsonItemValidValuesControl.resx">
     183      <DependentUpon>JsonItemValidValuesControl.cs</DependentUpon>
     184    </EmbeddedResource>
     185  </ItemGroup>
     186  <ItemGroup />
    95187  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    96188  <PropertyGroup>
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs

    r17395 r17404  
    4545      TypeCode typeCode = Type.GetTypeCode(t);
    4646
    47       if (typeof(ValueType).IsEqualTo(typeof(PercentValue)))
     47      if (t.IsEqualTo(typeof(PercentValue)))
    4848        return 1.0d;
    4949
     
    6767      TypeCode typeCode = Type.GetTypeCode(t);
    6868
    69       if (typeof(ValueType).IsEqualTo(typeof(PercentValue)))
     69      if (t.IsEqualTo(typeof(PercentValue)))
    7070        return 0.0d;
    7171
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ConstrainedValueParameterConverter.cs

    r17394 r17404  
    4646        if (x is IParameterizedItem) {
    4747          JsonItem tmp = JsonItemConverter.Extract(x);
    48           list.Add(tmp);
     48          if(!(tmp is UnsupportedJsonItem))
     49            list.Add(tmp);
    4950        }
    5051      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterizedItemConverter.cs

    r17394 r17404  
    2525
    2626      foreach (var param in parameterizedItem.Parameters) {
    27         if(!param.Hidden)
    28           item.AddChilds(root.Extract(param, root));
     27        if (!param.Hidden) {
     28          JsonItem tmp = root.Extract(param, root);
     29          if(!(tmp is UnsupportedJsonItem))
     30            item.AddChilds(tmp);
     31        }
     32         
    2933      }
    3034    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs

    r17394 r17404  
    2121      if (value.ActualValue != null) {
    2222        JsonItem tmp = root.Extract(value.ActualValue, root);
    23         if(tmp.Name == "[OverridableParamName]") {
    24           tmp.Name = value.Name;
    25           JsonItem.Merge(item, tmp);
     23        if(!(tmp is UnsupportedJsonItem)) {
     24          if (tmp.Name == "[OverridableParamName]") {
     25            tmp.Name = value.Name;
     26            JsonItem.Merge(item, tmp);
     27          } else
     28            item.AddChilds(tmp);
    2629        }
    27         else
    28           item.AddChilds(tmp);
    2930      }
    3031    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs

    r17395 r17404  
    1212namespace HeuristicLab.JsonInterface {
    1313  /// <summary>
    14   /// Static class to generate json interface templates.
     14  /// Class to generate json interface templates.
    1515  /// </summary>
    16   public static class JCGenerator {
    17     private struct GenData {
    18       public JObject Template { get; set; }
    19       public JArray JsonItems { get; set; }
    20     }
    21    
    22     public static string GenerateTemplate(IOptimizer optimizer) {
     16  public class JCGenerator {
     17    private JObject Template { get; set; }
     18    private JArray JArrayItems { get; set; }
     19    private IList<JsonItem> JsonItems { get; set; }
     20    private IOptimizer Optimizer { get; set; }
     21
     22    public string GenerateTemplate(IOptimizer optimizer) {
    2323      // data container
    24       GenData genData = new GenData() {
    25         Template = JObject.Parse(Constants.Template),
    26         JsonItems = new JArray()
    27       };
     24      JArrayItems = new JArray();
     25      JsonItems = new List<JsonItem>();
    2826
    2927      ProtoBufSerializer serializer = new ProtoBufSerializer();
    3028      serializer.Serialize(optimizer, @"C:\Workspace\template.hl");
    31       genData.Template[Constants.Metadata][Constants.HLFileLocation] = @"C:\Workspace\template.hl";
     29      Template[Constants.Metadata][Constants.HLFileLocation] = @"C:\Workspace\template.hl";
    3230
    3331      // extract JsonItem, save the name in the metadata section of the
    3432      // template and save it an JArray incl. all parameters of the JsonItem,
    3533      // which have parameters aswell
    36       AddInstantiableIItem(Constants.Optimizer, optimizer, genData);
     34      AddIItem(optimizer);
    3735
    3836      // save the JArray with JsonItems (= IParameterizedItems)
    39       genData.Template[Constants.Parameters] = genData.JsonItems;
     37      Template[Constants.Parameters] = JArrayItems;
    4038      // serialize template and return string
    41       return SingleLineArrayJsonWriter.Serialize(genData.Template);
     39      return SingleLineArrayJsonWriter.Serialize(Template);
     40    }
     41
     42    public string GenerateTemplate(IEnumerable<JsonItem> items) {
     43      ProtoBufSerializer serializer = new ProtoBufSerializer();
     44      serializer.Serialize(Optimizer, @"C:\Workspace\template.hl");
     45      Template[Constants.Metadata][Constants.HLFileLocation] = @"C:\Workspace\template.hl";
     46
     47      JArrayItems = new JArray();
     48      foreach (var item in items) {
     49        JArrayItems.Add(Serialize(item));
     50      }
     51      Template[Constants.Parameters] = JArrayItems;
     52
     53      // serialize template and return string
     54      return SingleLineArrayJsonWriter.Serialize(Template);
     55    }
     56
     57    public IEnumerable<JsonItem> FetchJsonItems(IOptimizer optimizer) {
     58      // data container
     59      Template = JObject.Parse(Constants.Template);
     60      JsonItems = new List<JsonItem>();
     61      Optimizer = optimizer;
     62
     63      // extract JsonItem, save the name in the metadata section of the
     64      // template and save it an JArray incl. all parameters of the JsonItem,
     65      // which have parameters aswell
     66      AddIItem(optimizer);
     67
     68      // serialize template and return string
     69      return JsonItems;
    4270    }
    4371   
    4472    #region Helper
    4573
    46     private static void AddInstantiableIItem(string metaDataTagName, IItem item, GenData genData) {
     74    private void AddIItem(IItem item) {
    4775      JsonItem jsonItem = JsonItemConverter.Extract(item);
    48      
    49       genData.Template[Constants.Metadata][metaDataTagName] = item.ItemName;
    50       PopulateJsonItems(jsonItem, genData);
     76      Template[Constants.Metadata][Constants.Optimizer] = item.ItemName;
     77      PopulateJsonItems(jsonItem);
    5178    }
    5279
    5380    // serializes ParameterizedItems and saves them in list "JsonItems".
    54     private static void PopulateJsonItems(JsonItem item, GenData genData) {
     81    private void PopulateJsonItems(JsonItem item) {
    5582      IEnumerable<JsonItem> tmpParameter = item.Children;
    5683
    5784      if (item.Value != null || item.Range != null) {
    58         genData.JsonItems.Add(Serialize(item));
     85        JsonItems.Add(item);
    5986      }
    6087
    6188      if (tmpParameter != null) {
    6289        foreach (var p in tmpParameter) {
    63           PopulateJsonItems(p, genData);
     90          PopulateJsonItems(p);
    6491        }
    6592      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs

    r17394 r17404  
    110110
    111111    #region Helper
    112 
    113 
    114112    protected bool IsInRange() {
    115113      bool b1 = true, b2 = true;
Note: See TracChangeset for help on using the changeset viewer.