private void UpdateGrid() { try { // sanity check if (gridSolution.ColumnsCount < 2) { return; } // remove all existing rows gridSolution.Rows.Clear(); // *** IViews // captionHeader SourceGrid.Cells.Views.RowHeader captionHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader veHeaderCaption = new DevAge.Drawing.VisualElements.RowHeader(); veHeaderCaption.BackColor = Color.SteelBlue; veHeaderCaption.Border = DevAge.Drawing.RectangleBorder.NoBorder; captionHeader.Background = veHeaderCaption; captionHeader.ForeColor = Color.Black; captionHeader.Font = new Font("Arial", 10, FontStyle.Bold); captionHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; // viewRowHeader SourceGrid.Cells.Views.RowHeader viewRowHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader backHeader = new DevAge.Drawing.VisualElements.RowHeader(); backHeader.BackColor = Color.LightGray; backHeader.Border = DevAge.Drawing.RectangleBorder.NoBorder; viewRowHeader.Background = backHeader; viewRowHeader.ForeColor = Color.Black; viewRowHeader.Font = new Font("Arial", 10, FontStyle.Regular); // viewNormal CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White); // *** SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // pallet caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Pallet"); rowHeader.ColumnSpan = 2; rowHeader.View = captionHeader; gridSolution[iRow, 0] = rowHeader; // layer # gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Layer #"); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // interlayer # if (_solution.InterlayerCount > 0) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Interlayer #"); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.InterlayerCount); } // *** Item # (Recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // outer dimensions BBox3D bboxGlobal = _solution.BBoxGlobal; // --- gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Outer dimensions\n({0} x {0} x {0})", UnitsManager.LengthUnitString)); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxGlobal.Length, bboxGlobal.Width, bboxGlobal.Height)); // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Load dimensions\n({0} x {0} x {0})", UnitsManager.LengthUnitString)); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Net weight ({0})", UnitsManager.MassUnitString)); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight)); } // load weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Load Weight ({0})", UnitsManager.MassUnitString)); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Total weight ({0})", UnitsManager.MassUnitString)); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Vol. efficiency (%)"); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); int noLayerTypesUsed = 0; for (int i = 0; i < _solution.Layers.Count; ++i) { noLayerTypesUsed += _solution.Layers[i].BoxCount > 0 ? 1 : 0; } // ### layers : begin for (int i = 0; i < _solution.Layers.Count; ++i) { List <int> layerIndexes = _solution.LayerTypeUsed(i); if (0 == layerIndexes.Count) { continue; } // layer caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader((noLayerTypesUsed == 1) ? "Layers : All" : BuildLayerCaption(layerIndexes)); rowHeader.ColumnSpan = 2; rowHeader.View = captionHeader; gridSolution[iRow, 0] = rowHeader; // *** Item # (recursive count) content = _analysis.Content; itemCount = _solution.LayerBoxCount(i); number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("{0} #", content.DetailedName)); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // layer weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Weight"); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerWeight(i))); // layer space gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Spaces"); rowHeader.View = viewRowHeader; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerMaximumSpace(i))); } // ### layers : end gridSolution.AutoSizeCells(); gridSolution.Columns.StretchToFit(); gridSolution.AutoStretchColumnsToFitWidth = true; gridSolution.Invalidate(); } catch (Exception ex) { _log.Error(ex.ToString()); } }
private void UpdateGrid() { try { // sanity check if (gridSolution.ColumnsCount < 2) { return; } // remove all existing rows gridSolution.Rows.Clear(); // cell visual properties var vPropHeader = CellProperties.VisualPropHeader; var vPropValue = CellProperties.VisualPropValue; SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // pallet caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Truck") { ColumnSpan = 2, View = vPropHeader }; gridSolution[iRow, 0] = rowHeader; // layer # gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Layer #") { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // *** Item # (Recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADDIMENSIONS, UnitsManager.LengthUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_NETWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight.Value)); } // load weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_TOTALWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_VOLUMEEFFICIENCY) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); // ### layers : begin for (int i = 0; i < _solution.Layers.Count; ++i) { } // ### layers : end gridSolution.AutoSizeCells(); gridSolution.Columns.StretchToFit(); gridSolution.AutoStretchColumnsToFitWidth = true; gridSolution.Invalidate(); } catch (Exception ex) { _log.Error(ex.ToString()); } }
public virtual void UpdateGrid() { try { // remove all existing rows gridSolution.Rows.Clear(); // cell visual properties var vPropHeader = CellProperties.VisualPropHeader; var vPropValue = CellProperties.VisualPropValue; SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // loading caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(GridCaption) { ColumnSpan = 2, View = vPropHeader }; gridSolution[iRow, 0] = rowHeader; // layer # gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_LAYERCOUNT) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // interlayer # if (_solution.InterlayerCount > 0) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_INTERLAYERCOUNT) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.InterlayerCount); } // *** Item # (Recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADDIMENSIONS, UnitsManager.LengthUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_NETWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight)); } // load weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_TOTALWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_VOLUMEEFFICIENCY) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); int noLayerTypesUsed = 0; for (int i = 0; i < _solution.Layers.Count; ++i) { noLayerTypesUsed += _solution.Layers[i].BoxCount > 0 ? 1 : 0; } // ### layers : begin for (int i = 0; i < _solution.NoLayerTypesUsed; ++i) { // layer caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(_solution.LayerCaption(i)) { ColumnSpan = 2, View = vPropHeader }; gridSolution[iRow, 0] = rowHeader; // *** Item # (recursive count) content = _analysis.Content; itemCount = _solution.LayerBoxCount(i); number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("{0} #", content.DetailedName)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // layer weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_WEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerWeight(i))); // layer space gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_SPACES_WU, UnitsManager.LengthUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerMaximumSpace(i))); } // ### layers : end gridSolution.AutoSizeCells(); gridSolution.Columns.StretchToFit(); gridSolution.AutoStretchColumnsToFitWidth = true; gridSolution.Invalidate(); } catch (Exception ex) { _log.Error(ex.ToString()); } }
public async Task TestPackTAsync_IPackable_NotNull_Success() { var value = new Packable(); using ( var buffer = new MemoryStream() ) using ( var packer = Packer.Create( buffer ) ) { await packer.PackAsync( value ); Assert.AreEqual( new byte[] { 0xC3 }, buffer.ToArray() ); } }
public void TestPackT_IPackable_NotNull_Success() { var value = new Packable(); using ( var buffer = new MemoryStream() ) using ( var packer = Packer.Create( buffer ) ) { packer.Pack( value ); Assert.AreEqual( new byte[] { 0xC3 }, buffer.ToArray() ); } }
public AnalysisCaseTruck(Document doc, Packable packable, TruckProperties truckProperties, ConstraintSetPackableTruck constraintSet) : base(doc, packable, truckProperties, constraintSet) { }
public List <ILayer2D> BuildLayers( Packable packable, Vector2D dimContainer, double offsetZ, /* e.g. pallet height */ ConstraintSetAbstract constraintSet, bool keepOnlyBest) { var listLayers0 = new List <ILayer2D>(); if (packable is PackableBrick packableBrick) { // loop through all patterns foreach (LayerPatternBox pattern in LayerPatternBox.All) { // loop through all orientation HalfAxis.HAxis[] patternAxes = pattern.IsSymetric ? HalfAxis.Positives : HalfAxis.All; foreach (HalfAxis.HAxis axisOrtho in patternAxes) { // is orientation allowed if (!constraintSet.AllowOrientation(Layer2DBrickImp.VerticalAxis(axisOrtho))) { continue; } // not swapped vs swapped pattern for (int iSwapped = 0; iSwapped < 2; ++iSwapped) { try { // does swapping makes sense for this layer pattern ? if (!pattern.CanBeSwapped && (iSwapped == 1)) { continue; } // instantiate layer var layer = new Layer2DBrickImp(packableBrick.OuterDimensions, dimContainer, pattern.Name, axisOrtho, iSwapped == 1) { ForcedSpace = constraintSet.MinimumSpace.Value }; if (layer.NoLayers(constraintSet.OptMaxHeight.Value) < 1) { continue; } if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth)) { continue; } pattern.GenerateLayer(layer, actualLength, actualWidth); if (0 == layer.Count) { continue; } listLayers0.Add(layer); } catch (Exception ex) { _log.ErrorFormat("Pattern: {0} Orient: {1} Swapped: {2} Message: {3}" , pattern.Name , axisOrtho.ToString() , iSwapped == 1 ? "True" : "False" , ex.Message); } } } } } else if (packable is CylinderProperties cylinder) { // loop through all patterns foreach (LayerPatternCyl pattern in LayerPatternCyl.All) { // not swapped vs swapped pattern for (int iSwapped = 0; iSwapped < 2; ++iSwapped) { try { var layer = new Layer2DCylImp(cylinder.RadiusOuter, cylinder.Height, dimContainer, iSwapped == 1) { PatternName = pattern.Name }; if (!pattern.GetLayerDimensions(layer as Layer2DCylImp, out double actualLength, out double actualWidth)) { continue; } pattern.GenerateLayer(layer as Layer2DCylImp, actualLength, actualWidth); if (0 == layer.Count) { continue; } listLayers0.Add(layer); } catch (Exception ex) { _log.ErrorFormat("Pattern: {0} Swapped: {1} Message: {2}" , pattern.Name , iSwapped == 1 ? "True" : "False" , ex.Message); } } } } // keep only best layers if (keepOnlyBest) { // 1. get best count int bestCount = 0; foreach (ILayer2D layer in listLayers0) { bestCount = Math.Max(layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ), bestCount); } // 2. remove any layer that does not match the best count given its orientation var listLayers1 = new List <ILayer2D>(); foreach (ILayer2D layer in listLayers0) { if (layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ) >= bestCount) { listLayers1.Add(layer); } } // 3. copy back in original list listLayers0.Clear(); listLayers0.AddRange(listLayers1); } if (constraintSet.OptMaxHeight.Activated) { listLayers0.Sort(new LayerComparerCount(constraintSet, offsetZ)); } return(listLayers0); }
private item[] BuildItemArray(AnalysisLayered analysis) { Packable packable = analysis.Content; List <item> items = new List <item>(); int itemIndex = 0; // case ? if (analysis is AnalysisCasePallet analysisCasePallet) { ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet; bool[] orient = constraintSet.AllowedOrientations; StringBuilder sbOrient = new StringBuilder(); foreach (bool b in orient) { sbOrient.Append(b ? "1" : "0"); } items.Add( new item() { id = ++itemIndex, name = packable.Name, length = packable.OuterDimensions.X, width = packable.OuterDimensions.Y, height = packable.OuterDimensions.Z, weight = packable.Weight, maxWeightOnTop = 0.0, permittedOrientations = sbOrient.ToString() } ); } // cylinder ? else if (analysis is AnalysisCylinderPallet analysisCylinderPallet) { items.Add( new item() { id = ++itemIndex, name = packable.Name, length = packable.OuterDimensions.X, width = packable.OuterDimensions.Y, height = packable.OuterDimensions.Z, maxWeightOnTop = 0.0, permittedOrientations = "001" } ); } else { throw new Exception($"Unexpected analysis type : {analysis.GetType()}"); } // interlayers OffsetIndexInterlayers = itemIndex + 1; foreach (var interlayer in analysis.Interlayers) { items.Add( new item() { id = ++itemIndex, name = interlayer.Name, length = interlayer.Length, width = interlayer.Width, height = interlayer.Thickness, weight = interlayer.Weight } ); } return(items.ToArray()); }
public virtual void UpdateGrid() { try { // remove all existing rows gridSolutions.Rows.Clear(); // *** IViews // caption header SourceGrid.Cells.Views.RowHeader captionHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader veHeaderCaption = new DevAge.Drawing.VisualElements.RowHeader() { BackColor = Color.SteelBlue, Border = DevAge.Drawing.RectangleBorder.NoBorder }; captionHeader.Background = veHeaderCaption; captionHeader.ForeColor = Color.Black; captionHeader.Font = new Font("Arial", GridFontSize, FontStyle.Bold); captionHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; // viewRowHeader SourceGrid.Cells.Views.RowHeader viewRowHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader backHeader = new DevAge.Drawing.VisualElements.RowHeader() { BackColor = Color.LightGray, Border = DevAge.Drawing.RectangleBorder.NoBorder }; viewRowHeader.Background = backHeader; viewRowHeader.ForeColor = Color.Black; viewRowHeader.Font = new Font("Arial", GridFontSize, FontStyle.Regular); // viewNormal CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White); // *** SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // loading caption gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(GridCaption) { ColumnSpan = 2, View = captionHeader }; gridSolutions[iRow, 0] = rowHeader; // layer # gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_LAYERCOUNT) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // interlayer # if (_solution.InterlayerCount > 0) { gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_INTERLAYERCOUNT) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(_solution.InterlayerCount); } // *** Item # (Recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADDIMENSIONS, UnitsManager.LengthUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_NETWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight)); } // load weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_TOTALWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_VOLUMEEFFICIENCY) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); int noLayerTypesUsed = 0; for (int i = 0; i < _solution.Layers.Count; ++i) { noLayerTypesUsed += _solution.Layers[i].BoxCount > 0 ? 1 : 0; } // ### layers : begin for (int i = 0; i < _solution.NoLayerTypesUsed; ++i) { // layer caption gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(_solution.LayerCaption(i)) { ColumnSpan = 2, View = captionHeader }; gridSolutions[iRow, 0] = rowHeader; // *** Item # (recursive count) content = _analysis.Content; itemCount = _solution.LayerBoxCount(i); number = 1; do { itemCount *= number; gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("{0} #", content.DetailedName)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // layer weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_WEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerWeight(i))); // layer space gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_SPACES_WU, UnitsManager.LengthUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerMaximumSpace(i))); } // ### layers : end gridSolutions.AutoSizeCells(); gridSolutions.Columns.StretchToFit(); gridSolutions.AutoStretchColumnsToFitWidth = true; gridSolutions.Invalidate(); } catch (Exception ex) { _log.Error(ex.ToString()); } }
void Pack(MsgPackWriter writer, object o) { if (o == null) { writer.WriteNil(); return; } Type t = o.GetType(); if (t.IsPrimitive) { if (t.Equals(typeof(int))) { writer.Write((int)o); } else if (t.Equals(typeof(uint))) { writer.Write((uint)o); } else if (t.Equals(typeof(float))) { writer.Write((float)o); } else if (t.Equals(typeof(double))) { writer.Write((double)o); } else if (t.Equals(typeof(long))) { writer.Write((long)o); } else if (t.Equals(typeof(ulong))) { writer.Write((ulong)o); } else if (t.Equals(typeof(bool))) { writer.Write((bool)o); } else if (t.Equals(typeof(byte))) { writer.Write((byte)o); } else if (t.Equals(typeof(sbyte))) { writer.Write((sbyte)o); } else if (t.Equals(typeof(short))) { writer.Write((short)o); } else if (t.Equals(typeof(ushort))) { writer.Write((ushort)o); } else if (t.Equals(typeof(char))) { writer.Write((ushort)(char)o); } else { throw new NotSupportedException(); } return; } PackDelegate packer; if (PackerMapping.TryGetValue(t, out packer)) { packer(this, writer, o); return; } if (o is Packable) { Packable p = o as Packable; p.Pack(this, writer); return; } if (t.IsArray) { Array ary = (Array)o; writer.WriteArrayHeader(ary.Length); for (int i = 0; i < ary.Length; i++) { Pack(writer, ary.GetValue(i)); } return; } if (typeof(IList).IsAssignableFrom(t)) { IList list = (IList)o; writer.WriteArrayHeader(list.Count); for (int i = 0; i < list.Count; i++) { Pack(writer, list[i]); } return; } if (t.IsGenericType) { var setType = typeof(ISet <>).MakeGenericType(t.GetGenericArguments()[0]); if (setType.IsAssignableFrom(t)) { IEnumerable list = (IEnumerable)o; writer.WriteArrayHeader((int)t.GetProperty("Count").GetValue(o, null)); foreach (object e in list) { Pack(writer, e); } return; } } if (typeof(IDictionary).IsAssignableFrom(t)) { IDictionary dict = (IDictionary)o; writer.WriteArrayHeader(dict.Count); IDictionaryEnumerator enumerator = dict.GetEnumerator(); while (enumerator.MoveNext()) { Pack(writer, enumerator.Key); Pack(writer, enumerator.Value); } return; } ReflectionCacheEntry entry = ReflectionCache.Lookup(t); writer.WriteMapHeader(entry.FieldMap.Count); foreach (KeyValuePair <string, FieldInfo> pair in entry.FieldMap) { writer.Write(pair.Key, _buf); object v = pair.Value.GetValue(o); if (pair.Value.FieldType.IsInterface && v != null) { writer.WriteArrayHeader(2); writer.Write(v.GetType().FullName); } Pack(writer, v); } }
public override bool InnerContent(ref Packable innerPackable, ref int number) { innerPackable = ParentAnalysis.Content; number = ParentSolution.ItemCount; return(true); }
object Unpack(MsgPackReader reader, Type t) { if (t.IsPrimitive) { if (!reader.Read()) { throw new FormatException(); } if (t.Equals(typeof(int)) && reader.IsSigned()) { return(reader.ValueSigned); } else if (t.Equals(typeof(uint)) && reader.IsUnsigned()) { return(reader.ValueUnsigned); } else if (t.Equals(typeof(float)) && reader.Type == TypePrefixes.Float) { return(reader.ValueFloat); } else if (t.Equals(typeof(double)) && reader.Type == TypePrefixes.Double) { return(reader.ValueDouble); } else if (t.Equals(typeof(long))) { if (reader.IsSigned64()) { return(reader.ValueSigned64); } if (reader.IsSigned()) { return((long)reader.ValueSigned); } } else if (t.Equals(typeof(ulong))) { if (reader.IsUnsigned64()) { return(reader.ValueUnsigned64); } if (reader.IsUnsigned()) { return((ulong)reader.ValueUnsigned); } } else if (t.Equals(typeof(bool)) && reader.IsBoolean()) { return(reader.Type == TypePrefixes.True); } else if (t.Equals(typeof(byte)) && reader.IsUnsigned()) { return((byte)reader.ValueUnsigned); } else if (t.Equals(typeof(sbyte)) && reader.IsSigned()) { return((sbyte)reader.ValueSigned); } else if (t.Equals(typeof(short)) && reader.IsSigned()) { return((short)reader.ValueSigned); } else if (t.Equals(typeof(ushort)) && reader.IsUnsigned()) { return((ushort)reader.ValueUnsigned); } else if (t.Equals(typeof(char)) && reader.IsUnsigned()) { return((char)reader.ValueUnsigned); } else { throw new NotSupportedException(); } } UnpackDelegate unpacker; if (UnpackerMapping.TryGetValue(t, out unpacker)) { return(unpacker(this, reader)); } if (typeof(Packable).IsAssignableFrom(t)) { Packable p = Activator.CreateInstance(t) as Packable; return(p.Unpack(this, reader)); } if (t.IsArray) { if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil)) { throw new FormatException(); } if (reader.Type == TypePrefixes.Nil) { return(null); } Type et = t.GetElementType(); Array ary = Array.CreateInstance(et, (int)reader.Length); for (int i = 0; i < ary.Length; i++) { ary.SetValue(Unpack(reader, et), i); } return(ary); } // IEnumerable 型の場合 // 現在は IList, ISet, IDictionary をサポート if (typeof(IEnumerable).IsAssignableFrom(t) && t.IsGenericType) { Type[] generics = t.GetGenericArguments(); // IList 型の場合 if (typeof(IList).IsAssignableFrom(t)) { if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil)) { throw new FormatException(); } if (reader.Type == TypePrefixes.Nil) { return(null); } Type et = generics.Single(); int count = (int)reader.Length; Array ary = Array.CreateInstance(et, count); for (int i = 0; i < count; i++) { ary.SetValue(Unpack(reader, et), i); } return(Activator.CreateInstance(t, new object[] { ary })); } // ISet 型の場合 var setType = typeof(ISet <>).MakeGenericType(generics[0]); if (setType.IsAssignableFrom(t)) { if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil)) { throw new FormatException(); } if (reader.Type == TypePrefixes.Nil) { return(null); } Type et = generics.Single(); int count = (int)reader.Length; Array ary = Array.CreateInstance(et, count); for (int i = 0; i < count; i++) { ary.SetValue(Unpack(reader, et), i); } return(Activator.CreateInstance(t, new object[] { ary })); } if (typeof(IDictionary).IsAssignableFrom(t)) { if (!reader.Read() || (!reader.IsArray() && reader.Type != TypePrefixes.Nil)) { throw new FormatException(); } if (reader.Type == TypePrefixes.Nil) { return(null); } Type kt = generics[0]; Type vt = generics[1]; IDictionary dict = (IDictionary)Activator.CreateInstance(t); int count = (int)reader.Length; for (int i = 0; i < count; i++) { dict[Unpack(reader, kt)] = Unpack(reader, vt); } return(dict); } } if (!reader.Read()) { throw new FormatException(); } if (reader.Type == TypePrefixes.Nil) { return(null); } if (t.IsInterface) { if (reader.Type != TypePrefixes.FixArray && reader.Length != 2) { throw new FormatException(); } if (!reader.Read() || !reader.IsRaw()) { throw new FormatException(); } CheckBufferSize((int)reader.Length); reader.ReadValueRaw(_buf, 0, (int)reader.Length); t = Type.GetType(Encoding.UTF8.GetString(_buf, 0, (int)reader.Length)); if (!reader.Read() || reader.Type == TypePrefixes.Nil) { throw new FormatException(); } } if (!reader.IsMap()) { throw new FormatException(); } object o = FormatterServices.GetUninitializedObject(t); ReflectionCacheEntry entry = ReflectionCache.Lookup(t); int members = (int)reader.Length; for (int i = 0; i < members; i++) { if (!reader.Read() || !reader.IsRaw()) { throw new FormatException(); } CheckBufferSize((int)reader.Length); reader.ReadValueRaw(_buf, 0, (int)reader.Length); string name = Encoding.UTF8.GetString(_buf, 0, (int)reader.Length); FieldInfo f; if (!entry.FieldMap.TryGetValue(name, out f)) { throw new FormatException(); } f.SetValue(o, Unpack(reader, f.FieldType)); } IDeserializationCallback callback = o as IDeserializationCallback; if (callback != null) { callback.OnDeserialization(this); } return(o); }
void Pack(MsgPackWriter writer, object o) { if (o == null) { writer.WriteNil(); return; } Type t = o.GetType(); if (t.IsPrimitive) { if (t.Equals(typeof(int))) { writer.Write((int)o); } else if (t.Equals(typeof(uint))) { writer.Write((uint)o); } else if (t.Equals(typeof(float))) { writer.Write((float)o); } else if (t.Equals(typeof(double))) { writer.Write((double)o); } else if (t.Equals(typeof(long))) { writer.Write((long)o); } else if (t.Equals(typeof(ulong))) { writer.Write((ulong)o); } else if (t.Equals(typeof(bool))) { writer.Write((bool)o); } else if (t.Equals(typeof(byte))) { writer.Write((byte)o); } else if (t.Equals(typeof(sbyte))) { writer.Write((sbyte)o); } else if (t.Equals(typeof(short))) { writer.Write((short)o); } else if (t.Equals(typeof(ushort))) { writer.Write((ushort)o); } else if (t.Equals(typeof(char))) { writer.Write((ushort)(char)o); } else { throw new NotSupportedException(); } return; } PackDelegate packer; if (PackerMapping.TryGetValue(t, out packer)) { packer(this, writer, o); return; } if (o is Packable) { Packable p = o as Packable; p.Pack(this, writer); return; } if (t.IsArray) { Array ary = (Array)o; writer.WriteArrayHeader(ary.Length); for (int i = 0; i < ary.Length; i++) { Pack(writer, ary.GetValue(i)); } return; } ReflectionCacheEntry entry = ReflectionCache.Lookup(t); writer.WriteMapHeader(entry.FieldMap.Count); foreach (KeyValuePair <string, FieldInfo> pair in entry.FieldMap) { writer.Write(pair.Key, _buf); object v = pair.Value.GetValue(o); if (pair.Value.FieldType.IsInterface && v != null) { writer.WriteArrayHeader(2); writer.Write(v.GetType().FullName); } Pack(writer, v); } }
public Box(uint pickId, Packable packable, BoxPosition bPosition) { if (!bPosition.IsValid) { throw new GraphicsException("Invalid BoxPosition: can not create box"); } _pickId = pickId; _dim[0] = packable.Length; _dim[1] = packable.Width; _dim[2] = packable.Height; // set position Position = bPosition.Position; // set direction length LengthAxis = HalfAxis.ToVector3D(bPosition.DirectionLength); // set direction width WidthAxis = HalfAxis.ToVector3D(bPosition.DirectionWidth); _colors = Enumerable.Repeat <Color>(Color.Chocolate, 6).ToArray(); BProperties bProperties = packable as BProperties; if (null != bProperties) { _colors = bProperties.Colors; } BoxProperties boxProperties = bProperties as BoxProperties; if (null != boxProperties) { List <Pair <HalfAxis.HAxis, Texture> > textures = boxProperties.TextureList; foreach (Pair <HalfAxis.HAxis, Texture> tex in textures) { int iIndex = (int)tex.first; if (null == _textureLists[iIndex]) { _textureLists[iIndex] = new List <Texture>(); } _textureLists[iIndex].Add(tex.second); } _showTape = boxProperties.ShowTape; _tapeWidth = boxProperties.TapeWidth; _tapeColor = boxProperties.TapeColor; } // IsBundle ? _isBundle = bProperties.IsBundle; if (bProperties.IsBundle) { BundleProperties bundleProp = bProperties as BundleProperties; if (null != bundleProp) { _noFlats = bundleProp.NoFlats; } } PackProperties packProperties = packable as PackProperties; if (null != packProperties) { } }
private int ToIconIndex(ItemBase item) { if (item is AnalysisCasePallet) { AnalysisCasePallet analysisCasePallet = item as AnalysisCasePallet; Packable content = analysisCasePallet.Content; if (content is BoxProperties) { return(14); } else if (content is BundleProperties) { return(15); } else if (content is PackProperties) { return(21); } else { return(0); } } else if (item is AnalysisBoxCase) { return(17); } else if (item is AnalysisPalletTruck) { return(16); } else if (item is AnalysisCaseTruck) { return(16); } else if (item is AnalysisCylinderPallet) { return(19); } else if (item is AnalysisCylinderCase) { return(17); } else if (item is HAnalysisPallet) { return(14); } else if (item is HAnalysisCase) { return(17); } else if (item is HAnalysisTruck) { return(16); } else { _log.Error("Unexpected analysis type"); return(0); } }
public void TestPackT_IPackable_NotNull_Success() { var value = new Packable(); TestPackTCore <Packable>(value, new byte[] { 0xC3 }); }