private List <AnalysisLayered> PackOptimSolutions(ConstraintSetCasePallet constraintSet, int iNumber) { // TODO: better as IEnumerable<>? var analyses = new List <AnalysisLayered>(); foreach (CaseDefinition caseDefinition in CaseDefinitions(iNumber)) { try { // build pack properties Vector3D outerDimensions = caseDefinition.OuterDimensions(BoxProperties, ParamSetPackOpt); var packProperties = new PackProperties( null, BoxProperties, caseDefinition.Arrangement, PackProperties.Orientation(caseDefinition.Dim0, caseDefinition.Dim1), PackProperties.EnuRevSolidLayout.ALIGNED, BuildWrapper(), BuildTray() ); packProperties.ForceOuterDimensions(outerDimensions); // solver var solver = new SolverCasePallet(packProperties, PalletProperties, constraintSet); analyses.AddRange(solver.BuildAnalyses(false)); } catch (Exception ex) { _log.Error(ex.Message); } } // sort caseOptimSolution analyses.Sort(new AnalysisComparer()); return(analyses); }
private item BuildItem(AnalysisLayered analysis) { if (analysis is AnalysisCasePallet analysisCasePallet) { Packable packable = analysisCasePallet.Content; ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet; bool[] orient = constraintSet.AllowedOrientations; StringBuilder sbOrient = new StringBuilder(); foreach (bool b in orient) { sbOrient.Append(b ? "1" : "0"); } return(new item() { id = 1, name = packable.Name, length = packable.OuterDimensions.X, width = packable.OuterDimensions.Y, height = packable.OuterDimensions.Z, weight = packable.Weight, maxWeightOnTop = 0.0, permittedOrientations = sbOrient.ToString() }); } else { throw new Exception(string.Format("Unexpected analysis type : {0}", analysis.GetType())); } }
protected override void ExportAnalysisSpecific(Analysis analysis) { var analysisCasePallet = analysis as AnalysisCasePallet; // analysis name WSheet.Cells[RowIndex, 1] = analysisCasePallet.Name; // case BoxProperties caseProperties = analysisCasePallet.Content as BoxProperties; WSheet.Cells[RowIndex, 2] = caseProperties.Name; WSheet.Cells[RowIndex, 3] = caseProperties.Description; WSheet.Cells[RowIndex, 4] = caseProperties.Length; WSheet.Cells[RowIndex, 5] = caseProperties.Width; WSheet.Cells[RowIndex, 6] = caseProperties.Height; // constraints ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet; WSheet.Cells[RowIndex, 7] = constraintSet.OptMaxHeight.Value; // solution Solution sol = analysisCasePallet.Solution; WSheet.Cells[RowIndex, 8] = sol.ItemCount; WSheet.Cells[RowIndex, 9] = sol.LayerCount; WSheet.Cells[RowIndex, 10] = sol.LayerBoxCount(0); WSheet.Cells[RowIndex, 11] = sol.LoadWeight; WSheet.Cells[RowIndex, 12] = sol.Weight; WSheet.Cells[RowIndex, 13] = sol.VolumeEfficiency; InsertImage(analysis, 14); }
static void Main(string[] args) { bool bestLayersOnly = true; Vector3D dimBox = new Vector3D(400.0, 300.0, 150.0); Vector2D dimContainer = new Vector2D(1200.0, 1000.0); ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetMaxHeight(new OptDouble(true, 1200.0)); try { LayerSolver solver = new LayerSolver(); List <Layer2D> layers = solver.BuildLayers(dimBox, dimContainer, 0.0, constraintSet, bestLayersOnly); int solIndex = 0; foreach (Layer2D layer in layers) { string fileName = string.Format("{0}_{1}.bmp", layer.Name, solIndex++); string filePath = Path.Combine(Path.GetTempPath(), fileName); Console.WriteLine(string.Format("Generating {0}...", filePath)); Graphics2DImage graphics = new Graphics2DImage(new Size(150, 150)); ViewerILayer2D solViewer = new ViewerILayer2D(layer); BoxProperties bProperties = new BoxProperties(null, 400.0, 300.0, 150.0); bProperties.SetColor(Color.Brown); solViewer.Draw(graphics, bProperties, 1500.0, false); graphics.SaveAs(filePath); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private ConstraintSetCasePallet BuildConstraintSet() { ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); constraintSet.SetMaxHeight( new OptDouble(true, MaximumPalletHeight)); constraintSet.Overhang = Overhang; return constraintSet; }
public static bool GetSolutionList( PackableBrick packableProperties, PalletProperties palletProperties, InterlayerProperties interlayerProperties , ConstraintSetCasePallet constraintSet , ref List <AnalysisLayered> analyses) { SolverCasePallet solver = new SolverCasePallet(packableProperties, palletProperties, constraintSet); analyses = solver.BuildAnalyses(false); return(analyses.Count > 0); }
private void onCriterionChanged(object sender, EventArgs args) { ConstraintSetCasePallet constraintSet = _solution.Analysis.ConstraintSet as ConstraintSetCasePallet; constraintSet.SetMaxHeight(new OptDouble(true, uCtrlMaxPalletHeight.Value)); constraintSet.OptMaxWeight = uCtrlOptMaximumWeight.Value; _solution.RebuildSolutionItemList(); // update drawing & grid graphCtrlSolution.Invalidate(); UpdateGrid(); }
private ConstraintSetCasePallet BuildConstraintSet() { // constraint set ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); // overhang constraintSet.Overhang = new Vector2D(uCtrlOverhang.ValueX, uCtrlOverhang.ValueY); // orientations constraintSet.SetAllowedOrientations(uCtrlCaseOrientation.AllowedOrientations); // conditions constraintSet.SetMaxHeight(new OptDouble(true, uCtrlMaximumHeight.Value)); constraintSet.OptMaxWeight = uCtrlOptMaximumWeight.Value; return(constraintSet); }
public static void GetLayers(Vector3D caseDim, double caseWeight, int palletIndex, double palletWeight, int layerNumber, bool bestLayersOnly, ref List <LayerDetails> listLayers) { // case var boxProperties = new BoxProperties(null, caseDim.X, caseDim.Y, caseDim.Z) { TapeColor = Color.Tan, 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 }; // ### define a constraintset object var constraintSet = new ConstraintSetCasePallet() { OptMaxNumber = new OptInt(false, 0), OptMaxWeight = new OptDouble(true, 1000.0), Overhang = Vector2D.Zero, }; constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); constraintSet.OptMaxLayerNumber = layerNumber; Vector3D vPalletDim = palletProperties.GetStackingDimensions(constraintSet); // ### // get a list of all possible layers and fill ListView control ILayerSolver solver = new LayerSolver(); var layers = solver.BuildLayers(boxProperties.OuterDimensions, new Vector2D(vPalletDim.X, vPalletDim.Y), 0.0, constraintSet, bestLayersOnly); foreach (var layer in layers) { listLayers.Add( new LayerDetails( layer.Name, layer.LayerDescriptor.ToString(), layer.Count, layer.NoLayers(caseDim.Z), caseDim.X, caseDim.Y, caseDim.Z, palletIndex) ); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); cbCases.Initialize(_document, this, AnalysisCast?.Content); cbPallets.Initialize(_document, this, AnalysisCast?.PalletProperties); // event handling uCtrlLayerList.LayerSelected += OnLayerSelected; uCtrlLayerList.RefreshFinished += OnLayerSelected; uCtrlLayerListEdited.LayerSelected += OnLayerSelected; if (null == AnalysisCast) { tbName.Text = _document.GetValidNewAnalysisName(ItemDefaultName); tbDescription.Text = tbName.Text; uCtrlCaseOrientation.AllowedOrientations = new bool[] { Settings.Default.AllowVerticalX, Settings.Default.AllowVerticalY, Settings.Default.AllowVerticalZ }; uCtrlMaximumHeight.Value = Settings.Default.MaximumPalletHeight; uCtrlOptMaximumWeight.Value = new OptDouble(false, Settings.Default.MaximumPalletWeight); uCtrlOptMaxNumber.Value = new OptInt(false, 1000); uCtrlOverhang.ValueX = Settings.Default.OverhangX; uCtrlOverhang.ValueY = Settings.Default.OverhangY; } else { tbName.Text = AnalysisBase.Name; tbDescription.Text = AnalysisBase.Description; ConstraintSetCasePallet constraintSet = AnalysisCast.ConstraintSet as ConstraintSetCasePallet; uCtrlCaseOrientation.AllowedOrientations = constraintSet.AllowedOrientations; uCtrlMaximumHeight.Value = constraintSet.OptMaxHeight.Value; uCtrlOptMaximumWeight.Value = constraintSet.OptMaxWeight; uCtrlOptMaxNumber.Value = constraintSet.OptMaxNumber; uCtrlOverhang.ValueX = constraintSet.Overhang.X; uCtrlOverhang.ValueY = constraintSet.Overhang.Y; uCtrlOptSpace.Value = constraintSet.MinimumSpace; } checkBoxBestLayersOnly.Checked = Settings.Default.KeepBestSolutions; OnLayerSelected(this, null); }
private void OnCriterionChanged(object sender, EventArgs args) { try { ConstraintSetCasePallet constraintSet = _solution.Analysis.ConstraintSet as ConstraintSetCasePallet; constraintSet.SetMaxHeight(new OptDouble(true, uCtrlMaxPalletHeight.Value)); constraintSet.OptMaxWeight = uCtrlOptMaximumWeight.Value; constraintSet.OptMaxNumber = uCtrlOptMaxNumber.Value; _solution.RebuildSolutionItemList(); } catch (Exception ex) { _log.Error(ex.ToString()); } // update drawing & grid graphCtrlSolution.Invalidate(); UpdateGrid(); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); cbCases.Initialize(_document, this, null != AnalysisCast ? AnalysisCast.Content : null); cbPallets.Initialize(_document, this, null != AnalysisCast ? AnalysisCast.PalletProperties : null); // event handling uCtrlLayerList.LayerSelected += onLayerSelected; uCtrlLayerList.RefreshFinished += onLayerSelected; uCtrlLayerList.ButtonSizes = new Size(100, 100); if (null == AnalysisCast) { tbName.Text = _document.GetValidNewAnalysisName(ItemDefaultName); tbDescription.Text = tbName.Text; uCtrlCaseOrientation.AllowedOrientations = new bool[] { Settings.Default.AllowVerticalX, Settings.Default.AllowVerticalY, Settings.Default.AllowVerticalZ }; uCtrlMaximumHeight.Value = Settings.Default.MaximumPalletHeight; uCtrlOptMaximumWeight.Value = new OptDouble(false, Settings.Default.MaximumPalletWeight); uCtrlOverhang.ValueX = Settings.Default.OverhangX; uCtrlOverhang.ValueY = Settings.Default.OverhangY; } else { tbName.Text = AnalysisBase.Name; tbDescription.Text = AnalysisBase.Description; ConstraintSetAbstract constraintSet = AnalysisBase.ConstraintSet; uCtrlCaseOrientation.AllowedOrientations = new bool[] { constraintSet.AllowOrientation(HalfAxis.HAxis.AXIS_X_P) , constraintSet.AllowOrientation(HalfAxis.HAxis.AXIS_Y_P) , constraintSet.AllowOrientation(HalfAxis.HAxis.AXIS_Z_P) }; uCtrlMaximumHeight.Value = constraintSet.OptMaxHeight.Value; uCtrlOptMaximumWeight.Value = constraintSet.OptMaxWeight; ConstraintSetCasePallet constraintSetCasePallet = constraintSet as ConstraintSetCasePallet; uCtrlOverhang.ValueX = constraintSetCasePallet.Overhang.X; uCtrlOverhang.ValueY = constraintSetCasePallet.Overhang.Y; } checkBoxBestLayersOnly.Checked = Settings.Default.KeepBestSolutions; }
private void OnBestCombinationClicked(object sender, EventArgs e) { try { if (!(cbCases.SelectedType is PackableBrick packable) || !(cbPallets.SelectedType is PalletProperties palletProperties)) { return; } ConstraintSetCasePallet constraintSet = BuildConstraintSet(); // get best combination List <KeyValuePair <LayerEncap, int> > listLayer = new List <KeyValuePair <LayerEncap, int> >(); LayerSolver.GetBestCombination( packable.OuterDimensions, packable.Bulge, palletProperties.GetStackingDimensions(constraintSet), constraintSet, ref listLayer); // select best layers List <LayerDesc> LayerDesc = new List <LayerDesc>(); foreach (KeyValuePair <LayerEncap, int> kvp in listLayer) { LayerDesc.Add(kvp.Key.LayerDesc); } uCtrlLayerList.SelectLayers(LayerDesc); _item = _document.CreateNewAnalysisCasePallet( ItemName, ItemDescription , SelectedPackable, SelectedPallet , new List <InterlayerProperties>() , null, null, null , constraintSet , listLayer ); Close(); } catch (Exception ex) { _log.Error(ex.ToString()); } }
private ConstraintSetCasePallet BuildConstraintSet() { // constraint set ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet() { Overhang = new Vector2D(uCtrlOverhang.ValueX, uCtrlOverhang.ValueY) }; // orientations if (SelectedPackable is PackProperties || SelectedPackable is BagProperties) { constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); } else { constraintSet.SetAllowedOrientations(uCtrlCaseOrientation.AllowedOrientations); } // conditions constraintSet.SetMaxHeight(new OptDouble(true, uCtrlMaximumHeight.Value)); constraintSet.OptMaxWeight = uCtrlOptMaximumWeight.Value; constraintSet.MinimumSpace = new OptDouble(uCtrlOptSpace.Value); return(constraintSet); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); cbCases.Initialize(_document, this, initiallySelectedItem: AnalysisCast?.Content); cbPallets.Initialize(_document, this, initiallySelectedItem: AnalysisCast?.PalletProperties); if (null == AnalysisCast) { ItemName = _document.GetValidNewAnalysisName(ItemDefaultName); ItemDescription = ItemName; uCtrlCaseOrientation.AllowedOrientations = new bool[] { Settings.Default.AllowVerticalX, Settings.Default.AllowVerticalY, Settings.Default.AllowVerticalZ }; uCtrlMaximumHeight.Value = Settings.Default.MaximumPalletHeight; uCtrlOptMaximumWeight.Value = new OptDouble(false, Settings.Default.MaximumPalletWeight); uCtrlOverhang.ValueX = Settings.Default.OverhangX; uCtrlOverhang.ValueY = Settings.Default.OverhangY; } else { ItemName = AnalysisBase.Name; ItemDescription = AnalysisBase.Description; ConstraintSetCasePallet constraintSet = AnalysisBase.ConstraintSet as ConstraintSetCasePallet; uCtrlCaseOrientation.AllowedOrientations = constraintSet.AllowedOrientations; uCtrlMaximumHeight.Value = constraintSet.OptMaxHeight.Value; uCtrlOptMaximumWeight.Value = constraintSet.OptMaxWeight; uCtrlOverhang.ValueX = constraintSet.Overhang.X; uCtrlOverhang.ValueY = constraintSet.Overhang.Y; } checkBoxBestLayersOnly.Checked = Settings.Default.KeepBestSolutions; // gridSolutions gridSolutions.Selection.SelectionChanged += GridSolutionsSelectionChanged; // graphCtrl graphCtrl.DrawingContainer = this; }
private loadSpace BuildLoadSpace(AnalysisLayered analysis) { if (analysis is AnalysisCasePallet analysisCasePallet) { PalletProperties palletProperties = analysisCasePallet.PalletProperties; ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet; return(new loadSpace() { id = 1, name = palletProperties.Name, length = palletProperties.Length, width = palletProperties.Width, baseHeight = palletProperties.Height, maxLengthOverhang = constraintSet.Overhang.X, maxWidthOverhang = constraintSet.Overhang.Y, maxLoadHeight = constraintSet.OptMaxHeight.Activated ? constraintSet.OptMaxHeight.Value : 0.0, maxLoadWeight = constraintSet.OptMaxWeight.Activated ? constraintSet.OptMaxWeight.Value : 0.0 }); } else { throw new Exception(string.Format("Unexpected analysis type : {0}", analysis.GetType())); } }
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 bool OnFileNew(ref string fileName) { // INTEX data are in cms UnitsManager.CurrentUnitSystem = UnitsManager.UnitSystem.UNIT_METRIC2; string dbPath = Properties.Settings.Default.DatabasePathINTEX; if (string.IsNullOrWhiteSpace(dbPath) || !File.Exists(dbPath)) { OpenFileDialog fd = new OpenFileDialog(); fd.DefaultExt = "xls"; fd.AddExtension = false; fd.Filter = "Microsoft Excel File (*.xls)|*.xls|All files (*.*)|*.*"; fd.FilterIndex = 0; fd.RestoreDirectory = true; fd.CheckFileExists = true; if (DialogResult.OK != fd.ShowDialog()) { return(false); } dbPath = fd.FileName; Properties.Settings.Default.DatabasePathINTEX = dbPath; Properties.Settings.Default.Save(); } // load INTEX excel file List <DataItemINTEX> listItems = null; List <DataPalletINTEX> listPallets = null; List <DataCaseINTEX> listCases = null; try { // Set cursor as hourglass Cursor.Current = Cursors.WaitCursor; // load excel file if (!ExcelDataReader.ExcelDataReader.LoadIntexFile(dbPath, ref listItems, ref listPallets, ref listCases)) { Cursor.Current = Cursors.Default; string message = string.Empty; if (null == listItems || listItems.Count < 1) { message = string.Format(Properties.Resources.ID_ERROR_NOITEMFOUND, "article", "Articles"); } else if (null == listPallets || listPallets.Count < 1) { message = string.Format(Properties.Resources.ID_ERROR_NOITEMFOUND, "palette", "Palettes"); } else { message = string.Format(Properties.Resources.ID_ERROR_INVALIDFILE, dbPath); } if (!string.IsNullOrEmpty(message)) { MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); } } catch (Exception ex) { MessageBox.Show( ex.Message , Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); _log.Error(ex.Message); } finally { Cursor.Current = Cursors.Default; } // do we have a valid list if (null == listItems || 0 == listItems.Count) { return(false); } // proceed : buid project file try { FormNewINTEX form = new FormNewINTEX() { ListItems = listItems, ListPallets = listPallets, ListCases = listCases }; if (DialogResult.OK != form.ShowDialog()) { return(false); } // create document DataItemINTEX item = form._currentItem; Document document = new Document(item._ref, item._description, "INTEX", DateTime.Now, null); // create box properties Color[] colorsCase = new Color[6]; for (int i = 0; i < 6; ++i) { colorsCase[i] = Color.Chocolate; } BoxProperties itemProperties = null; if (!form.UseIntermediatePacking) { itemProperties = document.CreateNewCase( item._ref , $"{item._description};EAN14 : {item._gencode};UPC : {item._UPC};PCB : {item._PCB}" , UnitsManager.ConvertLengthFrom(item._length, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(item._width, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(item._height, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertMassFrom(item._weight, UnitsManager.UnitSystem.UNIT_METRIC2) , colorsCase); } else { itemProperties = document.CreateNewBox( item._ref , string.Format("{0};EAN14 : {1};UPC : {2};PCB : {3}", item._description, item._gencode, item._UPC, item._PCB) , UnitsManager.ConvertLengthFrom(item._length, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(item._width, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(item._height, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertMassFrom(item._weight, UnitsManager.UnitSystem.UNIT_METRIC2) , colorsCase); } itemProperties.TapeColor = Color.Beige; itemProperties.TapeWidth = new OptDouble(true, 5.0); InsertPictogram(ref itemProperties); BoxProperties currentCase = null; if (form.UseIntermediatePacking) { // create cases foreach (DataCaseINTEX dataCase in listCases) { double lengthInt = dataCase._lengthInt > 0 ? dataCase._lengthInt : dataCase._lengthExt - 2 * form.DefaultCaseThickness; double widthInt = dataCase._widthInt > 0 ? dataCase._widthInt : dataCase._widthExt - 2 * form.DefaultCaseThickness; double heightInt = dataCase._heightInt > 0 ? dataCase._heightInt : dataCase._heightExt - 2 * form.DefaultCaseThickness; BoxProperties intercaseProperties = document.CreateNewCase( dataCase._ref , string.Format("{0:0.0}*{1:0.0}*{2:0.0}", dataCase._lengthExt, dataCase._widthExt, dataCase._heightExt) , UnitsManager.ConvertLengthFrom(dataCase._lengthExt, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(dataCase._widthExt, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(dataCase._heightExt, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(lengthInt, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(widthInt, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(heightInt, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertMassFrom(dataCase._weight, UnitsManager.UnitSystem.UNIT_METRIC2) , colorsCase); intercaseProperties.TapeColor = Color.Beige; intercaseProperties.TapeWidth = new OptDouble(true, 5.0); if (string.Equals(form._currentCase._ref, intercaseProperties.Name)) { currentCase = intercaseProperties; } } } // initialize Layer solver SolutionLayered.SetSolver(new LayerSolver()); if (form.UseIntermediatePacking) { // Case constraint set ConstraintSetBoxCase constraintSetBoxCase = new ConstraintSetBoxCase(currentCase); constraintSetBoxCase.AllowedOrientationsString = "1,1,1"; if (constraintSetBoxCase.Valid) { SolverBoxCase solver = new SolverBoxCase(itemProperties, currentCase); Layer2DBrickImp layer = solver.BuildBestLayer(constraintSetBoxCase); List <LayerDesc> layerDescs = new List <LayerDesc>(); if (null != layer) { layerDescs.Add(layer.LayerDescriptor); } // create case analysis AnalysisLayered analysis = document.CreateNewAnalysisBoxCase( string.Format(Properties.Resources.ID_PACKING, item._ref) , item._description , itemProperties , currentCase , null , constraintSetBoxCase , layerDescs); } } // create pallets PalletProperties currentPallet = null; foreach (DataPalletINTEX pallet in listPallets) { PalletProperties palletProperties = document.CreateNewPallet( pallet._type, pallet._type, "EUR" , UnitsManager.ConvertLengthFrom(pallet._length, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(pallet._width, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertLengthFrom(pallet._height, UnitsManager.UnitSystem.UNIT_METRIC2) , UnitsManager.ConvertMassFrom(pallet._weight, UnitsManager.UnitSystem.UNIT_METRIC2) , Color.Gold); if (string.Equals(form._currentPallet._type, pallet._type)) { currentPallet = palletProperties; } } // *** pallet analysis *** // constraint set ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetMaxHeight(new OptDouble(true, UnitsManager.ConvertLengthFrom(form.PalletHeight, UnitsManager.UnitSystem.UNIT_METRIC2))); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); if (constraintSet.Valid) { SolverCasePallet solver = new SolverCasePallet(form.UseIntermediatePacking ? currentCase : itemProperties, currentPallet); Layer2DBrickImp layer = solver.BuildBestLayer(constraintSet); List <LayerDesc> layerDescs = new List <LayerDesc>(); if (null != layer) { layerDescs.Add(layer.LayerDescriptor); } // create analysis AnalysisLayered palletAnalysis = document.CreateNewAnalysisCasePallet( item._ref, item.ToString() , form.UseIntermediatePacking ? currentCase : itemProperties , currentPallet, null, null, null, null, constraintSet, layerDescs); } // save document fileName = form.FilePath; document.Write(form.FilePath); if (null != OpenFile) { OpenFile(fileName); } // return true to let application open return(File.Exists(fileName)); } catch (Exception ex) { _log.Error(ex.Message); return(false); } }
public static bool GetBestSolution( PackableBrick packableProperties, PalletProperties palletProperties, InterlayerProperties interlayer , ConstraintSetCasePallet 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 string palletMapPhrase , ref byte[] imageBytes , ref string[] errors) { List <string> lErrors = new List <string>(); if (!packableProperties.FitsIn(palletProperties, constraintSet)) { lErrors.Add($"{packableProperties.Name} does not fit in {palletProperties.Name} with given constraint set!"); return(false); } try { // use a solver and get a list of sorted analyses + select the best one SolverCasePallet solver = new SolverCasePallet(packableProperties, palletProperties); List <Analysis> analyses = solver.BuildAnalyses(constraintSet, allowMultipleLayerOrientations); if (analyses.Count > 0) { // first solution 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; } palletMapPhrase = BuildPalletMapPhrase(analysis.Solution); Graphics3DImage graphics = null; // generate image path 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 DCSBSolution SB_GetCasePalletBestSolution( DCSBCase sbCase, DCSBPallet sbPallet, DCSBInterlayer sbInterlayer, DCSBConstraintSet sbConstraintSet, DCCompFormat expectedFormat, bool showCotations) { List <string> lErrors = new List <string>(); try { BoxProperties boxProperties = new BoxProperties(null, sbCase.DimensionsOuter.M0, sbCase.DimensionsOuter.M1, sbCase.DimensionsOuter.M2) { InsideLength = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M0 : 0.0, InsideWidth = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M1 : 0.0, InsideHeight = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M2 : 0.0, TapeColor = Color.FromArgb(sbCase.TapeColor), TapeWidth = new OptDouble(sbCase.TapeWidth != 0.0, sbCase.TapeWidth) }; boxProperties.SetWeight(sbCase.Weight); boxProperties.SetNetWeight(new OptDouble(sbCase.NetWeight.HasValue, sbCase.NetWeight.Value)); if (null != sbCase.Colors && sbCase.Colors.Length >= 6) { for (int i = 0; i < 6; ++i) { boxProperties.SetColor((HalfAxis.HAxis)i, Color.FromArgb(sbCase.Colors[i])); } } else { boxProperties.SetAllColors(Enumerable.Repeat <Color>(Color.Chocolate, 6).ToArray()); } PalletProperties palletProperties = null; if (null != sbPallet.Dimensions) { palletProperties = new PalletProperties(null, sbPallet.PalletType, sbPallet.Dimensions.M0, sbPallet.Dimensions.M1, sbPallet.Dimensions.M2) { Weight = sbPallet.Weight, Color = Color.FromArgb(sbPallet.Color) } } ; else { palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 150.0); } InterlayerProperties interlayerProperties = null; if (null != sbInterlayer) { interlayerProperties = new InterlayerProperties(null, sbInterlayer.Name, sbInterlayer.Description, sbInterlayer.Dimensions.M0, sbInterlayer.Dimensions.M1, sbInterlayer.Dimensions.M2, sbInterlayer.Weight, Color.FromArgb(sbInterlayer.Color)); } OptDouble oMaxWeight = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero; OptDouble oMaxHeight = null != sbConstraintSet.MaxHeight ? new OptDouble(sbConstraintSet.MaxHeight.Active, sbConstraintSet.MaxHeight.Value_d) : OptDouble.Zero; OptInt oMaxNumber = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero; ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet() { OptMaxWeight = oMaxWeight, OptMaxNumber = oMaxNumber }; constraintSet.SetMaxHeight(oMaxHeight); constraintSet.SetAllowedOrientations(new bool[] { sbConstraintSet.Orientation.X, sbConstraintSet.Orientation.Y, sbConstraintSet.Orientation.Z }); if (!constraintSet.Valid) { throw new Exception("Invalid constraint set"); } Vector3D cameraPosition = Graphics3D.Corner_0; int layerCount = 0, caseCount = 0, interlayerCount = 0; double weightTotal = 0.0, weightLoad = 0.0, volumeEfficiency = 0.0; double? weightEfficiency = 0.0; double? weightNet = (double?)null; Vector3D bbLoad = new Vector3D(); Vector3D bbGlob = new Vector3D(); string palletMapPhrase = string.Empty; byte[] imageBytes = null; string[] errors = null; if (StackBuilderProcessor.GetBestSolution( boxProperties, palletProperties, interlayerProperties, constraintSet, sbConstraintSet.AllowMultipleLayerOrientations, cameraPosition, showCotations, 0.03f, new Size(expectedFormat.Size.CX, expectedFormat.Size.CY), ref layerCount, ref caseCount, ref interlayerCount, ref weightTotal, ref weightLoad, ref weightNet, ref bbLoad, ref bbGlob, ref volumeEfficiency, ref weightEfficiency, ref palletMapPhrase, ref imageBytes, ref errors)) { foreach (string err in errors) { lErrors.Add(err); } return(new DCSBSolution() { LayerCount = layerCount, CaseCount = caseCount, InterlayerCount = interlayerCount, WeightLoad = weightLoad, WeightTotal = weightTotal, NetWeight = weightNet, BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z), BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z), Efficiency = volumeEfficiency, OutFile = new DCCompFileOutput() { Bytes = imageBytes, Format = new DCCompFormat() { Format = EOutFormat.IMAGE, Size = new DCCompSize() { CX = expectedFormat.Size.CX, CY = expectedFormat.Size.CY } } }, PalletMapPhrase = palletMapPhrase, Errors = lErrors.ToArray() }); } } catch (Exception ex) { lErrors.Add(ex.Message); _log.Error(ex.ToString()); } return(new DCSBSolution() { Errors = lErrors.ToArray() }); }
public DCSBSolution SB_GetBundlePalletBestSolution( DCSBBundle sbBundle, DCSBPallet sbPallet, DCSBInterlayer sbInterlayer , DCSBConstraintSet sbConstraintSet , DCCompFormat expectedFormat, bool showCotations) { List <string> lErrors = new List <string>(); try { BundleProperties bundleProperties = new BundleProperties(null , sbBundle.Name, sbBundle.Description , sbBundle.DimensionsUnit.M0, sbBundle.DimensionsUnit.M1, sbBundle.DimensionsUnit.M2 , sbBundle.UnitWeight, sbBundle.Number , Color.FromArgb(sbBundle.Color)); PalletProperties palletProperties = null; if (null != sbPallet.Dimensions) { palletProperties = new PalletProperties(null, sbPallet.PalletType, sbPallet.Dimensions.M0, sbPallet.Dimensions.M1, sbPallet.Dimensions.M2) { Weight = sbPallet.Weight, Color = Color.FromArgb(sbPallet.Color) } } ; else { palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 150.0); } InterlayerProperties interlayerProperties = null; if (null != sbInterlayer) { interlayerProperties = new InterlayerProperties(null, sbInterlayer.Name, sbInterlayer.Description, sbInterlayer.Dimensions.M0, sbInterlayer.Dimensions.M1, sbInterlayer.Dimensions.M2, sbInterlayer.Weight, Color.FromArgb(sbInterlayer.Color)); } OptDouble oMaxWeight = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero; OptDouble oMaxHeight = null != sbConstraintSet.MaxHeight ? new OptDouble(sbConstraintSet.MaxHeight.Active, sbConstraintSet.MaxHeight.Value_d) : OptDouble.Zero; OptInt oMaxNumber = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero; ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet() { OptMaxWeight = oMaxWeight, OptMaxNumber = oMaxNumber }; constraintSet.SetMaxHeight(oMaxHeight); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); if (!constraintSet.Valid) { throw new Exception("Invalid constraint set"); } Vector3D cameraPosition = Graphics3D.Corner_0; int layerCount = 0, caseCount = 0, interlayerCount = 0; double weightTotal = 0.0, weightLoad = 0.0, volumeEfficiency = 0.0; double? weightEfficiency = 0.0; double? weightNet = (double?)null; Vector3D bbLoad = new Vector3D(); Vector3D bbGlob = new Vector3D(); byte[] imageBytes = null; string[] errors = null; string palletMapPhrase = string.Empty; if (StackBuilderProcessor.GetBestSolution( bundleProperties, palletProperties, interlayerProperties, constraintSet, false, cameraPosition, showCotations, 0.03f, new Size(expectedFormat.Size.CX, expectedFormat.Size.CY), ref layerCount, ref caseCount, ref interlayerCount, ref weightTotal, ref weightLoad, ref weightNet, ref bbLoad, ref bbGlob, ref volumeEfficiency, ref weightEfficiency, ref palletMapPhrase, ref imageBytes, ref errors)) { foreach (string err in errors) { lErrors.Add(err); } return(new DCSBSolution() { LayerCount = layerCount, CaseCount = caseCount, InterlayerCount = interlayerCount, WeightLoad = weightLoad, WeightTotal = weightTotal, NetWeight = weightNet, BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z), BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z), Efficiency = volumeEfficiency, OutFile = new DCCompFileOutput() { Bytes = imageBytes, Format = new DCCompFormat() { Format = EOutFormat.IMAGE, Size = new DCCompSize() { CX = expectedFormat.Size.CX, CY = expectedFormat.Size.CY } } }, Errors = lErrors.ToArray() }); } } catch (Exception ex) { lErrors.Add(ex.Message); _log.Error(ex.ToString()); } return(new DCSBSolution() { Errors = lErrors.ToArray() }); }
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 Export( Vector3D caseDim, double caseWeight, Vector3D palletDim, double palletWeight, double maxPalletHeight, List <BoxPosition> boxPositions, bool mirrorLength, bool mirrorWidth, List <bool> interlayers, ref byte[] fileBytes) { 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 var layer2D = new Layer2DBrickExp(caseDim, new Vector2D(palletDim.X, palletDim.Y), "", 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); 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.Export(analysis, ref stream); // save stream to file using (var br = new BinaryReader(stream)) fileBytes = br.ReadBytes((int)stream.Length); }
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()); } }
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 DCSBSolution[] SB_GetSolutionList( DCSBCase sbCase, DCSBPallet sbPallet, DCSBInterlayer sbInterlayer, DCSBConstraintSet sbConstraintSet) { var listSolution = new List <DCSBSolution>(); var lErrors = new List <string>(); try { BoxProperties boxProperties = new BoxProperties(null, sbCase.DimensionsOuter.M0, sbCase.DimensionsOuter.M1, sbCase.DimensionsOuter.M2) { InsideLength = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M0 : 0.0, InsideWidth = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M1 : 0.0, InsideHeight = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M2 : 0.0, TapeColor = Color.FromArgb(sbCase.TapeColor), TapeWidth = new OptDouble(sbCase.TapeWidth != 0.0, sbCase.TapeWidth) }; boxProperties.SetWeight(sbCase.Weight); boxProperties.SetNetWeight(new OptDouble(sbCase.NetWeight.HasValue, sbCase.NetWeight.Value)); if (null != sbCase.Colors && sbCase.Colors.Length >= 6) { for (int i = 0; i < 6; ++i) { boxProperties.SetColor((HalfAxis.HAxis)i, Color.FromArgb(sbCase.Colors[i])); } } else { boxProperties.SetAllColors(Enumerable.Repeat(Color.Chocolate, 6).ToArray()); } PalletProperties palletProperties = null; if (null != sbPallet.Dimensions) { palletProperties = new PalletProperties(null, sbPallet.PalletType, sbPallet.Dimensions.M0, sbPallet.Dimensions.M1, sbPallet.Dimensions.M2) { Weight = sbPallet.Weight, Color = Color.FromArgb(sbPallet.Color) } } ; else { palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 150.0); } InterlayerProperties interlayerProperties = null; if (null != sbInterlayer) { interlayerProperties = new InterlayerProperties(null, sbInterlayer.Name, sbInterlayer.Description, sbInterlayer.Dimensions.M0, sbInterlayer.Dimensions.M1, sbInterlayer.Dimensions.M2, sbInterlayer.Weight, Color.FromArgb(sbInterlayer.Color)); } OptDouble oMaxWeight = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero; OptDouble oMaxHeight = null != sbConstraintSet.MaxHeight ? new OptDouble(sbConstraintSet.MaxHeight.Active, sbConstraintSet.MaxHeight.Value_d) : OptDouble.Zero; OptInt oMaxNumber = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero; ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet() { Overhang = new Vector2D(sbConstraintSet.Overhang.M0, sbConstraintSet.Overhang.M1), OptMaxWeight = oMaxWeight, OptMaxNumber = oMaxNumber }; constraintSet.SetMaxHeight(oMaxHeight); constraintSet.SetAllowedOrientations(new bool[] { sbConstraintSet.Orientation.X, sbConstraintSet.Orientation.Y, sbConstraintSet.Orientation.Z }); if (!constraintSet.Valid) { throw new Exception("Invalid constraint set"); } List <AnalysisLayered> analyses = new List <AnalysisLayered>(); if (StackBuilderProcessor.GetSolutionList( boxProperties, palletProperties, interlayerProperties, constraintSet, ref analyses )) { foreach (var analysis in analyses) { Vector3D bbGlob = analysis.Solution.BBoxGlobal.DimensionsVec; Vector3D bbLoad = analysis.Solution.BBoxLoad.DimensionsVec; OptDouble optNetWeight = analysis.Solution.NetWeight; double? weightNet = optNetWeight.Activated ? optNetWeight.Value : (double?)null; List <string> layerDescs = new List <string>(); foreach (var lp in analysis.SolutionLay.LayerPhrases.Keys) { layerDescs.Add(lp.LayerDescriptor.ToString()); } DCSBSolution solution = new DCSBSolution() { LayerCount = analysis.SolutionLay.LayerCount, CaseCount = analysis.Solution.ItemCount, InterlayerCount = analysis.SolutionLay.InterlayerCount, WeightLoad = analysis.Solution.LoadWeight, WeightTotal = analysis.Solution.Weight, NetWeight = weightNet, BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z), BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z), Efficiency = analysis.Solution.VolumeEfficiency, OutFile = null, LayerDescs = layerDescs.ToArray(), PalletMapPhrase = StackBuilderProcessor.BuildPalletMapPhrase(analysis.SolutionLay), Errors = lErrors.ToArray() }; listSolution.Add(solution); } } } catch (Exception ex) { lErrors.Add(ex.Message); _log.Error(ex.ToString()); } return(listSolution.ToArray()); }
public static void GenerateExport(Vector3D caseDim, double caseWeight, Bitmap bmpTexture, int palletIndex, double palletWeight, int layerNumber, List <BoxPositionIndexed> boxPositions, bool mirrorLength, bool mirrorWidth, List <bool> interlayers, string filePath, 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.OptMaxLayerNumber = layerNumber; // 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.White)); 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.White); } 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; // export file var exporter = new ExporterGLB(); exporter.Export(analysis, filePath); }
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 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[])); }