1 #define DWG_TYPE DWG_TYPE_HATCH
2 #include "common.c"
3 
4 void
api_process(dwg_object * obj)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", hatch->pixel_size);
74   CHK_ENTITY_TYPE (hatch, HATCH, num_seeds, BL);
75   //CHK_ENTITY_TYPE (hatch, HATCH, num_boundary_handles, BL);
76 
77   if (!dwg_dynapi_entity_value (hatch, "HATCH", "colors", &colors, NULL))
78     fail ("HATCH.colors");
79   if (num_colors)
80     {
81       if (!is_gradient_fill)
82         fail ("HATCH.num_colors without is_gradient_fill");
83       if (!colors)
84         fail ("HATCH.colors");
85       else
86         for (i = 0; i < num_colors; i++)
87           {
88             CHK_SUBCLASS_TYPE (colors[i], HATCH_Color, shift_value, BD);
89             CHK_SUBCLASS_CMC (colors[i], HATCH_Color, color);
90           }
91     }
92 
93   if (!dwg_dynapi_entity_value (hatch, "HATCH", "paths", &paths, NULL))
94     fail ("HATCH.paths");
95   if (num_paths)
96     {
97       if (!paths)
98         fail ("HATCH.paths");
99       else
100         for (i = 0; i < num_paths; i++)
101           {
102             CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, flag, BLx);
103             CHK_SUBCLASS_MAX (paths[i], HATCH_Path, flag, BL, 0x400);
104             CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, num_segs_or_paths, BL);
105             if (!(paths[i].flag & 2))
106               {
107                 for (BITCODE_BL j = 0; j < paths[i].num_segs_or_paths; j++)
108                   {
109                     CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, curve_type, RC);
110                     if (paths[i].segs[j].curve_type > 4)
111                       fail ("Invalid HATCH.paths[%d].segs[%d].curve_type %d > 4",
112                             i, j, paths[i].segs[j].curve_type);
113                     if (paths[i].segs[j].curve_type == 1)
114                       {
115                         CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg, first_endpoint);
116                         CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg, second_endpoint);
117                       }
118                     else if (paths[i].segs[j].curve_type == 2)
119                       { /* CIRCULAR ARC */
120                         CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg, center);
121                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, radius, BD);
122                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, start_angle, BD);
123                         //CHK_ENTITY_MAX (hatch, HATCH_PathSeg, start_angle, BD, MAX_ANGLE);
124                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, end_angle, BD);
125                         //CHK_ENTITY_MAX (hatch, HATCH_PathSeg, end_angle, BD, MAX_ANGLE);
126                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, is_ccw, B);
127                       }
128                     else if (paths[i].segs[j].curve_type == 3)
129                       { /* ELLIPTICAL ARC */
130                         CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg, center);
131                         CHK_SUBCLASS_2RD (paths[i].segs[j], HATCH_PathSeg, endpoint);
132                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, minor_major_ratio, BD);
133                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, start_angle, BD);
134                         //CHK_ENTITY_MAX (hatch, HATCH_PathSeg, start_angle, BD, MAX_ANGLE);
135                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, end_angle, BD);
136                         //CHK_ENTITY_MAX (hatch, HATCH_PathSeg, end_angle, BD, MAX_ANGLE);
137                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, is_ccw, B);
138                       }
139                     else if (paths[i].segs[j].curve_type == 4)
140                       { /* SPLINE */
141                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, degree, BL);
142                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, is_rational, B);
143                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, is_periodic, B);
144                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, num_knots, BL);
145                         CHK_SUBCLASS_TYPE (paths[i].segs[j], HATCH_PathSeg, num_control_points, BL);
146                         // knots: BD vector
147                         // control_points: HATCH_ControlPoint
148                       }
149                   }
150               }
151             else
152               {
153                 CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, bulges_present, B);
154                 CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, closed, B);
155                 CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, num_segs_or_paths, BL);
156                 for (BITCODE_BL j = 0; j < paths[i].num_segs_or_paths; j++)
157                   {
158                     CHK_SUBCLASS_2RD (paths[i].polyline_paths[j], HATCH_PolylinePath, point);
159                     CHK_SUBCLASS_TYPE (paths[i].polyline_paths[j], HATCH_PolylinePath, bulge, BD);
160                     if (paths[i].polyline_paths[j].bulge != 0.0 && paths[i].bulges_present)
161                       fail ("Illegal HATCH_PolylinePath.bulge %f without paths[i].bulges_present",
162                             paths[i].polyline_paths[j].bulge);
163                   }
164               }
165             CHK_SUBCLASS_TYPE (paths[i], HATCH_Path, num_boundary_handles, BL);
166             // boundary_handles SUB HV
167           }
168     }
169 
170   if (!dwg_dynapi_entity_value (hatch, "HATCH", "deflines", &deflines, NULL))
171     fail ("HATCH.deflines");
172   // only with !solid_fill
173   if (num_deflines)
174     {
175       if (is_solid_fill)
176         fail ("HATCH.num_deflines with solid_fill");
177       if (!deflines)
178         fail ("HATCH.deflines");
179       else
180         {
181           for (i = 0; i < num_deflines; i++)
182             {
183               CHK_SUBCLASS_TYPE (deflines[i], HATCH_DefLine, angle, BD);
184               CHK_SUBCLASS_2RD (deflines[i], HATCH_DefLine, pt0);
185               CHK_SUBCLASS_2RD (deflines[i], HATCH_DefLine, offset);
186               CHK_SUBCLASS_TYPE (deflines[i], HATCH_DefLine, num_dashes, BS);
187               for (BITCODE_BS j = 0; j < deflines[i].num_dashes; j++)
188                 {
189                   ok ("HATCH.deflines[%d].dashes[%d]: %f", i, j, deflines[i].dashes[j]);
190                 }
191             }
192         }
193     }
194 
195   if (!dwg_dynapi_entity_value (hatch, "HATCH", "seeds", &seeds, NULL))
196     fail ("HATCH.seeds");
197   if (num_seeds)
198     {
199       if (!seeds)
200         fail ("HATCH.seeds");
201       else
202         for (i = 0; i < num_seeds; i++)
203           {
204             ok ("HATCH.seeds[%d]: (%f, %f)", i, seeds[i].x, seeds[i].y);
205           }
206     }
207   else if (seeds)
208     fail ("HATCH.seeds with !num_seeds");
209 
210   /*
211   if (!dwg_dynapi_entity_value (hatch, "HATCH", "boundary_handles", &boundary_handles, NULL))
212     fail ("HATCH.boundary_handles");
213   if (num_boundary_handles)
214     {
215       if (!boundary_handles)
216         fail ("HATCH.boundary_handles");
217       else
218         for (i = 0; i < num_boundary_handles; i++)
219           {
220             ok ("HATCH.boundary_handles[%d]: " FORMAT_REF, i, ARGS_REF (boundary_handles[i]));
221           }
222     }
223   else if (boundary_handles)
224     fail ("HATCH.boundary_handles with !num_boundary_handles");
225   */
226 }
227