(root)/
libredwg-0.13/
test/
unit-testing/
multileader.c
       1  #define DWG_TYPE DWG_TYPE_MULTILEADER
       2  #include "common.c"
       3  
       4  void
       5  api_process (dwg_object *obj)
       6  {
       7    int error;
       8    BITCODE_BL i;
       9    BITCODE_BS class_version;
      10    Dwg_MLEADER_AnnotContext ctx;
      11    BITCODE_H mleaderstyle;
      12    BITCODE_BL flags;
      13    BITCODE_BS type;
      14    BITCODE_CMC line_color;
      15    BITCODE_H line_ltype;
      16    BITCODE_BLd line_linewt;
      17    BITCODE_B has_landing;
      18    BITCODE_B has_dogleg;
      19    BITCODE_BD landing_dist;
      20    BITCODE_H arrow_handle;
      21    BITCODE_BD arrow_size;
      22    BITCODE_BS style_content;
      23    BITCODE_H text_style;
      24    BITCODE_BS text_left;
      25    BITCODE_BS text_right;
      26    BITCODE_BS text_angletype;
      27    BITCODE_BS text_alignment;
      28    BITCODE_CMC text_color;
      29    BITCODE_B has_text_frame;
      30    BITCODE_H block_style;
      31    BITCODE_CMC block_color;
      32    dwg_point_3d block_scale;
      33    BITCODE_BD block_rotation;
      34    BITCODE_BS style_attachment;
      35    BITCODE_B is_annotative;
      36    /* until r2007: */
      37    BITCODE_BL num_arrowheads;
      38    Dwg_LEADER_ArrowHead *arrowheads;
      39    BITCODE_BL num_blocklabels;
      40    Dwg_LEADER_BlockLabel *blocklabels;
      41    BITCODE_B is_neg_textdir;
      42    BITCODE_BS ipe_alignment;
      43    BITCODE_BS justification;
      44    BITCODE_BD scale_factor;
      45    BITCODE_BS attach_dir;
      46    BITCODE_BS attach_top;
      47    BITCODE_BS attach_bottom;
      48    BITCODE_B is_text_extended;
      49    BITCODE_3RD *points;
      50    BITCODE_BD *transform;
      51  
      52    Dwg_Version_Type dwg_version = obj->parent->header.version;
      53    dwg_ent_mleader *mleader = dwg_object_to_MULTILEADER (obj);
      54  
      55    CHK_ENTITY_TYPE (mleader, MULTILEADER, class_version, BS);
      56    if (!dwg_dynapi_entity_value (mleader, "MULTILEADER", "ctx", &ctx, NULL))
      57      fail ("MULTILEADER.ctx");
      58    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, num_leaders, BL);
      59    if (!dwg_dynapi_subclass_value (&ctx, "MLEADER_AnnotContext", "leaders",
      60                                    &ctx.leaders, NULL))
      61      fail ("MULTILEADER.ctx.leaders");
      62    if (ctx.num_leaders)
      63      {
      64        if (!ctx.leaders)
      65          fail ("!MULTILEADER.ctx.leaders but ctx.num_leaders");
      66        else
      67          for (i = 0; i < ctx.num_leaders; i++)
      68            {
      69              CHK_SUBCLASS_TYPE (ctx.leaders[i], LEADER_Node,
      70                                 has_lastleaderlinepoint, B);
      71              if (ctx.leaders[i].has_lastleaderlinepoint)
      72                CHK_SUBCLASS_3RD (ctx.leaders[i], LEADER_Node,
      73                                  lastleaderlinepoint);
      74              CHK_SUBCLASS_TYPE (ctx.leaders[i], LEADER_Node, has_dogleg, B);
      75              if (ctx.leaders[i].has_dogleg)
      76                CHK_SUBCLASS_3RD (ctx.leaders[i], LEADER_Node, dogleg_vector);
      77              CHK_SUBCLASS_TYPE (ctx.leaders[i], LEADER_Node, num_breaks, BL);
      78              for (BITCODE_BL j = 0; j < ctx.leaders[i].num_breaks; j++)
      79                {
      80                  CHK_SUBCLASS_3RD (ctx.leaders[i].breaks[j], LEADER_Break,
      81                                    start);
      82                  CHK_SUBCLASS_3RD (ctx.leaders[i].breaks[j], LEADER_Break, end);
      83                }
      84              CHK_SUBCLASS_TYPE (ctx.leaders[i], LEADER_Node, branch_index, BL);
      85              CHK_SUBCLASS_TYPE (ctx.leaders[i], LEADER_Node, dogleg_length, BD);
      86              CHK_SUBCLASS_TYPE (ctx.leaders[i], LEADER_Node, num_lines, BL);
      87              for (BITCODE_BL j = 0; j < ctx.leaders[i].num_lines; j++)
      88                {
      89                  BITCODE_BL num_points = ctx.leaders[i].lines[j].num_points;
      90                  CHK_SUBCLASS_TYPE (ctx.leaders[i].lines[j], LEADER_Line,
      91                                     num_points, BL);
      92                  CHK_SUBCLASS_3DPOINTS (ctx.leaders[i].lines[j], LEADER_Line,
      93                                         points, num_points);
      94                  CHK_SUBCLASS_TYPE (ctx.leaders[i].lines[j], LEADER_Line,
      95                                     num_breaks, BL);
      96                  for (BITCODE_BL k = 0; k < ctx.leaders[i].lines[j].num_breaks;
      97                       k++)
      98                    {
      99                      CHK_SUBCLASS_3RD (ctx.leaders[i].lines[j].breaks[k],
     100                                        LEADER_Break, start);
     101                      CHK_SUBCLASS_3RD (ctx.leaders[i].lines[j].breaks[k],
     102                                        LEADER_Break, end);
     103                    }
     104                  CHK_SUBCLASS_TYPE (ctx.leaders[i].lines[j], LEADER_Line,
     105                                     line_index, BL);
     106                  if (dwg_version >= R_2010)
     107                    {
     108                      type = ctx.leaders[i].lines[j].type;
     109                      CHK_SUBCLASS_TYPE (ctx.leaders[i].lines[j], LEADER_Line,
     110                                         type, BS);
     111                      CHK_SUBCLASS_MAX (ctx.leaders[i].lines[j], LEADER_Line,
     112                                        type, BS, 3);
     113                      CHK_SUBCLASS_CMC (ctx.leaders[i].lines[j], LEADER_Line,
     114                                        color);
     115                      CHK_SUBCLASS_H (ctx.leaders[i].lines[j], LEADER_Line,
     116                                      ltype);
     117                      CHK_SUBCLASS_TYPE (ctx.leaders[i].lines[j], LEADER_Line,
     118                                         linewt, BLd);
     119                      CHK_SUBCLASS_TYPE (ctx.leaders[i].lines[j], LEADER_Line,
     120                                         arrow_size, BD);
     121                      CHK_SUBCLASS_H (ctx.leaders[i].lines[j], LEADER_Line,
     122                                      arrow_handle);
     123                      CHK_SUBCLASS_TYPE (ctx.leaders[i].lines[j], LEADER_Line,
     124                                         flags, BL);
     125                      CHK_SUBCLASS_MAX (ctx.leaders[i].lines[j], LEADER_Line,
     126                                        flags, BL, 63);
     127                    }
     128                }
     129              if (dwg_version >= R_2010)
     130                {
     131                  CHK_SUBCLASS_TYPE (ctx.leaders[i], LEADER_Node, attach_dir,
     132                                     BS);
     133                  CHK_SUBCLASS_MAX (ctx.leaders[i], LEADER_Node, attach_dir, BS,
     134                                    1);
     135                }
     136            }
     137      }
     138    else if (ctx.leaders)
     139      fail ("MULTILEADER.ctx.leaders but 0 ctx.num_leaders");
     140    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, scale_factor, BD);
     141    CHK_SUBCLASS_3RD (ctx, MLEADER_AnnotContext, content_base);
     142    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, text_height, BD);
     143    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, arrow_size, BD);
     144    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, landing_gap, BD);
     145    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, text_left, BS);
     146    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, text_right, BS);
     147    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, text_angletype, BS);
     148    CHK_SUBCLASS_MAX (ctx, MLEADER_AnnotContext, text_angletype, BS, 2);
     149    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, text_alignment, BS);
     150    CHK_SUBCLASS_MAX (ctx, MLEADER_AnnotContext, text_alignment, BS, 1);
     151    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, has_content_txt, B);
     152    if (ctx.has_content_txt)
     153      {
     154        CHK_SUBCLASS_UTF8TEXT (ctx.content.txt, MLEADER_Content_MText,
     155                               default_text);
     156        CHK_SUBCLASS_3RD (ctx.content.txt, MLEADER_Content_MText, normal);
     157        CHK_SUBCLASS_H (ctx.content.txt, MLEADER_Content_MText, style);
     158        CHK_SUBCLASS_3RD (ctx.content.txt, MLEADER_Content_MText, location);
     159        CHK_SUBCLASS_3RD (ctx.content.txt, MLEADER_Content_MText, direction);
     160        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, rotation, BD);
     161        CHK_SUBCLASS_MAX (ctx.content.txt, MLEADER_Content_MText, rotation, BD,
     162                          MAX_ANGLE);
     163        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, width, BD);
     164        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText,
     165                           line_spacing_factor, BD);
     166        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText,
     167                           line_spacing_style, BS);
     168        CHK_SUBCLASS_MAX (ctx.content.txt, MLEADER_Content_MText,
     169                          line_spacing_style, BS, 2);
     170        CHK_SUBCLASS_CMC (ctx.content.txt, MLEADER_Content_MText, color);
     171        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, alignment,
     172                           BS);
     173        CHK_SUBCLASS_MAX (ctx.content.txt, MLEADER_Content_MText, alignment, BS,
     174                          3);
     175        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, flow, BS);
     176        CHK_SUBCLASS_MAX (ctx.content.txt, MLEADER_Content_MText, flow, BS, 6);
     177        CHK_SUBCLASS_CMC (ctx.content.txt, MLEADER_Content_MText, bg_color);
     178        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, bg_scale,
     179                           BD); // FIXME! r2000
     180        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText,
     181                           bg_transparency, BL);
     182        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, is_bg_fill,
     183                           B);
     184        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText,
     185                           is_bg_mask_fill, B);
     186        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, col_type, BS);
     187        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText,
     188                           is_height_auto, B);
     189        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, col_width,
     190                           BD);
     191        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, col_gutter,
     192                           BD);
     193        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText,
     194                           is_col_flow_reversed, B);
     195        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, num_col_sizes,
     196                           BL);
     197        CHK_SUBCLASS_VECTOR_TYPE (ctx.content.txt, MLEADER_Content_MText,
     198                                  col_sizes, ctx.content.txt.num_col_sizes, BD);
     199        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, word_break,
     200                           B);
     201        CHK_SUBCLASS_TYPE (ctx.content.txt, MLEADER_Content_MText, unknown, B);
     202      }
     203    CHK_SUBCLASS_TYPE (ctx, MLEADER_AnnotContext, has_content_blk, B);
     204    if (ctx.has_content_blk)
     205      {
     206        if (ctx.has_content_txt)
     207          fail ("ctx.has_content_blk && ctx.has_content_txt");
     208        CHK_SUBCLASS_H (ctx.content.blk, MLEADER_Content_Block, block_table);
     209        CHK_SUBCLASS_3RD (ctx.content.blk, MLEADER_Content_Block, normal);
     210        CHK_SUBCLASS_3RD (ctx.content.blk, MLEADER_Content_Block, location);
     211        CHK_SUBCLASS_3RD (ctx.content.blk, MLEADER_Content_Block, scale);
     212        CHK_SUBCLASS_TYPE (ctx.content.blk, MLEADER_Content_Block, rotation, BD);
     213        CHK_SUBCLASS_MAX (ctx.content.blk, MLEADER_Content_Block, rotation, BD,
     214                          MAX_ANGLE);
     215        CHK_SUBCLASS_CMC (ctx.content.blk, MLEADER_Content_Block, color);
     216        CHK_SUBCLASS_VECTOR_TYPE (ctx.content.blk, MLEADER_Content_Block,
     217                                  transform, 16, BD);
     218      }
     219    else if (!ctx.has_content_txt)
     220      fail ("!ctx.has_content_blk && !ctx.has_content_txt");
     221  
     222    CHK_ENTITY_H (mleader, MULTILEADER, mleaderstyle);
     223    CHK_ENTITY_TYPE (mleader, MULTILEADER, flags, BL);
     224    CHK_ENTITY_TYPE (mleader, MULTILEADER, type, BS);
     225    // CHK_ENTITY_MAX (mleader, MULTILEADER, type, BS, 3);
     226    CHK_ENTITY_CMC (mleader, MULTILEADER, line_color);
     227    CHK_ENTITY_H (mleader, MULTILEADER, line_ltype);
     228    CHK_ENTITY_TYPE (mleader, MULTILEADER, line_linewt, BLd);
     229    CHK_ENTITY_TYPE (mleader, MULTILEADER, has_landing, B);
     230    CHK_ENTITY_TYPE (mleader, MULTILEADER, has_dogleg, B);
     231    CHK_ENTITY_TYPE (mleader, MULTILEADER, landing_dist, BD);
     232    CHK_ENTITY_H (mleader, MULTILEADER, arrow_handle);
     233    CHK_ENTITY_TYPE (mleader, MULTILEADER, arrow_size, BD);
     234    CHK_ENTITY_TYPE (mleader, MULTILEADER, style_content, BS);
     235    CHK_ENTITY_H (mleader, MULTILEADER, text_style);
     236    CHK_ENTITY_TYPE (mleader, MULTILEADER, text_left, BS);
     237    CHK_ENTITY_TYPE (mleader, MULTILEADER, text_right, BS);
     238    CHK_ENTITY_TYPE (mleader, MULTILEADER, text_angletype, BS);
     239    CHK_ENTITY_TYPE (mleader, MULTILEADER, text_alignment, BS);
     240    CHK_ENTITY_CMC (mleader, MULTILEADER, text_color);
     241    CHK_ENTITY_TYPE (mleader, MULTILEADER, has_text_frame, B);
     242    CHK_ENTITY_H (mleader, MULTILEADER, block_style);
     243    CHK_ENTITY_CMC (mleader, MULTILEADER, block_color);
     244    CHK_ENTITY_3RD (mleader, MULTILEADER, block_scale);
     245    CHK_ENTITY_TYPE (mleader, MULTILEADER, block_rotation, BD);
     246    CHK_ENTITY_MAX (mleader, MULTILEADER, block_rotation, BD, MAX_ANGLE);
     247    CHK_ENTITY_TYPE (mleader, MULTILEADER, style_attachment, BS);
     248    CHK_ENTITY_TYPE (mleader, MULTILEADER, is_annotative, B);
     249  
     250    if (dwg_version >= R_2000 && dwg_version <= R_2007)
     251      {
     252        // TODO no coverage
     253        CHK_ENTITY_TYPE (mleader, MULTILEADER, num_arrowheads, BL);
     254        if (!dwg_dynapi_entity_value (mleader, "MULTILEADER", "arrowheads",
     255                                      &arrowheads, NULL))
     256          fail ("MULTILEADER.arrowheads");
     257        if (num_arrowheads)
     258          {
     259            if (!arrowheads)
     260              fail ("!MULTILEADER.arrowheads but num_arrowheads");
     261            else
     262              for (i = 0; i < num_arrowheads; i++)
     263                {
     264                  ok ("MULTILEADER.arrowheads[%d].is_default: " FORMAT_B, i,
     265                      arrowheads[i].is_default);
     266                  ok ("MULTILEADER.arrowheads[%d].arrowhead: " FORMAT_REF, i,
     267                      ARGS_REF (arrowheads[i].arrowhead));
     268                }
     269          }
     270        else if (arrowheads)
     271          fail ("MULTILEADER.arrowheads but 0 num_arrowheads");
     272  
     273        // TODO no coverage
     274        CHK_ENTITY_TYPE (mleader, MULTILEADER, num_blocklabels, BL);
     275        if (!dwg_dynapi_entity_value (mleader, "MULTILEADER", "blocklabels",
     276                                      &blocklabels, NULL))
     277          fail ("MULTILEADER.blocklabels");
     278        if (num_blocklabels)
     279          {
     280            if (!blocklabels)
     281              fail ("!MULTILEADER.blocklabels but num_blocklabels");
     282            else
     283              for (i = 0; i < num_blocklabels; i++)
     284                {
     285                  ok ("MULTILEADER.blocklabels[%d].attdef: " FORMAT_REF, i,
     286                      ARGS_REF (blocklabels[i].attdef));
     287                  ok ("MULTILEADER.blocklabels[%d].label_text: %s", i,
     288                      blocklabels[i].label_text);
     289                  ok ("MULTILEADER.blocklabels[%d].ui_index: " FORMAT_BS, i,
     290                      blocklabels[i].ui_index);
     291                  ok ("MULTILEADER.blocklabels[%d].width: " FORMAT_BD, i,
     292                      blocklabels[i].width);
     293                }
     294          }
     295        else if (blocklabels)
     296          fail ("MULTILEADER.blocklabels but 0 num_blocklabels");
     297  
     298        CHK_ENTITY_TYPE (mleader, MULTILEADER, is_neg_textdir, B);
     299        CHK_ENTITY_TYPE (mleader, MULTILEADER, ipe_alignment, BS);
     300        CHK_ENTITY_TYPE (mleader, MULTILEADER, justification, BS);
     301        CHK_ENTITY_TYPE (mleader, MULTILEADER, scale_factor, BD);
     302      }
     303    if (dwg_version >= R_2010)
     304      {
     305        attach_dir = mleader->attach_dir;
     306        CHK_ENTITY_TYPE (mleader, MULTILEADER, attach_dir, BS);
     307        CHK_ENTITY_MAX (mleader, MULTILEADER, attach_dir, BS, 2);
     308        CHK_ENTITY_TYPE (mleader, MULTILEADER, attach_top, BS);
     309        // CHK_ENTITY_MAX (mleader, MULTILEADER, attach_top, BS, 160);
     310        CHK_ENTITY_TYPE (mleader, MULTILEADER, attach_bottom, BS);
     311        // CHK_ENTITY_MAX (mleader, MULTILEADER, attach_bottom, BS, 4786);
     312      }
     313    if (dwg_version >= R_2013)
     314      {
     315        CHK_ENTITY_TYPE (mleader, MULTILEADER, is_text_extended, B);
     316      }
     317  }