chr
7 天以前 43a0207d207390abdeeb3ab9155eebf03edd7b1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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
{
    /// <summary>
    /// XingcaiControl.xaml 的交互逻辑
    /// </summary>
    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);
        }
 
        /// <summary>
        /// 展开后重新获取长宽高
        /// </summary>
        public void ReSetProperty2()
        {
            ModelDoc2 swModel = ModelProperty.Doc;
            if (swModel == null)
            {
                return;
            }
            swApp.CommandInProgress = true;
 
            //钣金 变成平板模式的特征
            List<Feature> flatPatternFeatures = new List<Feature>();
 
            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);
        }
    }
}