Exemplo n.º 1
0
        private PackWrapper LoadWrapper(XmlElement xmlWrapperElt)
        {
            if (null == xmlWrapperElt) return null;

            string sType = xmlWrapperElt.Attributes["Type"].Value;
            string sColor = xmlWrapperElt.Attributes["Color"].Value;
            string sWeight = xmlWrapperElt.Attributes["Weight"].Value;
            string sUnitThickness = xmlWrapperElt.Attributes["UnitThickness"].Value;

            double thickness = UnitsManager.ConvertLengthFrom(System.Convert.ToDouble(sUnitThickness, System.Globalization.CultureInfo.InvariantCulture), _unitSystem);
            Color wrapperColor = Color.FromArgb(System.Convert.ToInt32(sColor));
            double weight = UnitsManager.ConvertMassFrom(System.Convert.ToDouble(sWeight, System.Globalization.CultureInfo.InvariantCulture), _unitSystem);

            if (sType == "WT_POLYETHILENE")
            {
                bool transparent = bool.Parse(xmlWrapperElt.Attributes["Transparent"].Value);
                return new WrapperPolyethilene(thickness, weight, wrapperColor, transparent);
            }
            else if (sType == "WT_PAPER")
            {
                return new WrapperPaper(thickness, weight, wrapperColor);
            }
            else if (sType == "WT_CARDBOARD")
            {
                string sWalls = "1 1 1";
                if (xmlWrapperElt.HasAttribute("NumberOfWalls"))
                    sWalls = xmlWrapperElt.Attributes["NumberOfWalls"].Value;
                int[] walls = sWalls.Split(' ').Select(n => Convert.ToInt32(n)).ToArray();
                WrapperCardboard wrapper = new WrapperCardboard(thickness, weight, wrapperColor);
                wrapper.SetNoWalls(walls[0], walls[1], walls[2]);
                return wrapper;
            }
            else if (sType == "WT_TRAY")
            {
                string sWalls = "1 1 1";
                if (xmlWrapperElt.HasAttribute("NumberOfWalls"))
                    sWalls = xmlWrapperElt.Attributes["NumberOfWalls"].Value;
                int[] walls = sWalls.Split(' ').Select(n => Convert.ToInt32(n)).ToArray();

                string sHeight = xmlWrapperElt.Attributes["Height"].Value;
                double height = UnitsManager.ConvertLengthFrom(System.Convert.ToDouble(sHeight, System.Globalization.CultureInfo.InvariantCulture), _unitSystem);
                WrapperTray wrapper = new WrapperTray(thickness, weight, wrapperColor);
                wrapper.SetNoWalls(walls[0], walls[1], walls[2]);
                wrapper.Height = height;
                return wrapper;
            }
            else
                return null;
        }
 private void btAddPackPalletAnalysis_Click(object sender, EventArgs e)
 {
     try
     {
         // get selected box
         BoxProperties boxProperties = SelectedBox;
         // get selected pallet
         PalletProperties palletProperties = SelectedPallet;
         // get selected caseOptimSolution
         CaseOptimSolution sol = SelectedSolution;
         PackArrangement arrangement = sol.CaseDefinition.Arrangement;
         // build new case name
         string name = string.Format("{0}_{1}*{2}*{3}_{4}{5}"
             , boxProperties.Name
             , arrangement._iLength
             , arrangement._iWidth
             , arrangement._iHeight
             , sol.CaseDefinition.Dim0
             , sol.CaseDefinition.Dim1);
         // build new case description
         string description = string.Format("Case generated by case optimization for box {0} and pallet {1}"
             , boxProperties.Name
             , palletProperties.Name);
         // analysis name/description
         string analysisName = string.Format("OptimAnalysis{0}_{1}*{2}*{3}_{4}{5}"
             , boxProperties.Name
             , boxProperties.Name
             , arrangement._iLength
             , arrangement._iWidth
             , arrangement._iHeight
             , sol.CaseDefinition.Dim0
             , sol.CaseDefinition.Dim1);
         string analysisDescription = string.Format("Pallet analysis generated by case optimisation for box {0} and pallet {1}"
             , boxProperties.Name
             , palletProperties.Name);
         // create PackProperties
         HalfAxis.HAxis axis = PackProperties.Orientation(sol.CaseDefinition.Dim0, sol.CaseDefinition.Dim1);
         double wrapperWeight =  WrapperCardboard.EstimateWeight(
                     SelectedBox
                     , arrangement
                     , axis
                     , NoWalls
                     , WallThickness
                     , WallSurfaceMass);
         // cardboard wrapper
         WrapperCardboard wrapper = new WrapperCardboard(WallThickness, wrapperWeight, Color.Chocolate);
         wrapper.SetNoWalls(NoWalls[0], NoWalls[1], NoWalls[2]);
         // pack
         PackProperties pack = _document.CreateNewPack(
             name, description
             , boxProperties, arrangement, axis
             , wrapper);
         // constraint set
         PackPalletConstraintSet constraintSet = new PackPalletConstraintSet();
         constraintSet.OverhangX = OverhangX;
         constraintSet.OverhangY = OverhangY;
         constraintSet.MaximumPalletHeight = new OptDouble(true, MaximumPalletHeight);
         // create analysis
         _document.CreateNewPackPalletAnalysis(
             analysisName
             , analysisDescription
             , pack
             , palletProperties
             , null
             , constraintSet
             , new PackPalletSolver());
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }