コード例 #1
0
ファイル: LayerSolver.cs プロジェクト: TimVelo/StackBuilder
        public List<Layer2D> BuildLayers(Vector3D dimBox, Vector2D dimContainer, ConstraintSetAbstract constraintSet, bool keepOnlyBest)
        {
            // instantiate list of layers
            List<Layer2D> listLayers0 = new List<Layer2D>();

            // loop through all patterns
            foreach (LayerPattern pattern in LayerPattern.All)
            {
                // loop through all orientation
                foreach (HalfAxis.HAxis axisOrtho in HalfAxis.All)
                {
                    // is orientation allowed
                    if ( !constraintSet.AllowOrientation(axisOrtho) )
                        continue;
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 1; ++iSwapped)
                    {
                        // does swapping makes sense for this layer pattern ?
                        if (!pattern.CanBeSwapped && (iSwapped == 1))
                            continue;
                        // instantiate layer
                        Layer2D layer = new Layer2D(dimBox, dimContainer, axisOrtho, iSwapped == 1);
                        layer.PatternName = pattern.Name;
                        double actualLength = 0.0, actualWidth = 0.0;
                        if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                            continue;
                        pattern.GenerateLayer(layer, actualLength, actualWidth);
                        if (0 == layer.Count)
                            continue;
                        listLayers0.Add(layer);
                    }
                }
            }

            // keep only best layers
            if (keepOnlyBest)
            {
                // 1. get best count
                int bestCount = 0;
                foreach (Layer2D layer in listLayers0)
                    bestCount = Math.Max(layer.CountInHeight(constraintSet.OptMaxHeight.Value), bestCount);

                // 2. remove any layer that does not match the best count given its orientation
                List<Layer2D> listLayers1 = new List<Layer2D>();
                foreach (Layer2D layer in listLayers0)
                {
                    if (layer.CountInHeight(constraintSet.OptMaxHeight.Value) >= bestCount)
                        listLayers1.Add(layer);
                }
                // 3. copy back in original list
                listLayers0.Clear();
                listLayers0.AddRange(listLayers1);
            }
            if (constraintSet.OptMaxHeight.Activated)
                listLayers0.Sort(new LayerComparerCount(constraintSet.OptMaxHeight.Value));

            return listLayers0;
        }
コード例 #2
0
        private void onTimerTick(object sender, EventArgs e)
        {
            if (_index == _layerList.Count)
            {
                _timer.Stop();
                return;
            }
            Layer2D layer = _layerList[_index];
            // create button and add to panel
            Button btn = new Button();

            btn.Image    = LayerToImage.Draw(_layerList[_index], _bProperties, _contHeight, szButtons, false);//bitmap;
            btn.Location = new Point(_x, _y) + (Size)AutoScrollPosition;
            btn.Size     = szButtons;
            btn.Tag      = new LayerItem(layer, false);
            btn.Click   += onLayerSelected;
            Controls.Add(btn);

            // give button a tooltip
            tooltip.SetToolTip(btn
                               , String.Format("{0} * {1} = {2}\n {3} | {4}"
                                               , layer.BoxCount
                                               , layer.NoLayers(_contHeight)
                                               , layer.CountInHeight(_contHeight)
                                               , HalfAxis.ToString(layer.AxisOrtho)
                                               , layer.PatternName));

            // adjust i, x and y for next image
            AdjustXY(ref _x, ref _y);
            ++_index;
        }
コード例 #3
0
        public void Draw(Graphics2D graphics, Packable packable, double height, bool selected)
        {
            graphics.NumberOfViews = 1;
            graphics.Graphics.Clear(selected ? Color.LightBlue : Color.White);
            graphics.SetViewport(0.0f, 0.0f, (float)_layer.PalletLength, (float)_layer.PalletWidth);

            if (_layer != null)
            {
                graphics.SetCurrentView(0);
                graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_layer.PalletLength, _layer.PalletWidth), Color.Black);
                uint pickId = 0;
                foreach (LayerPosition bPosition in _layer)
                {
                    Box b = null;
                    if (packable is PackProperties)
                    {
                        b = new Pack(pickId++, packable as PackProperties, bPosition);
                    }
                    else
                    {
                        b = new Box(pickId++, packable, bPosition);
                    }
                    b.Draw(graphics);
                }

                // draw axes
                bool showAxis = false;
                if (showAxis)
                {
                    // draw axis X
                    graphics.DrawLine(Vector2D.Zero, new Vector2D(_layer.PalletLength, 0.0), Color.Red);
                    // draw axis Y
                    graphics.DrawLine(Vector2D.Zero, new Vector2D(0.0, _layer.PalletWidth), Color.Green);
                }
            }

            Size s = graphics.Size;

            // *** Annotate : begin ***
            if (height > 0)
            {
                string annotation = string.Format(
                    "{0}*{1}={2}"
                    , _layer.Count
                    , _layer.NoLayers(height)
                    , _layer.CountInHeight(height));
                Font         tfont           = new Font("Arial", _fontSize);
                Color        brushColor      = Color.White;
                Color        backgroundColor = Color.Black;
                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignment.Far;
                sf.LineAlignment = StringAlignment.Far;
                System.Drawing.Graphics g = graphics.Graphics;
                Size txtSize = g.MeasureString(annotation, tfont).ToSize();
                g.FillRectangle(new SolidBrush(backgroundColor), new Rectangle(s.Width - txtSize.Width - 2, s.Height - txtSize.Height - 2, txtSize.Width + 2, txtSize.Height + 2));
                g.DrawString(annotation, tfont, new SolidBrush(brushColor), new Point(s.Width - 3, s.Height - 3), sf);
            }
            // *** Annotate : end ***
        }
