public DockContentReport(IDocument document, ReportData reportObject, string htmlFilePath)
        {
            _document = document;
            _reportObject = reportObject;
            _reportObject.AddListener(this);
            _htmlFilePath = htmlFilePath;

            InitializeComponent();
        }
        public ReporterMSWord(ReportData inputData
            , string templatePath, string outputFilePath, Margins margins)
        {
            // absolute output file path
            string absOutputFilePath = string.Empty;
            if (Path.IsPathRooted(outputFilePath))
                absOutputFilePath = outputFilePath;
            else
                absOutputFilePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), outputFilePath));
            // absolute template path
            string absTemplatePath = string.Empty;
            if (Path.IsPathRooted(templatePath))
                absTemplatePath = templatePath;
            else
                absTemplatePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), templatePath));

            // does output directory exists
            string outDir = Path.GetDirectoryName(absOutputFilePath);
            if (!Directory.Exists(outDir))
            {
                try { Directory.CreateDirectory(outDir); }
                catch (System.UnauthorizedAccessException /*ex*/)
                { throw new UnauthorizedAccessException(string.Format("User not allowed to write under {0}", Directory.GetParent(outDir).FullName)); }
                catch (Exception ex)
                { throw new Exception(string.Format("Directory {0} does not exist, and could not be created.", outDir), ex); }
            }
            // html file path
            string htmlFilePath = Path.ChangeExtension(absOutputFilePath, "html");
            BuildAnalysisReport(inputData, absTemplatePath, htmlFilePath);
            // opens word
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
            wordApp.Visible = true;
            Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(htmlFilePath, false, true, NoEncodingDialog: true);
            // embed pictures (unlinking images)
            for (int i = 1; i <= wordDoc.InlineShapes.Count; ++i)
            {
                if (null != wordDoc.InlineShapes[i].LinkFormat && !wordDoc.InlineShapes[i].LinkFormat.SavePictureWithDocument)
                    wordDoc.InlineShapes[i].LinkFormat.SavePictureWithDocument = true;
            }
            // set margins (unit?)
            wordDoc.PageSetup.TopMargin = wordApp.CentimetersToPoints(margins.Top);
            wordDoc.PageSetup.BottomMargin = wordApp.CentimetersToPoints(margins.Bottom);
            wordDoc.PageSetup.RightMargin = wordApp.CentimetersToPoints(margins.Right);
            wordDoc.PageSetup.LeftMargin = wordApp.CentimetersToPoints(margins.Left);
            // set print view
            wordApp.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView;
            wordDoc.SaveAs(absOutputFilePath, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault);
            _log.Info(string.Format("Saved doc report to {0}", outputFilePath));
            // delete image directory
            DeleteImageDirectory();
            // delete html report
            File.Delete(htmlFilePath);
        }
Example #3
0
 public void BuildAnalysisReport(ReportData inputData, string reportTemplatePath, string outputFilePath)
 {
     // verify if inputData is a valid entry
     if (!inputData.IsValid)
         throw new Exception("Reporter.BuildAnalysisReport(): ReportData argument is invalid!");
     // absolute path
     string absOutputFilePath = ToAbsolute(outputFilePath);
     string absReportTemplatePath = ToAbsolute(reportTemplatePath);
     // create directory if needed
     ImageDirectory = Path.Combine(Path.GetDirectoryName(absOutputFilePath), "Images");
     if (WriteImageFiles && !Directory.Exists(ImageDirectory))
         Directory.CreateDirectory(ImageDirectory);
     // create xml data file + XmlTextReader
     string xmlFilePath = Path.ChangeExtension(System.IO.Path.GetTempFileName(), "xml");
     CreateAnalysisDataFile(inputData, xmlFilePath, WriteNamespace);
     XmlTextReader xmlData = new XmlTextReader(new FileStream(xmlFilePath, FileMode.Open, FileAccess.Read));
     // validate against schema
     // note xml file validation against xml schema produces a large number of errors
     // For the moment, I can not remove all errors
     if (_validateAgainstSchema)
         Reporter.ValidateXmlDocument(xmlData, Path.Combine(Path.GetDirectoryName(absReportTemplatePath), "ReportSchema.xsd"));
     // check availibility of files
     if (!File.Exists(absReportTemplatePath))
         throw new System.IO.FileNotFoundException(string.Format("Report template path ({0}) is invalid", absReportTemplatePath));
     // load generated xslt
     XmlTextReader xsltReader = new XmlTextReader(new FileStream(absReportTemplatePath, FileMode.Open, FileAccess.Read));
     string threeLetterLanguageAbbrev = System.Globalization.CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName;
     if (!File.Exists(Path.Combine(Path.GetDirectoryName(absReportTemplatePath), threeLetterLanguageAbbrev + ".xml")))
     {
         _log.Warn(string.Format("Language file {0}.xml could not be found! Trying ENU.xml...", threeLetterLanguageAbbrev));
         threeLetterLanguageAbbrev = "ENU";
     }
     if (!File.Exists(Path.Combine(Path.GetDirectoryName(absReportTemplatePath), threeLetterLanguageAbbrev + ".xml")))
         _log.Warn(string.Format("Language file {0}.xml could not be found!", threeLetterLanguageAbbrev));
     // generate word document
     byte[] wordDoc = GetReport(xmlData, xsltReader, Path.Combine(Path.GetDirectoryName(absReportTemplatePath), threeLetterLanguageAbbrev));
     // write resulting array to HDD, show process information
     using (FileStream fs = new FileStream(absOutputFilePath, FileMode.Create))
         fs.Write(wordDoc, 0, wordDoc.Length);
 }
