private void FormNewAnalysis_FormClosing(object sender, FormClosingEventArgs e) { try { // overhang Settings.Default.OverhangX = OverhangX; Settings.Default.OverhangY = OverhangY; // allowed position box Settings.Default.AllowVerticalX = AllowVerticalX; Settings.Default.AllowVerticalY = AllowVerticalY; Settings.Default.AllowVerticalZ = AllowVerticalZ; // alternate / aligned layers Settings.Default.AllowAlignedLayer = AllowAlignedLayers; Settings.Default.AllowAlternateLayer = AllowAlternateLayers; // allowed patterns Settings.Default.AllowedPatterns = AllowedPatternsString; // Maximum pallet height / weight Settings.Default.MaximumPalletHeight = UnitsManager.ConvertLengthTo(MaximumPalletHeight, UnitsManager.UnitSystem.UNIT_METRIC1); Settings.Default.MaximumPalletWeight = UnitsManager.ConvertMassTo(MaximumPalletWeight, UnitsManager.UnitSystem.UNIT_METRIC1); // window position if (null == Settings.Default.FormNewAnalysisPosition) { Settings.Default.FormNewAnalysisPosition = new WindowSettings(); } Settings.Default.FormNewAnalysisPosition.Record(this); } catch (Exception ex) { _log.Error(ex.ToString()); } }
protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); // save settings // default pallet height Settings.Default.PalletHeight = MaximumPalletHeight; // default wall numbers and thickness Settings.Default.OptHasWrapper = HasWrapper; Settings.Default.NumberWallsLength = uCtrlWrapperWalls.NoX; Settings.Default.NumberWallsWidth = uCtrlWrapperWalls.NoY; Settings.Default.NumberWallsHeight = uCtrlWrapperWalls.NoZ; Settings.Default.WrapperThickness = WrapperWallThickness; Settings.Default.WrapperSurfMass = WrapperWallSurfMass; Settings.Default.OptHasTray = HasTray; Settings.Default.TrayThickness = UnitsManager.ConvertLengthTo(TrayWallThickness, UnitsManager.UnitSystem.UNIT_METRIC1); Settings.Default.TrayHeight = UnitsManager.ConvertLengthTo(TrayHeight, UnitsManager.UnitSystem.UNIT_METRIC1); // default number of boxes Settings.Default.NumberBoxesPerCase = (int)nudNumber.Value; // default wrapper type Settings.Default.WrapperType = cbWrapperType.SelectedIndex; // window position Settings.Default.FormOptimizeCasePosition ??= new WindowSettings(); Settings.Default.FormOptimizeCasePosition.Record(this); }
private static bool PalletMatchesDimensionsInMM(PalletProperties palletProperties, double length, double width) { double lengthInMM = UnitsManager.ConvertLengthTo(palletProperties.Length, UnitsManager.UnitSystem.UNIT_METRIC1); double widthInMM = UnitsManager.ConvertLengthTo(palletProperties.Width, UnitsManager.UnitSystem.UNIT_METRIC1); return((Math.Abs(lengthInMM - length) < 1.0 && Math.Abs(widthInMM - width) < 1.0) || (Math.Abs(lengthInMM - width) < 1.0 && Math.Abs(widthInMM - length) < 1.0)); }
private void FormNewAnalysisCylinder_FormClosing(object sender, FormClosingEventArgs e) { try { // window position if (null == Settings.Default.FormNewAnalysisPosition) { Settings.Default.FormNewAnalysisPosition = new WindowSettings(); } Settings.Default.FormNewAnalysisPosition.Record(this); // Maximum pallet height / weight Settings.Default.MaximumPalletHeight = UnitsManager.ConvertLengthTo(MaximumPalletHeight, UnitsManager.UnitSystem.UNIT_METRIC1); Settings.Default.MaximumPalletWeight = UnitsManager.ConvertMassTo(MaximumPalletWeight, UnitsManager.UnitSystem.UNIT_METRIC1); } catch (Exception ex) { _log.Error(ex.ToString()); } }
public void Compute() { if (!(Globals.StackBuilderAddIn.Application.ActiveSheet is Excel.Worksheet xlSheet)) { return; } Console.WriteLine($"Sheet name = {xlSheet.Name}"); var caseLength = ReadDouble(xlSheet, Settings.Default.CellCaseLength, Resources.ID_CASE_LENGTH); var caseWidth = ReadDouble(xlSheet, Settings.Default.CellCaseWidth, Resources.ID_CASE_WIDTH); var caseHeight = ReadDouble(xlSheet, Settings.Default.CellCaseHeight, Resources.ID_CASE_HEIGHT); var caseWeight = ReadDouble(xlSheet, Settings.Default.CellCaseWeight, Resources.ID_CASE_WEIGHT); var palletLength = ReadDouble(xlSheet, Settings.Default.CellPalletLength, Resources.ID_PALLET_LENGTH); var palletWidth = ReadDouble(xlSheet, Settings.Default.CellPalletWidth, Resources.ID_PALLET_WIDTH); var palletHeight = ReadDouble(xlSheet, Settings.Default.CellPalletHeight, Resources.ID_PALLET_HEIGHT); var palletWeight = ReadDouble(xlSheet, Settings.Default.CellPalletWeight, Resources.ID_PALLET_WEIGHT); var palletMaximumHeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletHeight, Resources.ID_CONSTRAINTS_PALLETMAXIHEIGHT); var palletMaximumWeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletWeight, Resources.ID_CONSTRAINTS_PALLETMAXIWEIGHT); var imageLeft = UnitsManager.ConvertLengthTo(Settings.Default.ImageLeft, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035; var imageTop = UnitsManager.ConvertLengthTo(Settings.Default.ImageTop, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035; // delete any existing image with same position foreach (Excel.Shape s in xlSheet.Shapes) { if (Math.Abs(s.Left - imageLeft) < 0.001 && Math.Abs(s.Top - imageTop) < 0.001) { s.Delete(); } } // initialize units UnitsManager.CurrentUnitSystem = (UnitsManager.UnitSystem)Settings.Default.UnitSystem; // ### // build a case var bProperties = new BoxProperties(null, caseLength, caseWidth, caseHeight); bProperties.SetWeight(caseWeight); bProperties.SetColor(Color.Chocolate); bProperties.TapeWidth = new OptDouble(true, 5); bProperties.TapeColor = Color.Beige; // build a pallet var palletProperties = new PalletProperties(null, PalletTypeName, palletLength, palletWidth, palletHeight); palletProperties.Weight = palletWeight; palletProperties.Color = Color.Yellow; // build a constraint set var constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); constraintSet.SetMaxHeight(new OptDouble(true, palletMaximumHeight)); constraintSet.OptMaxWeight = new OptDouble(true, palletMaximumWeight); // use a solver and get a list of sorted analyses + select the best one var solver = new SolverCasePallet(bProperties, palletProperties, constraintSet); var analyses = solver.BuildAnalyses(true); if (analyses.Count > 0) { var analysis = analyses[0]; var caseCount = analysis.Solution.ItemCount; // <- your case count var loadWeight = analysis.Solution.LoadWeight; var totalWeight = analysis.Solution.Weight; // <- your pallet weight // generate image Graphics3DImage graphics = null; // generate image path var stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); graphics = new Graphics3DImage(new Size(Settings.Default.ImageSize, Settings.Default.ImageSize)) { FontSizeRatio = Settings.Default.FontSizeRatio, CameraPosition = Graphics3D.Corner_0 }; var sv = new ViewerSolution(analysis.SolutionLay); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath); // write values WriteInt(xlSheet, Settings.Default.CellNoCases, Resources.ID_RESULT_NOCASES, caseCount); WriteDouble(xlSheet, Settings.Default.CellLoadWeight, Resources.ID_RESULT_LOADWEIGHT, loadWeight); WriteDouble(xlSheet, Settings.Default.CellTotalPalletWeight, Resources.ID_RESULT_TOTALPALLETWEIGHT, totalWeight); // write picture Globals.StackBuilderAddIn.Application.ActiveSheet.Shapes.AddPicture( stackImagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, imageLeft, imageTop, UnitsManager.ConvertLengthTo(Settings.Default.ImageWidth, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035, UnitsManager.ConvertLengthTo(Settings.Default.ImageHeight, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035); } else { MessageBox.Show(Resources.ID_RESULT_NOSOLUTIONFOUND, AppDomain.CurrentDomain.FriendlyName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } // ### }
private void OnOptionsSaving(object sender, EventArgs e) { Properties.Settings.Default.DistanceAboveSelectedLayer = UnitsManager.ConvertLengthTo(uCtrlDistAbove.Value, UnitsManager.UnitSystem.UNIT_METRIC1); Properties.Settings.Default.Save(); }
public void Compute() { Excel.Worksheet xlSheet = Globals.StackBuilderAddIn.Application.ActiveSheet as Excel.Worksheet; if (null != xlSheet) { Console.WriteLine(string.Format("Sheet name = {0}", xlSheet.Name)); double caseLength = ReadDouble(xlSheet, Settings.Default.CellCaseLength, Resources.ID_CASE_LENGTH); double caseWidth = ReadDouble(xlSheet, Settings.Default.CellCaseWidth, Resources.ID_CASE_WIDTH); double caseHeight = ReadDouble(xlSheet, Settings.Default.CellCaseHeight, Resources.ID_CASE_HEIGHT); double caseWeight = ReadDouble(xlSheet, Settings.Default.CellCaseWeight, Resources.ID_CASE_WEIGHT); double palletLength = ReadDouble(xlSheet, Settings.Default.CellPalletLength, Resources.ID_PALLET_LENGTH); double palletWidth = ReadDouble(xlSheet, Settings.Default.CellPalletWidth, Resources.ID_PALLET_WIDTH); double palletHeight = ReadDouble(xlSheet, Settings.Default.CellPalletHeight, Resources.ID_PALLET_HEIGHT); double palletWeight = ReadDouble(xlSheet, Settings.Default.CellPalletWeight, Resources.ID_PALLET_WEIGHT); double palletMaximumHeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletHeight, Resources.ID_CONSTRAINTS_PALLETMAXIHEIGHT); double palletMaximumWeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletWeight, Resources.ID_CONSTRAINTS_PALLETMAXIWEIGHT); // initialize units UnitsManager.CurrentUnitSystem = (UnitsManager.UnitSystem)Properties.Settings.Default.UnitSystem; // ### // build a case BoxProperties bProperties = new BoxProperties(null, caseLength, caseWidth, caseHeight); bProperties.SetWeight(caseWeight); bProperties.SetColor(Color.Chocolate); bProperties.TapeWidth = new OptDouble(true, 5); bProperties.TapeColor = Color.Beige; // build a pallet PalletProperties palletProperties = new PalletProperties(null, PalletTypeName, palletLength, palletWidth, palletHeight); palletProperties.Weight = palletWeight; palletProperties.Color = Color.Yellow; // build a constraint set ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); constraintSet.SetMaxHeight(new OptDouble(true, palletMaximumHeight)); constraintSet.OptMaxWeight = new OptDouble(true, palletMaximumWeight); // use a solver and get a list of sorted analyses + select the best one SolverCasePallet solver = new SolverCasePallet(bProperties, palletProperties); List <Analysis> analyses = solver.BuildAnalyses(constraintSet); if (analyses.Count > 0) { Analysis analysis = analyses[0]; int caseCount = analysis.Solution.ItemCount; // <- your case count double loadWeight = analysis.Solution.LoadWeight; double totalWeight = analysis.Solution.Weight; // <- your pallet weight Graphics3DImage graphics = null; // generate image path string stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); graphics = new Graphics3DImage(new Size(Settings.Default.ImageDef, Settings.Default.ImageDef)); graphics.FontSizeRatio = 0.01f; graphics.CameraPosition = Graphics3D.Corner_0; ViewerSolution sv = new ViewerSolution(analysis.Solution); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath); WriteInt(xlSheet, Settings.Default.CellNoCases, Resources.ID_RESULT_NOCASES, caseCount); WriteDouble(xlSheet, Settings.Default.CellLoadWeight, Resources.ID_RESULT_LOADWEIGHT, loadWeight); WriteDouble(xlSheet, Settings.Default.CellTotalPalletWeight, Resources.ID_RESULT_TOTALPALLETWEIGHT, totalWeight); string filePath = string.Empty; Globals.StackBuilderAddIn.Application.ActiveSheet.Shapes.AddPicture( stackImagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, UnitsManager.ConvertLengthTo(Settings.Default.ImageLeft, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035, UnitsManager.ConvertLengthTo(Settings.Default.ImageTop, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035, UnitsManager.ConvertLengthTo(Settings.Default.ImageWidth, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035, UnitsManager.ConvertLengthTo(Settings.Default.ImageHeight, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035); } // ### } }