Skip to content

Commit

Permalink
spec: refactor AcDbMTextObjectEmbedded to SUBCLASS
Browse files Browse the repository at this point in the history
functions can return errors, and we can still continue
outside the subclass.
  • Loading branch information
rurban committed Oct 13, 2024
1 parent cc25852 commit ffed471
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 106 deletions.
6 changes: 2 additions & 4 deletions doc/dynapi.texi
Original file line number Diff line number Diff line change
Expand Up @@ -2077,9 +2077,9 @@ Dwg_AcDbMTextObjectEmbedded
@item is_really_locked
B
@item annotative_data_size
BS, DXF 70
BS
@item annotative_data
TF
RC*
@item annotative_flag
BS
@item annotative_style
Expand Down Expand Up @@ -13214,8 +13214,6 @@ H
@indentedblock
@vtable @code

@item is_really_locked
B
@item attachment
BL
@item ins_pt
Expand Down
7 changes: 3 additions & 4 deletions include/dwg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,6 @@ typedef struct _dwg_entity_TEXT
*/
typedef struct _dwg_AcDbMTextObjectEmbedded
{
BITCODE_B is_really_locked; /*<! DXF 70 */
BITCODE_BL attachment; /*<! DXF 70 */
BITCODE_3BD ins_pt; /*!< DXF 10 */
BITCODE_3BD x_axis_dir; /*!< DXF 11 */
Expand Down Expand Up @@ -1397,7 +1396,7 @@ typedef struct _dwg_entity_ATTRIB
BITCODE_H style;
BITCODE_RC mtext_type; /* R2018+ */
Dwg_AcDbMTextObjectEmbedded mtext;
BITCODE_B is_really_locked; /* R2018+ */
BITCODE_B is_really_locked; /*<! DXF 70 */
BITCODE_BS annotative_data_size;/* R2018+ */
BITCODE_RC* annotative_data; /* R2018+ */
BITCODE_BS annotative_flag; /* R2018+ */
Expand Down Expand Up @@ -1440,7 +1439,7 @@ typedef struct _dwg_entity_ATTDEF
BITCODE_H style;
BITCODE_RC mtext_type; /* R2018+ */
Dwg_AcDbMTextObjectEmbedded mtext;
BITCODE_B is_really_locked; /* R2018+ */
BITCODE_B is_really_locked; /*<! DXF 70 */
BITCODE_BS annotative_data_size;/* R2018+ */
BITCODE_RC* annotative_data; /* R2018+ */
BITCODE_BS annotative_flag; /* R2018+ */
Expand Down Expand Up @@ -4912,7 +4911,7 @@ typedef struct _dwg_entity_GEOPOSITIONMARKER
BITCODE_B mtext_visible; /*!< DXF 290 */
BITCODE_B enable_frame_text; /*!< DXF 290 */
Dwg_AcDbMTextObjectEmbedded mtext;
BITCODE_B is_really_locked; /* R2018+ */
BITCODE_B is_really_locked; /*<! DXF 70 */
BITCODE_BS annotative_data_size;/* R2018+ */
BITCODE_RC* annotative_data; /* R2018+ */
BITCODE_BS annotative_flag; /* R2018+ */
Expand Down
154 changes: 69 additions & 85 deletions src/dwg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -186,51 +186,53 @@ DWG_ENTITY_END

// R2010+ Subclass of ATTRIB, ATTDEF, GEOPOSITIONMARKER.
// Similar to MTEXTOBJECTCONTEXTDATA?
#define AcDbMTextObjectEmbedded_fields \
{ \
FIELD_B (is_really_locked, 0); \
DXF { \
FIELD_BD (alignment_pt.x, 11); \
FIELD_BD (alignment_pt.y, 21); \
VALUE_RD (0.0, 31); \
VALUE_TFF ( "Embedded Object", 101 ); \
FIELD_BD (ins_pt.x, 10); \
FIELD_BD (ins_pt.y, 20); \
VALUE_RD (0.0, 30); \
SUB_FIELD_BD (mtext, rect_width, 40); \
SUB_FIELD_BD (mtext, rect_height, 41); \
SUB_FIELD_BL (mtext, column_type, 71); \
SUB_VALUEOUTOFBOUNDS (mtext, column_type, 2) \
if (SUB_FIELD_VALUE (mtext, column_type)) \
{ \
SUB_FIELD_BL (mtext, num_column_heights, 72); \
SUB_FIELD_BD (mtext, column_width, 44); \
SUB_FIELD_BD (mtext, gutter, 45); \
SUB_FIELD_B (mtext, auto_height, 73); \
SUB_FIELD_B (mtext, flow_reversed, 74); \
if (!SUB_FIELD_VALUE (mtext, auto_height) \
&& SUB_FIELD_VALUE (mtext, column_type) == 2) \
{ \
SUB_FIELD_VECTOR (mtext, column_heights, BD, num_column_heights, 46); \
} \
} \
} \
else { \
FIELD_BS (annotative_data_size, 70); \
if (FIELD_VALUE (annotative_data_size) > 0) \
{ \
/*FIELD_TF (annotative_data, _obj->annotative_data_size, 0);*/ \
SUB_FIELD_BS (mtext, attachment, 70); \
DEBUG_HERE_OBJ \
SUB_FIELD_3BD (mtext, ins_pt, 10); \
SUB_FIELD_3BD (mtext, x_axis_dir, 11); \
SUB_FIELD_BD (mtext, rect_height, 41); \
SUB_FIELD_BD (mtext, rect_width, 40); /* 1.2: @112 */ \
/*SUB_FIELD_BD (mtext, extents_width, 42); \
SUB_FIELD_BD (mtext, extents_height, 43);*/ \
SUB_FIELD_BS (mtext, column_type, 71); /* 8: @180 */ \
/*SUB_VALUEOUTOFBOUNDS (mtext, column_type, 2)*/ \
if (SUB_FIELD_VALUE (mtext, column_type)) \
#define AcDbMTextObjectEmbedded_fields \
FIELD_B (is_really_locked, 0); \
DXF \
{ \
FIELD_BD (alignment_pt.x, 11); \
FIELD_BD (alignment_pt.y, 21); \
VALUE_RD (0.0, 31); \
VALUE_TFF ("Embedded Object", 101); \
FIELD_BD (ins_pt.x, 10); \
FIELD_BD (ins_pt.y, 20); \
VALUE_RD (0.0, 30); \
SUB_FIELD_BD (mtext, rect_width, 40); \
SUB_FIELD_BD (mtext, rect_height, 41); \
SUB_FIELD_BL (mtext, column_type, 71); \
SUB_VALUEOUTOFBOUNDS (mtext, column_type, 2) \
if (SUB_FIELD_VALUE (mtext, column_type)) \
{ \
SUB_FIELD_BL (mtext, num_column_heights, 72); \
SUB_FIELD_BD (mtext, column_width, 44); \
SUB_FIELD_BD (mtext, gutter, 45); \
SUB_FIELD_B (mtext, auto_height, 73); \
SUB_FIELD_B (mtext, flow_reversed, 74); \
if (!SUB_FIELD_VALUE (mtext, auto_height) \
&& SUB_FIELD_VALUE (mtext, column_type) == 2) \
{ \
SUB_FIELD_VECTOR (mtext, column_heights, BD, \
num_column_heights, 46); \
} \
} \
} \
else \
{ \
FIELD_BS (annotative_data_size, 70); \
if (FIELD_VALUE (annotative_data_size) > 0) \
{ \
/*FIELD_TF (annotative_data, _obj->annotative_data_size, 0);*/ \
SUB_FIELD_BS (mtext, attachment, 70); \
DEBUG_HERE_OBJ \
SUB_FIELD_3BD (mtext, ins_pt, 10); \
SUB_FIELD_3BD (mtext, x_axis_dir, 11); \
SUB_FIELD_BD (mtext, rect_height, 41); \
SUB_FIELD_BD (mtext, rect_width, 40); /* 1.2: @112 */ \
/*SUB_FIELD_BD (mtext, extents_width, 42); \
SUB_FIELD_BD (mtext, extents_height, 43);*/ \
SUB_FIELD_BS (mtext, column_type, 71); /* 8: @180 */ \
/*SUB_VALUEOUTOFBOUNDS (mtext, column_type, 2)*/ \
if (SUB_FIELD_VALUE (mtext, column_type)) \
{ \
SUB_FIELD_BS (mtext, num_column_heights, 72); /* 5: @23.5 */\
SUB_FIELD_BD (mtext, column_width, 44); \
Expand All @@ -240,43 +242,17 @@ DWG_ENTITY_END
if (!SUB_FIELD_VALUE (mtext, auto_height) \
&& SUB_FIELD_VALUE (mtext, column_type) == 2) \
{ \
SUB_FIELD_VECTOR (mtext, column_heights, BD, num_column_heights, 46); \
SUB_FIELD_VECTOR (mtext, column_heights, BD, \
num_column_heights, 46); \
} \
} \
} \
FIELD_BS (annotative_flag, 0); \
} \
} \
}

#define AcDbMTextObjectEmbedded1_fields \
{ \
SUB_FIELD_B (mtext, is_really_locked, 0); \
DEBUG_HERE_OBJ \
SUB_FIELD_BL (mtext, attachment, 70); \
SUB_FIELD_3BD (mtext, x_axis_dir, 11); \
DXF { VALUE_TFF ( "Embedded Object", 101 ); } \
SUB_FIELD_3BD (mtext, ins_pt, 10); \
SUB_FIELD_BD (mtext, rect_width, 40); \
SUB_FIELD_BD (mtext, rect_height, 41); \
SUB_FIELD_BD (mtext, extents_width, 42); \
SUB_FIELD_BD (mtext, extents_height, 43); \
SUB_FIELD_BL (mtext, column_type, 71); \
SUB_VALUEOUTOFBOUNDS (mtext, column_type, 2) \
if (SUB_FIELD_VALUE (mtext, column_type)) \
{ \
SUB_FIELD_BL (mtext, num_column_heights, 72); \
SUB_FIELD_BD (mtext, column_width, 44); \
SUB_FIELD_BD (mtext, gutter, 45); \
SUB_FIELD_B (mtext, auto_height, 73); \
SUB_FIELD_B (mtext, flow_reversed, 74); \
if (!SUB_FIELD_VALUE (mtext, auto_height) \
&& SUB_FIELD_VALUE (mtext, column_type) == 2) \
{ \
SUB_FIELD_VECTOR (mtext, column_heights, BD, num_column_heights, 46); \
} \
} \
}

DWG_ENT_SUBCLASS_DECL (ATTRIB, AcDbMTextObjectEmbedded);
DWG_ENT_SUBCLASS_DECL (ATTDEF, AcDbMTextObjectEmbedded);

/* (2/16) */
DWG_ENTITY (ATTRIB)

Expand Down Expand Up @@ -452,7 +428,7 @@ DWG_ENTITY (ATTRIB)
{
FIELD_RC (mtext_type, 70); // 1=single line, 2=multi line attrib, 4=multi line attdef
if (FIELD_VALUE (mtext_type) > 1)
AcDbMTextObjectEmbedded_fields
CALL_SUBCLASS (_obj, ATTRIB, AcDbMTextObjectEmbedded);
}

SINCE (R_13b1) {
Expand Down Expand Up @@ -598,8 +574,8 @@ DWG_ENTITY (ATTDEF)
} else {
if (!(dataflags & 0x02))
FIELD_2DD (alignment_pt, ins_pt, 0);
FIELD_BE (extrusion, 0);
FIELD_BT (thickness, 0);
FIELD_BE (extrusion, 210);
FIELD_BT (thickness, 39);
}
DXF {
FIELD_RD0 (rotation, 50);
Expand Down Expand Up @@ -643,7 +619,7 @@ DWG_ENTITY (ATTDEF)

SUBCLASS (AcDbAttributeDefinition);
DXF {
VALUE_RS (0, 280); // 0 = 2010
VALUE_RS (0, 280); // 0 = 2010+ (class_version)
FIELD_T (prompt, 3);
FIELD_T (tag, 2);
FIELD_RC (mtext_type, 70);
Expand All @@ -664,9 +640,10 @@ DWG_ENTITY (ATTDEF)
}
IF_FREE_OR_SINCE (R_2018)
{
FIELD_RC (mtext_type, 0); // 1=single line, 2=multi line attrib, 4=multi line attdef
// 1=single line, 2=multi line attrib, 4=multi line attdef
FIELD_RC (mtext_type, 0);
if (FIELD_VALUE (mtext_type) > 1)
AcDbMTextObjectEmbedded_fields
CALL_SUBCLASS (_obj, ATTDEF, AcDbMTextObjectEmbedded);
}
SINCE (R_13b1) {
FIELD_T (tag, 0);
Expand All @@ -689,6 +666,9 @@ DWG_ENTITY (ATTDEF)

DWG_ENTITY_END

DWG_ENT_SUBCLASS (ATTRIB, AcDbMTextObjectEmbedded);
DWG_ENT_SUBCLASS (ATTDEF, AcDbMTextObjectEmbedded);

/* (4/12) */
DWG_ENTITY (BLOCK)

Expand Down Expand Up @@ -10205,6 +10185,8 @@ DWG_OBJECT (SUNSTUDY)

DWG_OBJECT_END

DWG_ENT_SUBCLASS_DECL (GEOPOSITIONMARKER, AcDbMTextObjectEmbedded);

// (varies) UNSTABLE
// in DXF as POSITIONMARKER (rename?, no), command: GEOMARKPOSITION, GEOMARKPOINT
// r2014+
Expand All @@ -10221,10 +10203,12 @@ DWG_ENTITY (GEOPOSITIONMARKER)
FIELD_RCd (text_alignment, 280);
FIELD_B (enable_frame_text, 290);
if (FIELD_VALUE (enable_frame_text))
AcDbMTextObjectEmbedded_fields;
CALL_SUBCLASS (_obj, GEOPOSITIONMARKER, AcDbMTextObjectEmbedded);
COMMON_ENTITY_HANDLE_DATA;
DWG_ENTITY_END

DWG_ENT_SUBCLASS (GEOPOSITIONMARKER, AcDbMTextObjectEmbedded)

#define SweepOptions_fields \
FIELD_BD (draft_angle, 42); \
FIELD_BD (draft_start_distance, 43); \
Expand Down Expand Up @@ -10786,7 +10770,7 @@ DWG_OBJECT (MTEXTATTRIBUTEOBJECTCONTEXTDATA)
dwg_setup_SCALE (_obj->context);
} */
DXF { VALUE_TFF ( "Embedded Object", 101 ); }
//CALL_ENTITY (SCALE, _obj->context);
//CALL_SUBCLASS (_obj->context, SCALE, AcDbScale);
SUBCLASS (AcDbScale);
SUB_FIELD_BS (context, flag, 70); // always 0
SUB_FIELD_T (context, name, 300);
Expand Down
6 changes: 2 additions & 4 deletions src/dynapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1883,8 +1883,8 @@ static const Dwg_DYNAPI_field _dwg_GEOPOSITIONMARKER_fields[] = {
{ "is_really_locked", "B", sizeof (BITCODE_B), OFF (struct _dwg_entity_GEOPOSITIONMARKER, is_really_locked),
0,0,0, 0 },
{ "annotative_data_size", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_entity_GEOPOSITIONMARKER, annotative_data_size),
0,0,0, 70 },
{ "annotative_data", "TF", sizeof (BITCODE_RC*), OFF (struct _dwg_entity_GEOPOSITIONMARKER, annotative_data),
0,0,0, 0 },
{ "annotative_data", "RC*", sizeof (BITCODE_RC*), OFF (struct _dwg_entity_GEOPOSITIONMARKER, annotative_data),
1,1,0, 0 },
{ "annotative_flag", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_entity_GEOPOSITIONMARKER, annotative_flag),
0,0,0, 0 },
Expand Down Expand Up @@ -10828,8 +10828,6 @@ static const Dwg_DYNAPI_field _dwg_ASSOCSURFACEACTIONBODY_fields[] = {
};
/* from typedef struct _dwg_AcDbMTextObjectEmbedded: (sorted by offset) */
static const Dwg_DYNAPI_field _dwg_AcDbMTextObjectEmbedded_fields[] = {
{ "is_really_locked", "B", sizeof (BITCODE_B), OFF (struct _dwg_AcDbMTextObjectEmbedded, is_really_locked),
0,0,0, 0 },
{ "attachment", "BL", sizeof (BITCODE_BL), OFF (struct _dwg_AcDbMTextObjectEmbedded, attachment),
0,0,0, 0 },
{ "ins_pt", "3BD", sizeof (BITCODE_3BD), OFF (struct _dwg_AcDbMTextObjectEmbedded, ins_pt),
Expand Down
22 changes: 18 additions & 4 deletions src/spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,11 @@
Dwg_Object_##parenttype *restrict _obj, Bit_Chain * dat, \
Bit_Chain * hdl_dat, Bit_Chain * str_dat, Dwg_Object *restrict obj)

#define DWG_ENT_SUBCLASS_DECL(parenttype, subtype) \
static int DWG_PRIVATE_N (ACTION, parenttype##_##subtype) ( \
Dwg_Entity_##parenttype *restrict _obj, Bit_Chain * dat, \
Bit_Chain * hdl_dat, Bit_Chain * str_dat, Dwg_Object *restrict obj)

#define DWG_SUBCLASS(parenttype, subtype) \
static int DWG_PRIVATE_N (ACTION, parenttype##_##subtype) ( \
Dwg_Object_##parenttype *restrict _obj, Bit_Chain * dat, \
Expand All @@ -873,13 +878,22 @@
return error; \
}

#define DWG_ENT_SUBCLASS(parenttype, subtype) \
static int DWG_PRIVATE_N (ACTION, parenttype##_##subtype) ( \
Dwg_Entity_##parenttype *restrict _obj, Bit_Chain * dat, \
Bit_Chain * hdl_dat, Bit_Chain * str_dat, Dwg_Object *restrict obj) \
{ \
BITCODE_BL vcount, rcount3, rcount4; \
Dwg_Data *dwg = obj->parent; \
int error = 0; \
subtype##_fields; \
return error; \
}


#define CALL_SUBCLASS(_xobj, parenttype, subtype) \
error |= DWG_PRIVATE_N (ACTION, parenttype##_##subtype) ( \
_xobj, dat, hdl_dat, str_dat, (Dwg_Object *)obj)
// if the name is compile-time known
#define CALL_ENTITY(name, xobj) \
error |= DWG_PRIVATE_N (ACTION, name) (dat, hdl_dat, str_dat, \
(Dwg_Object *)xobj)
// TODO: dispatch on the type
#define CALL_SUBENT(hdl, dxf)
// error |= DWG_PRIVATE_N (ACTION, xobj->fixedtype) (dat, hdl_dat, str_dat,
Expand Down
2 changes: 1 addition & 1 deletion test/unit-testing/attdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ api_process (dwg_object *obj)
{
CHK_SUBCLASS_TYPE (mtext, AcDbMTextObjectEmbedded, attachment, BS);
CHK_SUBCLASS_3RD (mtext, AcDbMTextObjectEmbedded, ins_pt);
CHK_SUBCLASS_3RD (mtext, AcDbMTextObjectEmbedded, x_axis_dir);
// CHK_SUBCLASS_3RD (mtext, AcDbMTextObjectEmbedded, x_axis_dir);
CHK_SUBCLASS_TYPE (mtext, AcDbMTextObjectEmbedded, rect_height, BD);
CHK_SUBCLASS_TYPE (mtext, AcDbMTextObjectEmbedded, rect_width, BD);
CHK_SUBCLASS_TYPE (mtext, AcDbMTextObjectEmbedded, column_type, BS);
Expand Down
10 changes: 6 additions & 4 deletions test/unit-testing/dynapi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12019,12 +12019,14 @@ static int test_GEOPOSITIONMARKER (const Dwg_Object *obj)
return 1;
}
{
BITCODE_TF annotative_data;
BITCODE_RC* annotative_data;
if (dwg_dynapi_entity_value (geopositionmarker, "GEOPOSITIONMARKER", "annotative_data", &annotative_data, NULL)
&& !memcmp (&annotative_data, &geopositionmarker->annotative_data, sizeof (BITCODE_TF)))
pass ();
&& annotative_data
? strEQ ((char *)annotative_data, (char *)geopositionmarker->annotative_data)
: !geopositionmarker->annotative_data)
pass ();
else
fail ("GEOPOSITIONMARKER.annotative_data [TF]");
fail ("GEOPOSITIONMARKER.annotative_data [RC*] '%s' <> '%s'", annotative_data, geopositionmarker->annotative_data);
}
{
BITCODE_BS annotative_data_size;
Expand Down

0 comments on commit ffed471

Please sign in to comment.