Skip to content

Commit

Permalink
Merge branch 'master' into 20231111_mme_2-support-dynamic-blocks-read…
Browse files Browse the repository at this point in the history
…-evaluation-graphs-and-block-visibility-parameters
  • Loading branch information
mme1950 committed Nov 20, 2023
2 parents aad6b54 + 69f4555 commit b78a897
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 94 deletions.
10 changes: 10 additions & 0 deletions ACadSharp.Tests/IO/DWG/DwgWriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public void DefaultLayer()
this.Document.Layers.Add(new ACadSharp.Tables.Layer("default_layer"));
}

public void SingleMText()
{
MText mtext = new MText();

mtext.Value = "HELLO I'm an MTEXT";

this.Document.Entities.Add(mtext);
}

public void Deserialize(IXunitSerializationInfo info)
{
this.Name = info.GetValue<string>(nameof(this.Name));
Expand Down Expand Up @@ -68,6 +77,7 @@ static DwgWriterSingleObjectTests()
Data.Add(new(nameof(SingleCaseGenerator.Empty)));
Data.Add(new(nameof(SingleCaseGenerator.SinglePoint)));
Data.Add(new(nameof(SingleCaseGenerator.DefaultLayer)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMText)));
}

[Theory()]
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp/Entities/MText.TextColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TextColumn
/// Text column type
/// </summary>
[DxfCodeValue(75)]
public ColumnType ColumnType { get; set; }
public ColumnType ColumnType { get; set; } = ColumnType.NoColumns;

/// <summary>
/// Number of columns
Expand Down
25 changes: 8 additions & 17 deletions ACadSharp/Entities/MText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public double Height
public double RectangleWidth { get; set; }

/// <summary>
///
/// Reference rectangle height
/// </summary>
[DxfCodeValue(46)]
public double ReferenceRectangleHeight { get; set; }
public double RectangleHeight { get; set; }

/// <summary>
/// Attachment point
/// </summary>
[DxfCodeValue(71)]
public AttachmentPointType AttachmentPoint { get; set; }
public AttachmentPointType AttachmentPoint { get; set; } = AttachmentPointType.TopLeft;

/// <summary>
/// Drawing direction
Expand All @@ -81,20 +81,11 @@ public double Height
public DrawingDirectionType DrawingDirection { get; set; }

/// <summary>
/// Specifies the text string for the entity.
/// Specifies the text string for the entity
/// </summary>
/// <value>
/// The maximum length is 256 characters.
/// </value>
[DxfCodeValue(1)]
public string Value { get; set; } = string.Empty;

/// <summary>
/// Additional text (always in 250-character chunks)
/// </summary>
[DxfCodeValue(DxfReferenceType.Optional, 3)]
public string AdditionalText { get; set; } = string.Empty;

/// <summary>
/// Style of this text entity.
/// </summary>
Expand Down Expand Up @@ -187,7 +178,7 @@ public double Rotation
/// Percentage of default (3-on-5) line spacing to be applied.Valid values range from 0.25 to 4.00
/// </remarks>
[DxfCodeValue(44)]
public double LineSpacing { get; set; }
public double LineSpacing { get; set; } = 1.0;

/// <summary>
/// Background fill setting
Expand Down Expand Up @@ -221,11 +212,11 @@ public double Rotation

public TextColumn Column { get; set; } = new TextColumn();

public bool IsAnnotative { get; set; }
public bool IsAnnotative { get; set; } = false;

private double _height = 0.0;
private double _height = 1.0;

private XYZ _alignmentPoint = XYZ.Zero;
private XYZ _alignmentPoint = XYZ.AxisX;

private double _rotation = 0.0;

Expand Down
45 changes: 26 additions & 19 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,7 @@ private CadTemplate readMText()
if (this.R2007Plus)
{
//Rect height BD 46 Reference rectangle height.
mtext.ReferenceRectangleHeight = this._objectReader.ReadBitDouble();
mtext.RectangleHeight = this._objectReader.ReadBitDouble();
}