Example #4
0
        private void AppendTruckSolutionElement(ReportData inputData, XmlElement elemTruckAnalysis, XmlDocument xmlDoc)
        {
            string ns = xmlDoc.DocumentElement.NamespaceURI;

            CasePalletSolution palletSolution = inputData.CasePalletSolution;
            TruckAnalysis truckAnalysis = inputData.SelSolution.TruckAnalyses[0];

            // retrieve selected truckSolution
            TruckSolution truckSolution = truckAnalysis.SelectedSolution;
            if (null == truckSolution) return;
            // create "truckSolution" element
            XmlElement elemTruckSolution = xmlDoc.CreateElement("truckSolution", ns);
            elemTruckAnalysis.AppendChild(elemTruckSolution);
            if (!string.IsNullOrEmpty(truckSolution.Title))
            {
                // title
                XmlElement elemTitle = xmlDoc.CreateElement("title", ns);
                elemTitle.InnerText = truckSolution.Title;
                elemTruckSolution.AppendChild(elemTitle);
            }
            // palletCount
            XmlElement elemPalletCount = xmlDoc.CreateElement("palletCount", ns);
            elemPalletCount.InnerText = string.Format("{0}", truckSolution.PalletCount);
            elemTruckSolution.AppendChild(elemPalletCount);
            // boxCount
            XmlElement elemBoxCount = xmlDoc.CreateElement("caseCount", ns);
            elemBoxCount.InnerText = string.Format("{0}", truckSolution.BoxCount);
            elemTruckSolution.AppendChild(elemBoxCount);

            double loadWeight = truckSolution.PalletCount * inputData.ActualPalletWeight;
            AppendElementValue(xmlDoc, elemTruckSolution, "loadWeight", UnitsManager.UnitType.UT_MASS, loadWeight);

            // loadEfficiency
            XmlElement elemLoadEfficiency = xmlDoc.CreateElement("loadEfficiency", ns);
            elemLoadEfficiency.InnerText = string.Format("{0:F}", 100.0 * loadWeight / truckAnalysis.TruckProperties.AdmissibleLoadWeight);
            elemTruckSolution.AppendChild(elemLoadEfficiency);
            // volumeEfficiency
            XmlElement elemVolumeEfficiency = xmlDoc.CreateElement("volumeEfficiency", ns);
            elemVolumeEfficiency.InnerText = string.Format("{0:F}", truckSolution.Efficiency);
            elemTruckSolution.AppendChild(elemVolumeEfficiency);

            // --- truck images
            for (int i = 0; i < 2; ++i)
            {
                // initialize drawing values
                string viewName = string.Empty;
                Vector3D cameraPos = Vector3D.Zero;
                int imageWidth = ImageSizeWide;
                switch (i)
                {
                    case 0: viewName = "view_trucksolution_top"; cameraPos = Graphics3D.Top; imageWidth = ImageSizeWide; break;
                    case 1: viewName = "view_trucksolution_iso"; cameraPos = Graphics3D.Corner_0; imageWidth = ImageSizeWide; break;
                    default: break;
                }
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(imageWidth, imageWidth));
                // set camera position
                graphics.CameraPosition = cameraPos;
                // dimensions
                if (1 == i)
                {
                    TruckProperties truckProp = truckSolution.ParentTruckAnalysis.TruckProperties;
                    graphics.AddDimensions(new DimensionCube(truckSolution.LoadBoundingBox, Color.Red, false));
                    graphics.AddDimensions(new DimensionCube(Vector3D.Zero, truckProp.Length, truckProp.Width, truckProp.Height, Color.Black, true));
                }
                // instantiate solution viewer
                TruckSolutionViewer sv = new TruckSolutionViewer(truckSolution);
                sv.Draw(graphics);
                graphics.Flush();
                // ---
                XmlElement elemImage = xmlDoc.CreateElement(viewName, ns);
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
                XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
                styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 3, graphics.Bitmap.Height / 3);
                elemImage.Attributes.Append(styleAttribute);
                elemTruckSolution.AppendChild(elemImage);
                // Save image ?
                SaveImageAs(graphics.Bitmap, viewName + ".png");
            }
        }
Example #5
0
        private void AppendTruckAnalysisElement(ReportData inputData, XmlElement elemDocument, XmlDocument xmlDoc)
        {
            if (!inputData.IsCasePalletAnalysis) return;
            CasePalletAnalysis analysis = inputData.CasePalletAnalysis;
            SelCasePalletSolution selSolution = inputData.SelSolution;

            // retrieve truck analysis if any
            if (!selSolution.HasTruckAnalyses) return;  // no truck analysis available -> exit

            string ns = xmlDoc.DocumentElement.NamespaceURI;
            // truckAnalysis
            XmlElement elemTruckAnalysis = xmlDoc.CreateElement("truckAnalysis", ns);
            elemDocument.AppendChild(elemTruckAnalysis);

            TruckAnalysis truckAnalysis = selSolution.TruckAnalyses[0];
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = analysis.Name;
            elemTruckAnalysis.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = analysis.Description;
            elemTruckAnalysis.AppendChild(elemDescription);
            // truck
            AppendTruckElement(truckAnalysis, elemTruckAnalysis, xmlDoc);
            // solution
            AppendTruckSolutionElement(inputData, elemTruckAnalysis, xmlDoc);
        }
