Example #1
0
        public void Draw(Graphics2D graphics)
        {
            if (null == _truckSolution)
            {
                throw new Exception("No trucksolution defined!");
            }

            // get analysis
            CasePalletAnalysis analysis = _truckSolution.ParentTruckAnalysis.ParentAnalysis;
            double             length   = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletLength;
            double             width    = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletWidth;
            double             height   = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletHeight;

            // initialize Graphics2D object
            graphics.NumberOfViews = 1;
            graphics.SetViewport(
                0.0f, 0.0f
                , (float)_truckSolution.ParentTruckAnalysis.TruckProperties.Length
                , (float)_truckSolution.ParentTruckAnalysis.TruckProperties.Width);

            graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_truckSolution.ParentTruckAnalysis.TruckProperties.Length, _truckSolution.ParentTruckAnalysis.TruckProperties.Width), Color.Black);

            uint pickId = 0;

            foreach (BoxPosition bPositionLayer in _truckSolution.Layer)
            {
                Box b = new Box(pickId++, length, width, height);
                b.Position   = bPositionLayer.Position;
                b.LengthAxis = HalfAxis.ToVector3D(bPositionLayer.DirectionLength);
                b.WidthAxis  = HalfAxis.ToVector3D(bPositionLayer.DirectionWidth);
                graphics.DrawBox(b);
            }
        }
 private void btAddSolution_Click(object sender, EventArgs e)
 {
     try
     {
         // get selected box
         BoxProperties boxProperties = SelectedBox;
         // get selected pallet
         PalletProperties palletProperties = SelectedPallet;
         // get selected caseOptimSolution
         CaseOptimSolution    sol         = SelectedSolution;
         CaseOptimArrangement 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);
         // add new case
         CaseOfBoxesProperties caseProperties = _document.CreateNewCaseOfBoxes(
             name, description
             , boxProperties
             , sol.CaseDefinition
             , BuildCaseOptimConstraintSet());
         // set color
         caseProperties.SetColor(Color.Chocolate);
         // add new pallet analysis
         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);
         List <CasePalletSolution> palletSolutionList = new List <CasePalletSolution>();
         palletSolutionList.Add(sol.PalletSolution);
         CasePalletAnalysis analysis = _document.CreateNewCasePalletAnalysis(
             analysisName
             , analysisDescription
             , caseProperties
             , palletProperties
             , null, null
             , null, null, null
             , BuildPalletConstraintSet()
             , palletSolutionList);
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }
        private void ProcessReportSolution(reportSolution rSol)
        {
            // create document
            Document doc = new Document(rSol.reportParameters.name, rSol.reportParameters.description, rSol.reportParameters.author, DateTime.Now, null);
            // load analysis
            CasePalletAnalysis analysis = LoadPalletAnalysis(doc, rSol.solutionRef.analysisId);

            if (null == analysis)
            {
                return;
            }
            // compute solutions
            treeDiM.StackBuilder.Engine.CasePalletSolver solver = new treeDiM.StackBuilder.Engine.CasePalletSolver();
            solver.ProcessAnalysis(analysis);
            // retrieve wanted solution
            List <Basics.CasePalletSolution> solutions = analysis.Solutions;

            if (rSol.solutionRef.index >= solutions.Count)
            {
                throw new Exception(string.Format("Analysis {0} has no solution with index {1}", analysis.Name, rSol.solutionRef.index));
            }
            Basics.CasePalletSolution sol = solutions[(int)rSol.solutionRef.index];
            // selected solution
            SelCasePalletSolution selSolution = new SelCasePalletSolution(doc, analysis, sol);
            // generate report
            ReporterMSWord reporter = new ReporterMSWord(new ReportData(analysis, selSolution)
                                                         , rSol.reportParameters.templateFilePath, rSol.reportParameters.outputPath, new Margins());
        }
Example #4
0
        private void ProcessDocument(genDocument genDoc)
        {
            // create document
            Document document = new Document(genDoc.name, genDoc.description, genDoc.author, DateTime.Now, null);

            foreach (analysisRef aRef in genDoc.analysisRef)
            {
                // get analysis
                CasePalletAnalysis analysis = LoadPalletAnalysis(document, aRef.analysisId);
                // load case if any
                // load bundle if any
                // load pallet
                // load interlayer if any
                // load pallet analysis
            }
            // attempt to create directory
            // save document
            document.Write(genDoc.path);
            // open generated document using TreeDim.StackBuilder.Desktop
            string stackbuilderExePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "TreeDim.StackBuilder.Desktop.exe");

            if (genDoc.open && File.Exists(stackbuilderExePath))
            {
                // build start info
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName  = stackbuilderExePath;
                startInfo.Arguments = "\"" + genDoc.path + "\"";
                System.Diagnostics.Process.Start(startInfo);
            }
            else
            {
                _log.Info(string.Format("Executable {0} could not be found!", stackbuilderExePath));
            }
        }
        private void ProcessAnalysisSolutionList(analysisSolutionList solutionList)
        {
            // load analysis
            CasePalletAnalysis analysis = LoadPalletAnalysis(null, solutionList.analysisId);

            if (solutionList.maxNumberOfSolutionsSpecified)
            {
                analysis.ConstraintSet.NumberOfSolutionsKept = (int)solutionList.maxNumberOfSolutions;
            }
            // compute solutions
            treeDiM.StackBuilder.Engine.CasePalletSolver solver = new treeDiM.StackBuilder.Engine.CasePalletSolver();
            solver.ProcessAnalysis(analysis);
            // instantiate pallet solution list
            PALLETSOLUTIONLIST palletSolutionList = new PALLETSOLUTIONLIST();

            // saves solutions to list
            foreach (CasePalletSolution sol in analysis.Solutions)
            {
                palletSolution xmlPalletSol = new palletSolution();
                xmlPalletSol.title      = sol.Title;
                xmlPalletSol.caseCount  = sol.CaseCount;
                xmlPalletSol.efficiency = sol.VolumeEfficiencyCases;
                xmlPalletSol.weight     = sol.PalletWeight;
                xmlPalletSol.palletDimensions.Add(sol.PalletLength);
                xmlPalletSol.palletDimensions.Add(sol.PalletWidth);
                xmlPalletSol.palletDimensions.Add(sol.PalletHeight);
                xmlPalletSol.homogeneousLayer = sol.HasHomogeneousLayers;

                palletSolutionList.palletSolution.Add(xmlPalletSol);
            }

            palletSolutionList.SaveToFile(solutionList.path);
        }
        private Bitmap GetBoxBitmapFromDesc(PalletSolutionDesc desc)
        {
            bool showDimensions = false;

            // load document
            Document document = new Document(desc.FullFilePath, null);

            if (document.Analyses.Count != 1)
            {
                throw new Exception("Failed to load analysis.");
            }
            // get analysis and solution
            CasePalletAnalysis analysis = document.Analyses[0];
            Graphics3DImage    graphics = new Graphics3DImage(new Size(50, 50));

            graphics.CameraPosition = Graphics3D.Corner_0;
            graphics.Target         = Vector3D.Zero;
            Box box = new Box(0, analysis.BProperties);

            graphics.AddBox(box);
            if (showDimensions)
            {
                graphics.AddDimensions(new DimensionCube(box.Length, box.Width, box.Height));
            }
            graphics.Flush();
            return(graphics.Bitmap);
        }
