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; }
private void AppendBundleElement(BundleProperties bundleProp, XmlElement elemAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; if (null == bundleProp) return; // bundle XmlElement elemBundle = CreateElement("bundle", null, elemAnalysis, xmlDoc, ns); elemAnalysis.AppendChild(elemBundle); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = bundleProp.Name; elemBundle.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = bundleProp.Description; elemBundle.AppendChild(elemDescription); // length / width / number of flats / unit thickness / unit weight / total thickness / total weight AppendElementValue(xmlDoc, elemBundle, "length", UnitsManager.UnitType.UT_LENGTH, bundleProp.Length); AppendElementValue(xmlDoc, elemBundle, "width", UnitsManager.UnitType.UT_LENGTH, bundleProp.Width); AppendElementValue(xmlDoc, elemBundle, "numberOfFlats", bundleProp.NoFlats); AppendElementValue(xmlDoc, elemBundle, "unitThickness", UnitsManager.UnitType.UT_LENGTH, bundleProp.UnitThickness); AppendElementValue(xmlDoc, elemBundle, "unitWeight", UnitsManager.UnitType.UT_MASS, bundleProp.UnitWeight); AppendElementValue(xmlDoc, elemBundle, "totalThickness", UnitsManager.UnitType.UT_LENGTH, bundleProp.UnitThickness * bundleProp.NoFlats); AppendElementValue(xmlDoc, elemBundle, "totalWeight", UnitsManager.UnitType.UT_MASS, bundleProp.UnitWeight * bundleProp.NoFlats); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; Box box = new Box(0, bundleProp); graphics.AddBox(box); DimensionCube dc = new DimensionCube(bundleProp.Length, bundleProp.Width, bundleProp.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // --- // view_bundle_iso XmlElement elemImage = xmlDoc.CreateElement("view_bundle_iso", 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 / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemBundle.AppendChild(elemImage); // save images ? SaveImageAs(graphics.Bitmap, "view_bundle_iso.png"); }
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.Analyses.Count == 0) return; // get analysis and solution CasePalletAnalysis analysis = document.Analyses[0]; { Graphics3DImage graphics = new Graphics3DImage(pictureBoxCase.Size); graphics.CameraPosition = Graphics3D.Corner_0; graphics.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 graphics.CameraPosition = Graphics3D.Corner_0; graphics.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()); } }
private void AppendCaseElement(CasePalletAnalysis analysis, CasePalletSolution sol, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get BoxProperties BoxProperties boxProp = analysis.BProperties as BoxProperties; if (null == boxProp) return; // case XmlElement elemCase = xmlDoc.CreateElement("case", ns); elemPalletAnalysis.AppendChild(elemCase); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = boxProp.Name; elemCase.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = boxProp.Description; elemCase.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemCase, "length", UnitsManager.UnitType.UT_LENGTH, boxProp.Length); AppendElementValue(xmlDoc, elemCase, "width", UnitsManager.UnitType.UT_LENGTH, boxProp.Width); AppendElementValue(xmlDoc, elemCase, "height", UnitsManager.UnitType.UT_LENGTH, boxProp.Height); AppendElementValue(xmlDoc, elemCase, "weight", UnitsManager.UnitType.UT_MASS, boxProp.Weight); AppendElementValue(xmlDoc, elemCase, "admissibleLoadOnTop", UnitsManager.UnitType.UT_MASS, 0.0); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Box box = new Box(0, boxProp); graphics.AddBox(box); DimensionCube dc = new DimensionCube(box.Length, box.Width, box.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // --- // view_case_iso XmlElement elemImage = xmlDoc.CreateElement("view_case_iso", 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 / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemCase.AppendChild(elemImage); // save image SaveImageAs(graphics.Bitmap, "view_case_iso.png"); }
private void AppendCylinderElement(CylinderProperties cylProperties, XmlElement elemAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get CylinderProperties XmlElement elemCylinder = xmlDoc.CreateElement("cylinder", ns); elemAnalysis.AppendChild(elemCylinder); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = cylProperties.Name; elemCylinder.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = cylProperties.Description; elemCylinder.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemCylinder, "radius", UnitsManager.UnitType.UT_LENGTH, cylProperties.RadiusOuter); AppendElementValue(xmlDoc, elemCylinder, "width", UnitsManager.UnitType.UT_LENGTH, cylProperties.Height); AppendElementValue(xmlDoc, elemCylinder, "height", UnitsManager.UnitType.UT_MASS, cylProperties.Weight); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Cylinder cyl = new Cylinder(0, cylProperties); graphics.AddCylinder(cyl); DimensionCube dc = new DimensionCube(cyl.DiameterOuter, cyl.DiameterOuter, cyl.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // --- // view_case_iso XmlElement elemImage = xmlDoc.CreateElement("view_cylinder_iso", 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 / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemCylinder.AppendChild(elemImage); // save image SaveImageAs(graphics.Bitmap, "view_cylinder_iso.png"); }
private void AppendCaseElement(SelBoxCasePalletSolution caseSolution, XmlElement elemCaseAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; BoxProperties boxProp = caseSolution.Solution.AttachedPalletSolution.Analysis.BProperties as BoxProperties; // case element XmlElement elemCase = CreateElement("caseWithInnerDims", null, elemCaseAnalysis, xmlDoc, ns); // name CreateElement("name", boxProp.Name, elemCase, xmlDoc, ns); // description CreateElement("description", boxProp.Description, elemCase, xmlDoc, ns); AppendElementValue(xmlDoc, elemCase, "length", UnitsManager.UnitType.UT_LENGTH, boxProp.Length); AppendElementValue(xmlDoc, elemCase, "width", UnitsManager.UnitType.UT_LENGTH, boxProp.Width); AppendElementValue(xmlDoc, elemCase, "height", UnitsManager.UnitType.UT_LENGTH, boxProp.Height); AppendElementValue(xmlDoc, elemCase, "innerLength", UnitsManager.UnitType.UT_LENGTH, boxProp.InsideLength); AppendElementValue(xmlDoc, elemCase, "innerWidth", UnitsManager.UnitType.UT_LENGTH, boxProp.InsideWidth); AppendElementValue(xmlDoc, elemCase, "innerHeight", UnitsManager.UnitType.UT_LENGTH, boxProp.InsideHeight); AppendElementValue(xmlDoc, elemCase, "weight", UnitsManager.UnitType.UT_MASS, boxProp.Height); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Box box = new Box(0, boxProp); graphics.AddBox(box); graphics.AddDimensions(new DimensionCube(box.Length, box.Width, box.Height)); graphics.Flush(); // --- // view_case_iso XmlElement elemImage = xmlDoc.CreateElement("view_case_iso", 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 / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemCase.AppendChild(elemImage); // save image SaveImageAs(graphics.Bitmap, "view_case_iso.png"); }
private void AppendPalletElement(PalletProperties palletProp, XmlElement elemAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; if (null == palletProp) return; // pallet XmlElement elemPallet = xmlDoc.CreateElement("pallet", ns); elemAnalysis.AppendChild(elemPallet); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = palletProp.Name; elemPallet.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = palletProp.Description; elemPallet.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemPallet, "length", UnitsManager.UnitType.UT_LENGTH, palletProp.Length); AppendElementValue(xmlDoc, elemPallet, "width", UnitsManager.UnitType.UT_LENGTH, palletProp.Width); AppendElementValue(xmlDoc, elemPallet, "height", UnitsManager.UnitType.UT_LENGTH, palletProp.Height); AppendElementValue(xmlDoc, elemPallet, "weight", UnitsManager.UnitType.UT_MASS, palletProp.Weight); AppendElementValue(xmlDoc, elemPallet, "admissibleLoad", UnitsManager.UnitType.UT_MASS, palletProp.AdmissibleLoadWeight); // type XmlElement elemType = xmlDoc.CreateElement("type", ns); elemType.InnerText = palletProp.TypeName; elemPallet.AppendChild(elemType); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(512, 512)); graphics.CameraPosition = Graphics3D.Corner_0; Pallet pallet = new Pallet(palletProp); pallet.Draw(graphics, Transform3D.Identity); graphics.AddDimensions(new DimensionCube(palletProp.Length, palletProp.Width, palletProp.Height)); graphics.Flush(); // --- // view_pallet_iso XmlElement elemImage = xmlDoc.CreateElement("view_pallet_iso", 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 / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemPallet.AppendChild(elemImage); // save image SaveImageAs(graphics.Bitmap, "view_pallet_iso.png"); }
private void AppendPackElement(PackProperties packProperties, XmlElement elemPackAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // pack element XmlElement elemPack = CreateElement("pack", null, elemPackAnalysis, xmlDoc, ns); // name CreateElement("name", packProperties.Name, elemPack, xmlDoc, ns); // description CreateElement("description", packProperties.Description, elemPack, xmlDoc, ns); // arrangement PackArrangement arrangement = packProperties.Arrangement; CreateElement( "arrangement" , string.Format("{0} * {1} * {2}", arrangement.Length, arrangement.Width, arrangement.Height) , elemPack, xmlDoc, ns); // length / width /height AppendElementValue(xmlDoc, elemPack, "length", UnitsManager.UnitType.UT_LENGTH, packProperties.Length); AppendElementValue(xmlDoc, elemPack, "width", UnitsManager.UnitType.UT_LENGTH, packProperties.Width); AppendElementValue(xmlDoc, elemPack, "height", UnitsManager.UnitType.UT_LENGTH, packProperties.Height); // weight AppendElementValue(xmlDoc, elemPack, "netWeight", UnitsManager.UnitType.UT_MASS, packProperties.NetWeight); AppendElementValue(xmlDoc, elemPack, "wrapperWeight", UnitsManager.UnitType.UT_MASS, packProperties.Wrap.Weight); AppendElementValue(xmlDoc, elemPack, "weight", UnitsManager.UnitType.UT_MASS, packProperties.Weight); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Pack pack = new Pack(0, packProperties); pack.ForceTransparency = true; graphics.AddBox(pack); DimensionCube dc = new DimensionCube(pack.Length, pack.Width, pack.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // view_pack_iso XmlElement elemImage = xmlDoc.CreateElement("view_pack_iso", 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 / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemPack.AppendChild(elemImage); // save image SaveImageAs(graphics.Bitmap, "view_pack_iso.png"); }
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"); } }
private void AppendTruckElement(TruckAnalysis truckAnalysis, XmlElement elemTruckAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get PalletProperties TruckProperties truckProp = truckAnalysis.TruckProperties; if (null == truckProp) return; // create "truck" element XmlElement elemTruck = xmlDoc.CreateElement("truck", ns); elemTruckAnalysis.AppendChild(elemTruck); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = truckProp.Name; elemTruck.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = truckProp.Description; elemTruck.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemTruck, "length", UnitsManager.UnitType.UT_LENGTH, truckProp.Length); AppendElementValue(xmlDoc, elemTruck, "width", UnitsManager.UnitType.UT_LENGTH, truckProp.Width); AppendElementValue(xmlDoc, elemTruck, "height", UnitsManager.UnitType.UT_LENGTH, truckProp.Height); AppendElementValue(xmlDoc, elemTruck, "admissibleLoad", UnitsManager.UnitType.UT_MASS, truckProp.AdmissibleLoadWeight); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; Truck truck = new Truck(truckProp); truck.DrawBegin(graphics); truck.DrawEnd(graphics); DimensionCube dc = new DimensionCube(truckProp.Length, truckProp.Width, truckProp.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // --- // view_truck_iso XmlElement elemImage = xmlDoc.CreateElement("view_truck_iso", 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 / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemTruck.AppendChild(elemImage); // Save image ? SaveImageAs(graphics.Bitmap, "view_truck_iso.png"); }
private void AppendPalletCapElement(PalletCapProperties palletCapProp, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { // sanity check if (null == palletCapProp) return; // namespace string ns = xmlDoc.DocumentElement.NamespaceURI; // interlayer XmlElement elemPalletCap = xmlDoc.CreateElement("palletCap", ns); elemPalletAnalysis.AppendChild(elemPalletCap); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = palletCapProp.Name; elemPalletCap.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = palletCapProp.Description; elemPalletCap.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemPalletCap, "length", UnitsManager.UnitType.UT_LENGTH, palletCapProp.Length); AppendElementValue(xmlDoc, elemPalletCap, "width", UnitsManager.UnitType.UT_LENGTH, palletCapProp.Width); AppendElementValue(xmlDoc, elemPalletCap, "height", UnitsManager.UnitType.UT_LENGTH, palletCapProp.Height); AppendElementValue(xmlDoc, elemPalletCap, "innerLength", UnitsManager.UnitType.UT_LENGTH, palletCapProp.InsideLength); AppendElementValue(xmlDoc, elemPalletCap, "innerWidth", UnitsManager.UnitType.UT_LENGTH, palletCapProp.InsideWidth); AppendElementValue(xmlDoc, elemPalletCap, "innerHeight", UnitsManager.UnitType.UT_LENGTH, palletCapProp.InsideHeight); AppendElementValue(xmlDoc, elemPalletCap, "weight", UnitsManager.UnitType.UT_MASS, palletCapProp.Weight); // --- // view_palletCap_iso // build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; PalletCap palletCap = new PalletCap(0, palletCapProp, Vector3D.Zero); palletCap.Draw(graphics); graphics.AddDimensions(new DimensionCube(palletCapProp.Length, palletCapProp.Width, palletCapProp.Height)); graphics.Flush(); // save image ? SaveImageAs(graphics.Bitmap, "view_palletCap_iso.png"); // --- // view_palletCap_iso XmlElement elemImage = xmlDoc.CreateElement("view_palletCap_iso", 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 / 4, graphics.Bitmap.Height / 4); elemImage.Attributes.Append(styleAttribute); elemPalletCap.AppendChild(elemImage); }
private void AppendCaseOfBoxesElement(CasePalletAnalysis analysis, CasePalletSolution sol, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get CaseOfBoxProperties CaseOfBoxesProperties caseOfBoxes = analysis.BProperties as CaseOfBoxesProperties; if (null == caseOfBoxes) return; // elemCaseOfBoxes XmlElement elemCaseOfBoxes = xmlDoc.CreateElement("caseOfBoxes", ns); elemPalletAnalysis.AppendChild(elemCaseOfBoxes); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = caseOfBoxes.Name; elemCaseOfBoxes.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = caseOfBoxes.Description; elemCaseOfBoxes.AppendChild(elemDescription); // length XmlElement elemNoX = xmlDoc.CreateElement("noX", ns); elemNoX.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iLength); elemCaseOfBoxes.AppendChild(elemNoX); // width XmlElement elemNoY = xmlDoc.CreateElement("noY", ns); elemNoY.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iWidth); elemCaseOfBoxes.AppendChild(elemNoY); // height XmlElement elemNoZ = xmlDoc.CreateElement("noZ", ns); elemNoZ.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Arrangement._iHeight); elemCaseOfBoxes.AppendChild(elemNoZ); // number of boxes XmlElement elemNoBoxes = xmlDoc.CreateElement("numberOfBoxes", ns); elemNoBoxes.InnerText = string.Format("{0}", caseOfBoxes.NumberOfBoxes); elemCaseOfBoxes.AppendChild(elemNoBoxes); // dim0 XmlElement eltDim0 = xmlDoc.CreateElement("dim0", ns); eltDim0.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Dim0); elemCaseOfBoxes.AppendChild(eltDim0); // dim1 XmlElement eltDim1 = xmlDoc.CreateElement("dim1", ns); eltDim1.InnerText = string.Format("{0}", caseOfBoxes.CaseDefinition.Dim1); elemCaseOfBoxes.AppendChild(eltDim1); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerLength", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideLength); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerWidth", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideWidth); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerHeight", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.InsideHeight); AppendElementValue(xmlDoc, elemCaseOfBoxes, "innerVolume", UnitsManager.UnitType.UT_VOLUME, caseOfBoxes.InsideVolume * UnitsManager.FactorCubeLengthToVolume); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerLength", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Length); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerWidth", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Width); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerHeight", UnitsManager.UnitType.UT_LENGTH, caseOfBoxes.Height); AppendElementValue(xmlDoc, elemCaseOfBoxes, "outerVolume", UnitsManager.UnitType.UT_VOLUME, caseOfBoxes.Volume * UnitsManager.FactorCubeLengthToVolume); AppendElementValue(xmlDoc, elemCaseOfBoxes, "emptyWeight", UnitsManager.UnitType.UT_MASS, caseOfBoxes.WeightEmpty); AppendElementValue(xmlDoc, elemCaseOfBoxes, "weight", UnitsManager.UnitType.UT_MASS, caseOfBoxes.Weight); // type converter TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); // view case of boxes iso1 Graphics3DImage graphics1 = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics1.CameraPosition = Graphics3D.Corner_0; CaseDefinitionViewer viewer = new CaseDefinitionViewer(caseOfBoxes.CaseDefinition, caseOfBoxes.InsideBoxProperties, caseOfBoxes.CaseOptimConstraintSet); viewer.CaseProperties = caseOfBoxes; viewer.Orientation = sol.FirstCaseOrientation; viewer.Draw(graphics1); graphics1.Flush(); // view case of boxes iso2 Graphics3DImage graphics2 = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics2.CameraPosition = Graphics3D.Corner_0; Box box = new Box(0, caseOfBoxes); graphics2.AddBox(box); graphics2.AddDimensions(new DimensionCube(caseOfBoxes.Length, caseOfBoxes.Width, caseOfBoxes.Height)); graphics2.Flush(); // view_caseOfBoxes_iso1 XmlElement elemImage1 = xmlDoc.CreateElement("view_caseOfBoxes_iso1", ns); elemImage1.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics1.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute1 = xmlDoc.CreateAttribute("style"); styleAttribute1.Value = string.Format("width:{0}pt;height:{1}pt", graphics1.Bitmap.Width / 3, graphics1.Bitmap.Height / 3); elemImage1.Attributes.Append(styleAttribute1); elemCaseOfBoxes.AppendChild(elemImage1); // save image SaveImageAs(graphics1.Bitmap, "view_caseOfBoxes_iso1.png"); // view_caseOfBoxes_iso2 XmlElement elemImage2 = xmlDoc.CreateElement("view_caseOfBoxes_iso2", ns); elemImage2.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics2.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute2 = xmlDoc.CreateAttribute("style"); styleAttribute2.Value = string.Format("width:{0}pt;height:{1}pt", graphics2.Bitmap.Width / 3, graphics2.Bitmap.Height / 3); elemImage2.Attributes.Append(styleAttribute2); elemCaseOfBoxes.AppendChild(elemImage2); // save image SaveImageAs(graphics2.Bitmap, "view_caseOfBoxes_iso2.png"); }