//Common:
Expand Down Expand Up @@ -3175,24 +3175,31 @@ private MultiLeaderAnnotContext readMultiLeaderAnnotContext(CadMLeaderTemplate t
// - OCS to WCS (using normal vector),
// - Scaling (using scale vector)
// - Translation (using location)
// Simply read an array of 16 doubles:
double[] matrix = annotContext.TransformationMatrix;
matrix[0] = _objectReader.ReadBitDouble();
matrix[1] = _objectReader.ReadBitDouble();
matrix[2] = _objectReader.ReadBitDouble();
matrix[3] = _objectReader.ReadBitDouble();
matrix[4] = _objectReader.ReadBitDouble();
matrix[5] = _objectReader.ReadBitDouble();
matrix[6] = _objectReader.ReadBitDouble();
matrix[7] = _objectReader.ReadBitDouble();
matrix[8] = _objectReader.ReadBitDouble();
matrix[9] = _objectReader.ReadBitDouble();
matrix[10] = _objectReader.ReadBitDouble();
matrix[11] = _objectReader.ReadBitDouble();
matrix[12] = _objectReader.ReadBitDouble();
matrix[13] = _objectReader.ReadBitDouble();
matrix[14] = _objectReader.ReadBitDouble();
matrix[15] = _objectReader.ReadBitDouble();
double m00 = _objectReader.ReadBitDouble();
double m10 = _objectReader.ReadBitDouble();
double m20 = _objectReader.ReadBitDouble();
double m30 = _objectReader.ReadBitDouble();

double m01 = _objectReader.ReadBitDouble();
double m11 = _objectReader.ReadBitDouble();
double m21 = _objectReader.ReadBitDouble();
double m31 = _objectReader.ReadBitDouble();

double m02 = _objectReader.ReadBitDouble();
double m12 = _objectReader.ReadBitDouble();
double m22 = _objectReader.ReadBitDouble();
double m32 = _objectReader.ReadBitDouble();

double m03 = _objectReader.ReadBitDouble();
double m13 = _objectReader.ReadBitDouble();
double m23 = _objectReader.ReadBitDouble();
double m33 = _objectReader.ReadBitDouble();

annotContext.TransformationMatrix = new Matrix4(
m00, m10, m20, m30,
m01, m11, m21, m31,
m02, m12, m22, m32,
m03, m13, m23, m33);
}
//END IF Has contents block
//END IF Has text contents
Expand Down
46 changes: 21 additions & 25 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ private void writeEntity(Entity entity)
switch (entity)
{
case AttributeEntity:
case MText:
case Shape:
case Solid3D:
case MultiLeader:
Expand Down Expand Up @@ -95,6 +94,9 @@ private void writeEntity(Entity entity)
case MLine mLine:
this.writeMLine(mLine);
break;
case MText mtext:
this.writeMText(mtext);
break;
case Point p:
this.writePoint(p);
break;
Expand Down Expand Up @@ -1322,7 +1324,7 @@ private void writeShape(Shape shape)
//When reading from DXF, the shape is found by iterating over all the text styles
//(SHAPEFILE, see paragraph 20.4.56) and when the text style contains a shape file,
//iterating over all the shapes until the one with the matching name is found.
this._writer.WriteBitShort(0); //TODO: missing implementation for shapeIndex
this._writer.WriteBitShort(0); //TODO: missing implementation for shapeIndex

//Extrusion 3BD 210
this._writer.Write3BitDouble(shape.Normal);
Expand Down Expand Up @@ -1615,7 +1617,7 @@ private void writeMText(MText mtext)
//R2007+:
if (this.R2007Plus)
{
this._writer.WriteBitDouble(mtext.ReferenceRectangleHeight);
this._writer.WriteBitDouble(mtext.RectangleHeight);
}

//Common:
Expand All @@ -1626,7 +1628,6 @@ private void writeMText(MText mtext)
//Drawing dir BS 72 Left to right, etc.; see DXF doc
this._writer.WriteBitShort((short)mtext.DrawingDirection);

//TODO: Check undocumented values for MText
//Extents ht BD ---Undocumented and not present in DXF or entget
this._writer.WriteBitDouble(0);
//Extents wid BD ---Undocumented and not present in DXF or entget
Expand Down Expand Up @@ -1683,9 +1684,6 @@ private void writeMText(MText mtext)
return;
}