Example #7
0
        public List <CaseOptimSolution> CaseOptimSolutions(int iNumber)
        {
            List <CaseOptimSolution> caseOptimSolutions = new List <CaseOptimSolution>();

            foreach (CaseDefinition caseDefinition in CaseDefinitions(iNumber))
            {
                Vector3D      outerDimensions = caseDefinition.OuterDimensions(_boxProperties, _caseOptimConstraintSet);
                BoxProperties bProperties     = new BoxProperties(_palletProperties.ParentDocument, outerDimensions.X, outerDimensions.Y, outerDimensions.Z);
                // build analysis
                CasePalletAnalysis casePalletAnalysis = new CasePalletAnalysis(
                    bProperties, _palletProperties,
                    null, null,
                    null, null, null,
                    _palletConstraintSet);
                // instantiate solver
                CasePalletSolver solver = new CasePalletSolver();
                // solve
                solver.ProcessAnalysis(casePalletAnalysis);
                // get list of pallet solutions
                List <CasePalletSolution> palletSolutions = casePalletAnalysis.Solutions;
                if (palletSolutions.Count > 0)
                {
                    int maxCaseCount = palletSolutions[0].CaseCount;
                    int i            = 0;
                    while (maxCaseCount == palletSolutions[i].CaseCount)
                    {
                        caseOptimSolutions.Add(new CaseOptimSolution(caseDefinition, palletSolutions[i]));
                        ++i;
                    }
                }
            }
            // sort caseOptimSolution
            caseOptimSolutions.Sort();
            return(caseOptimSolutions);
        }
        public DockContentAnalysisCaseOfBoxes(IDocument document, CasePalletAnalysis analysis)
        {
            _document = document;
            _analysis = analysis;
            _analysis.AddListener(this);

            InitializeComponent();
        }