Example #6
0
        private void AppendSolutionElement(ReportData inputData, XmlElement elemPalletAnalysis, XmlDocument xmlDoc)
        {
            string ns = xmlDoc.DocumentElement.NamespaceURI;

            SelCasePalletSolution selSolution = inputData.SelSolution;
            CasePalletSolution sol = inputData.CasePalletSolution;

            // solution
            XmlElement elemSolution = xmlDoc.CreateElement("palletSolution", ns);
            elemPalletAnalysis.AppendChild(elemSolution);
            // title
            XmlElement elemTitle = xmlDoc.CreateElement("title", ns);
            elemTitle.InnerText = sol.Title;
            elemSolution.AppendChild(elemTitle);
            // homogeneousLayer
            XmlElement elemHomogeneousLayer = xmlDoc.CreateElement("homogeneousLayer", ns);
            elemHomogeneousLayer.InnerText = sol.HasHomogeneousLayers.ToString();
            elemSolution.AppendChild(elemHomogeneousLayer);
            // efficiency
            XmlElement elemEfficiency = xmlDoc.CreateElement("efficiency", ns);
            elemEfficiency.InnerText = string.Format("{0:F}", sol.VolumeEfficiencyCases);
            elemSolution.AppendChild(elemEfficiency);

            AppendElementValue(xmlDoc, elemSolution, "palletWeight", UnitsManager.UnitType.UT_MASS, inputData.ActualPalletWeight);
            AppendElementValue(xmlDoc, elemSolution, "palletLength", UnitsManager.UnitType.UT_LENGTH, sol.PalletLength);
            AppendElementValue(xmlDoc, elemSolution, "palletWidth", UnitsManager.UnitType.UT_LENGTH, sol.PalletWidth);
            AppendElementValue(xmlDoc, elemSolution, "palletHeight", UnitsManager.UnitType.UT_LENGTH, sol.PalletHeight);

            // caseCount
            XmlElement elemCaseCount = xmlDoc.CreateElement("caseCount", ns);
            elemCaseCount.InnerText = string.Format("{0}", sol.CaseCount);
            elemSolution.AppendChild(elemCaseCount);
            // if case of boxes, add box count + box efficiency
            if (sol.Analysis.BProperties is CaseOfBoxesProperties)
            {
                CaseOfBoxesProperties caseOfBoxes = sol.Analysis.BProperties as CaseOfBoxesProperties;
                XmlElement elemBoxCount = xmlDoc.CreateElement("boxCount", ns);
                elemBoxCount.InnerText = string.Format("{0:F}", caseOfBoxes.NumberOfBoxes);
                elemSolution.AppendChild(elemBoxCount);
                XmlElement elemBoxEfficiency = xmlDoc.CreateElement("boxEfficiency", ns);
                elemBoxEfficiency.InnerText = string.Format("{0:F}", sol.VolumeEfficiencyCases);
            }
            // layerCount
            XmlElement elemLayerCount = xmlDoc.CreateElement("layerCount", ns);
            elemLayerCount.InnerText = string.Format("{0}", sol.CaseLayersCount);
            elemSolution.AppendChild(elemLayerCount);
            // layer1_caseCount / layer2_caseCount
            XmlElement elemLayer1_caseCount = xmlDoc.CreateElement("layer1_caseCount", ns);
            elemLayer1_caseCount.InnerText = string.Format("{0}", sol.CaseLayerFirst.BoxCount);
            elemSolution.AppendChild(elemLayer1_caseCount);
            if (sol.Count > 1 && (sol.CaseLayerFirst.BoxCount != sol.CaseLayerSecond.BoxCount))
            {
                XmlElement elemLayer2_caseCount = xmlDoc.CreateElement("layer2_caseCount", ns);
                elemLayer2_caseCount.InnerText = string.Format("{0}", sol.CaseLayerSecond.BoxCount);
                elemSolution.AppendChild(elemLayer2_caseCount);
            }
            // interlayer count
            if (sol.Analysis.ConstraintSet.HasInterlayer)
            {
                XmlElement elemInterlayerCount = xmlDoc.CreateElement("interlayerCount", ns);
                elemInterlayerCount.InnerText = string.Format("{0}", sol.InterlayerCount);
                elemSolution.AppendChild(elemInterlayerCount);
            }
            // --- layer images
            for (int i = 0; i < Math.Min(sol.Count, (sol.HasHomogeneousLayers ? 1 : 2)); ++i)
            {
                XmlElement elemLayer = xmlDoc.CreateElement("layer", ns);
                // layerId
                XmlElement xmlLayerId = xmlDoc.CreateElement("layerId", ns);
                xmlLayerId.InnerText = string.Format("{0}", i + 1);
                elemLayer.AppendChild(xmlLayerId);
                // --- build layer image
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail));
                // set camera position
                graphics.CameraPosition = Graphics3D.Top;
                // instantiate solution viewer
                CasePalletSolutionViewer sv = new CasePalletSolutionViewer(sol);
                sv.DrawLayers(graphics, true, i /* layer index*/);
                // ---
                // layerImage
                XmlElement elemLayerImage = xmlDoc.CreateElement("layerImage", ns);
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                elemLayerImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
                XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
                styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 2, graphics.Bitmap.Height / 2);
                elemLayerImage.Attributes.Append(styleAttribute);
                elemLayer.AppendChild(elemLayerImage);
                // layerCaseCount
                XmlElement elemLayerBoxCount = xmlDoc.CreateElement("layerCaseCount", ns);
                elemLayerBoxCount.InnerText = sol[i].BoxCount.ToString();
                elemLayer.AppendChild(elemLayerBoxCount);

                elemSolution.AppendChild(elemLayer);
                // save image
                SaveImageAs(graphics.Bitmap, string.Format("layerImage{0}.png", i + 1));
            }
            // --- pallet images
            for (int i = 0; i < 5; ++i)
            {
                // initialize drawing values
                string viewName = string.Empty;
                Vector3D cameraPos = Vector3D.Zero;
                int imageWidth = ImageSizeDetail;
                bool showDimensions = false;
                switch (i)
                {
                    case 0:
                        viewName = "view_palletsolution_front"; cameraPos = Graphics3D.Front; imageWidth = ImageSizeDetail;
                        break;
                    case 1:
                        viewName = "view_palletsolution_left"; cameraPos = Graphics3D.Left; imageWidth = ImageSizeDetail;
                        break;
                    case 2:
                        viewName = "view_palletsolution_right"; cameraPos = Graphics3D.Right; imageWidth = ImageSizeDetail;
                        break;
                    case 3:
                        viewName = "view_palletsolution_back"; cameraPos = Graphics3D.Back; imageWidth = ImageSizeDetail;
                        break;
                    case 4:
                        viewName = "view_palletsolution_iso"; cameraPos = Graphics3D.Corner_180; imageWidth = ImageSizeWide; showDimensions = true;
                        break;
                    default:
                        break;
                }
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(imageWidth, imageWidth));
                // set camera position
                graphics.CameraPosition = cameraPos;
                // instantiate solution viewer
                CasePalletSolutionViewer sv = new CasePalletSolutionViewer(sol);
                sv.ShowDimensions = showDimensions;
                sv.Draw(graphics);
                graphics.Flush();
                SaveImageAs(graphics.Bitmap, viewName + ".png");
                // ---
                XmlElement elemImage = xmlDoc.CreateElement(viewName, ns);
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
                XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
                styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 3, graphics.Bitmap.Height / 3);
                elemImage.Attributes.Append(styleAttribute);
                elemSolution.AppendChild(elemImage);
            }
        }