throw new System.NotImplementedException("Annotative MText not implemented for the writer");
//TODO: missing values depending on the reader to get them and process to be able to write
#if false
//Version BS Default 0
this._writer.WriteBitShort(0);
//Default flag B Default true
Expand All @@ -1695,51 +1693,49 @@ private void writeMText(MText mtext)
//Registered application H Hard pointer
this._writer.HandleReference(DwgReferenceType.HardPointer, null);

//TODO: finish Mtext Writer, save redundant fields??

//Attachment point BL
AttachmentPointType attachmentPoint = (AttachmentPointType)this._writer.WriteBitLong();
this._writer.WriteBitLong((int)mtext.AttachmentPoint);
//X - axis dir 3BD 10
this._writer.Write3BitDouble();
this._writer.Write3BitDouble(mtext.AlignmentPoint);
//Insertion point 3BD 11
this._writer.Write3BitDouble();
this._writer.Write3BitDouble(mtext.InsertPoint);
//Rect width BD 40
this._writer.WriteBitDouble();
this._writer.WriteBitDouble(mtext.Height);
//Rect height BD 41
this._writer.WriteBitDouble();
this._writer.WriteBitDouble(mtext.RectangleWidth);
//Extents width BD 42
this._writer.WriteBitDouble();
this._writer.WriteBitDouble(mtext.HorizontalWidth);
//Extents height BD 43
this._writer.WriteBitDouble();
this._writer.WriteBitDouble(mtext.VerticalWidth);
//END REDUNDANT FIELDS

//Column type BS 71 0 = No columns, 1 = static columns, 2 = dynamic columns
this._writer.WriteBitShort((short)mtext.Column.ColumnType);

//IF Has Columns data(column type is not 0)
if (mtext.Column.ColumnType != ColumnType.NoColumns)
{
//Column height count BL 72
int count = this._writer.WriteBitLong();
this._writer.WriteBitLong(mtext.Column.ColumnCount);
//Columnn width BD 44
mtext.Column.ColumnWidth = this._writer.WriteBitDouble();
this._writer.WriteBitDouble(mtext.Column.ColumnWidth);
//Gutter BD 45
mtext.Column.ColumnGutter = this._writer.WriteBitDouble();
this._writer.WriteBitDouble(mtext.Column.ColumnGutter);
//Auto height? B 73
mtext.Column.ColumnAutoHeight = this._writer.WriteBit();
this._writer.WriteBit(mtext.Column.ColumnAutoHeight);
//Flow reversed? B 74
mtext.Column.ColumnFlowReversed = this._writer.WriteBit();
this._writer.WriteBit(mtext.Column.ColumnFlowReversed);

//IF not auto height and column type is dynamic columns
if (!mtext.Column.ColumnAutoHeight && mtext.Column.ColumnType == ColumnType.DynamicColumns && count > 0)
if (!mtext.Column.ColumnAutoHeight && mtext.Column.ColumnType == ColumnType.DynamicColumns)
{
for (int i = 0; i < count; ++i)
foreach (double h in mtext.Column.ColumnHeights)
{
//Column height BD 46
mtext.Column.ColumnHeights.Add(this._writer.WriteBitDouble());
this._writer.WriteBitDouble(h);
}
}
}
#endif
}

