347 lines
13 KiB
C#
347 lines
13 KiB
C#
|
|
using CaeGlobals;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
// ReSharper disable IdentifierTypo
|
|||
|
|
#pragma warning disable IDE0130
|
|||
|
|
|
|||
|
|
namespace CPSO
|
|||
|
|
{
|
|||
|
|
[Serializable]
|
|||
|
|
public class SettingsContainer
|
|||
|
|
{
|
|||
|
|
// Variables
|
|||
|
|
[NonSerialized] private Dictionary<string, vtkControl.vtkMaxColorSpectrum> _colorSpectrums;
|
|||
|
|
[NonSerialized] private string _regenerationWorkDirectory;
|
|||
|
|
//
|
|||
|
|
private GeneralSettings _general;
|
|||
|
|
private GraphicsSettings _graphics;
|
|||
|
|
private ColorSettings _color;
|
|||
|
|
private AnnotationSettings _annotations;
|
|||
|
|
private MeshingSettings _meshing;
|
|||
|
|
private PreSettings _pre;
|
|||
|
|
private CalculixSettings _calculix;
|
|||
|
|
private AbaqusSettings _abaqus;
|
|||
|
|
private PostSettings _post;
|
|||
|
|
private LegendSettings _legend;
|
|||
|
|
private StatusBlockSettings _statusBlock;
|
|||
|
|
private PythonSettings _python;
|
|||
|
|
private CuttingForceSettings _cuttingForce;
|
|||
|
|
|
|||
|
|
// Properties
|
|||
|
|
public GeneralSettings General
|
|||
|
|
{
|
|||
|
|
get => _general;
|
|||
|
|
set => _general = value;
|
|||
|
|
}
|
|||
|
|
public GraphicsSettings Graphics
|
|||
|
|
{
|
|||
|
|
get => _graphics;
|
|||
|
|
set => _graphics = value;
|
|||
|
|
}
|
|||
|
|
public ColorSettings Color
|
|||
|
|
{
|
|||
|
|
get => _color;
|
|||
|
|
set => _color = value;
|
|||
|
|
}
|
|||
|
|
public AnnotationSettings Annotations
|
|||
|
|
{
|
|||
|
|
get => _annotations;
|
|||
|
|
set => _annotations = value;
|
|||
|
|
}
|
|||
|
|
public MeshingSettings Meshing
|
|||
|
|
{
|
|||
|
|
get => _meshing;
|
|||
|
|
set => _meshing = value;
|
|||
|
|
}
|
|||
|
|
public PreSettings Pre
|
|||
|
|
{
|
|||
|
|
get => _pre;
|
|||
|
|
set => _pre = value;
|
|||
|
|
}
|
|||
|
|
public CalculixSettings Calculix
|
|||
|
|
{
|
|||
|
|
get => _calculix;
|
|||
|
|
set => _calculix = value;
|
|||
|
|
}
|
|||
|
|
public AbaqusSettings Abaqus
|
|||
|
|
{
|
|||
|
|
get => _abaqus;
|
|||
|
|
set => _abaqus = value;
|
|||
|
|
}
|
|||
|
|
public PostSettings Post
|
|||
|
|
{
|
|||
|
|
get => _post;
|
|||
|
|
set => _post = value;
|
|||
|
|
}
|
|||
|
|
public LegendSettings Legend
|
|||
|
|
{
|
|||
|
|
get => _legend;
|
|||
|
|
set => _legend = value;
|
|||
|
|
}
|
|||
|
|
public StatusBlockSettings StatusBlock
|
|||
|
|
{
|
|||
|
|
get => _statusBlock;
|
|||
|
|
set => _statusBlock = value;
|
|||
|
|
}
|
|||
|
|
// Add by Luke
|
|||
|
|
public PythonSettings Python
|
|||
|
|
{
|
|||
|
|
get => _python;
|
|||
|
|
set => _python = value;
|
|||
|
|
}
|
|||
|
|
// Add by Luke
|
|||
|
|
public CuttingForceSettings CuttingForce
|
|||
|
|
{
|
|||
|
|
get => _cuttingForce;
|
|||
|
|
set => _cuttingForce = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Constructors
|
|||
|
|
public SettingsContainer()
|
|||
|
|
{
|
|||
|
|
Initialize();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public SettingsContainer(Dictionary<string, ISettings> items)
|
|||
|
|
{
|
|||
|
|
Initialize();
|
|||
|
|
FromDictionary(items);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Methods
|
|||
|
|
public void Initialize()
|
|||
|
|
{
|
|||
|
|
_colorSpectrums = new Dictionary<string, vtkControl.vtkMaxColorSpectrum>();
|
|||
|
|
//
|
|||
|
|
_general = new GeneralSettings();
|
|||
|
|
_graphics = new GraphicsSettings();
|
|||
|
|
_color = new ColorSettings();
|
|||
|
|
_annotations = new AnnotationSettings();
|
|||
|
|
_meshing = new MeshingSettings();
|
|||
|
|
_pre = new PreSettings();
|
|||
|
|
_calculix = new CalculixSettings();
|
|||
|
|
_abaqus = new AbaqusSettings();
|
|||
|
|
_post = new PostSettings();
|
|||
|
|
_legend = new LegendSettings();
|
|||
|
|
_statusBlock = new StatusBlockSettings();
|
|||
|
|
// Add by Luke
|
|||
|
|
_python = new PythonSettings();
|
|||
|
|
_cuttingForce = new CuttingForceSettings();
|
|||
|
|
}
|
|||
|
|
public void Reset()
|
|||
|
|
{
|
|||
|
|
_general.Reset();
|
|||
|
|
_graphics.Reset();
|
|||
|
|
_color.Reset();
|
|||
|
|
_annotations.Reset();
|
|||
|
|
_meshing.Reset();
|
|||
|
|
_pre.Reset();
|
|||
|
|
_calculix.Reset();
|
|||
|
|
_abaqus.Reset();
|
|||
|
|
_post.Reset();
|
|||
|
|
_legend.Reset();
|
|||
|
|
_statusBlock.Reset();
|
|||
|
|
// Add by Luke
|
|||
|
|
_python.Reset();
|
|||
|
|
_cuttingForce.Reset();
|
|||
|
|
}
|
|||
|
|
public void ClearColorSpectrums()
|
|||
|
|
{
|
|||
|
|
_colorSpectrums.Clear();
|
|||
|
|
_legend.ColorSpectrum.MinMaxType = vtkControl.vtkColorSpectrumMinMaxType.Automatic;
|
|||
|
|
}
|
|||
|
|
public void Set(SettingsContainer settingsContainer, ViewGeometryModelResults currentView,
|
|||
|
|
CaeResults.FieldData currentFieldData)
|
|||
|
|
{
|
|||
|
|
Clone(settingsContainer);
|
|||
|
|
//
|
|||
|
|
if (currentView == ViewGeometryModelResults.Results && currentFieldData != null)
|
|||
|
|
{
|
|||
|
|
string key = currentFieldData.Name + "_" + currentFieldData.Component;
|
|||
|
|
// Save individual Min/Max setting
|
|||
|
|
if (_legend.ColorSpectrum.MinMaxType == vtkControl.vtkColorSpectrumMinMaxType.Manual)
|
|||
|
|
{
|
|||
|
|
if (_colorSpectrums.ContainsKey(key)) _colorSpectrums[key] = _legend.ColorSpectrum.DeepClone();
|
|||
|
|
else _colorSpectrums.Add(key, _legend.ColorSpectrum.DeepClone());
|
|||
|
|
}
|
|||
|
|
// Remove individual Min/Max setting
|
|||
|
|
else _colorSpectrums.Remove(key);
|
|||
|
|
}
|
|||
|
|
//
|
|||
|
|
_legend.ColorSpectrum.MinMaxType = vtkControl.vtkColorSpectrumMinMaxType.Automatic;
|
|||
|
|
}
|
|||
|
|
public SettingsContainer Get(ViewGeometryModelResults currentView, CaeResults.FieldData currentFieldData)
|
|||
|
|
{
|
|||
|
|
SettingsContainer clone = new SettingsContainer();
|
|||
|
|
clone.Clone(this);
|
|||
|
|
clone._regenerationWorkDirectory = _regenerationWorkDirectory;
|
|||
|
|
//
|
|||
|
|
if (currentView == ViewGeometryModelResults.Results && currentFieldData != null)
|
|||
|
|
{
|
|||
|
|
vtkControl.vtkMaxColorSpectrum colorSpectrum;
|
|||
|
|
string key = currentFieldData.Name + "_" + currentFieldData.Component;
|
|||
|
|
// Apply individual Min/Max setting if it exists
|
|||
|
|
if (_colorSpectrums.TryGetValue(key, out colorSpectrum) &&
|
|||
|
|
colorSpectrum.MinMaxType == vtkControl.vtkColorSpectrumMinMaxType.Manual)
|
|||
|
|
{
|
|||
|
|
clone._legend.ColorSpectrum.SetMinMax(colorSpectrum);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//
|
|||
|
|
return clone;
|
|||
|
|
}
|
|||
|
|
private void Clone(SettingsContainer settingsContainer)
|
|||
|
|
{
|
|||
|
|
SettingsContainer clone = settingsContainer.DeepClone();
|
|||
|
|
//
|
|||
|
|
_general = clone._general;
|
|||
|
|
_graphics = clone._graphics;
|
|||
|
|
_color = clone._color;
|
|||
|
|
_annotations = clone._annotations;
|
|||
|
|
_meshing = clone._meshing;
|
|||
|
|
_pre = clone._pre;
|
|||
|
|
_calculix = clone._calculix;
|
|||
|
|
_abaqus = clone._abaqus;
|
|||
|
|
_post = clone._post;
|
|||
|
|
_legend = clone._legend;
|
|||
|
|
_statusBlock = clone._statusBlock;
|
|||
|
|
// Add by Luke
|
|||
|
|
_python = clone._python;
|
|||
|
|
_cuttingForce = clone._cuttingForce;
|
|||
|
|
}
|
|||
|
|
public Dictionary<string, ISettings> ToDictionary()
|
|||
|
|
{
|
|||
|
|
Dictionary<string, ISettings> items = new Dictionary<string, ISettings>();
|
|||
|
|
items.Add(Globals.GeneralSettingsName, _general);
|
|||
|
|
items.Add(Globals.GraphicsSettingsName, _graphics);
|
|||
|
|
items.Add(Globals.ColorSettingsName, _color);
|
|||
|
|
items.Add(Globals.AnnotationSettingsName, _annotations);
|
|||
|
|
items.Add(Globals.MeshingSettingsName, _meshing);
|
|||
|
|
items.Add(Globals.PreSettingsName, _pre);
|
|||
|
|
items.Add(Globals.CalculixSettingsName, _calculix);
|
|||
|
|
items.Add(Globals.AbaqusSettingsName, _abaqus);
|
|||
|
|
items.Add(Globals.PostSettingsName, _post);
|
|||
|
|
items.Add(Globals.LegendSettingsName, _legend);
|
|||
|
|
items.Add(Globals.StatusBlockSettingsName, _statusBlock);
|
|||
|
|
// Add by Luke
|
|||
|
|
items.Add(Globals.PythonSettingNames, _python);
|
|||
|
|
items.Add(Globals.CuttingForceSettingNames, _cuttingForce);
|
|||
|
|
return items;
|
|||
|
|
}
|
|||
|
|
public void FromDictionary(Dictionary<string, ISettings> items)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
_general = (GeneralSettings)items[Globals.GeneralSettingsName];
|
|||
|
|
_graphics = (GraphicsSettings)items[Globals.GraphicsSettingsName];
|
|||
|
|
_color = (ColorSettings)items[Globals.ColorSettingsName];
|
|||
|
|
_annotations = (AnnotationSettings)items[Globals.AnnotationSettingsName];
|
|||
|
|
_meshing = (MeshingSettings)items[Globals.MeshingSettingsName];
|
|||
|
|
_pre = (PreSettings)items[Globals.PreSettingsName];
|
|||
|
|
_calculix = (CalculixSettings)items[Globals.CalculixSettingsName];
|
|||
|
|
_abaqus = (AbaqusSettings)items[Globals.AbaqusSettingsName];
|
|||
|
|
_post = (PostSettings)items[Globals.PostSettingsName];
|
|||
|
|
_legend = (LegendSettings)items[Globals.LegendSettingsName];
|
|||
|
|
_statusBlock = (StatusBlockSettings)items[Globals.StatusBlockSettingsName];
|
|||
|
|
// Add by Luke
|
|||
|
|
_python = (PythonSettings)items[Globals.PythonSettingNames];
|
|||
|
|
_cuttingForce = (CuttingForceSettings)items[Globals.CuttingForceSettingNames];
|
|||
|
|
}
|
|||
|
|
catch(Exception ex)
|
|||
|
|
{
|
|||
|
|
// ExceptionTools.Show(ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void SaveToFile()
|
|||
|
|
{
|
|||
|
|
SaveToFile(Path.Combine(System.Windows.Forms.Application.StartupPath, Globals.SettingsFileName));
|
|||
|
|
}
|
|||
|
|
public void SaveToFile(string fileName)
|
|||
|
|
{
|
|||
|
|
if (_regenerationWorkDirectory == null)
|
|||
|
|
{
|
|||
|
|
// Use a temporary file to save the data and copy it at the end
|
|||
|
|
string tmpFileName = Tools.GetNonExistentRandomFileName(Path.GetDirectoryName(fileName), ".tmp");
|
|||
|
|
ToDictionary().DumpToFile(tmpFileName);
|
|||
|
|
File.Copy(tmpFileName, fileName, true);
|
|||
|
|
File.Delete(tmpFileName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void LoadFromFile()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Initialize();
|
|||
|
|
//
|
|||
|
|
string fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, Globals.SettingsFileName);
|
|||
|
|
if (File.Exists(fileName))
|
|||
|
|
{
|
|||
|
|
var t = Task.Run(() => LoadFromFile(fileName));
|
|||
|
|
t.Wait();
|
|||
|
|
}
|
|||
|
|
// Reset the color limits
|
|||
|
|
ClearColorSpectrums();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
Initialize();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private void LoadFromFile(string fileName)
|
|||
|
|
{
|
|||
|
|
Dictionary<string, ISettings> items = Tools.LoadDumpFromFile<Dictionary<string, ISettings>>(fileName);
|
|||
|
|
FromDictionary(items);
|
|||
|
|
}
|
|||
|
|
// 公开接口
|
|||
|
|
public void SetRegenerationWorkDirectory(string workDirectory)
|
|||
|
|
{
|
|||
|
|
_regenerationWorkDirectory = workDirectory;
|
|||
|
|
}
|
|||
|
|
public string GetRegenerationWorkDirectory()
|
|||
|
|
{
|
|||
|
|
return _regenerationWorkDirectory;
|
|||
|
|
}
|
|||
|
|
public string GetWorkDirectory()
|
|||
|
|
{
|
|||
|
|
string lastFileName = _general.LastFileName;
|
|||
|
|
if (_regenerationWorkDirectory != null)
|
|||
|
|
{
|
|||
|
|
return _regenerationWorkDirectory;
|
|||
|
|
}
|
|||
|
|
else if (_calculix.UsePmxFolderAsWorkDirectory && lastFileName != null && File.Exists(lastFileName) &&
|
|||
|
|
Path.GetExtension(lastFileName) == ".pmx")
|
|||
|
|
{
|
|||
|
|
return Path.GetDirectoryName(lastFileName);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return _calculix.WorkDirectoryForSettingsOnly;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public string GetAbaqusWorkDirectory()
|
|||
|
|
{
|
|||
|
|
string lastFileName = _general.LastFileName;
|
|||
|
|
if (_regenerationWorkDirectory != null)
|
|||
|
|
{
|
|||
|
|
return _regenerationWorkDirectory;
|
|||
|
|
}
|
|||
|
|
else if (_abaqus.UsePmxFolderAsWorkDirectory && lastFileName != null && File.Exists(lastFileName) &&
|
|||
|
|
Path.GetExtension(lastFileName) == ".pmx")
|
|||
|
|
{
|
|||
|
|
return Path.GetDirectoryName(lastFileName);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return _abaqus.WorkDirectoryForSettingsOnly;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void CheckWorkingDirectory()
|
|||
|
|
{
|
|||
|
|
if (GetWorkDirectory().ContainsNonEnglishCharacters())
|
|||
|
|
MessageBoxes.ShowWarning(CalculixSettings.NonEnglishDirectoryWarning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|