public CasePalletAnalysis(
     BProperties boxProperties,
     PalletProperties palletProperties,
     InterlayerProperties interlayerProperties,
     InterlayerProperties interlayerPropertiesAntiSlip,
     PalletCornerProperties palletCorners, PalletCapProperties palletCap, PalletFilmProperties palletFilm,
     PalletConstraintSet constraintSet)
     : base(boxProperties.ParentDocument)
 {
     // sanity checks
     if (palletProperties.ParentDocument != ParentDocument
         || (interlayerProperties != null && interlayerProperties.ParentDocument != ParentDocument))
         throw new Exception("box, pallet, interlayer do not belong to the same document");
     if ((boxProperties is BoxProperties && constraintSet is BundlePalletConstraintSet)
         || (boxProperties is BundleProperties && constraintSet is CasePalletConstraintSet))
         throw new Exception("Invalid analysis: either BoxProperties with ConstraintSetBundle or BundleProperties with ConstraintSetBox");
     // has interlayer ?
     constraintSet.HasInterlayer = null != interlayerProperties;
     // setting members
     this.BProperties = boxProperties;
     this.PalletProperties = palletProperties;
     this.InterlayerProperties = interlayerProperties;
     this.InterlayerPropertiesAntiSlip = interlayerPropertiesAntiSlip;
     this.PalletCornerProperties = palletCorners;
     this.PalletCapProperties = palletCap;
     this.PalletFilmProperties = palletFilm;
     this.ConstraintSet = constraintSet;
 }
        public FormNewPalletCap(Document document, PalletCapProperties capProperties)
            : base(document, capProperties)
        {
            InitializeComponent();
            // units
            UnitsManager.AdaptUnitLabels(this);

            if (null != capProperties)
            {
                CapLength = capProperties.Length;
                CapWidth = capProperties.Width;
                CapHeight = capProperties.Height;

                CapInnerLength = capProperties.InsideLength;
                CapInnerWidth = capProperties.InsideWidth;
                CapInnerHeight = capProperties.InsideHeight;

                CapWeight = capProperties.Weight;
                CapColor = capProperties.Color;
            }
            else
            {
                CapLength = UnitsManager.ConvertLengthFrom(1200.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                CapWidth = UnitsManager.ConvertLengthFrom(1000.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                CapHeight = UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1);

                CapWeight = UnitsManager.ConvertSurfaceMassFrom(0.5, UnitsManager.UnitSystem.UNIT_METRIC1);
                CapColor = Color.Khaki;
            }
            UpdateStatus(string.Empty);
        }
Exemple #3
0
        public FormNewPalletCap(Document document, PalletCapProperties capProperties)
            : base(document, capProperties)
        {
            InitializeComponent();
            // units
            UnitsManager.AdaptUnitLabels(this);

            if (null != capProperties)
            {
                CapLength = capProperties.Length;
                CapWidth  = capProperties.Width;
                CapHeight = capProperties.Height;

                CapInnerLength = capProperties.InsideLength;
                CapInnerWidth  = capProperties.InsideWidth;
                CapInnerHeight = capProperties.InsideHeight;

                CapWeight = capProperties.Weight;
                CapColor  = capProperties.Color;
            }
            else
            {
                CapLength = UnitsManager.ConvertLengthFrom(1200.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                CapWidth  = UnitsManager.ConvertLengthFrom(1000.0, UnitsManager.UnitSystem.UNIT_METRIC1);
                CapHeight = UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1);

                CapWeight = UnitsManager.ConvertSurfaceMassFrom(0.5, UnitsManager.UnitSystem.UNIT_METRIC1);
                CapColor  = Color.Khaki;
            }
            UpdateStatus(string.Empty);
        }
Exemple #4
0
 public Box(uint pickId, PalletCapProperties capProperties, Vector3D position)
     : base(pickId, capProperties.Length, capProperties.Width, capProperties.Height, new BoxPosition(position, HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P))
 {
     // colors & textures
     Colors = new Color[6];
     SetAllFacesColor(capProperties.Color);
 }
        public PalletCap(uint pickId, PalletCapProperties capProperties, Vector3D position)
        {
            _dim[0] = capProperties.Length;
            _dim[1] = capProperties.Width;
            _dim[2] = capProperties.Height;

            _color = capProperties.Color;

            Position = position;
        }
        public PalletCap(uint pickId, PalletCapProperties capProperties, BoxPosition bPosition)
        {
            _dim[0] = capProperties.Length;
            _dim[1] = capProperties.Width;
            _dim[2] = capProperties.Height;

            _color = capProperties.Color;

            _bPosition = bPosition;
        }
        public PalletCap(uint pickId, PalletCapProperties capProperties, Vector3D position)
        {
            _dim[0] = capProperties.Length;
            _dim[1] = capProperties.Width;
            _dim[2] = capProperties.Height;

            _color = capProperties.Color;

            Position = position;
        }
Exemple #8
0
 public Box(uint pickId, PalletCapProperties capProperties, Vector3D position)
 {
     _pickId = pickId;
     // dimensions
     _dim[0] = capProperties.Length;
     _dim[1] = capProperties.Width;
     _dim[2] = capProperties.Height;
     // box position
     _boxPosition = new BoxPosition(position, HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
     // colors & textures
     _colors = new Color[6];
     this.SetAllFacesColor(capProperties.Color);
 }
Exemple #9
0
        public Box(uint pickId, PalletCapProperties capProperties, Vector3D position)
        {
            _dim[0] = capProperties.Length;
            _dim[1] = capProperties.Width;
            _dim[2] = capProperties.Height;

            _colors = new Color[6];
            this.SetAllFacesColor(capProperties.Color);

            Position = position;

            LengthAxis = Vector3D.XAxis;
            WidthAxis  = Vector3D.YAxis;
        }
Exemple #10
0
 public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
 {
     if (CapLength > 0 && CapWidth > 0 && CapHeight > 0)
     {
         // draw
         PalletCapProperties palletCapProperties = new PalletCapProperties(
             null, ItemName, ItemDescription, CapLength, CapWidth, CapHeight,
             CapInnerLength, CapInnerWidth, CapInnerHeight,
             CapWeight, CapColor);
         PalletCap palletCap = new PalletCap(0, palletCapProperties, BoxPosition.Zero);
         palletCap.Draw(graphics);
         graphics.AddDimensions(new DimensionCube(CapLength, CapWidth, CapHeight));
     }
 }
Exemple #11
0
 /// <summary>
 /// Process case/pallet analysis
 /// </summary>
 /// <param name="analysis">Pallet analysis to process</param>
 public void ProcessAnalysis(CasePalletAnalysis analysis)
 {
     _bProperties                  = analysis.BProperties;
     _palletProperties             = analysis.PalletProperties;
     _interlayerProperties         = analysis.InterlayerProperties;
     _interlayerPropertiesAntiSlip = analysis.InterlayerPropertiesAntiSlip;
     _cornerProperties             = analysis.PalletCornerProperties;
     _capProperties                = analysis.PalletCapProperties;
     _constraintSet                = analysis.ConstraintSet;
     // check contraint set validity
     if (!_constraintSet.IsValid)
     {
         throw new EngineException("Constraint set is invalid!");
     }
     // generate solutions
     analysis.Solutions = GenerateSolutions();
 }
 public PalletCapProperties CreateNewPalletCap(PalletCapProperties palletCap)
 {
     // instantiate and initialize
         PalletCapProperties palletCapClone = new PalletCapProperties(
             this,
             palletCap.Name, palletCap.Description,
             palletCap.Length, palletCap.Width, palletCap.Height,
             palletCap.InsideLength, palletCap.InsideWidth, palletCap.InsideHeight,
             palletCap.Weight, palletCap.Color);
         // insert in list
         _typeList.Add(palletCapClone);
         // notify listeners
         NotifyOnNewTypeCreated(palletCapClone);
         Modify();
         return palletCapClone;
 }
 public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
 {
     if (CapLength > 0 && CapWidth > 0 && CapHeight > 0)
     {
         // draw
         PalletCapProperties palletCapProperties = new PalletCapProperties(
             null, ItemName, ItemDescription, CapLength, CapWidth, CapHeight,
             CapInnerLength, CapInnerWidth, CapInnerHeight,
             CapWeight, CapColor);
         PalletCap palletCap = new PalletCap(0, palletCapProperties, Vector3D.Zero);
         palletCap.Draw(graphics);
         graphics.AddDimensions(new DimensionCube(CapLength, CapWidth, CapHeight));
     }
 }
Exemple #14
0
        public Box(uint pickId, PalletCapProperties capProperties, Vector3D position)
        {
            _dim[0] = capProperties.Length;
            _dim[1] = capProperties.Width;
            _dim[2] = capProperties.Height;

            _colors = new Color[6];
            this.SetAllFacesColor(capProperties.Color);

            Position = position;

            LengthAxis = Vector3D.XAxis;
            WidthAxis = Vector3D.YAxis;
        }
Exemple #15
0
        public override void Draw(Graphics3D graphics, Transform3D transform)
        {
            // clear list of picking box
            ClearPickingBoxes();

            if (null == Solution)
            {
                return;
            }
            AnalysisHomo analysis = Solution.Analysis;

            if (analysis is AnalysisPackablePallet analysisPackablePallet)
            {
                // ### draw pallet
                Pallet pallet = new Pallet(analysisPackablePallet.PalletProperties);
                pallet.Draw(graphics, transform);

                if (analysis is AnalysisCasePallet && -1 == Solution.SelectedLayerIndex)
                {
                    // ### strappers
                    SolutionLayered sol = Solution;
                    foreach (var sd in sol.Strappers)
                    {
                        if (null != sd.Points && sd.Points.Count > 0)
                        {
                            Strapper s = new Strapper(
                                transform.transform(IntToAxis(sd.Strapper.Axis)),
                                sd.Strapper.Width,
                                sd.Strapper.Color,
                                sd.Points.ConvertAll(p => transform.transform(p)).ToList());
                            s.DrawBegin(graphics);
                        }
                    }
                }
            }
            else if (analysis is AnalysisPackableCase analysisPackableCase)
            {
                // ### draw case (inside)
                Case case_ = new Case(analysisPackableCase.CaseProperties);
                case_.DrawInside(graphics, transform);
            }
            else if (analysis is AnalysisPackableTruck analysisPackableTruck)
            {
                // ### draw truck
                Truck truck = new Truck(analysisPackableTruck.TruckProperties);
                truck.DrawBegin(graphics);
            }
            else if (analysis is AnalysisPalletTruck analysisPalletTruck)
            {
                // ### draw truck
                Truck truck = new Truck(analysisPalletTruck.TruckProperties);
                truck.DrawBegin(graphics);
            }
            // ### draw solution
            uint          layerId = 0, pickId = 0;
            List <ILayer> layers = Solution.Layers;

            foreach (ILayer layer in layers)
            {
                bool        aboveSelectedLayer = (Solution.SelectedLayerIndex != -1) && (layerId > Solution.SelectedLayerIndex);
                Transform3D upTranslation      = Transform3D.Translation(new Vector3D(0.0, 0.0, aboveSelectedLayer ? DistanceAboveSelectedLayer : 0.0));
                BBox3D      bbox = new BBox3D();
                // ### layer of boxes
                if (layer is Layer3DBox layerBox)
                {
                    if (analysis.Content is LoadedPallet)
                    {
                        LoadedPallet loadedPallet = analysis.Content as LoadedPallet;
                        BBox3D       solBBox      = loadedPallet.ParentAnalysis.Solution.BBoxGlobal;
                        foreach (BoxPosition bPosition in layerBox)
                        {
                            var dim = solBBox.DimensionsVec;
                            graphics.AddImage(++pickId, new SubContent(loadedPallet.ParentAnalysis as AnalysisHomo), solBBox.DimensionsVec, bPosition.Transform(transform));
                            // bbox used for picking
                            bbox.Extend(new BBox3D(bPosition.Transform(transform), solBBox.DimensionsVec));
                        }
                    }
                    else if (analysis.Content is PackProperties packProperties)
                    {
                        foreach (BoxPosition bPosition in layerBox)
                        {
                            BoxPosition boxPositionModified = bPosition.Transform(transform * upTranslation);
                            graphics.AddImage(++pickId, new SubContent(packProperties), packProperties.OuterDimensions, boxPositionModified);
                            // bbox used for picking
                            bbox.Extend(new BBox3D(boxPositionModified, packProperties.OuterDimensions));
                        }
                    }
                    else if (analysis.Content is BagProperties bagProperties)
                    {
                        foreach (BoxPosition bPosition in layerBox)
                        {
                            BoxPosition boxPositionModified = bPosition.Transform(transform * upTranslation);
                            graphics.AddImage(++pickId, new SubContent(bagProperties), bagProperties.OuterDimensions, boxPositionModified);
                            // bbox used for picking
                            bbox.Extend(new BBox3D(boxPositionModified, bagProperties.OuterDimensions));
                        }
                    }
                    else
                    {
                        foreach (BoxPosition bPosition in layerBox)
                        {
                            BoxPosition boxPositionModified = bPosition.Transform(transform * upTranslation);
                            BoxGeneric  b;
                            if (analysis.Content is BagProperties bagProp)
                            {
                                b = new BoxRounded(pickId++, bagProp.Length, bagProp.Width, bagProp.Height, bagProp.Radius, boxPositionModified)
                                {
                                    ColorFill = bagProp.ColorFill
                                }
                            }
                            ;
                            else
                            {
                                b = new Box(pickId++, analysis.Content as PackableBrick, boxPositionModified);
                            }
                            graphics.AddBox(b);
                            bbox.Extend(b.BBox);
                        }
                    }
                }
                else if (layer is Layer3DBoxIndexed layerBoxIndexed)
                {
                    foreach (var bpi in layerBoxIndexed)
                    {
                        BoxPosition boxPositionModified = bpi.BPos.Transform(transform * upTranslation);
                        var         bProperties         = analysis.Content as PackableBrick;
                        BoxGeneric  b = new Box(pickId++, analysis.Content as PackableBrick, boxPositionModified);
                        graphics.AddBox(b);
                        // bbox used for picking
                        bbox.Extend(new BBox3D(boxPositionModified, bProperties.OuterDimensions));
                    }
                }
                else if (layer is Layer3DCyl layerCyl)
                {
                    foreach (Vector3D vPos in layerCyl)
                    {
                        CylPosition cylPosition         = new CylPosition(transform.transform(vPos), HalfAxis.HAxis.AXIS_Z_P);
                        CylPosition cylPositionModified = cylPosition.Transform(transform * upTranslation);
                        Cyl         cyl = null;
                        if (analysis.Content is CylinderProperties cylProp)
                        {
                            cyl = new Cylinder(pickId++, cylProp, cylPositionModified);
                        }
                        else if (analysis.Content is BottleProperties bottleProperties)
                        {
                            cyl = new Bottle(pickId++, bottleProperties, cylPositionModified);
                        }
                        graphics.AddCylinder(cyl);
                        bbox.Extend(cyl.BBox);
                    }
                }
                // ### interlayer
                else if (layer is InterlayerPos interlayerPos)
                {
                    InterlayerProperties interlayerProp = Solution.Interlayers[interlayerPos.TypeId];
                    if (null != interlayerProp)
                    {
                        BoxPosition bPosition = new BoxPosition(
                            new Vector3D(
                                analysis.Offset.X + 0.5 * (analysis.ContainerDimensions.X - interlayerProp.Length)
                                , analysis.Offset.Y + 0.5 * (analysis.ContainerDimensions.Y - interlayerProp.Width)
                                , interlayerPos.ZLow
                                ), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                        BoxPosition boxPositionModified = bPosition.Transform(transform * upTranslation);

                        Box box = new Box(pickId++, interlayerProp, boxPositionModified);
                        if (analysis.Content is PackProperties)
                        {
                            graphics.AddImage(pickId, new SubContent(interlayerProp), interlayerProp.Dimensions, boxPositionModified);
                        }
                        else
                        {
                            graphics.AddBox(box);
                        }
                        bbox.Extend(box.BBox);
                    }
                }

                if (layer is Layer3DBox || layer is Layer3DCyl)
                {
                    // add layer BBox
                    AddPickingBox(bbox, layerId);
                    // draw bounding box around selected layer
                    if (layerId == Solution.SelectedLayerIndex)
                    {
                        DrawLayerBoundingBox(graphics, bbox);
                    }
                    ++layerId;
                }
            }
            BBox3D loadBBox      = Solution.BBoxLoad;
            BBox3D loadBBoxWDeco = Solution.BBoxLoadWDeco;

            if (analysis is AnalysisCasePallet analysisCasePallet)
            {
                #region Pallet corners
                // ### pallet corners : Begin
                Corner[] corners = new Corner[4];
                if (analysisCasePallet.HasPalletCorners)
                {
                    // positions
                    Vector3D[] cornerPositions =
                    {
                        loadBBox.PtMin
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                    };
                    // length axes
                    HalfAxis.HAxis[] lAxes =
                    {
                        HalfAxis.HAxis.AXIS_X_P,
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N
                    };
                    // width axes
                    HalfAxis.HAxis[] wAxes =
                    {
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N,
                        HalfAxis.HAxis.AXIS_X_P
                    };
                    for (int i = 0; i < 4; ++i)
                    {
                        corners[i] = new Corner(0, analysisCasePallet.PalletCornerProperties)
                        {
                            Height = Math.Min(analysisCasePallet.PalletCornerProperties.Length, loadBBox.Height)
                        };
                        corners[i].SetPosition(
                            transform.transform(cornerPositions[i])
                            , HalfAxis.Transform(lAxes[i], transform), HalfAxis.Transform(wAxes[i], transform)
                            );
                        corners[i].DrawBegin(graphics);
                    }
                }
                #endregion

                #region Top corners
                Corner[] cornersTop = new Corner[4];
                if (analysisCasePallet.HasPalletCornersTopX || analysisCasePallet.HasPalletCornersTopY)
                {
                    double cornerWidth  = analysisCasePallet.PalletCornerTopProperties.Width;
                    double lengthInLDir = Math.Min(analysisCasePallet.PalletCornerTopProperties.Length, loadBBox.Length - 2.0 * cornerWidth);
                    double widthInWDir  = Math.Min(analysisCasePallet.PalletCornerTopProperties.Length, loadBBox.Width - 2.0 * cornerWidth);
                    double offsetInLDir = 0.5 * (loadBBox.Length - lengthInLDir);
                    double offsetInWdir = 0.5 * (loadBBox.Width - widthInWDir);

                    Transform3D upTranslation = Transform3D.Translation(new Vector3D(0.0, 0.0, -1 != Solution.SelectedLayerIndex ? DistanceAboveSelectedLayer : 0.0));


                    // positions
                    Vector3D[] cornerPositions =
                    {
                        new Vector3D(loadBBox.PtMin.X + offsetInLDir, loadBBox.PtMin.Y,                             loadBBox.PtMax.Z)
                        ,                                             new Vector3D(loadBBox.PtMax.X - offsetInLDir, loadBBox.PtMax.Y, loadBBox.PtMax.Z)
                        ,                                             new Vector3D(loadBBox.PtMax.X,                loadBBox.PtMin.Y + offsetInWdir, loadBBox.PtMax.Z)
                        ,                                             new Vector3D(loadBBox.PtMin.X,                loadBBox.PtMax.Y - offsetInWdir, loadBBox.PtMax.Z)
                    };
                    // length axes
                    HalfAxis.HAxis[] lAxes =
                    {
                        HalfAxis.HAxis.AXIS_Z_N,
                        HalfAxis.HAxis.AXIS_Z_N,
                        HalfAxis.HAxis.AXIS_Z_N,
                        HalfAxis.HAxis.AXIS_Z_N,
                    };
                    // width axes
                    HalfAxis.HAxis[] wAxes =
                    {
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_Y_N,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_X_P
                    };
                    for (int i = 0; i < 4; ++i)
                    {
                        cornersTop[i] = new Corner(0, analysisCasePallet.PalletCornerTopProperties)
                        {
                            Height = Math.Min(analysisCasePallet.PalletCornerTopProperties.Length, (i < 2 ? loadBBox.Length : loadBBox.Width) - 2.0 * cornerWidth)
                        };
                        cornersTop[i].SetPosition(
                            transform.transform(upTranslation.transform(cornerPositions[i]))
                            , HalfAxis.Transform(lAxes[i], transform), HalfAxis.Transform(wAxes[i], transform)
                            );
                    }
                    // drawing
                    if (analysisCasePallet.HasPalletCornersTopX)
                    {
                        for (int i = 0; i < 2; ++i)
                        {
                            cornersTop[i].DrawBegin(graphics);
                        }
                    }
                    if (analysisCasePallet.HasPalletCornersTopY)
                    {
                        for (int i = 2; i < 4; ++i)
                        {
                            cornersTop[i].DrawBegin(graphics);
                        }
                    }
                }
                #endregion
                #region Pallet film
                // ### pallet film
                Film film = null;
                if (analysisCasePallet.HasPalletFilm && -1 == Solution.SelectedLayerIndex)
                {
                    // instantiate film
                    PalletFilmProperties palletFilmProperties = analysisCasePallet.PalletFilmProperties;
                    film = new Film(
                        palletFilmProperties.Color,
                        palletFilmProperties.UseTransparency,
                        palletFilmProperties.UseHatching,
                        palletFilmProperties.HatchSpacing,
                        palletFilmProperties.HatchAngle);
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), -1.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), -1.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_N, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), -1.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_N, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), -1.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width)
                                                        , analysisCasePallet.PalletFilmTopCovering));
                    film.DrawBegin(graphics);
                }
                #endregion

                #region Pallet corners
                // pallet corners : End
                if (analysisCasePallet.HasPalletCorners)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        corners[i].DrawEnd(graphics);
                    }
                }
                if (analysisCasePallet.HasPalletCornersTopX)
                {
                    for (int i = 0; i < 2; ++i)
                    {
                        cornersTop[i].DrawEnd(graphics);
                    }
                }
                if (analysisCasePallet.HasPalletCornersTopY)
                {
                    for (int i = 2; i < 4; ++i)
                    {
                        cornersTop[i].DrawEnd(graphics);
                    }
                }
                #endregion

                #region Pallet sleeves
                // ### pallet sleeve
                if (analysisCasePallet.HasPalletSleeve)
                {
                    var ps = new PalletSleeve(0, loadBBox, analysisCasePallet.PalletSleeveColor);
                    ps.DrawEnd(graphics);
                }
                #endregion

                #region Pallet Cap
                // ### pallet cap
                if (analysisCasePallet.HasPalletCap)
                {
                    PalletCapProperties capProperties = analysisCasePallet.PalletCapProperties;
                    BoxPosition         bPosition     = new BoxPosition(new Vector3D(
                                                                            0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length),
                                                                            0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width),
                                                                            loadBBox.PtMax.Z - capProperties.InsideHeight)
                                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform)
                                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform)
                                                                        );

                    Transform3D upTranslation = Transform3D.Translation(new Vector3D(0.0, 0.0, -1 != Solution.SelectedLayerIndex ? DistanceAboveSelectedLayer : 0.0));
                    PalletCap   cap           = new PalletCap(0, capProperties, bPosition.Transform(upTranslation));
                    cap.DrawEnd(graphics);
                }
                #endregion

                #region Pallet labels
                // ### pallet labels
                if (null != analysisCasePallet)
                {
                    foreach (var pli in analysisCasePallet.PalletLabels)
                    {
                        var pl = new PalletLabel(++pickId, pli.PalletLabelProperties, pli.ToBoxPosition(loadBBox));
                        pl.DrawEnd(graphics);
                    }
                }
                #endregion

                #region Strappers
                // ### strappers
                if (-1 == Solution.SelectedLayerIndex)
                {
                    foreach (var sd in Solution.Strappers)
                    {
                        if (null == sd.Points && sd.Points.Count > 0)
                        {
                            var strapper = new Strapper(
                                transform.transform(IntToAxis(sd.Strapper.Axis)),
                                sd.Strapper.Width,
                                sd.Strapper.Color,
                                sd.Points.Select(p => transform.transform(p)).ToList());
                            strapper.DrawEnd(graphics);
                        }
                    }
                }
                #endregion

                #region Pallet film
                // pallet film : End
                if (analysisCasePallet.HasPalletFilm && null != film)
                {
                    film.DrawEnd(graphics);
                }
                #endregion
            }
            else if (analysis is AnalysisPackableTruck analysisPackableTruck2)
            {
                Truck truck = new Truck(analysisPackableTruck2.TruckProperties);
                truck.DrawEnd(graphics);
            }
            else if (analysis is AnalysisPalletTruck analysisPalletTruck)
            {
                Truck truck = new Truck(analysisPalletTruck.TruckProperties);
                truck.DrawEnd(graphics);
            }
            // ### dimensions
            // dimensions should only be shown when no layer is selected
            if (graphics.ShowDimensions && (-1 == Solution.SelectedLayerIndex))
            {
                graphics.AddDimensions(new DimensionCube(BoundingBoxDim(DimCasePalletSol1), Color.Black, false));
                graphics.AddDimensions(new DimensionCube(BoundingBoxDim(DimCasePalletSol2), Color.Red, true));
            }
            // ###
        }
 /// <summary>
 /// Creates a new analysis without generating solutions
 /// </summary>
 /// <param name="name">Name of analysis</param>
 /// <param name="description">Description</param>
 /// <param name="box">Case</param>
 /// <param name="pallet">Pallet</param>
 /// <param name="interlayer">Interlayer</param>
 /// <param name="constraintSet">PalletConstraintSet</param>
 /// <param name="solutions">Solutions</param>
 /// <returns>CasePalletAnalysis generated using input parameters</returns>
 public CasePalletAnalysis CreateNewCasePalletAnalysis(
     string name, string description
     , BProperties box, PalletProperties pallet
     , InterlayerProperties interlayer, InterlayerProperties interlayerAntiSlip
     , PalletCornerProperties palletCorners, PalletCapProperties palletCap, PalletFilmProperties palletFilm
     , PalletConstraintSet constraintSet
     , List<CasePalletSolution> solutions)
 {
     CasePalletAnalysis analysis = new CasePalletAnalysis(
         box, pallet,
         interlayer, interlayerAntiSlip,
         palletCorners, palletCap, palletFilm,
         constraintSet);
     analysis.Name = name;
     analysis.Description = description;
     // insert in list
     _casePalletAnalyses.Add(analysis);
     // set solutions
     analysis.Solutions = solutions;
     // notify listeners
     NotifyOnNewCasePalletAnalysisCreated(analysis);
     // set solution selected if it is unique
     if (solutions.Count == 1)
         analysis.SelectSolutionByIndex(0);
     return analysis;
 }
 /// <summary>
 /// Creates a new analysis in this document + compute solutions
 /// </summary>
 /// <param name="name"></param>
 /// <param name="description"></param>
 /// <param name="box"></param>
 /// <param name="pallet"></param>
 /// <param name="interlayer"></param>
 /// <param name="constraintSet"></param>
 /// <param name="solver">Node : analysis creation requires a solver</param>
 /// <returns>An analysis</returns>
 public CasePalletAnalysis CreateNewCasePalletAnalysis(
     string name, string description
     , BProperties box, PalletProperties pallet
     , InterlayerProperties interlayer, InterlayerProperties interlayerAntiSlip
     , PalletCornerProperties palletCorners, PalletCapProperties palletCap, PalletFilmProperties palletFilm
     , PalletConstraintSet constraintSet
     , ICasePalletAnalysisSolver solver)
 {
     CasePalletAnalysis analysis = new CasePalletAnalysis(
         box, pallet,
         interlayer, interlayerAntiSlip,
         palletCorners, palletCap, palletFilm,
         constraintSet);
     analysis.Name = name;
     analysis.Description = description;
     // insert in list
     _casePalletAnalyses.Add(analysis);
     // compute analysis
     solver.ProcessAnalysis(analysis);
     if (analysis.Solutions.Count < 1)
     {	// remove analysis from list if it has no valid solution
         _casePalletAnalyses.Remove(analysis);
         return null;
     }
     // notify listeners
     NotifyOnNewCasePalletAnalysisCreated(analysis);
     Modify();
     return analysis;
 }
 public void Save(PalletCapProperties capProperties, XmlElement parentElement, XmlDocument xmlDoc)
 {
     // create PalletCornerProperties element
     XmlElement xmlCapProperties = xmlDoc.CreateElement("PalletCapProperties");
     parentElement.AppendChild(xmlCapProperties);
     // Id
     XmlAttribute guidAttribute = xmlDoc.CreateAttribute("Id");
     guidAttribute.Value = capProperties.Guid.ToString();
     xmlCapProperties.Attributes.Append(guidAttribute);
     // name
     XmlAttribute nameAttribute = xmlDoc.CreateAttribute("Name");
     nameAttribute.Value = capProperties.Name;
     xmlCapProperties.Attributes.Append(nameAttribute);
     // description
     XmlAttribute descAttribute = xmlDoc.CreateAttribute("Description");
     descAttribute.Value = capProperties.Description;
     xmlCapProperties.Attributes.Append(descAttribute);
     // length
     XmlAttribute lengthAttribute = xmlDoc.CreateAttribute("Length");
     lengthAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", capProperties.Length);
     xmlCapProperties.Attributes.Append(lengthAttribute);
     // width
     XmlAttribute widthAttribute = xmlDoc.CreateAttribute("Width");
     widthAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", capProperties.Width);
     xmlCapProperties.Attributes.Append(widthAttribute);
     // height
     XmlAttribute heightAttribute = xmlDoc.CreateAttribute("Height");
     heightAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", capProperties.Height);
     xmlCapProperties.Attributes.Append(heightAttribute);
     // inside length
     XmlAttribute insideLengthAttribute = xmlDoc.CreateAttribute("InsideLength");
     insideLengthAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", capProperties.Length);
     xmlCapProperties.Attributes.Append(insideLengthAttribute);
     // inside width
     XmlAttribute insideWidthAttribute = xmlDoc.CreateAttribute("InsideWidth");
     insideWidthAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", capProperties.Width);
     xmlCapProperties.Attributes.Append(insideWidthAttribute);
     // inside height
     XmlAttribute insideHeightAttribute = xmlDoc.CreateAttribute("InsideHeight");
     insideHeightAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", capProperties.Height);
     xmlCapProperties.Attributes.Append(insideHeightAttribute);
     // weight
     XmlAttribute weightAttribute = xmlDoc.CreateAttribute("Weight");
     weightAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", capProperties.Weight);
     xmlCapProperties.Attributes.Append(weightAttribute);
     // color
     XmlAttribute colorAttribute = xmlDoc.CreateAttribute("Color");
     colorAttribute.Value = string.Format("{0}", capProperties.Color.ToArgb());
     xmlCapProperties.Attributes.Append(colorAttribute);
 }
 public PalletCapProperties CreateNewPalletCap(
     string name, string description,
     double length, double width, double height,
     double innerLength, double innerWidth, double innerHeight,
     double weight,
     Color color)
 {
     // instantiate and initialize
     PalletCapProperties palletCap = new PalletCapProperties(
         this,
         name, description,
         length, width, height,
         innerLength, innerWidth, innerHeight,
         weight, color);
     // insert in list
     _typeList.Add(palletCap);
     // notify listeners
     NotifyOnNewTypeCreated(palletCap);
     Modify();
     return palletCap;
 }
        public override void Draw(Graphics3D graphics, Transform3D transform)
        {
            // clear list of picking box
            ClearPickingBoxes();

            if (null == _solution)
            {
                return;
            }
            AnalysisHomo analysis = _solution.Analysis;

            if (analysis is AnalysisPackablePallet analysisPackablePallet)
            {
                // ### draw pallet
                Pallet pallet = new Pallet(analysisPackablePallet.PalletProperties);
                pallet.Draw(graphics, transform);
            }
            else if (analysis is AnalysisPackableCase analysisPackableCase)
            {
                // ### draw case (inside)
                Case case_ = new Case(analysisPackableCase.CaseProperties);
                case_.DrawInside(graphics, transform);
            }
            else if (analysis is AnalysisPackableTruck analysisPackableTruck)
            {
                // ### draw truck
                Truck truck = new Truck(analysisPackableTruck.TruckProperties);
                truck.DrawBegin(graphics);
            }
            else if (analysis is AnalysisPalletTruck analysisPalletTruck)
            {
                // ### draw truck
                Truck truck = new Truck(analysisPalletTruck.TruckProperties);
                truck.DrawBegin(graphics);
            }
            // ### draw solution
            uint          layerId = 0, pickId = 0;
            List <ILayer> layers = _solution.Layers;

            foreach (ILayer layer in layers)
            {
                BBox3D bbox = new BBox3D();
                // ### layer of boxes
                Layer3DBox layerBox = layer as Layer3DBox;
                if (null != layerBox)
                {
                    if (analysis.Content is LoadedPallet)
                    {
                        LoadedPallet loadedPallet = analysis.Content as LoadedPallet;
                        BBox3D       solBBox      = loadedPallet.ParentAnalysis.Solution.BBoxGlobal;
                        foreach (BoxPosition bPosition in layerBox)
                        {
                            bool simplified = false;
                            if (simplified)
                            {
                                BoxProperties bProperties = new BoxProperties(null, solBBox.Dimensions);
                                bProperties.SetColor(Color.Chocolate);
                                Box b = new Box(pickId++, bProperties, bPosition.Transform(transform));
                                graphics.AddBox(b);
                                bbox.Extend(b.BBox);
                            }
                            else
                            {
                                graphics.AddImage(loadedPallet.ParentAnalysis, solBBox.DimensionsVec, bPosition.Transform(transform));
                            }
                        }
                    }
                    else
                    {
                        bool        aboveSelectedLayer = (_solution.SelectedLayerIndex != -1) && (layerId > _solution.SelectedLayerIndex);
                        Transform3D upTranslation      = Transform3D.Translation(new Vector3D(0.0, 0.0, aboveSelectedLayer ? DistanceAboveSelectedLayer : 0.0));

                        foreach (BoxPosition bPosition in layerBox)
                        {
                            BoxPosition boxPositionModified = bPosition.Transform(transform * upTranslation);
                            Box         b = null;
                            if (analysis.Content is PackProperties)
                            {
                                b = new Pack(pickId++, analysis.Content as PackProperties, boxPositionModified);
                            }
                            else
                            {
                                b = new Box(pickId++, analysis.Content as PackableBrick, boxPositionModified);
                            }
                            graphics.AddBox(b);
                            bbox.Extend(b.BBox);
                        }
                    }
                }
                Layer3DCyl layerCyl = layer as Layer3DCyl;
                if (null != layerCyl)
                {
                    foreach (Vector3D vPos in layerCyl)
                    {
                        Cylinder c = new Cylinder(pickId++, analysis.Content as CylinderProperties, new CylPosition(transform.transform(vPos), HalfAxis.HAxis.AXIS_Z_P));
                        graphics.AddCylinder(c);
                        bbox.Extend(c.BBox);
                    }
                }
                if (null != layerBox || null != layerCyl)
                {
                    // add layer BBox
                    AddPickingBox(bbox, layerId);
                    // draw bounding box around selected layer
                    if (layerId == _solution.SelectedLayerIndex)
                    {
                        DrawLayerBoundingBox(graphics, bbox);
                    }
                    ++layerId;
                }

                // ### interlayer
                if (layer is InterlayerPos interlayerPos)
                {
                    InterlayerProperties interlayerProp = _solution.Interlayers[interlayerPos.TypeId];
                    if (null != interlayerProp)
                    {
                        bool        aboveSelectedLayer = (_solution.SelectedLayerIndex != -1) && (layerId > _solution.SelectedLayerIndex);
                        Transform3D upTranslation      = Transform3D.Translation(new Vector3D(0.0, 0.0, aboveSelectedLayer ? DistanceAboveSelectedLayer : 0.0));

                        BoxPosition bPosition = new BoxPosition(
                            new Vector3D(
                                analysis.Offset.X + 0.5 * (analysis.ContainerDimensions.X - interlayerProp.Length)
                                , analysis.Offset.Y + 0.5 * (analysis.ContainerDimensions.Y - interlayerProp.Width)
                                , interlayerPos.ZLow
                                ), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                        Box box = new Box(pickId++, interlayerProp, bPosition.Transform(transform * upTranslation));
                        graphics.AddBox(box);
                        bbox.Extend(box.BBox);
                    }
                }
            }
            BBox3D loadBBox      = _solution.BBoxLoad;
            BBox3D loadBBoxWDeco = _solution.BBoxLoadWDeco;

            if (analysis is AnalysisCasePallet analysisCasePallet)
            {
                #region Pallet corners
                // ### pallet corners : Begin
                Corner[] corners = new Corner[4];
                if (analysisCasePallet.HasPalletCorners)
                {
                    // positions
                    Vector3D[] cornerPositions =
                    {
                        loadBBox.PtMin
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                    };
                    // length axes
                    HalfAxis.HAxis[] lAxes =
                    {
                        HalfAxis.HAxis.AXIS_X_P,
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N
                    };
                    // width axes
                    HalfAxis.HAxis[] wAxes =
                    {
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N,
                        HalfAxis.HAxis.AXIS_X_P
                    };
                    // corners
                    if (analysisCasePallet.HasPalletCorners)
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            corners[i] = new Corner(0, analysisCasePallet.PalletCornerProperties)
                            {
                                Height = Math.Min(analysisCasePallet.PalletCornerProperties.Length, loadBBox.Height)
                            };
                            corners[i].SetPosition(
                                transform.transform(cornerPositions[i])
                                , HalfAxis.Transform(lAxes[i], transform), HalfAxis.Transform(wAxes[i], transform)
                                );
                            corners[i].DrawBegin(graphics);
                        }
                    }
                }
                #endregion

                #region Pallet film
                // ### pallet film
                Film film = null;
                if (analysisCasePallet.HasPalletFilm && -1 == _solution.SelectedLayerIndex)
                {
                    // instantiate film
                    PalletFilmProperties palletFilmProperties = analysisCasePallet.PalletFilmProperties;
                    film = new Film(
                        palletFilmProperties.Color,
                        palletFilmProperties.UseTransparency,
                        palletFilmProperties.UseHatching,
                        palletFilmProperties.HatchSpacing,
                        palletFilmProperties.HatchAngle);
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_N, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_N, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis)
                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform)
                                                        , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width)
                                                        , UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1)));
                    film.DrawBegin(graphics);
                }
                #endregion

                #region Pallet corners
                // pallet corners : End
                if (analysisCasePallet.HasPalletCorners)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        corners[i].DrawEnd(graphics);
                    }
                }
                #endregion

                #region Pallet Cap
                // ### pallet cap
                if (analysisCasePallet.HasPalletCap)
                {
                    PalletCapProperties capProperties = analysisCasePallet.PalletCapProperties;
                    BoxPosition         bPosition     = new BoxPosition(new Vector3D(
                                                                            0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length),
                                                                            0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width),
                                                                            loadBBox.PtMax.Z - capProperties.InsideHeight)
                                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform)
                                                                        , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform)
                                                                        );

                    Transform3D upTranslation = Transform3D.Translation(new Vector3D(0.0, 0.0, -1 != _solution.SelectedLayerIndex ? DistanceAboveSelectedLayer : 0.0));
                    PalletCap   cap           = new PalletCap(0, capProperties, bPosition.Transform(upTranslation));
                    cap.DrawEnd(graphics);
                }
                #endregion

                #region Pallet film
                // pallet film : End
                if (analysisCasePallet.HasPalletFilm && null != film)
                {
                    film.DrawEnd(graphics);
                }
                #endregion
            }
            else if (analysis is AnalysisPackableTruck analysisPackableTruck2)
            {
                Truck truck = new Truck(analysisPackableTruck2.TruckProperties);
                truck.DrawEnd(graphics);
            }
            else if (analysis is AnalysisPalletTruck analysisPalletTruck)
            {
                Truck truck = new Truck(analysisPalletTruck.TruckProperties);
                truck.DrawEnd(graphics);
            }
            // ### dimensions
            // dimensions should only be shown when no layer is selected
            if (graphics.ShowDimensions && (-1 == _solution.SelectedLayerIndex))
            {
                graphics.AddDimensions(new DimensionCube(BoundingBoxDim(DimCasePalletSol1), Color.Black, false));
                graphics.AddDimensions(new DimensionCube(BoundingBoxDim(DimCasePalletSol2), Color.Red, true));
            }
            // ###
        }
