Beispiel #1
1
        public void Export(string filePath)
        {
            PalletProperties palletProperties = _palletSolution.Analysis.PalletProperties;

            COLLADA model = new COLLADA();
            // asset
            model.asset = new asset()
            {
                created = DateTime.Now,
                modified = DateTime.Now
            };
            model.asset.keywords = "StackBuilder Pallet Case";
            model.asset.title = _palletSolution.Title;
            model.asset.unit = new assetUnit() { name = "millimeters", meter = 0.001 };
            model.asset.up_axis = UpAxisType.Z_UP;

            library_images images = new library_images();
            library_materials materials = new library_materials();
            library_effects effects = new library_effects();
            library_geometries geometries = new library_geometries();
            library_nodes nodes = new library_nodes();
            library_cameras cameras = new library_cameras();
            library_animations animations = new library_animations();
            library_visual_scenes scenes = new library_visual_scenes();

            COLLADAScene colladaScene = new COLLADAScene();

            model.Items = new Object[] { images, materials, effects, geometries, nodes, cameras, animations, scenes };
            model.scene = colladaScene;

            // colors and materials
            List<effect> listEffects = new List<effect>();
            List<material> listMaterials = new List<material>();
            List<image> listImages = new List<image>();

            // effects
            effect effectPallet;
            material materialPallet;
            CreateMaterial(palletProperties.Color, null, null, "Pallet", out effectPallet, out materialPallet);
            listEffects.Add(effectPallet);
            listMaterials.Add(materialPallet);

            Box box = new Box(0, _palletSolution.Analysis.BProperties);

            // build list of effects / materials / images
            uint faceIndex = 0;
            foreach (Face face in box.Faces)
            {
                // build texture image if any
                string textureName = null;
                if (face.HasBitmap)
                {
                    textureName = string.Format("textureFace_{0}", faceIndex);
                    string texturePath = System.IO.Path.Combine(
                        System.IO.Path.GetDirectoryName(filePath)
                        , textureName + ".jpg");

                    double dimX = 0.0, dimY = 0.0;

                    switch (faceIndex)
                    {
                        case 0: dimX = box.Width; dimY = box.Height; break;
                        case 1: dimX = box.Width; dimY = box.Height; break;
                        case 2: dimX = box.Length; dimY = box.Height; break;
                        case 3: dimX = box.Length; dimY = box.Height; break;
                        case 4: dimX = box.Length; dimY = box.Width; break;
                        case 5: dimX = box.Length; dimY = box.Width; break;
                        default: break;
                    }
                    face.ExtractFaceBitmap(dimX, dimY, _bmpWidth, texturePath);
                    // create image
                    listImages.Add(
                        new image()
                        {
                            id = textureName + ".jpg",
                            name = textureName + ".jpg",
                            Item = @".\" + textureName + @".jpg"
                        }
                    );
                }
                material materialCase;
                effect effectCase;
                CreateMaterial(face.ColorFill, textureName, "0", string.Format("Case{0}", faceIndex), out effectCase, out materialCase);
                listEffects.Add(effectCase);
                listMaterials.Add(materialCase);

                ++faceIndex;
            }

            // add to image list
            images.image = listImages.ToArray();

            // case lines material
            effect effectCaseLines;
            material materialCaseLines;
            CreateMaterial(Color.Black, null, null, "CaseLines", out effectCaseLines, out materialCaseLines);
            listEffects.Add(effectCaseLines);
            listMaterials.Add(materialCaseLines);
            effects.effect = listEffects.ToArray();
            materials.material = listMaterials.ToArray();

            // geometries
            geometry geomPallet = new geometry() { id = "palletGeometry", name = "palletGeometry" };
            geometry geomCase = new geometry() { id = "caseGeometry", name = "caseGeometry" };
            geometries.geometry = new geometry[] { geomPallet, geomCase };
            // pallet
            mesh meshPallet = CreatePalletMesh(palletProperties);
            geomPallet.Item = meshPallet;
            // case
            mesh meshCase = CreateCaseMesh(_palletSolution.Analysis.BProperties as BoxProperties);
            geomCase.Item = meshCase;
            // library_animations
            animation animationMain = new animation() { id = "animationMain_ID", name = "animationMain" };
            animations.animation = new animation[] { animationMain };

            List<object> listAnimationSource = new List<object>();

            // library_visual_scenes
            visual_scene mainScene = new visual_scene() { id = "MainScene", name = "MainScene" };
            scenes.visual_scene = new visual_scene[] { mainScene };

            List<node> sceneNodes = new List<node>();
            sceneNodes.Add(new node()
            {
                id = "PalletNode",
                name = "PalletNode",
                instance_geometry = new instance_geometry[]
                {
                    new instance_geometry()
                    {
                        url = "#palletGeometry",
                        bind_material = new bind_material()
                        {
                            technique_common = new instance_material[]
                            {
                                new instance_material()
                                {
                                    symbol="materialPallet",
                                    target=string.Format("#{0}", materialPallet.id)
                                }
                            }
                        }
                    }
                }
            });
            uint caseIndex = 0;
            foreach (ILayer layer in _palletSolution)
            {
                BoxLayer bLayer = layer as BoxLayer;
                if (null == bLayer) continue;

                foreach (BoxPosition bp in bLayer)
                {
                    Vector3D translation = bp.Position;
                    Vector3D rotations = bp.Transformation.Rotations;

                    node caseNode = new node()
                    {
                        id = string.Format("CaseNode_{0}_ID", caseIndex),
                        name = string.Format("CaseNode_{0}", caseIndex),
                        ItemsElementName = new ItemsChoiceType2[]
                        {
                            ItemsChoiceType2.translate,
                            ItemsChoiceType2.rotate,
                            ItemsChoiceType2.rotate,
                            ItemsChoiceType2.rotate
                        },
                        Items = new object[]
                        {
                            new TargetableFloat3()
                            {
                                Values = new double[] { translation.X, translation.Y, translation.Z },
                                sid = "t",
                            },
                            new rotate()
                            {
                                Values = new double[] { 1.0, 0.0, 0.0, rotations.X },
                                sid = "rx"
                            },
                            new rotate()
                            {
                                Values = new double[] { 0.0, 1.0, 0.0, rotations.Y },
                                sid = "ry"
                            },
                            new rotate()
                            {
                                Values = new double[] { 0.0, 0.0, 1.0, rotations.Z },
                                sid = "rz"
                            } 
                        },

                        instance_geometry = new instance_geometry[]
                        {
                            new instance_geometry()
                            {
                                url="#caseGeometry",
                                bind_material = new bind_material()
                                {
                                    technique_common = new instance_material[]
                                    {
                                        new instance_material() { symbol="materialCase0", target="#material_Case0_ID" },
                                        new instance_material() { symbol="materialCase1", target="#material_Case1_ID" },
                                        new instance_material() { symbol="materialCase2", target="#material_Case2_ID" },
                                        new instance_material() { symbol="materialCase3", target="#material_Case3_ID" },
                                        new instance_material() { symbol="materialCase4", target="#material_Case4_ID" },
                                        new instance_material() { symbol="materialCase5", target="#material_Case5_ID" },
                                        new instance_material() { symbol="materialCaseLines", target="#material_CaseLines_ID"}
                                    }
                                }
                            }
                        }
                    };
                    sceneNodes.Add(caseNode);

                    // animations
                    CreateAnimation(caseIndex, (uint)_palletSolution.CaseCount, listAnimationSource, bp);

                    // increment case index
                    ++caseIndex;
                }
            }

            // add nodes
            mainScene.node = sceneNodes.ToArray();

            animationMain.Items = listAnimationSource.ToArray();

            // library_cameras
            camera cameraCamera = new camera() { id = "Camera-Camera", name = "Camera-Camera" };
            cameraOpticsTechnique_commonPerspective cameraPerspective = new cameraOpticsTechnique_commonPerspective()
            {
                znear = new TargetableFloat() { sid = "znear", Value = 1.0 },
                zfar = new TargetableFloat() { sid = "zfar", Value = 10000.0 }
            };
            cameraCamera.optics = new cameraOptics() { technique_common = new cameraOpticsTechnique_common() { Item = cameraPerspective } };
            cameras.camera = new camera[] { cameraCamera };

            // colladaScene
            colladaScene.instance_visual_scene = new InstanceWithExtra() { url = "#MainScene" };

            model.Save(filePath);
            model.Save(System.IO.Path.ChangeExtension(filePath, "xml"));
        }
Beispiel #2
0
 public Pack(uint pickId, PackProperties packProperties)
     : base(pickId, packProperties.Length, packProperties.Width, packProperties.Height)
 {
     _packProperties = packProperties;
     _arrangement = _packProperties.Arrangement;
     _innerBox = new Box(0, packProperties.Box);
 }
 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;
 }
Beispiel #4
0
 public Pack(uint pickId, PackProperties packProperties, BoxPosition position)
     : base(pickId, packProperties, position)
 {
     _packProperties = packProperties;
     _arrangement = _packProperties.Arrangement;
     _innerBox = new Box(0, packProperties.Box);
     _forceTransparency = false;
 }
