Skip to content

Commit

Permalink
support MTEXT entity and MTEXT attached to ATTRIB and ATTDEF
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo committed Jun 19, 2015
1 parent 86eebb6 commit 0b7a0c7
Show file tree
Hide file tree
Showing 12 changed files with 868 additions and 175 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ using (FileStream fs = new FileStream(@"C:\Path\To\File.dxf", FileMode.Open))
- BLOCKS section - complete R10 through R2014
- ENTITIES section
- common complete R10 through R2014
- still need AcDbXrecord for ATTDEF and ATTRIB
- entities complete R10 through R2014 _EXCEPT_
- HATCH
- MESH
- MLEADER
- MTEXT
- SURFACE
- TABLE
- VIEWPORT
Expand Down
5 changes: 5 additions & 0 deletions src/IxMilia.Dxf/DxfCommon.t4
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ bool DisableWritingDefault(XElement property)
return att != null && bool.Parse(att.Value);
}

bool GenerateReaderFunction(XElement entity)
{
return bool.Parse(AttributeOrDefault(entity, "GenerateReaderFunction", "true"));
}

string Type(XElement property)
{
return property.Attribute("Type").Value;
Expand Down
139 changes: 60 additions & 79 deletions src/IxMilia.Dxf/Entities/DxfAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class DxfAttribute : DxfEntity
public double TextHeight { get; set; }
public string Value { get; set; }
public DxfVersion Version { get; set; }
public string Tag { get; set; }
public string AttributeTag { get; set; }
public int Flags { get; set; }
public short FieldLength { get; set; }
public double Rotation { get; set; }
Expand All @@ -34,6 +34,14 @@ public partial class DxfAttribute : DxfEntity
public DxfPoint SecondAlignmentPoint { get; set; }
public DxfVector Normal { get; set; }
public bool IsLockedInBlock { get; set; }
public bool KeepDuplicateRecords { get; set; }
public DxfMTextFlag MTextFlag { get; set; }
public bool IsReallyLocked { get; set; }
private int SecondaryAttributeCount { get; set; }
public List<uint> SecondaryAttributeHandles { get; set; }
public DxfPoint AlignmentPoint { get; set; }
public double AnnotationScale { get; set; }
public string XRecordTag { get; set; }

// Flags flags

Expand Down Expand Up @@ -118,7 +126,7 @@ protected override void Initialize()
this.TextHeight = 1.0;
this.Value = null;
this.Version = DxfVersion.R2010;
this.Tag = null;
this.AttributeTag = null;
this.Flags = 0;
this.FieldLength = 0;
this.Rotation = 0;
Expand All @@ -131,6 +139,14 @@ protected override void Initialize()
this.SecondAlignmentPoint = DxfPoint.Origin;
this.Normal = DxfVector.ZAxis;
this.IsLockedInBlock = false;
this.KeepDuplicateRecords = false;
this.MTextFlag = DxfMTextFlag.MultilineAttribute;
this.IsReallyLocked = false;
this.SecondaryAttributeCount = 0;
this.SecondaryAttributeHandles = new List<uint>();
this.AlignmentPoint = DxfPoint.Origin;
this.AnnotationScale = 1.0;
this.XRecordTag = null;
}

protected override void AddValuePairs(List<DxfCodePair> pairs, DxfAcadVersion version, bool outputHandles)
Expand Down Expand Up @@ -159,7 +175,7 @@ protected override void AddValuePairs(List<DxfCodePair> pairs, DxfAcadVersion ve
pairs.Add(new DxfCodePair(280, (short)(this.Version)));
}

pairs.Add(new DxfCodePair(2, (this.Tag)));
pairs.Add(new DxfCodePair(2, (this.AttributeTag)));
pairs.Add(new DxfCodePair(70, (short)(this.Flags)));
if (this.FieldLength != 0)
{
Expand Down Expand Up @@ -216,86 +232,51 @@ protected override void AddValuePairs(List<DxfCodePair> pairs, DxfAcadVersion ve
pairs.Add(new DxfCodePair(280, BoolShort(this.IsLockedInBlock)));
}

}
if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(100, "AcDbXrecord"));
}
if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(280, BoolShort(this.KeepDuplicateRecords)));
}