Example #9
0
        private void Draw()
        {
            try
            {
                // get current descriptor
                PalletSolutionDesc desc = CurrentSolutionDesc;
                // sanity check
                if (null == desc ||
                    pictureBoxCase.Size.Width < 1 || pictureBoxCase.Size.Height < 1 ||
                    pictureBoxSolution.Size.Width < 1 || pictureBoxSolution.Size.Height < 1)
                {
                    return;
                }

                // load document
                Document document = new Document(desc.FullFilePath, null);
                if (!document.AnalysesCasePallet.Any())
                {
                    return;
                }
                // get analysis and solution
                CasePalletAnalysis analysis = document.AnalysesCasePallet.First() as CasePalletAnalysis;
                {
                    Graphics3DImage graphics = new Graphics3DImage(pictureBoxCase.Size)
                    {
                        CameraPosition = Graphics3D.Corner_0,
                        Target         = Vector3D.Zero
                    };
                    Box box = new Box(0, analysis.BProperties);
                    graphics.AddBox(box);
                    graphics.AddDimensions(new DimensionCube(box.Length, box.Width, box.Height));
                    graphics.Flush();
                    pictureBoxCase.Image = graphics.Bitmap;
                }

                {
                    // instantiate graphics
                    Graphics3DImage graphics = new Graphics3DImage(pictureBoxSolution.Size)
                    {
                        // set camera position
                        CameraPosition = Graphics3D.Corner_0,
                        Target         = Vector3D.Zero
                    };
                    // instantiate solution viewer
                    CasePalletSolutionViewer sv = new CasePalletSolutionViewer(analysis.Solutions[0]);
                    sv.Draw(graphics);
                    graphics.Flush();
                    // show generated bitmap on picture box control
                    pictureBoxSolution.Image = graphics.Bitmap;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Example #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="document">object implementing the IDocument interface</param>
        /// <param name="analysis">viewed analysis</param>
        public DockContentCasePalletAnalysis(IDocument document, CasePalletAnalysis analysis)
        {
            _document = document;

            _analysis = analysis;
            _analysis.AddListener(this);

            _analysis.SolutionSelected         += new CasePalletAnalysis.SelectSolution(onSolutionSelectionChanged);
            _analysis.SolutionSelectionRemoved += new CasePalletAnalysis.SelectSolution(onSolutionSelectionChanged);

            InitializeComponent();
        }
Example #11
0
        static void Main(string[] args)
        {
            ILog log = LogManager.GetLogger(typeof(Program));

            XmlConfigurator.Configure();

            try
            {
                // check arguments
                if (args.Length != 1)
                {
                    log.Info("No command argument. Exiting...");
                    return;
                }
                if (!File.Exists(args[0]))
                {
                    log.Info(string.Format("File {0} could not be found. Exiting...", args[0]));
                    return;
                }

                string filePath   = args[0];
                string outputPath = Path.ChangeExtension(filePath, "dae");
                // load document
                Document doc = new Document(filePath, new DocumentListenerLog());
                // get first analysis
                List <CasePalletAnalysis> analyses = doc.Analyses;
                if (analyses.Count == 0)
                {
                    log.Info("Document has no analysis -> Exiting...");
                    return;
                }
                CasePalletAnalysis analysis = analyses[0];
                if (analysis.Solutions.Count == 0)
                {
                    log.Info("Analysis has no solution -> Exiting...");
                    return;
                }

                CasePalletSolution palletSolution = analysis.Solutions[0];
                // export collada file
                ColladaExporter.Exporter exporter = new Exporter(palletSolution);
                exporter.Export(outputPath);
                log.Debug(string.Format("Successfully exported {0} ...", outputPath));

                // browse file
                Exporter.BrowseWithGoogleChrome(outputPath);
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
        }
Example #12
0
 /// <summary>
 /// handles ECT analysis removal
 /// </summary>
 public void OnECTAnalysisRemoved(Document doc, CasePalletAnalysis analysis, SelCasePalletSolution selSolution, ECTAnalysis ectAnalysis)
 {
     /*
      * // get node
      * TreeNode ectAnalysisNode = FindNode(null, new NodeTag(NodeTag.NodeType.NT_ECTANALYSIS, doc, analysis, selSolution, ectAnalysis));
      * // test
      * if (null == ectAnalysisNode)
      * {
      *  _log.Warn(string.Format("Failed to find a valid tree node for truck analysis {0}", ectAnalysis.Name));
      * }
      * // remove node
      * Nodes.Remove(ectAnalysisNode);
      */
 }
Example #13
0
        public static void StartPalletization(string name, double length, double width, double height)
        {
            // show analysis details dialog
            FormDefineAnalysis formDefinition = new FormDefineAnalysis();

            formDefinition.CaseName   = name;
            formDefinition.CaseLength = length;
            formDefinition.CaseWidth  = width;
            formDefinition.CaseHeight = height;
            formDefinition.Pallets    = Pallets;

            if (DialogResult.OK != formDefinition.ShowDialog())
            {
                return;
            }

            // create document
            Document doc = new Document(name, name + "_on_" + formDefinition.Pallet.Name, "from extension component", DateTime.Now, null);
            // create case in document
            BoxProperties caseInDoc = doc.CreateNewCase(formDefinition.Case);
            // create pallet in document
            PalletProperties palletInDoc = doc.CreateNewPallet(formDefinition.Pallet);
            // create interlayer in document
            InterlayerProperties interlayerInDoc = formDefinition.Interlayer == null ? null : doc.CreateNewInterlayer(formDefinition.Interlayer);

            // solver
            CasePalletSolver solver = new CasePalletSolver();
            // build list of solutions
            CasePalletAnalysis analysis = doc.CreateNewCasePalletAnalysis(
                string.Format(Resources.ID_ANALYSISNAME, name, formDefinition.Pallet.Name)
                , string.Format(Resources.ID_ANALYSISDESCRIPTION, name, formDefinition.Pallet.Name)
                , caseInDoc
                , palletInDoc
                , interlayerInDoc
                , null
                , null
                , null
                , null
                , formDefinition.Constraints
                , solver);

            // select solution / generate report / generate StackBuilder file
            FormSelectSolution formSolutions = new FormSelectSolution(doc, analysis);

            if (DialogResult.OK == formSolutions.ShowDialog())
            {
                return;
            }
        }
 public FormNewAnalysisBundle(Document document, CasePalletAnalysis analysis)
     : base(document, analysis)
 {
     InitializeComponent();
     // set unit labels
     UnitsManager.AdaptUnitLabels(this);
     // save document reference
     _document = document;
     _analysis = analysis;
     // set caption text
     if (null != _analysis)
     {
         Text = string.Format(Properties.Resources.ID_EDIT, _analysis.Name);
     }
 }
Example #15
0
 /// <summary>
 /// Constructor used while browsing/editing existing analysis
 /// </summary>
 /// <param name="document">Parent document</param>
 /// <param name="analysis">Analysis</param>
 public FormNewAnalysisLegacy(Document document, CasePalletAnalysis analysis)
 {
     InitializeComponent();
     // set unit labels
     UnitsManager.AdaptUnitLabels(this);
     // save document reference
     _document = document;
     _analysis = analysis;
     // set caption text
     Text = string.Format(Properties.Resources.ID_EDIT, _analysis.Name);
     // update combo boxes
     onInterlayerChecked(this, null);
     onAntiSlipInterlayerChecked(this, null);
     onPalletCornersChecked(this, null);
     onPalletCapChecked(this, null);
     onPalletFilmChecked(this, null);
 }
Example #16
0
 /// <summary>
 /// Process case/pallet analysis
 /// </summary>
 /// <param name="analysis">Pallet analysis to process</param>
 public void ProcessAnalysis(CasePalletAnalysis analysis)
 {
     _bProperties                  = analysis.BProperties;
     _palletProperties             = analysis.PalletProperties;
     _interlayerProperties         = analysis.InterlayerProperties;
     _interlayerPropertiesAntiSlip = analysis.InterlayerPropertiesAntiSlip;
     _cornerProperties             = analysis.PalletCornerProperties;
     _capProperties                = analysis.PalletCapProperties;
     _constraintSet                = analysis.ConstraintSet;
     // check contraint set validity
     if (!_constraintSet.IsValid)
     {
         throw new EngineException("Constraint set is invalid!");
     }
     // generate solutions
     analysis.Solutions = GenerateSolutions();
 }
        private void Compute()
        {
            try
            {
                _document = new Document(_name, _name, "", DateTime.Now, null);
                _analysis = null;
                // bundle
                BundleProperties bundleProperties = _document.CreateNewBundle(_name, _name, FlatLength, FlatWidth, FlatThickness, FlatWeight, Color.Beige, NoFlats);
                // pallet
                PalletProperties palletProp = _document.CreateNewPallet(CurrentPallet);
                // constraint set
                BundlePalletConstraintSet constraintSet = new BundlePalletConstraintSet();
                constraintSet.OverhangX = 0.0;
                constraintSet.OverhangY = 0.0;
                constraintSet.UseMaximumNumberOfCases = false;
                constraintSet.UseMaximumPalletWeight  = false;
                constraintSet.UseMaximumWeightOnBox   = false;
                constraintSet.UseMaximumHeight        = true;
                constraintSet.MaximumHeight           = MaximumPalletHeight;
                constraintSet.AllowAlignedLayers      = true;
                constraintSet.AllowAlternateLayers    = true;
                constraintSet.AllowedPatternString    = "Column,Diagonale,Interlocked,Trilock,Spirale";

                _analysis = _document.CreateNewCasePalletAnalysis(
                    _name, _name
                    , bundleProperties, palletProp
                    , null /*interlayer */, null                          /* interlayerAntiSlip */
                    , null /* palletCorners */, null /*palletCap */, null /* palletFilm */
                    , constraintSet
                    , new treeDiM.StackBuilder.Engine.LayerSolver()
                    );
                // fill grid
                FillGrid();
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
        private void ProcessViewSolution(viewSolution vSol)
        {
            // instantiate graphics
            Graphics3DImage graphics = InitializeImageFromViewParameters(vSol.viewParameters);
            // load analysis
            CasePalletAnalysis analysis = LoadPalletAnalysis(null, vSol.solutionRef.analysisId);

            // compute solutions
            treeDiM.StackBuilder.Engine.CasePalletSolver solver = new treeDiM.StackBuilder.Engine.CasePalletSolver();
            solver.ProcessAnalysis(analysis);
            // retrieve wanted solution
            List <Basics.CasePalletSolution> solutions = analysis.Solutions;

            if (vSol.solutionRef.index >= solutions.Count)
            {
                throw new Exception(string.Format("Analysis {0} has no solution with index {1}", analysis.Name, vSol.solutionRef.index));
            }
            Basics.CasePalletSolution sol = solutions[(int)vSol.solutionRef.index];
            // display solution
            CasePalletSolutionViewer solViewer = new CasePalletSolutionViewer(sol);

            solViewer.Draw(graphics);
            FinalizeImageFromViewParameters(vSol.viewParameters, graphics);
        }
        public void Draw(Graphics3D graphics)
        {
            if (null == _truckSolution)
            {
                throw new Exception("No trucksolution defined!");
            }
            // draw truck
            Truck truck = new Truck(_truckSolution.ParentTruckAnalysis.TruckProperties);

            truck.DrawBegin(graphics);
            truck.DrawEnd(graphics);

            // get pallet height
            CasePalletAnalysis analysis     = _truckSolution.ParentTruckAnalysis.ParentAnalysis;
            double             palletLength = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletLength;
            double             palletWidth  = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletWidth;
            double             palletHeight = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletHeight;

            // get parent pallet solution
            CasePalletSolution sol = _truckSolution.ParentTruckAnalysis.ParentSolution;

            // draw solution
            uint pickIdGlobal = 0;

            for (int i = 0; i < _truckSolution.NoLayers; ++i)
            {
                foreach (BoxPosition bPositionLayer in _truckSolution.Layer)
                {
                    BoxPosition bPalletPosition = new BoxPosition(
                        new Vector3D(
                            bPositionLayer.Position.X
                            , bPositionLayer.Position.Y
                            , bPositionLayer.Position.Z + palletHeight * i)
                        , bPositionLayer.DirectionLength
                        , bPositionLayer.DirectionWidth);
                    if (_showDetails)
                    {
                        // build transformation
                        Transform3D transformPallet = bPalletPosition.Transformation;

                        // draw pallet
                        Pallet pallet = new Pallet(analysis.PalletProperties);
                        pallet.Draw(graphics, transformPallet);

                        // draw solution
                        uint pickId = 0;
                        foreach (ILayer layer in sol)
                        {
                            Layer3DBox bLayer = layer as Layer3DBox;
                            if (null != bLayer)
                            {
                                foreach (BoxPosition bPosition in bLayer)
                                {
                                    graphics.AddBox(new Box(pickId++, analysis.BProperties, BoxPosition.Transform(bPosition, transformPallet)));
                                }
                            }

                            InterlayerPos interlayerPos = layer as InterlayerPos;
                            if (null != interlayerPos)
                            {
                                BoxPosition iPos = new BoxPosition(new Vector3D(0.0, 0.0, interlayerPos.ZLow), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                                graphics.AddBox(new Box(pickId++, analysis.InterlayerProperties, BoxPosition.Transform(iPos, transformPallet)));
                            }
                        }
                    }
                    else
                    {
                        Box b = new Box(pickIdGlobal++, new BoxProperties(null, palletLength, palletWidth, palletHeight), bPalletPosition);
                        b.SetAllFacesColor(Color.Chocolate);
                        graphics.AddBox(b);
                    }
                }
            }

            // fluch
            graphics.UseBoxelOrderer = false; // can not use boxel orderer for full truck view -> too slow...
        }
 public CasePalletSolutionViewer(CasePalletSolution solution)
 {
     _analysis = null != solution ? solution.Analysis : null;
     _solution = solution;
 }
Example #21
0
        /// <summary>
        /// Edit specified pallet analysis
        /// </summary>
        /// <param name="analysis"></param>
        public void EditCasePalletAnalysis(CasePalletAnalysis analysis)
        {
            // do we need to recompute analysis
            bool recomputeRequired = false;

            if (analysis.IsBoxAnalysis)
            {
                FormNewAnalysisLegacy form = new FormNewAnalysisLegacy(this, analysis);
                form.Cases         = Cases.ToArray();
                form.Pallets       = Pallets.ToArray();
                form.Interlayers   = Interlayers.ToArray();
                form.PalletCorners = ListByType(typeof(PalletCornerProperties)).ToArray();
                form.PalletCaps    = ListByType(typeof(PalletCapProperties)).ToArray();
                form.PalletFilms   = ListByType(typeof(PalletFilmProperties)).ToArray();

                if (recomputeRequired = (DialogResult.OK == form.ShowDialog()))
                {
                    // analysis name / description
                    analysis.Name        = form.AnalysisName;
                    analysis.Description = form.AnalysisDescription;
                    // box / palet / interlayer
                    analysis.BProperties                  = form.SelectedBox;
                    analysis.PalletProperties             = form.SelectedPallet;
                    analysis.InterlayerProperties         = form.SelectedInterlayer;
                    analysis.InterlayerPropertiesAntiSlip = form.SelectedInterlayerAntiSlip;
                    // build constraint set
                    CasePalletConstraintSet constraintSet = analysis.ConstraintSet as CasePalletConstraintSet;
                    // overhang / underhang
                    constraintSet.OverhangX = form.OverhangX;
                    constraintSet.OverhangY = form.OverhangY;
                    // allowed axes
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_N, form.AllowVerticalX);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_P, form.AllowVerticalX);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_N, form.AllowVerticalY);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_P, form.AllowVerticalY);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_N, form.AllowVerticalZ);
                    constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_P, form.AllowVerticalZ);
                    // allowed dir change
                    constraintSet.AllowTwoLayerOrientations       = form.AllowTwoLayerOrientations;
                    constraintSet.AllowLastLayerOrientationChange = form.AllowLastLayerOrientationChange;
                    // allowed patterns
                    constraintSet.ClearAllowedPatterns();
                    foreach (string s in form.AllowedPatterns)
                    {
                        constraintSet.SetAllowedPattern(s);
                    }
                    // allow alternate layer
                    constraintSet.AllowAlternateLayers = form.AllowAlternateLayers;
                    constraintSet.AllowAlignedLayers   = form.AllowAlignedLayers;
                    // interlayers
                    constraintSet.HasInterlayer         = form.HasInterlayers;
                    constraintSet.InterlayerPeriod      = form.InterlayerPeriod;
                    constraintSet.HasInterlayerAntiSlip = form.HasInterlayerAntiSlip;
                    // pallet corner
                    analysis.PalletCornerProperties = form.SelectedPalletCorners;
                    // pallet cap
                    analysis.PalletCapProperties = form.SelectedPalletCap;
                    // pallet film
                    analysis.PalletFilmProperties = form.SelectedPalletFilm;
                    // stop criterion
                    constraintSet.UseMaximumHeight        = form.UseMaximumPalletHeight;
                    constraintSet.UseMaximumNumberOfCases = form.UseMaximumNumberOfBoxes;
                    constraintSet.UseMaximumPalletWeight  = form.UseMaximumPalletWeight;
                    constraintSet.UseMaximumWeightOnBox   = form.UseMaximumLoadOnBox;
                    constraintSet.MaximumHeight           = form.MaximumPalletHeight;
                    constraintSet.MaximumNumberOfItems    = form.MaximumNumberOfBoxes;
                    constraintSet.MaximumPalletWeight     = form.MaximumPalletWeight;
                    constraintSet.MaximumWeightOnBox      = form.MaximumLoadOnBox;
                    // number of solution kept
                    constraintSet.UseNumberOfSolutionsKept = Properties.Settings.Default.KeepBestSolutions;
                    if (constraintSet.UseNumberOfSolutionsKept)
                    {
                        constraintSet.NumberOfSolutionsKept = Properties.Settings.Default.NoSolutionsToKeep;
                    }
                    // pallet film turns
                    constraintSet.PalletFilmTurns = form.PalletFilmTurns;
                }
            }
            else if (analysis.IsBundleAnalysis)
            {
                FormNewAnalysisBundle form = new FormNewAnalysisBundle(this, analysis);
                form.Boxes   = Bundles.ToArray();
                form.Pallets = Pallets.ToArray();

                if (recomputeRequired = (DialogResult.OK == form.ShowDialog()))
                {
                    // analysis name / description
                    analysis.Name        = form.ItemName;
                    analysis.Description = form.ItemDescription;
                    // analysis bundle / pallet
                    analysis.BProperties      = form.SelectedBundle;
                    analysis.PalletProperties = form.SelectedPallet;
                    // build constraintSet
                    BundlePalletConstraintSet constraintSet = analysis.ConstraintSet as BundlePalletConstraintSet;
                    // overhang / underhang
                    constraintSet.OverhangX = form.OverhangX;
                    constraintSet.OverhangY = form.OverhangY;
                    // allowed patterns
                    constraintSet.ClearAllowedPatterns();
                    foreach (string s in form.AllowedPatterns)
                    {
                        constraintSet.SetAllowedPattern(s);
                    }
                    // allow aligned / alternate layer
                    constraintSet.AllowAlternateLayers = form.AllowAlternateLayers;
                    constraintSet.AllowAlignedLayers   = form.AllowAlignedLayers;
                    // stop criterions
                    constraintSet.UseMaximumHeight        = form.UseMaximumPalletHeight;
                    constraintSet.UseMaximumNumberOfCases = form.UseMaximumNumberOfBoxes;
                    constraintSet.UseMaximumPalletWeight  = form.UseMaximumPalletWeight;
                    constraintSet.MaximumHeight           = form.MaximumPalletHeight;
                    constraintSet.MaximumNumberOfItems    = form.MaximumNumberOfBoxes;
                    constraintSet.MaximumPalletWeight     = form.MaximumPalletWeight;
                }
            }
            if (recomputeRequired)
            {
                analysis.OnEndUpdate(null);
            }
        }
Example #22
0
 public void OnNewCasePalletAnalysisCreated(Document doc, CasePalletAnalysis analysis)
 {
     _log.Info(string.Format("Loaded analysis {0}", analysis.Name));
 }
Example #23
0
 public FormSelectSolution(Document doc, CasePalletAnalysis analysis)
 {
     _document = doc;
     _analysis = analysis;
     InitializeComponent();
 }
Example #24
0
 public void OnECTAnalysisRemoved(Document doc, CasePalletAnalysis analysis, SelCasePalletSolution selectedSolution, ECTAnalysis ectAnalysis)
 {
 }
Example #25
0
 /*
  * public void OnCaseAnalysisRemoved(Document doc, BoxCasePalletAnalysis caseAnalysis)
  * {
  * }
  */
 public void OnTruckAnalysisRemoved(Document doc, CasePalletAnalysis analysis, SelCasePalletSolution selectedSolution, TruckAnalysis truckAnalysis)
 {
 }
Example #26
0
        /// <summary>
        /// Draw case solution
        /// </summary>
        public void Draw(Graphics3D graphics)
        {
            if (null == _caseSolution)
            {
                throw new Exception("No case solution defined!");
            }

            // load pallet solution
            BoxProperties caseProperties;

            CasePalletSolution palletSolution = _caseSolution.PalletSolutionDesc.LoadPalletSolution();

            if (null == palletSolution)
            {
                caseProperties = new BoxProperties(null, _caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight);
            }
            else
            {
                CasePalletAnalysis palletAnalysis = palletSolution.Analysis;
                // retrieve case properties
                caseProperties = palletAnalysis.BProperties as BoxProperties;
            }
            if (null == caseProperties)
            {
                return;
            }
            // draw case (inside)
            Case case_ = new Case(caseProperties);

            case_.DrawInside(graphics);
            // get case analysis
            BoxCasePalletAnalysis caseAnalysis = _caseSolution.ParentCaseAnalysis;
            // draw solution
            uint pickId = 0;

            foreach (ILayer layer in _caseSolution)
            {
                BoxLayer blayer = layer as BoxLayer;
                if (null != blayer)
                {
                    foreach (BoxPosition bPosition in blayer)
                    {
                        graphics.AddBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition));
                    }
                }

                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    Box box = new Box(pickId++, caseAnalysis.InterlayerProperties);
                    // set position
                    box.Position = new Vector3D(0.0, 0.0, interlayerPos.ZLow);
                    // draw
                    graphics.AddBox(box);
                }
            }
            // get case analysis
            if (_showDimensions)
            {
                graphics.AddDimensions(new DimensionCube(_caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight));
            }
        }
        private CasePalletAnalysis LoadPalletAnalysis(Document doc, string sid)
        {
            CasePalletAnalysis analysis = null;

            palletAnalysis xmlAnalysis = _root.data.analyses.palletAnalysis.Find(delegate(palletAnalysis pa) { return(pa.id == sid); });

            if (null == xmlAnalysis)
            {
                throw new XmlFileProcessorException(string.Format("Failed to load analysis with Id = {0}", xmlAnalysis.id));
            }

            BoxProperties    caseProperties   = LoadCaseById(doc, _root.data.items.library_cases, xmlAnalysis.caseId);
            BundleProperties bundleProperties = LoadBundleById(doc, _root.data.items.library_bundles, xmlAnalysis.bundleId);

            BProperties         bProperties;
            PalletConstraintSet constraintSet;

            if (null != caseProperties)
            {
                CasePalletConstraintSet caseConstraintSet = new CasePalletConstraintSet();
                // interlayer
                caseConstraintSet.HasInterlayer         = xmlAnalysis.interlayerPeriodSpecified;
                caseConstraintSet.HasInterlayerAntiSlip = false;

                // allowed ortho axes
                caseConstraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_N, true);
                caseConstraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_P, true);
                caseConstraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_N, true);
                caseConstraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_P, true);
                caseConstraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_N, true);
                caseConstraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_P, true);

                // interlayer period
                caseConstraintSet.InterlayerPeriod = xmlAnalysis.interlayerPeriodSpecified ? (int)xmlAnalysis.interlayerPeriod : 1;

                bProperties   = caseProperties;
                constraintSet = caseConstraintSet;
            }
            else if (null != bundleProperties)
            {
                BundlePalletConstraintSet bundleConstraintSet = new BundlePalletConstraintSet();

                bProperties   = bundleProperties;
                constraintSet = bundleConstraintSet;
            }
            else
            {
                throw new XmlFileProcessorException(string.Format("Failed to load analysis with Id = {0}", xmlAnalysis.id));
            }

            // generic constraintSet properties
            // allow aligned / alternate layers
            constraintSet.AllowAlignedLayers   = false;
            constraintSet.AllowAlternateLayers = false;
            foreach (layerArrangement layerArr in xmlAnalysis.allowedLayerArrangements)
            {
                if (layerArr == layerArrangement.ALIGNED)
                {
                    constraintSet.AllowAlignedLayers = true;
                }
                if (layerArr == layerArrangement.ROTATED180 | layerArr == layerArrangement.ROTATED90)
                {
                    constraintSet.AllowAlternateLayers = true;
                }
            }
            // allowed patterns
            foreach (patternName pName in xmlAnalysis.allowedLayerPatterns)
            {
                switch (pName)
                {
                case patternName.COLUMN: constraintSet.SetAllowedPattern("Column"); break;

                case patternName.DIAGONAL: constraintSet.SetAllowedPattern("Diagonal"); break;

                case patternName.INTERLOCK: constraintSet.SetAllowedPattern("Interlock"); break;

                case patternName.TRILOCK: constraintSet.SetAllowedPattern("Trilock"); break;

                case patternName.SPIRAL: constraintSet.SetAllowedPattern("Spiral"); break;

                case patternName.ENLARGED_SPIRAL: constraintSet.SetAllowedPattern("Enlarged spiral"); break;

                default: break;
                }
            }
            // overhang
            constraintSet.OverhangX = xmlAnalysis.overhang[0];
            constraintSet.OverhangY = xmlAnalysis.overhang[1];

            // stop criterions
            // max height
            if (xmlAnalysis.stackingStopCriterions.stopMaxHeight.maxHeightSpecified)
            {
                constraintSet.UseMaximumHeight = true;
                constraintSet.MaximumHeight    = xmlAnalysis.stackingStopCriterions.stopMaxHeight.maxHeight;
            }
            else
            {
                constraintSet.UseMaximumHeight = false;
            }
            // max weight
            if (xmlAnalysis.stackingStopCriterions.stopMaxWeight.maxWeightSpecified)
            {
                constraintSet.UseMaximumPalletWeight = true;
                constraintSet.MaximumPalletWeight    = xmlAnalysis.stackingStopCriterions.stopMaxWeight.maxWeight;
            }
            else
            {
                constraintSet.UseMaximumPalletWeight = false;
            }
            // max number of box/bundle
            if (xmlAnalysis.stackingStopCriterions.stopMaxNumber.maxNumberSpecified)
            {
                constraintSet.UseMaximumNumberOfCases = true;
                constraintSet.MaximumNumberOfItems    = (int)xmlAnalysis.stackingStopCriterions.stopMaxNumber.maxNumber;
            }
            else
            {
                constraintSet.UseMaximumNumberOfCases = false;
            }
            // max weight on case
            if (xmlAnalysis.stackingStopCriterions.stopMaxWeightOnCase.maxWeightOnCaseSpecified)
            {
                constraintSet.UseMaximumWeightOnBox = true;
                constraintSet.MaximumWeightOnBox    = xmlAnalysis.stackingStopCriterions.stopMaxWeightOnCase.maxWeightOnCase;
            }
            else
            {
                constraintSet.UseMaximumWeightOnBox = false;
            }

            if (null != doc)
            {
                analysis = doc.CreateNewCasePalletAnalysis(xmlAnalysis.name, xmlAnalysis.description
                                                           , bProperties
                                                           , LoadPalletById(doc, _root.data.items.library_pallets, xmlAnalysis.palletId)
                                                           , LoadInterlayerById(doc, _root.data.items.library_interlayers, xmlAnalysis.interlayerId)
                                                           , LoadInterlayerById(doc, _root.data.items.library_interlayers, xmlAnalysis.interlayerAntiSlipId)
                                                           , null
                                                           , null
                                                           , null
                                                           , constraintSet
                                                           , new treeDiM.StackBuilder.Engine.CasePalletSolver());
            }
            else
            {
                // instantiate pallet analysis
                analysis = new CasePalletAnalysis(
                    bProperties
                    , LoadPalletById(null, _root.data.items.library_pallets, xmlAnalysis.palletId)
                    , LoadInterlayerById(null, _root.data.items.library_interlayers, xmlAnalysis.interlayerId)
                    , null
                    , null
                    , null
                    , null
                    , constraintSet);
                // name
                analysis.Name = xmlAnalysis.name;
                // description
                analysis.Description = xmlAnalysis.description;
            }
            return(analysis);
        }
        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();
                form._listItems   = listItems;
                form._listPallets = listPallets;
                form._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
                        , 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.ConvertLengthFrom(item._length - 0.6, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._width - 0.6, UnitsManager.UnitSystem.UNIT_METRIC2)
                        , UnitsManager.ConvertLengthFrom(item._height - 0.6, 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.ShowTape  = true;
                itemProperties.TapeColor = Color.Beige;
                itemProperties.TapeWidth = 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.ShowTape  = true;
                        intercaseProperties.TapeColor = Color.Beige;
                        intercaseProperties.TapeWidth = 5.0;

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

                if (form.UseIntermediatePacking)
                {
                    // Case constraint set
                    BoxCaseConstraintSet boxCaseConstraintSet = new BoxCaseConstraintSet();
                    boxCaseConstraintSet.SetAllowedOrthoAxisAll();
                    if (boxCaseConstraintSet.IsValid)
                    {
                        // create case analysis
                        BoxCaseAnalysis analysis = document.CreateNewBoxCaseAnalysis(
                            string.Format(Properties.Resources.ID_PACKING, item._ref)
                            , item._description
                            , itemProperties
                            , currentCase
                            , boxCaseConstraintSet
                            , new BoxCaseSolver());
                    }
                }

                // 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));
                    if (string.Equals(form._currentPallet._type, pallet._type))
                    {
                        currentPallet = palletProperties;
                    }
                }

                // *** pallet analysis ***
                // constraint set
                CasePalletConstraintSet constraintSet = new CasePalletConstraintSet();
                constraintSet.UseMaximumHeight = true;
                constraintSet.MaximumHeight    = UnitsManager.ConvertLengthFrom(form.PalletHeight, UnitsManager.UnitSystem.UNIT_METRIC2);
                constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_P, true);
                constraintSet.AllowAlignedLayers   = true;
                constraintSet.AllowAlternateLayers = true;
                constraintSet.SetAllowedPattern("Column");
                constraintSet.SetAllowedPattern("Diagonale");
                constraintSet.SetAllowedPattern("Interlocked");
                constraintSet.SetAllowedPattern("Trilock");
                constraintSet.SetAllowedPattern("Spirale");
                constraintSet.SetAllowedPattern("Enlarged spirale");
                if (constraintSet.IsValid)
                {
                    // create analysis
                    CasePalletSolver   solver         = new CasePalletSolver();
                    CasePalletAnalysis palletAnalysis = document.CreateNewCasePalletAnalysis(
                        item._ref, item.ToString()
                        , form.UseIntermediatePacking ? currentCase : itemProperties
                        , currentPallet,
                        null, null,
                        null, null, null,
                        constraintSet, solver);
                }
                // save document
                fileName = form.FilePath;
                document.Write(form.FilePath);
                // return true to let application open
                return(File.Exists(fileName));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
