public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { bool showDimensions = true; ViewerSolution sv = new ViewerSolution(Solution); sv.Draw(graphics, showDimensions); }
protected void InsertImage(Analysis analysis, int colIndex) { if (!(analysis is AnalysisLayered analysisHomo)) { return; } var stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); var graphics = new Graphics3DImage(new Size(768, 768)) { FontSizeRatio = 0.01f, CameraPosition = Graphics3D.Corner_0 }; using (ViewerSolution sv = new ViewerSolution(analysisHomo.SolutionLay)) sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png); Range imageCell = (Range)WSheet.Cells[RowIndex, colIndex]; imageCell.RowHeight = 128; imageCell.ColumnWidth = 24; WSheet.Shapes.AddPicture(stackImagePath, LinkToFile: MsoTriState.msoFalse, SaveWithDocument: MsoTriState.msoCTrue, Left: (int)imageCell.Left + 1, Top: (int)imageCell.Top + 1, Width: (int)imageCell.Width - 2, Height: (int)imageCell.Height - 2); }
protected void InsertImage(Analysis analysis, int colIndex) { try { if (analysis is AnalysisLayered analysisHomo) { var stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); var graphics = new Graphics3DImage(new Size(768, 768)) { FontSizeRatio = 0.01f, CameraPosition = Graphics3D.Corner_0 }; using (ViewerSolution sv = new ViewerSolution(analysisHomo.SolutionLay)) sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png); Range imageCell = (Range)WSheet.Cells[RowIndex, colIndex]; imageCell.RowHeight = 128; imageCell.ColumnWidth = 24; WSheet.Shapes.AddPicture(stackImagePath, LinkToFile: MsoTriState.msoFalse, SaveWithDocument: MsoTriState.msoCTrue, Left: float.Parse(imageCell.Left.ToString()) + 1, Top: float.Parse(imageCell.Top.ToString()) + 1, Width: float.Parse(imageCell.Width.ToString()) - 2, Height: float.Parse(imageCell.Height.ToString()) - 2 ); } } catch (Exception ex) { _log.Error($"Failed to insert image in Excel sheet with error:{ex.Message}"); } }
public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { if (ctrl == graphCtrl) { ViewerSolution vs = new ViewerSolution(_analysis.SolutionLay); vs.Draw(graphics, Transform3D.Identity); } }
public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { Layer2DBrickImp selLayer = SelectedLayer; PalletProperties pallet = SelectedPallet; Packable packable = SelectedPackable; if (null == selLayer || null == packable || null == pallet) return; var analysis = new AnalysisCasePallet(packable, pallet, BuildConstraintSet(), true /*temporary*/); analysis.AddSolution(new List<LayerDesc> { selLayer.LayerDescriptor }); ViewerSolution sv = new ViewerSolution(analysis.SolutionLay); sv.Draw(graphics, Transform3D.Identity); }
public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { if (null == SelectedAnalysis) { return; } try { ViewerSolution sv = new ViewerSolution(SelectedAnalysis.Solution); sv.Draw(graphics, Transform3D.Identity); } catch (Exception ex) { _log.Error(ex.Message); } }
public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { if (null == SelectedAnalysis) { return; } try { AnalysisCasePallet analysis = SelectedAnalysis; if (graphCtrlPack == ctrl) { bool showDimensions = true; // build pack if (analysis.Content is PackProperties packProperties) { var pack = new Pack(0, packProperties) { ForceTransparency = true }; graphics.AddBox(pack); if (showDimensions) { graphics.AddDimensions(new DimensionCube(Vector3D.Zero, pack.Length, pack.Width, pack.Height, Color.Black, true)); if (packProperties.Wrap.Transparent) { graphics.AddDimensions( new DimensionCube( packProperties.InnerOffset , packProperties.InnerLength, packProperties.InnerWidth, packProperties.InnerHeight , Color.Red, false)); } } } } else if (graphCtrlSolution == ctrl) { var sv = new ViewerSolution(SelectedAnalysis.SolutionLay); sv.Draw(graphics, Transform3D.Identity); } } catch (Exception ex) { _log.Error(ex.Message); } }
private void GenerateResult( string name, string description , double length, double width, double height , double?weight , PalletProperties palletProperties , ref int stackCount, ref double loadWeight, ref double totalWeight , ref double stackEfficiency , ref string stackImagePath) { stackCount = 0; totalWeight = 0.0; stackImagePath = string.Empty; // generate case BoxProperties bProperties = new BoxProperties(null, length, width, height); bProperties.ID.SetNameDesc(name, description); if (weight.HasValue) { bProperties.SetWeight(weight.Value); } bProperties.SetColor(Color.Chocolate); bProperties.TapeWidth = new OptDouble(true, Math.Min(UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1), 0.5 * width)); bProperties.TapeColor = Color.Beige; Graphics3DImage graphics = null; if (GenerateImage || GenerateImageInFolder) { // generate image path stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); if (GenerateImageInFolder) { stackImagePath = Path.ChangeExtension(Path.Combine(Path.Combine(DirectoryPathImages, name)), "png"); } graphics = new Graphics3DImage(new Size(ImageSize, ImageSize)) { FontSizeRatio = Settings.Default.FontSizeRatio, CameraPosition = Graphics3D.Corner_0 }; } // compute analysis ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true }); constraintSet.SetMaxHeight(new OptDouble(true, PalletMaximumHeight)); constraintSet.Overhang = Overhang; SolverCasePallet solver = new SolverCasePallet(bProperties, palletProperties); List <Analysis> analyses = solver.BuildAnalyses(constraintSet, false); if (analyses.Count > 0) { Analysis analysis = analyses[0]; stackCount = analysis.Solution.ItemCount; loadWeight = analysis.Solution.LoadWeight; totalWeight = analysis.Solution.Weight; stackEfficiency = analysis.Solution.VolumeEfficiency; if (stackCount <= StackCountMax) { if (GenerateImage || GenerateImageInFolder) { ViewerSolution sv = new ViewerSolution(analysis.Solution); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); } if (GenerateReport) { ReportData inputData = new ReportData(analysis); string outputFilePath = Path.ChangeExtension(Path.Combine(DirectoryPathReports, string.Format("Report_{0}_on_{1}", analysis.Content.Name, analysis.Container.Name)), "doc"); ReportNode rnRoot = null; Margins margins = new Margins(); Reporter reporter = new ReporterMSWord(inputData, ref rnRoot, Reporter.TemplatePath, outputFilePath, margins); } } } if (GenerateImage) { Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png); } }
public void Draw(Graphics3DControl ctrl, Graphics3D graphics) { using (ViewerSolution sv = new ViewerSolution(Solution)) sv.Draw(graphics, Transform3D.Identity); }
private void OnCompute(object sender, EventArgs e) { try { if (Globals.StackBuilderAddIn.Application.ActiveSheet is Excel.Worksheet 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); // ### actually compute result ### // build a case BoxProperties bProperties = new BoxProperties(null, caseLength, caseWidth, caseHeight); bProperties.SetWeight(caseWeight); bProperties.SetColor(Color.Chocolate); bProperties.TapeWidth = new OptDouble(true, UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1)); bProperties.TapeColor = Color.Beige; // build a pallet PalletProperties palletProperties = new PalletProperties(null, PalletTypeName, palletLength, palletWidth, palletHeight) { Weight = palletWeight, 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 <AnalysisHomo> analyses = solver.BuildAnalyses(constraintSet, true); if (analyses.Count > 0) { AnalysisHomo 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.ImageSize, Settings.Default.ImageSize)) { FontSizeRatio = Settings.Default.FontSizeRatio, 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, Settings.Default.ImageLeft / 0.035, Settings.Default.ImageTop / 0.035, Settings.Default.ImageWidth / 0.035, Settings.Default.ImageHeight / 0.035); } // ### } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void GenerateResult( string name, string description , double length, double width, double height, double?weight , PalletProperties palletProperties, Vector2D overhang , ref int stackCount , ref int layerCount, ref int byLayerCount , ref double loadWeight, ref double totalWeight , ref double stackEfficiency , ref string stackImagePath) { stackCount = 0; totalWeight = 0.0; stackImagePath = string.Empty; // generate case var bProperties = new BoxProperties(null, length, width, height); bProperties.ID.SetNameDesc(name, description); if (weight.HasValue) { bProperties.SetWeight(weight.Value); } bProperties.SetColor(Color.Chocolate); bProperties.TapeWidth = new OptDouble(true, Math.Min(UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1), 0.5 * width)); bProperties.TapeColor = Color.Beige; // generate image path if (GenerateImage) { stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); } else if (GenerateImageInFolder) { stackImagePath = Path.ChangeExtension(Path.Combine(DirectoryPathImages, name), "png"); } Graphics3DImage graphics = null; if (GenerateImage || GenerateImageInFolder) { graphics = new Graphics3DImage(new Size(ImageSize, ImageSize)) { FontSizeRatio = 0.01F, CameraPosition = Graphics3D.Corner_0 }; } // compute analysis ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true }); constraintSet.SetMaxHeight(new OptDouble(true, MaxPalletHeight)); constraintSet.Overhang = overhang; SolverCasePallet solver = new SolverCasePallet(bProperties, palletProperties, constraintSet); List <AnalysisLayered> analyzes = solver.BuildAnalyses(false); if (analyzes.Count > 0) { var analysis = analyzes[0]; stackCount = analysis.Solution.ItemCount; loadWeight = analysis.Solution.LoadWeight; totalWeight = analysis.Solution.Weight; stackEfficiency = analysis.Solution.VolumeEfficiency; if (analysis.Solution is SolutionLayered solutionLayered) { layerCount = solutionLayered.LayerCount; if (solutionLayered.Layers.Count > 0) { byLayerCount = solutionLayered.Layers[0].BoxCount; } } if (stackCount <= StackCountMax) { if (GenerateImage || GenerateImageInFolder) { var sv = new ViewerSolution(analysis.SolutionLay); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); } if (GenerateReport) { var inputData = new ReportDataAnalysis(analysis); string outputFilePath = Path.ChangeExtension(Path.Combine(DirectoryPathReports, $"Report_{analysis.Content.Name}_on_{analysis.Container.Name}"), "pdf"); var rnRoot = new ReportNode(Resources.ID_REPORT); var margins = new Margins(); //Reporter reporter = new ReporterMSWord(inputData, ref rnRoot, Settings.Default.ReportTemplatePath/*Reporter.TemplatePath*/, outputFilePath, margins); Reporter.SetFontSizeRatios(0.015F, 0.05F); Reporter reporter = new ReporterPDF(inputData, ref rnRoot, Reporter.TemplatePath, outputFilePath); } } } if (GenerateImage || GenerateImageInFolder) { var bmp = graphics.Bitmap; bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png); } }
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); } // ### }
public static bool GetSolutionByLayer( PackableBrick packableProperties, PalletProperties palletProperties, InterlayerProperties interlayerProperties , ConstraintSetCasePallet constraintSet , LayerDesc layerDesc , Vector3D cameraPosition, bool showCotations, float fontSizeRatio, Size sz , ref int layerCount, ref int caseCount, ref int interlayerCount , ref double weightTotal, ref double weightLoad, ref double?weightNet , ref Vector3D bbLoad, ref Vector3D bbGlob , ref double volumeEfficency, ref double?weightEfficiency , ref string palletMapPhrase , ref byte[] imageBytes , ref string[] errors ) { List <string> lErrors = new List <string>(); try { if (!packableProperties.FitsIn(palletProperties, constraintSet)) { lErrors.Add($"{packableProperties.Name} does not fit in {palletProperties.Name} with given constraint set!"); return(false); } SolutionLayered.SetSolver(new LayerSolver()); var analysis = new AnalysisCasePallet(packableProperties, palletProperties, constraintSet); analysis.AddSolution(new List <LayerDesc>() { layerDesc }); layerCount = analysis.SolutionLay.LayerCount; caseCount = analysis.Solution.ItemCount; interlayerCount = analysis.SolutionLay.LayerCount; weightLoad = analysis.Solution.LoadWeight; weightTotal = analysis.Solution.Weight; OptDouble optNetWeight = analysis.Solution.NetWeight; weightNet = optNetWeight.Activated ? optNetWeight.Value : (double?)null; bbGlob = analysis.Solution.BBoxGlobal.DimensionsVec; bbLoad = analysis.Solution.BBoxLoad.DimensionsVec; volumeEfficency = analysis.Solution.VolumeEfficiency; weightEfficiency = null; if (analysis.Solution.WeightEfficiency.Activated) { weightEfficiency = analysis.Solution.WeightEfficiency.Value; } // generate image path Graphics3DImage graphics = new Graphics3DImage(sz) { FontSizeRatio = fontSizeRatio, CameraPosition = cameraPosition, ShowDimensions = showCotations }; using (ViewerSolution sv = new ViewerSolution(analysis.SolutionLay)) sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; ImageConverter converter = new ImageConverter(); imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[])); // pallet phrase palletMapPhrase = BuildPalletMapPhrase(analysis.SolutionLay); } catch (Exception ex) { lErrors.Add(ex.Message); } errors = lErrors.ToArray(); return(0 == lErrors.Count); }
public void ExportAnalysesToExcel() { // open excel file Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application { Visible = true, DisplayAlerts = false }; Workbooks xlWorkBooks = xlApp.Workbooks; Workbook xlWorkBook = xlWorkBooks.Add(Type.Missing); Worksheet xlWorkSheetCasePallet = xlWorkBook.Worksheets.get_Item(1); // create header xlWorkSheetCasePallet.Cells[1, 1] = "Analysis name"; xlWorkSheetCasePallet.Cells[1, 2] = "Case name"; xlWorkSheetCasePallet.Cells[1, 3] = "Case description"; xlWorkSheetCasePallet.Cells[1, 4] = "Ext. length"; xlWorkSheetCasePallet.Cells[1, 5] = "Ext. width"; xlWorkSheetCasePallet.Cells[1, 6] = "Ext. height"; xlWorkSheetCasePallet.Cells[1, 7] = "Max pallet height"; xlWorkSheetCasePallet.Cells[1, 8] = "Solution case count"; xlWorkSheetCasePallet.Cells[1, 9] = "Layers"; xlWorkSheetCasePallet.Cells[1, 10] = "Cases per layer"; xlWorkSheetCasePallet.Cells[1, 11] = "Load weight"; xlWorkSheetCasePallet.Cells[1, 12] = "Weight"; xlWorkSheetCasePallet.Cells[1, 13] = "Volume efficiency"; xlWorkSheetCasePallet.Cells[1, 14] = "Image"; Range headerRange = xlWorkSheetCasePallet.get_Range("A1", "N1"); headerRange.Font.Bold = true; xlWorkSheetCasePallet.Columns.AutoFit(); // *** get all users from Azure database and write them down int iRowCasePallet = 2; foreach (var analysis in Analyses) { try { if (analysis is AnalysisCasePallet analysisCasePallet) { // analysis name xlWorkSheetCasePallet.Cells[iRowCasePallet, 1] = analysisCasePallet.Name; // case BoxProperties caseProperties = analysisCasePallet.Content as BoxProperties; xlWorkSheetCasePallet.Cells[iRowCasePallet, 2] = caseProperties.Name; xlWorkSheetCasePallet.Cells[iRowCasePallet, 3] = caseProperties.Description; xlWorkSheetCasePallet.Cells[iRowCasePallet, 4] = caseProperties.Length; xlWorkSheetCasePallet.Cells[iRowCasePallet, 5] = caseProperties.Width; xlWorkSheetCasePallet.Cells[iRowCasePallet, 6] = caseProperties.Height; // constraints ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet; xlWorkSheetCasePallet.Cells[iRowCasePallet, 7] = constraintSet.OptMaxHeight.Value; // solution Solution sol = analysisCasePallet.Solution; xlWorkSheetCasePallet.Cells[iRowCasePallet, 8] = sol.ItemCount; xlWorkSheetCasePallet.Cells[iRowCasePallet, 9] = sol.LayerCount; xlWorkSheetCasePallet.Cells[iRowCasePallet, 10] = sol.LayerBoxCount(0); xlWorkSheetCasePallet.Cells[iRowCasePallet, 11] = sol.LoadWeight; xlWorkSheetCasePallet.Cells[iRowCasePallet, 12] = sol.Weight; xlWorkSheetCasePallet.Cells[iRowCasePallet, 13] = sol.VolumeEfficiency; var stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); var graphics = new Graphics3DImage(new Size(768, 768)) { FontSizeRatio = 0.01f, CameraPosition = Graphics3D.Corner_0 }; using (ViewerSolution sv = new ViewerSolution(analysis.Solution)) sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png); Range imageCell = (Range)xlWorkSheetCasePallet.Cells[iRowCasePallet, 14]; imageCell.RowHeight = 128; imageCell.ColumnWidth = 24; xlWorkSheetCasePallet.Shapes.AddPicture(stackImagePath, LinkToFile: MsoTriState.msoFalse, SaveWithDocument: MsoTriState.msoCTrue, Left: imageCell.Left + 1, Top: imageCell.Top + 1, Width: imageCell.Width - 2, Height: imageCell.Height - 2); ++iRowCasePallet; } else if (analysis is AnalysisBoxCase analysisBoxCase) { } else if (analysis is AnalysisCaseTruck analysisCaseTruck) { } else if (analysis is AnalysisCylinderPallet analysisCylinderPallet) { } else if (analysis is AnalysisCylinderCase analysisCylinderCase) { } else if (analysis is AnalysisCylinderTruck analysisCylinderTruck) { } } catch (Exception ex) { _log.Error(ex.ToString()); } } }
private void GenerateResult( string name , double length, double width, double height , double?weight , ref int stackCount, ref double stackWeight, ref double stackEfficiency , ref string stackImagePath) { stackCount = 0; stackWeight = 0.0; stackImagePath = string.Empty; // generate case BoxProperties bProperties = new BoxProperties(null, length, width, height); if (weight.HasValue) { bProperties.SetWeight(weight.Value); } bProperties.SetColor(Color.Chocolate); bProperties.TapeWidth = new OptDouble(true, Math.Min(50.0, 0.5 * width)); bProperties.TapeColor = Color.Beige; Graphics3DImage graphics = null; if (GenerateImage || GenerateImageInFolder) { // generate image path stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); if (GenerateImageInFolder) { stackImagePath = Path.ChangeExtension(Path.Combine(Path.Combine(DirectoryPathImages, name)), "png"); } graphics = new Graphics3DImage(new Size(ImageSize, ImageSize)) { FontSizeRatio = this.FontSizeRatio, CameraPosition = Graphics3D.Corner_0 }; } // compute analysis if (0 == Mode) { ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true }); constraintSet.SetMaxHeight(new OptDouble(true, PalletMaximumHeight)); SolverCasePallet solver = new SolverCasePallet(bProperties, PalletProperties, constraintSet); List <AnalysisLayered> analyses = solver.BuildAnalyses(false); if (analyses.Count > 0) { AnalysisLayered analysis = analyses[0]; stackCount = analysis.Solution.ItemCount; stackWeight = analysis.Solution.Weight; stackEfficiency = analysis.Solution.VolumeEfficiency; if (stackCount <= StackCountMax) { if (GenerateImage || GenerateImageInFolder) { ViewerSolution sv = new ViewerSolution(analysis.Solution as SolutionLayered); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); } if (GenerateReport) { ReportDataAnalysis inputData = new ReportDataAnalysis(analysis); string outputFilePath = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(OutputFilePath), string.Format("Report_{0}_on_{1}", analysis.Content.Name, analysis.Container.Name)), "doc"); ReportNode rnRoot = null; Margins margins = new Margins(); Reporter reporter = new ReporterMSWord(inputData, ref rnRoot, Reporter.TemplatePath, outputFilePath, margins); } } } } else { BoxProperties container = new BoxProperties(null, TruckLength, TruckWidth, TruckHeight, TruckLength, TruckWidth, TruckHeight); Color lblue = Color.LightBlue; container.SetAllColors(new Color[] { lblue, lblue, lblue, lblue, lblue, lblue }); container.SetWeight(0.0); ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(container); constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true }); SolverBoxCase solver = new SolverBoxCase(bProperties, container, constraintSet); List <AnalysisLayered> analyses = solver.BuildAnalyses(false); if (analyses.Count > 0) { AnalysisLayered analysis = analyses[0]; stackCount = analysis.Solution.ItemCount; stackWeight = analysis.Solution.Weight; if ((GenerateImage || GenerateImageInFolder) && stackCount <= StackCountMax) { ViewerSolution sv = new ViewerSolution(analysis.Solution as SolutionLayered); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); } } } if (GenerateImage) { Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png); } }
public static void GetSolution( Vector3D caseDim, double caseWeight, Bitmap bmpTexture, int palletIndex, double palletWeight, double maxPalletHeight, List <BoxPositionIndexed> boxPositions, bool mirrorLength, bool mirrorWidth, List <bool> interlayers, double angle, Size sz, ref byte[] imageBytes, ref int caseCount, ref int layerCount, ref double weightLoad, ref double weightTotal, ref Vector3D bbLoad, ref Vector3D bbGlob ) { SolutionLayered.SetSolver(new LayerSolver()); // case var boxProperties = new BoxProperties(null, caseDim.X, caseDim.Y, caseDim.Z) { TapeColor = Color.Tan, TapeWidth = new OptDouble(true, 50.0) }; if (null != bmpTexture) { double ratio = (double)bmpTexture.Height / bmpTexture.Width; boxProperties.AddTexture(HalfAxis.HAxis.AXIS_X_N, TexturePosition(caseDim.Y, caseDim.Z, ratio), TextureSize(caseDim.Y, caseDim.Z, ratio), 0.0, bmpTexture); boxProperties.AddTexture(HalfAxis.HAxis.AXIS_X_P, TexturePosition(caseDim.Y, caseDim.Z, ratio), TextureSize(caseDim.Y, caseDim.Z, ratio), 0.0, bmpTexture); boxProperties.AddTexture(HalfAxis.HAxis.AXIS_Y_N, TexturePosition(caseDim.X, caseDim.Z, ratio), TextureSize(caseDim.X, caseDim.Z, ratio), 0.0, bmpTexture); boxProperties.AddTexture(HalfAxis.HAxis.AXIS_Y_P, TexturePosition(caseDim.X, caseDim.Z, ratio), TextureSize(caseDim.X, caseDim.Z, ratio), 0.0, bmpTexture); } boxProperties.SetWeight(caseWeight); boxProperties.SetAllColors(Enumerable.Repeat(Color.Beige, 6).ToArray()); // pallet Vector3D palletDim = PalletIndexToDim3D(palletIndex); var palletProperties = new PalletProperties(null, PalletIndexToPalletType(palletIndex), palletDim.X, palletDim.Y, palletDim.Z) { Weight = palletWeight, Color = Color.Yellow }; // constraint set var constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); constraintSet.SetMaxHeight(new OptDouble(true, maxPalletHeight)); // layer 2D var layer2D = new Layer2DBrickExpIndexed(caseDim, new Vector2D(), "", HalfAxis.HAxis.AXIS_Z_P); layer2D.SetPositions(boxPositions); // analysis var analysis = new AnalysisCasePallet(boxProperties, palletProperties, constraintSet); analysis.AddInterlayer(new InterlayerProperties(null, "interlayer", "", palletDim.X, palletDim.Y, 1.0, 0.0, Color.LightYellow)); analysis.AddSolution(layer2D, mirrorLength, mirrorWidth); // solution SolutionLayered sol = analysis.SolutionLay; var solutionItems = sol.SolutionItems; int iCount = solutionItems.Count; for (int i = 0; i < iCount; ++i) { solutionItems[i].InterlayerIndex = ((i < interlayers.Count) && interlayers[i]) ? 0 : -1; } if (iCount < interlayers.Count && interlayers[iCount]) { analysis.PalletCapProperties = new PalletCapProperties(null, "palletcap", "", palletDim.X, palletDim.Y, 1, palletDim.X, palletDim.Y, 0.0, 0.0, Color.LightYellow); } layerCount = analysis.SolutionLay.LayerCount; caseCount = analysis.Solution.ItemCount; weightLoad = analysis.Solution.LoadWeight; weightTotal = analysis.Solution.Weight; bbGlob = analysis.Solution.BBoxGlobal.DimensionsVec; bbLoad = analysis.Solution.BBoxLoad.DimensionsVec; // generate image path Graphics3DImage graphics = new Graphics3DImage(sz) { BackgroundColor = Color.Transparent, FontSizeRatio = ConfigSettings.FontSizeRatio, ShowDimensions = true }; graphics.SetCameraPosition(10000.0, angle, 45.0); using (ViewerSolution sv = new ViewerSolution(analysis.SolutionLay)) sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; ImageConverter converter = new ImageConverter(); imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[])); }
public static void Export( Vector3D caseDim, double caseWeight, int palletIndex, double palletWeight, int noLayers, List <BoxPositionIndexed> listBoxPositionIndexed, bool mirrorLength, bool mirrorWidth, List <bool> interlayers, ref byte[] fileBytes, System.Drawing.Imaging.ImageFormat imageFormat, ref byte[] imageFileBytes) { SolutionLayered.SetSolver(new LayerSolver()); // case var boxProperties = new BoxProperties(null, caseDim.X, caseDim.Y, caseDim.Z) { TapeColor = Color.LightGray, TapeWidth = new OptDouble(true, 50.0) }; boxProperties.SetWeight(caseWeight); boxProperties.SetAllColors(Enumerable.Repeat(Color.Beige, 6).ToArray()); // pallet Vector3D palletDim = PalletIndexToDim3D(palletIndex); var palletProperties = new PalletProperties(null, PalletIndexToPalletType(palletIndex), palletDim.X, palletDim.Y, palletDim.Z) { Weight = palletWeight, Color = Color.Yellow }; // constraint set var constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); constraintSet.OptMaxLayerNumber = noLayers; // layer var layer2D = new Layer2DBrickExpIndexed(caseDim, new Vector2D(palletDim.X, palletDim.Y), "", HalfAxis.HAxis.AXIS_Z_P); layer2D.SetPositions(listBoxPositionIndexed); // analysis var analysis = new AnalysisCasePallet(boxProperties, palletProperties, constraintSet); analysis.AddInterlayer(new InterlayerProperties(null, "interlayer", "", palletDim.X, palletDim.Y, 1.0, 0.0, Color.LightYellow)); analysis.AddSolution(layer2D, mirrorLength, mirrorWidth); SolutionLayered sol = analysis.SolutionLay; var solutionItems = sol.SolutionItems; int iCount = solutionItems.Count; for (int i = 0; i < iCount; ++i) { solutionItems[i].InterlayerIndex = ((i < interlayers.Count) && interlayers[i]) ? 0 : -1; } if (iCount < interlayers.Count && interlayers[iCount]) { analysis.PalletCapProperties = new PalletCapProperties( null, "palletCap", "", palletDim.X, palletDim.Y, 1, palletDim.X, palletDim.Y, 0.0, 0.0, Color.LightYellow); } // export var exporter = ExporterFactory.GetExporterByName("csv (TechnologyBSA)"); exporter.PositionCoordinateMode = Exporter.CoordinateMode.CM_COG; Stream stream = new MemoryStream(); exporter.ExportIndexed(analysis, ref stream); // save stream to file using (var br = new BinaryReader(stream)) fileBytes = br.ReadBytes((int)stream.Length); // image var graphics = new Graphics3DImage(ConfigSettings.ExportImageSize) { CameraPosition = Graphics3D.Corner_0, ShowDimensions = ConfigSettings.ExportShowDimensions }; using (ViewerSolution sv = new ViewerSolution(analysis.SolutionLay)) sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); imageFileBytes = ImageToByteArray(graphics.Bitmap, imageFormat); }
public static bool GetBestSolution(PackableBrick packableProperties, BoxProperties caseProperties, InterlayerProperties interlayer , ConstraintSetBoxCase constraintSet, bool allowMultipleLayerOrientations , Vector3D cameraPosition, bool showCotations, float fontSizeRatio, Size sz , ref int layerCount, ref int caseCount, ref int interlayerCount , ref double weightTotal, ref double weightLoad, ref double?weightNet , ref Vector3D bbLoad, ref Vector3D bbGlob , ref double volumeEfficency, ref double?weightEfficiency , ref byte[] imageBytes , ref string[] errors ) { List <string> lErrors = new List <string>(); if (!packableProperties.FitsIn(caseProperties, constraintSet)) { lErrors.Add($"{packableProperties.Name} does not fit in {caseProperties.Name} with given constraint set!"); return(false); } try { SolverBoxCase solver = new SolverBoxCase(packableProperties, caseProperties); List <Analysis> analyses = solver.BuildAnalyses(constraintSet, allowMultipleLayerOrientations); if (analyses.Count > 0) { Analysis analysis = analyses[0]; layerCount = analysis.Solution.LayerCount; caseCount = analysis.Solution.ItemCount; interlayerCount = analysis.Solution.LayerCount; weightLoad = analysis.Solution.LoadWeight; weightTotal = analysis.Solution.Weight; OptDouble optNetWeight = analysis.Solution.NetWeight; weightNet = optNetWeight.Activated ? optNetWeight.Value : (double?)null; bbGlob = analysis.Solution.BBoxGlobal.DimensionsVec; bbLoad = analysis.Solution.BBoxLoad.DimensionsVec; volumeEfficency = analysis.Solution.VolumeEfficiency; weightEfficiency = null; if (analysis.Solution.WeightEfficiency.Activated) { weightEfficiency = analysis.Solution.WeightEfficiency.Value; } // generate image path Graphics3DImage graphics = new Graphics3DImage(sz) { FontSizeRatio = fontSizeRatio, CameraPosition = cameraPosition, ShowDimensions = showCotations }; ViewerSolution sv = new ViewerSolution(analysis.Solution); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; ImageConverter converter = new ImageConverter(); imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[])); } else { lErrors.Add("No solution found!"); } } catch (Exception ex) { lErrors.Add(ex.Message); } errors = lErrors.ToArray(); return(0 == lErrors.Count); }
public static void GetSolution( Vector3D caseDim, double caseWeight, Vector3D palletDim, double palletWeight, double maxPalletHeight, List <BoxPosition> boxPositions, bool alternateLayer, bool interlayerBottom, bool interlayerIntermediate, bool interlayerTop, double angle, ref byte[] imageBytes, ref int caseCount, ref int layerCount, ref double weightLoad, ref double weightTotal, ref Vector3D bbLoad, ref Vector3D bbGlob ) { SolutionLayered.SetSolver(new LayerSolver()); // case var boxProperties = new BoxProperties(null, caseDim.X, caseDim.Y, caseDim.Z) { TapeColor = Color.LightGray, TapeWidth = new OptDouble(true, 50.0) }; boxProperties.SetWeight(caseWeight); boxProperties.SetAllColors(Enumerable.Repeat(Color.Beige, 6).ToArray()); // pallet var palletProperties = new PalletProperties(null, "EUR2", palletDim.X, palletDim.Y, palletDim.Z) { Weight = palletWeight, Color = Color.Yellow }; // constraint set var constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); constraintSet.SetMaxHeight(new OptDouble(true, maxPalletHeight)); // layer 2D var layer2D = new Layer2DBrickExp(caseDim, new Vector2D(), "", HalfAxis.HAxis.AXIS_Z_P); layer2D.SetPositions(boxPositions); // analysis var analysis = new AnalysisCasePallet(boxProperties, palletProperties, constraintSet); analysis.AddInterlayer(new InterlayerProperties(null, "interlayer", "", palletDim.X, palletDim.Y, 1.0, 0.0, Color.LightYellow)); analysis.AddSolution(layer2D, alternateLayer); if (interlayerTop) { analysis.PalletCapProperties = new PalletCapProperties(null, "palletcap", "", palletDim.X, palletDim.Y, 1, palletDim.X, palletDim.Y, 0.0, 0.0, Color.LightYellow); } // solution SolutionLayered sol = analysis.SolutionLay; var solutionItems = sol.SolutionItems; int iCount = solutionItems.Count; for (int i = 0; i < iCount; ++i) { bool hasInterlayer = (i == 0 && interlayerBottom) || (i != 0 && interlayerIntermediate); solutionItems[i].InterlayerIndex = hasInterlayer ? 0 : -1; } layerCount = analysis.SolutionLay.LayerCount; caseCount = analysis.Solution.ItemCount; weightLoad = analysis.Solution.LoadWeight; weightTotal = analysis.Solution.Weight; bbGlob = analysis.Solution.BBoxGlobal.DimensionsVec; bbLoad = analysis.Solution.BBoxLoad.DimensionsVec; // generate image path Graphics3DImage graphics = new Graphics3DImage(new Size(500, 500)) { FontSizeRatio = ConfigSettings.FontSizeRatio, ShowDimensions = true }; graphics.SetCameraPosition(10000.0, angle, 45.0); using (ViewerSolution sv = new ViewerSolution(analysis.SolutionLay)) sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; ImageConverter converter = new ImageConverter(); imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[])); }