Example #7
0
 private void DocumentTreeView_SolutionReportNodeClicked(object sender, AnalysisTreeViewEventArgs eventArg)
 {
     try
     {
         // build analysis name
         string analysisName = string.Empty;
         if (null != eventArg.Analysis) analysisName = eventArg.Analysis.Name;
         else if (null != eventArg.PackPalletAnalysis) analysisName = eventArg.PackPalletAnalysis.Name;
         else if (null != eventArg.BoxCaseAnalysis) analysisName = eventArg.BoxCaseAnalysis.Name;
         else if (null != eventArg.BoxCasePalletAnalysis) analysisName = eventArg.BoxCasePalletAnalysis.Name;
         else if (null != eventArg.CylinderAnalysis) analysisName = eventArg.CylinderAnalysis.Name;
         else if (null != eventArg.HCylinderAnalysis) analysisName = eventArg.HCylinderAnalysis.Name;
         else
         {
             _log.Error("Unsupported analysis type ?");
             return;
         }
         // save file dialog
         SaveFileDialog dlg = new SaveFileDialog();
         dlg.InitialDirectory = Properties.Settings.Default.ReportInitialDirectory;
         dlg.FileName = Path.ChangeExtension(CleanString(analysisName), "doc");
         dlg.Filter = Resources.ID_FILTER_MSWORD;
         dlg.DefaultExt = "doc";
         dlg.ValidateNames = true;
         if (DialogResult.OK == dlg.ShowDialog())
         {
             // build output file path
             string outputFilePath = dlg.FileName;
             string htmlFilePath = Path.ChangeExtension(outputFilePath, "html");
             // save directory
             Properties.Settings.Default.ReportInitialDirectory = Path.GetDirectoryName(dlg.FileName);
             // getting current culture
             string cultAbbrev = System.Globalization.CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName;
             // build report
             ReportData reportObject = new ReportData(
                     eventArg.Analysis, eventArg.SelSolution
                     , eventArg.CylinderAnalysis, eventArg.SelCylinderPalletSolution
                     , eventArg.HCylinderAnalysis, eventArg.SelHCylinderPalletSolution
                     , eventArg.BoxCaseAnalysis, eventArg.SelBoxCaseSolution
                     , eventArg.BoxCasePalletAnalysis, eventArg.SelBoxCasePalletSolution
                     , eventArg.PackPalletAnalysis, eventArg.SelPackPalletSolution
                     );
             Reporter.CompanyLogo = Properties.Settings.Default.CompanyLogoPath;
             Reporter.ImageSizeSetting = (Reporter.eImageSize)Properties.Settings.Default.ReporterImageSize;
             ReporterMSWord reporter = new ReporterMSWord(
                 reportObject
                 , Settings.Default.ReportTemplatePath
                 , dlg.FileName
                 , new Margins());
         }
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
         _log.Error("MS Word not installed? : "+ ex.Message);
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }
Example #8
0
        private void AppendCaseAnalysisElement(ReportData inputData, XmlElement elemDocument, XmlDocument xmlDoc)
        {
            // check if case analysis
            if (!inputData.IsBoxCasePalletAnalysis)
                return;
            BoxCasePalletAnalysis caseAnalysis = inputData.CaseAnalysis;
            SelBoxCasePalletSolution selSolution = inputData.SelCaseSolution;

            if (null == selSolution.Solution.PalletSolutionDesc.LoadPalletSolution())
                return;

            // namespace
            string ns = xmlDoc.DocumentElement.NamespaceURI;
            // caseAnalysis
            XmlElement elemCaseAnalysis = xmlDoc.CreateElement("boxCasePalletAnalysis", ns);
            elemDocument.AppendChild(elemCaseAnalysis);
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = caseAnalysis.Name;
            elemCaseAnalysis.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = caseAnalysis.Description;
            elemCaseAnalysis.AppendChild(elemDescription);
            // box
            AppendBoxElement(caseAnalysis.BoxProperties, elemCaseAnalysis, xmlDoc);
            // case
            AppendCaseElement(selSolution, elemCaseAnalysis, xmlDoc);
            // constraint set
            AppendCaseConstraintSet(caseAnalysis, elemCaseAnalysis, xmlDoc);
            // case solution
            AppendCaseSolutionElement(selSolution, elemCaseAnalysis, xmlDoc);
        }
Example #9
0
        private void AppendHCylinderPalletAnalysisElement(ReportData inputData, XmlElement elemDocument, XmlDocument xmlDoc)
        {
            if (!inputData.IsHCylinderPalletAnalysis)
                return;
            string ns = xmlDoc.DocumentElement.NamespaceURI;
            // cylinder/pallet analysis
            HCylinderPalletAnalysis analysis = inputData.HCylinderPalletAnalysis;
            SelHCylinderPalletSolution selSolution = inputData.SelHCylinderPalletSolution;

            // cylinder/pallet analysis
            XmlElement elemCylinderPalletAnalysis = xmlDoc.CreateElement("hCylinderPalletAnalysis", ns);
            elemDocument.AppendChild(elemCylinderPalletAnalysis);
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = analysis.Name;
            elemCylinderPalletAnalysis.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = analysis.Description;
            elemCylinderPalletAnalysis.AppendChild(elemDescription);
            // pallet
            AppendPalletElement(analysis.PalletProperties, elemCylinderPalletAnalysis, xmlDoc);
            // cylinder
            AppendCylinderElement(analysis.CylinderProperties, elemCylinderPalletAnalysis, xmlDoc);
            // constraintSet
            AppendHCylinderPalletConstraintSet(analysis.ConstraintSet, elemCylinderPalletAnalysis, xmlDoc);
            // solution
            AppendHCylinderPalletSolutionElement(inputData, elemCylinderPalletAnalysis, xmlDoc);
        }
Example #10
0
        private void AppendEctAnalysisElement(ReportData inputData, XmlElement elemDocument, XmlDocument xmlDoc)
        {
            if (!inputData.IsCasePalletAnalysis)
                return;
            CasePalletAnalysis analysis = inputData.CasePalletAnalysis;
            SelCasePalletSolution selSolution = inputData.SelSolution;

            // retrieve ect analysis if any
            if (!selSolution.HasECTAnalyses) return;

            string ns = xmlDoc.DocumentElement.NamespaceURI;
            // ectAnalysis
            XmlElement elemEctAnalysis = xmlDoc.CreateElement("ectAnalysis", ns);
            elemDocument.AppendChild(elemEctAnalysis);

            ECTAnalysis ectAnalysis = selSolution.EctAnalyses[0];
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = ectAnalysis.Name;
            elemEctAnalysis.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = ectAnalysis.Description;
            elemEctAnalysis.AppendChild(elemDescription);
             // cardboard
            XmlElement elemCardboard = xmlDoc.CreateElement("cardboard", ns);
            elemEctAnalysis.AppendChild(elemCardboard);
            XmlElement elemCardboardName = xmlDoc.CreateElement("name", ns);
            elemCardboardName.InnerText = ectAnalysis.Cardboard.Name;
            elemCardboard.AppendChild(elemCardboardName);

            AppendElementValue(xmlDoc, elemCardboard, "thickness", UnitsManager.UnitType.UT_LENGTH, ectAnalysis.Cardboard.Thickness);

            XmlElement elemCardboadECT = xmlDoc.CreateElement("ect", ns);
            elemCardboadECT.InnerText = string.Format("{0:0.00}", ectAnalysis.Cardboard.ECT);
            elemCardboard.AppendChild(elemCardboadECT);
            XmlElement elemCardboardStiffnessX = xmlDoc.CreateElement("stiffnessX", ns);
            elemCardboardStiffnessX.InnerText = string.Format("{0:0.00}", ectAnalysis.Cardboard.RigidityDX);
            elemCardboard.AppendChild(elemCardboardStiffnessX);
            XmlElement elemCardboardStiffnessY = xmlDoc.CreateElement("stiffnessY", ns);
            elemCardboardStiffnessY.InnerText = string.Format("{0:0.00}", ectAnalysis.Cardboard.RigidityDY);
            elemCardboard.AppendChild(elemCardboardStiffnessY);
            // case type
            XmlElement elemCaseType = xmlDoc.CreateElement("caseType", ns);
            elemCaseType.InnerText = ectAnalysis.CaseType;
            elemEctAnalysis.AppendChild(elemCaseType);
            // printed surface
            XmlElement elemPrintedSurface = xmlDoc.CreateElement("printedSurface", ns);
            elemPrintedSurface.InnerText = ectAnalysis.PrintSurface;
            elemEctAnalysis.AppendChild(elemPrintedSurface);
            // mc kee formula mode
            XmlElement elemMcKeeFormula = xmlDoc.CreateElement("mcKeeFormulaMode", ns);
            elemMcKeeFormula.InnerText = ectAnalysis.McKeeFormulaText;
            elemEctAnalysis.AppendChild(elemMcKeeFormula);
            // bct_static
            XmlElement elemStaticBCT = xmlDoc.CreateElement("bct_static", ns);
            elemEctAnalysis.AppendChild(elemStaticBCT);
            XmlElement elemStaticValue = xmlDoc.CreateElement("static_value", ns);
            elemStaticValue.InnerText = string.Format("{0:0.00}", ectAnalysis.StaticBCT);
            elemStaticBCT.AppendChild(elemStaticValue);
            // bct_dynamic
            XmlElement elemDynamicBCT = xmlDoc.CreateElement("bct_dynamic", ns);
            elemEctAnalysis.AppendChild(elemDynamicBCT);
            Dictionary<KeyValuePair<string, string>, double> ectDictionary = ectAnalysis.DynamicBCTDictionary;
            foreach (string storageKey in TreeDim.EdgeCrushTest.McKeeFormula.StockCoefDictionary.Keys)
            {
                XmlElement elemBCTStorage = xmlDoc.CreateElement("bct_dynamic_storage", ns);
                elemDynamicBCT.AppendChild(elemBCTStorage);
                // duration
                XmlElement elemStorageDuration = xmlDoc.CreateElement("duration", ns);
                elemStorageDuration.InnerText = storageKey;
                elemBCTStorage.AppendChild(elemStorageDuration);
                // humidity rate -> values
                string[] elementHumidityNames
                    = {
                      "humidity_0_45"
                      , "humidity_46_55"
                      , "humidity_56_65"
                      , "humidity_66_75"
                      , "humidity_76_85"
                      , "humidity_86_100"
                   };
                int indexHumidity = 0;
                foreach (string humidityKey in TreeDim.EdgeCrushTest.McKeeFormula.HumidityCoefDictionary.Keys)
                {
                    // get value of ect for "storage time" + "humidity"
                    double ectValue = ectDictionary[new KeyValuePair<string, string>(storageKey, humidityKey)];
                    XmlElement elemHumidity = xmlDoc.CreateElement(elementHumidityNames[indexHumidity++], ns);
                    elemHumidity.InnerText = string.Format("{0:0.00}", ectValue);
                    elemBCTStorage.AppendChild(elemHumidity);

                    // attribute stating if value is correct or below admissible value
                    XmlAttribute attributeAdmissible = xmlDoc.CreateAttribute("admissible");
                    attributeAdmissible.Value = selSolution.Solution.AverageLoadOnFirstLayerCase < ectValue ? "true" : "false";
                    elemHumidity.Attributes.Append(attributeAdmissible);
                }
            }
        }
Example #11
0
        private void AppendCasePalletAnalysisElement(ReportData inputData, XmlElement elemDocument, XmlDocument xmlDoc)
        {
            if (!inputData.IsCasePalletAnalysis && !inputData.IsBoxCasePalletAnalysis)
                return;
            string ns = xmlDoc.DocumentElement.NamespaceURI;

            CasePalletAnalysis analysis = inputData.CasePalletAnalysis;
            SelCasePalletSolution selSolution = inputData.SelSolution;

            // palletAnalysis
            XmlElement eltPalletAnalysis = xmlDoc.CreateElement("casePalletAnalysis", ns);
            elemDocument.AppendChild(eltPalletAnalysis);
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = analysis.Name;
            eltPalletAnalysis.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = analysis.Description;
            eltPalletAnalysis.AppendChild(elemDescription);
            // pallet
            AppendPalletElement(analysis.PalletProperties, eltPalletAnalysis, xmlDoc);
            // case
            if (analysis.BProperties is CaseOfBoxesProperties)
            {
                AppendInsideBoxElement(analysis, selSolution.Solution, eltPalletAnalysis, xmlDoc);
                AppendCaseOfBoxesElement(analysis, selSolution.Solution, eltPalletAnalysis, xmlDoc);
            }
            else if (analysis.BProperties is BoxProperties && inputData.IsCasePalletAnalysis)
                AppendCaseElement(analysis, selSolution.Solution, eltPalletAnalysis, xmlDoc);
            else if (analysis.BProperties is BundleProperties)
                AppendBundleElement(analysis.BProperties as BundleProperties, eltPalletAnalysis, xmlDoc);
            // interlayer
            AppendInterlayerElement(analysis.InterlayerProperties, eltPalletAnalysis, xmlDoc);
            // pallet corners
            AppendPalletCornerElement(analysis.PalletCornerProperties, eltPalletAnalysis, xmlDoc);
            // pallet cap
            AppendPalletCapElement(analysis.PalletCapProperties, eltPalletAnalysis, xmlDoc);
            // pallet film
            AppendPalletFilmElement(analysis.PalletFilmProperties, analysis, eltPalletAnalysis, xmlDoc);
            // constraintSet
            AppendConstraintSet(analysis, selSolution.Solution, eltPalletAnalysis, xmlDoc);
            // solution
            AppendSolutionElement(inputData, eltPalletAnalysis, xmlDoc);
        }
Example #12
0
 public DockContentReport CreateReportHtml(ReportData reportObject, string htmlFilePath)
 {
     DockContentReport form = new DockContentReport(this, reportObject, htmlFilePath);
     AddView(form);
     return form;
 }
 /// <summary>
 /// ReportHtml : generate html report
 /// </summary>
 public ReporterHtml(ReportData inputData, string templatePath, string outpuFilePath)
 {
     BuildAnalysisReport(inputData, templatePath, outpuFilePath);
 }
Example #14
0
 /// <summary>
 /// Create or activate report view
 /// </summary>
 public DockContentReport CreateOrActivateHtmlReport(ReportData reportObject, string htmlFilePath)
 {
     // search among existing views
     foreach (IDocument doc in Documents)
         foreach (IView view in doc.Views)
         {
             DockContentReport form = view as DockContentReport;
             if (null == form) continue;
             if (reportObject.Equals(form.ReportObject))
             {
                 form.Activate();
                 return form;
             }
         }
     // ---> not found
     // ---> create new form
     DocumentSB parentDocument = reportObject.Document as DocumentSB;
     DockContentReport formReport = parentDocument.CreateReportHtml(reportObject, htmlFilePath);
     formReport.Show(dockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Document);
     return formReport;
 }
Example #15
0
        public void CreateAnalysisDataFile(ReportData inputData, string xmlDataFilePath, bool writeNamespace)
        {
            // instantiate XmlDocument
            XmlDocument xmlDoc = new XmlDocument();
            // set declaration
            XmlDeclaration declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "no");
            xmlDoc.AppendChild(declaration);
            // report (root) element
            XmlElement elemDocument;
            if (writeNamespace)
                elemDocument = xmlDoc.CreateElement("report", "http://treeDim/StackBuilder/ReportSchema.xsd");
            else
                elemDocument = xmlDoc.CreateElement("report");
            xmlDoc.AppendChild(elemDocument);

            string ns = xmlDoc.DocumentElement.NamespaceURI;
            Document doc = inputData.Document;
            // name element
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = doc.Name;
            elemDocument.AppendChild(elemName);
            // description element
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = doc.Description;
            elemDocument.AppendChild(elemDescription);
            // author element
            XmlElement elemAuthor = xmlDoc.CreateElement("author", ns);
            elemAuthor.InnerText = doc.Author;
            elemDocument.AppendChild(elemAuthor);
            // date of creation element
            XmlElement elemDateOfCreation = xmlDoc.CreateElement("dateOfCreation", ns);
            elemDateOfCreation.InnerText = doc.DateOfCreation.Year < 2000 ? DateTime.Now.ToShortDateString() : doc.DateOfCreation.ToShortDateString();
            elemDocument.AppendChild(elemDateOfCreation);
            // CompanyLogo
            if (!string.IsNullOrEmpty(CompanyLogo))
            {
                System.Drawing.Bitmap logoBitmap = new Bitmap(System.Drawing.Bitmap.FromFile(CompanyLogo));

                XmlElement elemCompanyLogo = xmlDoc.CreateElement("companyLogo", ns);
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                elemCompanyLogo.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(logoBitmap, typeof(byte[])));
                XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
                styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", 100, 100);
                elemCompanyLogo.Attributes.Append(styleAttribute);
                elemDocument.AppendChild(elemCompanyLogo);

                SaveImageAs(logoBitmap, "CompanyLogo.png");
            }
            // case analysis
            AppendCaseAnalysisElement(inputData, elemDocument, xmlDoc);
            // box/case analysis
            AppendBoxCaseAnalysisElement(inputData, elemDocument, xmlDoc);
            // case/pallet analysis
            AppendCasePalletAnalysisElement(inputData, elemDocument, xmlDoc);
            // pack/pallet analysis
            AppendPackPalletAnalysisElement(inputData, elemDocument, xmlDoc);
            // cylinder/pallet analysis
            AppendCylinderPalletAnalysisElement(inputData, elemDocument, xmlDoc);
            // hcylinder/pallet analysis
            AppendHCylinderPalletAnalysisElement(inputData, elemDocument, xmlDoc);
            // truckAnalysis
            AppendTruckAnalysisElement(inputData, elemDocument, xmlDoc);
            // ectAnalysis
            AppendEctAnalysisElement(inputData, elemDocument, xmlDoc);

            // finally save xml document
            _log.Debug(string.Format("Generating xml data file {0}", xmlDataFilePath));
            xmlDoc.Save(xmlDataFilePath);
        }