Beispiel #5
0
        public void DrawBox(Box box)
        {
            System.Drawing.Graphics g = Graphics;

            // get points
            Point[] pt = TransformPoint( box.TopFace.Points);

            // draw solid face
            Brush brushSolid = new SolidBrush(box.TopFace.ColorFill);
            g.FillPolygon(brushSolid, pt);
            Brush brushPath = new SolidBrush(box.TopFace.ColorPath);
            Pen penPath = new Pen(brushPath);
            g.DrawPolygon(penPath, pt);
        }
        /// <summary>
        /// Use this method when drawing a solution that belongs an analysis
        /// </summary>
        public void Draw(Graphics3D graphics)
        {
            if (null == _solution)
                return;
            // initialize Graphics3D object
            if (!graphics.ShowBoxIds)
            {
                // draw pallet
                Pallet pallet = new Pallet(_analysis.PalletProperties);
                pallet.Draw(graphics, Transform3D.Identity);
            }
            // draw solution
            uint pickId = 0;
            foreach (ILayer layer in _solution)
            {
                CylinderLayer cylLayer = layer as CylinderLayer;
                if (null != cylLayer)
                {
                    foreach (Vector3D pos in cylLayer)
                        graphics.AddCylinder(
                            new Cylinder(pickId++, _analysis.CylinderProperties, new CylPosition(pos, HalfAxis.HAxis.AXIS_Z_P))
                            );
                }

                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    Box box = new Box(pickId++, _analysis.InterlayerProperties);
                    // set position
                    box.Position = new Vector3D(
                        0.5 * (_analysis.PalletProperties.Length - _analysis.InterlayerProperties.Length)
                        , 0.5 * (_analysis.PalletProperties.Width - _analysis.InterlayerProperties.Width)
                        , interlayerPos.ZLow);
                    // draw
                    graphics.AddBox(box);
                }
            }
            if (_showDimensions)
            {
                if (_showDimensions)
                {
                    graphics.AddDimensions(
                        new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1)
                        , Color.Black, false));
                    graphics.AddDimensions(
                        new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2)
                        , Color.Red, true));
                }
            }
        }
        /// <summary>
        /// Draw case solution
        /// </summary>
        public void Draw(Graphics3D graphics)
        {
            if (null == _caseSolution)
                throw new Exception("No case solution defined!");

            // load pallet solution
            BoxProperties caseProperties;

            CasePalletSolution palletSolution = _caseSolution.PalletSolutionDesc.LoadPalletSolution();
            if (null == palletSolution)
                caseProperties = new BoxProperties(null, _caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight);
            else
            {
                CasePalletAnalysis palletAnalysis = palletSolution.Analysis;
                // retrieve case properties 
                caseProperties = palletAnalysis.BProperties as BoxProperties;
            }
            if (null == caseProperties) return;
            // draw case (inside)
            Case case_ = new Case(caseProperties);
            case_.DrawInside(graphics);
            // get case analysis
            BoxCasePalletAnalysis caseAnalysis = _caseSolution.ParentCaseAnalysis;
            // draw solution
            uint pickId = 0;
            foreach (ILayer layer in _caseSolution)
            {
                BoxLayer blayer = layer as BoxLayer;
                if (null != blayer)
                {
                    foreach (BoxPosition bPosition in blayer)
                        graphics.AddBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition));
                }

                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    Box box = new Box(pickId++, caseAnalysis.InterlayerProperties);
                    // set position
                    box.Position = new Vector3D(0.0, 0.0, interlayerPos.ZLow);
                    // draw
                    graphics.AddBox(box);
                }
            }
            // get case analysis
            if (_showDimensions)
                graphics.AddDimensions(new DimensionCube(_caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight));
        }
        public void Draw(Graphics3D graphics)
        {
            // sanity check
            if (null == _solution) return;
            InterlayerProperties interlayerProperties = _analysis.InterlayerProperties;
            // draw pallet
            Pallet pallet = new Pallet(_analysis.PalletProperties);
            pallet.Draw(graphics, Transform3D.Identity);
            // draw solution
            uint pickid = 0;
            for (int iLayerIndex = 0; iLayerIndex < _solution.LayerCount; ++iLayerIndex)
            {
                bool hasInterlayer = false;
                double zInterlayer = 0.0;
                BoxLayer blayer = _solution.GetBoxLayer(iLayerIndex, ref hasInterlayer, ref zInterlayer);

                if (hasInterlayer && (null != interlayerProperties))
                {
                    // instantiate box
                    Box box = new Box(pickid++, interlayerProperties);
                    // set position
                    box.Position = new Vector3D(
                        0.5 * (_analysis.PalletProperties.Length - interlayerProperties.Length)
                        , 0.5 * (_analysis.PalletProperties.Width - interlayerProperties.Width)
                        , zInterlayer);
                    // draw
                    graphics.AddBox(box);
                }
                foreach (BoxPosition bPosition in blayer)
                    graphics.AddBox(new Pack(pickid++, _analysis.PackProperties, bPosition));

                if (_showDimensions)
                {
                    graphics.AddDimensions(
                        new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1)
                        , Color.Black, false));
                    graphics.AddDimensions(
                        new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2)
                        , Color.Red, true));
                }
            }
        }
Beispiel #9
0
        public void DrawBox(Box box)
        {
            System.Drawing.Graphics g = Graphics;

            // get points
            Point[] pt = TransformPoint( box.TopFace.Points);

            // draw solid face
            Brush brushSolid = new SolidBrush(box.TopFace.ColorFill);
            g.FillPolygon(brushSolid, pt);
            // draw box tape
            if (box.ShowTape)
            {
                // instantiate brush
                Brush brushTape = new SolidBrush(box.TapeColor);
                // fill polygon
                Point[] pts = TransformPoint(box.TapePoints);
                g.FillPolygon(brushTape, pts);
            }

            Brush brushPath = new SolidBrush(box.TopFace.ColorPath);
            Pen penPath = new Pen(brushPath);
            g.DrawPolygon(penPath, pt);
        }
Beispiel #10
0
 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 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;
        }
Beispiel #12
0
        public override void Draw(Graphics3D graphics, bool showDimensions)
        {
            if (null == _solution) return;
            AnalysisCasePallet analysisCasePallet = _solution.Analysis as AnalysisCasePallet;

            // ### draw pallet
            Pallet pallet = new Pallet(analysisCasePallet.PalletProperties);
            pallet.Draw(graphics, Transform3D.Identity);

            // ### draw solution
            uint layerId = 0, pickId = 0;
            List<ILayer> layers = _solution.Layers;
            foreach (ILayer layer in layers)
            {
                // ### layer of boxes
                BoxLayer blayer = layer as BoxLayer;
                if (null != blayer)
                {
                    BBox3D bbox = new BBox3D();
                    foreach (BoxPosition bPosition in blayer)
                    {
                        Box b = new Box(pickId++, analysisCasePallet.BProperties, bPosition);
                        graphics.AddBox(b);
                        bbox.Extend(b.BBox);
                    }
                    // add layer BBox
                    AddPickingBox(bbox, layerId);
                    // draw bounding box around selected layer
                    if (layerId == _solution.SelectedLayerIndex)
                        DrawLayerBoundingBox(graphics, bbox);
                    ++layerId;
                }
                // ### intetrlayer
                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    InterlayerProperties interlayerProp = _solution.Interlayers[interlayerPos.TypeId];//analysisCasePallet.Interlayer(interlayerPos.TypeId);
                    if (null != interlayerProp)
                    {
                        Box box = new Box(pickId++, interlayerProp);
                        box.Position = new Vector3D(
                            0.5 * (analysisCasePallet.PalletProperties.Length - interlayerProp.Length)
                            , 0.5 * (analysisCasePallet.PalletProperties.Width - interlayerProp.Width)
                            , interlayerPos.ZLow
                            );
                        graphics.AddBox(box);
                    }
                }
            }
            BBox3D loadBBox = _solution.BBoxLoad;
            BBox3D loadBBoxWDeco = _solution.BBoxLoadWDeco;
            #region Pallet corners
            // ### pallet corners : Begin
            Corner[] corners = new Corner[4];
            if (analysisCasePallet.HasPalletCorners)
            {
                // positions
                Vector3D[] cornerPositions =
                {
                    loadBBox.PtMin
                    , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                    , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                    , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                };
                // length axes
                HalfAxis.HAxis[] lAxes =
                {
                    HalfAxis.HAxis.AXIS_X_P,
                    HalfAxis.HAxis.AXIS_Y_P,
                    HalfAxis.HAxis.AXIS_X_N,
                    HalfAxis.HAxis.AXIS_Y_N
                };
                // width axes
                HalfAxis.HAxis[] wAxes =
                {
                    HalfAxis.HAxis.AXIS_Y_P,
                    HalfAxis.HAxis.AXIS_X_N,
                    HalfAxis.HAxis.AXIS_Y_N,
                    HalfAxis.HAxis.AXIS_X_P
                };
                // corners
                if (analysisCasePallet.HasPalletCorners)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        corners[i] = new Corner(0, analysisCasePallet.PalletCornerProperties);
                        corners[i].Height = Math.Min(analysisCasePallet.PalletCornerProperties.Length, loadBBox.Height);
                        corners[i].SetPosition(cornerPositions[i], lAxes[i], wAxes[i]);
                        corners[i].DrawBegin(graphics);
                    }
                }
            }
            #endregion

            #region Pallet cap
            #endregion

            #region Pallet film
            // ### pallet film
            Film film = null;
            if (analysisCasePallet.HasPalletFilm)
            {
                PalletFilmProperties palletFilmProperties = analysisCasePallet.PalletFilmProperties;
                film = new Film(
                    palletFilmProperties.Color,
                    palletFilmProperties.UseTransparency,
                    palletFilmProperties.UseHatching,
                    palletFilmProperties.HatchSpacing,
                    palletFilmProperties.HatchAngle);
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin,
                    HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis,
                    HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis,
                    HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis,
                    HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis,
                    HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width),
                    UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1)));
                film.DrawBegin(graphics);
            }
            #endregion

            // ### dimensions
            if (showDimensions)
            {
                graphics.AddDimensions(
                    new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1)
                    , Color.Black, false));
                graphics.AddDimensions(
                    new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2)
                    , Color.Red, true));
            }

            #region Pallet corners
            // pallet corners : End
            if (analysisCasePallet.HasPalletCorners)
            {
                for (int i = 0; i < 4; ++i)
                    corners[i].DrawEnd(graphics);
            }
            #endregion

            #region Pallet Cap
            // ### pallet cap
            if (analysisCasePallet.HasPalletCap)
            {
                PalletCapProperties capProperties = analysisCasePallet.PalletCapProperties;
                Vector3D pos = new Vector3D(
                    0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length),
                    0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width),
                    loadBBox.PtMax.Z - capProperties.InsideHeight);
                PalletCap cap = new PalletCap(0, capProperties, pos);
                cap.DrawEnd(graphics);
            }
            #endregion

            #region Pallet film
            // pallet film : End
            if (analysisCasePallet.HasPalletFilm)
                film.DrawEnd(graphics);
            #endregion
        }