private void writeFaceRecord(VertexFaceRecord face)
Expand Down
11 changes: 7 additions & 4 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,20 @@ private void writeLayer(Layer layer)
short values = (short)(CadUtils.ToIndex(layer.LineWeight) << 5);

//contains frozen (1 bit),
values |= (short)LayerFlags.Frozen;
if (layer.Flags.HasFlag(LayerFlags.Frozen))
values |= 0b1;

//on (2 bit)
if (layer.IsOn)
if (!layer.IsOn)
values |= 0b10;

//frozen by default in new viewports (4 bit)
values |= (short)LayerFlags.FrozenNewViewports;
if (layer.Flags.HasFlag(LayerFlags.Frozen))
values |= 0b100;

//locked (8 bit)
values |= (short)LayerFlags.Locked;
if (layer.Flags.HasFlag(LayerFlags.Locked))
values |= 0b1000;

//plotting flag (16 bit),
if (layer.PlotFlag)
Expand Down
4 changes: 2 additions & 2 deletions ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subcl
switch (this._reader.Code)
{
//TODO: Implement multiline text def codes
case 3 when tmp.CadObject is MText mtext:
mtext.AdditionalText.Concat(this._reader.ValueAsString);
case 1 or 3 when tmp.CadObject is MText mtext:
mtext.Value += this._reader.ValueAsString;
return true;
case 70:
case 74:
Expand Down
36 changes: 14 additions & 22 deletions ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ protected void writeEntity<T>(T entity)
{
case Mesh:
case MLine:
case MText:
case Solid3D:
case MultiLeader:
case Wipeout:
this.notify($"Entity type not implemented : {entity.GetType().FullName}", NotificationType.NotImplemented);
return;
}
Expand Down Expand Up @@ -606,45 +606,37 @@ private void writeMText(MText mtext)

this._writer.Write(40, mtext.Height, map);
this._writer.Write(41, mtext.RectangleWidth, map);
this._writer.Write(44, mtext.LineSpacing, map);

if (this.Version >= ACadVersion.AC1021)
{
this._writer.Write(46, mtext.ReferenceRectangleHeight, map);
this._writer.Write(46, mtext.RectangleHeight, map);
}

this._writer.Write(71, (short)mtext.AttachmentPoint, map);
this._writer.Write(72, (short)mtext.DrawingDirection, map);

this._writer.Write(1, mtext.Value, map);

if (string.IsNullOrEmpty(mtext.AdditionalText))
{
for (int i = 0; i < mtext.AdditionalText.Length; i += 250)
this._writer.Write(3, mtext.AdditionalText.Substring(i, 250), map);
}
this.writeMTextValue(mtext.Value);

this._writer.WriteName(7, mtext.Style);

this._writer.Write(73, (short)mtext.LineSpacingStyle, map);

this._writer.Write(11, mtext.AlignmentPoint, map);

if (this.Version >= ACadVersion.AC1018)
this._writer.Write(210, mtext.Normal, map);
}

private void writeMTextValue(string text)
{
string encoded = text?.Replace("\n", "^J");

for (int i = 0; i < encoded.Length - 250; i += 250)
{
this._writer.Write(90, (int)mtext.BackgroundFillFlags, map);
if (mtext.BackgroundFillFlags.HasFlag(BackgroundFillFlags.UseBackgroundFillColor))
{
//this._writer.Write(63, mtext.BackgroundColor, map);
this._writer.Write(45, mtext.BackgroundScale, map);
//Transparency of background fill color (not implemented)
//this._writer.Write(441, mtext.BackgroundTransparency, map);
}
this._writer.Write(3, encoded.Substring(i, 250));
}

this._writer.Write(44, mtext.LineSpacing, map);
this._writer.Write(45, mtext.BackgroundScale, map);

this._writer.Write(210, mtext.Normal, map);
this._writer.Write(1, encoded);
}

private void writePoint(Point line)
Expand Down
Loading

0 comments on commit b78a897

Please sign in to comment.