using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.ComponentModel;
|
using System.IO;
|
using System.Runtime.CompilerServices;
|
using System.Windows.Controls;
|
using PdmSwPlugin.Common.CustomHandler;
|
using PdmSwPlugin.Common.Util;
|
using PdmSwPlugin.PropertySetting.Entity;
|
using PdmSwPlugin.PropertySetting.Interface;
|
using PdmSwPlugin.PropertySetting.Panel.Attr;
|
using SolidWorks.Interop.sldworks;
|
using SolidWorks.Interop.swconst;
|
|
namespace PdmSwPlugin.PropertySetting.Panel
|
{
|
|
public partial class JgjModulePanel : UserControl, INotifyPropertyChanged, IPropertyOpt
|
{
|
#region 不能公用的东西,真有你的啊C#
|
public event PropertyChangedEventHandler PropertyChanged;
|
public void RaisePropertyChanged(string name)
|
{
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
}
|
|
public void ccc<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
|
{
|
old = @new;
|
if (propertyName != null)
|
{
|
RaisePropertyChanged(propertyName);
|
}
|
}
|
|
public void RaiseAndSetIfChanged<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
|
{
|
old = @new;
|
if (propertyName != null)
|
{
|
RaisePropertyChanged(propertyName);
|
/*var attr = GetType().GetProperty(propertyName)?.GetCustomAttribute<PropertySettingAttr>();
|
if (attr == null)
|
{
|
return;
|
}
|
if (attr.NeedSave)
|
{
|
UpdateProperty?.Invoke(this, attr.Name, @new);
|
}*/
|
}
|
}
|
#endregion
|
|
public event PanelPropertyChanged UpdateProperty;
|
|
private Dictionary<string, string> InitData = new Dictionary<string, string>();
|
|
private Dictionary<string, JgjType> datas;
|
private Dictionary<string, ObservableCollection<string>> stuffItemCache;
|
|
private Dictionary<string, ObservableCollection<string>> surfaceItemCache;
|
|
private Dictionary<string, ObservableCollection<string>> heatItemCache;
|
|
private ModelDoc2 doc;
|
|
#region 下拉框数据源
|
private ObservableCollection<string> _jgjTypeItems;
|
public ObservableCollection<string> jgjTypeItems
|
{
|
get => _jgjTypeItems;
|
set => ccc(ref _jgjTypeItems, value);
|
}
|
|
private ObservableCollection<string> _stuffItems;
|
public ObservableCollection<string> stuffItems
|
{
|
get => _stuffItems;
|
set => ccc(ref _stuffItems, value);
|
}
|
|
private ObservableCollection<string> _surfaceItems;
|
public ObservableCollection<string> surfaceItems
|
{
|
get => _surfaceItems;
|
set => ccc(ref _surfaceItems, value);
|
}
|
|
private ObservableCollection<string> _heatItems;
|
public ObservableCollection<string> heatItems
|
{
|
get => _heatItems;
|
set => ccc(ref _heatItems, value);
|
}
|
|
private ObservableCollection<string> _materialTypeItems = NameConstant.MaterialTypes;
|
public ObservableCollection<string> materialTypeItems
|
{
|
get => _materialTypeItems;
|
set => ccc(ref _materialTypeItems, value);
|
}
|
|
private ObservableCollection<string> _docTypeItems = NameConstant.DocTypes;
|
public ObservableCollection<string> docTypeItems
|
{
|
get => _docTypeItems;
|
set => ccc(ref _docTypeItems, value);
|
}
|
#endregion
|
|
private bool _docTypeEnabled = true;
|
[PropertySettingAttr(NeedInit = false, NeedSave = false)]
|
public bool DocTypeEnabled
|
{
|
get => _docTypeEnabled;
|
set => RaiseAndSetIfChanged(ref _docTypeEnabled, value);
|
}
|
|
#region UI属性
|
private string _materialCode;
|
[PropertySettingAttr(Name = NameConstant.materialCode, defaultValue = "$PRP:\"SW-File Name\"")]
|
public string materialCode
|
{
|
get => _materialCode;
|
set
|
{
|
RaiseAndSetIfChanged(ref _materialCode, value);
|
}
|
}
|
|
private string _materialName;
|
[PropertySettingAttr(Name = NameConstant.materialName)]
|
public string materialName
|
{
|
get => _materialName;
|
set
|
{
|
RaiseAndSetIfChanged(ref _materialName, value);
|
}
|
}
|
|
private string _materialModel;
|
[PropertySettingAttr(Name = NameConstant.materialModel)]
|
public string materialModel
|
{
|
get => _materialModel;
|
set
|
{
|
RaiseAndSetIfChanged(ref _materialModel, value);
|
}
|
}
|
|
private string _materialType = "";
|
[PropertySettingAttr(Name = NameConstant.materialType, defaultValue = "普通件")]
|
public string materialType
|
{
|
get => _materialType;
|
set
|
{
|
RaiseAndSetIfChanged(ref _materialType, value);
|
}
|
}
|
|
private string _jgjType;
|
[PropertySettingAttr(Name = NameConstant.jgjType)]
|
public string jgjType
|
{
|
get => _jgjType;
|
set
|
{
|
string temp = value;// jgjTypeItems.Contains(value) ? value : "无";
|
var datas = stuffItemCache.Get(temp, new ObservableCollection<string> { "无" });
|
ccc(ref _stuffItems, datas, "stuffItems");
|
ccc(ref _jgjType, temp);
|
UpdateField("jgjType", temp);
|
}
|
}
|
|
private string _stuff;
|
[PropertySettingAttr(Name = NameConstant.stuff)]
|
public string stuff
|
{
|
get => _stuff;
|
set
|
{
|
string temp = value;// stuffItems.Contains(value) ? value : "无";
|
var sDatas = surfaceItemCache.Get($"{jgjType}_{temp}", new ObservableCollection<string> { "无" });
|
var hDatas = heatItemCache.Get($"{jgjType}_{temp}", new ObservableCollection<string> { "无" });
|
ccc(ref _surfaceItems, sDatas, "surfaceItems");
|
ccc(ref _heatItems, hDatas, "heatItems");
|
ccc(ref _stuff, temp);
|
}
|
}
|
|
private string _surface;
|
[PropertySettingAttr(Name = NameConstant.surface)]
|
public string surface
|
{
|
get => _surface;
|
set
|
{
|
string temp = value;// surfaceItems.Contains(value) ? value : "无";
|
ccc(ref _surface, temp);
|
}
|
}
|
|
private string _heat;
|
[PropertySettingAttr(Name = NameConstant.heat)]
|
public string heat
|
{
|
get => _heat;
|
set
|
{
|
string temp = value;// heatItems.Contains(value) ? value : "无";
|
ccc(ref _heat, temp);
|
}
|
}
|
|
private string _weight = "";
|
[PropertySettingAttr(Name = NameConstant.weight, NeedSave = false)]
|
public string weight
|
{
|
get => CustomPropertyUtil.GetMass(doc);
|
set
|
{
|
ccc(ref _weight, value);
|
}
|
}
|
|
[PropertySettingAttr(Name = NameConstant.weight, NeedInit = false)]
|
public string weightEval
|
{
|
get => doc == null ? null : $"\"SW-质量@{Path.GetFileName(doc.GetPathName())}\"";
|
set { }
|
}
|
|
private string _designer = "";
|
[PropertySettingAttr(Name = NameConstant.designer)]
|
public string designer
|
{
|
get => _designer;
|
set
|
{
|
RaiseAndSetIfChanged(ref _designer, value);
|
}
|
}
|
|
private string _version = "";
|
[PropertySettingAttr(Name = NameConstant.version)]
|
public string version
|
{
|
get => _version;
|
set
|
{
|
RaiseAndSetIfChanged(ref _version, value);
|
}
|
}
|
|
private string _remark = "";
|
[PropertySettingAttr(Name = NameConstant.remark)]
|
public string remark
|
{
|
get => _remark;
|
set
|
{
|
RaiseAndSetIfChanged(ref _remark, value);
|
}
|
}
|
|
private string _docType = "";
|
[PropertySettingAttr(Name = NameConstant.docType, defaultValue = "加工件")]
|
public string docType
|
{
|
get => _docType;
|
set
|
{
|
string temp = value;
|
if (NameConstant.SpecialJgjType.Contains(jgjType))
|
{
|
temp = "加工件";
|
}
|
ccc(ref _docType, temp);
|
}
|
}
|
|
private string _versionChange = "0";
|
[PropertySettingAttr(Name = NameConstant.versionChange, defaultValue = "0")]
|
public string versionChange
|
{
|
get => _versionChange;
|
set
|
{
|
RaiseAndSetIfChanged(ref _versionChange, value);
|
RaiseAndSetIfChanged(ref _versionChangeBind, value == "1", "versionChangeBind");
|
}
|
}
|
|
private bool _versionChangeBind = false;
|
[PropertySettingAttr(Name = NameConstant.versionChange, NeedSave = false, NeedInit = false)]
|
public bool versionChangeBind
|
{
|
get => _versionChangeBind;
|
set
|
{
|
RaiseAndSetIfChanged(ref _versionChangeBind, value);
|
RaiseAndSetIfChanged(ref _versionChange, value ? "1" : "0", "versionChange");
|
}
|
}
|
|
private bool changed;
|
|
private string _size = "";
|
[PropertySettingAttr(Name = NameConstant.size)]
|
public string size
|
{
|
get => _size;
|
set
|
{
|
RaiseAndSetIfChanged(ref _size, value);
|
}
|
}
|
#endregion
|
|
public JgjModulePanel()
|
{
|
InitializeComponent();
|
DataContext = this;
|
}
|
|
/// <summary>
|
/// 设置属性
|
/// </summary>
|
/// <param name="properties"></param>
|
/// <param name="errMsg"></param>
|
/// <returns></returns>
|
public bool SetProperties(ModelDoc2 doc, object properties, bool docChange, out string errMsg)
|
{
|
this.doc = doc;
|
var data = docChange ? InitData : null;
|
return NameConstant.SetProperties(this, properties, data, out errMsg);
|
}
|
|
public bool SaveDoc(ref int err, ref int warn)
|
{
|
Dictionary<string, string> props = GetAllProperties();
|
CustomPropertyUtil.SetCustomProperties(doc, props);
|
if (doc.Save3((int)swSaveAsOptions_e.swSaveAsOptions_AvoidRebuildOnSave,
|
ref err, ref warn))
|
{
|
InitData = props;
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 获取属性
|
/// </summary>
|
/// <returns></returns>
|
public Dictionary<string, string> GetAllProperties()
|
{
|
return NameConstant.GetAllProperties(this);
|
}
|
|
public bool UpdateSingleProperty(string name, string value)
|
{
|
changed = NameConstant.UpdateSingleProperty(this, name, value);
|
return changed;
|
}
|
|
public bool SetSettings(object settings)
|
{
|
Dictionary<string, JgjType> datas = settings as Dictionary<string, JgjType>;
|
this.datas = datas;
|
|
stuffItemCache = new Dictionary<string, ObservableCollection<string>>();
|
|
surfaceItemCache = new Dictionary<string, ObservableCollection<string>>();
|
|
heatItemCache = new Dictionary<string, ObservableCollection<string>>();
|
|
ObservableCollection<string> jgjTypes = new ObservableCollection<string> { "无" };
|
|
foreach (string key in datas.Keys)
|
{
|
jgjTypes.Add(key);
|
JgjType type = datas[key];
|
ObservableCollection<string> stuffs = new ObservableCollection<string> { "无" };
|
|
Dictionary<string, StuffType> stuffDatas = type.stuffMap;
|
foreach (string stuff in stuffDatas.Keys)
|
{
|
if (stuff != "无")
|
{
|
stuffs.Add(stuff);
|
}
|
StuffType stuffType = stuffDatas[stuff];
|
string key2 = key + "_" + stuff;
|
|
ObservableCollection<string> surfaces = new ObservableCollection<string> { "无" };
|
ObservableCollection<string> heats = new ObservableCollection<string> { "无" };
|
foreach (string surface in stuffType.surfaceParam)
|
{
|
if (surface != "无") surfaces.Add(surface);
|
}
|
foreach (string heat in stuffType.heatParam)
|
{
|
if (heat != "无") heats.Add(heat);
|
}
|
surfaceItemCache.Add(key2, surfaces);
|
heatItemCache.Add(key2, heats);
|
}
|
stuffItemCache.Add(key, stuffs);
|
if (!stuffItemCache.ContainsKey("无"))
|
{
|
stuffItemCache.Add("无", new ObservableCollection<string> { "无" });
|
}
|
}
|
|
Dispatcher.Invoke(() =>
|
{
|
jgjTypeItems = jgjTypes;
|
});
|
return true;
|
}
|
|
public bool ClearAllProperties(out string ErrMsg)
|
{
|
ErrMsg = null;
|
Dispatcher.Invoke(() =>
|
{
|
|
});
|
return true;
|
}
|
|
public bool GetDocChanged()
|
{
|
return NameConstant.CompareWithInit(this, InitData);
|
}
|
|
public bool ResetProperty(out string errMsg)
|
{
|
return SetProperties(doc, InitData, false, out errMsg);
|
}
|
|
private void stuffInput_DropDownOpened(object sender, System.EventArgs e)
|
{
|
ComboBox comboBox = sender as ComboBox;
|
if (comboBox == null) return;
|
if (comboBox.Name == "stuffInput")
|
{
|
stuffItems = stuffItemCache.Get(jgjType, new ObservableCollection<string> { "无" });
|
}
|
else if (comboBox.Name == "surfaceInput")
|
{
|
string key = $"{jgjType}_{stuff}";
|
surfaceItems = surfaceItemCache.Get(key, new ObservableCollection<string> { "无" });
|
}
|
else if (comboBox.Name == "heatInput")
|
{
|
string key = $"{jgjType}_{stuff}";
|
heatItems = heatItemCache.Get(key, new ObservableCollection<string> { "无" });
|
}
|
}
|
|
private void UpdateField(string field, string value)
|
{
|
if (field == "jgjType")
|
{
|
if (NameConstant.SpecialJgjType.Contains(value))
|
{
|
docType = "加工件";
|
DocTypeEnabled = false;
|
}
|
else
|
{
|
DocTypeEnabled = true;
|
}
|
return;
|
}
|
}
|
}
|
}
|