Beispiel #13
0
        protected mesh CreateComplexCaseMesh(BoxProperties caseProperties)
        {
            // build box
            Box box = new Box(0, caseProperties);
            // build list of vertex
            double ct = 5.0;
            Vector3D[] vertices = new Vector3D[16];
            // 1st layer
            vertices[0] = new Vector3D(ct, ct, 0.0);
            vertices[1] = new Vector3D(box.Length - ct, ct, 0.0);
            vertices[2] = new Vector3D(box.Length - ct, box.Width - ct, 0.0);
            vertices[3] = new Vector3D(ct, box.Width - ct, 0.0);
            // 2nd layer (8)
            vertices[4] = new Vector3D(0.0, 0.0, ct);
            vertices[5] = new Vector3D(box.Length, 0.0, ct);
            vertices[6] = new Vector3D(box.Length, box.Width, ct);
            vertices[7] = new Vector3D(0.0, box.Width, ct);
            // 3rd later (8)
            vertices[8] = new Vector3D(0.0, 0.0, box.Height - ct);
            vertices[9] = new Vector3D(box.Length, 0.0, box.Height - ct);
            vertices[10] = new Vector3D(box.Length, box.Width, box.Height - ct);
            vertices[11] = new Vector3D(0.0, box.Width, box.Height - ct);
            // 4th layer
            vertices[12] = new Vector3D(ct, ct, box.Height);
            vertices[13] = new Vector3D(box.Length - ct, ct, box.Height);
            vertices[14] = new Vector3D(box.Length - ct, box.Width - ct, box.Height);
            vertices[15] = new Vector3D(ct, box.Width - ct, box.Height);

            // build list of loops
            Loop[] loops = new Loop[14];

            mesh caseMesh = new mesh();
            return caseMesh;
        }
Beispiel #14
0
        // list of boxes
        public List<Box> BuildListOfBoxes(Vector3D dimensions, Color color, Transform3D t)
        {
            List<Box> listPalletLumbers = new List<Box>();

            double coefX = dimensions.X / _defaultDimensions.X;
            double coefY = dimensions.Y / _defaultDimensions.Y;
            double coefZ = dimensions.Z / _defaultDimensions.Z;
            uint pickId = 0;
            foreach (Position pos in _positions)
            {
                double coef0 = coefX, coef1 = coefY, coef2 = coefZ;
                if (pos.Axis1 == HalfAxis.HAxis.AXIS_X_P && pos.Axis2 == HalfAxis.HAxis.AXIS_Y_P)
                { coef0 = coefX; coef1 = coefY; }
                else if (pos.Axis1 == HalfAxis.HAxis.AXIS_Y_P && pos.Axis2 == HalfAxis.HAxis.AXIS_X_N)
                { coef0 = coefY; coef1 = coefX; }
                Vector3D dim = _lumbers[pos.Index];
                Box box = new Box(pickId++, dim.X * coef0, dim.Y * coef1, dim.Z * coef2);
                box.SetAllFacesColor(color);
                box.Position = t.transform(new Vector3D(pos.XYZ.X * coefX, pos.XYZ.Y * coefY, pos.XYZ.Z * coefZ));
                box.LengthAxis = Basics.HalfAxis.ToVector3D(HalfAxis.Transform(pos.Axis1, t)); ;
                box.WidthAxis = Basics.HalfAxis.ToVector3D(HalfAxis.Transform(pos.Axis2, t)); ;
                listPalletLumbers.Add(box);
            }
            return listPalletLumbers;
        }
        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());
            }

        }
Beispiel #16
0
        private void AppendInterlayerElement(InterlayerProperties interlayerProp, XmlElement elemPalletAnalysis, XmlDocument xmlDoc)
        {
            // sanity check
            if (null == interlayerProp) return;
            // namespace
            string ns = xmlDoc.DocumentElement.NamespaceURI;
            // interlayer
            XmlElement elemInterlayer = xmlDoc.CreateElement("interlayer", ns);
            elemPalletAnalysis.AppendChild(elemInterlayer);
            // name
            XmlElement elemName = xmlDoc.CreateElement("name", ns);
            elemName.InnerText = interlayerProp.Name;
            elemInterlayer.AppendChild(elemName);
            // description
            XmlElement elemDescription = xmlDoc.CreateElement("description", ns);
            elemDescription.InnerText = interlayerProp.Description;
            elemInterlayer.AppendChild(elemDescription);

            AppendElementValue(xmlDoc, elemInterlayer, "length", UnitsManager.UnitType.UT_LENGTH, interlayerProp.Length);
            AppendElementValue(xmlDoc, elemInterlayer, "width", UnitsManager.UnitType.UT_LENGTH, interlayerProp.Width);
            AppendElementValue(xmlDoc, elemInterlayer, "thickness", UnitsManager.UnitType.UT_LENGTH, interlayerProp.Thickness);
            AppendElementValue(xmlDoc, elemInterlayer, "weight", UnitsManager.UnitType.UT_MASS, interlayerProp.Weight);

            // --- build image
            Graphics3DImage graphics = new Graphics3DImage(new Size(ImageSizeDetail, ImageSizeDetail));
            graphics.CameraPosition = Graphics3D.Corner_0;
            Box box = new Box(0, interlayerProp);
            graphics.AddBox(box);
            graphics.Flush();
            // ---
            // view_interlayer_iso
            XmlElement elemImage = xmlDoc.CreateElement("view_interlayer_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);
            elemInterlayer.AppendChild(elemImage);
            // save image ?
            SaveImageAs(graphics.Bitmap, "view_interlayer_iso.png");
        }
Beispiel #17
0
        internal void Draw(Box box)
        {
            System.Drawing.Graphics g = Graphics;

            if (box is Pack)
            {
                Pack pack = box as Pack;
                pack.Draw(this);
            }
            else
            {

                Vector3D[] points = box.Points;

                Face[] faces = box.Faces;
                for (int i = 0; i < 6; ++i)
                {
                    // Face
                    Face face = faces[i];
                    // face normal
                    Vector3D normal = face.Normal;
                    // visible ?
                    if (!faces[i].IsVisible(_vTarget - _vCameraPos))
                        continue;
                    // color
                    faces[i].ColorFill = box.Colors[i];
                    double cosA = System.Math.Abs(Vector3D.DotProduct(faces[i].Normal, VLight));
                    Color color = Color.FromArgb((int)(faces[i].ColorFill.R * cosA), (int)(faces[i].ColorFill.G * cosA), (int)(faces[i].ColorFill.B * cosA));
                    // points
                    Vector3D[] points3D = faces[i].Points;
                    Point[] pt = TransformPoint(GetCurrentTransformation(), points3D);
                    //  draw solid face
                    Brush brush = new SolidBrush(color);
                    g.FillPolygon(brush, pt);
                    // draw textures
                    if (null != face.Textures && ShowTextures)
                        foreach (Texture texture in face.Textures)
                        {
                            Point[] ptsImage = TransformPoint(GetCurrentTransformation(), box.PointsImage(i, texture));
                            Point[] pts = new Point[3];
                            pts[0] = ptsImage[3];
                            pts[1] = ptsImage[2];
                            pts[2] = ptsImage[0];
                            g.DrawImage(texture.Bitmap, pts);
                        }
                    // draw path
                    Brush brushPath = new SolidBrush(faces[i].ColorPath);
                    Pen penPathThick = new Pen(brushPath, box.IsBundle ? 2.0f : 1.5f);
                    int ptCount = pt.Length;
                    for (int j = 1; j < ptCount; ++j)
                        g.DrawLine(penPathThick, pt[j - 1], pt[j]);
                    g.DrawLine(penPathThick, pt[ptCount - 1], pt[0]);
                    // draw bundle lines
                    if (box.IsBundle && i < 4)
                    {
                        Pen penPathThin = new Pen(brushPath, 1.5f);
                        int noSlice = Math.Min(box.BundleFlats, 4);
                        for (int iSlice = 0; iSlice < noSlice - 1; ++iSlice)
                        {
                            Vector3D[] ptSlice = new Vector3D[2];
                            ptSlice[0] = points3D[0] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[3] - points3D[0]);
                            ptSlice[1] = points3D[1] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[2] - points3D[1]);

                            Point[] pt2D = TransformPoint(GetCurrentTransformation(), ptSlice);
                            g.DrawLine(penPathThin, pt2D[0], pt2D[1]);
                        }
                    }
                }

                // draw box tape
                if (box.ShowTape && faces[5].IsVisible(_vTarget - _vCameraPos))
                {
                    // get color
                    double cosA = System.Math.Abs(Vector3D.DotProduct(faces[5].Normal, VLight));
                    Color color = Color.FromArgb((int)(box.TapeColor.R * cosA), (int)(box.TapeColor.G * cosA), (int)(box.TapeColor.B * cosA));
                    // instantiate brush
                    Brush brushTape = new SolidBrush(color);
                    // get tape points
                    Point[] pts = TransformPoint(GetCurrentTransformation(), box.TapePoints);
                    // fill polygon
                    g.FillPolygon(brushTape, pts);
                    // draw path
                    Brush brushPath = new SolidBrush(faces[5].ColorPath);
                    Pen penPathThick = new Pen(brushPath, 1.5f);
                    int ptCount = pts.Length;
                    for (int j = 1; j < ptCount; ++j)
                        g.DrawLine(penPathThick, pts[j - 1], pts[j]);
                    g.DrawLine(penPathThick, pts[ptCount - 1], pts[0]);
                }
            }
            if (_showBoxIds)
            {
                // draw box id
                Point ptId = TransformPoint(GetCurrentTransformation(), box.TopFace.Center);
                g.DrawString(
                    box.PickId.ToString()
                    , new Font("Arial", 8.0f)
                    , Brushes.Black
                    , new Rectangle(ptId.X - 15, ptId.Y - 10, 30, 20)
                    , StringFormat.GenericDefault);
                g.DrawString(
                    _boxDrawingCounter.ToString()
                    , new Font("Arial", 8.0f)
                    , Brushes.Red
                    , new Rectangle(ptId.X + 5, ptId.Y - 10, 30, 20)
                    , StringFormat.GenericDefault);
            }
            ++_boxDrawingCounter;
        }
Beispiel #18
0
 public void AddBox(Box box)
 {
     if (!box.IsValid)
         throw new GraphicsException("Box is invalid and cannot be drawn!");
     _boxes.Add(box);
 }
 public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
 { 
     InterlayerProperties interlayerProperties = new InterlayerProperties(
         null, tbName.Text, tbDescription.Text
         , InterlayerLength, InterlayerWidth
         , Thickness, Weight, Color);
     Box box = new Box(0, interlayerProperties);
     graphics.AddBox(box);
 }
Beispiel #20
0
 public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
 {
     BundleProperties bundleProperties = new BundleProperties(
         null, BundleName, Description
         , BundleLength, BundleWidth, UnitThickness, UnitWeight, NoFlats, Color);
     Box box = new Box(0, bundleProperties);
     graphics.AddBox(box);
     graphics.AddDimensions(new DimensionCube(BundleLength, BundleWidth, UnitThickness * NoFlats));
 }
Beispiel #21
0
        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");
        }
Beispiel #22
0
        public void Draw(Graphics3D graphics)
        {
            if (null == _truckSolution)
            {
                throw new Exception("No trucksolution defined!");
            }
            // draw truck
            Truck truck = new Truck(_truckSolution.ParentTruckAnalysis.TruckProperties);

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

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

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

            // draw solution
            uint pickIdGlobal = 0;

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

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

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

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

            // fluch
            graphics.UseBoxelOrderer = false; // can not use boxel orderer for full truck view -> too slow...
        }
Beispiel #23
0
 internal void DrawWireFrame(Box box)
 {
 }
        public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
        {
            if (null == _dt)
                return;
            DataCase dtCase = _dt as DataCase;
            if (null != dtCase)
            {
                Box b = new Box(0, ToCase(dtCase));
                graphics.AddBox(b);
                graphics.AddDimensions(new DimensionCube(dtCase.OuterDimensions));
            }
            DataBox dtBox = _dt as DataBox;
            if (null != dtBox)
            {
                Box b = new Box(0, ToBox(dtBox));
                graphics.AddBox(b);
                graphics.AddDimensions(new DimensionCube(dtBox.Dimensions));
            }
            DataPallet dtPallet = _dt as DataPallet;
            if (null != dtPallet)
            {
                Pallet pallet = new Pallet(ToPallet(dtPallet));
                pallet.Draw(graphics, Sharp3D.Math.Core.Transform3D.Identity);
                graphics.AddDimensions(new DimensionCube(dtPallet.Dimensions));
            }
            DataInterlayer dtInterlayer = _dt as DataInterlayer;
            if (null != dtInterlayer)
            {
                graphics.AddBox(new Box(0, ToInterlayer(dtInterlayer)));
                graphics.AddDimensions(new DimensionCube(dtInterlayer.Dimensions));
            }

            DataPalletCap dtPalletCap = _dt as DataPalletCap;
            if (null != dtPalletCap)
            {
                PalletCap palletCap = new PalletCap(0, ToPalletCap(dtPalletCap), Sharp3D.Math.Core.Vector3D.Zero);
                palletCap.Draw(graphics);
                graphics.AddDimensions(new DimensionCube(dtPalletCap.Dimensions));
            }

            DataCylinder dtCylinder = _dt as DataCylinder;
            if (null != dtCylinder)
            {
                Cylinder cyl = new Cylinder(0, ToCylinder(dtCylinder));
                graphics.AddCylinder(cyl);
            }
        }
        /// <summary>
        ///  Use this method when solution does not refer an analysis (e.g. when displaying CaseOptimizer result)
        /// </summary>
        public static void Draw(Graphics3D graphics
            , CasePalletSolution solution
            , BoxProperties boxProperties, InterlayerProperties interlayerProperties, PalletProperties palletProperties)
        {
            // draw pallet
            Pallet pallet = new Pallet(palletProperties);
            pallet.Draw(graphics, Transform3D.Identity);
            // draw solution
            uint pickId = 0;
            foreach (ILayer layer in solution)
            {
                BoxLayer blayer = layer as BoxLayer;
                if (null != blayer)
                {
                    foreach (BoxPosition bPosition in blayer)
                        graphics.AddBox(new Box(pickId++, boxProperties, bPosition));
                }

                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos && null != interlayerProperties)
                {
                    Box box = new Box(pickId++, interlayerProperties);
                    // set position
                    box.Position = new Vector3D(
                        0.5 * (palletProperties.Length - interlayerProperties.Length)
                        , 0.5 * (palletProperties.Width - interlayerProperties.Width)
                        , interlayerPos.ZLow);
                    // draw
                    graphics.AddBox(box);
                }
            }
 
            // always show dimensions
            BoxLayer bLayer = solution[solution.Count - 1] as BoxLayer;
            double palletHeight = solution[solution.Count - 1].ZLow + (null != bLayer ? bLayer.Thickness(boxProperties) : 0.0);

            // show dimensions
            graphics.AddDimensions(new DimensionCube(solution.BoundingBox, Color.Black, false));
            graphics.AddDimensions(new DimensionCube(solution.LoadBoundingBox, Color.Red, true));
        }
Beispiel #26
0
 public void Draw(Graphics3D graphics, Vector3D dimensions, Color color, Transform3D t)
 {
     double coefX = dimensions.X / _defaultDimensions.X;
     double coefY = dimensions.Y / _defaultDimensions.Y;
     double coefZ = dimensions.Z / _defaultDimensions.Z;
     uint pickId = 0;
     foreach (Position pos in _positions)
     {
         double coef0 = coefX, coef1 = coefY, coef2 = coefZ;
         if (pos.Axis1 == HalfAxis.HAxis.AXIS_X_P && pos.Axis2 == HalfAxis.HAxis.AXIS_Y_P)
         { coef0 = coefX; coef1 = coefY; }
         else if (pos.Axis1 == HalfAxis.HAxis.AXIS_Y_P && pos.Axis2 == HalfAxis.HAxis.AXIS_X_N)
         { coef0 = coefY; coef1 = coefX; }
         Vector3D dim = _lumbers[pos.Index];
         Box box = new Box(pickId++, dim.X * coef0, dim.Y * coef1, dim.Z * coef2);
         box.SetAllFacesColor(color);
         box.Position = t.transform(new Vector3D(pos.XYZ.X * coefX, pos.XYZ.Y * coefY, pos.XYZ.Z * coefZ));
         box.LengthAxis = Basics.HalfAxis.ToVector3D(HalfAxis.Transform(pos.Axis1, t)); ;
         box.WidthAxis = Basics.HalfAxis.ToVector3D(HalfAxis.Transform(pos.Axis2, t)); ;
         graphics.AddBox(box);
     }
 }
        /// <summary>
        /// Use this method when drawing a solution that belongs an analysis
        /// </summary>
        public void Draw(Graphics3D graphics)
        {
            if (null == _solution)
                return;
            // initialize Graphics3D object
            if (!graphics.ShowBoxIds)
            {
                // draw pallet
                Pallet pallet = new Pallet(_analysis.PalletProperties);
                pallet.Draw(graphics, Transform3D.Identity);
            }
            // load bounding box
            BBox3D loadBBox = _solution.LoadBoundingBox; 
            BBox3D loadBBoxWDeco = _solution.LoadBoundingBoxWDeco;

            #region Pallet film : begin
            // draw film
            Film film = null;
            if (_solution.Analysis.HasPalletFilm)
            {
                PalletFilmProperties palletFilmProperties = _solution.Analysis.PalletFilmProperties;
                film = new Film(
                    palletFilmProperties.Color,
                    palletFilmProperties.UseTransparency,
                    palletFilmProperties.UseHatching,
                    palletFilmProperties.HatchSpacing,
                    palletFilmProperties.HatchAngle);
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin,
                    HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis,
                    HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis,
                    HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis,
                    HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0));
                film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis,
                    HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width),
                    UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1)));
                film.DrawBegin(graphics);
            }
            #endregion

            #region Pallet corners
            // *** pallet corners 
            // positions
            Vector3D[] cornerPositions =
            {
                loadBBox.PtMin
                , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z)
                , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
                , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z)
            };
            // length axes
            HalfAxis.HAxis[] lAxes =
            {
                HalfAxis.HAxis.AXIS_X_P,
                HalfAxis.HAxis.AXIS_Y_P,
                HalfAxis.HAxis.AXIS_X_N,
                HalfAxis.HAxis.AXIS_Y_N
            };
            // width axes
            HalfAxis.HAxis[] wAxes =
            {
                HalfAxis.HAxis.AXIS_Y_P,
                HalfAxis.HAxis.AXIS_X_N,
                HalfAxis.HAxis.AXIS_Y_N,
                HalfAxis.HAxis.AXIS_X_P
            };
            // corners
            Corner[] corners = new Corner[4];
            if (_solution.Analysis.HasPalletCorners)
            {
                for (int i = 0; i < 4; ++i)
                {
                    corners[i] = new Corner(0, _solution.Analysis.PalletCornerProperties);
                    corners[i].Height = Math.Min(_solution.Analysis.PalletCornerProperties.Length, loadBBox.Height);
                    corners[i].SetPosition(cornerPositions[i], lAxes[i], wAxes[i]);
                    corners[i].DrawBegin(graphics);
                }
            }
            // *** pallet corners : end
            #endregion

            // draw solution
            uint pickId = 0;
            foreach (ILayer layer in _solution)
            {
                BoxLayer blayer = layer as BoxLayer;
                if (null != blayer)
                {
                    foreach (BoxPosition bPosition in blayer)
                        graphics.AddBox(new Box(pickId++, _analysis.BProperties, bPosition));
                }

                InterlayerPos interlayerPos = layer as InterlayerPos;
                if (null != interlayerPos)
                {
                    InterlayerProperties currInterlayerProperties = (0 == interlayerPos.TypeId)
                        ? _analysis.InterlayerProperties : _analysis.InterlayerPropertiesAntiSlip;
                    Box box = new Box(pickId++, currInterlayerProperties);
                    // set position
                    box.Position = new Vector3D(
                        0.5 * (_analysis.PalletProperties.Length - currInterlayerProperties.Length)
                        , 0.5 * (_analysis.PalletProperties.Width - currInterlayerProperties.Width)
                        , interlayerPos.ZLow);
                    // draw
                    graphics.AddBox(box);
                }
            }

            if (_showDimensions)
            {
                graphics.AddDimensions(
                    new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1)
                    , Color.Black, false));
                graphics.AddDimensions(
                    new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2)
                    , Color.Red, true));
            }

            // pallet corners
            if (_solution.Analysis.HasPalletCorners)
            {
                for (int i = 0; i < 4; ++i)
                    corners[i].DrawEnd(graphics);
            }
            // pallet cap
            if (_solution.HasPalletCap)
            {
                PalletCapProperties capProperties = _solution.Analysis.PalletCapProperties;
                Vector3D pos = new Vector3D(
                    0.5 * (_analysis.PalletProperties.Length - capProperties.Length),
                    0.5 * (_analysis.PalletProperties.Width - capProperties.Width),
                    loadBBox.PtMax.Z - capProperties.InsideHeight);
                PalletCap cap = new PalletCap(0, capProperties, pos);
                cap.DrawEnd(graphics);
            }
            // pallet film
            if (_solution.Analysis.HasPalletFilm)
            {
                film.DrawEnd(graphics);
            }
            graphics.EnableFaceSorting = false;
        }
Beispiel #28
0
        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");
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            try
            {
                Graphics = new Graphics2DForm(this, e.Graphics);
                if (null == Layer)
                {
                    return;
                }
                Graphics.SetViewport(PtMin, PtMax);

                uint pickId = 0;
                foreach (var bp in Layer.Positions)
                {
                    Box b;
                    if (Content is PackProperties pack)
                    {
                        b = new Pack(pickId++, pack, bp);
                    }
                    else
                    {
                        b = new Box(pickId++, Content as PackableBrick, bp);
                    }
                    b.Draw(Graphics);
                }
                Graphics.DrawRectangle(Vector2D.Zero, Layer.DimContainer, Color.OrangeRed);

                if (-1 != SelectedIndex)
                {
                    var bp = Layer.Positions[SelectedIndex];

                    Box boxSelected;
                    if (Content is PackProperties pack)
                    {
                        boxSelected = new Pack((uint)SelectedIndex, pack, bp);
                    }
                    else
                    {
                        boxSelected = new Box(((uint)SelectedIndex), Content as PackableBrick, bp);
                    }
                    Graphics.DrawBoxSelected(boxSelected);

                    ArrowButtons.Clear();
                    Vector2D ptCenter = new Vector2D(boxSelected.Center.X, boxSelected.Center.Y);

                    // draw translation arrows
                    for (int i = 0; i < 4; ++i)
                    {
                        if (Arrows[i])
                        {
                            Graphics.DrawArrow(ptCenter, i, 100, 5, 10, Color.Red, out Rectangle rect);
                            ArrowButtons.Add(i, rect);
                        }
                    }
                    // draw rotation arrows
                    if (ArrowRotate)
                    {
                        Graphics.DrawArcArrow(ptCenter, 75, 10, Color.Red, out _rotateRectangle);
                    }

                    // draw position
                    Graphics.DrawText($"({bp.Position.X:0.##}, {bp.Position.Y:0.##}, {bp.Position.Z:0.##}), {HalfAxis.ToString(bp.DirectionLength)}, {HalfAxis.ToString(bp.DirectionWidth)}", 16);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Beispiel #30
0
        protected mesh CreateCaseMesh(BoxProperties caseProperties)
        {
            // build box
            Box box = new Box(0, caseProperties);
            // build list of vertices / normals / UVs
            ulong vertexCount = 0, normalCount = 0, uvCount = 0;
            List<double> doubleArrayPosition = new List<double>(), doubleArrayNormal = new List<double>(), doubleArrayUV = new List<double>();
            foreach (Vector3D p in box.PointsSmallOffset)
            {
                doubleArrayPosition.Add(p.X); doubleArrayPosition.Add(p.Y); doubleArrayPosition.Add(p.Z);
                ++vertexCount;
            }
            foreach (Vector3D n in box.Normals)
            {
                doubleArrayNormal.Add(n.X); doubleArrayNormal.Add(n.Y); doubleArrayNormal.Add(n.Z);
                ++normalCount;
            }
            foreach (Vector2D uv in box.UVs)
            {
                doubleArrayUV.Add(uv.X); doubleArrayUV.Add(uv.Y);
                ++uvCount;
            }

            mesh caseMesh = new mesh();

            // position source
            source casePositionSource = new source() { id = "case_position", name = "case_position" };
            float_array farrayPosition = new float_array { id = "case_position_float_array", count = (ulong)doubleArrayPosition.Count, Values = doubleArrayPosition.ToArray() };
            casePositionSource.technique_common = new sourceTechnique_common()
            {
                accessor = new accessor()
                {
                    stride = 3,
                    count = vertexCount,
                    source = "#case_position_float_array",
                    param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } }
                }
            };
            casePositionSource.Item = farrayPosition;

            // normal source
            source casePositionNormal = new source() { id = "case_normal", name = "case_normal" };
            float_array farrayNormal = new float_array { id = "case_normal_float_array", count = (ulong)doubleArrayNormal.Count, Values = doubleArrayNormal.ToArray() };
            casePositionNormal.technique_common = new sourceTechnique_common()
            {
                accessor = new accessor()
                {
                    stride = 3,
                    count = normalCount,
                    source = "#case_normal_float_array",
                    param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } }
                }
            };
            casePositionNormal.Item = farrayNormal;

            // uv source
            source casePositionUV = new source() { id = "case_UV", name = "pallet_UV" };
            float_array farrayUV = new float_array { id = "case_UV_float_array", count = (ulong)doubleArrayUV.Count, Values = doubleArrayUV.ToArray() };
            casePositionUV.technique_common = new sourceTechnique_common()
            {
                accessor = new accessor()
                {
                    stride = 2,
                    count = vertexCount,
                    source = "#case_UV_float_array",
                    param = new param[] { new param() { name = "S", type = "float" }, new param() { name = "T", type = "float" } }
                }
            };
            casePositionUV.Item = farrayUV;
            // insert sources
            caseMesh.source = new source[] { casePositionSource, casePositionNormal, casePositionUV };

            // vertices
            InputLocal verticesInput = new InputLocal() { semantic = "POSITION", source = "#case_position" };
            caseMesh.vertices = new vertices() { id = "case_vertex", input = new InputLocal[] { verticesInput } };

            List<object> trianglesList = new List<object>();

            // build list of triangles
            foreach (HalfAxis.HAxis axis in HalfAxis.All)
            {
                triangles trianglesCase = new triangles() { material = string.Format("materialCase{0}", (uint)axis), count = 2 };
                trianglesCase.input = new InputLocalOffset[]
                                    {
                                        new InputLocalOffset() { semantic="VERTEX", source="#case_vertex", offset=0}
                                        , new InputLocalOffset() { semantic="NORMAL", source="#case_normal", offset=1}
                                        , new InputLocalOffset() { semantic="TEXCOORD", source="#case_UV", offset=2, set=0, setSpecified=true }
                                    };
                string triangle_string = string.Empty;
                foreach (TriangleIndices tr in box.TrianglesByFace(axis))
                    triangle_string += tr.ConvertToString(0);
                trianglesCase.p = triangle_string;
                trianglesList.Add(trianglesCase);
            }
            // build list of lines
            lines linesCase = new lines()
            {
                material = "materialCaseLines",
                count = 12,
                input = new InputLocalOffset[]
                {
                    new InputLocalOffset() { semantic="VERTEX", source="#case_vertex", offset=0}
                },
                p = "0 1 1 2 2 3 3 0 4 5 5 6 6 7 7 4 0 4 1 5 2 6 3 7"
            };
            trianglesList.Add(linesCase);

            caseMesh.Items = trianglesList.ToArray();
            return caseMesh;
        }
Beispiel #31
0
        private void SortLayer(ref List <Box> layerList)
        {
            foreach (Box b in layerList)
            {
                b.ApplyElong(-_tuneParam);
            }

            // build y list
            List <double> yList = new List <double>();

            foreach (Box b in layerList)
            {
                if (!yList.Contains(b.PtMin.Y))
                {
                    yList.Add(b.PtMin.Y);
                }
                if (!yList.Contains(b.PtMax.Y))
                {
                    yList.Add(b.PtMax.Y);
                }
            }
            yList.Sort();
            if (_direction.Y < 0)
            {
                yList.Reverse();
            }

            List <Box> treeList = new List <Box>();
            List <Box> resList  = new List <Box>();

            // sweep stage
            foreach (double y in yList)
            {
                // clean treelist
                if (_direction.Y > 0.0)
                {
                    CleanByYMax(treeList, y);
                    // add new
                    List <Box> listYMin = GetByYMin(layerList, y);

                    foreach (Box by in listYMin)
                    {
                        treeList.Add(by);
                        if (_direction.X > 0.0)
                        {
                            treeList.Sort(new BoxComparerXMin(_direction));
                        }
                        else
                        {
                            treeList.Sort(new BoxComparerXMax(_direction));
                        }

                        // find successor of by
                        int id = treeList.FindIndex(delegate(Box b) { return(b.PickId == by.PickId); });
                        Box successor = null;
                        if (id < treeList.Count - 1)
                        {
                            successor = treeList[id + 1];
                        }

                        // insert by
                        if (null == successor)
                        {
                            resList.Add(by);
                        }
                        else
                        {
                            int idBefore = resList.FindIndex(delegate(Box b) { return(b.PickId == successor.PickId); });
                            resList.Insert(idBefore, by);
                        }
                    }
                }
                else
                {
                    CleanByYMin(treeList, y);
                    // add new
                    List <Box> listYMax = GetByYMax(layerList, y);

                    foreach (Box by in listYMax)
                    {
                        treeList.Add(by);
                        if (_direction.X > 0.0)
                        {
                            treeList.Sort(new BoxComparerXMin(_direction));
                        }
                        else
                        {
                            treeList.Sort(new BoxComparerXMax(_direction));
                        }

                        // find successor of by
                        int id = treeList.FindIndex(delegate(Box b) { return(b.PickId == by.PickId); });
                        Box successor = null;
                        if (id < treeList.Count - 1)
                        {
                            successor = treeList[id + 1];
                        }

                        // insert by
                        if (null == successor)
                        {
                            resList.Add(by);
                        }
                        else
                        {
                            int idBefore = resList.FindIndex(delegate(Box b) { return(b.PickId == successor.PickId); });
                            resList.Insert(idBefore, by);
                        }
                    }
                }
            }

            layerList.Clear();
            resList.Reverse();
            layerList.AddRange(resList);

            foreach (Box b in layerList)
            {
                b.ApplyElong(_tuneParam);
            }
        }
Beispiel #32
0
        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());
            }
        }
Beispiel #33
0
        /// <summary>
        /// Draw all entities stored in buffer
        /// </summary>
        public void Flush()
        {
            // initialize
            Vector3D vLight = _vCameraPos - _vTarget; vLight.Normalize();

            _boxDrawingCounter = 0;
            _currentTransf     = null;
            System.Drawing.Graphics g = Graphics;
            g.Clear(_backgroundColor);

            if (EnableFaceSorting)
            {
                // sort face list
                FaceComparison faceComparer = new FaceComparison(GetWorldToEyeTransformation());
                _faces.Sort(faceComparer);
            }
            // draw background segments
            foreach (Segment s in _segmentsBackground)
            {
                Draw(s);
            }
            // draw background faces
            foreach (Face face in _facesBackground)
            {
                Draw(face, FaceDir.FRONT);
            }
            // draw all faces using solid / transparency depending on
            foreach (Face face in _faces)
            {
                Draw(face, FaceDir.BACK);
            }

            // sort box list
            if (_useBoxelOrderer)
            {
                BoxelOrderer boxelOrderer = new BoxelOrderer(_boxes);
                boxelOrderer.Direction = _vTarget - _vCameraPos;
                _boxes = boxelOrderer.GetSortedList();
            }
            else
            {
                _boxes.Sort(new BoxComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));
            }

            // sort cylinder list
            _cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));

            if (_cylinders.Count > 0)
            {
                // sort by Z
                List <Drawable> drawableList = new List <Drawable>();
                drawableList.AddRange(_boxes);
                drawableList.AddRange(_cylinders);
                drawableList.Sort(new DrawableComparerSimplifiedPainterAlgo());

                List <Box>      boxes         = new List <Box>();
                List <Cylinder> cylinders     = new List <Cylinder>();
                bool            processingBox = drawableList[0] is Box;
                foreach (Drawable drawable in drawableList)
                {
                    Box      b = drawable as Box;
                    Cylinder c = drawable as Cylinder;

                    if ((null != b) && processingBox)
                    {
                        boxes.Add(b);
                    }
                    else if ((null == b) && !processingBox)
                    {
                        cylinders.Add(c);
                    }
                    else
                    {
                        if (boxes.Count > 0)
                        {
                            BoxelOrderer boxelOrderer = new BoxelOrderer(boxes);
                            boxelOrderer.Direction = _vTarget - _vCameraPos;
                            boxes = boxelOrderer.GetSortedList();
                            // draw boxes
                            foreach (Box bb in boxes)
                            {
                                Draw(bb);
                            }
                            // clear
                            boxes.Clear();
                        }
                        if (cylinders.Count > 0)
                        {
                            cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));
                            // draw cylinders
                            foreach (Cylinder cc in cylinders)
                            {
                                Draw(cc);
                            }
                            // clear
                            cylinders.Clear();
                        }
                        if (null != b)
                        {
                            boxes.Add(b);
                            processingBox = true;
                        }
                        else
                        {
                            cylinders.Add(c);
                            processingBox = false;
                        }
                    }
                }

                // remaining boxes
                BoxelOrderer boxelOrdererRem = new BoxelOrderer(boxes);
                boxelOrdererRem.Direction = _vTarget - _vCameraPos;
                boxes = boxelOrdererRem.GetSortedList();
                // draw boxes
                foreach (Box bb in boxes)
                {
                    Draw(bb);
                }

                // remaining cylinders
                cylinders.Sort(new CylinderComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));
                // draw cylinders
                foreach (Cylinder cc in cylinders)
                {
                    Draw(cc);
                }
                // clear
                boxes.Clear();
            }
            else
            {
                // draw all boxes
                foreach (Box box in _boxes)
                {
                    Draw(box);
                }
            }
            // images inst
            if (_listImageInst.Count > 0)
            {
                // --- sort image inst
                Analysis   analysis   = _listImageInst[0].Analysis;
                BBox3D     bbox       = analysis.Solution.BBoxGlobal;
                List <Box> boxesImage = new List <Box>();
                foreach (ImageInst imageInst in _listImageInst)
                {
                    boxesImage.Add(imageInst.ToBox());
                }

                if (_useBoxelOrderer && false) // NOT WORKING ?
                {
                    BoxelOrderer boxelOrderer = new BoxelOrderer(boxesImage);
                    boxelOrderer.TuneParam = 10.0;
                    boxelOrderer.Direction = _vTarget - _vCameraPos;
                    boxesImage             = boxelOrderer.GetSortedList();
                }
                else
                {
                    boxesImage.Sort(new BoxComparerSimplifiedPainterAlgo(GetWorldToEyeTransformation()));
                }
                // ---

                List <ImageInst> listImageInstSorted = new List <ImageInst>();
                foreach (Box b in boxesImage)
                {
                    listImageInstSorted.Add(new ImageInst(analysis, new Vector3D(b.Length, b.Width, b.Height), b.BPosition));
                }

                // draw image inst
                foreach (ImageInst im in listImageInstSorted)
                {
                    Draw(im);
                }
            }
            // draw faces : end
            foreach (Face face in _faces)
            {
                Draw(face, FaceDir.FRONT);
            }

            // draw segment list (e.g. hatching)
            foreach (Segment seg in _segments)
            {
                Draw(seg);
            }

            // draw cotation cubes
            if (ShowDimensions)
            {
                foreach (DimensionCube qc in _dimensions)
                {
                    qc.Draw(this);
                }
            }
        }
Beispiel #34
0
        static void Main(string[] args)
        {
            // instantiate
            BoxelOrderer orderer0 = new BoxelOrderer();

            // fill BoxelOrderer class
            Box b0 = new Box(0, 400.0, 300.0, 200.0);
            b0.Position = new Vector3D(300.0, 0.0, 0.0);
            b0.LengthAxis = Vector3D.YAxis;
            b0.WidthAxis = -Vector3D.XAxis;
            orderer0.Add(b0);
            Box b1 = new Box(1, 400.0, 300.0, 200.0);
            b1.Position = new Vector3D(600.0, 0.0, 0.0);
            b1.LengthAxis = Vector3D.YAxis;
            b1.WidthAxis = -Vector3D.XAxis;
            orderer0.Add(b1);
            Box b2 = new Box(2, 400.0, 300.0, 200.0);
            b2.Position = new Vector3D(300.0, 400.0, 0.0);
            b2.LengthAxis = Vector3D.YAxis;
            b2.WidthAxis = -Vector3D.XAxis;
            orderer0.Add(b2);
            Box b3 = new Box(3, 400.0, 300.0, 200.0);
            b3.Position = new Vector3D(600.0, 400.0, 0.0);
            b3.LengthAxis = Vector3D.YAxis;
            b3.WidthAxis = -Vector3D.XAxis;
            orderer0.Add(b3);
            Box b4 = new Box(4, 400.0, 300.0, 200.0);
            b4.Position = new Vector3D(300.0, 800.0, 0.0);
            b4.LengthAxis = Vector3D.YAxis;
            b4.WidthAxis = -Vector3D.XAxis;
            orderer0.Add(b4);
            Box b5 = new Box(5, 400.0, 300.0, 200.0);
            b5.Position = new Vector3D(600.0, 800.0, 0.0);
            b5.LengthAxis = Vector3D.YAxis;
            b5.WidthAxis = -Vector3D.XAxis;
            orderer0.Add(b5);

            Box b6 = new Box(6, 400.0, 300.0, 200.0);
            b6.Position = new Vector3D(600.0, 0.0, 0.0);
            b6.LengthAxis = Vector3D.XAxis;
            b6.WidthAxis = Vector3D.YAxis;
            orderer0.Add(b6);
            Box b7 = new Box(7, 400.0, 300.0, 200.0);
            b7.Position = new Vector3D(600.0, 300.0, 0.0);
            b7.LengthAxis = Vector3D.XAxis;
            b7.WidthAxis = Vector3D.YAxis;
            orderer0.Add(b7);
            Box b8 = new Box(8, 400.0, 300.0, 200.0);
            b8.Position = new Vector3D(600.0, 600.0, 0.0);
            b8.LengthAxis = Vector3D.XAxis;
            b8.WidthAxis = Vector3D.YAxis;
            orderer0.Add(b8);
            Box b9 = new Box(9, 400.0, 300.0, 200.0);
            b9.Position = new Vector3D(600.0, 900.0, 0.0);
            b9.LengthAxis = Vector3D.XAxis;
            b9.WidthAxis = Vector3D.YAxis;
            orderer0.Add(b9);


            Vector3D target = Vector3D.Zero;

            // set direction 0
            Vector3D camera = new Vector3D(-1000.0, -1000.0, 1000.0);
            orderer0.Direction = target - camera;
            List<Box> orderedList = orderer0.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 1
            camera = new Vector3D(1000.0, -1000.0, 1000.0);
            orderer0.Direction = target - camera;
            orderedList = orderer0.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 2
            camera = new Vector3D(1000.0, 1000.0, 1000.0);
            orderer0.Direction = target - camera;
            orderedList = orderer0.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 3
            camera = new Vector3D(-1000.0, 1000.0, 1000.0);
            orderer0.Direction = target - camera;
            orderedList = orderer0.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();
            Console.WriteLine("########################################################");


            // instantiate
            BoxelOrderer orderer1 = new BoxelOrderer();
            // fill BoxelOrderer class
             Box b16 = new Box(0, 400.0, 300.0, 200.0);
            b16.Position = new Vector3D(0.0, 0.0, 0.0);
            b16.LengthAxis = Vector3D.XAxis;
            b16.WidthAxis = Vector3D.YAxis;
            orderer1.Add(b16);
            Box b17 = new Box(1, 400.0, 300.0, 200.0);
            b17.Position = new Vector3D(0.0, 300.0, 0.0);
            b17.LengthAxis = Vector3D.XAxis;
            b17.WidthAxis = Vector3D.YAxis;
            orderer1.Add(b17);
            Box b18 = new Box(2, 400.0, 300.0, 200.0);
            b18.Position = new Vector3D(0.0, 600.0, 0.0);
            b18.LengthAxis = Vector3D.XAxis;
            b18.WidthAxis = Vector3D.YAxis;
            orderer1.Add(b18);
            Box b19 = new Box(3, 400.0, 300.0, 200.0);
            b19.Position = new Vector3D(0.0, 900.0, 0.0);
            b19.LengthAxis = Vector3D.XAxis;
            b19.WidthAxis = Vector3D.YAxis;
            orderer1.Add(b19);

            Box b10 = new Box(4, 400.0, 300.0, 200.0);
            b10.Position = new Vector3D(700.0, 0.0, 0.0);
            b10.LengthAxis = Vector3D.YAxis;
            b10.WidthAxis = -Vector3D.XAxis;
            orderer1.Add(b10);
            Box b11 = new Box(5, 400.0, 300.0, 200.0);
            b11.Position = new Vector3D(1000.0, 0.0, 0.0);
            b11.LengthAxis = Vector3D.YAxis;
            b11.WidthAxis = -Vector3D.XAxis;
            orderer1.Add(b11);
            Box b12 = new Box(6, 400.0, 300.0, 200.0);
            b12.Position = new Vector3D(700.0, 400.0, 0.0);
            b12.LengthAxis = Vector3D.YAxis;
            b12.WidthAxis = -Vector3D.XAxis;
            orderer1.Add(b12);
            Box b13 = new Box(7, 400.0, 300.0, 200.0);
            b13.Position = new Vector3D(1000.0, 400.0, 0.0);
            b13.LengthAxis = Vector3D.YAxis;
            b13.WidthAxis = -Vector3D.XAxis;
            orderer1.Add(b13);
            Box b14 = new Box(8, 400.0, 300.0, 200.0);
            b14.Position = new Vector3D(700.0, 800.0, 0.0);
            b14.LengthAxis = Vector3D.YAxis;
            b14.WidthAxis = -Vector3D.XAxis;
            orderer1.Add(b14);
            Box b15 = new Box(9, 400.0, 300.0, 200.0);
            b15.Position = new Vector3D(1000.0, 800.0, 0.0);
            b15.LengthAxis = Vector3D.YAxis;
            b15.WidthAxis = -Vector3D.XAxis;
            orderer1.Add(b15);


            // set direction 0
            camera = new Vector3D(-1000.0, -1000.0, 1000.0);
            orderer1.Direction = target - camera;
            orderedList = orderer1.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 1
            camera = new Vector3D(1000.0, -1000.0, 1000.0);
            orderer1.Direction = target - camera;
            orderedList = orderer1.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 2
            camera = new Vector3D(1000.0, 1000.0, 1000.0);
            orderer1.Direction = target - camera;
            orderedList = orderer1.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 3
            camera = new Vector3D(-1000.0, 1000.0, 1000.0);
            orderer1.Direction = target - camera;
            orderedList = orderer1.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();
            Console.WriteLine("########################################################");


            // #####################################################################################
            // instantiate
            BoxelOrderer orderer3 = new BoxelOrderer();
            // fill BoxelOrderer class
            Box b_0 = new Box(0, 400.0, 300.0, 200.0);
            b_0.Position = new Vector3D(1200.0, 0.0, 200.0);
            b_0.LengthAxis = Vector3D.YAxis;
            b_0.WidthAxis = -Vector3D.XAxis;
            orderer3.Add(b_0);
            Box b_1 = new Box(1, 400.0, 300.0, 200.0);
            b_1.Position = new Vector3D(900.0, 0.0, 200.0);
            b_1.LengthAxis = Vector3D.YAxis;
            b_1.WidthAxis = -Vector3D.XAxis;
            orderer3.Add(b_1);
            Box b_2 = new Box(2, 400.0, 300.0, 200.0);
            b_2.Position = new Vector3D(600.0, 0.0, 200.0);
            b_2.LengthAxis = Vector3D.YAxis;
            b_2.WidthAxis = -Vector3D.XAxis;
            orderer3.Add(b_2);
            Box b_3 = new Box(3, 400.0, 300.0, 200.0);
            b_3.Position = new Vector3D(300.0, 0.0, 200.0);
            b_3.LengthAxis = Vector3D.YAxis;
            b_3.WidthAxis = -Vector3D.XAxis;
            orderer3.Add(b_3);

            Box b_4 = new Box(4, 400.0, 300.0, 200.0);
            b_4.Position = new Vector3D(1200.0, 700.0, 200.0);
            b_4.LengthAxis = -Vector3D.XAxis;
            b_4.WidthAxis = -Vector3D.YAxis;
            orderer3.Add(b_4);
            Box b_5 = new Box(5, 400.0, 300.0, 200.0);
            b_5.Position = new Vector3D(800.0, 700.0, 200.0);
            b_5.LengthAxis = -Vector3D.XAxis;
            b_5.WidthAxis = -Vector3D.YAxis;
            orderer3.Add(b_5);
            Box b_6 = new Box(6, 400.0, 300.0, 200.0);
            b_6.Position = new Vector3D(400.0, 700.0, 200.0);
            b_6.LengthAxis = -Vector3D.XAxis;
            b_6.WidthAxis = -Vector3D.YAxis;
            orderer3.Add(b_6);
            Box b_7 = new Box(7, 400.0, 300.0, 200.0);
            b_7.Position = new Vector3D(1200.0, 1000.0, 200.0);
            b_7.LengthAxis = -Vector3D.XAxis;
            b_7.WidthAxis = -Vector3D.YAxis;
            orderer3.Add(b_7);
            Box b_8 = new Box(8, 400.0, 300.0, 200.0);
            b_8.Position = new Vector3D(800.0, 1000.0, 200.0);
            b_8.LengthAxis = -Vector3D.XAxis;
            b_8.WidthAxis = -Vector3D.YAxis;
            orderer3.Add(b_8);
            Box b_9 = new Box(9, 400.0, 300.0, 200.0);
            b_9.Position = new Vector3D(400.0, 1000.0, 200.0);
            b_9.LengthAxis = -Vector3D.XAxis;
            b_9.WidthAxis = -Vector3D.YAxis;
            orderer3.Add(b_9);


            // set direction 0
            camera = new Vector3D(-1000.0, -1000.0, 1000.0);
            orderer3.Direction = target - camera;
            orderedList = orderer3.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 1
            camera = new Vector3D(1000.0, -1000.0, 1000.0);
            orderer3.Direction = target - camera;
            orderedList = orderer3.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 2
            camera = new Vector3D(1000.0, 1000.0, 1000.0);
            orderer3.Direction = target - camera;
            orderedList = orderer3.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();

            // set direction 3
            camera = new Vector3D(-1000.0, 1000.0, 1000.0);
            orderer3.Direction = target - camera;
            orderedList = orderer3.GetSortedList();
            Console.WriteLine("******************************");
            foreach (Box b in orderedList)
                Console.Write("{0} ", b.PickId);
            Console.WriteLine();
            Console.WriteLine("########################################################");
        }
Beispiel #35
0
        internal void Draw(Box box)
        {
            System.Drawing.Graphics g = Graphics;

            if (box is Pack)
            {
                Pack pack = box as Pack;
                pack.Draw(this);
            }
            else
            {
                Vector3D[] points = box.Points;

                Face[] faces = box.Faces;
                for (int i = 0; i < 6; ++i)
                {
                    // Face
                    Face face = faces[i];
                    // face normal
                    Vector3D normal = face.Normal;
                    // visible ?
                    if (!faces[i].IsVisible(_vTarget - _vCameraPos))
                    {
                        continue;
                    }
                    // color
                    faces[i].ColorFill = box.Colors[i];
                    double cosA  = System.Math.Abs(Vector3D.DotProduct(faces[i].Normal, VLight));
                    Color  color = Color.FromArgb((int)(faces[i].ColorFill.R * cosA), (int)(faces[i].ColorFill.G * cosA), (int)(faces[i].ColorFill.B * cosA));
                    // points
                    Vector3D[] points3D = faces[i].Points;
                    Point[]    pt       = TransformPoint(GetCurrentTransformation(), points3D);
                    //  draw solid face
                    Brush brush = new SolidBrush(color);
                    g.FillPolygon(brush, pt);
                    // draw textures
                    if (null != face.Textures && ShowTextures)
                    {
                        foreach (Texture texture in face.Textures)
                        {
                            Point[] ptsImage = TransformPoint(GetCurrentTransformation(), box.PointsImage(i, texture));
                            Point[] pts      = new Point[3];
                            pts[0] = ptsImage[3];
                            pts[1] = ptsImage[2];
                            pts[2] = ptsImage[0];
                            g.DrawImage(texture.Bitmap, pts);
                        }
                    }
                    // draw path
                    Brush brushPath    = new SolidBrush(faces[i].ColorPath);
                    Pen   penPathThick = new Pen(brushPath, box.IsBundle ? 2.0f : 1.5f);
                    int   ptCount      = pt.Length;
                    for (int j = 1; j < ptCount; ++j)
                    {
                        g.DrawLine(penPathThick, pt[j - 1], pt[j]);
                    }
                    g.DrawLine(penPathThick, pt[ptCount - 1], pt[0]);
                    // draw bundle lines
                    if (box.IsBundle && i < 4)
                    {
                        Pen penPathThin = new Pen(brushPath, 1.5f);
                        int noSlice     = Math.Min(box.BundleFlats, 4);
                        for (int iSlice = 0; iSlice < noSlice - 1; ++iSlice)
                        {
                            Vector3D[] ptSlice = new Vector3D[2];
                            ptSlice[0] = points3D[0] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[3] - points3D[0]);
                            ptSlice[1] = points3D[1] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[2] - points3D[1]);

                            Point[] pt2D = TransformPoint(GetCurrentTransformation(), ptSlice);
                            g.DrawLine(penPathThin, pt2D[0], pt2D[1]);
                        }
                    }
                }

                // draw box tape
                if (box.ShowTape && faces[5].IsVisible(_vTarget - _vCameraPos))
                {
                    // get color
                    double cosA  = System.Math.Abs(Vector3D.DotProduct(faces[5].Normal, VLight));
                    Color  color = Color.FromArgb((int)(box.TapeColor.R * cosA), (int)(box.TapeColor.G * cosA), (int)(box.TapeColor.B * cosA));
                    // instantiate brush
                    Brush brushTape = new SolidBrush(color);
                    // get tape points
                    Point[] pts = TransformPoint(GetCurrentTransformation(), box.TapePoints);
                    // fill polygon
                    g.FillPolygon(brushTape, pts);
                    // draw path
                    Brush brushPath    = new SolidBrush(faces[5].ColorPath);
                    Pen   penPathThick = new Pen(brushPath, 1.5f);
                    int   ptCount      = pts.Length;
                    for (int j = 1; j < ptCount; ++j)
                    {
                        g.DrawLine(penPathThick, pts[j - 1], pts[j]);
                    }
                    g.DrawLine(penPathThick, pts[ptCount - 1], pts[0]);
                }
            }
            if (_showBoxIds)
            {
                // draw box id
                Point ptId = TransformPoint(GetCurrentTransformation(), box.TopFace.Center);
                g.DrawString(
                    box.PickId.ToString()
                    , new Font("Arial", GridFontSize)
                    , Brushes.Black
                    , new Rectangle(ptId.X - 15, ptId.Y - 10, 30, 20)
                    , StringFormat.GenericDefault);
                g.DrawString(
                    _boxDrawingCounter.ToString()
                    , new Font("Arial", GridFontSize)
                    , Brushes.Red
                    , new Rectangle(ptId.X + 5, ptId.Y - 10, 30, 20)
                    , StringFormat.GenericDefault);
            }
            ++_boxDrawingCounter;
        }
Beispiel #36
0
 public void Add(Box b)
 {
     _boxes.Add(b);
 }
Beispiel #37
0
        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");
        }