Example #29
0
        private bool GenerateProject(out Document doc, out CasePalletAnalysis analysis, out CasePalletSolution casePalletSolution)
        {
            doc                = null;
            analysis           = null;
            casePalletSolution = null;

            try
            {
                // build solution
                doc = new Document(
                    _boxName,
                    string.Format(Properties.Resources.ID_OPTDOCUMENTDESCRIPTION, _boxName),
                    string.Empty,
                    DateTime.Now,
                    null);
                // box
                BoxProperties boxProperties = doc.CreateNewBox(SelectedBox);
                // pallet
                PalletProperties palletProperties = doc.CreateNewPallet(SelectedPallet);
                // get selected caseOptimSolution
                CaseOptimSolution sol         = SelectedSolution;
                PackArrangement   arrangement = sol.CaseDefinition.Arrangement;
                // build new case name
                string arrangName = string.Format("{0}_{1}x{2}x{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(
                    Properties.Resources.ID_OPTCASEDESCRIPTION
                    , boxProperties.Name
                    , palletProperties.Name);
                // add new case
                CaseOfBoxesProperties caseProperties = doc.CreateNewCaseOfBoxes(
                    arrangName, description
                    , boxProperties
                    , sol.CaseDefinition
                    , BuildCaseOptimConstraintSet());
                // set color
                caseProperties.SetColor(Color.Chocolate);
                // add new pallet analysis
                string analysisName = string.Format(
                    Properties.Resources.ID_OPTANALYSISNAME
                    , boxProperties.Name
                    , boxProperties.Name
                    , arrangement._iLength
                    , arrangement._iWidth
                    , arrangement._iHeight
                    , sol.CaseDefinition.Dim0
                    , sol.CaseDefinition.Dim1);
                string analysisDescription = string.Format(
                    Properties.Resources.ID_OPTANALYSISDESCRIPTION
                    , boxProperties.Name
                    , palletProperties.Name);
                List <CasePalletSolution> palletSolutionList = new List <CasePalletSolution>();
                palletSolutionList.Add(sol.PalletSolution);
                analysis = doc.CreateNewCasePalletAnalysis(
                    analysisName
                    , analysisDescription
                    , caseProperties
                    , palletProperties
                    , null
                    , null
                    , null
                    , null
                    , null
                    , BuildPalletConstraintSet()
                    , palletSolutionList);
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
                return(false);
            }
            return(true);
        }
