private static Vector2D OppositePoint(PicTypedDrawable entity, Vector2D pt) { PicSegment seg = entity as PicSegment; if (null != seg) { if ((seg.Pt0 - pt).GetLength() < (seg.Pt1 - pt).GetLength()) { return(seg.Pt1); } else { return(seg.Pt0); } } PicArc arc = entity as PicArc; if (null != arc) { if ((arc.Source - pt).GetLength() < (arc.Target - pt).GetLength()) { return(arc.Target); } else { return(arc.Source); } } return(Vector2D.Zero); }
private static bool EntityPoints(PicTypedDrawable entity, Vector2D pt, ref Vector2D pt0, ref Vector2D pt1) { PicSegment seg = entity as PicSegment; if (null != seg) { if ((pt - seg.Pt0).GetLength() < (pt - seg.Pt1).GetLength()) { pt0 = seg.Pt0; pt1 = seg.Pt1; } else { pt0 = seg.Pt1; pt1 = seg.Pt0; } } PicArc arc = entity as PicArc; if (null != arc) { if ((pt - arc.Source).GetLength() < (pt - arc.Target).GetLength()) { pt0 = arc.Source; pt1 = arc.Target; } else { pt1 = arc.Target; pt0 = arc.Source; } } return((pt0 - pt).GetLength() < _epsilon); }
public void ExportEntity(ExpBlock block, PicEntity entity) { PicTypedDrawable drawable = entity as PicTypedDrawable; ExpLayer layer = null; ExpPen pen = null; if (null != drawable) { pen = _exporter.GetPenByAttribute(LineTypeToExpPen(drawable.LineType)); layer = _exporter.GetLayerByName(string.Format("Layer {0}", drawable.Layer)); } PicSegment seg = entity as PicSegment; if (null != seg) { _exporter.AddSegment(block, layer, pen, seg.Pt0.X, seg.Pt0.Y, seg.Pt1.X, seg.Pt1.Y); } PicArc arc = entity as PicArc; if (null != arc) { // using dxf conversions double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg; if (ang < 0.0) { angd += ang; ango = -ang; } else { ango = ang; } _exporter.AddArc(block, layer, pen, arc.Center.X, arc.Center.Y, arc.Radius, angd, angd + ango); } }
private static List <Segment> BlockRefToSegmentList(PicBlockRef blockRef, double angle) { Transform2D transform = Transform2D.Rotation(angle); List <Segment> segList = new List <Segment>(); Transform2D transformBlock = transform * blockRef.BlockTransformation; // convert bolckRef1 to segList1 foreach (PicEntity entity1 in blockRef._block) { PicSegment picSeg1 = entity1 as PicSegment; if (null != picSeg1) { Segment seg = new Segment(picSeg1.Pt0, picSeg1.Pt1); seg.Transform(transformBlock); segList.Add(seg); } PicArc picArc1 = entity1 as PicArc; if (null != picArc1) { Arc arc = new Arc(picArc1.Center, (float)picArc1.Radius, (float)(picArc1.AngleBeg), (float)(picArc1.AngleEnd)); List <Segment> arcExploded = arc.Explode(20); foreach (Segment seg in arcExploded) { seg.Transform(transformBlock); segList.Add(seg); } } } return(segList); }
/// <summary> /// insert new arc /// </summary> /// <param name="arc"></param> public void AddArc(DES_Arc arc) { float angle0 = arc._dir , angle1 = arc._dir + arc._angle; if (arc._angle > 0.0f) { } else { angle0 += arc._angle; angle1 -= arc._angle; while (angle0 < 0) { angle0 += 360.0f; angle1 += 360.0f; } } PicArc picArc = Factory.AddArc( DesPenToLineType(arc._pen), arc._grp, arc._layer, new Vector2D(arc._x, arc._y), arc._dim, angle0, angle1 ); }
void ProcessDxfCircle(DxfCircle dxfCircle) { PicArc picArc = Factory.AddArc( DxfColor2PicLT(dxfCircle), DxfLayer2PicGrp(dxfCircle.Layer), 0 , new Vector2D(dxfCircle.Center.X, dxfCircle.Center.Y) , dxfCircle.Radius , 0.0, 360.0 ); }
public static PicArc CreateNewArc(uint id, PicGraphics.LT lType, Vector2D center, double radius, double angleBeg, double angleEnd) { PicArc arc = new PicArc(id, lType); arc._center = center; arc._radius = radius; arc._angleBeg = angleBeg; arc._angleEnd = angleEnd; return arc; }
public override PicEntity Clone(IEntityContainer factory) { PicArc arc = new PicArc(factory.GetNewEntityId(), LineType); arc._center = this._center; arc._radius = this._radius; arc._angleBeg = this._angleBeg; arc._angleEnd = this._angleEnd; return(arc); }
public static PicArc CreateNewArc(uint id, PicGraphics.LT lType, Vector2D center, double radius, double angleBeg, double angleEnd) { PicArc arc = new PicArc(id, lType); arc._center = center; arc._radius = radius; arc._angleBeg = angleBeg; arc._angleEnd = angleEnd; return(arc); }
/// <summary> /// Add a new arc with center, radius, start angle and end angle /// </summary> /// <param name="lType">Line type</param> /// <param name="grp">Group</param> /// <param name="layer">Layer</param> /// <param name="xc">abscissa of center</param> /// <param name="yc">ordinate of center</param> /// <param name="radius">Radius of arc</param> /// <param name="angle0">Start angle</param> /// <param name="angle1">End angle</param> public PicArc AddArc(PicGraphics.LT lType, short grp, short layer , double xc, double yc, double radius, double angle0, double angle1) { PicArc arc = PicArc.CreateNewArc(GetNewEntityId(), lType, new Vector2D(xc, yc), radius, angle0, angle1); arc.Group = grp; arc.Layer = layer; AddEntity(arc); return(arc); }
/// <summary> /// Add a new arc with center, first point and second point /// </summary> /// <param name="lType">Line type</param> /// <param name="ptCenter">Center</param> /// <param name="radius">Radius of arc</param> /// <param name="pt0">Start point</param> /// <param name="pt1">End point</param> public PicArc AddArc(PicGraphics.LT lType, short grp, short layer , Vector2D ptCenter, Vector2D pt0, Vector2D pt1) { PicArc arc = PicArc.CreateNewArc(GetNewEntityId(), lType, ptCenter, pt0, pt1); arc.Group = grp; arc.Layer = layer; AddEntity(arc); return(arc); }
void ProcessDxfArc(DxfArc dxfArc) { double angle0 = dxfArc.StartAngle; double angle1 = dxfArc.EndAngle; double angle = dxfArc.EndAngle - dxfArc.StartAngle; if (angle > 0.0) { PicArc picArc = Factory.AddArc( DxfColor2PicLT(dxfArc), DxfLayer2PicGrp(dxfArc.Layer), 0 , new Vector2D(dxfArc.Center.X, dxfArc.Center.Y) , dxfArc.Radius , angle0, angle1 ); } else { while (angle < 0) { angle += 360.0; } while (angle > 360.0) { angle -= 360.0; } angle0 += angle; angle1 -= angle; while (angle0 < 0.0) { angle0 += 360.0; angle1 += 360.0; } while (angle0 >= 360.0) { angle0 -= 360.0; } PicArc picArc = Factory.AddArc( DxfColor2PicLT(dxfArc), DxfLayer2PicGrp(dxfArc.Layer), 0 , new Vector2D(dxfArc.Center.X, dxfArc.Center.Y) , dxfArc.Radius , angle0, angle1 ); } }
public void ExportEntity(ExpBlock block, PicEntity entity) { PicTypedDrawable drawable = entity as PicTypedDrawable; ExpLayer layer = null; ExpPen pen = null; if (null != drawable) { pen = _exporter.GetPenByAttribute(LineTypeToExpPen(drawable.LineType)); layer = _exporter.GetLayerByName(string.Format("Layer {0}", drawable.Layer)); } PicSegment seg = entity as PicSegment; if (null != seg) { _exporter.AddSegment(block, layer, pen, seg.Pt0.X, seg.Pt0.Y, seg.Pt1.X, seg.Pt1.Y); } PicArc arc = entity as PicArc; if (null != arc) { // using dxf conversions double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg; if (ang < 0.0) { angd += ang; ango = -ang; } else { ango = ang; } _exporter.AddArc(block, layer, pen, arc.Center.X, arc.Center.Y, arc.Radius, angd, angd + ango); } PicCotationDistance cotation = drawable as PicCotationDistance; if (null != cotation) { List <Segment> segments = new List <Segment>(); Vector2D textPt = Vector2D.Zero; double textSize = 0.0; cotation.DrawSeg(ref segments, ref textPt, ref textSize); foreach (Segment cotSeg in segments) { _exporter.AddSegment(block, layer, pen, cotSeg.P0.X, cotSeg.P0.Y, cotSeg.P1.X, cotSeg.P1.Y); } _exporter.AddText(block, layer, pen, textPt.X, textPt.Y, cotation.Text); } }
private static double DistanceEntityPt(PicTypedDrawable entity, Vector2D pt) { PicSegment seg = entity as PicSegment; if (null != seg) { return(Math.Min((seg.Pt0 - pt).GetLength(), (seg.Pt1 - pt).GetLength())); } PicArc arc = entity as PicArc; if (null != arc) { return(Math.Min((arc.Source - pt).GetLength(), (arc.Target - pt).GetLength())); } return(0.0); }
public static PicArc CreateNewArc(uint id, PicGraphics.LT lType, Vector2D center, Vector2D pt0, Vector2D pt1) { PicArc arc = new PicArc(id, lType); arc._center = center; arc._radius = (pt0 - center).GetLength(); arc._angleBeg = vecToAngleDeg(pt0 - center); arc._angleEnd = vecToAngleDeg(pt1 - center); while (arc._angleBeg < 0.0) { arc._angleBeg += 360.0; } while (arc._angleEnd < arc._angleBeg) { arc._angleEnd += 360.0; } return(arc); }
public void CreateEntities(PicFactory factory) { if (null == _entities) { return; } // show entities for (int i = 0; i < Math.Min(_entities.Count, trackBarEntities.Value); ++i) { PicTypedDrawable entity = _entities[i]; PicSegment seg = entity as PicSegment; if (null != seg) { factory.AddSegment(seg.LineType, seg.Group, seg.Layer, seg.Pt0, seg.Pt1); } PicArc arc = entity as PicArc; if (null != arc) { factory.AddArc(arc.LineType, arc.Group, arc.Layer, arc.Center, arc.Radius, arc.AngleBeg, arc.AngleEnd); } } }
/// <summary> /// ProcessEntity : write entity corresponding dxf description in line buffer /// </summary> /// <param name="entity">Entity</param> public override void ProcessEntity(PicEntity entity) { PicTypedDrawable drawable = (PicTypedDrawable)entity; if (null != drawable) { switch (drawable.Code) { case PicEntity.eCode.PE_POINT: break; case PicEntity.eCode.PE_SEGMENT: { PicSegment seg = (PicSegment)entity; dxf.writeLine( dw , new DL_LineData( seg.Pt0.X // start point , seg.Pt0.Y , 0.0 , seg.Pt1.X // end point , seg.Pt1.Y , 0.0 , 256 , LineTypeToDxfLayer(seg.LineType) ) , new DL_Attributes(LineTypeToDxfLayer(seg.LineType), 256, -1, "BYLAYER") ); } break; case PicEntity.eCode.PE_ARC: { PicArc arc = (PicArc)entity; double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg; if (ang < 0.0) { angd += ang; ango = -ang; } else { ango = ang; } dxf.writeArc(dw, new DL_ArcData( arc.Center.X, arc.Center.Y, 0.0, arc.Radius, angd, angd + ango, 256, LineTypeToDxfLayer(arc.LineType) ), new DL_Attributes(LineTypeToDxfLayer(arc.LineType), 256, -1, "BYLAYER") ); } break; case PicEntity.eCode.PE_ELLIPSE: break; case PicEntity.eCode.PE_NURBS: break; default: throw new Exception("Can not export this kind of entity!"); } } }
public static PicArc CreateNewArc(uint id, PicGraphics.LT lType, Vector2D center, Vector2D pt0, Vector2D pt1) { PicArc arc = new PicArc(id, lType); arc._center = center; arc._radius = (pt0 - center).GetLength(); arc._angleBeg = vecToAngleDeg(pt0 - center); arc._angleEnd = vecToAngleDeg(pt1 - center); while (arc._angleBeg < 0.0) arc._angleBeg += 360.0; while (arc._angleEnd < arc._angleBeg) arc._angleEnd += 360.0; return arc; }
/// <summary> /// ProcessEntity : write entity corresponding des description /// </summary> /// <param name="entity"></param> public override void ProcessEntity(PicEntity entity) { switch (entity.Code) { case PicEntity.ECode.PE_POINT: break; case PicEntity.ECode.PE_SEGMENT: { PicSegment seg = (PicSegment)entity; _desWriter.WriteSegment( new DES_Segment( (float)seg.Pt0.X , (float)seg.Pt0.Y , (float)seg.Pt1.X , (float)seg.Pt1.Y , LineTypeToDesPen(seg.LineType) , (byte)seg.Group , (byte)seg.Layer ) ); } break; case PicEntity.ECode.PE_ARC: { PicArc arc = (PicArc)entity; _desWriter.WriteArc( new DES_Arc( (float)arc.Center.X , (float)arc.Center.Y , (float)arc.Radius , (float)arc.AngleBeg , (float)arc.AngleEnd , LineTypeToDesPen(arc.LineType) , (byte)arc.Group , (byte)arc.Layer ) ); } break; case PicEntity.ECode.PE_COTATIONDISTANCE: { PicCotationDistance cotation = entity as PicCotationDistance; _desWriter.WriteCotationDistance( new DES_CotationDistance( (float)cotation.Pt0.X, (float)cotation.Pt0.Y, (float)cotation.Pt1.X, (float)cotation.Pt1.Y , LineTypeToDesPen(cotation.LineType) , (byte)cotation.Group , (byte)cotation.Layer , (float)cotation.Offset , 0.0f , 0.0f , 0.0f , false, false, false, false, 1, cotation.Text, ' ') ); } break; case PicEntity.ECode.PE_COTATIONHORIZONTAL: { PicCotationHorizontal cotation = entity as PicCotationHorizontal; // get offset points Vector2D offsetPt0, offsetPt1; cotation.GetOffsetPoints(out offsetPt0, out offsetPt1); _desWriter.WriteCotationDistance( new DES_CotationDistance( (float)offsetPt0.X, (float)offsetPt0.Y, (float)offsetPt1.X, (float)offsetPt1.Y , LineTypeToDesPen(cotation.LineType) , (byte)cotation.Group , (byte)cotation.Layer , (float)(cotation.Pt0.Y - offsetPt0.Y + cotation.Offset) , 0.0f , 0.0f , 0.0f , false, false, false, false, 1, cotation.Text, ' ') ); } break; case PicEntity.ECode.PE_COTATIONVERTICAL: { PicCotationVertical cotation = entity as PicCotationVertical; // get offset points Vector2D offsetPt0, offsetPt1; cotation.GetOffsetPoints(out offsetPt0, out offsetPt1); _desWriter.WriteCotationDistance( new DES_CotationDistance( (float)offsetPt0.X, (float)offsetPt0.Y, (float)offsetPt1.X, (float)offsetPt1.Y , LineTypeToDesPen(cotation.LineType) , (byte)cotation.Group , (byte)cotation.Layer , (float)(offsetPt0.X - cotation.Pt0.X + cotation.Offset) , 0.0f , 0.0f , 0.0f , false, false, false, false, 1, cotation.Text, ' ') ); } break; case PicEntity.ECode.PE_COTATIONRADIUSEXT: { } break; case PicEntity.ECode.PE_COTATIONRADIUSINT: { } break; case PicEntity.ECode.PE_BLOCK: { PicBlock block = entity as PicBlock; foreach (PicEntity blockEntity in block) { ProcessEntity(blockEntity); } } break; case PicEntity.ECode.PE_BLOCKREF: { PicBlockRef blockRef = entity as PicBlockRef; _desWriter.WriteBlockRef( new DES_Pose( (float)blockRef.Position.X , (float)blockRef.Position.Y , (float)blockRef.Angle , (byte)blockRef.Block.ExportedGroup) ); } break; case PicEntity.ECode.PE_CARDBOARDFORMAT: { } break; default: throw new Exception("Can not export this kind of entity!"); } }
public void CreateFactoryEntities(PicFactory factory, ParameterStack stack, Transform2D transform) { PicFactory fTemp = new PicFactory(); // free variables double a0 = stack.GetDoubleParameterValue("a0"); double a1 = stack.GetDoubleParameterValue("a1"); bool bbox = stack.GetBoolParameterValue("bbox"); bool arcDefault = stack.GetBoolParameterValue("Arc default"); bool arcReflX = stack.GetBoolParameterValue("Arc Refl X"); bool arcReflY = stack.GetBoolParameterValue("Arc Refl Y"); bool arcReflXY = stack.GetBoolParameterValue("Arc Refl XY"); bool arcComplement = stack.GetBoolParameterValue("Complement"); if (arcDefault) { PicArc arc0 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1); arc0.Transform(Transform2D.Identity); if (bbox) { Box2D box = arc0.Box; fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0 , box.PtMin.X // x0 , box.PtMin.Y // y0 , box.PtMax.X // x1 , box.PtMin.Y // y1 ); fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0 , box.PtMax.X // x0 , box.PtMin.Y // y0 , box.PtMax.X // x1 , box.PtMax.Y // y1 ); fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0 , box.PtMin.X // x0 , box.PtMax.Y // y0 , box.PtMax.X // x1 , box.PtMax.Y // y1 ); fTemp.AddSegment(PicGraphics.LT.LT_CUT, 0, 0 , box.PtMin.X // x0 , box.PtMin.Y // y0 , box.PtMin.X // x1 , box.PtMax.Y // y1 ); } } if (arcReflY) { PicArc arc1 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1); arc1.Transform(Transform2D.ReflectionY); } if (arcReflX) { PicArc arc2 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1); arc2.Transform(Transform2D.ReflectionX); } if (arcReflXY) { PicArc arc3 = fTemp.AddArc(PicGraphics.LT.LT_CUT, new Vector2D(0.0, 0.0), 100.0, a0, a1); arc3.Transform(Transform2D.ReflectionX * Transform2D.ReflectionY); } if (arcComplement) { PicArc arc4 = fTemp.AddArc(PicGraphics.LT.LT_COTATION, new Vector2D(0.0, 0.0), 100.0, a0, a1); arc4.Complement(); } // end factory.AddEntities(fTemp, transform); }
public static bool Export(PicFactory factory, Dictionary <PicGraphics.LT, CutTool> dicTool , double[] dimensions , string materialName, double thickness , string filePath) { List <PicTypedDrawable> lEntities = new List <PicTypedDrawable>(); ProcessEntities(factory, dicTool, ref lEntities); StringBuilder sb = new StringBuilder(); // start file with keyword ";OptiSCOUT" sb.AppendLine(";OptiSCOUT"); // total number of copies sb.AppendLine("SR1,1;"); // number of copies in X sb.AppendLine("SR2,1;"); // number of copies in Y sb.AppendLine("SR3;1;"); // type of regmark (0=Circle) sb.AppendLine("SR4,0;"); // material width in Y [mm] sb.AppendLine(string.Format("SR5,{0};", dimensions[1])); // material length in X [mm] sb.AppendLine(string.Format("SR6,{0};", dimensions[0])); // material thickness [mm] sb.AppendLine(string.Format("SR7,{0};", thickness)); // used material sb.AppendLine(string.Format("TM{0};", materialName)); bool PenDown = false, toolChanged = false; Vector2D currentPt = Vector2D.Zero; PicGraphics.LT lt = PicGraphics.LT.LT_DEFAULT; // tool Up ->lift the tool sb.AppendLine("PU;"); foreach (PicTypedDrawable entity in lEntities) { if (lt != entity.LineType) { // change current line type lt = entity.LineType; // get corresponding CutTool CutTool ct = dicTool[lt]; // SP -> change layer sb.AppendLine("PU;"); sb.AppendLine(string.Format("SP{0};LN{1};LC{2},{3},{4};TN{5}" , ct._number, ct._type, ct._color[0], ct._color[1], ct._color[2], ct._name)); toolChanged = true; } Vector2D pt0 = Vector2D.Zero, pt1 = Vector2D.Zero; if (entity is PicSegment) { PenDown = EntityPoints(entity, currentPt, ref pt0, ref pt1); // if connected, then PenDown if (!PenDown || toolChanged) { sb.AppendLine(string.Format("PU;PA{0:0},{1:0};", 100 * pt0.X, 100 * pt0.Y)); sb.AppendLine("PD;"); toolChanged = false; } sb.AppendLine(string.Format("PA{0:0},{1:0};", 100 * pt1.X, 100 * pt1.Y)); } if (entity is PicArc) { PenDown = EntityPoints(entity, currentPt, ref pt0, ref pt1); if (!PenDown || toolChanged) { sb.AppendLine(string.Format("PU;PA{0:0},{1:0};", 100 * pt0.X, 100 * pt0.Y)); sb.AppendLine("PD;"); toolChanged = false; } PicArc arc = entity as PicArc; Vector2D arcCenter = arc.Center; sb.AppendLine(string.Format("AA{0:0},{1:0},{2}" , 100 * arcCenter.X , 100 * arcCenter.Y , arc.Angle(pt0, pt1).ToString("F2", System.Globalization.CultureInfo.InvariantCulture))); } currentPt = pt1; } // write byte array to stream using (StreamWriter file = new StreamWriter(filePath, false)) file.WriteLine(sb); return(true); }
public override PicEntity Clone(IEntityContainer factory) { PicArc arc = new PicArc(factory.GetNewEntityId(), LineType); arc._center = this._center; arc._radius = this._radius; arc._angleBeg = this._angleBeg; arc._angleEnd = this._angleEnd; return arc; }
public void FillFactory() { // points foreach (netDxf.Entities.Point pt in _dxf.Points) { PicPoint picPoint = _factory.AddPoint( DxfLineType2PicLT(pt.LineType), 0, 0 , new Vector2D(pt.Location.X, pt.Location.Y)); picPoint.Group = DxfLineType2PicGrp(pt.LineType); } // lines foreach (netDxf.Entities.Line line in _dxf.Lines) { PicSegment picSegment = _factory.AddSegment( DxfLineType2PicLT(line.LineType), 0, 0 , new Vector2D(line.StartPoint.X, line.StartPoint.Y) , new Vector2D(line.EndPoint.X, line.EndPoint.Y) ); picSegment.Group = DxfLineType2PicGrp(line.LineType); } // arcs foreach (netDxf.Entities.Arc arc in _dxf.Arcs) { PicArc picArc = _factory.AddArc( DxfLineType2PicLT(arc.LineType), DxfLineType2PicGrp(arc.LineType), 0 , new Vector2D(arc.Center.X, arc.Center.Y) , arc.Radius , 360.0 - arc.EndAngle, 360.0 - arc.StartAngle ); } foreach (netDxf.Entities.Circle circle in _dxf.Circles) { PicArc picArc = _factory.AddArc( DxfLineType2PicLT(circle.LineType), 0, 0 , new Vector2D(circle.Center.X, circle.Center.Y) , circle.Radius , 0.0, 360.0); } // polylines foreach (netDxf.Entities.Polyline polyLine in _dxf.Polylines) { if (polyLine.Vertexes.Count < 2) { continue; } int iVertexCount = 0; Vector2D startPoint = new Vector2D(); foreach (netDxf.Entities.PolylineVertex vertex in polyLine.Vertexes) { Vector2D endPoint = new Vector2D(vertex.Location.X, vertex.Location.Y); if (iVertexCount > 0) { PicSegment picSegment = _factory.AddSegment( DxfLineType2PicLT(polyLine.LineType), 0, 0 , startPoint , endPoint); } startPoint = endPoint; ++iVertexCount; } } }
/// <summary> /// ProcessEntity : write entity corresponding des description /// </summary> /// <param name="entity"></param> public override void ProcessEntity(PicEntity entity) { switch (entity.Code) { case PicEntity.eCode.PE_POINT: break; case PicEntity.eCode.PE_SEGMENT: { PicSegment seg = (PicSegment)entity; _desWriter.WriteSegment( new DES_Segment( (float)seg.Pt0.X , (float)seg.Pt0.Y , (float)seg.Pt1.X , (float)seg.Pt1.Y , LineTypeToDesPen(seg.LineType) , (byte)seg.Group , (byte)seg.Layer ) ); } break; case PicEntity.eCode.PE_ARC: { PicArc arc = (PicArc)entity; _desWriter.WriteArc( new DES_Arc( (float)arc.Center.X , (float)arc.Center.Y , (float)arc.Radius , (float)arc.AngleBeg , (float)arc.AngleEnd , LineTypeToDesPen(arc.LineType) , (byte)arc.Group , (byte)arc.Layer ) ); } break; case PicEntity.eCode.PE_COTATIONDISTANCE: { PicCotationDistance cotation = entity as PicCotationDistance; /* * _desWriter.WriteCotationDistance( * new DES_CotationDistance( * (float)cotation.Pt0.X * , (float)cotation.Pt0.Y * , (float)cotation.Pt1.X * , (float)cotation.Pt1.Y * , (float)cotation.Offset * , (byte)cotation.Group * , (byte)cotation.Layer * ) * ); */ } break; case PicEntity.eCode.PE_COTATIONHORIZONTAL: { } break; case PicEntity.eCode.PE_COTATIONVERTICAL: { } break; case PicEntity.eCode.PE_COTATIONRADIUSEXT: { } break; case PicEntity.eCode.PE_COTATIONRADIUSINT: { } break; case PicEntity.eCode.PE_BLOCK: { PicBlock block = entity as PicBlock; foreach (PicEntity blockEntity in block) { ProcessEntity(blockEntity); } } break; case PicEntity.eCode.PE_BLOCKREF: { PicBlockRef blockRef = entity as PicBlockRef; _desWriter.WriteBlockRef( new DES_Pose( (float)blockRef.Position.X , (float)blockRef.Position.Y , (float)blockRef.Angle , (byte)blockRef.Block.ExportedGroup) ); } break; case PicEntity.eCode.PE_CARDBOARDFORMAT: { } break; default: throw new Exception("Can not export this kind of entity!"); } }
/// <summary> /// ProcessEntity : write entity corresponding dxf description in line buffer /// </summary> /// <param name="entity">Entity</param> public override void ProcessEntity(PicEntity entity) { PicTypedDrawable drawable = (PicTypedDrawable)entity; if (null != drawable) { switch (drawable.Code) { case PicEntity.ECode.PE_POINT: break; case PicEntity.ECode.PE_SEGMENT: { PicSegment seg = (PicSegment)entity; dxf.WriteLine( dw , new DL_LineData( seg.Pt0.X // start point , seg.Pt0.Y , 0.0 , seg.Pt1.X // end point , seg.Pt1.Y , 0.0 , InternalLineTypeToDxfColor(seg.LineType) , "0" ) , new DL_Attributes("0", InternalLineTypeToDxfColor(seg.LineType), -1, InternalLineTypeToDxfLineType(seg.LineType)) ); } break; case PicEntity.ECode.PE_ARC: { PicArc arc = (PicArc)entity; double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg; if (ang < 0.0) { angd += ang; ango = -ang; } else { ango = ang; } dxf.WriteArc(dw, new DL_ArcData( arc.Center.X, arc.Center.Y, 0.0, arc.Radius, angd, angd + ango, InternalLineTypeToDxfColor(arc.LineType), "0" ), new DL_Attributes("0", InternalLineTypeToDxfColor(arc.LineType), -1, InternalLineTypeToDxfLineType(arc.LineType)) ); } break; case PicEntity.ECode.PE_COTATIONDISTANCE: case PicEntity.ECode.PE_COTATIONHORIZONTAL: case PicEntity.ECode.PE_COTATIONVERTICAL: { PicCotationDistance cotation = entity as PicCotationDistance; List <Segment> segments = new List <Segment>(); Vector2D textPt = Vector2D.Zero; double textSize = 0.0; cotation.DrawSeg(ref segments, ref textPt, ref textSize); // draw segments foreach (Segment seg in segments) { dxf.WriteLine(dw, new DL_LineData( seg.P0.X, seg.P0.Y, 0.0, seg.P1.X, seg.P1.Y, 0.0, InternalLineTypeToDxfColor(cotation.LineType), "0" ), new DL_Attributes("0", InternalLineTypeToDxfColor(cotation.LineType), -1, InternalLineTypeToDxfLineType(cotation.LineType)) ); } // draw text dxf.WriteText(dw, new DL_TextData( textPt.X, textPt.Y, 0.0, textPt.X, textPt.Y, 0.0, textSize, 1.0, 0, 1, 2, cotation.Text, "STANDARD", 0.0), new DL_Attributes("0", InternalLineTypeToDxfColor(cotation.LineType), -1, InternalLineTypeToDxfLineType(cotation.LineType))); } break; case PicEntity.ECode.PE_ELLIPSE: break; case PicEntity.ECode.PE_NURBS: break; default: throw new Exception("Can not export this kind of entity!"); } } }