internal override bool TrySetPair(DxfCodePair pair)
{
switch (pair.Code)
if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(70, (short)(this.MTextFlag)));
}

if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(70, BoolShort(this.IsReallyLocked)));
}

if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(70, (short)SecondaryAttributeHandles.Count));
}
if (version >= DxfAcadVersion.R2007)
{
pairs.AddRange(this.SecondaryAttributeHandles.Select(p => new DxfCodePair(340, p)));
}

if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(10, AlignmentPoint.X));
pairs.Add(new DxfCodePair(20, AlignmentPoint.Y));
pairs.Add(new DxfCodePair(30, AlignmentPoint.Z));
}

if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(40, (this.AnnotationScale)));
}

if (version >= DxfAcadVersion.R2007)
{
case 1:
this.Value = (pair.StringValue);
break;
case 2:
this.Tag = (pair.StringValue);
break;
case 7:
this.TextStyleName = (pair.StringValue);
break;
case 10:
this.Location.X = pair.DoubleValue;
break;
case 20:
this.Location.Y = pair.DoubleValue;
break;
case 30:
this.Location.Z = pair.DoubleValue;
break;
case 11:
this.SecondAlignmentPoint.X = pair.DoubleValue;
break;
case 21:
this.SecondAlignmentPoint.Y = pair.DoubleValue;
break;
case 31:
this.SecondAlignmentPoint.Z = pair.DoubleValue;
break;
case 39:
this.Thickness = (pair.DoubleValue);
break;
case 40:
this.TextHeight = (pair.DoubleValue);
break;
case 41:
this.RelativeXScaleFactor = (pair.DoubleValue);
break;
case 50:
this.Rotation = (pair.DoubleValue);
break;
case 51:
this.ObliqueAngle = (pair.DoubleValue);
break;
case 70:
this.Flags = (int)(pair.ShortValue);
break;
case 71:
this.TextGenerationFlags = (int)(pair.ShortValue);
break;
case 72:
this.HorizontalTextJustification = (DxfHorizontalTextJustification)(pair.ShortValue);
break;
case 73:
this.FieldLength = (pair.ShortValue);
break;
case 74:
this.VerticalTextJustification = (DxfVerticalTextJustification)(pair.ShortValue);
break;
case 210:
this.Normal.X = pair.DoubleValue;
break;
case 220:
this.Normal.Y = pair.DoubleValue;
break;
case 230:
this.Normal.Z = pair.DoubleValue;
break;
case 280:
// TODO: code is shared by properties Version, IsLockedInBlock
break;
default:
return base.TrySetPair(pair);
pairs.Add(new DxfCodePair(2, (this.XRecordTag)));
}

return true;
}
}

Expand Down
142 changes: 60 additions & 82 deletions src/IxMilia.Dxf/Entities/DxfAttributeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ public partial class DxfAttributeDefinition : DxfEntity
public DxfVector Normal { get; set; }
public DxfVersion Version { get; set; }
public string Prompt { get; set; }
public string Tag { get; set; }
public string TextTag { get; set; }
public int Flags { get; set; }
public short FieldLength { get; set; }
public DxfVerticalTextJustification VerticalTextJustification { get; set; }
public bool IsLockedInBlock { get; set; }
public bool KeepDuplicateRecords { get; set; }
public DxfMTextFlag MTextFlag { get; set; }
public bool IsReallyLocked { get; set; }
private int SecondaryAttributeCount { get; set; }
public List<uint> SecondaryAttributeHandles { get; set; }
public DxfPoint AlignmentPoint { get; set; }
public double AnnotationScale { get; set; }
public string XRecordTag { get; set; }

// TextGenerationFlags flags

Expand Down Expand Up @@ -128,11 +136,19 @@ protected override void Initialize()
this.Normal = DxfVector.ZAxis;
this.Version = DxfVersion.R2010;
this.Prompt = null;
this.Tag = null;
this.TextTag = null;
this.Flags = 0;
this.FieldLength = 0;
this.VerticalTextJustification = DxfVerticalTextJustification.Baseline;
this.IsLockedInBlock = false;
this.KeepDuplicateRecords = false;
this.MTextFlag = DxfMTextFlag.MultilineAttribute;
this.IsReallyLocked = false;
this.SecondaryAttributeCount = 0;
this.SecondaryAttributeHandles = new List<uint>();
this.AlignmentPoint = DxfPoint.Origin;
this.AnnotationScale = 1.0;
this.XRecordTag = null;
}

