public override void Export(AnalysisHomo analysis, string filePath) { Solution sol = analysis.Solution; string nameContainer = analysis.Container.Name; string nameContent = analysis.Content.Name; // Geometry container Geometry geomContainer = new Geometry() { Uuid = Guid.NewGuid().ToString(), Type = "Geometry", Data = new Data() { Vertices = new List <double>(), Normals = new List <double>(), Uvs = new List <List <double> >(), Faces = new List <int>() } }; // Material container Material matContainer = new Material() { Uuid = Guid.NewGuid().ToString(), Type = "Material", Name = string.Format("Mat_{0}", nameContainer) }; // Geometry content Geometry geomContent = new Geometry() { }; // Material content Material matContent = new Material() { Uuid = Guid.NewGuid().ToString(), Type = "Material", Name = string.Format("Mat_{0}", nameContent) }; // RootObject rootObj = new RootObject() { Geometries = new List <Geometry>() { geomContainer, geomContent }, Materials = new List <Material>() { matContainer, matContent }, Object = new Json.Object() }; File.WriteAllText(filePath, JsonConvert.SerializeObject(rootObj)); }
private void onSelChangeGrid(object sender, SourceGrid.RangeRegionChangedEventArgs e) { try { SourceGrid.Selection.RowSelection select = sender as SourceGrid.Selection.RowSelection; SourceGrid.Grid g = select.Grid as SourceGrid.Grid; SourceGrid.RangeRegion region = g.Selection.GetSelectionRegion(); int[] indexes = region.GetRowsIndex(); if (indexes.Length < 1 || indexes[0] < 1) { _selectedAnalysis = null; } else { _selectedAnalysis = _analyses[indexes[0] - 1]; // analysis name/description if (null != _selectedAnalysis) { BoxProperties box = SelectedBox; PackProperties pack = _selectedAnalysis.Content as PackProperties; UpdateStatus(string.Empty); } } graphCtrlPack.Invalidate(); graphCtrlSolution.Invalidate(); } catch (Exception ex) { _log.Error(ex.Message); } }
public void EditAnalysis(AnalysisHomo analysis) { // search for any DockContentAnalysis window and close it var seq = (from view in Views where view is DockContentAnalysisEdit && analysis == (view as DockContentAnalysisEdit).Analysis select view); if (seq.Count() > 0) { seq.First().Close(); } // instantiate a form to edit analysis Form form = null; if (analysis is AnalysisCasePallet analysisCasePallet) { form = new FormNewAnalysisCasePallet(this, analysisCasePallet); } else if (analysis is AnalysisBoxCase analysisBoxCase) { form = new FormNewAnalysisBoxCase(this, analysisBoxCase); } else if (analysis is AnalysisCylinderPallet analysisCylinderPallet) { form = new FormNewAnalysisCylinderPallet(this, analysisCylinderPallet); } else if (analysis is AnalysisCylinderCase analysisCylinderCase) { form = new FormNewAnalysisCylinderCase(this, analysisCylinderCase); } else if (analysis is AnalysisPalletTruck analysisPalletTruck) { form = new FormNewAnalysisPalletTruck(this, analysisPalletTruck); } else if (analysis is AnalysisCaseTruck analysisCaseTruck) { form = new FormNewAnalysisCaseTruck(this, analysisCaseTruck); } else if (analysis is AnalysisCylinderTruck analysisCylinderTruck) { form = new FormNewAnalysisCylinderTruck(this, analysisCylinderTruck); } else if (analysis is AnalysisHCylPallet analysisHCylPallet) { form = new FormNewAnalysisHCylPallet(this, analysisHCylPallet); } else if (analysis is AnalysisHCylTruck analysisHCylTruck) { form = new FormNewAnalysisHCylTruck(this, analysisHCylTruck); } else { MessageBox.Show("Unexepected analysis type!"); return; } if (DialogResult.OK == form.ShowDialog()) { } }
public FormNewAnalysis(Document document, AnalysisHomo item) { InitializeComponent(); _document = document; _item = item; }
public FormBrowseSolution(Document doc, AnalysisHomo analysis) { InitializeComponent(); _doc = doc; _analysis = analysis; }
private placement[] BuildPlacementArray(Solution sol, AnalysisHomo analysis) { List <placement> lPlacements = new List <placement>(); List <ILayer> layers = sol.Layers; foreach (ILayer layer in layers) { if (layer is Layer3DBox layerBox) { foreach (BoxPosition bPosition in layerBox) { Vector3D writtenPosition = ConvertPosition(bPosition, analysis.ContentDimensions); lPlacements.Add( new placement() { itemId = 1, x = writtenPosition.X, y = writtenPosition.Y, z = writtenPosition.Z, L = ToAxis(bPosition.DirectionLength), W = ToAxis(bPosition.DirectionWidth) } ); } } } return(lPlacements.ToArray()); }
private void onNext(object sender, EventArgs e) { try { // selected analysis -> get pack AnalysisCasePallet analysisSel = SelectedAnalysis; PackProperties packSel = analysisSel.Content as PackProperties; packSel.ID.SetNameDesc(AnalysisName, AnalysisName); // create pack PackProperties packProperties = _doc.CreateNewPack(packSel); PalletProperties palletProperties = _doc.CreateNewPallet(SelectedPallet); // create analysis List <InterlayerProperties> interlayers = new List <InterlayerProperties>(); AnalysisHomo analysis = _doc.CreateNewAnalysisCasePallet( AnalysisName, AnalysisDescription, packProperties, palletProperties, interlayers, null, null, null, BuildConstraintSet(), analysisSel.Solution.LayerDescriptors); FormBrowseSolution form = new FormBrowseSolution(_doc, analysis); if (DialogResult.OK == form.ShowDialog()) { } } catch (Exception ex) { _log.Error(ex.Message); } }
private item BuildItem(AnalysisHomo analysis) { if (analysis is AnalysisCasePallet analysisCasePallet) { Packable packable = analysisCasePallet.Content; ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet; bool[] orient = constraintSet.AllowedOrientations; StringBuilder sbOrient = new StringBuilder(); foreach (bool b in orient) { sbOrient.Append(b ? "1" : "0"); } return(new item() { id = 1, name = packable.Name, length = packable.OuterDimensions.X, width = packable.OuterDimensions.Y, height = packable.OuterDimensions.Z, weight = packable.Weight, maxWeightOnTop = 0.0, permittedOrientations = sbOrient.ToString() }); } else { throw new Exception(string.Format("Unexpected analysis type : {0}", analysis.GetType())); } }
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); }
public override void Export(AnalysisHomo analysis, ref Stream stream) { var csv = new StringBuilder(); Solution sol = analysis.Solution; List <ILayer> layers = sol.Layers; foreach (ILayer layer in layers) { if (layer is Layer3DBox layerBox) { foreach (BoxPosition bPosition in layerBox) { Vector3D writtenPosition = ConvertPosition(bPosition, analysis.ContentDimensions); csv.AppendLine(string.Format("{0};{1};{2};{3};{4};{5}", 1, writtenPosition.X, writtenPosition.Y, writtenPosition.Z, bPosition.DirectionLength, bPosition.DirectionWidth)); } } } var writer = new StreamWriter(stream); writer.Write(csv.ToString()); writer.Flush(); stream.Position = 0; }
public void Initialize(Document doc, IItemBaseFilter filter, ItemBase initiallySelectedItem) { Items.Clear(); try { int index = 0, iSelected = -1; foreach (ItemBase itemBase in doc.TypeList) { if (null == filter || filter.Accept(this, itemBase)) { Items.Add(new ItemBaseWrapper(itemBase)); if (initiallySelectedItem == itemBase) { iSelected = index; } ++index; } } AnalysisHomo analysisInitial = null; if (null != initiallySelectedItem) { if (initiallySelectedItem is PackableLoaded packableLoadedInitial) { analysisInitial = packableLoadedInitial.ParentAnalysis; } } foreach (AnalysisHomo analysis in doc.Analyses) { PackableLoaded eqvtPackable = analysis.EquivalentPackable; if (null == eqvtPackable) { continue; } if (null == filter || filter.Accept(this, eqvtPackable)) { Items.Add(new ItemBaseWrapper(eqvtPackable)); if (analysisInitial == analysis) { iSelected = index; } ++index; } } if (-1 == iSelected && Items.Count > 0) { SelectedIndex = 0; } else { SelectedIndex = iSelected; } } catch (Exception ex) { _log.Error(ex.ToString()); } }
public DockContentAnalysisEdit(IDocument document, AnalysisHomo analysis) : base(document) { _analysis = analysis; _analysis.AddListener(this); _solution = analysis.Solution; InitializeComponent(); }
public void OnAnalysisUpdated(Document doc, AnalysisHomo analysis) { // get parent node TreeNode analysisNode = FindNode(null, new NodeTag(NodeTag.NodeType.NT_ANALYSIS, doc, analysis)); if (null != analysisNode) { analysisNode.Name = analysis.Name; } }
private void onNext(object sender, EventArgs e) { try { Close(); List <LayerDesc> layerDescs = new List <LayerDesc>(); foreach (ILayer2D layer2D in uCtrlLayerList.Selected) { layerDescs.Add(layer2D.LayerDescriptor); } string userName = string.Empty; using (WCFClient wcfClient = new WCFClient()) { userName = wcfClient.User.Name; } Document doc = new Document(DocumentName, DocumentDescription, userName, DateTime.Now, null); Packable packable = doc.CreateNewPackable(BundleProp); BoxProperties caseProperties = doc.CreateNewCase( CaseName, CaseName , CaseInsideLength, CaseInsideWidth, CaseInsideHeight , CaseInsideLength, CaseInsideWidth, CaseInsideHeight , CaseWeight , new Color[] { Color.Chocolate, Color.Chocolate, Color.Chocolate, Color.Chocolate, Color.Chocolate, Color.Chocolate } ); if (null == packable || null == caseProperties) { return; } Solution.SetSolver(new LayerSolver()); AnalysisHomo analysis = doc.CreateNewAnalysisBoxCase( DocumentName, DocumentDescription , packable, caseProperties , new List <InterlayerProperties>() , BuildConstraintSet() , layerDescs); FormBrowseSolution form = new FormBrowseSolution(doc, analysis); if (DialogResult.OK == form.ShowDialog()) { } } catch (Exception ex) { _log.Error(ex.ToString()); } }
public void OnNewAnalysisCreated(Document doc, AnalysisHomo analysis) { // get parent node TreeNode parentNode = FindNode(null, new NodeTag(NodeTag.NodeType.NT_LISTANALYSIS, doc)); // instantiate analysis node TreeNode nodeAnalysis = new TreeNode(analysis.Name, ToIconIndex(analysis), ToIconIndex(analysis)) { Tag = new NodeTag(NodeTag.NodeType.NT_ANALYSIS, doc, analysis) }; // insert context menu parentNode.Nodes.Add(nodeAnalysis); parentNode.Expand(); }
public override void Export(AnalysisHomo analysis, string fileName) { Solution sol = analysis.Solution; // build orderDocument element orderDocument document = new orderDocument() { date = DateTime.Now, unit = CurrentUnit, author = analysis.ParentDocument != null ? analysis.ParentDocument.Author : string.Empty, orderType = new orderDocumentOrderType() { orderNumber = analysis.Name, orderLine = new orderLine() { itemId = 1, quantity = analysis.Solution.ItemCount }, loadSpace = BuildLoadSpace(analysis), item = BuildItem(analysis), load = new load() { loadSpaceId = 1, statistics = new statistics() { loadVolume = sol.LoadVolume, loadWeight = sol.LoadWeight, volumeUtilization = sol.VolumeEfficiency, weightUtilization = sol.WeightEfficiency.ToDouble(), cOfG = new cOfG() { x = sol.COfG.X, y = sol.COfG.Y, z = sol.COfG.Z }, loadHeight = sol.BBoxLoad.Height }, placement = BuildPlacementArray(sol) } } }; // serialization using (Stream stream = File.Open(fileName, FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(orderDocument)); serializer.Serialize(stream, document); stream.Flush(); } }
private void OnNext(object sender, EventArgs e) { try { Close(); List <LayerDesc> layerDescs = new List <LayerDesc>(); foreach (ILayer2D layer2D in uCtrlLayerList.Selected) { layerDescs.Add(layer2D.LayerDescriptor); } string userName = string.Empty; using (WCFClient wcfClient = new WCFClient()) { userName = wcfClient.User.Name; } Document doc = new Document(DocumentName, DocumentDescription, userName, DateTime.Now, null); Packable packable = doc.CreateNewPackable(_uctrlPackable.PackableProperties); PalletProperties palletProperties = doc.CreateNewPallet(cbPallet.SelectedPallet); if (null == packable || null == palletProperties) { return; } Solution.SetSolver(new LayerSolver()); AnalysisHomo analysis = doc.CreateNewAnalysisCasePallet( DocumentName, DocumentDescription , packable, palletProperties, new List <InterlayerProperties>(), null, null, null , BuildConstraintSet() , layerDescs); FormBrowseSolution form = new FormBrowseSolution(doc, analysis); if (DialogResult.OK == form.ShowDialog()) { } } catch (Exception ex) { _log.Error(ex.ToString()); } }
public DockContentView CreateViewAnalysis(AnalysisHomo analysis) { DockContentView form = null; if (analysis is AnalysisCasePallet) { form = new DockContentAnalysisCasePallet(this, analysis as AnalysisCasePallet); } else if (analysis is AnalysisBoxCase) { form = new DockContentAnalysisBoxCase(this, analysis as AnalysisBoxCase); } else if (analysis is AnalysisCylinderPallet) { form = new DockContentAnalysisCylinderPallet(this, analysis as AnalysisCylinderPallet); } else if (analysis is AnalysisCylinderCase) { form = new DockContentAnalysisCylinderCase(this, analysis as AnalysisCylinderCase); } else if (analysis is AnalysisPalletTruck) { form = new DockContentAnalysisPalletTruck(this, analysis as AnalysisPalletTruck); } else if (analysis is AnalysisCaseTruck) { form = new DockContentAnalysisCaseTruck(this, analysis as AnalysisCaseTruck); } else if (analysis is AnalysisCylinderTruck) { form = new DockContentAnalysisCylinderTruck(this, analysis as AnalysisCylinderTruck); } else { _log.Error(string.Format("Analysis ({0}) type not handled", analysis.Name)); return(null); } AddView(form); return(form); }
private void OnCreateAnalysis(object sender, EventArgs e) { try { // selected analysis -> get case AnalysisBoxCase analysisSel = SelectedAnalysis; BoxProperties caseSel = analysisSel.CaseProperties; // create case BoxProperties caseProperties = Document.CreateNewCase(caseSel); // create analysis List <InterlayerProperties> interlayers = new List <InterlayerProperties>(); AnalysisHomo analysis = Document.CreateNewAnalysisBoxCase( AnalysisName, AnalysisDescription, analysisSel.Content, caseProperties, interlayers, analysisSel.ConstraintSet as ConstraintSetBoxCase, analysisSel.Solution.LayerEncaps); } catch (Exception ex) { _log.Error(ex.Message); } }
public override void Export(AnalysisHomo analysis, string filePath) { var csv = new StringBuilder(); Solution sol = analysis.Solution; List <ILayer> layers = sol.Layers; foreach (ILayer layer in layers) { if (layer is Layer3DBox layerBox) { foreach (BoxPosition bPosition in layerBox) { csv.AppendLine(string.Format("{0};{1};{2};{3};{4};{5}", 1, bPosition.Position.X, bPosition.Position.Y, bPosition.Position.Z, bPosition.DirectionLength, bPosition.DirectionWidth)); } } } File.WriteAllText(filePath, csv.ToString()); }
private loadSpace BuildLoadSpace(AnalysisHomo analysis) { if (analysis is AnalysisCasePallet analysisCasePallet) { PalletProperties palletProperties = analysisCasePallet.PalletProperties; ConstraintSetCasePallet constraintSet = analysisCasePallet.ConstraintSet as ConstraintSetCasePallet; return(new loadSpace() { id = 1, name = palletProperties.Name, length = palletProperties.Length, width = palletProperties.Width, baseHeight = palletProperties.Height, maxLengthOverhang = constraintSet.Overhang.X, maxWidthOverhang = constraintSet.Overhang.Y, maxLoadHeight = constraintSet.OptMaxHeight.Activated ? constraintSet.OptMaxHeight.Value : 0.0, maxLoadWeight = constraintSet.OptMaxWeight.Activated ? constraintSet.OptMaxWeight.Value : 0.0 }); } else { throw new Exception(string.Format("Unexpected analysis type : {0}", analysis.GetType())); } }
private void OnCreateAnalysis(object sender, EventArgs e) { try { // selected analysis -> get pack AnalysisCasePallet analysisSel = SelectedAnalysis; PackProperties packSel = analysisSel.Content as PackProperties; packSel.ID.SetNameDesc(AnalysisName, AnalysisName); // create pack PackProperties packProperties = _doc.CreateNewPack(packSel); // create analysis List <InterlayerProperties> interlayers = new List <InterlayerProperties>(); AnalysisHomo packAnalysis = _doc.CreateNewAnalysisCasePallet( AnalysisName, AnalysisDescription, packProperties, SelectedPallet, interlayers, null, null, null, BuildConstraintSet(), analysisSel.Solution.LayerEncaps); } catch (Exception ex) { _log.Error(ex.Message); } }
private void FillGrid() { try { // 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", GridFontSize, FontStyle.Bold); captionHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; // viewRowHeader SourceGrid.Cells.Views.ColumnHeader viewColumnHeader = new SourceGrid.Cells.Views.ColumnHeader(); DevAge.Drawing.VisualElements.ColumnHeader backHeader = new DevAge.Drawing.VisualElements.ColumnHeader(); backHeader.BackColor = Color.LightGray; backHeader.Border = DevAge.Drawing.RectangleBorder.NoBorder; viewColumnHeader.Background = backHeader; viewColumnHeader.ForeColor = Color.Black; viewColumnHeader.Font = new Font("Arial", GridFontSize, FontStyle.Regular); viewColumnHeader.ElementSort.SortStyle = DevAge.Drawing.HeaderSortStyle.None; // viewNormal CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.LightBlue, Color.White); // *** // set first row gridSolutions.BorderStyle = BorderStyle.FixedSingle; gridSolutions.ColumnsCount = 7; gridSolutions.FixedRows = 1; gridSolutions.Rows.Insert(0); // header int iCol = 0; SourceGrid.Cells.ColumnHeader columnHeader; // A1xA2xA3 columnHeader = new SourceGrid.Cells.ColumnHeader("A1 x A2 x A3"); columnHeader.AutomaticSortEnabled = false; columnHeader.View = viewColumnHeader; gridSolutions[0, iCol++] = columnHeader; // dimensions columnHeader = new SourceGrid.Cells.ColumnHeader( string.Format(Properties.Resources.ID_DIMENSIONS, UnitsManager.LengthUnitString)); columnHeader.AutomaticSortEnabled = false; columnHeader.View = viewColumnHeader; gridSolutions[0, iCol++] = columnHeader; // weight columnHeader = new SourceGrid.Cells.ColumnHeader(string.Format(Properties.Resources.ID_WEIGHT_WU, UnitsManager.MassUnitString)); columnHeader.AutomaticSortEnabled = false; columnHeader.View = viewColumnHeader; gridSolutions[0, iCol++] = columnHeader; // #packs columnHeader = new SourceGrid.Cells.ColumnHeader("#"); columnHeader.AutomaticSortEnabled = false; columnHeader.View = viewColumnHeader; gridSolutions[0, iCol++] = columnHeader; // weight columnHeader = new SourceGrid.Cells.ColumnHeader(string.Format(Properties.Resources.ID_PALLETWEIGHT, UnitsManager.MassUnitString)); columnHeader.AutomaticSortEnabled = false; columnHeader.View = viewColumnHeader; gridSolutions[0, iCol++] = columnHeader; // efficiency columnHeader = new SourceGrid.Cells.ColumnHeader(Properties.Resources.ID_EFFICIENCYPERCENTAGE); columnHeader.AutomaticSortEnabled = false; columnHeader.View = viewColumnHeader; gridSolutions[0, iCol++] = columnHeader; // maximum space columnHeader = new SourceGrid.Cells.ColumnHeader(string.Format(Properties.Resources.ID_MAXIMUMSPACE, UnitsManager.LengthUnitString)); columnHeader.AutomaticSortEnabled = false; columnHeader.View = viewColumnHeader; gridSolutions[0, iCol++] = columnHeader; int iRow = 0; foreach (AnalysisHomo analysis in _analyses) { AnalysisCasePallet analysisCasePallet = analysis as AnalysisCasePallet; PackProperties pack = analysisCasePallet.Content as PackProperties; int layerCount = analysisCasePallet.Solution.Layers.Count; if (layerCount < 1) { continue; } int packPerLayerCount = analysisCasePallet.Solution.Layers[0].BoxCount; int itemCount = analysisCasePallet.Solution.ItemCount; double palletWeight = analysisCasePallet.Solution.Weight; double volumeEfficiency = analysisCasePallet.Solution.VolumeEfficiency; double maximumSpace = analysisCasePallet.Solution.LayerCount > 0 ? analysisCasePallet.Solution.LayerMaximumSpace(0) : 0; gridSolutions.Rows.Insert(++iRow); iCol = 0; gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell(string.Format("{0} x {1} x {2}", pack.Arrangement.Length, pack.Arrangement.Width, pack.Arrangement.Height)); gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell(string.Format("{0:0.#} x {1:0.#} x {2:0.#}", pack.OuterDimensions.X, pack.OuterDimensions.Y, pack.OuterDimensions.Z)); gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell(string.Format("{0:0.###}", pack.Weight)); gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell(string.Format("{0} = {1} x {2}", itemCount, packPerLayerCount, layerCount)); gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell(string.Format("{0:0.###}", palletWeight)); gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell(string.Format("{0:0.#}", volumeEfficiency)); gridSolutions[iRow, iCol++] = new SourceGrid.Cells.Cell(string.Format("{0:0.#}", maximumSpace)); } gridSolutions.AutoStretchColumnsToFitWidth = true; gridSolutions.AutoSizeCells(); gridSolutions.Columns.StretchToFit(); // select first solution if (gridSolutions.RowsCount > 1) { gridSolutions.Selection.SelectRow(1, true); } else { // grid empty -> clear drawing _selectedAnalysis = null; graphCtrlPack.Invalidate(); graphCtrlSolution.Invalidate(); } } catch (Exception ex) { _log.Error(ex.Message); } }
public FormNewAnalysisCasePalletDM(Document doc, AnalysisHomo analysis) : base(doc, analysis) { InitializeComponent(); }
public ImageCached(AnalysisHomo analysis, HalfAxis.HAxis axisLength, HalfAxis.HAxis axisWidth) { _analysis = analysis; _axisLength = axisLength; _axisWidth = axisWidth; }
public ImageInst(AnalysisHomo analysis, Vector3D dims, BoxPosition boxPosition) { _analysis = analysis; _dims = dims; _boxPosition = boxPosition; }
public void AddImage(AnalysisHomo analysis, Vector3D vDimensions, BoxPosition boxPosition) { _listImageInst.Add(new ImageInst(analysis, vDimensions, boxPosition)); }
/// <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); } } }
private void OnCompute(object sender, EventArgs e) { try { if (Globals.StackBuilderAddIn.Application.ActiveSheet is Excel.Worksheet xlSheet) { Console.WriteLine(string.Format("Sheet name = {0}", xlSheet.Name)); double caseLength = ReadDouble(xlSheet, Settings.Default.CellCaseLength, Resources.ID_CASE_LENGTH); double caseWidth = ReadDouble(xlSheet, Settings.Default.CellCaseWidth, Resources.ID_CASE_WIDTH); double caseHeight = ReadDouble(xlSheet, Settings.Default.CellCaseHeight, Resources.ID_CASE_HEIGHT); double caseWeight = ReadDouble(xlSheet, Settings.Default.CellCaseWeight, Resources.ID_CASE_WEIGHT); double palletLength = ReadDouble(xlSheet, Settings.Default.CellPalletLength, Resources.ID_PALLET_LENGTH); double palletWidth = ReadDouble(xlSheet, Settings.Default.CellPalletWidth, Resources.ID_PALLET_WIDTH); double palletHeight = ReadDouble(xlSheet, Settings.Default.CellPalletHeight, Resources.ID_PALLET_HEIGHT); double palletWeight = ReadDouble(xlSheet, Settings.Default.CellPalletWeight, Resources.ID_PALLET_WEIGHT); double palletMaximumHeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletHeight, Resources.ID_CONSTRAINTS_PALLETMAXIHEIGHT); double palletMaximumWeight = ReadDouble(xlSheet, Settings.Default.CellMaxPalletWeight, Resources.ID_CONSTRAINTS_PALLETMAXIWEIGHT); // ### actually compute result ### // build a case BoxProperties bProperties = new BoxProperties(null, caseLength, caseWidth, caseHeight); bProperties.SetWeight(caseWeight); bProperties.SetColor(Color.Chocolate); bProperties.TapeWidth = new OptDouble(true, UnitsManager.ConvertLengthFrom(50.0, UnitsManager.UnitSystem.UNIT_METRIC1)); bProperties.TapeColor = Color.Beige; // build a pallet PalletProperties palletProperties = new PalletProperties(null, PalletTypeName, palletLength, palletWidth, palletHeight) { Weight = palletWeight, Color = Color.Yellow }; // build a constraint set ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); constraintSet.SetMaxHeight(new OptDouble(true, palletMaximumHeight)); constraintSet.OptMaxWeight = new OptDouble(true, palletMaximumWeight); // use a solver and get a list of sorted analyses + select the best one SolverCasePallet solver = new SolverCasePallet(bProperties, palletProperties); List <AnalysisHomo> analyses = solver.BuildAnalyses(constraintSet, true); if (analyses.Count > 0) { AnalysisHomo analysis = analyses[0]; int caseCount = analysis.Solution.ItemCount; // <- your case count double loadWeight = analysis.Solution.LoadWeight; double totalWeight = analysis.Solution.Weight; // <- your pallet weight Graphics3DImage graphics = null; // generate image path string stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); graphics = new Graphics3DImage(new Size(Settings.Default.ImageSize, Settings.Default.ImageSize)) { FontSizeRatio = Settings.Default.FontSizeRatio, CameraPosition = Graphics3D.Corner_0 }; ViewerSolution sv = new ViewerSolution(analysis.Solution); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath); WriteInt(xlSheet, Settings.Default.CellNoCases, Resources.ID_RESULT_NOCASES, caseCount); WriteDouble(xlSheet, Settings.Default.CellLoadWeight, Resources.ID_RESULT_LOADWEIGHT, loadWeight); WriteDouble(xlSheet, Settings.Default.CellTotalPalletWeight, Resources.ID_RESULT_TOTALPALLETWEIGHT, totalWeight); string filePath = string.Empty; Globals.StackBuilderAddIn.Application.ActiveSheet.Shapes.AddPicture( stackImagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Settings.Default.ImageLeft / 0.035, Settings.Default.ImageTop / 0.035, Settings.Default.ImageWidth / 0.035, Settings.Default.ImageHeight / 0.035); } // ### } } catch (Exception ex) { Console.WriteLine(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)); } // ### }