private void BuildCommon(FactorioObject target, ImGui gui) { BuildHeader(gui); using (gui.EnterGroup(contentPadding)) { if (InputSystem.Instance.control) { gui.BuildText(target.typeDotName); } if (target.locDescr != null) { gui.BuildText(target.locDescr, wrap: true); } if (!target.IsAccessible()) { gui.BuildText("This " + target.type + " is inaccessible, or it is only accessible through mod or map script. Middle click to open dependency analyser to investigate.", wrap: true); } else if (!target.IsAutomatable()) { gui.BuildText("This " + target.type + " cannot be fully automated. This means that it requires either manual crafting, or manual labor such as cutting trees", wrap: true); } else { gui.BuildText(CostAnalysis.GetDisplayCost(target), wrap: true); } } }
/// <summary> /// 有无待核算体 /// </summary> /// <param name="bodies">待核算体</param> /// <param name="swcostingpart">CostPart参数</param> /// <param name="type">零件类型</param> /// <returns>是否有</returns> private bool hasBody(int bodies, CostPart swcostingpart, HZ_EnumType type) { bool isBody = false; if ((bodies > 0)) { var costingBodies = (object[])swcostingpart.GetBodies(); CostBody swCostingBody = (CostBody)costingBodies[0]; string costingBodyName = swCostingBody.GetName(); // 确保是机加工零件 if ((swCostingBody.GetBodyType() == (int)swcBodyType_e.swcBodyType_Machined)) { isBody = true; switch ((int)swCostingBody.BodyStatus) { case (int)swcBodyStatus_e.swcBodyStatus_Analysed: // 得到模板 m_swCostingAnalysis = swCostingBody.CreateCostAnalysis((selectCostingTemp(type))); m_swCostingAnalysis = swCostingBody.GetCostAnalysis(); break; default: isBody = false; break; } } } return(isBody); }
public override void Build(ImGui gui) { BuildHeader(gui, "Never Enough Items Explorer"); using (gui.EnterRow()) { if (recent.Count == 0) { gui.AllocateRect(0f, 3f); } for (var i = recent.Count - 1; i >= 0; i--) { var elem = recent[i]; if (gui.BuildFactorioObjectButton(elem, 3f)) { changing = elem; } } } using (gui.EnterGroup(new Padding(0.5f), RectAllocator.LeftRow)) { gui.spacing = 0.2f; gui.BuildFactorioObjectIcon(current, size: 3f); gui.BuildText(current.locName, Font.subheader); gui.allocator = RectAllocator.RightAlign; gui.BuildText(CostAnalysis.GetDisplayCost(current)); var amount = CostAnalysis.Instance.GetItemAmount(current); if (amount != null) { gui.BuildText(amount, wrap: true); } } if (gui.BuildFactorioObjectButton(gui.lastRect, current, SchemeColor.Grey)) { SelectObjectPanel.Select(Database.goods.all, "Select item", SetItem); } using (var split = gui.EnterHorizontalSplit(2)) { split.Next(); gui.BuildText("Production:", Font.subheader); productionList.Build(gui); split.Next(); gui.BuildText("Usages:", Font.subheader); usageList.Build(gui); } CheckChanging(); using (gui.EnterRow()) { gui.BuildText("Legend:"); gui.BuildText("This color is flow (Estimated fraction of item production/consumption)"); gui.DrawRectangle(gui.lastRect, SchemeColor.Primary); gui.BuildText("This color is estimated recipe efficiency"); gui.DrawRectangle(gui.lastRect, SchemeColor.Secondary); } }
private void button3_Click(object sender, EventArgs e) { HZ_EnumType type = HZ_EnumType.hz_SimpleTurning; //工艺 int lotSize = 100; //批量大小 int totalNum = 100; //零件总个数 string materialClass = ""; //材料类型 string materialName = ""; //材料名称 HZ_StockType stocktype = HZ_StockType.Block; //配料类型 //Solidworks程序对象 m_SwApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")); //打开文件 m_ModelDoc = openModle(partfilepath); //生成缩略图 // ModelView LoMyModelView; //生成缩略图 //LoMyModelView = m_ModelDoc.ActiveView; //LoMyModelView.FrameState = (int)swWindowState_e.swWindowMaximized; ////m_ModelDoc.ShowNamedView2("*Isometric", 7); //m_ModelDoc.ViewZoomtofit2(); //m_ModelDoc.SaveAs(Application.StartupPath + "\\test.jpg"); //m_ModelDoc.SaveAs(Application.StartupPath + "\\test.stl"); //仅支持零部件 if (m_ModelDoc.GetType() != (int)swDocumentTypes_e.swDocPART) { MessageBox.Show("仅支持零部件!"); return; } bool isSheetMetal = false; bool isSolidBody = false; bool isBlank = false; string strError = string.Empty; //仅支持单实体零部件 if (isMutiBodyOrSheetMetal(ref isBlank, ref isSheetMetal, ref isSolidBody, ref strError)) { MessageBox.Show("仅支持单体零部件!"); return; } //空白图纸 if (isBlank) { MessageBox.Show("空白图纸!"); return; } //不支持钣金件 if (isSheetMetal) { MessageBox.Show("不支持钣金件!"); return; } //是否为实体零件 if (!isSolidBody) { MessageBox.Show("非实体零部件!"); return; } //获取SolidWorks扩展器 ModelDocExtension swModelDocExt = m_ModelDoc.Extension; // 初始化成本输出对象 HZ_CostingOutput CostingOutput = new HZ_CostingOutput(); //详细输出对象 HZ_MassProperty massOutput = new HZ_MassProperty(); // 得到质量属性 Part Mass getMass("", ref massOutput); // 得到外形尺寸属性 getBox(ref massOutput); swCosting = (CostManager)swModelDocExt.GetCostingManager(); swCosting.WaitForUIUpdate(); // 得到 Costing part object swCostingModel = (object)swCosting.CostingModel; swCostingPart = (CostPart)swCostingModel; //设置默认模块参数 //模板,批量大小,零件总个数,材料类型,材料名称,计算方式,配料类型 swcCostingDefaults = (CostingDefaults)swCosting.CostingDefaults; swcCostingDefaults.SetTemplateName((int)swcCostingType_e.swcCostingType_Machining, selectCostingTemp(type)); //单体零件 swcCostingDefaults.LotSizeForSingleBody = lotSize; swcCostingDefaults.TotalNumberOfPartsForSingleBody = totalNum; //多实体文件 swcCostingDefaults.LotSizeForMultibody = lotSize; swcCostingDefaults.TotalNumberOfPartsForMultibody = totalNum; //设置材料以及材料处理方式 swcCostingDefaults.SetMaterialClass((int)swcMethodType_e.swcMethodType_Machining, materialClass); swcCostingDefaults.SetMaterialName((int)swcMethodType_e.swcMethodType_Machining, materialName); swcCostingDefaults.SetManufacturingMethod((int)swcBodyType_e.swcBodyType_Machined, (int)swcBodyType_e.swcBodyType_Machined); swcCostingDefaults.MachiningStockBodyType = (int)stocktype; //获取Cost Body swCostingBody = swCostingPart.SetCostingMethod("", (int)swcMethodType_e.swcMethodType_Machining); if (swCostingBody == null) { MessageBox.Show("制造成本计算失败"); return; } // 创建 common Costing analysis m_swCostingAnalysis = swCostingBody.CreateCostAnalysis(selectCostingTemp(type)); m_swCostingAnalysis = swCostingBody.GetCostAnalysis(); m_swCostingAnalysis.TotalQuantity = totalNum; m_swCostingAnalysis.LotSize = lotSize; CostFeature swCostingFeat = default(CostFeature); CostFeature swCostingNextFeat = default(CostFeature); CostFeature swCostingSubFeat = default(CostFeature); CostFeature swCostingNextSubFeat = default(CostFeature); swCostingFeat = (CostFeature)m_swCostingAnalysis.GetFirstCostFeature(); while ((swCostingFeat != null)) { // swcCostFeatureType_e. Debug.Print(" Feature: " + swCostingFeat.Name); Debug.Print(" Type: " + swCostingFeat.GetType()); Debug.Print(" Setup related: " + swCostingFeat.IsSetup); Debug.Print(" Overridden: " + swCostingFeat.IsOverridden); Debug.Print(" Combined cost: " + swCostingFeat.CombinedCost); Debug.Print(" Combined time: " + swCostingFeat.CombinedTime); swCostingSubFeat = swCostingFeat.GetFirstSubFeature(); while ((swCostingSubFeat != null)) { Debug.Print(" Subfeature: " + swCostingSubFeat.Name); Debug.Print(" Type: " + swCostingSubFeat.GetType()); Debug.Print(" Setup related: " + swCostingSubFeat.IsSetup); Debug.Print(" Overridden: " + swCostingSubFeat.IsOverridden); Debug.Print(" Combined cost: " + swCostingSubFeat.CombinedCost); Debug.Print(" Combined time: " + swCostingSubFeat.CombinedTime); swCostingNextSubFeat = (CostFeature)swCostingSubFeat.GetNextFeature(); swCostingSubFeat = null; swCostingSubFeat = (CostFeature)swCostingNextSubFeat; swCostingNextSubFeat = null; } swCostingNextFeat = swCostingFeat.GetNextFeature(); swCostingFeat = null; swCostingFeat = (CostFeature)swCostingNextFeat; swCostingNextFeat = null; } }
private void button1_Click(object sender, EventArgs e) { DateTime dt1 = DateTime.Now; HZ_EnumType type = HZ_EnumType.hz_SimpleTurning; //工艺 int lotSize = 100; //批量大小 int totalNum = 100; //零件总个数 string materialClass = ""; //材料类型 string materialName = ""; //材料名称 HZ_StockType stocktype = HZ_StockType.Block; //配料类型 //Solidworks程序对象 m_SwApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")); //打开文件 m_ModelDoc = openModle(partfilepath); //生成缩略图 // ModelView LoMyModelView; //生成缩略图 //LoMyModelView = m_ModelDoc.ActiveView; //LoMyModelView.FrameState = (int)swWindowState_e.swWindowMaximized; ////m_ModelDoc.ShowNamedView2("*Isometric", 7); //m_ModelDoc.ViewZoomtofit2(); //m_ModelDoc.SaveAs(Application.StartupPath + "\\test.jpg"); //m_ModelDoc.SaveAs(Application.StartupPath + "\\test.stl"); //仅支持零部件 if (m_ModelDoc.GetType() != (int)swDocumentTypes_e.swDocPART) { MessageBox.Show("仅支持零部件!"); return; } bool isSheetMetal = false; bool isSolidBody = false; bool isBlank = false; string strError = string.Empty; //仅支持单实体零部件 if (isMutiBodyOrSheetMetal(ref isBlank, ref isSheetMetal, ref isSolidBody, ref strError)) { MessageBox.Show("仅支持单体零部件!"); return; } //空白图纸 if (isBlank) { MessageBox.Show("空白图纸!"); return; } //不支持钣金件 if (isSheetMetal) { MessageBox.Show("不支持钣金件!"); return; } //是否为实体零件 if (!isSolidBody) { MessageBox.Show("非实体零部件!"); return; } //获取SolidWorks扩展器 ModelDocExtension swModelDocExt = m_ModelDoc.Extension; // 初始化成本输出对象 HZ_CostingOutput CostingOutput = new HZ_CostingOutput(); //详细输出对象 HZ_MassProperty massOutput = new HZ_MassProperty(); // 得到质量属性 Part Mass getMass("", ref massOutput); // 得到外形尺寸属性 getBox(ref massOutput); swCosting = (CostManager)swModelDocExt.GetCostingManager(); swCosting.WaitForUIUpdate(); // 得到 Costing part object swCostingModel = (object)swCosting.CostingModel; swCostingPart = (CostPart)swCostingModel; //设置默认模块参数 //模板,批量大小,零件总个数,材料类型,材料名称,计算方式,配料类型 swcCostingDefaults = (CostingDefaults)swCosting.CostingDefaults; swcCostingDefaults.SetTemplateName((int)swcCostingType_e.swcCostingType_Machining, selectCostingTemp(type)); //单体零件 swcCostingDefaults.LotSizeForSingleBody = lotSize; swcCostingDefaults.TotalNumberOfPartsForSingleBody = totalNum; //多实体文件 swcCostingDefaults.LotSizeForMultibody = lotSize; swcCostingDefaults.TotalNumberOfPartsForMultibody = totalNum; //设置材料以及材料处理方式 swcCostingDefaults.SetMaterialClass((int)swcMethodType_e.swcMethodType_Machining, materialClass); swcCostingDefaults.SetMaterialName((int)swcMethodType_e.swcMethodType_Machining, materialName); swcCostingDefaults.SetManufacturingMethod((int)swcBodyType_e.swcBodyType_Machined, (int)swcBodyType_e.swcBodyType_Machined); swcCostingDefaults.MachiningStockBodyType = (int)stocktype; //获取Cost Body swCostingBody = swCostingPart.SetCostingMethod("", (int)swcMethodType_e.swcMethodType_Machining); if (swCostingBody == null) { MessageBox.Show("制造成本计算失败"); return; } // 创建 common Costing analysis m_swCostingAnalysis = swCostingBody.CreateCostAnalysis(selectCostingTemp(type)); m_swCostingAnalysis = swCostingBody.GetCostAnalysis(); m_swCostingAnalysis.TotalQuantity = totalNum; m_swCostingAnalysis.LotSize = lotSize; // 得到 Costing bodies int nbrCostingBodies = swCostingPart.GetBodyCount(); if (hasBody(nbrCostingBodies, swCostingPart, type)) { // 得到 machining Costing Analysis 数据 getMachiningCostingAnalysisData(CostingOutput, ref massOutput, stocktype, materialClass, materialName); //得到返回的质量属性 CostingOutput.massProperty = massOutput; // 得到 common Costing analysis 数据 getCommonCostingAnalysisData(CostingOutput, totalNum, lotSize); //孔超标数据,标准 > 5 直接剔除,并+2 元,处理倒角导致成本超高的问题 getCostingFeatures(ref CostingOutput); } DateTime dt2 = DateTime.Now; TimeSpan dt3 = dt2 - dt1; int goTime = dt3.Seconds; MessageBox.Show(goTime.ToString() + "秒"); }
public override void Build(ImGui gui) { BuildHeader(gui, "Never Enough Items Explorer"); using (gui.EnterRow()) { if (recent.Count == 0) { gui.AllocateRect(0f, 3f); } for (var i = recent.Count - 1; i >= 0; i--) { var elem = recent[i]; if (gui.BuildFactorioObjectButton(elem, 3f)) { changing = elem; } } } using (gui.EnterGroup(new Padding(0.5f), RectAllocator.LeftRow)) { gui.spacing = 0.2f; gui.BuildFactorioObjectIcon(current, size: 3f); gui.BuildText(current.locName, Font.subheader); gui.allocator = RectAllocator.RightAlign; gui.BuildText(CostAnalysis.GetDisplayCost(current)); var amount = CostAnalysis.Instance.GetItemAmount(current); if (amount != null) { gui.BuildText(amount, wrap: true); } } if (gui.BuildFactorioObjectButton(gui.lastRect, current, SchemeColor.Grey)) { SelectObjectPanel.Select(Database.goods.all, "Select item", SetItem); } using (var split = gui.EnterHorizontalSplit(2)) { split.Next(); gui.BuildText("Production:", Font.subheader); productionList.Build(gui); split.Next(); gui.BuildText("Usages:", Font.subheader); usageList.Build(gui); } CheckChanging(); using (gui.EnterRow()) { if (gui.BuildLink("What do colored bars mean?")) { MessageBox.Show("How to read colored bars", "Blue bar means estimated production or comsumption of the thing you selected. Blue bar at 50% means that that recipe produces(consumes) 50% of the product.\n\n" + "Orange bar means estimated recipe efficiency. If it is not full, the recipe looks inefficient to YAFC.\n\n" + "It is possible for a recipe to be efficient but not useful - for example a recipe that produces something that is not useful.\n\n" + "YAFC only estimates things that are required for science recipes. So buildings, belts, weapons, fuel - are not shown in estimations.", "Ok"); } if (gui.BuildCheckBox("Current milestones info", atCurrentMilestones, out atCurrentMilestones, allocator: RectAllocator.RightRow)) { var item = current; current = null; SetItem(item); } } }