示例#1
0
 void RemoveUnusedParameters(string tomoSource)
 {
     lock (lockRemoveUnusedParameters)
     {
         try
         {
             if (tomoSource.Contains("SetParameterBulk"))
             {
                 return;
             }
             Dictionary <string, bool> usedParameters  = UsedParameters(tomoSource);
             List <string>             entriesToDelete = new List <string>();
             foreach (KeyValuePair <string, string> entry in ParameterDict.Current.Entries)
             {
                 if (entry.Key.StartsWith("Formula.Parameters."))
                 {
                     if (!ParameterDict.IsAdditionalInfo(entry.Key))
                     {
                         string parameterName = entry.Key.Substring("Formula.Parameters.".Length);
                         if (!usedParameters.ContainsKey(parameterName))
                         {
                             entriesToDelete.Add(parameterName);
                         }
                     }
                 }
             }
             foreach (string entryToDelete in entriesToDelete)
             {
                 ParameterDict.Current.RemoveProperty("Formula.Parameters." + entryToDelete);
             }
         } catch (System.InvalidOperationException)
         {
             // throwed if enumeration is not possible because ParameterDict.Current.Entries has changed in other thread.
         }
     }
 }
示例#2
0
        /// <summary>
        /// Generates the compressed formula.
        /// The formula parameters and the formula itself are combined in a compact text,
        /// which can later be copied into the formula text window to get the current
        /// formula configuration.
        /// </summary>
        public static string GenerateCompressedFormulaAndViewSettings()
        {
            string formula = ParameterDict.Current["Intern.Formula.Source"];

            List <string> formulaSettingCategories = new List <string>();

            formulaSettingCategories.Add("Scene");
            formulaSettingCategories.Add("Transformation.Camera");
            formulaSettingCategories.Add("Transformation.Perspectice");
            formulaSettingCategories.Add("Formula");
            formulaSettingCategories.Add("Renderer");
            formulaSettingCategories.Add("Renderer.BackColor");
            formulaSettingCategories.Add("Renderer.ColorFactor");
            formulaSettingCategories.Add("Renderer.Light");

            // To make the new settings unique
            ParameterDict.Current["intern.Formula.TempUpdateVal"] = "vv";
            string testHash = ParameterDict.Current.GetHash("");

            string insertSettingsStringHere = "base.Init();";

            if (!formula.Contains(insertSettingsStringHere))
            {
                formula = @"
public override void Init() 
{
  base.Init();
}
" + formula;
            }
            StringBuilder settingsString = new StringBuilder();

            settingsString.Append("if(GetString(\"intern.Formula.TempUpdateVal\")!=\"" + testHash + "\"){");
            settingsString.Append("SetParameterBulk(\"");
            foreach (KeyValuePair <string, string> entry in ParameterDict.Current.SortedEntries)
            {
                bool isInCategorie = false;
                foreach (string testCategorie in formulaSettingCategories)
                {
                    if (entry.Key.StartsWith(testCategorie))
                    {
                        isInCategorie = true;
                        break;
                    }
                }
                if (isInCategorie)
                {
                    if (!ParameterDict.IsAdditionalInfo(entry.Key))
                    {
                        settingsString.Append("<Entry Key='" + entry.Key + "' Value='" + entry.Value + "' />");
                    }
                }
            }
            // fix this formula to testHash
            settingsString.Append("<Entry Key='intern.Formula.TempUpdateVal' Value='" + testHash + "' />");
            settingsString.Append("\");");
            settingsString.Append("}");
            formula = formula.Replace(insertSettingsStringHere, insertSettingsStringHere + settingsString.ToString());

            StringBuilder retVal = new StringBuilder();

            retVal.Append(CompressFormula(formula));
            return(retVal.ToString());
        }