Example #30
0
        private static void RunBoxTest(bool useSingleColor, Document doc, PalletProperties palletProperties)
        {
            // define box properties
            var boxProperties = new BoxProperties(doc, 162, 210, 250);

            //boxProperties.Name = "Box1";
            boxProperties.SetWeight(3.0);
            if (!useSingleColor)
            {
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_X_N, Color.Red);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_X_P, Color.Red);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_Y_N, Color.Green);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_Y_P, Color.Green);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_Z_N, Color.Blue);
                boxProperties.SetColor(HalfAxis.HAxis.AXIS_Z_P, Color.Blue);
            }
            else
            {
                boxProperties.SetColor(Color.Chocolate);
            }

            Console.WriteLine(boxProperties.ToString());


            InterlayerProperties interlayerProperties = null;

            // define constraints
            var constraintSet = new CasePalletConstraintSet();

            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_N, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_X_P, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_N, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Y_P, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_N, true);
            constraintSet.SetAllowedOrthoAxis(HalfAxis.HAxis.AXIS_Z_P, true);

            constraintSet.SetAllowedPattern("Trilock");

            constraintSet.AllowAlignedLayers   = true;
            constraintSet.AllowAlternateLayers = false;

            constraintSet.MaximumPalletWeight             = 2000;
            constraintSet.MaximumNumberOfItems            = 2000;
            constraintSet.MaximumHeight                   = 2000.0;
            constraintSet.UseMaximumHeight                = true;
            constraintSet.UseMaximumPalletWeight          = true;
            constraintSet.UseMaximumWeightOnBox           = false;
            constraintSet.AllowLastLayerOrientationChange = true;
            Console.WriteLine("=== Constraint set ===");
            Console.WriteLine(constraintSet.ToString());

            // initialize analysis
            var analysis = new CasePalletAnalysis(
                boxProperties, palletProperties, interlayerProperties,
                null, null, null, null,
                constraintSet);

            // initialize solver
            var solver = new CasePalletSolver();

            solver.ProcessAnalysis(analysis);

            Console.WriteLine("=== Solutions ===");
            int solIndex = 0;

            foreach (CasePalletSolution sol in analysis.Solutions)
            {
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(1000, 1000));
                graphics.CameraPosition = new Vector3D(10000.0, 10000.0, 10000.0);
                graphics.Target         = Vector3D.Zero;
                graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f);
                // instantiate solution viewer
                CasePalletSolutionViewer sv = new CasePalletSolutionViewer(sol);
                sv.Draw(graphics);
                graphics.Flush();
                // save
                string fileName = string.Format("Pallet_{0}.bmp", solIndex++);
                string filePath = Path.Combine(Path.GetTempPath(), fileName);
                Console.WriteLine("Saving file " + filePath + "...");
                graphics.SaveAs(filePath);
            }
        }