using PdmSwPlugin.Common.Constants; using PdmSwPlugin.PriceCheck.Model; using PdmSwPlugin.PriceCheck.Param; using PdmSwPlugin.PriceCheck.Util; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Controls; namespace PdmSwPlugin.PriceCheck { /// /// XingcaiControl.xaml 的交互逻辑 /// public partial class BanjinControl : UserControl, PriceCounter { public SldWorks swApp { get; set; } public BanjinModel Model { get; set; } public ModelProperty ModelProperty { get => Model.ModelProperty; set => Model.ModelProperty = value; } // 缓存服务器返回的工艺数据 private Technology tech { get; set; } public BanjinControl(ModelProperty modelProperty, SldWorks swApp) { this.swApp = swApp; Model = new BanjinModel(modelProperty); DataContext = Model; InitializeComponent(); } public double GetPrice(out string message) { return Model.CountTotal(out message); } /// /// 展开后重新获取长宽高 /// public void ReSetProperty2() { ModelDoc2 swModel = ModelProperty.Doc; if (swModel == null) { return; } swApp.CommandInProgress = true; //钣金 变成平板模式的特征 List flatPatternFeatures = new List(); var bendState = swModel.GetBendState(); if (bendState == 0) { swApp.SendMsgToUser("不是钣金零件!"); return; } // swApp.SendMsgToUser("当前状态" + bendState); if (bendState != 2) { //swApp.Command((int)swCommands_e.swCommands_Flatten, ""); //设定当前钣金状态 平板 ,下面这行代码不适用现在的零件 ,只适用于很早之前的零件 //var setStatus = swModel.SetBendState((int)swSMBendState_e.swSMBendStateFlattened); //新钣金均是通过获取零件 var swFeatureManager = swModel.FeatureManager; var flatPatternFolder = (FlatPatternFolder)swFeatureManager.GetFlatPatternFolder(); var featArray = (object[])flatPatternFolder.GetFlatPatterns(); for (int i = featArray.GetLowerBound(0); i <= featArray.GetUpperBound(0); i++) { var feat = (Feature)featArray[i]; flatPatternFeatures.Add(feat); feat.SetSuppression2((int)swFeatureSuppressionAction_e.swUnSuppressFeature, (int)swInConfigurationOpts_e.swThisConfiguration, null); } ModelReader.RefreshModelInfo(swApp, ModelProperty, out string errorInfo); for (int i = featArray.GetLowerBound(0); i <= featArray.GetUpperBound(0); i++) { var feat = (Feature)featArray[i]; flatPatternFeatures.Add(feat); feat.SetSuppression2((int)swFeatureSuppressionAction_e.swSuppressFeature, (int)swInConfigurationOpts_e.swThisConfiguration, null); } } return; } public double DoCount(Technology tech, out string message) { message = null; // 傻逼WPF瞎几把触发事件,真尼玛弱智,垃圾,垃圾垃圾,傻逼 if (tech == null) { return 0; } // ReSetProperty2(); this.tech = tech; TechProp densityProp = tech.props.FirstOrDefault(e => e.name == PriceCheckName.DENSITY); TechProp unitPriceProp = tech.props.FirstOrDefault(e => e.name == PriceCheckName.UNIT_PRICE); TechCraft surfaceCraft = tech.surfaceProcesses.FirstOrDefault(e => e.parameter == PriceCheckName.SURFACE_UP_W); TechCraft heatCraft = tech.heatProcesses.FirstOrDefault(e => e.parameter == PriceCheckName.UNIT_PRICE_CN); ModelProperty.density = densityProp == null ? 0 : double.Parse(densityProp.value); if (ModelProperty.round) { ModelProperty.currentVolume = 3.14 * (ModelProperty.length / 2) * (ModelProperty.length / 2) * ModelProperty.height; } else { ModelProperty.currentVolume = ModelProperty.length * ModelProperty.width * ModelProperty.height; } // 体积是立方mm,转成立方cm,计算出来的单位是g ModelProperty.weight = ModelProperty.currentVolume / 1000000 * ModelProperty.density; // 保存材料单价 ModelProperty.stuffUnitPrice = unitPriceProp == null ? 0 : double.Parse(unitPriceProp.value); // 计算材料费 double cache = 0; if (ModelProperty.round) { cache = 3.14 * (ModelProperty.length / 2 + 2) * (ModelProperty.length / 2 + 2) * (ModelProperty.height + 10) * ModelProperty.density * ModelProperty.stuffUnitPrice / 1000000; } else { cache = (ModelProperty.length + 10) * (ModelProperty.width + 10) * (ModelProperty.height + 5) * ModelProperty.density * ModelProperty.stuffUnitPrice / 1000000; } cache = cache < 5 ? 5 : cache; ModelProperty.stuffPrice = cache; // ModelProperty.stuffUnitPrice * ModelProperty.weight; Model.stuffFee = ModelProperty.stuffPrice.ToString(); ModelProperty.surfaceUnitPrice = surfaceCraft == null ? 0 : double.Parse(surfaceCraft.value); ModelProperty.surfacePrice = ModelProperty.surfaceUnitPrice * ModelProperty.weight; Model.surfaceFee = ModelProperty.surfacePrice.ToString(); // 钣金费直接等于材料单价*净重 double totalPrice = ModelProperty.stuffUnitPrice * ModelProperty.weight;// Model.CountTotal(out message); if (message != null) { Model.price = null; return 0; } Model.price = totalPrice.ToString(); return totalPrice; } private void workFeeTable_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { double totalPrice = Model.CountTotal(out string message); if (message != null) { Model.price = null; } else { Model.price = totalPrice.ToString(); } } private void CheckBox_Changed(object sender, System.Windows.RoutedEventArgs e) { DoCount(tech, out string message); } } }