(root)/
libredwg-0.13/
test/
unit-testing/
hatch.c
       1  #define DWG_TYPE DWG_TYPE_HATCH
       2  #include "common.c"
       3  
       4  void
       5  api_process (dwg_object *obj)
       6  {
       7    int error, isnew;
       8    BITCODE_BL i;
       9    BITCODE_BL is_gradient_fill;
      10    BITCODE_BL reserved;
      11    BITCODE_BD gradient_angle;
      12    BITCODE_BD gradient_shift;
      13    BITCODE_BL single_color_gradient;
      14    BITCODE_BD gradient_tint;
      15    BITCODE_BL num_colors;
      16    BITCODE_T gradient_name;
      17    BITCODE_BD elevation;
      18    BITCODE_BE extrusion;
      19    BITCODE_TV name;
      20    BITCODE_B is_solid_fill;
      21    BITCODE_B is_associative;
      22    BITCODE_BL num_paths;
      23    BITCODE_BS style;
      24    BITCODE_BS pattern_type;
      25    BITCODE_BD angle;
      26    BITCODE_BD scale_spacing;
      27    BITCODE_B double_flag;
      28    BITCODE_BS num_deflines;
      29    BITCODE_B has_derived;
      30    BITCODE_BD pixel_size;
      31    BITCODE_BL num_seeds;
      32    BITCODE_2RD *seeds;
      33    BITCODE_BL num_boundary_handles;
      34    BITCODE_H *boundary_handles;
      35    Dwg_HATCH_Color *colors;
      36    Dwg_HATCH_Path *paths;
      37    Dwg_HATCH_DefLine *deflines;
      38  
      39    Dwg_Version_Type dwg_version = obj->parent->header.version;
      40    dwg_ent_hatch *hatch = dwg_object_to_HATCH (obj);
      41  
      42    CHK_ENTITY_TYPE (hatch, HATCH, is_gradient_fill, BL);
      43    if (is_gradient_fill)
      44      {
      45        CHK_ENTITY_TYPE (hatch, HATCH, reserved, BL);
      46        CHK_ENTITY_TYPE (hatch, HATCH, gradient_angle, BD);
      47        CHK_ENTITY_MAX (hatch, HATCH, gradient_angle, BD, MAX_ANGLE);
      48        CHK_ENTITY_TYPE (hatch, HATCH, gradient_shift, BD);
      49        CHK_ENTITY_TYPE (hatch, HATCH, single_color_gradient, BL);
      50        CHK_ENTITY_TYPE (hatch, HATCH, gradient_tint, BD);
      51        CHK_ENTITY_UTF8TEXT (hatch, HATCH, gradient_name);
      52      }
      53    CHK_ENTITY_TYPE (hatch, HATCH, num_colors, BL);
      54    CHK_ENTITY_TYPE (hatch, HATCH, elevation, BD);
      55    CHK_ENTITY_3RD (hatch, HATCH, extrusion);
      56    CHK_ENTITY_UTF8TEXT (hatch, HATCH, name);
      57    CHK_ENTITY_TYPE (hatch, HATCH, is_solid_fill, B);
      58    CHK_ENTITY_TYPE (hatch, HATCH, is_associative, B);
      59    CHK_ENTITY_TYPE (hatch, HATCH, num_paths, BL);
      60    CHK_ENTITY_TYPE (hatch, HATCH, style, BS);
      61    if (hatch->style > 2)
      62      fail ("Invalid HATCH.style " FORMAT_BS " > 2", hatch->style);
      63    CHK_ENTITY_TYPE (hatch, HATCH, pattern_type, BS);
      64    if (hatch->pattern_type > 2)
      65      fail ("Invalid HATCH.pattern_type " FORMAT_BS " > 2", hatch->pattern_type);
      66    CHK_ENTITY_TYPE (hatch, HATCH, angle, BD);
      67    CHK_ENTITY_TYPE (hatch, HATCH, scale_spacing, BD);
      68    CHK_ENTITY_TYPE (hatch, HATCH, double_flag, B);
      69    CHK_ENTITY_TYPE (hatch, HATCH, num_deflines, BS);
      70    CHK_ENTITY_TYPE (hatch, HATCH, has_derived, B);
      71    CHK_ENTITY_TYPE (hatch, HATCH, pixel_size, BD);
      72    if (hatch->pixel_size != 0.0 && !hatch->has_derived)
      73      fail ("Invalid HATCH.pixel_size %f without HATCH.has_derived",
      74            hatch->pixel_size);
      75    CHK_ENTITY_TYPE (hatch, HATCH, num_seeds, BL);
      76    // CHK_ENTITY_TYPE (hatch, HATCH, num_boundary_handles, BL);
      77  
      78    if (!dwg_dynapi_entity_value (hatch, "HATCH", "colors", &colors, NULL))
      79      fail ("HATCH.colors");
      80    if (num_colors)
      81      {
      82        if (!is_gradient_fill)
      83          fail ("HATCH.num_colors without is_gradient_fill");
      84        if (!colors)
      85          fail ("HATCH.colors");
      86        else
      87          for (i = 0; i < num_colors; i++)
      88            {
      89              CHK_SUBCLASS_TYPE (colors[i], HATCH_Color, shift_value, BD);
      90              CHK_SUBCLASS_CMC (colors[i], HATCH_Color, color);
      91            }
      92      }
      93  
      94    if (!dwg_dynapi_entity_value (hatch, "HATCH", "paths", &paths, NULL))
      95      fail ("HATCH.paths");
      96    if (num_paths)
      97      {
      98        if (!paths)
      99          fail ("HATCH.paths");
     100        else
     101          for (i = 0; i < num_paths; i++)
     102            {
     103              CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, flag, BLx);
     104              CHK_SUBCLASS_MAX (paths[i], HATCH_Path, flag, BL, 0x400);
     105              CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, num_segs_or_paths, BL);
     106              if (!(paths[i].flag & 2))
     107                {
     108                  for (BITCODE_BL j = 0; j < paths[i].num_segs_or_paths; j++)
     109                    {
     110                      CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     111                                         curve_type, RC);
     112                      if (paths[i].segs[j].curve_type > 4)
     113                        fail (
     114                            "Invalid HATCH.paths[%d].segs[%d].curve_type %d > 4",
     115                            i, j, paths[i].segs[j].curve_type);
     116                      if (paths[i].segs[j].curve_type == 1)
     117                        {
     118                          CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg,
     119                                            first_endpoint);
     120                          CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg,
     121                                            second_endpoint);
     122                        }
     123                      else if (paths[i].segs[j].curve_type == 2)
     124                        { /* CIRCULAR ARC */
     125                          CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg,
     126                                            center);
     127                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     128                                             radius, BD);
     129                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     130                                             start_angle, BD);
     131                          // CHK_ENTITY_MAX (hatch, HATCH_PathSeg, start_angle,
     132                          // BD, MAX_ANGLE);
     133                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     134                                             end_angle, BD);
     135                          // CHK_ENTITY_MAX (hatch, HATCH_PathSeg, end_angle, BD,
     136                          // MAX_ANGLE);
     137                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     138                                             is_ccw, B);
     139                        }
     140                      else if (paths[i].segs[j].curve_type == 3)
     141                        { /* ELLIPTICAL ARC */
     142                          CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg,
     143                                            center);
     144                          CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg,
     145                                            endpoint);
     146                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     147                                             minor_major_ratio, BD);
     148                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     149                                             start_angle, BD);
     150                          // CHK_ENTITY_MAX (hatch, HATCH_PathSeg, start_angle,
     151                          // BD, MAX_ANGLE);
     152                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     153                                             end_angle, BD);
     154                          // CHK_ENTITY_MAX (hatch, HATCH_PathSeg, end_angle, BD,
     155                          // MAX_ANGLE);
     156                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     157                                             is_ccw, B);
     158                        }
     159                      else if (paths[i].segs[j].curve_type == 4)
     160                        { /* SPLINE */
     161                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     162                                             degree, BL);
     163                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     164                                             is_rational, B);
     165                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     166                                             is_periodic, B);
     167                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     168                                             num_knots, BL);
     169                          CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg,
     170                                             num_control_points, BL);
     171                          // knots: BD vector
     172                          // control_points: HATCH_ControlPoint
     173                        }
     174                    }
     175                }
     176              else
     177                {
     178                  CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, bulges_present, B);
     179                  CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, closed, B);
     180                  CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, num_segs_or_paths,
     181                                     BL);
     182                  for (BITCODE_BL j = 0; j < paths[i].num_segs_or_paths; j++)
     183                    {
     184                      CHK_SUBCLASS_2RD (paths[i].polyline_paths[j],
     185                                        HATCH_PolylinePath, point);
     186                      CHK_SUBCLASS_TYPE (paths[i].polyline_paths[j],
     187                                         HATCH_PolylinePath, bulge, BD);
     188                      if (paths[i].polyline_paths[j].bulge != 0.0
     189                          && paths[i].bulges_present)
     190                        fail ("Illegal HATCH_PolylinePath.bulge %f without "
     191                              "paths[i].bulges_present",
     192                              paths[i].polyline_paths[j].bulge);
     193                    }
     194                }
     195              CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, num_boundary_handles, BL);
     196              // boundary_handles SUB HV
     197            }
     198      }
     199  
     200    if (!dwg_dynapi_entity_value (hatch, "HATCH", "deflines", &deflines, NULL))
     201      fail ("HATCH.deflines");
     202    // only with !solid_fill
     203    if (num_deflines)
     204      {
     205        if (is_solid_fill)
     206          fail ("HATCH.num_deflines with solid_fill");
     207        if (!deflines)
     208          fail ("HATCH.deflines");
     209        else
     210          {
     211            for (i = 0; i < num_deflines; i++)
     212              {
     213                CHK_SUBCLASS_TYPE (deflines[i], HATCH_DefLine, angle, BD);
     214                CHK_SUBCLASS_2RD (deflines[i], HATCH_DefLine, pt0);
     215                CHK_SUBCLASS_2RD (deflines[i], HATCH_DefLine, offset);
     216                CHK_SUBCLASS_TYPE (deflines[i], HATCH_DefLine, num_dashes, BS);
     217                for (BITCODE_BS j = 0; j < deflines[i].num_dashes; j++)
     218                  {
     219                    ok ("HATCH.deflines[%d].dashes[%d]: %f", i, j,
     220                        deflines[i].dashes[j]);
     221                  }
     222              }
     223          }
     224      }
     225  
     226    if (!dwg_dynapi_entity_value (hatch, "HATCH", "seeds", &seeds, NULL))
     227      fail ("HATCH.seeds");
     228    if (num_seeds)
     229      {
     230        if (!seeds)
     231          fail ("HATCH.seeds");
     232        else
     233          for (i = 0; i < num_seeds; i++)
     234            {
     235              ok ("HATCH.seeds[%d]: (%f, %f)", i, seeds[i].x, seeds[i].y);
     236            }
     237      }
     238    else if (seeds)
     239      fail ("HATCH.seeds with !num_seeds");
     240  
     241    /*
     242    if (!dwg_dynapi_entity_value (hatch, "HATCH", "boundary_handles",
     243    &boundary_handles, NULL)) fail ("HATCH.boundary_handles"); if
     244    (num_boundary_handles)
     245      {
     246        if (!boundary_handles)
     247          fail ("HATCH.boundary_handles");
     248        else
     249          for (i = 0; i < num_boundary_handles; i++)
     250            {
     251              ok ("HATCH.boundary_handles[%d]: " FORMAT_REF, i, ARGS_REF
     252    (boundary_handles[i]));
     253            }
     254      }
     255    else if (boundary_handles)
     256      fail ("HATCH.boundary_handles with !num_boundary_handles");
     257    */
     258  }