Example #16
0
        private void AppendHCylinderPalletSolutionElement(ReportData inputData, XmlElement elemPalletAnalysis, XmlDocument xmlDoc)
        {
            if (!inputData.IsHCylinderPalletAnalysis) return;

            string ns = xmlDoc.DocumentElement.NamespaceURI;

            SelHCylinderPalletSolution selSolution = inputData.SelHCylinderPalletSolution;
            HCylinderPalletSolution sol = inputData.HCylinderPalletSolution;

            // solution
            XmlElement elemSolution = xmlDoc.CreateElement("palletSolution", ns);
            elemPalletAnalysis.AppendChild(elemSolution);
            // title
            XmlElement elemTitle = xmlDoc.CreateElement("title", ns);
            elemTitle.InnerText = sol.Title;
            elemSolution.AppendChild(elemTitle);

            AppendElementValue(xmlDoc, elemSolution, "palletWeight", UnitsManager.UnitType.UT_MASS, inputData.ActualPalletWeight);
            AppendElementValue(xmlDoc, elemSolution, "palletHeight", UnitsManager.UnitType.UT_LENGTH, sol.PalletHeight);

            // cylinderCount
            XmlElement elemCaseCount = xmlDoc.CreateElement("cylinderCount", ns);
            elemCaseCount.InnerText = string.Format("{0}", sol.CylinderCount);
            elemSolution.AppendChild(elemCaseCount);
            // --- pallet images
            for (int i = 0; i < 5; ++i)
            {
                // initialize drawing values
                string viewName = string.Empty;
                Vector3D cameraPos = Vector3D.Zero;
                int imageWidth = ImageSizeDetail;
                bool showDimensions = false;
                switch (i)
                {
                    case 0:
                        viewName = "view_palletsolution_front"; cameraPos = Graphics3D.Front; imageWidth = ImageSizeDetail;
                        break;
                    case 1:
                        viewName = "view_palletsolution_left"; cameraPos = Graphics3D.Left; imageWidth = ImageSizeDetail;
                        break;
                    case 2:
                        viewName = "view_palletsolution_right"; cameraPos = Graphics3D.Right; imageWidth = ImageSizeDetail;
                        break;
                    case 3:
                        viewName = "view_palletsolution_back"; cameraPos = Graphics3D.Back; imageWidth = ImageSizeDetail;
                        break;
                    case 4:
                        viewName = "view_palletsolution_iso"; cameraPos = Graphics3D.Corner_0; imageWidth = ImageSizeWide; showDimensions = true;
                        break;
                    default:
                        break;
                }
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(imageWidth, imageWidth));
                // set camera position
                graphics.CameraPosition = cameraPos;
                // instantiate solution viewer
                HCylinderPalletSolutionViewer sv = new HCylinderPalletSolutionViewer(sol);
                sv.ShowDimensions = showDimensions;
                sv.Draw(graphics);
                // ---
                XmlElement elemImage = xmlDoc.CreateElement(viewName, ns);
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
                XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
                styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 3, graphics.Bitmap.Height / 3);
                elemImage.Attributes.Append(styleAttribute);
                elemSolution.AppendChild(elemImage);
                // Save image ?
                SaveImageAs(graphics.Bitmap, viewName + ".png");
            }
        }