protected override void AddValuePairs(List<DxfCodePair> pairs, DxfAcadVersion version, bool outputHandles)
Expand Down Expand Up @@ -206,7 +222,7 @@ protected override void AddValuePairs(List<DxfCodePair> pairs, DxfAcadVersion ve
}

pairs.Add(new DxfCodePair(3, (this.Prompt)));
pairs.Add(new DxfCodePair(2, (this.Tag)));
pairs.Add(new DxfCodePair(2, (this.TextTag)));
pairs.Add(new DxfCodePair(70, (short)(this.Flags)));
if (this.FieldLength != 0)
{
Expand All @@ -223,89 +239,51 @@ protected override void AddValuePairs(List<DxfCodePair> pairs, DxfAcadVersion ve
pairs.Add(new DxfCodePair(280, BoolShort(this.IsLockedInBlock)));
}

}
if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(100, "AcDbXrecord"));
}
if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(280, BoolShort(this.KeepDuplicateRecords)));
}

internal override bool TrySetPair(DxfCodePair pair)
{
switch (pair.Code)
if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(70, (short)(this.MTextFlag)));
}

if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(70, BoolShort(this.IsReallyLocked)));
}

if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(70, (short)SecondaryAttributeHandles.Count));
}
if (version >= DxfAcadVersion.R2007)
{
pairs.AddRange(this.SecondaryAttributeHandles.Select(p => new DxfCodePair(340, p)));
}

if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(10, AlignmentPoint.X));
pairs.Add(new DxfCodePair(20, AlignmentPoint.Y));
pairs.Add(new DxfCodePair(30, AlignmentPoint.Z));
}

if (version >= DxfAcadVersion.R2007)
{
pairs.Add(new DxfCodePair(40, (this.AnnotationScale)));
}

if (version >= DxfAcadVersion.R2007)
{
case 1:
this.Value = (pair.StringValue);
break;
case 2:
this.Tag = (pair.StringValue);
break;
case 3:
this.Prompt = (pair.StringValue);
break;
case 7:
this.TextStyleName = (pair.StringValue);
break;
case 10:
this.Location.X = pair.DoubleValue;
break;
case 20:
this.Location.Y = pair.DoubleValue;
break;
case 30:
this.Location.Z = pair.DoubleValue;
break;
case 11:
this.SecondAlignmentPoint.X = pair.DoubleValue;
break;
case 21:
this.SecondAlignmentPoint.Y = pair.DoubleValue;
break;
case 31:
this.SecondAlignmentPoint.Z = pair.DoubleValue;
break;
case 39:
this.Thickness = (pair.DoubleValue);
break;
case 40:
this.TextHeight = (pair.DoubleValue);
break;
case 41:
this.RelativeXScaleFactor = (pair.DoubleValue);
break;
case 50:
this.Rotation = (pair.DoubleValue);
break;
case 51:
this.ObliqueAngle = (pair.DoubleValue);
break;
case 70:
this.Flags = (int)(pair.ShortValue);
break;
case 71:
this.TextGenerationFlags = (int)(pair.ShortValue);
break;
case 72:
this.HorizontalTextJustification = (DxfHorizontalTextJustification)(pair.ShortValue);
break;
case 73:
this.FieldLength = (pair.ShortValue);
break;
case 74:
this.VerticalTextJustification = (DxfVerticalTextJustification)(pair.ShortValue);
break;
case 210:
this.Normal.X = pair.DoubleValue;
break;
case 220:
this.Normal.Y = pair.DoubleValue;
break;
case 230:
this.Normal.Z = pair.DoubleValue;
break;
case 280:
// TODO: code is shared by properties Version, IsLockedInBlock
break;
default:
return base.TrySetPair(pair);
pairs.Add(new DxfCodePair(2, (this.XRecordTag)));
}

return true;
}
}

Expand Down
Loading

0 comments on commit 0b7a0c7

Please sign in to comment.