Exemple #21
0
        public void Export(AnalysisLayered analysis, string filePath)
        {
            // solution
            SolutionLayered sol = analysis.SolutionLay;
            // scene
            var scene = new SceneBuilder();

            if (analysis.Content is BoxProperties boxProperties)
            {
                Color[] colors     = boxProperties.Colors;
                Color   colorFilet = boxProperties.Colors[0];
                Color   colorTape  = boxProperties.TapeColor;

                var meshPallet = BuildPalletMesh(analysis.Container as PalletProperties);
                var meshCase   = BuildCaseMesh("Case", (float)boxProperties.Length, (float)boxProperties.Width, (float)boxProperties.Height,
                                               colors, 0.0f, colorFilet,
                                               boxProperties.TapeWidth.Activated ? (float)boxProperties.TapeWidth.Value : 0.0f, colorTape);
                var meshesInterlayer = BuildInterlayerMeshes(analysis);

                // add pallet mesh
                scene.AddRigidMesh(meshPallet, Matrix4x4.Identity);
                // add cases (+ interlayers) mesh

                List <ILayer> layers = sol.Layers;
                foreach (ILayer layer in layers)
                {
                    if (layer is Layer3DBox layerBox)
                    {
                        foreach (BoxPosition bPosition in layerBox)
                        {
                            scene.AddRigidMesh(meshCase, BoxPositionToMatrix4x4(bPosition));
                        }
                    }
                    else if (layer is InterlayerPos interlayerPos)
                    {
                        InterlayerProperties interlayerProp = sol.Interlayers[interlayerPos.TypeId];
                        var bPosition = new BoxPosition(new Vector3D(
                                                            0.5 * (analysis.ContainerDimensions.X - interlayerProp.Length)
                                                            , 0.5 * (analysis.ContainerDimensions.Y - interlayerProp.Width)
                                                            , interlayerPos.ZLow),
                                                        HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                        scene.AddRigidMesh(meshesInterlayer[interlayerPos.TypeId], BoxPositionToMatrix4x4(bPosition));
                    }
                }
            }
            // add pallet cap if any
            if (analysis is AnalysisCasePallet analysisCasePallet && analysisCasePallet.HasPalletCap)
            {
                PalletCapProperties capProperties = analysisCasePallet.PalletCapProperties;
                BoxPosition         bPosition     = new BoxPosition(new Vector3D(
                                                                        0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length),
                                                                        0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width),
                                                                        sol.BBoxLoad.PtMax.Z - capProperties.InsideHeight)
                                                                    , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P
                                                                    );

                scene.AddRigidMesh(BuildPalletCapMesh(
                                       (float)capProperties.Length, (float)capProperties.Width, (float)capProperties.Height,
                                       (float)capProperties.InsideLength, (float)capProperties.InsideWidth, (float)capProperties.InsideHeight,
                                       capProperties.Color),
                                   BoxPositionToMatrix4x4(bPosition));
            }
            // save model
            var model = scene.ToGltf2();

            model.Save(filePath);
        }
        private void AppendPalletCapElement(PalletCapProperties palletCapProp, XmlElement elemPalletAnalysis, XmlDocument xmlDoc)
        {
            // sanity check
            if (null == palletCapProp) return;
            // namespace
            string ns = xmlDoc.DocumentElement.NamespaceURI;
            // interlayer
            XmlElement elemPalletCap = xmlDoc.CreateElement("palletCap", ns);
            elemPalletAnalysis.AppendChild(elemPalletCap);
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = palletCapProp.Name;
            elemPalletCap.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = palletCapProp.Description;
            elemPalletCap.AppendChild(elemDescription);

            AppendElementValue(xmlDoc, elemPalletCap, "length", UnitsManager.UnitType.UT_LENGTH, palletCapProp.Length);
            AppendElementValue(xmlDoc, elemPalletCap, "width", UnitsManager.UnitType.UT_LENGTH, palletCapProp.Width);
            AppendElementValue(xmlDoc, elemPalletCap, "height", UnitsManager.UnitType.UT_LENGTH, palletCapProp.Height);
            AppendElementValue(xmlDoc, elemPalletCap, "innerLength", UnitsManager.UnitType.UT_LENGTH, palletCapProp.InsideLength);
            AppendElementValue(xmlDoc, elemPalletCap, "innerWidth", UnitsManager.UnitType.UT_LENGTH, palletCapProp.InsideWidth);
            AppendElementValue(xmlDoc, elemPalletCap, "innerHeight", UnitsManager.UnitType.UT_LENGTH, palletCapProp.InsideHeight);
            AppendElementValue(xmlDoc, elemPalletCap, "weight", UnitsManager.UnitType.UT_MASS, palletCapProp.Weight);
            // ---
            // view_palletCap_iso
            // build image
            Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail));
            graphics.CameraPosition = Graphics3D.Corner_0;
            PalletCap palletCap = new PalletCap(0, palletCapProp, Vector3D.Zero);
            palletCap.Draw(graphics);
            graphics.AddDimensions(new DimensionCube(palletCapProp.Length, palletCapProp.Width, palletCapProp.Height));
            graphics.Flush();
            // save image ?
            SaveImageAs(graphics.Bitmap, "view_palletCap_iso.png");
            // ---
            // view_palletCap_iso
            XmlElement elemImage = xmlDoc.CreateElement("view_palletCap_iso", ns);
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
            elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
            XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
            styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 4, graphics.Bitmap.Height / 4);
            elemImage.Attributes.Append(styleAttribute);
            elemPalletCap.AppendChild(elemImage);
        }
        public override void Draw(Graphics3D graphics, bool showDimensions)
        {
            // clear list of picking box
            ClearPickingBoxes();

            if (null == _solution)
            {
                return;
            }
            Analysis           analysis           = _solution.Analysis;
            AnalysisCasePallet analysisCasePallet = analysis as AnalysisCasePallet;
            AnalysisBoxCase    analysisBoxCase    = analysis as AnalysisBoxCase;

            if (null != analysisCasePallet)
            {
                // ### draw pallet
                Pallet pallet = new Pallet(analysisCasePallet.PalletProperties);
                pallet.Draw(graphics, Transform3D.Identity);
            }
            else if (null != analysisBoxCase)
            {
                // draw case (inside)
                Case case_ = new Case(analysisBoxCase._caseProperties);
                case_.DrawInside(graphics);
            }

            // ### draw solution
            uint          layerId = 0, pickId = 0;
            List <ILayer> layers = _solution.Layers;

            foreach (ILayer layer in layers)
            {
                // ### layer of boxes
                BoxLayer blayer = layer as BoxLayer;
                if (null != blayer)
                {
                    BBox3D bbox = new BBox3D();
                    foreach (BoxPosition bPosition in blayer)
                    {
                        Box b = null;
                        if (analysis.Content is PackProperties)
                        {
                            b = new Pack(pickId++, analysis.Content as PackProperties, bPosition);
                        }
                        else
                        {
                            b = new Box(pickId++, analysis.Content, bPosition);
                        }
                        graphics.AddBox(b);
                        bbox.Extend(b.BBox);
                    }
                    // add layer BBox
                    AddPickingBox(bbox, layerId);
                    // draw bounding box around selected layer
                    if (layerId == _solution.SelectedLayerIndex)
                    {
                        DrawLayerBoundingBox(graphics, bbox);
                    }
                    ++layerId;
                }
                // ### interlayer
                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    InterlayerProperties interlayerProp = _solution.Interlayers[interlayerPos.TypeId];
                    if (null != interlayerProp)
                    {
                        Box box = new Box(pickId++, interlayerProp);
                        box.Position = new Vector3D(
                            0.5 * (analysis.ContainerDimensions.X - interlayerProp.Length)
                            , 0.5 * (analysis.ContainerDimensions.Y - interlayerProp.Width)
                            , interlayerPos.ZLow
                            );
                        graphics.AddBox(box);
                    }
                }
            }
            BBox3D loadBBox      = _solution.BBoxLoad;
            BBox3D loadBBoxWDeco = _solution.BBoxLoadWDeco;

            if (null != analysisCasePallet)
            {
                #region Pallet corners
                // ### pallet corners : Begin
                Corner[] corners = new Corner[4];
                if (analysisCasePallet.HasPalletCorners)
                {
                    // positions
                    Vector3D[] cornerPositions =
                    {
                        loadBBox.PtMin
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                        , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                    };
                    // length axes
                    HalfAxis.HAxis[] lAxes =
                    {
                        HalfAxis.HAxis.AXIS_X_P,
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N
                    };
                    // width axes
                    HalfAxis.HAxis[] wAxes =
                    {
                        HalfAxis.HAxis.AXIS_Y_P,
                        HalfAxis.HAxis.AXIS_X_N,
                        HalfAxis.HAxis.AXIS_Y_N,
                        HalfAxis.HAxis.AXIS_X_P
                    };
                    // corners
                    if (analysisCasePallet.HasPalletCorners)
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            corners[i]        = new Corner(0, analysisCasePallet.PalletCornerProperties);
                            corners[i].Height = Math.Min(analysisCasePallet.PalletCornerProperties.Length, loadBBox.Height);
                            corners[i].SetPosition(cornerPositions[i], lAxes[i], wAxes[i]);
                            corners[i].DrawBegin(graphics);
                        }
                    }
                }
                #endregion

                #region Pallet film
                // ### pallet film
                Film film = null;
                if (analysisCasePallet.HasPalletFilm)
                {
                    PalletFilmProperties palletFilmProperties = analysisCasePallet.PalletFilmProperties;
                    film = new Film(
                        palletFilmProperties.Color,
                        palletFilmProperties.UseTransparency,
                        palletFilmProperties.UseHatching,
                        palletFilmProperties.HatchSpacing,
                        palletFilmProperties.HatchAngle);
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin,
                                                        HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis,
                                                        HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis,
                                                        HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis,
                                                        HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                    film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis,
                                                        HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width),
                                                        UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1)));
                    film.DrawBegin(graphics);
                }
                #endregion

                #region Pallet corners
                // pallet corners : End
                if (analysisCasePallet.HasPalletCorners)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        corners[i].DrawEnd(graphics);
                    }
                }
                #endregion

                #region Pallet Cap
                // ### pallet cap
                if (analysisCasePallet.HasPalletCap)
                {
                    PalletCapProperties capProperties = analysisCasePallet.PalletCapProperties;
                    Vector3D            pos           = new Vector3D(
                        0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length),
                        0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width),
                        loadBBox.PtMax.Z - capProperties.InsideHeight);
                    PalletCap cap = new PalletCap(0, capProperties, pos);
                    cap.DrawEnd(graphics);
                }
                #endregion

                #region Pallet film
                // pallet film : End
                if (analysisCasePallet.HasPalletFilm)
                {
                    film.DrawEnd(graphics);
                }
                #endregion
            }

            // ### dimensions
            if (showDimensions)
            {
                graphics.AddDimensions(
                    new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1)
                                      , Color.Black, false));
                graphics.AddDimensions(
                    new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2)
                                      , Color.Red, true));
            }
        }
        /// <summary>
        /// Use this method when drawing a solution that belongs an analysis
        /// </summary>
        /// <param name="graphics"></param>
        public void Draw(Graphics3D graphics)
        {
            if (null == _solution)
            {
                return;
            }
            // initialize Graphics3D object
            if (!graphics.ShowBoxIds)
            {
                // draw pallet
                Pallet pallet = new Pallet(_analysis.PalletProperties);
                pallet.Draw(graphics, Transform3D.Identity);
            }
            // load bounding box
            BBox3D loadBBox      = _solution.LoadBoundingBox;
            BBox3D loadBBoxWDeco = _solution.LoadBoundingBoxWDeco;

            #region Pallet film : begin
            // draw film
            Film film = null;
            if (_solution.Analysis.HasPalletFilm)
            {
                PalletFilmProperties palletFilmProperties = _solution.Analysis.PalletFilmProperties;
                film = new Film(
                    palletFilmProperties.Color,
                    palletFilmProperties.UseTransparency,
                    palletFilmProperties.UseHatching,
                    palletFilmProperties.HatchSpacing,
                    palletFilmProperties.HatchAngle);
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin,
                                                    HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis,
                                                    HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis,
                                                    HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis,
                                                    HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis,
                                                    HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width),
                                                    UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1)));
                film.DrawBegin(graphics);
            }
            #endregion

            #region Pallet corners
            // *** pallet corners
            // positions
            Vector3D[] cornerPositions =
            {
                loadBBox.PtMin
                , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
            };
            // length axes
            HalfAxis.HAxis[] lAxes =
            {
                HalfAxis.HAxis.AXIS_X_P,
                HalfAxis.HAxis.AXIS_Y_P,
                HalfAxis.HAxis.AXIS_X_N,
                HalfAxis.HAxis.AXIS_Y_N
            };
            // width axes
            HalfAxis.HAxis[] wAxes =
            {
                HalfAxis.HAxis.AXIS_Y_P,
                HalfAxis.HAxis.AXIS_X_N,
                HalfAxis.HAxis.AXIS_Y_N,
                HalfAxis.HAxis.AXIS_X_P
            };
            // corners
            Corner[] corners = new Corner[4];
            if (_solution.Analysis.HasPalletCorners)
            {
                for (int i = 0; i < 4; ++i)
                {
                    corners[i]        = new Corner(0, _solution.Analysis.PalletCornerProperties);
                    corners[i].Height = Math.Min(_solution.Analysis.PalletCornerProperties.Length, loadBBox.Height);
                    corners[i].SetPosition(cornerPositions[i], lAxes[i], wAxes[i]);
                    corners[i].DrawBegin(graphics);
                }
            }
            // *** pallet corners : end
            #endregion

            // draw solution
            uint pickId = 0;
            foreach (ILayer layer in _solution)
            {
                BoxLayer blayer = layer as BoxLayer;
                if (null != blayer)
                {
                    foreach (BoxPosition bPosition in blayer)
                    {
                        graphics.AddBox(new Box(pickId++, _analysis.BProperties, bPosition));
                    }
                }

                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    InterlayerProperties currInterlayerProperties = (0 == interlayerPos.TypeId)
                        ? _analysis.InterlayerProperties : _analysis.InterlayerPropertiesAntiSlip;
                    Box box = new Box(pickId++, currInterlayerProperties);
                    // set position
                    box.Position = new Vector3D(
                        0.5 * (_analysis.PalletProperties.Length - currInterlayerProperties.Length)
                        , 0.5 * (_analysis.PalletProperties.Width - currInterlayerProperties.Width)
                        , interlayerPos.ZLow);
                    // draw
                    graphics.AddBox(box);
                }
            }

            if (_showDimensions)
            {
                graphics.AddDimensions(
                    new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1)
                                      , Color.Black, false));
                graphics.AddDimensions(
                    new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2)
                                      , Color.Red, true));
            }

            // pallet corners
            if (_solution.Analysis.HasPalletCorners)
            {
                for (int i = 0; i < 4; ++i)
                {
                    corners[i].DrawEnd(graphics);
                }
            }
            // pallet cap
            if (_solution.HasPalletCap)
            {
                PalletCapProperties capProperties = _solution.Analysis.PalletCapProperties;
                Vector3D            pos           = new Vector3D(
                    0.5 * (_analysis.PalletProperties.Length - capProperties.Length),
                    0.5 * (_analysis.PalletProperties.Width - capProperties.Width),
                    loadBBox.PtMax.Z - capProperties.InsideHeight);
                PalletCap cap = new PalletCap(0, capProperties, pos);
                cap.DrawEnd(graphics);
            }
            // pallet film
            if (_solution.Analysis.HasPalletFilm)
            {
                film.DrawEnd(graphics);
            }
            graphics.EnableFaceSorting = false;
        }
 /// <summary>
 /// Process case/pallet analysis
 /// </summary>
 /// <param name="analysis">Pallet analysis to process</param>
 public void ProcessAnalysis(CasePalletAnalysis analysis)
 {
     _bProperties = analysis.BProperties;
     _palletProperties = analysis.PalletProperties;
     _interlayerProperties = analysis.InterlayerProperties;
     _interlayerPropertiesAntiSlip = analysis.InterlayerPropertiesAntiSlip;
     _cornerProperties = analysis.PalletCornerProperties;
     _capProperties = analysis.PalletCapProperties;
     _constraintSet = analysis.ConstraintSet;
     // check contraint set validity
     if (!_constraintSet.IsValid)
         throw new EngineException("Constraint set is invalid!");
     // generate solutions
     analysis.Solutions = GenerateSolutions();
 }