Example #17
0
 private void AppendBoxCaseAnalysisElement(ReportData inputData, XmlElement elemDocument, XmlDocument xmlDoc)
 {
     // check if case analysis
     if (!inputData.IsBoxCaseAnalysis)
         return;
     BoxCaseAnalysis boxCaseAnalysis = inputData.BoxCaseAnalysis;
     SelBoxCaseSolution selBoxCaseSolution = inputData.SelBoxCaseSolution;
     // namespace
     string ns = xmlDoc.DocumentElement.NamespaceURI;
     // caseAnalysis
     XmlElement elemBoxCaseAnalysis = xmlDoc.CreateElement("boxCaseAnalysis", ns);
     elemDocument.AppendChild(elemBoxCaseAnalysis);
     // name
     XmlElement elemName = xmlDoc.CreateElement("name", ns);
     elemName.InnerText = boxCaseAnalysis.Name;
     elemBoxCaseAnalysis.AppendChild(elemName);
     // description
     XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
     elemDescription.InnerText = boxCaseAnalysis.Description;
     elemBoxCaseAnalysis.AppendChild(elemDescription);
     // box
     if (boxCaseAnalysis.BProperties is BoxProperties)
         AppendBoxElement(boxCaseAnalysis.BProperties as BoxProperties, elemBoxCaseAnalysis, xmlDoc);
     else if (boxCaseAnalysis.BProperties is BundleProperties)
         AppendBundleElement(boxCaseAnalysis.BProperties as BundleProperties, elemBoxCaseAnalysis, xmlDoc);
     // case
     AppendCaseElement(boxCaseAnalysis.CaseProperties, elemBoxCaseAnalysis, xmlDoc);
     // constraint set
     AppendBoxCaseConstraintSet(boxCaseAnalysis.ConstraintSet, elemBoxCaseAnalysis, xmlDoc);
     // solution
     AppendBoxCaseSolutionElement(selBoxCaseSolution.Solution, elemBoxCaseAnalysis, xmlDoc);
 }
