public override void UpdateGrid() { if (gridSolutions.ColumnsCount < 2 && gridSolutions.Rows.Count < 4) { return; } CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White); BBox3D bboxGlobal = _solution.BBoxGlobal; BBox3D bboxLoad = _solution.BBoxLoad; int iRow = 0; gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(_solution.InterlayerCount); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(_solution.ItemCount); for (int i = 0; i < iRow; ++i) { gridSolutions[i, 1].View = viewNormal; gridSolutions[i, 1].View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; } gridSolutions.AutoStretchColumnsToFitWidth = true; gridSolutions.AutoSizeCells(); gridSolutions.Invalidate(); }
internal void GetCachedBitmap(ImageInst img, ref Bitmap bmp, ref Point offset) { ImageCached imgCached = _listImageCached.Find(delegate(ImageCached imgc) { return(imgc.Matches(img)); }); if (null == imgCached) { imgCached = new ImageCached(img.Analysis, img.AxisLength, img.AxisWidth); _listImageCached.Add(imgCached); } AnalysisHomo analysis = imgCached.Analysis; // *** get size in pixels int xmin = int.MaxValue, ymin = int.MaxValue, xmax = int.MinValue, ymax = int.MinValue; BBox3D bbox = analysis.Solution.BBoxGlobal; foreach (Vector3D vPt in bbox.Corners) { Point pt = TransformPoint(GetCurrentTransformation() * imgCached.RelativeTransf, vPt); xmin = Math.Min(xmin, pt.X); xmax = Math.Max(xmax, pt.X); ymin = Math.Min(ymin, pt.Y); ymax = Math.Max(ymax, pt.Y); } Size s = new Size(xmax - xmin + 1, ymax - ymin + 1); // *** Point ptZero = TransformPoint(GetCurrentTransformation(), Vector3D.Zero); bmp = imgCached.Image(s, CameraPosition, Target, ref offset); }
private void UpdateGrid() { if (gridSolutions.ColumnsCount < 2 && gridSolutions.Rows.Count < 4) { return; } CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White); BBox3D bboxGlobal = _solution.BBoxGlobal; BBox3D bboxLoad = _solution.BBoxLoad; int iRow = 0; gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(_solution.InterlayerCount); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(_solution.ItemCount); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxGlobal.Length, bboxGlobal.Width, bboxGlobal.Height)); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); gridSolutions[iRow++, 1] = new SourceGrid.Cells.Cell(string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); for (int i = 0; i < iRow; ++i) { gridSolutions[i, 1].View = viewNormal; gridSolutions[i, 1].View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; } gridSolutions.AutoStretchColumnsToFitWidth = true; gridSolutions.AutoSizeCells(); gridSolutions.Invalidate(); }
public static IEnumerable <Face3d> DrawCuboid(this BBox3D bbox, DxfObject dxfObj, Layer layer = null) { var ents = bbox.ToFace3DList().ToList(); dxfObj.AddEntities(ents, layer); return(ents); }
/// <summary> /// tries to zoom dxf viewport on the given bbox /// </summary> public static void AutoZoom(this DxfDocument dxf, BBox3D bbox) { var bbox_center = (bbox.Min + bbox.Max) / 2; var bbox_size = bbox.Max - bbox.Min; dxf.Viewport.ViewCenter = new Vector2(bbox.Min.X, bbox_center.Y); dxf.Viewport.ViewAspectRatio = bbox_size.X / (bbox_size.Y * 2); }
public BBox3D GetBBox(Transform3D transf) { BBox3D bbox = new BBox3D(); foreach (var pt in Points) { bbox.Extend(transf.transform(pt)); } return(bbox); }
public static string CadScript(this BBox3D bbox) { var sb = new StringBuilder(); foreach (var x in bbox.ToFace3DList()) { sb.AppendLine(x.CadScript()); } return(sb.ToString()); }
public static BBox3D BBox(this IEnumerable <EntityObject> ents) { var bbox = new BBox3D(); foreach (var x in ents) { bbox = bbox.Union(x.BBox()); } return(bbox); }
public static BBox3D BBox(this IEnumerable <Geometry> geometry_block, double tol_len, double tol_rad) { var bbox = new BBox3D(); foreach (var x in geometry_block) { bbox = bbox.Union(x.BBox(tol_len, tol_rad)); } return(bbox); }
public bool EqualsTol(double tol, BBox3D other) { if (IsEmpty) { return(other.IsEmpty); } if (other.IsEmpty) { return(false); } return(Min.EqualsTol(tol, other.Min) && Max.EqualsTol(tol, other.Max)); }
public BBox3D Union(BBox3D other) { if (IsEmpty) { return(other); } if (other.IsEmpty) { return(this); } return(this.Union(other.Min).Union(other.Max)); }
public static void DrawILayer(Graphics3D graphics, ILayer layer, Packable packable, bool showDimensions) { bool show3D = Properties.Settings.Default.LayerView3D; graphics.CameraPosition = show3D ? Graphics3D.Corner_0 : Graphics3D.Top; uint pickId = 0; BBox3D bbox = new BBox3D(); // ### layer of boxes ### if (layer is Layer3DBox layerBox) { foreach (BoxPosition bPosition in layerBox) { Box b = null; if (packable is PackProperties) { b = new Pack(pickId++, packable as PackProperties, bPosition); } else { b = new Box(pickId++, packable as PackableBrick, bPosition); } graphics.AddBox(b); bbox.Extend(b.BBox); } } // ### // ### layer of cylinders ### if (layer is Layer3DCyl layerCyl) { foreach (Vector3D vPos in layerCyl) { Cyl cyl = null; if (packable is CylinderProperties cylinderProp) { cyl = new Cylinder(pickId++, cylinderProp, new CylPosition(vPos, HalfAxis.HAxis.AXIS_Z_P)); } else if (packable is BottleProperties bottleProp) { cyl = new Bottle(pickId++, bottleProp, new CylPosition(vPos, HalfAxis.HAxis.AXIS_Z_P)); } graphics.AddCylinder(cyl); bbox.Extend(cyl.BBox); } } // ### if (showDimensions) { graphics.AddDimensions(new DimensionCube(bbox, Color.Black, false)); } }
public bool Contains(double tol, BBox3D other) { if (IsEmpty) { return(false); } if (other.IsEmpty) { return(true); } return (other.Min.X.GreatThanOrEqualsTol(tol, Min.X) && other.Min.Y.GreatThanOrEqualsTol(tol, Min.Y) && other.Min.Z.GreatThanOrEqualsTol(tol, Min.Z) && other.Max.X.LessThanOrEqualsTol(tol, Max.X) && other.Max.Y.LessThanOrEqualsTol(tol, Max.Y) && other.Max.Z.LessThanOrEqualsTol(tol, Max.Z)); }
void BBox3DTest() { var tolLen = model.MUDomain.Length.DefaultTolerance; var pts = Vector3D.From3DCoords( 1, 5, 8, -2, -.5, 9, 10, .5, .9); var bbox = pts.BBox(); Assert.True(bbox.Min.EqualsTol(tolLen, -2, -.5, .9)); Assert.True(bbox.Max.EqualsTol(tolLen, 10, 5, 9)); var bbox2 = new BBox3D().Union(new Vector3D(1, 2, 3)); Assert.True(bbox.EqualsTol(tolLen, bbox.Union(bbox2))); Assert.True(bbox.Contains(tolLen, bbox2)); }
public void Draw(Graphics2D graphics) { if (null == _solution || _solution.LayerCount == 0) { return; } BoxLayer blayer = _solution.Layer; if (blayer != null) { // initialize Graphics2D object graphics.NumberOfViews = 1; BBox3D bbox = blayer.BoundingBox(_analysis.PackProperties); graphics.SetViewport(0.0f, 0.0f, (float)bbox.Length, (float)bbox.Width); graphics.SetCurrentView(0); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, _analysis.PalletProperties.Width), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer) { graphics.DrawBox(new Box(pickId++, _analysis.PackProperties, bPosition)); } } }
private void DrawLayerBoundingBox(Graphics3D graphics, BBox3D bbox) { Vector3D ptMin = bbox.PtMin; Vector3D ptMax = bbox.PtMax; Vector3D[] vertices = { new Vector3D(ptMin.X, ptMin.Y, ptMin.Z) // 0 , new Vector3D(ptMax.X, ptMin.Y, ptMin.Z) // 1 , new Vector3D(ptMax.X, ptMax.Y, ptMin.Z) // 2 , new Vector3D(ptMin.X, ptMax.Y, ptMin.Z) // 3 , new Vector3D(ptMin.X, ptMin.Y, ptMax.Z) // 4 , new Vector3D(ptMax.X, ptMin.Y, ptMax.Z) // 5 , new Vector3D(ptMax.X, ptMax.Y, ptMax.Z) // 6 , new Vector3D(ptMin.X, ptMax.Y, ptMax.Z) // 7 }; Face[] faces = { new Face(0, vertices[0], vertices[1], vertices[5], vertices[4], false), new Face(0, vertices[1], vertices[2], vertices[6], vertices[5], false), new Face(0, vertices[2], vertices[3], vertices[7], vertices[6], false), new Face(0, vertices[3], vertices[0], vertices[4], vertices[7], false), }; foreach (Face f in faces) { if (f.IsVisible(ViewDir)) { Vector3D[] points = f.Points; graphics.AddSegment(new Segment(points[0], points[1], Color.Red)); graphics.AddSegment(new Segment(points[1], points[2], Color.Red)); graphics.AddSegment(new Segment(points[2], points[3], Color.Red)); graphics.AddSegment(new Segment(points[3], points[0], Color.Red)); } } }
/// <summary> /// Use this method when drawing a solution that belongs an analysis /// </summary> /// <param name="graphics"></param> 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; }
private void UpdateGrid() { try { // sanity check if (gridSolution.ColumnsCount < 2) { return; } // remove all existing rows gridSolution.Rows.Clear(); // *** IViews // captionHeader SourceGrid.Cells.Views.RowHeader captionHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader veHeaderCaption = new DevAge.Drawing.VisualElements.RowHeader() { BackColor = Color.SteelBlue, Border = DevAge.Drawing.RectangleBorder.NoBorder }; captionHeader.Background = veHeaderCaption; captionHeader.ForeColor = Color.Black; captionHeader.Font = new Font("Arial", GridFontSize, FontStyle.Bold); captionHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; // viewRowHeader SourceGrid.Cells.Views.RowHeader viewRowHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader backHeader = new DevAge.Drawing.VisualElements.RowHeader() { BackColor = Color.LightGray, Border = DevAge.Drawing.RectangleBorder.NoBorder }; viewRowHeader.Background = backHeader; viewRowHeader.ForeColor = Color.Black; viewRowHeader.Font = new Font("Arial", GridFontSize, FontStyle.Regular); // viewNormal CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White); // *** SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // pallet caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Truck") { ColumnSpan = 2, View = captionHeader }; gridSolution[iRow, 0] = rowHeader; // layer # gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Layer #") { View = viewRowHeader }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // *** Item # (Recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)) { View = viewRowHeader }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADDIMENSIONS, UnitsManager.LengthUnitString)) { View = viewRowHeader }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_NETWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight)); } // load weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_TOTALWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_VOLUMEEFFICIENCY) { View = viewRowHeader }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); // ### layers : begin for (int i = 0; i < _solution.Layers.Count; ++i) { } // ### layers : end gridSolution.AutoSizeCells(); gridSolution.Columns.StretchToFit(); gridSolution.AutoStretchColumnsToFitWidth = true; gridSolution.Invalidate(); } catch (Exception ex) { _log.Error(ex.ToString()); } }
public Transform3D GetCurrentTransformation() { if (null == CurrentTransf) { // get transformations Transform3D world2eye = GetWorldToEyeTransformation(); Transform3D orthographicProj = GetOrthographicProjection( new Vector3D(_viewport[0], _viewport[1], -10000.0) , new Vector3D(_viewport[2], _viewport[3], 10000.0)); // build automatic viewport if (_autoViewport) { BBox3D bbox = new BBox3D(); // boxes foreach (var box in Boxes) { bbox.Extend(box.GetBBox(world2eye)); } // triangles foreach (var tr in Triangles) { foreach (Vector3D pt in tr.Points) { bbox.Extend(world2eye.transform(pt)); } } // cylinders foreach (var cyl in Cylinders) { bbox.Extend(cyl.GetBBox(world2eye)); } // faces foreach (Face face in Faces) { foreach (Vector3D pt in face.Points) { bbox.Extend(world2eye.transform(pt)); } } // segments foreach (Segment seg in Segments) { foreach (Vector3D pt in seg.Points) { bbox.Extend(world2eye.transform(pt)); } } // cube dimensions foreach (DimensionCube dimCube in _dimensions) { foreach (Vector3D pt in dimCube.DrawingPoints(this)) { bbox.Extend(world2eye.transform(pt)); } } // image inst foreach (var imageInst in _listImageInst) { bbox.Extend(world2eye.transform(imageInst.PointBase)); } if (bbox.IsValid) { Vector3D vecMin1 = bbox.PtMin, vecMax1 = bbox.PtMax; // adjust width/height if ((bbox.PtMax.Y - bbox.PtMin.Y) / Size.Height > (bbox.PtMax.X - bbox.PtMin.X) / Size.Width) { double actualWidth = (bbox.PtMax.Y - bbox.PtMin.Y) * Size.Width / Size.Height; vecMin1.X = 0.5 * (bbox.PtMin.X + bbox.PtMax.X) - 0.5 * actualWidth; vecMax1.X = 0.5 * (bbox.PtMin.X + bbox.PtMax.X) + 0.5 * actualWidth; } else { double actualHeight = (bbox.PtMax.X - bbox.PtMin.X) * Size.Height / Size.Width; vecMin1.Y = 0.5 * (bbox.PtMin.Y + bbox.PtMax.Y) - 0.5 * actualHeight; vecMax1.Y = 0.5 * (bbox.PtMin.Y + bbox.PtMax.Y) + 0.5 * actualHeight; } // set margins double width = vecMax1.X - vecMin1.X; vecMin1.X -= MarginPercentage * width; vecMax1.X += MarginPercentage * width; double height = vecMax1.Y - vecMin1.Y; vecMin1.Y -= MarginPercentage * height; vecMax1.Y += MarginPercentage * height; orthographicProj = GetOrthographicProjection(vecMin1, vecMax1); } else { _log.Warn("Graphics3D.GetCurrentTransformation() -> BBox invalid : can not compute viewport automatically"); } } CurrentTransf = orthographicProj * world2eye; } return(CurrentTransf); }
/// <summary> /// Draw all entities stored in buffer /// </summary> public void Flush() { // initialize Vector3D vLight = CameraPosition - Target; 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 foreach (Face face in Faces) { Draw(face, FaceDir.BACK); } // draw triangles foreach (Triangle tr in Triangles) { Draw(tr, FaceDir.FRONT); } // sort box list if (UseBoxelOrderer) { BoxelOrderer boxelOrderer = new BoxelOrderer(Boxes) { Direction = Target - CameraPosition }; 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) { Direction = Target - CameraPosition }; 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) { Direction = Target - CameraPosition }; 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); } // draw all triangles foreach (Triangle tr in Triangles) { Draw(tr, FaceDir.FRONT); } } // images inst if (_listImageInst.Count > 0) { // --- sort image inst AnalysisHomo 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) { TuneParam = 10.0, Direction = Target - CameraPosition }; 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); } } }
public virtual void UpdateGrid() { try { // remove all existing rows gridSolution.Rows.Clear(); // cell visual properties var vPropHeader = CellProperties.VisualPropHeader; var vPropValue = CellProperties.VisualPropValue; SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // loading caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(GridCaption) { ColumnSpan = 2, View = vPropHeader }; gridSolution[iRow, 0] = rowHeader; // layer # gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_LAYERCOUNT) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // interlayer # if (_solution.InterlayerCount > 0) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_INTERLAYERCOUNT) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.InterlayerCount); } // *** Item # (Recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADDIMENSIONS, UnitsManager.LengthUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_NETWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight)); } // load weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_TOTALWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_VOLUMEEFFICIENCY) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); int noLayerTypesUsed = 0; for (int i = 0; i < _solution.Layers.Count; ++i) { noLayerTypesUsed += _solution.Layers[i].BoxCount > 0 ? 1 : 0; } // ### layers : begin for (int i = 0; i < _solution.NoLayerTypesUsed; ++i) { // layer caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(_solution.LayerCaption(i)) { ColumnSpan = 2, View = vPropHeader }; gridSolution[iRow, 0] = rowHeader; // *** Item # (recursive count) content = _analysis.Content; itemCount = _solution.LayerBoxCount(i); number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("{0} #", content.DetailedName)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // layer weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_WEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerWeight(i))); // layer space gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_SPACES_WU, UnitsManager.LengthUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerMaximumSpace(i))); } // ### layers : end gridSolution.AutoSizeCells(); gridSolution.Columns.StretchToFit(); gridSolution.AutoStretchColumnsToFitWidth = true; gridSolution.Invalidate(); } catch (Exception ex) { _log.Error(ex.ToString()); } }
public override void Draw(Graphics3D graphics, Transform3D transform) { // clear list of picking box ClearPickingBoxes(); if (null == _solution) { return; } AnalysisHomo analysis = _solution.Analysis; if (analysis is AnalysisPackablePallet analysisPackablePallet) { // ### draw pallet Pallet pallet = new Pallet(analysisPackablePallet.PalletProperties); pallet.Draw(graphics, transform); } else if (analysis is AnalysisPackableCase analysisPackableCase) { // ### draw case (inside) Case case_ = new Case(analysisPackableCase.CaseProperties); case_.DrawInside(graphics, transform); } else if (analysis is AnalysisPackableTruck analysisPackableTruck) { // ### draw truck Truck truck = new Truck(analysisPackableTruck.TruckProperties); truck.DrawBegin(graphics); } else if (analysis is AnalysisPalletTruck analysisPalletTruck) { // ### draw truck Truck truck = new Truck(analysisPalletTruck.TruckProperties); truck.DrawBegin(graphics); } // ### draw solution uint layerId = 0, pickId = 0; List <ILayer> layers = _solution.Layers; foreach (ILayer layer in layers) { BBox3D bbox = new BBox3D(); // ### layer of boxes Layer3DBox layerBox = layer as Layer3DBox; if (null != layerBox) { if (analysis.Content is LoadedPallet) { LoadedPallet loadedPallet = analysis.Content as LoadedPallet; BBox3D solBBox = loadedPallet.ParentAnalysis.Solution.BBoxGlobal; foreach (BoxPosition bPosition in layerBox) { bool simplified = false; if (simplified) { BoxProperties bProperties = new BoxProperties(null, solBBox.Dimensions); bProperties.SetColor(Color.Chocolate); Box b = new Box(pickId++, bProperties, bPosition.Transform(transform)); graphics.AddBox(b); bbox.Extend(b.BBox); } else { graphics.AddImage(loadedPallet.ParentAnalysis, solBBox.DimensionsVec, bPosition.Transform(transform)); } } } else { bool aboveSelectedLayer = (_solution.SelectedLayerIndex != -1) && (layerId > _solution.SelectedLayerIndex); Transform3D upTranslation = Transform3D.Translation(new Vector3D(0.0, 0.0, aboveSelectedLayer ? DistanceAboveSelectedLayer : 0.0)); foreach (BoxPosition bPosition in layerBox) { BoxPosition boxPositionModified = bPosition.Transform(transform * upTranslation); Box b = null; if (analysis.Content is PackProperties) { b = new Pack(pickId++, analysis.Content as PackProperties, boxPositionModified); } else { b = new Box(pickId++, analysis.Content as PackableBrick, boxPositionModified); } graphics.AddBox(b); bbox.Extend(b.BBox); } } } Layer3DCyl layerCyl = layer as Layer3DCyl; if (null != layerCyl) { foreach (Vector3D vPos in layerCyl) { Cylinder c = new Cylinder(pickId++, analysis.Content as CylinderProperties, new CylPosition(transform.transform(vPos), HalfAxis.HAxis.AXIS_Z_P)); graphics.AddCylinder(c); bbox.Extend(c.BBox); } } if (null != layerBox || null != layerCyl) { // add layer BBox AddPickingBox(bbox, layerId); // draw bounding box around selected layer if (layerId == _solution.SelectedLayerIndex) { DrawLayerBoundingBox(graphics, bbox); } ++layerId; } // ### interlayer if (layer is InterlayerPos interlayerPos) { InterlayerProperties interlayerProp = _solution.Interlayers[interlayerPos.TypeId]; if (null != interlayerProp) { bool aboveSelectedLayer = (_solution.SelectedLayerIndex != -1) && (layerId > _solution.SelectedLayerIndex); Transform3D upTranslation = Transform3D.Translation(new Vector3D(0.0, 0.0, aboveSelectedLayer ? DistanceAboveSelectedLayer : 0.0)); BoxPosition bPosition = new BoxPosition( new Vector3D( analysis.Offset.X + 0.5 * (analysis.ContainerDimensions.X - interlayerProp.Length) , analysis.Offset.Y + 0.5 * (analysis.ContainerDimensions.Y - interlayerProp.Width) , interlayerPos.ZLow ), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P); Box box = new Box(pickId++, interlayerProp, bPosition.Transform(transform * upTranslation)); graphics.AddBox(box); bbox.Extend(box.BBox); } } } BBox3D loadBBox = _solution.BBoxLoad; BBox3D loadBBoxWDeco = _solution.BBoxLoadWDeco; if (analysis is AnalysisCasePallet analysisCasePallet) { #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) { Height = Math.Min(analysisCasePallet.PalletCornerProperties.Length, loadBBox.Height) }; corners[i].SetPosition( transform.transform(cornerPositions[i]) , HalfAxis.Transform(lAxes[i], transform), HalfAxis.Transform(wAxes[i], transform) ); corners[i].DrawBegin(graphics); } } } #endregion #region Pallet film // ### pallet film Film film = null; if (analysisCasePallet.HasPalletFilm && -1 == _solution.SelectedLayerIndex) { // instantiate film PalletFilmProperties palletFilmProperties = analysisCasePallet.PalletFilmProperties; film = new Film( palletFilmProperties.Color, palletFilmProperties.UseTransparency, palletFilmProperties.UseHatching, palletFilmProperties.HatchSpacing, palletFilmProperties.HatchAngle); film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin) , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform) , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis) , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform) , new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis) , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_N, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform) , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis) , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_N, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Z_P, transform) , new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(transform.transform(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis) , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform), HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform) , new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width) , UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1))); film.DrawBegin(graphics); } #endregion #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; BoxPosition bPosition = new BoxPosition(new Vector3D( 0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length), 0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width), loadBBox.PtMax.Z - capProperties.InsideHeight) , HalfAxis.Transform(HalfAxis.HAxis.AXIS_X_P, transform) , HalfAxis.Transform(HalfAxis.HAxis.AXIS_Y_P, transform) ); Transform3D upTranslation = Transform3D.Translation(new Vector3D(0.0, 0.0, -1 != _solution.SelectedLayerIndex ? DistanceAboveSelectedLayer : 0.0)); PalletCap cap = new PalletCap(0, capProperties, bPosition.Transform(upTranslation)); cap.DrawEnd(graphics); } #endregion #region Pallet film // pallet film : End if (analysisCasePallet.HasPalletFilm && null != film) { film.DrawEnd(graphics); } #endregion } else if (analysis is AnalysisPackableTruck analysisPackableTruck2) { Truck truck = new Truck(analysisPackableTruck2.TruckProperties); truck.DrawEnd(graphics); } else if (analysis is AnalysisPalletTruck analysisPalletTruck) { Truck truck = new Truck(analysisPalletTruck.TruckProperties); truck.DrawEnd(graphics); } // ### dimensions // dimensions should only be shown when no layer is selected if (graphics.ShowDimensions && (-1 == _solution.SelectedLayerIndex)) { graphics.AddDimensions(new DimensionCube(BoundingBoxDim(DimCasePalletSol1), Color.Black, false)); graphics.AddDimensions(new DimensionCube(BoundingBoxDim(DimCasePalletSol2), Color.Red, true)); } // ### }
protected void AddPickingBox(BBox3D bbox, uint id) { _listPickingBox.Add(new Tuple <BBox3D, uint>(bbox, id)); }
/// <summary> /// build polygons from given list of segments /// if want to represent arcs, add them as dummy lines to segs /// polys returned are ordered anticlockwise /// </summary> public static IEnumerable <IReadOnlyList <Vector3D> > ClosedPolys2D(this IEnumerable <Line3D> segs, double tolLen, int polyMaxPoints = 0) { var minCoord = new BBox3D(segs.SelectMany(r => new[] { r.From, r.To })).Min; var vcmp = new Vector3DEqualityComparer(tolLen); var lcmp = new Line3DEqualityComparer(tolLen); var segsDict = segs.ToDictionary(k => k.ToString(tolLen), v => v); var segsFromDict = segs.GroupBy(g => g.From, v => v, vcmp).ToDictionary(k => k.Key, v => v.ToList(), vcmp); var segsToDict = segs.GroupBy(g => g.To, v => v, vcmp).ToDictionary(k => k.Key, v => v.ToList(), vcmp); var segsLeft = segs.OrderBy(w => w.MidPoint.Distance(minCoord)).ToList(); var polys = new List <List <Vector3D> >(); var polyCentroidDone = new HashSet <Vector3D>(vcmp); while (segsLeft.Count > 0) { Console.WriteLine($"segsLeft: {segsLeft.Count} polys:{polys.Count}"); var seg = segsLeft.First(); segsLeft.Remove(seg); var poly = new List <Vector3D>() { seg.From, seg.To }; var rotDir = 1.0; // 1=+Z, -1=-Z while (true) { List <Line3D> segsNext = null; { var hs = new HashSet <Line3D>(lcmp); { List <Line3D> tmp = null; if (segsFromDict.TryGetValue(seg.To, out tmp)) { foreach (var x in tmp.Where(r => !r.EqualsTol(tolLen, seg))) { hs.Add(x); } } if (segsToDict.TryGetValue(seg.To, out tmp)) { foreach (var x in tmp.Where(r => !r.EqualsTol(tolLen, seg))) { hs.Add(x); } } } segsNext = hs.Select(w => w.EnsureFrom(tolLen, seg.To)).ToList(); } Line3D segNext = null; var force_close_poly = false; if (polyMaxPoints > 0 && poly.Count > polyMaxPoints) { throw new Exception($"polygon [{poly.PolygonSegments(tolLen).ToCadScript()}] max point exceeded"); } //#if DEBUG // if (//poly.Count >= 2 && // poly.Any(r => r.EqualsTol(1e-2, 31.0626,-0.0018)) // //&& // //poly.Any(r => r.EqualsTol(tolLen, -42.9561, 0)) // ) // ; //#endif if (poly.Count == 2) { if (segsNext.Count == 0) { throw new Exception($"check singular segment [{seg}] cadscript [{seg.CadScript}]"); } segNext = segsNext .OrderBy(w => (-seg.V).AngleRad(tolLen, w.V)) .First(); rotDir = seg.V.CrossProduct(segNext.V).Z > 0 ? 1 : -1; } else { var qSegsNext = segsNext .Select(w => new { arad = (seg.V).AngleToward(tolLen, w.V, Vector3D.ZAxis * rotDir), seg = w }) .Where(r => r.arad <= PI).ToList(); if (qSegsNext.Count == 0) { force_close_poly = true; } else { // retrieve next segment with current rotation direction w/acutest angle segNext = qSegsNext .OrderByDescending(r => r.arad) .First().seg; } } if (force_close_poly) { break; } segsLeft.Remove(segNext); if (segNext.To.EqualsTol(tolLen, poly[0])) { break; } poly.Add(segNext.To); seg = segNext; } if (poly.Count > 2) { poly = poly.SortPoly(tolLen, Vector3D.ZAxis).ToList(); var polyCentroid = poly.Centroid(tolLen); if (!polyCentroidDone.Contains(polyCentroid)) { polys.Add(poly); polyCentroidDone.Add(polyCentroid); } } else { // todo warning } } return(polys.OrderByDescending(w => w.Count)); }
public override void UpdateGrid() { // remove all existing rows gridSolutions.Rows.Clear(); // *** IViews // captionHeader SourceGrid.Cells.Views.RowHeader captionHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader veHeaderCaption = new DevAge.Drawing.VisualElements.RowHeader() { BackColor = Color.SteelBlue, Border = DevAge.Drawing.RectangleBorder.NoBorder }; captionHeader.Background = veHeaderCaption; captionHeader.ForeColor = Color.Black; captionHeader.Font = new Font("Arial", GridFontSize, FontStyle.Bold); captionHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; // viewRowHeader SourceGrid.Cells.Views.RowHeader viewRowHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader backHeader = new DevAge.Drawing.VisualElements.RowHeader() { BackColor = Color.LightGray, Border = DevAge.Drawing.RectangleBorder.NoBorder }; viewRowHeader.Background = backHeader; viewRowHeader.ForeColor = Color.Black; viewRowHeader.Font = new Font("Arial", GridFontSize, FontStyle.Regular); // viewNormal CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White); // *** SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // case caption gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_CASECOUNT) { ColumnSpan = 2, View = captionHeader }; gridSolutions[iRow, 0] = rowHeader; // layer # gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_LAYERCOUNT) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // interlayer # if (_solution.InterlayerCount > 0) { gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_INTERLAYERCOUNT) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(_solution.InterlayerCount); } // *** Item # (recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADDIMENSIONS, UnitsManager.LengthUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_NETWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight)); } // load weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_TOTALWEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_VOLUMEEFFICIENCY) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); int noLayerTypesUsed = 0; for (int i = 0; i < _solution.Layers.Count; ++i) { noLayerTypesUsed += _solution.Layers[i].BoxCount > 0 ? 1 : 0; } // ### layers : begin for (int i = 0; i < _solution.NoLayerTypesUsed; ++i) { // layer caption gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(_solution.LayerCaption(i)) { ColumnSpan = 2, View = captionHeader }; gridSolutions[iRow, 0] = rowHeader; // *** Item # (recursive count) content = _analysis.Content; itemCount = _solution.LayerBoxCount(i); number = 1; do { itemCount *= number; gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("{0} #", content.DetailedName)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // layer weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_WEIGHT_WU, UnitsManager.MassUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerWeight(i))); // layer space gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_SPACES_WU, UnitsManager.LengthUnitString)) { View = viewRowHeader }; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerMaximumSpace(i))); } gridSolutions.AutoSizeCells(); gridSolutions.Columns.StretchToFit(); gridSolutions.AutoStretchColumnsToFitWidth = true; gridSolutions.Invalidate(); }
public override void UpdateGrid() { // remove all existing rows gridSolutions.Rows.Clear(); // *** IViews // captionHeader SourceGrid.Cells.Views.RowHeader captionHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader veHeaderCaption = new DevAge.Drawing.VisualElements.RowHeader(); veHeaderCaption.BackColor = Color.SteelBlue; veHeaderCaption.Border = DevAge.Drawing.RectangleBorder.NoBorder; captionHeader.Background = veHeaderCaption; captionHeader.ForeColor = Color.Black; captionHeader.Font = new Font("Arial", 10, FontStyle.Bold); captionHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; // viewRowHeader SourceGrid.Cells.Views.RowHeader viewRowHeader = new SourceGrid.Cells.Views.RowHeader(); DevAge.Drawing.VisualElements.RowHeader backHeader = new DevAge.Drawing.VisualElements.RowHeader(); backHeader.BackColor = Color.LightGray; backHeader.Border = DevAge.Drawing.RectangleBorder.NoBorder; viewRowHeader.Background = backHeader; viewRowHeader.ForeColor = Color.Black; viewRowHeader.Font = new Font("Arial", 10, FontStyle.Regular); // viewNormal CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White); // *** SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // case caption gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Case"); rowHeader.ColumnSpan = 2; rowHeader.View = captionHeader; gridSolutions[iRow, 0] = rowHeader; // layer # gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Layer #"); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // interlayer # if (_solution.InterlayerCount > 0) { gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Interlayer #"); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(_solution.InterlayerCount); } // *** Item # (recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Load dimensions\n({0} x {0} * {0})", UnitsManager.LengthUnitString)); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Net weight ({0})", UnitsManager.MassUnitString)); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight)); } // load weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Load Weight ({0})", UnitsManager.MassUnitString)); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("Total weight ({0})", UnitsManager.MassUnitString)); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Vol. efficiency (%)"); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); int noLayerTypesUsed = 0; for (int i = 0; i < _solution.Layers.Count; ++i) { noLayerTypesUsed += _solution.Layers[i].BoxCount > 0 ? 1 : 0; } // ### layers : begin for (int i = 0; i < _solution.Layers.Count; ++i) { List <int> layerIndexes = _solution.LayerTypeUsed(i); if (0 == layerIndexes.Count) { continue; } // layer caption gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader((noLayerTypesUsed == 1) ? "Layers : All" : BuildLayerCaption(layerIndexes)); rowHeader.ColumnSpan = 2; rowHeader.View = captionHeader; gridSolutions[iRow, 0] = rowHeader; // *** Item # (recursive count) content = _analysis.Content; itemCount = _solution.LayerBoxCount(i); number = 1; do { itemCount *= number; gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format("{0} #", content.DetailedName)); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // layer weight gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Weight"); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerWeight(i))); // layer space gridSolutions.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader("Spaces"); rowHeader.View = viewRowHeader; gridSolutions[iRow, 0] = rowHeader; gridSolutions[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LayerMaximumSpace(i))); } gridSolutions.AutoSizeCells(); gridSolutions.Columns.StretchToFit(); gridSolutions.AutoStretchColumnsToFitWidth = true; gridSolutions.Invalidate(); }
public virtual void UpdateGrid() { try { // remove all existing rows gridSolution.Rows.Clear(); // cell visual properties var vPropHeader = CellProperties.VisualPropHeader; var vPropValue = CellProperties.VisualPropValue; SourceGrid.Cells.RowHeader rowHeader; int iRow = -1; // loading caption gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(GridCaption) { ColumnSpan = 2, View = vPropHeader }; gridSolution[iRow, 0] = rowHeader; // *** Item # (Recursive count) Packable content = Analysis.Content; var solution = Analysis.Solution; int itemCount = solution.ItemCount; int number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = solution.BBoxLoad; // --- gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADDIMENSIONS, UnitsManager.LengthUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // total dimensions BBox3D bboxGlobal = solution.BBoxGlobal; // --- gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_DIMENSIONS, UnitsManager.LengthUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxGlobal.Length, bboxGlobal.Width, bboxGlobal.Height)); // net weight if (Analysis.Solution.HasNetWeight) { gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_NETWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", solution.NetWeight)); } // load weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", solution.LoadWeight)); // total weight gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_TOTALWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", solution.Weight)); // volume efficiency gridSolution.Rows.Insert(++iRow); rowHeader = new SourceGrid.Cells.RowHeader(Resources.ID_VOLUMEEFFICIENCY) { View = vPropValue }; gridSolution[iRow, 0] = rowHeader; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", solution.VolumeEfficiency)); gridSolution.AutoSizeCells(); gridSolution.AutoStretchColumnsToFitWidth = true; gridSolution.Invalidate(); } catch (Exception ex) { _log.Error(ex.ToString()); } }
public static IEnumerable <Face3d> ToFace3DList(this BBox3D bbox) { var d = bbox.Max - bbox.Min; return(DxfKit.Cuboid((bbox.Max + bbox.Min) / 2, d)); }
private List <PackPalletSolution> GenerateSolutions() { List <PackPalletSolution> solutions = new List <PackPalletSolution>(); HalfAxis.HAxis[] axes = { HalfAxis.HAxis.AXIS_Z_N, HalfAxis.HAxis.AXIS_Z_P }; // loop throught all patterns foreach (LayerPattern pattern in _patterns) { // loop throught all axes foreach (HalfAxis.HAxis axis in axes) // axis { // loop through Layer layer = new Layer(_packProperties, _palletProperties, _constraintSet, axis, false); double actualLength = 0.0, actualWidth = 0.0; if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth)) { continue; } pattern.GenerateLayer(layer, actualLength, actualWidth); // filter by layer weight if (_constraintSet.MaximumLayerWeight.Activated && (layer.Count * _packProperties.Weight > _constraintSet.MaximumLayerWeight.Value)) { continue; } // filter by maximum space if (_constraintSet.MaximumSpaceAllowed.Activated && layer.MaximumSpace > _constraintSet.MaximumSpaceAllowed.Value) { continue; } double layerHeight = layer.BoxHeight; string title = string.Format("{0}-{1}", pattern.Name, axis.ToString()); double zLayer = 0.0; BoxLayer boxLayer = new BoxLayer(zLayer, ""); foreach (LayerPosition layerPos in layer) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); boxLayer.Add(boxPos); } boxLayer.MaximumSpace = layer.MaximumSpace; BBox3D layerBBox = boxLayer.BoundingBox(_packProperties); // filter by overhangX if (_constraintSet.MinOverhangX.Activated && (0.5 * (layerBBox.Length - _palletProperties.Length) < _constraintSet.MinOverhangX.Value)) { continue; } // filter by overhangY if (_constraintSet.MinOverhangY.Activated && (0.5 * (layerBBox.Width - _palletProperties.Width) < _constraintSet.MinOverhangY.Value)) { continue; } double interlayerThickness = null != _interlayerProperties ? _interlayerProperties.Thickness : 0; double interlayerWeight = null != _interlayerProperties ? _interlayerProperties.Weight : 0; PackPalletSolution sol = new PackPalletSolution(null, title, boxLayer); int noLayer = 1, noInterlayer = (null != _interlayerProperties && _constraintSet.HasFirstInterlayer) ? 1 : 0; bool maxHeightReached = _constraintSet.MaximumPalletHeight.Activated && (_packProperties.Height + noInterlayer * interlayerThickness + noLayer * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value; bool maxWeightReached = _constraintSet.MaximumPalletWeight.Activated && (_palletProperties.Weight + noInterlayer * interlayerWeight + noLayer * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value); noLayer = 0; noInterlayer = 0; int iCountInterlayer = 0, iCountSwap = 1; bool bSwap = false; while (!maxHeightReached && !maxWeightReached) { bool bInterlayer = (0 == iCountInterlayer) && ((noLayer != 0) || _constraintSet.HasFirstInterlayer); // actually insert new layer sol.AddLayer(bSwap, bInterlayer); // increment number of layers noLayer++; noInterlayer += (bInterlayer ? 1 : 0); // update iCountInterlayer && iCountSwap ++iCountInterlayer; if (iCountInterlayer >= _constraintSet.InterlayerPeriod) { iCountInterlayer = 0; } ++iCountSwap; if (iCountSwap > _constraintSet.LayerSwapPeriod) { iCountSwap = 1; bSwap = !bSwap; } // update maxHeightReached & maxWeightReached maxHeightReached = _constraintSet.MaximumPalletHeight.Activated && (_palletProperties.Height + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerThickness + (noLayer + 1) * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value; maxWeightReached = _constraintSet.MaximumPalletWeight.Activated && (_palletProperties.Weight + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerWeight + (noLayer + 1) * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value); } if (sol.PackCount > 0) { solutions.Add(sol); } } // axis } // pattern solutions.Sort(); return(solutions); }
private void UpdateGrid() { try { // sanity check if (gridSolution.ColumnsCount < 2) { return; } // remove all existing rows gridSolution.Rows.Clear(); // cell visual properties var vPropHeader = CellProperties.VisualPropHeader; var vPropValue = CellProperties.VisualPropValue; int iRow = -1; // pallet caption gridSolution.Rows.Insert(++iRow); gridSolution[iRow, 0] = new ColumnHeaderSolution(Resources.ID_TRUCK) { ColumnSpan = 1 }; gridSolution[iRow, 1] = new ColumnHeaderSolution(string.Empty) { ColumnSpan = 1 }; // layer # gridSolution.Rows.Insert(++iRow); gridSolution[iRow, 0] = new SourceGrid.Cells.RowHeader(Resources.ID_LAYERNUMBER) { View = vPropValue }; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(_solution.LayerCount); // *** Item # (Recursive count) Packable content = _analysis.Content; int itemCount = _solution.ItemCount; int number = 1; do { itemCount *= number; gridSolution.Rows.Insert(++iRow); gridSolution[iRow, 0] = new SourceGrid.Cells.RowHeader(string.Format("{0} #", content.DetailedName)) { View = vPropValue }; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell(itemCount); }while (null != content && content.InnerContent(ref content, ref number)); // *** // load dimensions BBox3D bboxLoad = _solution.BBoxLoad; // --- gridSolution.Rows.Insert(++iRow); gridSolution[iRow, 0] = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADDIMENSIONS, UnitsManager.LengthUnitString)) { View = vPropValue }; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#} x {1:0.#} x {2:0.#}", bboxLoad.Length, bboxLoad.Width, bboxLoad.Height)); // net weight if (_solution.HasNetWeight) { gridSolution.Rows.Insert(++iRow); gridSolution[iRow, 0] = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_NETWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.NetWeight.Value)); } // load weight gridSolution.Rows.Insert(++iRow); gridSolution[iRow, 0] = new SourceGrid.Cells.RowHeader( string.Format(Resources.ID_LOADWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.LoadWeight)); // total weight gridSolution.Rows.Insert(++iRow); gridSolution[iRow, 0] = new SourceGrid.Cells.RowHeader(string.Format(Resources.ID_TOTALWEIGHT_WU, UnitsManager.MassUnitString)) { View = vPropValue }; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.Weight)); // volume efficiency gridSolution.Rows.Insert(++iRow); gridSolution[iRow, 0] = new SourceGrid.Cells.RowHeader(Resources.ID_VOLUMEEFFICIENCY) { View = vPropValue }; gridSolution[iRow, 1] = new SourceGrid.Cells.Cell( string.Format(CultureInfo.InvariantCulture, "{0:0.#}", _solution.VolumeEfficiency)); // ### layers : begin for (int i = 0; i < _solution.Layers.Count; ++i) { } // ### layers : end gridSolution.AutoSizeCells(); gridSolution.Columns.StretchToFit(); gridSolution.AutoStretchColumnsToFitWidth = true; gridSolution.Invalidate(); } catch (Exception ex) { _log.Error(ex.ToString()); } }