Skip to content

Commit

Permalink
encode: more disable_3DSOLID_materials
Browse files Browse the repository at this point in the history
disable materials in 3DSOLIDs and all its subtypes.
GH #954
  • Loading branch information
rurban committed Jul 27, 2024
1 parent 6e7839f commit 5cfc387
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/dwg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2984,7 +2984,7 @@ static int free_3dsolid (Dwg_Object *restrict obj, Dwg_Entity_3DSOLID *restrict
FIELD_B (acis_empty_bit, 0); /* ?? */ \
if (FIELD_VALUE (version) > 1) \
{ \
SINCE (R_2007a) \
SINCE (R_2007a) \
{ \
FIELD_BL (num_materials, 0); \
REPEAT (num_materials, materials, Dwg_3DSOLID_material) \
Expand Down
48 changes: 39 additions & 9 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3300,9 +3300,10 @@ dwg_encode (Dwg_Data *restrict dwg, Bit_Chain *restrict dat)
|| obj->fixedtype == DWG_TYPE_UNKNOWN_ENT
# ifndef DEBUG_CLASSES
|| (dwg->opts & DWG_OPTS_IN
&& (/*obj->fixedtype == DWG_TYPE_WIPEOUT (GH #244) || */
obj->fixedtype == DWG_TYPE_TABLEGEOMETRY ||
obj->fixedtype == DWG_TYPE_MATERIAL))
&& (/*obj->fixedtype == DWG_TYPE_WIPEOUT (GH #244) ||
*/
obj->fixedtype == DWG_TYPE_TABLEGEOMETRY
|| obj->fixedtype == DWG_TYPE_MATERIAL))
# endif
)
{
Expand Down Expand Up @@ -4883,6 +4884,22 @@ encode_preR13_section (const Dwg_Section_Type_r11 id, Bit_Chain *restrict dat,
return error;
}

static void
disable_3DSOLID_materials (Dwg_Object *obj)
{
BITCODE_BL num_materials = 0;
// or some child of it
Dwg_Entity_BODY *_obj = obj->tio.entity->tio.BODY;
if (dwg_dynapi_entity_value (_obj, obj->name, "num_materials",
&num_materials, NULL)
&& num_materials)
{
num_materials = 0;
dwg_dynapi_entity_set_value (_obj, obj->name, "num_materials",
&num_materials, NULL);
}
}

/*
static int
encode_preR13_POLYLINE (Bit_Chain *restrict dat, Dwg_Object *restrict obj)
Expand Down Expand Up @@ -5538,12 +5555,21 @@ dwg_encode_add_object (Dwg_Object *restrict obj, Bit_Chain *restrict dat,
error = dwg_encode_SPLINE (dat, obj);
break;
case DWG_TYPE_REGION:
#ifndef DEBUG_CLASSES
disable_3DSOLID_materials (obj);
#endif
error = dwg_encode_REGION (dat, obj);
break;
case DWG_TYPE__3DSOLID:
#ifndef DEBUG_CLASSES
disable_3DSOLID_materials (obj);
#endif
error = dwg_encode__3DSOLID (dat, obj);
break;
case DWG_TYPE_BODY:
#ifndef DEBUG_CLASSES
disable_3DSOLID_materials (obj);
#endif
error = dwg_encode_BODY (dat, obj);
break;
case DWG_TYPE_RAY:
Expand Down Expand Up @@ -5696,6 +5722,10 @@ dwg_encode_add_object (Dwg_Object *restrict obj, Bit_Chain *restrict dat,
break;
*/
default:
#ifndef DEBUG_CLASSES
if (dwg && dwg_dynapi_entity_field (obj->name, "num_materials"))
disable_3DSOLID_materials (obj);
#endif
if (dwg && obj->type == dwg->layout_type
&& obj->fixedtype == DWG_TYPE_LAYOUT)
{
Expand Down Expand Up @@ -6412,12 +6442,12 @@ encode_preR13_header_variables (Bit_Chain *dat, Dwg_Data *restrict dwg)
Bit_Chain *hdl_dat = dat;
int error = 0;

// PRE (R_13b1)
// {
// if (dat->from_version >= R_13b1)
// downgrade_preR13_header_variables (dat, dwg);
// }
// clang-format off
// PRE (R_13b1)
// {
// if (dat->from_version >= R_13b1)
// downgrade_preR13_header_variables (dat, dwg);
// }
// clang-format off
#include "header_variables_r11.spec"
// clang-format on

Expand Down

0 comments on commit 5cfc387

Please sign in to comment.