Example #18
0
        private void AppendPackPalletAnalysisElement(ReportData inputData, XmlElement elemDocument, XmlDocument xmlDoc)
        {
            if (!inputData.IsPackPalletAnalysis)
                return;
            string ns = xmlDoc.DocumentElement.NamespaceURI;

            PackPalletAnalysis analysis = inputData.PackPalletAnalysis;
            SelPackPalletSolution selSolution = inputData.SelPackPalletSolution;

            // packPalletAnalysis element
            XmlElement eltPackPalletAnalysis = xmlDoc.CreateElement("packPalletAnalysis", ns);
            elemDocument.AppendChild(eltPackPalletAnalysis);
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = analysis.Name;
            eltPackPalletAnalysis.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = analysis.Description;
            eltPackPalletAnalysis.AppendChild(elemDescription);
            // pack
            AppendPackElement(analysis.PackProperties, eltPackPalletAnalysis, xmlDoc);
            // pallet
            AppendPalletElement(analysis.PalletProperties, eltPackPalletAnalysis, xmlDoc);
            // interlayer
            AppendInterlayerElement(analysis.InterlayerProperties, eltPackPalletAnalysis, xmlDoc);
            // solution
            AppendPackPalletSolutionElement(inputData, eltPackPalletAnalysis, xmlDoc);
        }
        private void ToolsGenerateReport(object sender, EventArgs e)
        {
            try
            {
                FormDefineReport formReport = new FormDefineReport();
                formReport.ProjectName = _analysis.Name;
                if (DialogResult.OK != formReport.ShowDialog())
                    return;
                // selected solution
                SelCasePalletSolution selSolution = new SelCasePalletSolution(null, _analysis, CurrentSolution);
                ReportData reportData = new ReportData(_analysis, selSolution);

                Reporter.CompanyLogo = string.Empty;
                Reporter.ImageSizeSetting = Reporter.eImageSize.IMAGESIZE_DEFAULT;
                Reporter reporter;
                if (formReport.FileExtension == "doc")
                {
                    // create "MS Word" report file
                    reporter = new ReporterMSWord(
                        reportData
                        , Settings.Default.ReportTemplatePath
                        , formReport.FilePath
                        , new Margins());
                }
                else if (formReport.FileExtension == "html")
                {
                    // create "html" report file
                    reporter = new ReporterHtml(
                        reportData
                        , Settings.Default.ReportTemplatePath
                        , formReport.FilePath);
                }
                else
                    return;

                // open file
                if (formReport.OpenGeneratedFile)
                    Process.Start(new ProcessStartInfo(formReport.FilePath));
            }
            catch (Exception ex)
            { _log.Error(ex.ToString()); }
        }
