public static void Draw(BProperties boxProperties, HalfAxis.HAxis axis, PictureBox pictureBox) { // get horizontal angle double angle = 45; // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size); graphics.CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // draw Box box = new Box(0, boxProperties); // set axes HalfAxis.HAxis lengthAxis = HalfAxis.HAxis.AXIS_X_P; HalfAxis.HAxis widthAxis = HalfAxis.HAxis.AXIS_Y_P; switch (axis) { case HalfAxis.HAxis.AXIS_X_P: lengthAxis = HalfAxis.HAxis.AXIS_Z_P; widthAxis = HalfAxis.HAxis.AXIS_X_P; break; case HalfAxis.HAxis.AXIS_Y_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Z_N; break; case HalfAxis.HAxis.AXIS_Z_P: lengthAxis = HalfAxis.HAxis.AXIS_X_P; widthAxis = HalfAxis.HAxis.AXIS_Y_P; break; default: break; } box.LengthAxis = TreeDim.StackBuilder.Basics.HalfAxis.ToVector3D(lengthAxis); box.WidthAxis = TreeDim.StackBuilder.Basics.HalfAxis.ToVector3D(widthAxis); // draw box graphics.AddBox(box); graphics.Flush(); // set to picture box pictureBox.Image = graphics.Bitmap; }
public static void Draw(PalletProperties palletProperties, PictureBox pictureBox) { double angle = 45.0; Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size); graphics.CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); Pallet pallet = new Pallet(palletProperties); pallet.Draw(graphics, Transform3D.Identity); DimensionCube dc = new DimensionCube(palletProperties.Length, palletProperties.Width, palletProperties.Height) { FontSize = 6.0f }; graphics.AddDimensions(dc); graphics.Flush(); pictureBox.Image = graphics.Bitmap; }
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 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"); }
static void Main(string[] args) { ILog log = LogManager.GetLogger(typeof(Program)); XmlConfigurator.Configure(); try { // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(new Size(512, 512)); graphics.CameraPosition = new Vector3D(-10000.0, -10000.0, 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // load Bitmap string imageFilePath = @"..\..\Image16.bmp"; Bitmap bmp = new Bitmap(imageFilePath); Texture texture = new Texture(bmp, new Vector2D(100.0, 20.0), new Vector2D(40.0 * bmp.Size.Width / bmp.Size.Height, 40.0), 10.0); List<Texture> listTexture= new List<Texture>(); listTexture.Add(texture); // instantiate box and draw List<Box> boxList = new List<Box>(); Box box0 = new Box(0, 200.0, 160.0, 100.0); box0.Position = Vector3D.Zero; box0.SetAllFacesColor(Color.Chocolate); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_X_P, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_P, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Z_P, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_X_N, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_N, listTexture); box0.SetFaceTextures(HalfAxis.HAxis.AXIS_Z_N, listTexture); boxList.Add(box0); Box box1 = new Box(1, 200.0, 160.0, 100.0); box1.Position = new Vector3D(210.0, 0.0, 0.0); box1.SetAllFacesColor(Color.Chocolate); box1.SetFaceTextures(HalfAxis.HAxis.AXIS_Y_P, listTexture); boxList.Add(box1); Box box2 = new Box(2, 200.0, 160.0, 100.0); box2.Position = new Vector3D(0.0, 170.0, 0.0); box2.SetAllFacesColor(Color.Chocolate); boxList.Add(box2); Box box3 = new Box(3, 200.0, 160.0, 100.0); box3.Position = new Vector3D(0.0, 0.0, 110.0); box3.SetAllFacesColor(Color.Chocolate); boxList.Add(box3); // draw foreach (Box box in boxList) graphics.AddBox(box); graphics.Flush(); // Save as %TEMP%\Pallet.jpg string filePath = Path.Combine(Path.GetTempPath(), "Pallet.bmp"); graphics.SaveAs(filePath); bmp.Dispose(); // open file using (System.Diagnostics.Process proc = new System.Diagnostics.Process()) { proc.StartInfo.FileName = "mspaint.exe"; proc.StartInfo.Arguments = filePath; proc.Start(); } } catch (System.Exception ex) { log.Error(ex.ToString()); } }
private void AppendBoxElement(BoxProperties boxProperties, XmlElement elemCaseAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // box element XmlElement elemBox = CreateElement("box", null, elemCaseAnalysis, xmlDoc, ns); // name CreateElement("name", boxProperties.Name, elemBox, xmlDoc, ns); // description CreateElement("description", boxProperties.Description, elemBox, xmlDoc, ns); AppendElementValue(xmlDoc, elemBox, "length", UnitsManager.UnitType.UT_LENGTH, boxProperties.Length); AppendElementValue(xmlDoc, elemBox, "width", UnitsManager.UnitType.UT_LENGTH, boxProperties.Width); AppendElementValue(xmlDoc, elemBox, "height", UnitsManager.UnitType.UT_LENGTH, boxProperties.Height); AppendElementValue(xmlDoc, elemBox, "weight", UnitsManager.UnitType.UT_MASS, boxProperties.Weight); // view_box_iso // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Box box = new Box(0, boxProperties); graphics.AddBox(box); graphics.AddDimensions(new DimensionCube(box.Length, box.Width, box.Height)); graphics.Flush(); // --- // view_box_iso XmlElement elemImage = xmlDoc.CreateElement("view_box_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); elemBox.AppendChild(elemImage); // save image ? SaveImageAs(graphics.Bitmap, "view_box_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 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); } }
static int Main(string[] args) { ILog log = LogManager.GetLogger(typeof(Program)); XmlConfigurator.Configure(); try { bool useSingleColor = false; // instantiate document Document doc = new Document("Test", "Test", "fga", DateTime.Now, null); // define pallet properties PalletProperties palletProperties = new PalletProperties(doc, "EUR2", 1200, 1000, 150); Console.WriteLine("=== Pallet properties ==="); Console.WriteLine(palletProperties.ToString()); bool testCylinder = false; if (!testCylinder) { // define box properties BoxProperties boxProperties = new BoxProperties(doc, 162, 210, 250); boxProperties.Name = "Box1"; boxProperties.Weight = 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 CasePalletConstraintSet 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 CasePalletAnalysis analysis = new CasePalletAnalysis( boxProperties, palletProperties, interlayerProperties, null, null, null, null, constraintSet); // initialize solver CasePalletSolver 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); // save string fileName = string.Format("Pallet_{0}.bmp", solIndex++); string filePath = Path.Combine(Path.GetTempPath(), fileName); Console.WriteLine("Saving file " + filePath + "..."); graphics.SaveAs(filePath); } } else { // cylinder Console.WriteLine("=== Cylinder properties ==="); CylinderProperties cylProperties = new CylinderProperties(doc, "Cylinder", "Default cylinder", 90, 45.0, 100, 1.5, Color.Gray, Color.SkyBlue, Color.SkyBlue); Console.WriteLine(cylProperties.ToString()); // constraint set Console.WriteLine("=== Constraint set ==="); CylinderPalletConstraintSet constraintSet = new CylinderPalletConstraintSet(); constraintSet.UseMaximumPalletHeight = true; constraintSet.MaximumPalletHeight = 1200.0; constraintSet.UseMaximumPalletWeight = true; constraintSet.MaximumPalletWeight = 2000; constraintSet.UseMaximumNumberOfItems = true; constraintSet.MaximumNumberOfItems = 2000; Console.WriteLine(constraintSet.ToString()); // cylinder analysis CylinderPalletAnalysis analysis = new CylinderPalletAnalysis(cylProperties, palletProperties, null, null, constraintSet); // initialize solver CylinderSolver solver = new CylinderSolver(); solver.ProcessAnalysis(analysis); Console.WriteLine("=== Solutions ==="); int solIndex = 0; foreach (CylinderPalletSolution sol in analysis.Solutions) { // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(new Size(512, 512)); 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 CylinderPalletSolutionViewer sv = new CylinderPalletSolutionViewer(sol); sv.Draw(graphics); string fileName = string.Format("Pallet_{0}.jpg", solIndex++); string filePath = Path.Combine(Path.GetTempPath(), fileName); Console.WriteLine("Saving file " + filePath + "..."); graphics.SaveAs(filePath); } } } catch (Exception ex) { log.Error(ex.ToString()); } return 0; }
private Graphics3DImage InitializeImageFromViewParameters(viewParameters vParam) { long[] iSize = vParam.imageSize.ToArray(); Graphics3DImage graphics = new Graphics3DImage(new Size((int)iSize[0], (int)iSize[1])); if (vParam.predefinedPointOfViewSpecified) { switch (vParam.predefinedPointOfView) { case pointOfViewValue.CORNER0: graphics.CameraPosition = Graphics3D.Corner_0; break; case pointOfViewValue.CORNER1: graphics.CameraPosition = Graphics3D.Corner_90; break; case pointOfViewValue.CORNER2: graphics.CameraPosition = Graphics3D.Corner_180; break; case pointOfViewValue.CORNER3: graphics.CameraPosition = Graphics3D.Corner_270; break; case pointOfViewValue.FRONT: graphics.CameraPosition = Graphics3D.Front; break; case pointOfViewValue.BACK: graphics.CameraPosition = Graphics3D.Back; break; case pointOfViewValue.LEFT: graphics.CameraPosition = Graphics3D.Left; break; case pointOfViewValue.RIGHT: graphics.CameraPosition = Graphics3D.Right; break; case pointOfViewValue.TOP: graphics.CameraPosition = Graphics3D.Top; break; default: break; } } return graphics; }
private void FinalizeImageFromViewParameters(viewParameters vParam, Graphics3DImage graphics) { graphics.Flush(); // attempt to create directory string dirPath = Path.GetDirectoryName(vParam.path); try { Directory.CreateDirectory(dirPath); } catch (Exception ex) { _log.Error(ex.Message); } // check that directory exists if (!Directory.Exists(dirPath)) throw new Exception(string.Format("Directory {0} does not exist!\n Can not generate output file!", Path.GetDirectoryName(vParam.path))); // save image graphics.SaveAs(vParam.path); _log.Info(string.Format("Successfully saved file {0}", vParam.path)); }
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); // show generated bitmap on picture box control pictureBoxSolution.Image = graphics.Bitmap; } } catch (Exception ex) { _log.Error(ex.ToString()); } }
private void DrawBox() { try { // get horizontal angle double angle = trackBarHorizAngle.Value; // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(pictureBox.Size); graphics.CameraPosition = new Vector3D( Math.Cos(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , Math.Sin(angle * Math.PI / 180.0) * Math.Sqrt(2.0) * 10000.0 , 10000.0); graphics.Target = Vector3D.Zero; graphics.SetViewport(-500.0f, -500.0f, 500.0f, 500.0f); // draw BoxProperties boxProperties = new BoxProperties(null, _boxProperties.Length, _boxProperties.Width, _boxProperties.Height); boxProperties.SetAllColors(_boxProperties.Colors); boxProperties.TextureList = _textures; Box box = new Box(0, boxProperties); graphics.AddBox(box); graphics.Flush(); // set to picture box pictureBox.Image = graphics.Bitmap; } catch (Exception ex) { _log.Error(ex.ToString()); } }
private void AppendPalletCornerElement(PalletCornerProperties palletCornerProp, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { // sanity check if (null == palletCornerProp) return; // namespace string ns = xmlDoc.DocumentElement.NamespaceURI; // interlayer XmlElement elemPalletCorner = xmlDoc.CreateElement("palletCorner", ns); elemPalletAnalysis.AppendChild(elemPalletCorner); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = palletCornerProp.Name; elemPalletCorner.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = palletCornerProp.Description; elemPalletCorner.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemPalletCorner, "length", UnitsManager.UnitType.UT_LENGTH, palletCornerProp.Length); AppendElementValue(xmlDoc, elemPalletCorner, "width", UnitsManager.UnitType.UT_LENGTH, palletCornerProp.Width); AppendElementValue(xmlDoc, elemPalletCorner, "thickness", UnitsManager.UnitType.UT_LENGTH, palletCornerProp.Thickness); AppendElementValue(xmlDoc, elemPalletCorner, "weight", UnitsManager.UnitType.UT_LENGTH, palletCornerProp.Weight); // --- // view_palletCorner_iso // build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; Corner corner = new Corner(0, palletCornerProp); corner.Draw(graphics); graphics.Flush(); // save image ? SaveImageAs(graphics.Bitmap, "view_palletCorner_iso.png"); // --- // view_palletCorner_iso XmlElement elemImage = xmlDoc.CreateElement("view_palletCorner_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); elemPalletCorner.AppendChild(elemImage); }
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 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"); }
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 AppendCaseSolutionElement(SelBoxCasePalletSolution selSolution, XmlElement elemCaseAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; BoxCasePalletSolution caseSolution = selSolution.Solution; // caseSolution element XmlElement elemCaseSolution = CreateElement("boxCasePalletSolution", null, elemCaseAnalysis, xmlDoc, ns); // title CreateElement("title", caseSolution.Title, elemCaseSolution, xmlDoc, ns); // homogeneousLayer CreateElement("homogeneousLayer", caseSolution.HasHomogeneousLayers ? "Y" : "N", elemCaseSolution, xmlDoc, ns); // casePerPalletCount CreateElement("casePerPalletCount", caseSolution.CasePerPalletCount, elemCaseSolution, xmlDoc, ns); // boxPerCaseCount CreateElement("boxPerCaseCount", caseSolution.BoxPerCaseCount, elemCaseSolution, xmlDoc, ns); // boxPerPalletCount CreateElement("boxPerPalletCount", caseSolution.BoxPerPalletCount, elemCaseSolution, xmlDoc, ns); // caseEfficiency CreateElement("caseEfficiency", caseSolution.CaseEfficiency, elemCaseSolution, xmlDoc, ns); // palletEfficiency CreateElement("palletEfficiency", caseSolution.PalletEfficiency, elemCaseSolution, xmlDoc, ns); AppendElementValue(xmlDoc, elemCaseSolution, "caseWeight", UnitsManager.UnitType.UT_MASS, caseSolution.CaseWeight); AppendElementValue(xmlDoc, elemCaseSolution, "palletWeight", UnitsManager.UnitType.UT_MASS, caseSolution.PalletWeight); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(512, 512)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; // instantiate solution viewer BoxCasePalletSolutionViewer sv = new BoxCasePalletSolutionViewer(caseSolution); sv.Draw(graphics); graphics.Flush(); SaveImageAs(graphics.Bitmap, "view_caseSolution_iso.png"); // --- // view_caseSolution_iso XmlElement elemImage = xmlDoc.CreateElement("view_caseSolution_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); elemCaseSolution.AppendChild(elemImage); }
private void AppendBoxCaseSolutionElement(BoxCaseSolution solution, XmlElement elemBoxCaseAnalysis, XmlDocument xmlDoc) { BoxCaseAnalysis analysis = solution.Analysis; string ns = xmlDoc.DocumentElement.NamespaceURI; // solution XmlElement elemSolution = xmlDoc.CreateElement("boxCaseSolution", ns); elemBoxCaseAnalysis.AppendChild(elemSolution); // title XmlElement elemTitle = xmlDoc.CreateElement("title", ns); elemTitle.InnerText = solution.Title; elemSolution.AppendChild(elemTitle); // boxPerLayerCount XmlElement elemBoxPerLayerCount = xmlDoc.CreateElement("boxPerLayerCount", ns); elemBoxPerLayerCount.InnerText = solution.BoxPerLayerCount.ToString(); elemSolution.AppendChild(elemBoxPerLayerCount); // boxPerCaseCount XmlElement elemBoxPerCaseCount = xmlDoc.CreateElement("boxPerCaseCount", ns); elemBoxPerCaseCount.InnerText = solution.BoxPerCaseCount.ToString(); elemSolution.AppendChild(elemBoxPerCaseCount); // BoxLayersCount XmlElement elemBoxLayersCount = xmlDoc.CreateElement("boxLayersCount", ns); elemBoxLayersCount.InnerText = solution.BoxLayersCount.ToString(); elemSolution.AppendChild(elemBoxLayersCount); // criterions // load weight AppendElementValue(xmlDoc, elemSolution, "LoadWeight", UnitsManager.UnitType.UT_MASS, solution.BoxPerCaseCount * analysis.BProperties.Weight); // case weight AppendElementValue(xmlDoc, elemSolution, "CaseWeight", UnitsManager.UnitType.UT_MASS, solution.CaseWeight); // EfficiencyWeight XmlElement elemEfficiencyWeight = xmlDoc.CreateElement("EfficiencyWeight", ns); if (solution.CaseWeight > 0) elemEfficiencyWeight.InnerText = string.Format("{0:F}", solution.EfficiencyWeight); else elemEfficiencyWeight.InnerText = string.Empty; elemSolution.AppendChild(elemEfficiencyWeight); // EfficiencyVolume XmlElement elemEfficiencyVolume = xmlDoc.CreateElement("EfficiencyVolume", ns); elemEfficiencyVolume.InnerText = string.Format("{0:F}", solution.EfficiencyVolume); elemSolution.AppendChild(elemEfficiencyVolume); // LimitReached string limitReached = string.Empty; switch (solution.LimitReached) { case BoxCaseSolution.Limit.LIMIT_MAXHEIGHTREACHED: limitReached="Maximum height"; break; case BoxCaseSolution.Limit.LIMIT_MAXNUMBERREACHED: limitReached="Maximum number"; break; case BoxCaseSolution.Limit.LIMIT_MAXWEIGHTREACHED: limitReached="Maximum weight"; break; default: break; } XmlElement elemLimitReached = xmlDoc.CreateElement("LimitReached", ns); elemLimitReached.InnerText = limitReached; elemSolution.AppendChild(elemLimitReached); // --- case 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_caseSolution_front"; cameraPos = Graphics3D.Front; imageWidth = ImageSizeDetail; break; case 1: viewName = "view_caseSolution_left"; cameraPos = Graphics3D.Left; imageWidth = ImageSizeDetail; break; case 2: viewName = "view_caseSolution_right"; cameraPos = Graphics3D.Right; imageWidth = ImageSizeDetail; break; case 3: viewName = "view_caseSolution_back"; cameraPos = Graphics3D.Back; imageWidth = ImageSizeDetail; break; case 4: viewName = "view_caseSolution_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 BoxCaseSolutionViewer sv = new BoxCaseSolutionViewer(solution); sv.ShowDimensions = showDimensions; 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); elemSolution.AppendChild(elemImage); // Save image ? SaveImageAs(graphics.Bitmap, viewName + ".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 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 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"); } }
private void AppendInsideBoxElement(CasePalletAnalysis analysis, CasePalletSolution sol, XmlElement elemPalletAnalysis, XmlDocument xmlDoc) { string ns = xmlDoc.DocumentElement.NamespaceURI; // get caseOfBoxProperties CaseOfBoxesProperties caseOfBoxes = analysis.BProperties as CaseOfBoxesProperties; // get box properties BoxProperties boxProperties = caseOfBoxes.InsideBoxProperties; // elemBoxes XmlElement elemBox = xmlDoc.CreateElement("box", ns); elemPalletAnalysis.AppendChild(elemBox); // name XmlElement elemName = xmlDoc.CreateElement("name", ns); elemName.InnerText = boxProperties.Name; elemBox.AppendChild(elemName); // description XmlElement elemDescription = xmlDoc.CreateElement("description", ns); elemDescription.InnerText = boxProperties.Description; elemBox.AppendChild(elemDescription); AppendElementValue(xmlDoc, elemBox, "length", UnitsManager.UnitType.UT_LENGTH, boxProperties.Length); AppendElementValue(xmlDoc, elemBox, "width", UnitsManager.UnitType.UT_LENGTH, boxProperties.Width); AppendElementValue(xmlDoc, elemBox, "height", UnitsManager.UnitType.UT_LENGTH, boxProperties.Height); AppendElementValue(xmlDoc, elemBox, "weight", UnitsManager.UnitType.UT_MASS, boxProperties.Weight); // --- build image Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail)); graphics.CameraPosition = Graphics3D.Corner_0; graphics.Target = Vector3D.Zero; Box box = new Box(0, boxProperties); graphics.AddBox(box); DimensionCube dc = new DimensionCube(box.Length, box.Width, box.Height); dc.FontSize = 6.0f; graphics.AddDimensions(dc); graphics.Flush(); // --- // view_box_iso XmlElement elemImage = xmlDoc.CreateElement("view_box_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); elemBox.AppendChild(elemImage); // save image ? SaveImageAs(graphics.Bitmap, "view_box_iso.png"); }
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; }