Ejemplo n.º 1
0
        public FormBrowseSolution(Document doc, AnalysisLayered analysis)
        {
            InitializeComponent();

            _doc      = doc;
            _analysis = analysis;
        }
        private void OnSelChangeGrid(object sender, SourceGrid.RangeRegionChangedEventArgs e)
        {
            try
            {
                SourceGrid.Selection.RowSelection select = sender as SourceGrid.Selection.RowSelection;
                SourceGrid.Grid g = select.Grid as SourceGrid.Grid;

                SourceGrid.RangeRegion region = g.Selection.GetSelectionRegion();
                int[] indexes = region.GetRowsIndex();
                if (indexes.Length < 1 || indexes[0] < 1)
                {
                    _selectedAnalysis = null;
                }
                else
                {
                    _selectedAnalysis = _analyses[indexes[0] - 1];
                    // analysis name/description
                    if (null != _selectedAnalysis)
                    {
                        BoxProperties  box  = SelectedBox;
                        PackProperties pack = _selectedAnalysis.Content as PackProperties;
                        UpdateStatus(string.Empty);
                    }
                }

                graphCtrlPack.Invalidate();
                graphCtrlSolution.Invalidate();
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
        }
Ejemplo n.º 3
0
 private item BuildItem(AnalysisLayered analysis)
 {
     if (analysis is AnalysisCasePallet analysisCasePallet)
     {
         Packable packable = analysisCasePallet.Content;
         ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet;
         bool[]        orient   = constraintSet.AllowedOrientations;
         StringBuilder sbOrient = new StringBuilder();
         foreach (bool b in orient)
         {
             sbOrient.Append(b ? "1" : "0");
         }
         return(new item()
         {
             id = 1,
             name = packable.Name,
             length = packable.OuterDimensions.X,
             width = packable.OuterDimensions.Y,
             height = packable.OuterDimensions.Z,
             weight = packable.Weight,
             maxWeightOnTop = 0.0,
             permittedOrientations = sbOrient.ToString()
         });
     }
     else
     {
         throw new Exception(string.Format("Unexpected analysis type : {0}", analysis.GetType()));
     }
 }
Ejemplo n.º 4
0
        private placement[] BuildPlacementArray(SolutionLayered sol, AnalysisLayered analysis)
        {
            List <placement> lPlacements = new List <placement>();
            List <ILayer>    layers      = sol.Layers;

            foreach (ILayer layer in layers)
            {
                if (layer is Layer3DBox layerBox)
                {
                    foreach (BoxPosition bPosition in layerBox)
                    {
                        Vector3D writtenPosition = ConvertPosition(bPosition, analysis.ContentDimensions);
                        lPlacements.Add(
                            new placement()
                        {
                            itemId = 1,
                            x      = writtenPosition.X,
                            y      = writtenPosition.Y,
                            z      = writtenPosition.Z,
                            L      = ToAxis(bPosition.DirectionLength),
                            W      = ToAxis(bPosition.DirectionWidth)
                        }
                            );
                    }
                }
            }
            return(lPlacements.ToArray());
        }
Ejemplo n.º 5
0
        public override void Export(AnalysisLayered analysis, ref Stream stream)
        {
            SolutionLayered sol           = analysis.SolutionLay;
            string          nameContainer = analysis.Container.Name;
            string          nameContent   = analysis.Content.Name;

            // Geometry container
            Geometry geomContainer = new Geometry()
            {
                Uuid = Guid.NewGuid().ToString(),
                Type = "Geometry",
                Data = new Data()
                {
                    Vertices = new List <double>(),
                    Normals  = new List <double>(),
                    Uvs      = new List <List <double> >(),
                    Faces    = new List <int>()
                }
            };

            // Material container
            Material matContainer = new Material()
            {
                Uuid = Guid.NewGuid().ToString(),
                Type = "Material",
                Name = string.Format("Mat_{0}", nameContainer)
            };

            // Geometry content
            Geometry geomContent = new Geometry()
            {
            };

            // Material content
            Material matContent = new Material()
            {
                Uuid = Guid.NewGuid().ToString(),
                Type = "Material",
                Name = string.Format("Mat_{0}", nameContent)
            };

            RootObject rootObj = new RootObject()
            {
                Geometries = new List <Geometry>()
                {
                    geomContainer, geomContent
                },
                Materials = new List <Material>()
                {
                    matContainer, matContent
                },
                Object = new Json.Object()
            };
            string filePath = string.Empty;

            File.WriteAllText(filePath, JsonConvert.SerializeObject(rootObj));
        }
Ejemplo n.º 6
0
        public DockContentAnalysisEdit(IDocument document, AnalysisLayered analysis)
            : base(document)
        {
            _analysis = analysis;
            _analysis.AddListener(this);
            _solution = analysis.SolutionLay;

            InitializeComponent();
        }
Ejemplo n.º 7
0
        public override void Export(AnalysisLayered analysis, ref Stream stream)
        {
            // number formatting
            NumberFormatInfo nfi = new NumberFormatInfo
            {
                NumberDecimalSeparator = ".",
                NumberGroupSeparator   = "",
                NumberDecimalDigits    = 1
            };

            // initialize csv file
            var             csv    = new StringBuilder();
            SolutionLayered sol    = analysis.SolutionLay;
            var             layers = sol.Layers;

            foreach (ILayer layer in layers)
            {
                if (layer is Layer3DBox layerBox)
                {
                    layerBox.Sort(analysis.Content, Layer3DBox.SortType.DIST_MAXCORNER);
                    foreach (BoxPosition bPosition in layerBox)
                    {
                        Vector3D pos = ConvertPosition(bPosition, analysis.ContentDimensions);
                        csv.AppendLine(
                            $"1;" +
                            $"{pos.X.ToString("0,0.0", nfi)};" +
                            $"{pos.Y.ToString("0,0.0", nfi)};" +
                            $"{pos.Z.ToString("0,0.0", nfi)};" +
                            $"{bPosition.DirectionLength};" +
                            $"{bPosition.DirectionWidth}");
                    }
                }
                else if (layer is Layer3DCyl layerCyl)
                {
                    layerCyl.Sort(analysis.Content, Layer3DCyl.SortType.DIST_CENTER);
                    foreach (Vector3D vPos in layerCyl)
                    {
                        csv.AppendLine(
                            $"1;" +
                            $"{vPos.X.ToString("0,0.0", nfi)};" +
                            $"{vPos.Y.ToString("0,0.0", nfi)};" +
                            $"{vPos.Z.ToString("0,0.0", nfi)};"
                            );
                    }
                }
            }
            var writer = new StreamWriter(stream);

            writer.Write(csv.ToString());
            writer.Flush();
            stream.Position = 0;
        }
Ejemplo n.º 8
0
        private List <MeshBuilder <VPOS /*, VTEX*/> > BuildInterlayerMeshes(AnalysisLayered analysis)
        {
            var lMesh = new List <MeshBuilder <VPOS /*, VTEX*/> >();

            foreach (var interlayer in analysis.Interlayers)
            {
                lMesh.Add(BuildCaseMesh(
                              $"{interlayer.Name}",
                              (float)interlayer.Length, (float)interlayer.Width, (float)interlayer.Thickness,
                              Enumerable.Repeat(interlayer.Color, 6).ToArray(),
                              0.0f, Color.Black, 0.0f, Color.Beige));
            }
            return(lMesh);
        }
Ejemplo n.º 9
0
        public DockContentAnalysisEdit(IDocument document, AnalysisLayered analysis)
            : base(document)
        {
            _analysis = analysis;
            _analysis.AddListener(this);
            _solution = analysis.SolutionLay;

            InitializeComponent();

            if (document is Document doc)
            {
                doc.TypeCreated += OnTypeCreated;
                doc.TypeRemoved += OnTypeRemoved;
            }
        }
Ejemplo n.º 10
0
        public override void Export(AnalysisLayered analysis, ref Stream stream)
        {
            SolutionLayered sol = analysis.SolutionLay;

            // build orderDocument element
            orderDocument document = new orderDocument()
            {
                date      = DateTime.Now,
                unit      = CurrentUnit,
                author    = analysis.ParentDocument != null ? analysis.ParentDocument.Author : string.Empty,
                orderType = new orderDocumentOrderType()
                {
                    orderNumber = analysis.Name,
                    orderLine   = new orderLine()
                    {
                        itemId   = 1,
                        quantity = analysis.Solution.ItemCount
                    },
                    loadSpace = BuildLoadSpace(analysis),
                    item      = BuildItem(analysis),
                    load      = new load()
                    {
                        loadSpaceId = 1,
                        statistics  = new statistics()
                        {
                            loadVolume        = sol.LoadVolume,
                            loadWeight        = sol.LoadWeight,
                            volumeUtilization = sol.VolumeEfficiency,
                            weightUtilization = sol.WeightEfficiency.ToDouble(),
                            cOfG = new cOfG()
                            {
                                x = sol.COfG.X, y = sol.COfG.Y, z = sol.COfG.Z
                            },
                            loadHeight = sol.BBoxLoad.Height
                        },
                        placement = BuildPlacementArray(sol, analysis)
                    }
                }
            };

            // serialization
            XmlSerializer serializer = new XmlSerializer(typeof(orderDocument));

            serializer.Serialize(stream, document);
            stream.Flush();
            stream.Seek(0, SeekOrigin.Begin);
        }
Ejemplo n.º 11
0
        public override void Export(AnalysisLayered analysis, ref Stream stream)
        {
            var sol    = analysis.SolutionLay;
            var layers = sol.Layers;

            // number formatting
            NumberFormatInfo nfi = new NumberFormatInfo
            {
                NumberDecimalSeparator = ".",
                NumberGroupSeparator   = "",
                NumberDecimalDigits    = 1
            };

            var csv = new StringBuilder();
            // case dimension
            Vector3D caseDim = analysis.ContentDimensions;

            csv.AppendLine($"{caseDim.X.ToString("0,0.0", nfi)};{caseDim.Y.ToString("0,0.0", nfi)};{caseDim.Z.ToString("0,0.0", nfi)}");
            // number of layers; number of drops
            int noDrops = sol.SolutionItems.Count;

            csv.AppendLine($"{sol.SolutionItems.Count};{noDrops}");
            // interlayers
            foreach (var solItem in sol.SolutionItems)
            {
                csv.AppendLine($"{(solItem.HasInterlayer ? 1 : 0)};{solItem.InterlayerIndex}");
            }
            // boxes layer 0
            if (sol.SolutionItems.Count > 1)
            {
                var solItem = sol.SolutionItems[0];
            }

            // boxes layer 1
            if (sol.SolutionItems.Count > 2)
            {
                var solItem = sol.SolutionItems[1];
            }

            // write to stream
            var writer = new StreamWriter(stream);

            writer.Write(csv.ToString());
            writer.Flush();
            stream.Position = 0;
        }
Ejemplo n.º 12
0
        private placement[] BuildPlacementArray(SolutionLayered sol, AnalysisLayered analysis)
        {
            List <placement> lPlacements = new List <placement>();
            List <ILayer>    layers      = sol.Layers;

            foreach (ILayer layer in layers)
            {
                if (layer is Layer3DBox layerBox)
                {
                    layerBox.Sort(analysis.Content, Layer3DBox.SortType.DIST_MAXCORNER);
                    foreach (BoxPosition bPosition in layerBox)
                    {
                        Vector3D writtenPosition = ConvertPosition(bPosition, analysis.ContentDimensions);
                        lPlacements.Add(
                            new placement()
                        {
                            itemId = 1,
                            x      = writtenPosition.X,
                            y      = writtenPosition.Y,
                            z      = writtenPosition.Z,
                            L      = ToAxis(bPosition.DirectionLength),
                            W      = ToAxis(bPosition.DirectionWidth)
                        }
                            );
                    }
                }
                else if (layer is Layer3DCyl layerCyl)
                {
                    layerCyl.Sort(analysis.Content, Layer3DCyl.SortType.DIST_CENTER);
                    foreach (Vector3D vPos in layerCyl)
                    {
                        lPlacements.Add(
                            new placement()
                        {
                            itemId = 1,
                            x      = vPos.X, y = vPos.Y, z = vPos.Z
                        }
                            );
                    }
                }
            }
            return(lPlacements.ToArray());
        }
Ejemplo n.º 13
0
 private loadSpace BuildLoadSpace(AnalysisLayered analysis)
 {
     if (analysis is AnalysisCasePallet analysisCasePallet)
     {
         PalletProperties        palletProperties = analysisCasePallet.PalletProperties;
         ConstraintSetCasePallet constraintSet    = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet;
         return(new loadSpace()
         {
             id = 1,
             name = palletProperties.Name,
             length = palletProperties.Length,
             width = palletProperties.Width,
             baseHeight = palletProperties.Height,
             maxLengthOverhang = constraintSet.Overhang.X,
             maxWidthOverhang = constraintSet.Overhang.Y,
             maxLoadHeight = constraintSet.OptMaxHeight.Activated ? constraintSet.OptMaxHeight.Value : 0.0,
             maxLoadWeight = constraintSet.OptMaxWeight.Activated ? constraintSet.OptMaxWeight.Value : 0.0
         });
     }
     else
     {
         throw new Exception(string.Format("Unexpected analysis type : {0}", analysis.GetType()));
     }
 }
Ejemplo n.º 14
0
        private void GenerateResult(
            string name
            , double length, double width, double height
            , double?weight
            , ref int stackCount, ref double stackWeight, ref double stackEfficiency
            , ref string stackImagePath)
        {
            stackCount     = 0;
            stackWeight    = 0.0;
            stackImagePath = string.Empty;

            // generate case
            BoxProperties bProperties = new BoxProperties(null, length, width, height);

            if (weight.HasValue)
            {
                bProperties.SetWeight(weight.Value);
            }
            bProperties.SetColor(Color.Chocolate);
            bProperties.TapeWidth = new OptDouble(true, Math.Min(50.0, 0.5 * width));
            bProperties.TapeColor = Color.Beige;

            Graphics3DImage graphics = null;

            if (GenerateImage || GenerateImageInFolder)
            {
                // generate image path
                stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png"));

                if (GenerateImageInFolder)
                {
                    stackImagePath = Path.ChangeExtension(Path.Combine(Path.Combine(DirectoryPathImages, name)), "png");
                }

                graphics = new Graphics3DImage(new Size(ImageSize, ImageSize))
                {
                    FontSizeRatio  = this.FontSizeRatio,
                    CameraPosition = Graphics3D.Corner_0
                };
            }

            // compute analysis
            if (0 == Mode)
            {
                ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet();
                constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true });
                constraintSet.SetMaxHeight(new OptDouble(true, PalletMaximumHeight));

                SolverCasePallet       solver   = new SolverCasePallet(bProperties, PalletProperties, constraintSet);
                List <AnalysisLayered> analyses = solver.BuildAnalyses(false);
                if (analyses.Count > 0)
                {
                    AnalysisLayered analysis = analyses[0];
                    stackCount      = analysis.Solution.ItemCount;
                    stackWeight     = analysis.Solution.Weight;
                    stackEfficiency = analysis.Solution.VolumeEfficiency;

                    if (stackCount <= StackCountMax)
                    {
                        if (GenerateImage || GenerateImageInFolder)
                        {
                            ViewerSolution sv = new ViewerSolution(analysis.Solution as SolutionLayered);
                            sv.Draw(graphics, Transform3D.Identity);
                            graphics.Flush();
                        }
                        if (GenerateReport)
                        {
                            ReportDataAnalysis inputData      = new ReportDataAnalysis(analysis);
                            string             outputFilePath = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(OutputFilePath), string.Format("Report_{0}_on_{1}", analysis.Content.Name, analysis.Container.Name)), "doc");

                            ReportNode rnRoot   = null;
                            Margins    margins  = new Margins();
                            Reporter   reporter = new ReporterMSWord(inputData, ref rnRoot, Reporter.TemplatePath, outputFilePath, margins);
                        }
                    }
                }
            }
            else
            {
                BoxProperties container = new BoxProperties(null, TruckLength, TruckWidth, TruckHeight, TruckLength, TruckWidth, TruckHeight);
                Color         lblue     = Color.LightBlue;
                container.SetAllColors(new Color[] { lblue, lblue, lblue, lblue, lblue, lblue });
                container.SetWeight(0.0);
                ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(container);
                constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true });

                SolverBoxCase          solver   = new SolverBoxCase(bProperties, container, constraintSet);
                List <AnalysisLayered> analyses = solver.BuildAnalyses(false);
                if (analyses.Count > 0)
                {
                    AnalysisLayered analysis = analyses[0];
                    stackCount  = analysis.Solution.ItemCount;
                    stackWeight = analysis.Solution.Weight;

                    if ((GenerateImage || GenerateImageInFolder) && stackCount <= StackCountMax)
                    {
                        ViewerSolution sv = new ViewerSolution(analysis.Solution as SolutionLayered);
                        sv.Draw(graphics, Transform3D.Identity);
                        graphics.Flush();
                    }
                }
            }
            if (GenerateImage)
            {
                Bitmap bmp = graphics.Bitmap;
                bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
Ejemplo n.º 15
0
        public static bool GetBestSolution(PackableBrick packableProperties, BoxProperties caseProperties, InterlayerProperties interlayer
                                           , ConstraintSetBoxCase constraintSet, bool allowMultipleLayerOrientations
                                           , Vector3D cameraPosition, bool showCotations, float fontSizeRatio, Size sz
                                           , ref int layerCount, ref int caseCount, ref int interlayerCount
                                           , ref double weightTotal, ref double weightLoad, ref double?weightNet
                                           , ref Vector3D bbLoad, ref Vector3D bbGlob
                                           , ref double volumeEfficency, ref double?weightEfficiency
                                           , ref byte[] imageBytes
                                           , ref string[] errors
                                           )
        {
            List <string> lErrors = new List <string>();

            if (!packableProperties.FitsIn(caseProperties, constraintSet))
            {
                lErrors.Add($"{packableProperties.Name} does not fit in {caseProperties.Name} with given constraint set!");
                return(false);
            }
            try
            {
                SolverBoxCase          solver   = new SolverBoxCase(packableProperties, caseProperties, constraintSet);
                List <AnalysisLayered> analyses = solver.BuildAnalyses(allowMultipleLayerOrientations);
                if (analyses.Count > 0)
                {
                    AnalysisLayered analysis = analyses[0];
                    layerCount      = analysis.SolutionLay.LayerCount;
                    caseCount       = analysis.Solution.ItemCount;
                    interlayerCount = analysis.SolutionLay.LayerCount;

                    weightLoad  = analysis.Solution.LoadWeight;
                    weightTotal = analysis.Solution.Weight;

                    OptDouble optNetWeight = analysis.Solution.NetWeight;
                    weightNet        = optNetWeight.Activated ? optNetWeight.Value : (double?)null;
                    bbGlob           = analysis.Solution.BBoxGlobal.DimensionsVec;
                    bbLoad           = analysis.Solution.BBoxLoad.DimensionsVec;
                    volumeEfficency  = analysis.Solution.VolumeEfficiency;
                    weightEfficiency = null;
                    if (analysis.Solution.WeightEfficiency.Activated)
                    {
                        weightEfficiency = analysis.Solution.WeightEfficiency.Value;
                    }

                    // generate image path
                    Graphics3DImage graphics = new Graphics3DImage(sz)
                    {
                        FontSizeRatio  = fontSizeRatio,
                        CameraPosition = cameraPosition,
                        ShowDimensions = showCotations
                    };
                    using (ViewerSolution sv = new ViewerSolution(analysis.SolutionLay))
                        sv.Draw(graphics, Transform3D.Identity);
                    graphics.Flush();
                    Bitmap         bmp       = graphics.Bitmap;
                    ImageConverter converter = new ImageConverter();
                    imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[]));
                }
                else
                {
                    lErrors.Add("No solution found!");
                }
            }
            catch (Exception ex)
            {
                lErrors.Add(ex.Message);
            }
            errors = lErrors.ToArray();
            return(0 == lErrors.Count);
        }
Ejemplo n.º 16
0
        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());
        }
Ejemplo n.º 17
0
        private placement[] BuildPlacementArray(SolutionLayered sol, AnalysisLayered analysis)
        {
            List <placement> lPlacements = new List <placement>();
            List <ILayer>    layers      = sol.Layers;

            foreach (ILayer layer in layers)
            {
                if (layer is Layer3DBox layerBox)
                {
                    layerBox.Sort(analysis.Content, Layer3DBox.SortType.DIST_MAXCORNER);
                    foreach (BoxPosition bPosition in layerBox)
                    {
                        Vector3D writtenPosition = ConvertPosition(bPosition, analysis.ContentDimensions);
                        lPlacements.Add(
                            new placement()
                        {
                            itemId     = 1,
                            x          = writtenPosition.X,
                            y          = writtenPosition.Y,
                            z          = writtenPosition.Z,
                            LSpecified = true,
                            L          = ToAxis(bPosition.DirectionLength),
                            WSpecified = true,
                            W          = ToAxis(bPosition.DirectionWidth)
                        }
                            );
                    }
                }
                else if (layer is Layer3DCyl layerCyl)
                {
                    layerCyl.Sort(analysis.Content, Layer3DCyl.SortType.DIST_CENTER);
                    foreach (Vector3D vPos in layerCyl)
                    {
                        lPlacements.Add(
                            new placement()
                        {
                            itemId     = 1,
                            x          = vPos.X,
                            y          = vPos.Y,
                            z          = vPos.Z,
                            LSpecified = false,
                            WSpecified = false
                        }
                            );
                    }
                }
                else if (layer is InterlayerPos interlayerPos)
                {
                    var 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);
                    Vector3D writtenPosition = ConvertPosition(bPosition, interlayerProp.Dimensions);
                    lPlacements.Add(
                        new placement()
                    {
                        itemId = interlayerPos.TypeId + OffsetIndexInterlayers,
                        x      = writtenPosition.X,
                        y      = writtenPosition.Y,
                        z      = writtenPosition.Z
                    }
                        );
                }
            }
            return(lPlacements.ToArray());
        }
Ejemplo n.º 18
0
 public DockContentAnalysisBoxCase(IDocument document, AnalysisLayered analysis)
     : base(document, analysis)
 {
     InitializeComponent();
 }
Ejemplo n.º 19
0
        public override void Export(AnalysisLayered analysis, ref Stream stream)
        {
            if (analysis.SolutionLay.ItemCount > MaximumNumberOfCases)
            {
                throw new ExceptionTooManyItems(Name, analysis.Solution.ItemCount, MaximumNumberOfCases);
            }

            // number formatting
            NumberFormatInfo nfi = new NumberFormatInfo
            {
                NumberDecimalSeparator = ".",
                NumberGroupSeparator   = "",
                NumberDecimalDigits    = 1
            };

            // initialize csv file
            var csv = new StringBuilder();

            csv.AppendLine("Parameter; Field; DataType; Value");
            csv.AppendLine("Program:StackBuilder;$Type; STRING; PvParameter");

            // ### CASES ###
            // case counter
            uint iCaseCount = 0;
            var  sol        = analysis.SolutionLay;
            var  layers     = sol.Layers;

            foreach (var layer in layers)
            {
                if (layer is Layer3DBox layerBox)
                {
                    layerBox.Sort(analysis.Content, Layer3DBox.SortType.DIST_MAXCORNER);
                    foreach (var bPosition in layerBox)
                    {
                        var pos   = ConvertPosition(bPosition, analysis.ContentDimensions);
                        int angle = 0;
                        switch (bPosition.DirectionLength)
                        {
                        case HalfAxis.HAxis.AXIS_X_P: angle = 0; break;

                        case HalfAxis.HAxis.AXIS_Y_P: angle = 90; break;

                        case HalfAxis.HAxis.AXIS_X_N: angle = 180; break;

                        case HalfAxis.HAxis.AXIS_Y_N: angle = 270; break;

                        default: break;
                        }
                        if (iCaseCount < MaximumNumberOfCases)
                        {
                            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Box[{iCaseCount}].C;INT;{angle}");
                            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Box[{iCaseCount}].X;REAL;{pos.X.ToString("0,0.0", nfi)}");
                            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Box[{iCaseCount}].Y;REAL;{pos.Y.ToString("0,0.0", nfi)}");
                            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Box[{iCaseCount++}].Z;REAL;{pos.Z.ToString("0,0.0", nfi)}");
                        }
                    }
                }
            }
            // up to MaximumNumberOfCases
            while (iCaseCount < MaximumNumberOfCases)
            {
                csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Box[{iCaseCount}].C;INT;0");
                csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Box[{iCaseCount}].X;REAL;0");
                csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Box[{iCaseCount}].Y;REAL;0");
                csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Box[{iCaseCount++}].Z;REAL;0");
            }
            // ### INTERLAYERS ###
            int iLayerCount = 0;

            foreach (var solItem in sol.SolutionItems)
            {
                if (iLayerCount < MaximumNumberOfInterlayers)
                {
                    csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.InterlayerOnOff[{iLayerCount++}];BOOL;{Bool2string(solItem.HasInterlayer)}");
                }
            }
            // pallet cap
            var hasPalletCap = false;

            if (analysis is AnalysisCasePallet analysisCasePallet)
            {
                hasPalletCap = analysisCasePallet.HasPalletCap;
            }
            if (iLayerCount < MaximumNumberOfInterlayers)
            {
                csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.InterlayerOnOff[{iLayerCount++}];BOOL;{Bool2string(hasPalletCap)}");
            }
            // up to MaximumNumberOfInterlayers
            while (iLayerCount < MaximumNumberOfInterlayers)
            {
                csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.InterlayerOnOff[{iLayerCount++}];BOOL;{Bool2string(false)}");
            }


            // ### BOX OUTER DIMENSIONS
            var    dimensions = analysis.Content.OuterDimensions;
            double weight     = analysis.Content.Weight;

            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.BoxDimension.L;REAL;{dimensions.X.ToString("0,0.0", nfi)}");
            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.BoxDimension.P;REAL;{dimensions.Y.ToString("0,0.0", nfi)}");
            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.BoxDimension.H;REAL;{dimensions.Z.ToString("0,0.0", nfi)}");
            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.BoxDimension.W;REAL;{weight.ToString("0,0.0", nfi)}");
            if (analysis.Container is PalletProperties palletProperties)
            {
                csv.AppendLine(
                    $"Program:StackBuilder;Program:StackBuilder.PalletDimension.L;REAL;{palletProperties.Length.ToString("0,0.0", nfi)}");
                csv.AppendLine(
                    $"Program:StackBuilder;Program:StackBuilder.PalletDimension.P;REAL;{palletProperties.Width.ToString("0,0.0", nfi)}");
                csv.AppendLine(
                    $"Program:StackBuilder;Program:StackBuilder.PalletDimension.H;REAL;{palletProperties.Height.ToString("0,0.0", nfi)}");
                csv.AppendLine(
                    $"Program:StackBuilder;Program:StackBuilder.PalletDimension.W;REAL;{palletProperties.Weight.ToString("0,0.0", nfi)}");
            }

            double maxPalletHeight = analysis.ConstraintSet.OptMaxHeight.Value;

            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.Pallet.MaxPalletHeight;REAL;{maxPalletHeight.ToString("0,0.0", nfi)}");
            bool layersMirrorX = false;

            if (sol.ItemCount > 1)
            {
                layersMirrorX = sol.SolutionItems[0].SymetryX != sol.SolutionItems[1].SymetryX;
            }
            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.LayersMirrorXOnOff;BOOL;{Bool2string(layersMirrorX)}");
            bool layersMirrorY = false;

            if (sol.ItemCount > 1)
            {
                layersMirrorY = sol.SolutionItems[0].SymetryY != sol.SolutionItems[1].SymetryY;
            }
            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.LayersMirrorYOnOff;BOOL;{Bool2string(layersMirrorY)}");
            csv.AppendLine($"Program:StackBuilder;Program:StackBuilder.TotalWeight;REAL;{sol.Weight.ToString("0,0.0", nfi)}");

            var writer = new StreamWriter(stream);

            writer.Write(csv.ToString());
            writer.Flush();
            stream.Position = 0;
        }
        private void FillGrid()
        {
            try
            {
                // remove all existing rows
                gridSolutions.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", GridFontSize, FontStyle.Bold);
                captionHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
                // viewRowHeader
                SourceGrid.Cells.Views.ColumnHeader        viewColumnHeader = new SourceGrid.Cells.Views.ColumnHeader();
                DevAge.Drawing.VisualElements.ColumnHeader backHeader       = new DevAge.Drawing.VisualElements.ColumnHeader();
                backHeader.BackColor                   = Color.LightGray;
                backHeader.Border                      = DevAge.Drawing.RectangleBorder.NoBorder;
                viewColumnHeader.Background            = backHeader;
                viewColumnHeader.ForeColor             = Color.Black;
                viewColumnHeader.Font                  = new Font("Arial", GridFontSize, FontStyle.Regular);
                viewColumnHeader.ElementSort.SortStyle = DevAge.Drawing.HeaderSortStyle.None;
                // viewNormal
                CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White);
                // ***
                // set first row
                gridSolutions.BorderStyle  = BorderStyle.FixedSingle;
                gridSolutions.ColumnsCount = 7;
                gridSolutions.FixedRows    = 1;
                gridSolutions.Rows.Insert(0);
                // header
                int iCol = 0;
                SourceGrid.Cells.ColumnHeader columnHeader;
                // A1xA2xA3
                columnHeader = new SourceGrid.Cells.ColumnHeader("A1 x A2 x A3")
                {
                    AutomaticSortEnabled = false,
                    View = viewColumnHeader
                };
                gridSolutions[0, iCol++] = columnHeader;
                // dimensions
                columnHeader = new SourceGrid.Cells.ColumnHeader(
                    string.Format(Resources.ID_DIMENSIONS, UnitsManager.LengthUnitString))
                {
                    AutomaticSortEnabled = false,
                    View = viewColumnHeader
                };
                gridSolutions[0, iCol++] = columnHeader;
                // weight
                columnHeader = new SourceGrid.Cells.ColumnHeader(string.Format(Resources.ID_WEIGHT_WU, UnitsManager.MassUnitString))
                {
                    AutomaticSortEnabled = false,
                    View = viewColumnHeader
                };
                gridSolutions[0, iCol++] = columnHeader;
                // #packs
                columnHeader = new SourceGrid.Cells.ColumnHeader("#")
                {
                    AutomaticSortEnabled = false,
                    View = viewColumnHeader
                };
                gridSolutions[0, iCol++] = columnHeader;
                // weight
                columnHeader = new SourceGrid.Cells.ColumnHeader(string.Format(Resources.ID_PALLETWEIGHT, UnitsManager.MassUnitString))
                {
                    AutomaticSortEnabled = false,
                    View = viewColumnHeader
                };
                gridSolutions[0, iCol++] = columnHeader;
                // efficiency
                columnHeader = new SourceGrid.Cells.ColumnHeader(Resources.ID_EFFICIENCYPERCENTAGE)
                {
                    AutomaticSortEnabled = false,
                    View = viewColumnHeader
                };
                gridSolutions[0, iCol++] = columnHeader;
                // maximum space
                columnHeader = new SourceGrid.Cells.ColumnHeader(string.Format(Resources.ID_MAXIMUMSPACE, UnitsManager.LengthUnitString))
                {
                    AutomaticSortEnabled = false,
                    View = viewColumnHeader
                };
                gridSolutions[0, iCol++] = columnHeader;

                int iRow = 0;
                foreach (AnalysisLayered analysis in _analyses)
                {
                    AnalysisCasePallet analysisCasePallet = analysis as AnalysisCasePallet;
                    PackProperties     pack = analysisCasePallet.Content as PackProperties;
                    int layerCount          = analysisCasePallet.SolutionLay.Layers.Count;
                    if (layerCount < 1)
                    {
                        continue;
                    }
                    int    packPerLayerCount = analysisCasePallet.SolutionLay.Layers[0].BoxCount;
                    int    itemCount         = analysisCasePallet.Solution.ItemCount;
                    double palletWeight      = analysisCasePallet.Solution.Weight;
                    double volumeEfficiency  = analysisCasePallet.Solution.VolumeEfficiency;
                    double maximumSpace      = analysisCasePallet.SolutionLay.LayerCount > 0 ? analysisCasePallet.SolutionLay.LayerMaximumSpace(0) : 0;

                    gridSolutions.Rows.Insert(++iRow);
                    iCol = 0;
                    gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell($"{pack.Arrangement.Length} x {pack.Arrangement.Width} x {pack.Arrangement.Height}");
                    gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell($"{pack.OuterDimensions.X:0.#} x {pack.OuterDimensions.Y:0.#} x {pack.OuterDimensions.Z:0.#}");
                    gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell($"{pack.Weight:0.###}");
                    gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell($"{itemCount} = {packPerLayerCount} x {layerCount}");
                    gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell($"{palletWeight:0.###}");
                    gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell($"{volumeEfficiency:0.#}");
                    gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell($"{maximumSpace:0.#}");
                }

                gridSolutions.AutoStretchColumnsToFitWidth = true;
                gridSolutions.AutoSizeCells();
                gridSolutions.Columns.StretchToFit();

                // select first solution
                if (gridSolutions.RowsCount > 1)
                {
                    gridSolutions.Selection.SelectRow(1, true);
                }
                else
                {
                    // grid empty -> clear drawing
                    _selectedAnalysis = null;
                    graphCtrlPack.Invalidate();
                    graphCtrlSolution.Invalidate();
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
        }
Ejemplo n.º 21
0
        public void Export(AnalysisLayered analysis, string filePath)
        {
            // solution
            var sol = analysis.SolutionLay;
            // scene
            var scene = new SceneBuilder();

            if (analysis.Content is BoxProperties boxProperties)
            {
                var colors     = boxProperties.Colors;
                var colorFilet = boxProperties.Colors[0];
                var 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

                var layers = sol.Layers;
                foreach (ILayer layer in layers)
                {
                    if (layer is Layer3DBox layerBox)
                    {
                        foreach (var bPosition in layerBox)
                        {
                            scene.AddRigidMesh(meshCase, BoxPositionToMatrix4x4(bPosition));
                        }
                    }
                    else if (layer is Layer3DBoxIndexed layerBoxi)
                    {
                        foreach (var bposi in layerBoxi)
                        {
                            scene.AddRigidMesh(meshCase, BoxPositionToMatrix4x4(bposi.BPos));
                        }
                    }
                    else if (layer is InterlayerPos interlayerPos)
                    {
                        var 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)
            {
                var capProperties = analysisCasePallet.PalletCapProperties;
                var 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);
        }
Ejemplo n.º 22
0
 public override void Export(AnalysisLayered analysis, ref Stream stream)
 {
 }
Ejemplo n.º 23
0
 public override void Export(AnalysisLayered analysis, ref Stream stream)
 {
     /*
      * PalletProperties palletProperties = _palletSolution.Analysis.PalletProperties;
      *
      * COLLADA model = new COLLADA
      * {
      *  // asset
      *  asset = new asset()
      *  {
      *      created = DateTime.Now,
      *      modified = DateTime.Now
      *  }
      * };
      * model.asset.keywords = "StackBuilder Pallet Case";
      * model.asset.title = _palletSolution.Title;
      * model.asset.unit = new assetUnit() { name = "millimeters", meter = 0.001 };
      * model.asset.up_axis = UpAxisType.Z_UP;
      *
      * library_images images = new library_images();
      * library_materials materials = new library_materials();
      * library_effects effects = new library_effects();
      * library_geometries geometries = new library_geometries();
      * library_nodes nodes = new library_nodes();
      * library_cameras cameras = new library_cameras();
      * library_animations animations = new library_animations();
      * library_visual_scenes scenes = new library_visual_scenes();
      *
      * COLLADAScene colladaScene = new COLLADAScene();
      *
      * model.Items = new Object[] { images, materials, effects, geometries, nodes, cameras, animations, scenes };
      * model.scene = colladaScene;
      *
      * // colors and materials
      * List<effect> listEffects = new List<effect>();
      * List<material> listMaterials = new List<material>();
      * List<image> listImages = new List<image>();
      *
      * // effects
      * material materialPallet;
      * CreateMaterial(palletProperties.Color, null, null, "Pallet", out effect effectPallet, out materialPallet);
      * listEffects.Add(effectPallet);
      * listMaterials.Add(materialPallet);
      *
      * Box box = new Box(0, _palletSolution.Analysis.BProperties);
      *
      * // build list of effects / materials / images
      * uint faceIndex = 0;
      * foreach (Face face in box.Faces)
      * {
      *  // build texture image if any
      *  string textureName = null;
      *  if (face.HasBitmap)
      *  {
      *      textureName = string.Format("textureFace_{0}", faceIndex);
      *      string texturePath = Path.Combine(Path.GetDirectoryName(filePath), textureName + ".jpg");
      *
      *      double dimX = 0.0, dimY = 0.0;
      *
      *      switch (faceIndex)
      *      {
      *          case 0: dimX = box.Width; dimY = box.Height; break;
      *          case 1: dimX = box.Width; dimY = box.Height; break;
      *          case 2: dimX = box.Length; dimY = box.Height; break;
      *          case 3: dimX = box.Length; dimY = box.Height; break;
      *          case 4: dimX = box.Length; dimY = box.Width; break;
      *          case 5: dimX = box.Length; dimY = box.Width; break;
      *          default: break;
      *      }
      *      face.ExtractFaceBitmap(dimX, dimY, _bmpWidth, texturePath);
      *      // create image
      *      listImages.Add(
      *          new image()
      *          {
      *              id = textureName + ".jpg",
      *              name = textureName + ".jpg",
      *              Item = @".\" + textureName + @".jpg"
      *          }
      *      );
      *  }
      *  material materialCase;
      *  effect effectCase;
      *  CreateMaterial(face.ColorFill, textureName, "0", string.Format("Case{0}", faceIndex), out effectCase, out materialCase);
      *  listEffects.Add(effectCase);
      *  listMaterials.Add(materialCase);
      *
      ++faceIndex;
      * }
      *
      * // add to image list
      * images.image = listImages.ToArray();
      *
      * // case lines material
      * effect effectCaseLines;
      * material materialCaseLines;
      * CreateMaterial(Color.Black, null, null, "CaseLines", out effectCaseLines, out materialCaseLines);
      * listEffects.Add(effectCaseLines);
      * listMaterials.Add(materialCaseLines);
      * effects.effect = listEffects.ToArray();
      * materials.material = listMaterials.ToArray();
      *
      * // geometries
      * geometry geomPallet = new geometry() { id = "palletGeometry", name = "palletGeometry" };
      * geometry geomCase = new geometry() { id = "caseGeometry", name = "caseGeometry" };
      * geometries.geometry = new geometry[] { geomPallet, geomCase };
      * // pallet
      * mesh meshPallet = CreatePalletMesh(palletProperties);
      * geomPallet.Item = meshPallet;
      * // case
      * mesh meshCase = CreateCaseMesh(_palletSolution.Analysis.BProperties as BoxProperties);
      * geomCase.Item = meshCase;
      * // library_animations
      * animation animationMain = new animation() { id = "animationMain_ID", name = "animationMain" };
      * animations.animation = new animation[] { animationMain };
      *
      * List<object> listAnimationSource = new List<object>();
      *
      * // library_visual_scenes
      * visual_scene mainScene = new visual_scene() { id = "MainScene", name = "MainScene" };
      * scenes.visual_scene = new visual_scene[] { mainScene };
      *
      * List<node> sceneNodes = new List<node>();
      * sceneNodes.Add(new node()
      * {
      *  id = "PalletNode",
      *  name = "PalletNode",
      *  instance_geometry = new instance_geometry[]
      *  {
      *      new instance_geometry()
      *      {
      *          url = "#palletGeometry",
      *          bind_material = new bind_material()
      *          {
      *              technique_common = new instance_material[]
      *              {
      *                  new instance_material()
      *                  {
      *                      symbol="materialPallet",
      *                      target=string.Format("#{0}", materialPallet.id)
      *                  }
      *              }
      *          }
      *      }
      *  }
      * });
      * uint caseIndex = 0;
      * foreach (ILayer layer in _palletSolution)
      * {
      *  Layer3DBox bLayer = layer as Layer3DBox;
      *  if (null == bLayer) continue;
      *
      *  foreach (BoxPosition bp in bLayer)
      *  {
      *      Vector3D translation = bp.Position;
      *      Vector3D rotations = bp.Transformation.Rotations;
      *
      *      node caseNode = new node()
      *      {
      *          id = string.Format("CaseNode_{0}_ID", caseIndex),
      *          name = string.Format("CaseNode_{0}", caseIndex),
      *          ItemsElementName = new ItemsChoiceType2[]
      *          {
      *              ItemsChoiceType2.translate,
      *              ItemsChoiceType2.rotate,
      *              ItemsChoiceType2.rotate,
      *              ItemsChoiceType2.rotate
      *          },
      *          Items = new object[]
      *          {
      *              new TargetableFloat3()
      *              {
      *                  Values = new double[] { translation.X, translation.Y, translation.Z },
      *                  sid = "t",
      *              },
      *              new rotate()
      *              {
      *                  Values = new double[] { 1.0, 0.0, 0.0, rotations.X },
      *                  sid = "rx"
      *              },
      *              new rotate()
      *              {
      *                  Values = new double[] { 0.0, 1.0, 0.0, rotations.Y },
      *                  sid = "ry"
      *              },
      *              new rotate()
      *              {
      *                  Values = new double[] { 0.0, 0.0, 1.0, rotations.Z },
      *                  sid = "rz"
      *              }
      *          },
      *
      *          instance_geometry = new instance_geometry[]
      *          {
      *              new instance_geometry()
      *              {
      *                  url="#caseGeometry",
      *                  bind_material = new bind_material()
      *                  {
      *                      technique_common = new instance_material[]
      *                      {
      *                          new instance_material() { symbol="materialCase0", target="#material_Case0_ID" },
      *                          new instance_material() { symbol="materialCase1", target="#material_Case1_ID" },
      *                          new instance_material() { symbol="materialCase2", target="#material_Case2_ID" },
      *                          new instance_material() { symbol="materialCase3", target="#material_Case3_ID" },
      *                          new instance_material() { symbol="materialCase4", target="#material_Case4_ID" },
      *                          new instance_material() { symbol="materialCase5", target="#material_Case5_ID" },
      *                          new instance_material() { symbol="materialCaseLines", target="#material_CaseLines_ID"}
      *                      }
      *                  }
      *              }
      *          }
      *      };
      *      sceneNodes.Add(caseNode);
      *
      *      // animations
      *      CreateAnimation(caseIndex, (uint)_palletSolution.CaseCount, listAnimationSource, bp);
      *
      *      // increment case index
      ++caseIndex;
      *  }
      * }
      *
      * // add nodes
      * mainScene.node = sceneNodes.ToArray();
      *
      * animationMain.Items = listAnimationSource.ToArray();
      *
      * // library_cameras
      * camera cameraCamera = new camera() { id = "Camera-Camera", name = "Camera-Camera" };
      * cameraOpticsTechnique_commonPerspective cameraPerspective = new cameraOpticsTechnique_commonPerspective()
      * {
      *  znear = new TargetableFloat() { sid = "znear", Value = 1.0 },
      *  zfar = new TargetableFloat() { sid = "zfar", Value = 10000.0 }
      * };
      * cameraCamera.optics = new cameraOptics() { technique_common = new cameraOpticsTechnique_common() { Item = cameraPerspective } };
      * cameras.camera = new camera[] { cameraCamera };
      *
      * // colladaScene
      * colladaScene.instance_visual_scene = new InstanceWithExtra() { url = "#MainScene" };
      *
      * model.Save(filePath);
      * model.Save(System.IO.Path.ChangeExtension(filePath, "xml"));
      */
 }
Ejemplo n.º 24
0
        public void Compute()
        {
            Excel.Worksheet xlSheet = Globals.StackBuilderAddIn.Application.ActiveSheet as Excel.Worksheet;
            if (null != xlSheet)
            {
                Console.WriteLine(string.Format("Sheet name = {0}", xlSheet.Name));

                double caseLength = ReadDouble(xlSheet, Settings.Default.CellCaseLength, Resources.ID_CASE_LENGTH);
                double caseWidth  = ReadDouble(xlSheet, Settings.Default.CellCaseWidth, Resources.ID_CASE_WIDTH);
                double caseHeight = ReadDouble(xlSheet, Settings.Default.CellCaseHeight, Resources.ID_CASE_HEIGHT);
                double caseWeight = ReadDouble(xlSheet, Settings.Default.CellCaseWeight, Resources.ID_CASE_WEIGHT);

                double palletLength = ReadDouble(xlSheet, Settings.Default.CellPalletLength, Resources.ID_PALLET_LENGTH);
                double palletWidth  = ReadDouble(xlSheet, Settings.Default.CellPalletWidth, Resources.ID_PALLET_WIDTH);
                double palletHeight = ReadDouble(xlSheet, Settings.Default.CellPalletHeight, Resources.ID_PALLET_HEIGHT);
                double palletWeight = ReadDouble(xlSheet, Settings.Default.CellPalletWeight, Resources.ID_PALLET_WEIGHT);

                double palletMaximumHeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletHeight, Resources.ID_CONSTRAINTS_PALLETMAXIHEIGHT);
                double palletMaximumWeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletWeight, Resources.ID_CONSTRAINTS_PALLETMAXIWEIGHT);

                double imageLeft = UnitsManager.ConvertLengthTo(Settings.Default.ImageLeft, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035;
                double imageTop  = UnitsManager.ConvertLengthTo(Settings.Default.ImageTop, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035;

                // delete any existing image with same position
                foreach (Excel.Shape s in xlSheet.Shapes)
                {
                    if (Math.Abs(s.Left - imageLeft) < 0.001 &&
                        Math.Abs(s.Top - imageTop) < 0.001)
                    {
                        s.Delete();
                    }
                }
                // initialize units
                UnitsManager.CurrentUnitSystem = (UnitsManager.UnitSystem)Properties.Settings.Default.UnitSystem;

                // ###
                // build a case
                BoxProperties bProperties = new BoxProperties(null, caseLength, caseWidth, caseHeight);
                bProperties.SetWeight(caseWeight);
                bProperties.SetColor(Color.Chocolate);
                bProperties.TapeWidth = new OptDouble(true, 5);
                bProperties.TapeColor = Color.Beige;

                // build a pallet
                PalletProperties palletProperties = new PalletProperties(null, PalletTypeName, palletLength, palletWidth, palletHeight);
                palletProperties.Weight = palletWeight;
                palletProperties.Color  = Color.Yellow;

                // build a constraint set
                ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet();
                constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
                constraintSet.SetMaxHeight(new OptDouble(true, palletMaximumHeight));
                constraintSet.OptMaxWeight = new OptDouble(true, palletMaximumWeight);

                // use a solver and get a list of sorted analyses + select the best one
                SolverCasePallet       solver   = new SolverCasePallet(bProperties, palletProperties, constraintSet);
                List <AnalysisLayered> analyses = solver.BuildAnalyses(true);
                if (analyses.Count > 0)
                {
                    AnalysisLayered analysis    = analyses[0];
                    int             caseCount   = analysis.Solution.ItemCount; // <- your case count
                    double          loadWeight  = analysis.Solution.LoadWeight;
                    double          totalWeight = analysis.Solution.Weight;    // <- your pallet weight

                    // generate image
                    Graphics3DImage graphics = null;
                    // generate image path
                    string stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png"));
                    graphics = new Graphics3DImage(new Size(Settings.Default.ImageSize, Settings.Default.ImageSize))
                    {
                        FontSizeRatio  = Settings.Default.FontSizeRatio,
                        CameraPosition = Graphics3D.Corner_0
                    };
                    ViewerSolution sv = new ViewerSolution(analysis.SolutionLay);
                    sv.Draw(graphics, Transform3D.Identity);
                    graphics.Flush();
                    Bitmap bmp = graphics.Bitmap;
                    bmp.Save(stackImagePath);

                    // write values
                    WriteInt(xlSheet, Settings.Default.CellNoCases, Resources.ID_RESULT_NOCASES, caseCount);
                    WriteDouble(xlSheet, Settings.Default.CellLoadWeight, Resources.ID_RESULT_LOADWEIGHT, loadWeight);
                    WriteDouble(xlSheet, Settings.Default.CellTotalPalletWeight, Resources.ID_RESULT_TOTALPALLETWEIGHT, totalWeight);

                    // write picture
                    string filePath = string.Empty;
                    Globals.StackBuilderAddIn.Application.ActiveSheet.Shapes.AddPicture(
                        stackImagePath,
                        Microsoft.Office.Core.MsoTriState.msoFalse,
                        Microsoft.Office.Core.MsoTriState.msoCTrue,
                        imageLeft,
                        imageTop,
                        UnitsManager.ConvertLengthTo(Settings.Default.ImageWidth, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035,
                        UnitsManager.ConvertLengthTo(Settings.Default.ImageHeight, UnitsManager.UnitSystem.UNIT_METRIC2) / 0.035);
                }
                else
                {
                    MessageBox.Show(Resources.ID_RESULT_NOSOLUTIONFOUND,
                                    AppDomain.CurrentDomain.FriendlyName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
                // ###
            }
        }
Ejemplo n.º 25
0
 public abstract void Export(AnalysisLayered analysis, ref Stream stream);
Ejemplo n.º 26
0
        public bool OnFileNew(ref string fileName)
        {
            // INTEX data are in cms
            UnitsManager.CurrentUnitSystem = UnitsManager.UnitSystem.UNIT_METRIC2;

            string dbPath = Properties.Settings.Default.DatabasePathINTEX;

            if (string.IsNullOrWhiteSpace(dbPath) || !File.Exists(dbPath))
            {
                OpenFileDialog fd = new OpenFileDialog();
                fd.DefaultExt       = "xls";
                fd.AddExtension     = false;
                fd.Filter           = "Microsoft Excel File (*.xls)|*.xls|All files (*.*)|*.*";
                fd.FilterIndex      = 0;
                fd.RestoreDirectory = true;
                fd.CheckFileExists  = true;
                if (DialogResult.OK != fd.ShowDialog())
                {
                    return(false);
                }

                dbPath = fd.FileName;
                Properties.Settings.Default.DatabasePathINTEX = dbPath;
                Properties.Settings.Default.Save();
            }
            // load INTEX excel file
            List <DataItemINTEX>   listItems   = null;
            List <DataPalletINTEX> listPallets = null;
            List <DataCaseINTEX>   listCases   = null;

            try
            {
                // Set cursor as hourglass
                Cursor.Current = Cursors.WaitCursor;
                // load excel file
                if (!ExcelDataReader.ExcelDataReader.LoadIntexFile(dbPath, ref listItems, ref listPallets, ref listCases))
                {
                    Cursor.Current = Cursors.Default;
                    string message = string.Empty;
                    if (null == listItems || listItems.Count < 1)
                    {
                        message = string.Format(Properties.Resources.ID_ERROR_NOITEMFOUND, "article", "Articles");
                    }
                    else if (null == listPallets || listPallets.Count < 1)
                    {
                        message = string.Format(Properties.Resources.ID_ERROR_NOITEMFOUND, "palette", "Palettes");
                    }
                    else
                    {
                        message = string.Format(Properties.Resources.ID_ERROR_INVALIDFILE, dbPath);
                    }
                    if (!string.IsNullOrEmpty(message))
                    {
                        MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message
                    , Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                _log.Error(ex.Message);
            }
            finally
            { Cursor.Current = Cursors.Default; }
            // do we have a valid list
            if (null == listItems || 0 == listItems.Count)
            {
                return(false);
            }
            // proceed : buid project file
            try
            {
                FormNewINTEX form = new FormNewINTEX()
                {
                    ListItems   = listItems,
                    ListPallets = listPallets,
                    ListCases   = listCases
                };
                if (DialogResult.OK != form.ShowDialog())
                {
                    return(false);
                }
                // create document
                DataItemINTEX item     = form._currentItem;
                Document      document = new Document(item._ref, item._description, "INTEX", DateTime.Now, null);
                // create box properties
                Color[] colorsCase = new Color[6];
                for (int i = 0; i < 6; ++i)
                {
                    colorsCase[i] = Color.Chocolate;
                }
                BoxProperties itemProperties = null;
                if (!form.UseIntermediatePacking)
                {
                    itemProperties = document.CreateNewCase(
                        item._ref
                        , $"{item._description};EAN14 : {item._gencode};UPC : {item._UPC};PCB : {item._PCB}"
                        , UnitsManager.ConvertLengthFrom(item._length, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._width, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._height, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertMassFrom(item._weight, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , colorsCase);
                }
                else
                {
                    itemProperties = document.CreateNewBox(
                        item._ref
                        , string.Format("{0};EAN14 : {1};UPC : {2};PCB : {3}", item._description, item._gencode, item._UPC, item._PCB)
                        , UnitsManager.ConvertLengthFrom(item._length, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._width, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._height, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertMassFrom(item._weight, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , colorsCase);
                }
                itemProperties.TapeColor = Color.Beige;
                itemProperties.TapeWidth = new OptDouble(true, 5.0);
                InsertPictogram(ref itemProperties);

                BoxProperties currentCase = null;
                if (form.UseIntermediatePacking)
                {
                    // create cases
                    foreach (DataCaseINTEX dataCase in listCases)
                    {
                        double lengthInt = dataCase._lengthInt > 0 ? dataCase._lengthInt : dataCase._lengthExt - 2 * form.DefaultCaseThickness;
                        double widthInt  = dataCase._widthInt > 0 ? dataCase._widthInt : dataCase._widthExt - 2 * form.DefaultCaseThickness;
                        double heightInt = dataCase._heightInt > 0 ? dataCase._heightInt : dataCase._heightExt - 2 * form.DefaultCaseThickness;

                        BoxProperties intercaseProperties = document.CreateNewCase(
                            dataCase._ref
                            , string.Format("{0:0.0}*{1:0.0}*{2:0.0}", dataCase._lengthExt, dataCase._widthExt, dataCase._heightExt)
                            , UnitsManager.ConvertLengthFrom(dataCase._lengthExt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(dataCase._widthExt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(dataCase._heightExt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(lengthInt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(widthInt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertLengthFrom(heightInt, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , UnitsManager.ConvertMassFrom(dataCase._weight, UnitsManager.UnitSystem.UNIT_METRIC2)
                            , colorsCase);
                        intercaseProperties.TapeColor = Color.Beige;
                        intercaseProperties.TapeWidth = new OptDouble(true, 5.0);

                        if (string.Equals(form._currentCase._ref, intercaseProperties.Name))
                        {
                            currentCase = intercaseProperties;
                        }
                    }
                }

                // initialize Layer solver
                SolutionLayered.SetSolver(new LayerSolver());

                if (form.UseIntermediatePacking)
                {
                    // Case constraint set
                    ConstraintSetBoxCase constraintSetBoxCase = new ConstraintSetBoxCase(currentCase);
                    constraintSetBoxCase.AllowedOrientationsString = "1,1,1";
                    if (constraintSetBoxCase.Valid)
                    {
                        SolverBoxCase    solver     = new SolverBoxCase(itemProperties, currentCase);
                        Layer2DBrickImp  layer      = solver.BuildBestLayer(constraintSetBoxCase);
                        List <LayerDesc> layerDescs = new List <LayerDesc>();
                        if (null != layer)
                        {
                            layerDescs.Add(layer.LayerDescriptor);
                        }

                        // create case analysis
                        AnalysisLayered analysis = document.CreateNewAnalysisBoxCase(
                            string.Format(Properties.Resources.ID_PACKING, item._ref)
                            , item._description
                            , itemProperties
                            , currentCase
                            , null
                            , constraintSetBoxCase
                            , layerDescs);
                    }
                }

                // create pallets
                PalletProperties currentPallet = null;
                foreach (DataPalletINTEX pallet in listPallets)
                {
                    PalletProperties palletProperties = document.CreateNewPallet(
                        pallet._type, pallet._type, "EUR"
                        , UnitsManager.ConvertLengthFrom(pallet._length, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(pallet._width, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(pallet._height, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertMassFrom(pallet._weight, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , Color.Gold);
                    if (string.Equals(form._currentPallet._type, pallet._type))
                    {
                        currentPallet = palletProperties;
                    }
                }

                // *** pallet analysis ***
                // constraint set
                ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet();
                constraintSet.SetMaxHeight(new OptDouble(true, UnitsManager.ConvertLengthFrom(form.PalletHeight, UnitsManager.UnitSystem.UNIT_METRIC2)));
                constraintSet.SetAllowedOrientations(new bool[] { false, false, true });
                if (constraintSet.Valid)
                {
                    SolverCasePallet solver     = new SolverCasePallet(form.UseIntermediatePacking ? currentCase : itemProperties, currentPallet);
                    Layer2DBrickImp  layer      = solver.BuildBestLayer(constraintSet);
                    List <LayerDesc> layerDescs = new List <LayerDesc>();
                    if (null != layer)
                    {
                        layerDescs.Add(layer.LayerDescriptor);
                    }

                    // create analysis
                    AnalysisLayered palletAnalysis = document.CreateNewAnalysisCasePallet(
                        item._ref, item.ToString()
                        , form.UseIntermediatePacking ? currentCase : itemProperties
                        , currentPallet,
                        null, null,
                        null, null,
                        constraintSet,
                        layerDescs);
                }
                // save document
                fileName = form.FilePath;
                document.Write(form.FilePath);

                if (null != OpenFile)
                {
                    OpenFile(fileName);
                }
                // return true to let application open
                return(File.Exists(fileName));
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                return(false);
            }
        }
Ejemplo n.º 27
0
 public FormNewAnalysisPalletTruck(Document doc, AnalysisLayered analysis)
     : base(doc, analysis)
 {
     InitializeComponent();
 }
Ejemplo n.º 28
0
 public virtual void ExportIndexed(AnalysisLayered analysis, ref Stream stream)
 {
 }
 public FormNewAnalysisBoxCase(Document doc, AnalysisLayered analysis)
     : base(doc, analysis)
 {
     InitializeComponent();
 }
 public FormNewAnalysisCylinderPallet(Document doc, AnalysisLayered analysis)
     : base(doc, analysis)
 {
     InitializeComponent();
 }