Example #20
0
        private void AppendPackPalletSolutionElement(ReportData inputData, XmlElement elemPackPalletAnalysis, XmlDocument xmlDoc)
        {
            if (!inputData.IsPackPalletAnalysis) return;

            string ns = xmlDoc.DocumentElement.NamespaceURI;

            SelPackPalletSolution selSolution = inputData.SelPackPalletSolution;
            PackPalletSolution sol = inputData.PackPalletSolution;

            // solution
            XmlElement elemSolution = xmlDoc.CreateElement("packPalletSolution", ns);
            elemPackPalletAnalysis.AppendChild(elemSolution);
            // title
            XmlElement elemTitle = xmlDoc.CreateElement("title", ns);
            elemTitle.InnerText = sol.Title;
            elemSolution.AppendChild(elemTitle);
            // efficiency
            XmlElement elemEfficiency = xmlDoc.CreateElement("efficiency", ns);
            elemEfficiency.InnerText = string.Format( "{0:F}", sol.VolumeEfficiency );
            elemSolution.AppendChild(elemEfficiency);
            // length / width / height
            AppendElementValue(xmlDoc, elemSolution, "length", UnitsManager.UnitType.UT_LENGTH, sol.PalletLength);
            AppendElementValue(xmlDoc, elemSolution, "width", UnitsManager.UnitType.UT_LENGTH, sol.PalletWidth);
            AppendElementValue(xmlDoc, elemSolution, "height", UnitsManager.UnitType.UT_LENGTH, sol.PalletHeight);
            // counts
            AppendElementValue(xmlDoc, elemSolution, "palletPackCount", sol.PackCount);
            AppendElementValue(xmlDoc, elemSolution, "palletCSUCount", sol.CSUCount);
            AppendElementValue(xmlDoc, elemSolution, "palletInterlayerCount", sol.InterlayerCount);
            //
            AppendElementValue(xmlDoc, elemSolution, "palletWeight", UnitsManager.UnitType.UT_MASS, sol.PalletWeight);
            AppendElementValue(xmlDoc, elemSolution, "palletLoadWeight", UnitsManager.UnitType.UT_MASS, sol.PalletLoadWeight);
            AppendElementValue(xmlDoc, elemSolution, "palletNetWeight", UnitsManager.UnitType.UT_MASS, sol.PalletNetWeight);
            AppendElementValue(xmlDoc, elemSolution, "overhangX", UnitsManager.UnitType.UT_LENGTH, sol.OverhangX);
            AppendElementValue(xmlDoc, elemSolution, "overhangY", UnitsManager.UnitType.UT_LENGTH, sol.OverhangY);
            // --- pallet images
            for (int i = 0; i < 5; ++i)
            {
                // initialize drawing values
                string viewName = string.Empty;
                Vector3D cameraPos = Vector3D.Zero;
                int imageWidth = ImageSizeDetail;
                bool showDimensions = false;
                switch (i)
                {
                    case 0: viewName = "view_palletsolution_front"; cameraPos = Graphics3D.Front; imageWidth = ImageSizeDetail; break;
                    case 1: viewName = "view_palletsolution_left"; cameraPos = Graphics3D.Left; imageWidth = ImageSizeDetail;   break;
                    case 2: viewName = "view_palletsolution_right"; cameraPos = Graphics3D.Right; imageWidth = ImageSizeDetail; break;
                    case 3: viewName = "view_palletsolution_back"; cameraPos = Graphics3D.Back; imageWidth = ImageSizeDetail;   break;
                    case 4: viewName = "view_palletsolution_iso"; cameraPos = Graphics3D.Corner_180; imageWidth = ImageSizeWide; showDimensions = true; break;
                    default:  break;
                }
                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(imageWidth, imageWidth));
                // set camera position
                graphics.CameraPosition = cameraPos;
                // instantiate solution viewer
                PackPalletSolutionViewer sv = new PackPalletSolutionViewer(sol);
                sv.ShowDimensions = showDimensions;
                sv.Draw(graphics);
                graphics.Flush();
                SaveImageAs(graphics.Bitmap, viewName + ".png");
                // ---
                XmlElement elemImage = xmlDoc.CreateElement(viewName, ns);
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[])));
                XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style");
                styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 3, graphics.Bitmap.Height / 3);
                elemImage.Attributes.Append(styleAttribute);
                elemSolution.AppendChild(elemImage);
            }

            // --- layers
            for (int i=0; i<sol.NoLayerTypes; ++i)
            {
                XmlElement elemLayerPack = xmlDoc.CreateElement("layerPack", ns);
                elemSolution.AppendChild(elemLayerPack);

                LayerType layerType = sol.GetLayerType(i);
                AppendElementValue(xmlDoc, elemLayerPack, "layerPackCount", layerType.PackCount);
                AppendElementValue(xmlDoc, elemLayerPack, "layerCSUCount", layerType.CSUCount);
                AppendElementValue(xmlDoc, elemLayerPack, "layerWeight", UnitsManager.UnitType.UT_MASS, layerType.LayerWeight);
                AppendElementValue(xmlDoc, elemLayerPack, "layerNetWeight", UnitsManager.UnitType.UT_MASS, layerType.LayerNetWeight);
                AppendElementValue(xmlDoc, elemLayerPack, "layerLength", UnitsManager.UnitType.UT_LENGTH, layerType.Length);
                AppendElementValue(xmlDoc, elemLayerPack, "layerWidth", UnitsManager.UnitType.UT_LENGTH, layerType.Width);
                AppendElementValue(xmlDoc, elemLayerPack, "layerHeight", UnitsManager.UnitType.UT_LENGTH, layerType.Height);
                AppendElementValue(xmlDoc, elemLayerPack, "maximumSpace", UnitsManager.UnitType.UT_LENGTH, layerType.MaximumSpace);
                AppendElementValue(xmlDoc, elemLayerPack, "layerIndexes", layerType.LayerIndexes);

                // instantiate graphics
                Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail));
                // set camera position
                graphics.CameraPosition = Graphics3D.Corner_180;
                // instantiate solution viewer
                PackPalletSolutionViewer sv = new PackPalletSolutionViewer(sol);
                sv.ShowDimensions = true;
                sv.DrawLayer(graphics, i);
                graphics.Flush();
                string viewName = string.Format("view_layer_iso{0}", i);
                SaveImageAs(graphics.Bitmap, viewName + ".png");
                // ---
                XmlElement elemImage = xmlDoc.CreateElement("imagePackLayer", ns);
                elemImage.InnerText = "images\\" + viewName + ".png";
                elemLayerPack.AppendChild(elemImage);
            }
        }
        private void toolStripButtonReport_Click(object sender, EventArgs e)
        {
            try
            {
                Document doc;
                CasePalletAnalysis analysis;
                CasePalletSolution casePalletSol;
                if (!GenerateProject(out doc, out analysis, out casePalletSol))
                    return;
                SelCasePalletSolution selSolution = new SelCasePalletSolution(doc, analysis, casePalletSol);

                // define report
                FormDefineReport formReport = new FormDefineReport();
                formReport.ProjectName = doc.Name;
                if (DialogResult.OK != formReport.ShowDialog())
                    return;

                Reporter.CompanyLogo = string.Empty;
                Reporter.ImageSizeSetting = Reporter.eImageSize.IMAGESIZE_DEFAULT;
                Reporter reporter;

                ReportData reportData = new ReportData(analysis, selSolution);

                if (formReport.FileExtension == "doc")
                {
                    // create "MS Word" report file
                    reporter = new ReporterMSWord(
                        reportData
                        , Settings.Default.ReportTemplatePath
                        , formReport.FilePath
                        , new Margins());
                }
                else if (formReport.FileExtension == "html")
                {
                    // create "html" report file
                    reporter = new ReporterHtml(
                        reportData
                        , Settings.Default.ReportTemplatePath
                        , formReport.FilePath);
                }
                else
                    return;

                // open file
                if (formReport.OpenGeneratedFile)
                    Process.Start(new ProcessStartInfo(formReport.FilePath));
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Example #22
0
 private void DocumentTreeView_SolutionReportHtmlClicked(object sender, AnalysisTreeViewEventArgs eventArg)
 {
     try
     {
         // build output file path
         string outputFilePath = Path.ChangeExtension(Path.GetTempFileName(), "html");
         // getting current culture
         string cultAbbrev = System.Globalization.CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName;
         // build report
         ReportData reportObject = new ReportData(
                 eventArg.Analysis, eventArg.SelSolution
                 , eventArg.CylinderAnalysis, eventArg.SelCylinderPalletSolution
                 , eventArg.HCylinderAnalysis, eventArg.SelHCylinderPalletSolution
                 , eventArg.BoxCaseAnalysis, eventArg.SelBoxCaseSolution
                 , eventArg.BoxCasePalletAnalysis, eventArg.SelBoxCasePalletSolution
                 , eventArg.PackPalletAnalysis, eventArg.SelPackPalletSolution
                 );
         Reporter.CompanyLogo = Properties.Settings.Default.CompanyLogoPath;
         Reporter.ImageSizeSetting = (Reporter.eImageSize)Properties.Settings.Default.ReporterImageSize;
         ReporterHtml reporter = new ReporterHtml(
             reportObject
             , Settings.Default.ReportTemplatePath
             , outputFilePath);
         // logging
         _log.Debug(string.Format("Saved report to {0}", outputFilePath));
         // open resulting report
         DocumentSB parentDocument = eventArg.Document as DocumentSB;
         DockContentReport dockContent = CreateOrActivateHtmlReport(reportObject, outputFilePath);
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }