public SelPackPalletSolution(Document document, PackPalletAnalysis analysis, PackPalletSolution sol)
     : base(document)
 {
     _analysis = analysis;
     _solution = sol;
     Name      = sol.Title;
 }
        public void SelectSolutionBySol(PackPalletSolution sol)
        {
            if (HasSolutionSelected(sol))
            {
                return;
            }
            // instantiate new SelSolution
            SelPackPalletSolution selSolution = new SelPackPalletSolution(ParentDocument, this, sol);

            // insert in list
            _selectedSolutions.Add(selSolution);
            // fire event
            if (null != SolutionSelected)
            {
                SolutionSelected(this, selSolution);
            }
            // set document modified (not analysis, otherwise selected solutions are erased)
            ParentDocument.Modify();
        }
        public int CompareTo(object obj)
        {
            // cast
            PackPalletSolution sol = obj as PackPalletSolution;

            if (null == sol)
            {
                return(0);
            }
            // comparison
            if (this.PackCount > sol.PackCount)
            {
                return(-1);
            }
            else if (this.PackCount < sol.PackCount)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Beispiel #4
0
 private void SavePackPalletSolution(
     PackPalletSolution sol
     , SelPackPalletSolution selSolution
     , XmlElement solutionsElt
     , XmlDocument xmlDoc)
 {
     // solution
     XmlElement solutionElt = xmlDoc.CreateElement("Solution");
     solutionsElt.AppendChild(solutionElt);
     // title
     XmlAttribute titleAttribute = xmlDoc.CreateAttribute("Title");
     titleAttribute.Value = sol.Title;
     solutionElt.Attributes.Append(titleAttribute);
     // layers
     XmlElement boxLayersElt = xmlDoc.CreateElement("BoxLayers");
     solutionElt.AppendChild(boxLayersElt);
     Save(sol.Layer, boxLayersElt, xmlDoc);
     // layerRefs
     XmlElement layerRefsElt = xmlDoc.CreateElement("LayerRefs");
     solutionElt.AppendChild(layerRefsElt);
     // layers
     foreach (LayerDescriptor layerDesc in sol.Layers)
     {
         XmlElement layerRefElt = xmlDoc.CreateElement("LayerRef");
         layerRefsElt.AppendChild(layerRefElt);
         XmlAttribute attributeSwapped = xmlDoc.CreateAttribute("Swapped");
         attributeSwapped.Value = layerDesc.Swapped.ToString();
         layerRefElt.Attributes.Append(attributeSwapped);
         XmlAttribute attributeHasInterlayer = xmlDoc.CreateAttribute("HasInterlayer");
         attributeHasInterlayer.Value = layerDesc.HasInterlayer.ToString();
         layerRefElt.Attributes.Append(attributeHasInterlayer);
     }
     // Is selected ?
     if (null != selSolution)
     {
         // selected attribute
         XmlAttribute selAttribute = xmlDoc.CreateAttribute("Selected");
         selAttribute.Value = "true";
         solutionElt.Attributes.Append(selAttribute);
     }
 }
Beispiel #5
0
        private PackPalletSolution LoadPackPalletSolution(XmlElement eltSolution)
        {
            // title -> instantiation
            string stitle = eltSolution.Attributes["Title"].Value;
            // layer and list
            ILayer layer = null;
            List<LayerDescriptor> layerDescriptors = new List<LayerDescriptor>();

            foreach (XmlNode nodeSolChild in eltSolution.ChildNodes)
            {
                XmlElement eltChild = nodeSolChild as XmlElement;
                if (null != eltChild)
                {
                    if (string.Equals(eltChild.Name, "BoxLayers", StringComparison.CurrentCultureIgnoreCase))
                    {
                        foreach (XmlNode nodeLayer in eltChild.ChildNodes)
                        {
                            XmlElement eltLayer = nodeLayer as XmlElement;
                            if (null != eltLayer)
                                layer = LoadLayer(eltLayer);
                        }
                    }
                    else if (string.Equals(eltChild.Name, "LayerRefs", StringComparison.CurrentCultureIgnoreCase))
                    {
                        foreach (XmlNode nodeLayerRef in eltChild.ChildNodes)
                        {
                            XmlElement eltLayerRef = nodeLayerRef as XmlElement;
                            if (null != eltLayerRef)
                            {
                                bool swapped = bool.Parse(eltLayerRef.Attributes["Swapped"].Value);
                                bool hasInterlayer = bool.Parse(eltLayerRef.Attributes["HasInterlayer"].Value);
                                layerDescriptors.Add(new LayerDescriptor(swapped, hasInterlayer));
                            }
                        }
                    }
                }
            }
            // create solution
            PackPalletSolution sol = new PackPalletSolution(null, stitle, layer as BoxLayer);
            foreach (LayerDescriptor desc in layerDescriptors)
                sol.AddLayer(desc.Swapped, desc.HasInterlayer);
            return sol;
        }
 public void UnselectSolutionBySol(PackPalletSolution sol)
 {
     UnSelectSolution(GetSelSolutionBySolution(sol));
 }
 public void SelectSolutionBySol(PackPalletSolution sol)
 {
     if (HasSolutionSelected(sol)) return;
     // instantiate new SelSolution
     SelPackPalletSolution selSolution = new SelPackPalletSolution(ParentDocument, this, sol);
     // insert in list
     _selectedSolutions.Add(selSolution);
     // fire event
     if (null != SolutionSelected)
         SolutionSelected(this, selSolution);
     // set document modified (not analysis, otherwise selected solutions are erased)
     ParentDocument.Modify();
 }
 public bool HasSolutionSelected(PackPalletSolution sol)
 {
     return (null != GetSelSolutionBySolution(sol));
 }
        private List<PackPalletSolution> GenerateSolutions()
        {
            List<PackPalletSolution> solutions = new List<PackPalletSolution>();

            HalfAxis.HAxis[] axes = { HalfAxis.HAxis.AXIS_Z_N, HalfAxis.HAxis.AXIS_Z_P };
            // loop throught all patterns
            foreach (LayerPattern pattern in _patterns)
            {
                // loop throught all axes
                foreach (HalfAxis.HAxis axis in axes) // axis
                {
                    // loop through
                    Layer layer = new Layer(_packProperties, _palletProperties, _constraintSet, axis, false);
                    double actualLength = 0.0, actualWidth = 0.0;
                    if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                        continue;
                    pattern.GenerateLayer(layer, actualLength, actualWidth);

                    // filter by layer weight
                    if (_constraintSet.MaximumLayerWeight.Activated
                        && (layer.Count * _packProperties.Weight > _constraintSet.MaximumLayerWeight.Value))
                        continue;
                    // filter by maximum space
                    if (_constraintSet.MaximumSpaceAllowed.Activated
                        && layer.MaximumSpace > _constraintSet.MaximumSpaceAllowed.Value)
                        continue;
                    double layerHeight = layer.BoxHeight;

                    string title = string.Format("{0}-{1}", pattern.Name, axis.ToString());
                    double zLayer = 0.0;
                    BoxLayer boxLayer = new BoxLayer(zLayer, "");
                    foreach (LayerPosition layerPos in layer)
                    {
                        LayerPosition layerPosTemp = AdjustLayerPosition(layerPos);
                        BoxPosition boxPos = new BoxPosition(
                            layerPosTemp.Position
                                - (0.5 * _constraintSet.OverhangX) * Vector3D.XAxis
                                - (0.5 * _constraintSet.OverhangY) * Vector3D.YAxis
                                + zLayer * Vector3D.ZAxis
                            , layerPosTemp.LengthAxis
                            , layerPosTemp.WidthAxis
                            );
                        boxLayer.Add(boxPos);
                    }
                    boxLayer.MaximumSpace = layer.MaximumSpace;
                    BBox3D layerBBox = boxLayer.BoundingBox(_packProperties);
                    // filter by overhangX
                    if (_constraintSet.MinOverhangX.Activated
                        && (0.5 * (layerBBox.Length - _palletProperties.Length) < _constraintSet.MinOverhangX.Value))
                        continue;
                    // filter by overhangY
                    if (_constraintSet.MinOverhangY.Activated
                        && (0.5 * (layerBBox.Width - _palletProperties.Width) < _constraintSet.MinOverhangY.Value))
                        continue;

                    double interlayerThickness = null != _interlayerProperties ? _interlayerProperties.Thickness : 0;
                    double interlayerWeight = null != _interlayerProperties ? _interlayerProperties.Weight : 0;

                    PackPalletSolution sol = new PackPalletSolution(null, title, boxLayer);
                    int noLayer = 1,
                        noInterlayer = (null != _interlayerProperties && _constraintSet.HasFirstInterlayer) ? 1 : 0;

                    bool maxHeightReached = _constraintSet.MaximumPalletHeight.Activated
                        && (_packProperties.Height
                        + noInterlayer * interlayerThickness
                        + noLayer * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value;
                    bool maxWeightReached = _constraintSet.MaximumPalletWeight.Activated
                        && (_palletProperties.Weight
                        + noInterlayer * interlayerWeight
                        + noLayer * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value);

                    noLayer = 0; noInterlayer = 0;
                    int iCountInterlayer = 0, iCountSwap = 1;
                    bool bSwap = false;
                    while (!maxHeightReached && !maxWeightReached)
                    {
                        bool bInterlayer = (0 == iCountInterlayer) && ((noLayer != 0) || _constraintSet.HasFirstInterlayer);
                        // actually insert new layer
                        sol.AddLayer(bSwap, bInterlayer);
                        // increment number of layers
                        noLayer++;
                        noInterlayer += (bInterlayer ? 1 : 0);
                        // update iCountInterlayer && iCountSwap
                        ++iCountInterlayer;
                        if (iCountInterlayer >= _constraintSet.InterlayerPeriod) iCountInterlayer = 0;
                        ++iCountSwap;
                        if (iCountSwap > _constraintSet.LayerSwapPeriod) { iCountSwap = 1; bSwap = !bSwap; }
                        // update maxHeightReached & maxWeightReached
                        maxHeightReached = _constraintSet.MaximumPalletHeight.Activated
                            && (_palletProperties.Height
                            + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerThickness
                            + (noLayer + 1) * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value;
                        maxWeightReached = _constraintSet.MaximumPalletWeight.Activated
                            && (_palletProperties.Weight
                            + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerWeight
                            + (noLayer + 1) * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value);
                    }

                    if (sol.PackCount > 0)
                        solutions.Add(sol);
                } // axis
            } // pattern
            solutions.Sort();
            return solutions;
        }
 private void onGridSolutionSelectionChanged(object sender, SourceGrid.RangeRegionChangedEventArgs e)
 {
     SourceGrid.RangeRegion region = gridSolutions.Selection.GetSelectionRegion();
     int[] indexes = region.GetRowsIndex();
     // no selection -> exit
     if (indexes.Length == 0) return;
     // get selected solution
     _sol = gridSolutions.Rows[indexes[0]].Tag as PackPalletSolution;
     //_sol = _analysis.Solutions[indexes[0]];
     // update select/unselect button text
     UpdateSelectButtonText();
     // redraw
     graphCtrlSolution.Invalidate();
 }
 public LayerType(PackPalletSolution sol, bool swapped)
 {
     _sol = sol; _swapped = swapped;
 }
 public void UnselectSolutionBySol(PackPalletSolution sol)
 {
     UnSelectSolution(GetSelSolutionBySolution(sol));
 }
 public bool HasSolutionSelected(PackPalletSolution sol)
 {
     return(null != GetSelSolutionBySolution(sol));
 }
 public SelPackPalletSolution GetSelSolutionBySolution(PackPalletSolution sol)
 {
     return(_selectedSolutions.Find(delegate(SelPackPalletSolution selSol) { return selSol.Solution == sol; }));
 }
 public LayerType(PackPalletSolution sol, bool swapped)
 {
     _sol = sol; _swapped = swapped;
 }
 public PackPalletSolutionViewer(PackPalletSolution solution)
 {
     _analysis = null != solution ? solution.Analysis : null;
     _solution = solution;
 }
 private void btSelectSolution_Click(object sender, EventArgs e)
 {
     try
     {
         int iSel = GetCurrentSolutionIndex();
         // get selected solution
         _sol = gridSolutions.Rows[iSel].Tag as PackPalletSolution;
         if (null == _sol) return;
         if (!_analysis.HasSolutionSelected(_sol))
             _analysis.SelectSolutionBySol(_sol);
         else
             _analysis.UnselectSolutionBySol(_sol);
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }
 public SelPackPalletSolution(Document document, PackPalletAnalysis analysis, PackPalletSolution sol)
     : base(document)
 {
     _analysis = analysis;
     _solution = sol;
     Name = sol.Title;
 }
 public void Update(ItemBase item)
 {
     // update grid
     FillGrid();
     // select first solution
     if (gridSolutions.RowsCount > 0)
         gridSolutions.Selection.SelectRow(1, true);
     if (_analysis.Solutions.Count > 0)
         _sol = _analysis.Solutions[0];
     // draw
     graphCtrlSolution.Invalidate();
 }
 public SelPackPalletSolution GetSelSolutionBySolution(PackPalletSolution sol)
 {
     return _selectedSolutions.Find(delegate(SelPackPalletSolution selSol) { return selSol.Solution == sol; });
 }