Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimension: Dimension type and dimension flags #236

Closed
mme1950 opened this issue Dec 28, 2023 · 12 comments · Fixed by #242 or #247
Closed

Dimension: Dimension type and dimension flags #236

mme1950 opened this issue Dec 28, 2023 · 12 comments · Fixed by #242 or #247
Labels
bug Something isn't working

Comments

@mme1950
Copy link
Contributor

mme1950 commented Dec 28, 2023

Dimension type and dimension flags are not read.

In DXF the field with the group code 70 contains an enum value 1...6 representing the dimension type and three flags.

In DWG no field containing the value known from DXF is found.
This field is therefore read in the sequence but not used.

For this field the documentation is available:

Non-bit-pair-coded. NOT the 70 group, but helps define it. Apparently only the two lowest bit are used:
76543210:
Bit 0 : The OPPOSITE of bit 7 (128) of 70.
Bit 1 : Same as bit 5 (32) of the 70 (but 32 is not doc'd by ACAD).
The actual 70-group value comes from 3 things:
6 for being an ordinate DIMENSION, plus whatever bits "Flags 1" and "Flags 2" specify.

In the field read in the sequence only the values 10 or 11 occur (in available examples).
The Dimension Type is not important and can be set in the constructor.
The bits 0, 1 can be extracted as specified. But the meaning is not quite clear. Also the meaning of the other bits is not clear.
The Ordinate bit specifying whether an Ordinate Dimension measures in X or Y direction seems to be missing.

@mme1950 mme1950 added the bug Something isn't working label Dec 28, 2023
@DomCR
Copy link
Owner

DomCR commented Jan 4, 2024

Hi @mme1950

This is the documentation that I've followed:

Dimension type:
Values 0-6 are integer values that represent the dimension type. Values 32, 64, and 128 are bit values, which are added to the integer values (value 32 is always set in R13 and later releases)
0 = Rotated, horizontal, or vertical
1 = Aligned
2 = Angular
3 = Diameter
4 = Radius
5 = Angular 3-point
6 = Ordinate
32 = Indicates that the block reference (group code 2) is referenced by this dimension only
64 = Ordinate type. This is a bit value (bit 7) used only with integer value 6. If set, ordinate is X-type; if not set, ordinate is Y-type
128 = This is a bit value (bit 8) added to the other group 70 values if the dimension text has been positioned at a user-defined location rather than at the default location

I the Dxf reader I can see that I'm ignoring bits 7 and 8, all the others seem to have a fixed value depending on the dimension and bit 32 is always set for all compatible versions.

I'll open a branch to implement the reader for this values.

Thanks for the help!

@mme1950
Copy link
Contributor Author

mme1950 commented Jan 4, 2024

Hi @DomCR,

I believe it is possible to read the field with group code 70 fron DXF. The values I saw in DXF/ascii seem to be OK.
I tried to read the corresponding field as byte from all available DWG dimension examples. I received either the value 10 or 11.
None of the bits can be related to the 64 = Ordinate type.
I am afraid we cannot solve this problem without more information.

BTW: I would suggest to separate the value into two properties:
enum DimensionType (values 0-6)
flags enum DiemenaionFlags (bits: 32, 64, 128)

@DomCR DomCR linked a pull request Jan 6, 2024 that will close this issue
@DomCR DomCR closed this as completed in #242 Jan 6, 2024
@mme1950
Copy link
Contributor Author

mme1950 commented Jan 6, 2024

Hi @DomCR,

I just tried to test the changes reading sample_AC1032.dwg.
This file contains two ordinate.dimension objects, one in X direction and one in Y direction.
IsOrdinateTypeX is false in both cases.

@DomCR
Copy link
Owner

DomCR commented Jan 6, 2024

I was comparing the results with the DXF, maybe I've missed something, I'll reopen the issue and take a second look.

@DomCR DomCR reopened this Jan 6, 2024
@mme1950
Copy link
Contributor Author

mme1950 commented Jan 6, 2024

I spent some time with investigation of this problem (see above).
I seems that the byte read from DWG does not contain the dimension-type (0-6).
The value is either 10 or 11: 0b1000 and 0b0010 are always set, 0b0001 is somtimes set.
In all ordinate-dimension objects the value is 10.
Maybe the ordinate bit occurs as separate bit. This is hard to find.

@DomCR
Copy link
Owner

DomCR commented Jan 6, 2024

For my part I can confirm that the dimension type is not saved in the dwg, the type is specified at the ObjectType so dwg does not need any further specification, the documentation that I've followed and the implementation for this specific issue is this one:

//Bit 0 : The OPPOSITE of bit 7(128) of 70.
//Bit 1 : Same as bit 5(32) of the 70(but 32 is not doc'd by ACAD).
//The actual 70 - group value comes from 3 things:
//6 for being an ordinate DIMENSION, plus whatever bits "Flags 1" and "Flags 2" specify.

byte flags = (this._objectReader.ReadByte());
dimension.IsTextUserDefinedLocation = (flags & 0b01) == 0;
dimension.IsOrdinateTypeX = (flags & 0b10) == 0;

For me it makes sense and comparing the flags with the dxf seemed to work but I'll take a second look.

@mme1950
Copy link
Contributor Author

mme1950 commented Jan 6, 2024

The documentation (pdf) identifies bit 0 and 1 (dwg) with bit 5 and 7, but says nothing about where bit 6 can be found.

@mme1950
Copy link
Contributor Author

mme1950 commented Jan 9, 2024

Hi @DomCR,

I think I found the solution. I should have read the documentation. I did not expect that part of the value corresponding to the DXF group code 70 appears in the ordinate-dimension data. So I missed it. The three XYZ fields are followed by a non two-bit-coded byte. The lowest bit should be the ordinate flag.

see PDF: 20.4.23 DIMENSION (ORDINATE) (20)

This seems to work:

		private CadTemplate readDimOrdinate()
		{
			DimensionOrdinate dimension = new DimensionOrdinate();
			CadDimensionTemplate template = new CadDimensionTemplate(dimension);

			this.readCommonDimensionData(template);

			//Common:
			//10 - pt 3BD 10 See DXF documentation.
			dimension.DefinitionPoint = this._objectReader.Read3BitDouble();
			//13 - pt 3BD 13 See DXF documentation.
			dimension.FeatureLocation = this._objectReader.Read3BitDouble();
			//14 - pt 3BD 14 See DXF documentation.
			dimension.LeaderEndpoint = this._objectReader.Read3BitDouble();

			byte flags = (this._objectReader.ReadByte());
			dimension.IsOrdinateTypeX = (flags & 0b01) != 0;

			this.readCommonDimensionHandles(template);

			return template;
		}

@mme1950
Copy link
Contributor Author

mme1950 commented Jan 9, 2024

And we need this line and the new boolean property IsBlockReference:
dimension.IsBlockReference = (flags & 0b10) != 0;

The IsOrdinateTypeX property should be moved to DimensionOrdinate.

The flags should be removed from the DimensionType enum.

@DomCR
Copy link
Owner

DomCR commented Jan 11, 2024

Good work with the IsOrdinateTypeX!!!

The flag IsBlockReference It should be always set, in the documentation is specified that this value is always set for the versions R13 and later so to avoid issues when reading or writing the files I would ignore this bit due ACadSharp is not compatible with R12 and earlier.

Quote from documentation:

(value 32 is always set in R13 and later releases)

@DomCR DomCR linked a pull request Jan 11, 2024 that will close this issue
@DomCR
Copy link
Owner

DomCR commented Jan 11, 2024

If you have a moment could you check the PR for this issue?

It seems that you have a more accurate test case than I do, it will help a lot.

Thanks

@mme1950
Copy link
Contributor Author

mme1950 commented Jan 11, 2024

Hi @DomCR,

  • I checked the code: You implemented the readDimOrdinate() method exactly as shown above.
  • With this code I read the sample DWG file: sample_AC1032.dwg. This file contains one ordinate dimension in x-direction and one in y-direction. The IsOrdinateTypeX is returned correctly.

Here are the screen shots from AutoCAD and SVG conversion after reading with ACadSharp:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants