Skip to content

Commit

Permalink
Fix BLOCKSTRETCHACTION situation after handles
Browse files Browse the repository at this point in the history
Last fix was wrong. Each handle could have zero, one or more indexes.

Fixes GH#1053
  • Loading branch information
michal-josef-spacek committed Dec 3, 2024
1 parent b8fd725 commit ed5fc34
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 114 deletions.
26 changes: 21 additions & 5 deletions doc/dynapi.texi
Original file line number Diff line number Diff line change
Expand Up @@ -8546,6 +8546,8 @@ BL, DXF 72
BL, DXF 73
@item hdls
Dwg_BLOCKSTRETCHACTION_handles*
@item bl94
BL
@item num_codes
BL, DXF 75
@item codes
Expand Down Expand Up @@ -13804,6 +13806,20 @@ BL, DXF 94
@end vtable
@end indentedblock

@strong{Dwg_BLOCKSTRETCHACTION_handle_indexes} @anchor{Dwg_BLOCKSTRETCHACTION_handle_indexes}
@vindex Dwg_BLOCKSTRETCHACTION_handle_indexes

@indentedblock
@vtable @code

@item parent
struct _dwg_object_BLOCKSTRETCHACTION*
@item index
BL, DXF 94

@end vtable
@end indentedblock

@strong{Dwg_BLOCKSTRETCHACTION_handles} @anchor{Dwg_BLOCKSTRETCHACTION_handles}
@vindex Dwg_BLOCKSTRETCHACTION_handles

Expand All @@ -13814,10 +13830,10 @@ BL, DXF 94
struct _dwg_object_BLOCKSTRETCHACTION*
@item hdl
H, DXF 331
@item bs74
@item num_indexes
BS, DXF 74
@item bl94
BL, DXF 94
@item indexes
Dwg_BLOCKSTRETCHACTION_handle_indexes*

@end vtable
@end indentedblock
Expand Down Expand Up @@ -14559,9 +14575,9 @@ BL, DXF 97
@item fitpts
2RD*
@item start_tangent
2RD
2RD, DXF 12
@item end_tangent
2RD
2RD, DXF 13

@end vtable
@end indentedblock
Expand Down
14 changes: 10 additions & 4 deletions include/dwg.h
Original file line number Diff line number Diff line change
Expand Up @@ -7797,11 +7797,16 @@ typedef struct _dwg_object_BLOCKSCALEACTION
BLOCKACTION_WITHBASEPT_fields(5);
} Dwg_Object_BLOCKSCALEACTION;

typedef struct _dwg_BLOCKSTRETCHACTION_handle_indexes {
struct _dwg_object_BLOCKSTRETCHACTION *parent;
BITCODE_BL index; // 94
} Dwg_BLOCKSTRETCHACTION_handle_indexes;

typedef struct _dwg_BLOCKSTRETCHACTION_handles {
struct _dwg_object_BLOCKSTRETCHACTION *parent;
BITCODE_H hdl; // 331
BITCODE_BS bs74; // 74
BITCODE_BL bl94; // 94
BITCODE_H hdl; // 331
BITCODE_BS num_indexes; // 74
Dwg_BLOCKSTRETCHACTION_handle_indexes *indexes;
} Dwg_BLOCKSTRETCHACTION_handles;

typedef struct _dwg_BLOCKSTRETCHACTION_codes {
Expand All @@ -7819,7 +7824,8 @@ typedef struct _dwg_object_BLOCKSTRETCHACTION
BITCODE_BL num_pts; // 72
BITCODE_2RD *pts; // 10
BITCODE_BL num_hdls; // 72
Dwg_BLOCKSTRETCHACTION_handles *hdls; /*!< DXF 331, 74, 94, 94 */
Dwg_BLOCKSTRETCHACTION_handles *hdls; /*!< DXF 331, 74, 94 */
BITCODE_BL bl94;
BITCODE_BL num_codes; // 75
Dwg_BLOCKSTRETCHACTION_codes *codes; /*!< DXF 95, 76, 94 */
BLOCKACTION_doubles_fields;
Expand Down
9 changes: 7 additions & 2 deletions src/dwg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12427,8 +12427,13 @@ DWG_OBJECT (BLOCKSTRETCHACTION)
REPEAT (num_hdls, hdls, Dwg_BLOCKSTRETCHACTION_handles)
REPEAT_BLOCK
SUB_FIELD_HANDLE (hdls[rcount1], hdl, 0, 331);
SUB_FIELD_BS (hdls[rcount1], bs74, 74);
SUB_FIELD_BL (hdls[rcount1], bl94, 94);
SUB_FIELD_BS (hdls[rcount1], num_indexes, 74);
REPEAT2 (hdls[rcount1].num_indexes, hdls[rcount1].indexes, Dwg_BLOCKSTRETCHACTION_handle_indexes)
REPEAT_BLOCK
SUB_FIELD_BL (hdls[rcount1].indexes[rcount2], index, 94);
SET_PARENT_OBJ (hdls[rcount1].indexes[rcount2]);
END_REPEAT_BLOCK
END_REPEAT (hdls[rcount1].indexes)
SET_PARENT_OBJ (hdls[rcount1]);
END_REPEAT_BLOCK
END_REPEAT (hdls)
Expand Down
191 changes: 101 additions & 90 deletions src/dynapi.c

Large diffs are not rendered by default.

31 changes: 21 additions & 10 deletions src/in_dxf.c
Original file line number Diff line number Diff line change
Expand Up @@ -7867,18 +7867,29 @@ add_AcDbBlockStretchAction (Dwg_Object *restrict obj, Bit_Chain *restrict dat)
dxf_free_pair (pair);

pair = dxf_read_pair (dat);
EXPECT_DXF (obj->name, o->hdls[i].bs74, 74);
o->hdls[i].bs74 = pair->value.i;
LOG_TRACE ("%s.hdls[%d].bs74 = %u [BS 74]\n", obj->name, i,
(unsigned)o->hdls[i].bs74);
EXPECT_DXF (obj->name, o->hdls[i].num_indexes, 74);
o->hdls[i].num_indexes = pair->value.i;
LOG_TRACE ("%s.hdls[%d].num_indexes = %u [BS 74]\n", obj->name, i,
(unsigned)o->hdls[i].num_indexes);
dxf_free_pair (pair);

pair = dxf_read_pair (dat);
EXPECT_DXF (obj->name, o->hdls[i].bl94, 94);
o->hdls[i].bl94 = pair->value.u;
LOG_TRACE ("%s.hdls[%d].bl94 = %u [BL 94]\n", obj->name, i,
(unsigned)o->hdls[i].bl94);
dxf_free_pair (pair);
if (o->hdls[i].num_indexes)
{
o->hdls[i].indexes = (Dwg_BLOCKSTRETCHACTION_handle_indexes *)xcalloc (
o->hdls[i].num_indexes, sizeof (Dwg_BLOCKSTRETCHACTION_handle_indexes));
if (!o->hdls[i].indexes)
return pair;
for (unsigned j = 0; j < o->hdls[i].num_indexes; j++)
{
pair = dxf_read_pair (dat);
EXPECT_DXF (obj->name, o->hdls[i].indexes[j], 94);
o->hdls[i].indexes[j].index = pair->value.u;
LOG_TRACE ("%s.hdls[%d].indexes[%d] = %u [BL 94]\n", obj->name, i, j,
(unsigned)o->hdls[i].indexes[j].index);
dxf_free_pair (pair);
}
}

}
}

Expand Down
9 changes: 6 additions & 3 deletions test/unit-testing/blockstretchaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void
api_process (dwg_object *obj)
{
int error, isnew;
BITCODE_BL i;
BITCODE_BL i, j;
BLOCKACTION_fields;
BITCODE_BL num_pts;
BITCODE_2RD *pts;
Expand Down Expand Up @@ -40,8 +40,11 @@ api_process (dwg_object *obj)
for (i = 0; i < num_hdls; i++)
{
CHK_SUBCLASS_H (_obj->hdls[i], BLOCKSTRETCHACTION_handles, hdl);
CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, bs74, BS);
CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, bl94, BL);
CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, num_indexes, BS);
for (j = 0; j < _obj->hdls[i].num_indexes; j++)
{
CHK_SUBCLASS_TYPE (_obj->hdls[i].indexes[j], BLOCKSTRETCHACTION_handle_indexes, index, BL);
}
}
CHK_ENTITY_TYPE (_obj, BLOCKSTRETCHACTION, num_codes, BL);
for (i = 0; i < num_codes; i++)
Expand Down
23 changes: 23 additions & 0 deletions test/unit-testing/dynapi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -42987,6 +42987,21 @@ static int test_BLOCKSTRETCHACTION (const Dwg_Object *obj)
fail ("BLOCKSTRETCHACTION.be_minor [BL] set+1 %u != %u", blockstretchaction->be_minor, be_minor);
blockstretchaction->be_minor--;
}
{
BITCODE_BL bl94;
if (dwg_dynapi_entity_value (blockstretchaction, "BLOCKSTRETCHACTION", "bl94", &bl94, NULL)
&& bl94 == blockstretchaction->bl94)
pass ();
else
fail ("BLOCKSTRETCHACTION.bl94 [BL] %u != %u", blockstretchaction->bl94, bl94);
bl94++;
if (dwg_dynapi_entity_set_value (blockstretchaction, "BLOCKSTRETCHACTION", "bl94", &bl94, 0)
&& bl94 == blockstretchaction->bl94)
pass ();
else
fail ("BLOCKSTRETCHACTION.bl94 [BL] set+1 %u != %u", blockstretchaction->bl94, bl94);
blockstretchaction->bl94--;
}
{
Dwg_BLOCKSTRETCHACTION_codes* codes;
BITCODE_BL count = 0;
Expand Down Expand Up @@ -67931,6 +67946,14 @@ test_sizes (void)
"dwg_dynapi_fields_size (\"BLOCKSTRETCHACTION_codes\"): %d\n", size1, size2);
error++;
}
size1 = sizeof (struct _dwg_BLOCKSTRETCHACTION_handle_indexes);
size2 = dwg_dynapi_fields_size ("BLOCKSTRETCHACTION_handle_indexes");
if (size1 != size2)
{
fprintf (stderr, "sizeof(struct _dwg_BLOCKSTRETCHACTION_handle_indexes): %d != "
"dwg_dynapi_fields_size (\"BLOCKSTRETCHACTION_handle_indexes\"): %d\n", size1, size2);
error++;
}
size1 = sizeof (struct _dwg_BLOCKSTRETCHACTION_handles);
size2 = dwg_dynapi_fields_size ("BLOCKSTRETCHACTION_handles");
if (size1 != size2)
Expand Down

0 comments on commit ed5fc34

Please sign in to comment.