/// <summary> /// Drawing method used to draw factory content /// </summary> /// <param name="graphics">Graphic environment parameters</param> public void Draw(PicGraphics graphics, PicFilter filter) { graphics.Initialize(); // bounding box if (!graphics.DrawingBox.IsValid) { // compute bounding box using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { ProcessVisitor(visitor); Box2D box = visitor.Box; box.AddMarginRatio(0.01); // set as drawing box graphics.DrawingBox = box; } } // first, draw cotation foreach (PicEntity entity in _entities) { try { // cotation PicCotation cotation = entity as PicCotation; if (cotation != null && !cotation.Deleted && filter.Accept(entity)) { cotation.Draw(graphics); } } catch (Exception ex) { _log.Error(ex.Message); } } // then other entities foreach (Object o in _entities) { try { // drawable entities PicDrawable drawable = o as PicDrawable; if (drawable != null && !drawable.Deleted && !(drawable is PicCotation) && filter.Accept(drawable)) { drawable.Draw(graphics); } } catch (Exception ex) { _log.Error(ex.Message); } } // cardboard format if (null != _cardboardFormat) { _cardboardFormat.Draw(graphics); } graphics.Finish(); }
public static bool ComputePositionDefault(IEntityContainer factory, Box2D boxBorder, Vector2D spaceBetween, ref List <BPosition> lPos, ref Box2D bbox) { if (boxBorder.Width <= 0.0 || boxBorder.Height <= 0.0) { return(false); } ImpositionTool tool = Instantiate(factory, new ImpositionSettings(boxBorder.Width, boxBorder.Height)); tool.SpaceBetween = spaceBetween; tool.AllowOrthogonalImposition = true; tool.AllowBothDirection = false; tool.HorizontalAlignment = ImpositionSettings.HAlignment.HALIGN_LEFT; tool.VerticalAlignment = ImpositionSettings.VAlignment.VALIGN_BOTTOM; tool.GenerateSortedSolutionList(null, out List <ImpositionSolution> solutions); if (solutions.Count > 0) { ImpositionSolution impSol = solutions[0]; Vector2D cardboardPos = impSol.CardboardPosition; foreach (var p in impSol.Positions) { BPosition pos = p; pos.Pt += boxBorder.PtMin - cardboardPos; lPos.Add(pos); } Vector2D ptMin = impSol.Bbox.PtMin + boxBorder.PtMin; Vector2D ptMax = impSol.Bbox.PtMax + boxBorder.PtMin; bbox = new Box2D(ptMin, ptMax); } return(lPos.Count > 0); }
public void Extend(Box2D box) { _ptMin.X = Math.Min(_ptMin.X, box._ptMin.X); _ptMin.Y = Math.Min(_ptMin.Y, box._ptMin.Y); _ptMax.X = Math.Max(_ptMax.X, box._ptMax.X); _ptMax.Y = Math.Max(_ptMax.Y, box._ptMax.Y); }
public void GenerateImage(Size size, ParameterStack stack, out Image bmp) { // check if plugin was instantiated if (null == _component) { throw new Exception("No valid plugin instance loaded!"); } // instantiate factory PicFactory factory = new PicFactory(); // generate entities _component.CreateFactoryEntities(factory, stack); // apply any needed transformation if (_reflexionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (_reflexionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // get bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); Pic.Factory2D.Box2D box = visitor.Box; box.AddMarginRatio(0.05); // draw image PicGraphicsImage picImage = new PicGraphicsImage(size, box); factory.Draw(picImage, _showCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation); bmp = picImage.Bitmap; }
public void Dimensions(ParameterStack stack, out double width, out double height, out double lengthCut, out double lengthFold) { // build factory Pic.Factory2D.PicFactory factory = new Pic.Factory2D.PicFactory(); _component.CreateFactoryEntities(factory, stack); if (_reflexionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (_reflexionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // get bounding box Pic.Factory2D.PicVisitorBoundingBox visitorBoundingBox = new Pic.Factory2D.PicVisitorBoundingBox(); factory.ProcessVisitor(visitorBoundingBox, _showCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation); Pic.Factory2D.Box2D box = visitorBoundingBox.Box; width = box.Width; height = box.Height; // get length Pic.Factory2D.PicVisitorDieCutLength visitorLength = new Pic.Factory2D.PicVisitorDieCutLength(); factory.ProcessVisitor(visitorLength, PicFilter.FilterNone); lengthCut = visitorLength.Lengths.ContainsKey(PicGraphics.LT.LT_CUT) ? visitorLength.Lengths[PicGraphics.LT.LT_CUT] : 0.0; lengthFold = visitorLength.Lengths.ContainsKey(PicGraphics.LT.LT_CREASING) ? visitorLength.Lengths[PicGraphics.LT.LT_CREASING] : 0.0; }
public override Box2D ComputeBox(Transform2D transform) { Box2D box = Box2D.Initial; box.Extend(transform.transform(Pt)); return(box); }
public Box2D Transform(Transform2D transf) { Box2D box = Initial; box.Extend(transf.transform(_ptMin)); box.Extend(transf.transform(_ptMax)); return(box); }
/// <summary> /// Returns a value indicating whether this instance is equal to /// the specified object. /// </summary> /// <param name="obj">An object to compare to this instance.</param> /// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="Box2D"/> and has the same values as this instance; otherwise, <see langword="false"/>.</returns> public override bool Equals(object obj) { if (obj is Box2D) { Box2D v = (Box2D)obj; return((_ptMin == v._ptMin) && (_ptMax == v._ptMax)); } return(false); }
void _parentControl_SizeChanged(object sender, EventArgs e) { // force box recomputation if (_box.IsValid) { Pic.Factory2D.Box2D box = _box; DrawingBox = box; } }
public override void Initialize(PicFactory factory) { _exporter.Initialize(); _exporter.AuthoringTool = _authoringTool; // set bounding box Box2D bbox = Tools.BoundingBox(factory, 0.0); _exporter.SetBoundingBox(bbox.XMin, bbox.YMin, bbox.XMax, bbox.YMax); }
public byte[] GenerateExportFile(string fileFormat, ParameterStack stack) { // build factory Pic.Factory2D.PicFactory factory = new Pic.Factory2D.PicFactory(); _component.CreateFactoryEntities(factory, stack); if (_reflexionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (_reflexionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // instantiate filter PicFilter filter = (_showCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation) & PicFilter.FilterNoZeroEntities; // get bounding box Pic.Factory2D.PicVisitorBoundingBox visitorBoundingBox = new Pic.Factory2D.PicVisitorBoundingBox(); factory.ProcessVisitor(visitorBoundingBox, filter); Pic.Factory2D.Box2D box = visitorBoundingBox.Box; // add margins : 5 % of the smallest value among height box.AddMarginHorizontal(box.Width * 0.05); box.AddMarginVertical(box.Height * 0.05); // get file content if ("des" == fileFormat) { Pic.Factory2D.PicVisitorDesOutput visitor = new Pic.Factory2D.PicVisitorDesOutput(); visitor.Author = "treeDiM"; // process visitor factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } else if ("dxf" == fileFormat) { Pic.Factory2D.PicVisitorOutput visitor = new Pic.Factory2D.PicVisitorDxfOutput(); visitor.Author = "treeDiM"; // process visitor factory.ProcessVisitor(visitor, filter); return(visitor.GetResultByteArray()); } else if ("pdf" == fileFormat) { PicGraphicsPdf graphics = new PicGraphicsPdf(box); graphics.Author = "treeDiM"; graphics.Title = "Pdf Export"; // draw factory.Draw(graphics, filter); return(graphics.GetResultByteArray()); } else { throw new Exception("Invalid file format : " + fileFormat); } }
public override Box2D ComputeBox(Transform2D transform) { // instantiate bounding box Box2D box = Box2D.Initial; box.XMin = 0.0; box.YMin = 0.0; box.XMax = _dimensions.X; box.YMax = _dimensions.Y; return(box); }
public override Box2D ComputeBox(Transform2D transform) { Box2D box = Box2D.Initial; box.Extend(transform.transform(_pt0)); box.Extend(transform.transform(_pt1)); GetOffsetPoints(out Vector2D pt2, out Vector2D pt3); box.Extend(transform.transform(pt2)); box.Extend(transform.transform(pt3)); return(box); }
public static void GenerateImage(Size size, PicFactory factory, bool showCotations, out Image bmp) { // get bounding box Box2D box = Tools.BoundingBox(factory, 0.05); // draw image PicGraphicsImage picImage = new PicGraphicsImage(size, box); factory.Draw(picImage, showCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation); bmp = picImage.Bitmap; }
internal override ImpositionSolution GenerateSolution(ImpositionPattern pattern) { // instantiate solution ImpositionSolution solution = new ImpositionSolution(InitialEntities, pattern.Name, pattern.RequiresRotationInRows, pattern.RequiresRotationInColumns); // noRows / noCols solution.Rows = NoRowsExpected; solution.Cols = NoColsExpected; // number of each row / col of the pattern int[,] rowNumber = new int[pattern.NoRows, pattern.NoCols]; int[,] colNumber = new int[pattern.NoRows, pattern.NoCols]; int iCount = 0; for (int i = 0; i < pattern.NoRows; ++i) for (int j = 0; j < pattern.NoCols; ++j) { colNumber[i ,j] = NoRowsExpected / pattern.NoRows + (NoRowsExpected % pattern.NoRows) / (i+1); rowNumber[i, j] = NoColsExpected / pattern.NoCols + (NoColsExpected % pattern.NoCols) / (j+1); iCount += rowNumber[i, j] * colNumber[i, j]; } // verify count System.Diagnostics.Debug.Assert(iCount == NoRowsExpected * NoColsExpected); // compute offsets Box2D boxGlobal = pattern.BBox; double xOffset = _margin.X - boxGlobal.XMin; double yOffset = _margin.Y - boxGlobal.YMin; _box = new Box2D(); for (int i = 0; i < pattern.NoRows; ++i) for (int j = 0; j < pattern.NoCols; ++j) { Box2D localBox = pattern._bboxes[i,j]; for (int k = 0; k < rowNumber[i, j]; ++k) for (int l = 0; l < colNumber[i, j]; ++l) { // insert Box position BPosition pos = pattern._relativePositions[i, j]; pos._pt.X = xOffset + k * pattern.PatternStep.X + pos._pt.X; pos._pt.Y = yOffset + l * pattern.PatternStep.Y + pos._pt.Y; solution.Add(pos); // extend bounding box Vector2D vOffset = new Vector2D(xOffset + k * pattern.PatternStep.X, yOffset + l * pattern.PatternStep.Y); _box.Extend(new Box2D(vOffset + localBox.PtMin, vOffset + localBox.PtMax)); } } // compute actual margin solution.CardboardPosition = new Vector2D(_margin.X, _margin.Y); solution.CardboardDimensions = new Vector2D(_box.XMax - _box.XMin + _margin.X + _minMargin.X, _box.YMax - _box.YMin + _margin.Y + _minMargin.Y); return solution; }
public override Box2D ComputeBox(Transform2D transf) { Box2D box = new Box2D(); foreach (var entity in _entities) { if (entity is PicDrawable drawable) { box.Extend(drawable.ComputeBox(transf)); } } return(box); }
public override Box2D ComputeBox(Transform2D transf) { Box2D box = new Box2D(); foreach (PicEntity entity in _entities) { PicDrawable drawable = entity as PicDrawable; if (null != drawable) { box.Extend(drawable.ComputeBox(transf)); } } return(box); }
// global quotation private void BuildGlobalQuotation(PicFactory factory, short grp, Box2D box) { if (!box.IsValid) { return; } double delta = 0.1 * Math.Max(box.Width, box.Height); PicCotationDistance cotH = factory.AddCotation(PicCotation.CotType.COT_HORIZONTAL, grp, 0, box.PtMin, new Vector2D(box.XMax, box.YMin), -delta, "", 1) as PicCotationDistance; cotH.UseShortLines = true; PicCotationDistance cotV = factory.AddCotation(PicCotation.CotType.COT_VERTICAL, grp, 0, box.PtMin, new Vector2D(box.XMin, box.YMax), delta, "", 1) as PicCotationDistance; cotV.UseShortLines = true; }
public static void GenerateImage(Size size, PicFactory factory, bool showCotations, out Image bmp) { // get bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); Box2D box = visitor.Box; box.AddMarginRatio(0.05); // draw image PicGraphicsImage picImage = new PicGraphicsImage(size, box); factory.Draw(picImage, showCotations ? PicFilter.FilterNone : PicFilter.FilterCotation); bmp = picImage.Bitmap; }
public static Box2D BoundingBox(PicFactory factory, double marginRatio = 0.0, bool takePicBlocsIntoAccount = true) { var visitor = new PicVisitorBoundingBox() { TakePicBlocksIntoAccount = takePicBlocsIntoAccount }; factory.ProcessVisitor(visitor, !PicFilter.FilterCotation); Box2D box = visitor.Box; if (box.IsValid && marginRatio > 0.0) { box.AddMarginRatio(marginRatio); } return(box); }
public override Box2D ComputeBox(Transform2D transform) { Box2D box = Box2D.Initial; foreach (var entity in Block) { if (entity is PicDrawable drawable) { if (!(drawable is PicTypedDrawable typeDrawable) || typeDrawable.LineType != PicGraphics.LT.LT_CONSTRUCTION) { box.Extend(drawable.ComputeBox(transform * BlockTransformation)); } } } return(box); }
public override Box2D ComputeBox(Transform2D transform) { Box2D box = Box2D.Initial; foreach (PicEntity entity in _block) { PicDrawable drawable = entity as PicDrawable; if (null != drawable) { PicTypedDrawable typeDrawable = drawable as PicTypedDrawable; if (null == typeDrawable || typeDrawable.LineType != PicGraphics.LT.LT_CONSTRUCTION) { box.Extend(drawable.ComputeBox(transform * BlockTransformation)); } } } return(box); }
/// <summary> /// Initialize DES_Writer object /// </summary> /// <param name="factory"></param> public override void Initialize(PicFactory factory) { // save factory _factory = factory; // build .des file header DES_Header header = new DES_Header(); Box2D bbox = Tools.BoundingBox(factory, 0.0); header._xmin = (float)bbox.XMin; header._xmax = (float)bbox.XMax; header._ymin = (float)bbox.YMin; header._ymax = (float)bbox.YMax; // initialize des writer _desWriter = new DES_WriterMem(header); DES_SuperBaseHeader superBaseHeader = new DES_SuperBaseHeader(); _desWriter.WriteSuperBaseHeader(superBaseHeader); }
public override void GeneratePattern(IEntityContainer container, Vector2D minDistance, Vector2D impositionOffset, bool ortho) { using (PicFactory factory = new PicFactory()) { // instantiate block and BlockRef PicBlock block = factory.AddBlock(container); PicBlockRef blockRef00 = factory.AddBlockRef(block, new Vector2D(0.0, 0.0), ortho ? 90.0 : 0.0); // compute bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); visitor.TakePicBlocksIntoAccount = false; factory.ProcessVisitor(visitor, !PicFilter.FilterCotation); Box2D boxEntities = visitor.Box; // compute default X step PicBlockRef blockRef01 = factory.AddBlockRef(block, new Vector2D(5.0 * boxEntities.Width + minDistance.X, 0.0), ortho ? 90.0 : 0.0); double horizontalDistance = 0.0; if (!PicBlockRef.Distance(blockRef00, blockRef01, PicBlockRef.DistDirection.HORIZONTAL_RIGHT, out horizontalDistance)) { throw new Exception("Failed to compute distance between to block refs"); } _patternStep.X = 5.0 * boxEntities.Width - horizontalDistance + 2.0 * minDistance.X; // compute default Y step PicBlockRef blockRef10 = factory.AddBlockRef(block, new Vector2D(0.0, 5.0 * boxEntities.Height + minDistance.Y), ortho ? 90.0 : 0.0); double verticalDistance = 0.0; if (!PicBlockRef.Distance(blockRef00, blockRef10, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance)) { throw new Exception("Failed to compute distance between to block refs"); } _patternStep.Y = 5.0 * boxEntities.Height - verticalDistance + 2.0 * minDistance.Y; // positions _relativePositions = new BPosition[1, 1]; BPosition position = new BPosition(Vector2D.Zero, ortho ? 90.0 : 0.0); _relativePositions[0, 0] = position; // bboxes _bboxes = new Box2D[1, 1]; _bboxes[0, 0] = blockRef00.Box;//boxEntities; } }
public override Box2D ComputeBox(Transform2D transform) { // instantiate bounding box Box2D box = Box2D.Initial; // 6 points to be considered // arc extremities _box.Extend(transform.transform(PointAtAngle(AngleBegActual))); _box.Extend(transform.transform(PointAtAngle(AngleEndActual))); // horizontal and vertical tangent points double[] tab = new double[] { 0.0, 90.0, 180.0, 270.0 }; foreach (double d in tab) { if (PointOnArc(d)) { box.Extend(transform.transform(PointAtAngle(d))); } } return(box); }
public static bool GetBBCotations( Box2D bbox, CotBBType cotBBType, double offsetRatio, out Vector2D pt0, out Vector2D pt1, out Vector2D pt2, out Vector2D pt3, out double delta0, out double delta1) { double deltaHoriz = offsetRatio * bbox.Width; double deltaVert = offsetRatio * bbox.Height; Vector2D v0 = bbox.PtMin; Vector2D v1 = new Vector2D(bbox.XMax, bbox.XMin); Vector2D v2 = bbox.PtMax; Vector2D v3 = new Vector2D(bbox.XMin, bbox.YMax); switch (cotBBType) { case CotBBType.COT_LOWERLEFT: pt0 = v0; pt1 = v1; pt2 = v3; pt3 = v0; delta0 = -deltaVert; delta1 = deltaHoriz; return(true); case CotBBType.COT_LOWERRIGHT: pt0 = v0; pt1 = v1; pt2 = v1; pt3 = v2; delta0 = -deltaVert; delta1 = -deltaHoriz; return(true); case CotBBType.COT_UPPERRIGHT: pt0 = v2; pt1 = v3; pt2 = v1; pt3 = v2; delta0 = deltaVert; delta1 = -deltaHoriz; return(true); case CotBBType.COT_UPPERLEFT: pt0 = v2; pt1 = v3; pt2 = v3; pt3 = v0; delta0 = deltaVert; delta1 = deltaHoriz; return(true); default: pt0 = Vector2D.Zero; pt1 = Vector2D.Zero; pt2 = Vector2D.Zero; pt3 = Vector2D.Zero; delta0 = 0.0; delta1 = 0.0; return(false); } }
void FactoryViewer_MouseWheel(object sender, MouseEventArgs e) { try { Pic.Factory2D.Box2D box = new Pic.Factory2D.Box2D(_picGraphics.DrawingBox); box.Zoom((double)-e.Delta / 1000.0); _picGraphics.DrawingBox = box; } catch (InvalidBoxException ex) { _log.Error(ex.ToString()); } catch (Exception ex) { _log.Error(ex.ToString()); } finally { Invalidate(); } }
public void GenerateThumbnail() { using (PicFactory factory = new PicFactory()) { CreateEntities(factory); // compute bounding box without format PicVisitorBoundingBox visitor0 = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor0); _box = visitor0.Box; // insert format factory.InsertCardboardFormat(CardboardPosition, CardboardDimensions); // compute bounding box with format PicVisitorBoundingBox visitor1 = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor1); // draw thumbnail PicGraphicsImage picImage = new PicGraphicsImage(new System.Drawing.Size(50, 50), visitor1.Box); factory.Draw(picImage); // save thumbnail _thumbnail = picImage.Bitmap; } }
private void RePaint(PaintEventArgs e, ParameterStack stack) { try { // instantiate PicGraphics if (_picGraphics == null) _picGraphics = new PicGraphicsCtrlBased(this.Panel1.ClientSize, e.Graphics); _picGraphics.GdiGraphics = e.Graphics; _picGraphics.Size = this.Panel1.ClientSize; // instantiate filter PicFilter filter = _showCotations ? PicFilter.FilterNone : PicFilter.FilterCotation; // build factory using (Pic.Factory2D.PicFactory factory = new Pic.Factory2D.PicFactory()) { // create entities Component.CreateFactoryEntities(factory, stack); if (_reflectionX) factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); if (_reflectionY) factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); // remove existing quotations factory.Remove((new PicFilterCode(PicEntity.eCode.PE_COTATIONDISTANCE)) | (new PicFilterCode(PicEntity.eCode.PE_COTATIONHORIZONTAL)) | (new PicFilterCode(PicEntity.eCode.PE_COTATIONVERTICAL)) ); // build auto quotation if (_showCotations) PicAutoQuotation.BuildQuotation(factory); // update drawing box? if (_computeBbox) { Pic.Factory2D.PicVisitorBoundingBox visitor = new Pic.Factory2D.PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); _box = new Box2D(visitor.Box); Box2D box = visitor.Box; box.AddMarginRatio(0.05); _picGraphics.DrawingBox = box; // update factory data if (null != factoryDataCtrl) factoryDataCtrl.Factory = factory; _computeBbox = false; } // draw factory.Draw(_picGraphics, filter); } } catch (Pic.Plugin.PluginException ex) { // might happen _picGraphics.ShowMessage(ex.Message); } catch (Exception ex) { _picGraphics.ShowMessage(ex.ToString()); _log.Error(ex.ToString()); } }
private void Panel1_MouseWheel(object sender, MouseEventArgs e) { try { Pic.Factory2D.Box2D box = new Pic.Factory2D.Box2D(_picGraphics.DrawingBox); box.Zoom((double)-e.Delta / 1000.0); _picGraphics.DrawingBox = box; } catch (InvalidBoxException /*ex*/) { _computeBbox = true; } catch (Exception ex) { _log.Debug(ex.ToString()); } finally { Panel1.Invalidate(); } }
internal override ImpositionSolution GenerateSolution(ImpositionPattern pattern) { // instantiate solution ImpositionSolution solution = new ImpositionSolution(InitialEntities, pattern.Name, pattern.RequiresRotationInRows, pattern.RequiresRotationInColumns); // noRows / noCols solution.Rows = NoRowsExpected; solution.Cols = NoColsExpected; // number of each row / col of the pattern int[,] rowNumber = new int[pattern.NoRows, pattern.NoCols]; int[,] colNumber = new int[pattern.NoRows, pattern.NoCols]; int iCount = 0; for (int i = 0; i < pattern.NoRows; ++i) { for (int j = 0; j < pattern.NoCols; ++j) { colNumber[i, j] = NoRowsExpected / pattern.NoRows + (NoRowsExpected % pattern.NoRows) / (i + 1); rowNumber[i, j] = NoColsExpected / pattern.NoCols + (NoColsExpected % pattern.NoCols) / (j + 1); iCount += rowNumber[i, j] * colNumber[i, j]; } } // verify count System.Diagnostics.Debug.Assert(iCount == NoRowsExpected * NoColsExpected); // compute offsets Box2D boxGlobal = pattern.BBox; double xOffset = _margin.X - boxGlobal.XMin; double yOffset = _margin.Y - boxGlobal.YMin; _box = new Box2D(); for (int i = 0; i < pattern.NoRows; ++i) { for (int j = 0; j < pattern.NoCols; ++j) { Box2D localBox = pattern._bboxes[i, j]; for (int k = 0; k < rowNumber[i, j]; ++k) { for (int l = 0; l < colNumber[i, j]; ++l) { // insert Box position BPosition pos = pattern._relativePositions[i, j]; pos._pt.X = xOffset + k * pattern.PatternStep.X + pos._pt.X; pos._pt.Y = yOffset + l * pattern.PatternStep.Y + pos._pt.Y; solution.Add(pos); // extend bounding box Vector2D vOffset = new Vector2D(xOffset + k * pattern.PatternStep.X, yOffset + l * pattern.PatternStep.Y); _box.Extend(new Box2D(vOffset + localBox.PtMin, vOffset + localBox.PtMax)); } } } } // compute actual margin solution.CardboardPosition = new Vector2D(_margin.X, _margin.Y); solution.CardboardDimensions = new Vector2D(_box.XMax - _box.XMin + _margin.X + _minMargin.X, _box.YMax - _box.YMin + _margin.Y + _minMargin.Y); return(solution); }
public PicGraphicsPdf(Box2D box) { bbox = box; author = ""; title = ""; }
public override void ProcessFactory(PicFactory factory) { // initialization _segList.Clear(); _box = new Box2D(); _area = 0.0; // build list of segments with entities that belongs to group factory.ProcessToolAllEntities(this); _box.AddMarginRatio(0.2); // exit if no of segments exceeds MAXSEG int maxSeg = Pic.Factory2D.Properties.Settings.Default.AreaMaxNoSegments; if (_segList.Count > maxSeg) throw new PicToolTooLongException(string.Format("No of segments exceeds {0}", maxSeg)); // compute actual step size uint iNoStep = (uint)(_box.Width / _stepSize); iNoStep = Math.Min(iNoStep, _iNoStepMax); double stepDefault = _box.Width / iNoStep; // compute area for (int i = 0; i < iNoStep; ++i) { double xh = _box.XMin + i * stepDefault; int nby = 1; double stepCurrent = stepDefault; List<double> tabyh = new List<double>(); tabyh.Add(double.MaxValue); bool bAgain = false; do { bAgain = false; stepCurrent = stepDefault; foreach (Segment segTemp in _segList) { Segment seg; if (segTemp.P0.X <= segTemp.P1.X) seg = segTemp; else seg = new Segment(segTemp.P1, segTemp.P0); if (xh >= seg.P0.X && xh <= seg.P1.X) { // cas intersections confondues if ((Math.Abs(xh - seg.P0.X) < 0.001) || (Math.Abs(seg.P1.X - xh) < 0.001)) { // restart loop from the beginning nby = 1; tabyh[0] = double.MaxValue; stepCurrent = 0.9 * stepDefault; xh -= stepDefault * 0.1; bAgain = true; break; } else { double yh = seg.P0.Y + (xh - seg.P0.X) * ((seg.P1.Y - seg.P0.Y) / (seg.P1.X - seg.P0.X)); tabyh.Add(yh); } } } } while (bAgain); tabyh.Sort(); nby = tabyh.Count; // increment area if (nby > 1 && (nby % 2 != 0)) { for (int l = 0; l < nby - 1; l += 2) { _area = _area + stepCurrent * (tabyh[l + 1] - tabyh[l]); } } } }
public bool Contains(Box2D box) { double epsilon = Sharp3D.Math.Core.MathFunctions.EpsilonD; return _ptMin.X - box._ptMin.X <= epsilon && _ptMin.Y - box._ptMin.Y <= epsilon && _ptMax.X - box._ptMax.X >= -epsilon && _ptMax.Y - box._ptMax.Y >= -epsilon; }
protected PicGraphics() { _box = new Box2D(); }
static void Main(string[] args) { // set up a simple configuration that logs on the console. XmlConfigurator.Configure(); string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; try { _log.Info(assemblyName + " starting..."); const PicGraphics.LT ltCut = PicGraphics.LT.LT_CUT; // instantiate factory PicFactory initialFactory = new PicFactory(); ParameterStack stack = Program.Parameters; Program.CreateFactoryEntities(initialFactory, stack, Transform2D.Identity); // imposition double width = 1000.0, height = 1000.0; ImpositionTool impositionTool = new ImpositionToolCardboardFormat(initialFactory, new CardboardFormat(0, "Format1", "Format1", width, height)); impositionTool.SpaceBetween = new Vector2D(0.0, 0.0); impositionTool.Margin = new Vector2D(0.0, 0.0); List<ImpositionSolution> solutions; impositionTool.GenerateSortedSolutionList(null, out solutions); _log.Info(string.Format("{0} : Solutions", solutions.Count)); if (solutions.Count <= 0) return; foreach (ImpositionSolution chosenSolution in solutions) { _log.Info(string.Format("NoRows={0}, NoCols={1}", chosenSolution.Rows, chosenSolution.Cols)); PicFactory factoryOut = new PicFactory(); chosenSolution.CreateEntities(factoryOut); factoryOut.AddSegment(ltCut, new Vector2D(0.0, 0.0), new Vector2D(width, 0.0)); factoryOut.AddSegment(ltCut, new Vector2D(width, 0.0), new Vector2D(width, height)); factoryOut.AddSegment(ltCut, new Vector2D(width, height), new Vector2D(0.0, height)); factoryOut.AddSegment(ltCut, new Vector2D(0.0, height), new Vector2D(0.0, 0.0)); // get bounding box Box2D box = new Box2D(); using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { factoryOut.ProcessVisitor(visitor); box = visitor.Box; } string filePath = Path.Combine(Path.GetTempPath(), "Imposition.bmp"); PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = new System.Drawing.Size(4096, 4096); box.AddMargin(1.0); picImage.DrawingBox = box; factoryOut.Draw(picImage); picImage.SaveAs(filePath); System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), filePath); _log.Info(assemblyName + " ending..."); } } catch (Exception ex) { _log.Error(ex.ToString()); } }
public override void GeneratePattern(IEntityContainer container, Vector2D minDistance, Vector2D impositionOffset, bool ortho) { using (PicFactory factory = new PicFactory()) { // 20 21 // 10 11 12 // 00 01 02 // // instantiate block and BlockRef PicBlock block = factory.AddBlock(container); PicBlockRef blockRef00 = factory.AddBlockRef(block, new Vector2D(0.0, 0.0), ortho ? 90.0 : 0.0); // compute bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); visitor.TakePicBlocksIntoAccount = false; factory.ProcessVisitor(visitor, new PicFilter()); Box2D boxEntities = visitor.Box; // compute second entity position PicBlockRef blockRef10 = factory.AddBlockRef(block , new Vector2D( boxEntities.XMin + boxEntities.XMax + (ortho ? 0.0 : 1.0) * impositionOffset.X , boxEntities.YMin + boxEntities.YMax + 5.0 * boxEntities.Height + minDistance.Y + (ortho ? 1.0 : 0.0) * impositionOffset.Y ), ortho ? 270.0 : 180.0); double verticalDistance = 0.0; if (!PicBlockRef.Distance(blockRef00, blockRef10, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance)) { throw new Exception("Failed to compute distance between to block refs"); } Vector2D vecPosition = new Vector2D( boxEntities.XMin + boxEntities.XMax + (ortho ? 0.0 : 1.0) * impositionOffset.X , boxEntities.YMin + boxEntities.YMax + 5.0 * boxEntities.Height + 2.0 * minDistance.Y - verticalDistance + (ortho ? 1.0 : 0.0) * impositionOffset.Y); blockRef10.Position = vecPosition; // positions _relativePositions = new BPosition[2, 1]; _relativePositions[0, 0] = new BPosition(Vector2D.Zero, ortho ? 90.0 : 0.0); _relativePositions[1, 0] = new BPosition(vecPosition, ortho ? 270.0 : 180.0); // bboxes _bboxes = new Box2D[2, 1]; _bboxes[0, 0] = blockRef00.Box;//boxEntities; _bboxes[1, 0] = blockRef10.Box; // compute X step (col1 / col0) // col0 List <PicBlockRef> listCol0 = new List <PicBlockRef>(); listCol0.Add(blockRef00); listCol0.Add(blockRef10); // col1 PicBlockRef blockRef01 = factory.AddBlockRef(block , new Vector2D(5.0 * boxEntities.Width + minDistance.X, 0.0) , ortho ? 90.0 : 0.0); PicBlockRef blockRef11 = factory.AddBlockRef(block , new Vector2D(5.0 * boxEntities.Width + minDistance.X + vecPosition.X, vecPosition.Y) , ortho ? 270.0 : 180.0); List <PicBlockRef> listCol1 = new List <PicBlockRef>(); listCol1.Add(blockRef01); listCol1.Add(blockRef11); double horizontalDistance = 0.0; if (!PicBlockRef.Distance(listCol0, listCol1, PicBlockRef.DistDirection.HORIZONTAL_RIGHT, out horizontalDistance)) { throw new Exception("Failed to compute distance between to block refs"); } _patternStep.X = 5.0 * boxEntities.Width - horizontalDistance + 2.0 * minDistance.X; blockRef01.Position = vecPosition; blockRef11.Position = new Vector2D(vecPosition.X + _patternStep.X, vecPosition.Y); // compute Y step (row2 / row1) // row1 List <PicBlockRef> listRow1 = new List <PicBlockRef>(); listRow1.Add(blockRef10); listRow1.Add(blockRef11); PicBlockRef blockRef20 = factory.AddBlockRef(block , new Vector2D(0.0, 5.0 * (boxEntities.Height + minDistance.Y)) , ortho ? 90.0 : 0.0); PicBlockRef blockRef21 = factory.AddBlockRef(block , new Vector2D(_patternStep.X, 5.0 * (boxEntities.Height + minDistance.Y)) , ortho ? 90.0 : 0.0); List <PicBlockRef> listRow2 = new List <PicBlockRef>(); listRow2.Add(blockRef20); listRow2.Add(blockRef21); verticalDistance = 0.0; if (!PicBlockRef.Distance(listRow1, listRow2, PicBlockRef.DistDirection.VERTICAL_TOP, out verticalDistance)) { throw new Exception("Failed to compute distance between to block refs"); } _patternStep.Y = 5.0 * boxEntities.Height - verticalDistance + 6.0 * minDistance.Y; } }
public PicGraphicsImage(Size size, Box2D box) { ImageSize = size; DrawingBox = box; }
public Box2D(Box2D box) { Extend(box._ptMin); Extend(box._ptMax); }