コード例 #4
0
ファイル: LayerSolver.cs プロジェクト: sm2x/StackBuilder
        public List <Layer2D> BuildLayers(
            Vector3D dimBox, Vector2D dimContainer,
            double offsetZ, /* e.g. pallet height */
            ConstraintSetAbstract constraintSet, bool keepOnlyBest)
        {
            // instantiate list of layers
            var listLayers0 = new List <Layer2D>();

            // loop through all patterns
            foreach (LayerPatternBox pattern in LayerPatternBox.All)
            {
                // loop through all orientation
                HalfAxis.HAxis[] patternAxes = pattern.IsSymetric ? HalfAxis.Positives : HalfAxis.All;
                foreach (HalfAxis.HAxis axisOrtho in patternAxes)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(Layer2D.VerticalAxis(axisOrtho)))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 2; ++iSwapped)
                    {
                        try
                        {
                            // does swapping makes sense for this layer pattern ?
                            if (!pattern.CanBeSwapped && (iSwapped == 1))
                            {
                                continue;
                            }
                            // instantiate layer
                            var layer = new Layer2D(dimBox, dimContainer, pattern.Name, axisOrtho, iSwapped == 1)
                            {
                                ForcedSpace = constraintSet.MinimumSpace.Value
                            };
                            if (layer.NoLayers(constraintSet.OptMaxHeight.Value) < 1)
                            {
                                continue;
                            }
                            layer.PatternName = pattern.Name;
                            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
                            {
                                continue;
                            }
                            pattern.GenerateLayer(layer, actualLength, actualWidth);
                            if (0 == layer.Count)
                            {
                                continue;
                            }
                            listLayers0.Add(layer);
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Pattern: {0} Orient: {1} Swapped: {2} Message: {3}"
                                             , pattern.Name
                                             , axisOrtho.ToString()
                                             , iSwapped == 1 ? "True" : "False"
                                             , ex.Message);
                        }
                    }
                }
            }
            // keep only best layers
            if (keepOnlyBest)
            {
                // 1. get best count
                int bestCount = 0;
                foreach (Layer2D layer in listLayers0)
                {
                    bestCount = Math.Max(layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ), bestCount);
                }

                // 2. remove any layer that does not match the best count given its orientation
                var listLayers1 = new List <Layer2D>();
                foreach (Layer2D layer in listLayers0)
                {
                    if (layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ) >= bestCount)
                    {
                        listLayers1.Add(layer);
                    }
                }
                // 3. copy back in original list
                listLayers0.Clear();
                listLayers0.AddRange(listLayers1);
            }
            if (constraintSet.OptMaxHeight.Activated)
            {
                listLayers0.Sort(new LayerComparerCount(constraintSet, offsetZ));
            }

            return(listLayers0);
        }
コード例 #5
0
        public List <Layer2D> BuildLayers(Vector3D dimBox, Vector2D dimContainer, ConstraintSetAbstract constraintSet, bool keepOnlyBest)
        {
            // instantiate list of layers
            List <Layer2D> listLayers0 = new List <Layer2D>();

            // loop through all patterns
            foreach (LayerPattern pattern in LayerPattern.All)
            {
                // loop through all orientation
                foreach (HalfAxis.HAxis axisOrtho in HalfAxis.All)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(axisOrtho))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 1; ++iSwapped)
                    {
                        // does swapping makes sense for this layer pattern ?
                        if (!pattern.CanBeSwapped && (iSwapped == 1))
                        {
                            continue;
                        }
                        // instantiate layer
                        Layer2D layer = new Layer2D(dimBox, dimContainer, axisOrtho, iSwapped == 1);
                        layer.PatternName = pattern.Name;
                        double actualLength = 0.0, actualWidth = 0.0;
                        if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                        {
                            continue;
                        }
                        pattern.GenerateLayer(layer, actualLength, actualWidth);
                        if (0 == layer.Count)
                        {
                            continue;
                        }
                        listLayers0.Add(layer);
                    }
                }
            }

            // keep only best layers
            if (keepOnlyBest)
            {
                // 1. get best count
                int bestCount = 0;
                foreach (Layer2D layer in listLayers0)
                {
                    bestCount = Math.Max(layer.CountInHeight(constraintSet.OptMaxHeight.Value), bestCount);
                }

                // 2. remove any layer that does not match the best count given its orientation
                List <Layer2D> listLayers1 = new List <Layer2D>();
                foreach (Layer2D layer in listLayers0)
                {
                    if (layer.CountInHeight(constraintSet.OptMaxHeight.Value) >= bestCount)
                    {
                        listLayers1.Add(layer);
                    }
                }
                // 3. copy back in original list
                listLayers0.Clear();
                listLayers0.AddRange(listLayers1);
            }
            if (constraintSet.OptMaxHeight.Activated)
            {
                listLayers0.Sort(new LayerComparerCount(constraintSet.OptMaxHeight.Value));
            }

            return(listLayers0);
        }