1 /************
2 *
3 *   This file is part of a tool for producing 3D content in the PRC format.
4 *   Copyright (C) 2008  Orest Shardt <shardtor (at) gmail dot com>
5 *
6 *   This program is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU Lesser General Public License  as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   This program is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *   GNU Lesser General Public License  for more details.
15 *
16 *   You should have received a copy of the GNU Lesser General Public License
17 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 *
19 *************/
20 
21 #ifndef __WRITE_PRC_H
22 #define __WRITE_PRC_H
23 #include <string>
24 #include <vector>
25 #include <deque>
26 #include <list>
27 #include <map>
28 #include <iostream>
29 #include <algorithm>
30 #include "PRCbitStream.h"
31 #include "PRC.h"
32 #include <float.h>
33 #include <math.h>
34 
35 static const uint32_t m1=(uint32_t)-1;
36 static const double pi=acos(-1.0);
37 
38 class PRCVector3d
39 {
40 public :
41  double x;
42  double y;
43  double z;
PRCVector3d()44  PRCVector3d() :
45  x(0), y(0), z(0) {}
PRCVector3d(double fx,double fy,double fz)46  PRCVector3d(double fx, double fy, double fz) :
47  x(fx), y(fy), z(fz) {}
48  PRCVector3d(const double c[], double fx=0, double fy=0, double fz=0) :
49  x(c?c[0]:fx), y(c?c[1]:fy), z(c?c[2]:fz) {}
PRCVector3d(const PRCVector3d & sVector3d)50  PRCVector3d(const PRCVector3d& sVector3d) :
51  x(sVector3d.x), y(sVector3d.y), z(sVector3d.z) {}
52 
Set(double fx,double fy,double fz)53  void Set(double fx, double fy, double fz)
54  { x = fx; y = fy; z = fz; }
Dot(const PRCVector3d & sPt)55  double Dot(const PRCVector3d & sPt) const
56  { return(x*sPt.x)+(y*sPt.y)+(z*sPt.z); }
LengthSquared()57  double LengthSquared()
58  { return(x*x+y*y+z*z); }
59 
60  friend PRCVector3d operator + (const PRCVector3d& a, const PRCVector3d& b)
61  { return PRCVector3d(a.x+b.x,a.y+b.y,a.z+b.z); }
62  friend PRCVector3d operator - (const PRCVector3d& a)
63  { return PRCVector3d(-a.x,-a.y,-a.z); }
64  friend PRCVector3d operator - (const PRCVector3d& a, const PRCVector3d& b)
65  { return PRCVector3d(a.x-b.x,a.y-b.y,a.z-b.z); }
66  friend PRCVector3d operator * (const PRCVector3d& a, const double d)
67  { return PRCVector3d(a.x*d,a.y*d,a.z*d); }
68  friend PRCVector3d operator * (const double d, const PRCVector3d& a)
69  { return PRCVector3d(a.x*d,a.y*d,a.z*d); }
70  friend PRCVector3d operator / (const PRCVector3d& a, const double d)
71  { return PRCVector3d(a.x/d,a.y/d,a.z/d); }
72  friend PRCVector3d operator * (const PRCVector3d& a, const PRCVector3d& b)
73  { return PRCVector3d((a.y*b.z)-(a.z*b.y), (a.z*b.x)-(a.x*b.z), (a.x*b.y)-(a.y*b.x)); }
74 
write(PRCbitStream & out)75  void write(PRCbitStream &out) { out << x << y << z; }
serializeVector3d(PRCbitStream & pbs)76  void serializeVector3d(PRCbitStream &pbs) const { pbs << x << y << z; }
serializeVector2d(PRCbitStream & pbs)77  void serializeVector2d(PRCbitStream &pbs) const { pbs << x << y; }
78 
79  double Length();
80  bool Normalize();
81 
82  bool operator==(const PRCVector3d &v) const
83  {
84   return x==v.x && y==v.y && z==v.z;
85  }
86  bool operator!=(const PRCVector3d &v) const
87  {
88   return !(x==v.x && y==v.y && z==v.z);
89  }
90  bool operator<(const PRCVector3d &v) const
91  {
92    if(x!=v.x)
93      return (x<v.x);
94    if(y!=v.y)
95      return (y<v.y);
96    return (z<v.z);
97  }
98  friend std::ostream& operator << (std::ostream& out, const PRCVector3d& v)
99  {
100    out << "(" << v.x << "," << v.y << "," << v.z << ")";
101    return out;
102  }
103 };
104 /*
105 class UUID
106 {
107   public:
108     UUID(uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3) :
109       id0(u0),id1(u1),id2(u2),id3(u3) {}
110     void write(PRCbitStream &out)
111     {
112       out << id0 << id1 << id2 << id3;
113     }
114   private:
115     uint32_t id0,id1,id2,id3;
116 }; */
117 
118 void writeUncompressedUnsignedInteger(std::ostream &out, uint32_t data);
119 
120 void writeUnit(PRCbitStream &,bool,double);
121 
122 void writeEmptyMarkups(PRCbitStream&);
123 
124 class UserData
125 {
126   public:
size(s)127     UserData(uint32_t s = 0, uint8_t* d = 0) : size(s),data(d) {}
128     void write(PRCbitStream&);
129   private:
130     uint32_t size;
131     uint8_t* data;
132 };
133 
134 struct PRCAttributeEntry
135 {
PRCAttributeEntryPRCAttributeEntry136 	PRCAttributeEntry() : title_is_integer(false) {}
PRCAttributeEntryPRCAttributeEntry137 	PRCAttributeEntry(uint32_t integer) : title_is_integer(true)
138   {
139     title_integer = integer;
140   }
PRCAttributeEntryPRCAttributeEntry141 	PRCAttributeEntry(const std::string &text) : title_is_integer(false)
142   {
143     title_text = text;
144   }
145   void serializeAttributeEntry(PRCbitStream&) const;
146   bool title_is_integer;
147   std::string title_text;
148   uint32_t title_integer;
149 };
150 
151 class PRCSingleAttribute : public PRCAttributeEntry
152 {
153   public:
PRCSingleAttribute()154   PRCSingleAttribute() : type(KEPRCModellerAttributeTypeNull) {}
PRCSingleAttribute(int32_t integer)155 	PRCSingleAttribute(int32_t integer) : PRCAttributeEntry(), type(KEPRCModellerAttributeTypeInt)
156   {
157     value.integer = integer;
158   }
PRCSingleAttribute(double real)159 	PRCSingleAttribute(double real) : PRCAttributeEntry(), type(KEPRCModellerAttributeTypeReal)
160   {
161     value.real = real;
162   }
PRCSingleAttribute(uint32_t time)163   PRCSingleAttribute(uint32_t time) : PRCAttributeEntry(), type(KEPRCModellerAttributeTypeTime)
164   {
165     value.time = time;
166   }
PRCSingleAttribute(const std::string & text)167 	PRCSingleAttribute(const std::string &text) : PRCAttributeEntry(), type(KEPRCModellerAttributeTypeString)
168   {
169     value_text = text;}
PRCSingleAttribute(uint32_t title,int32_t integer)170 	PRCSingleAttribute(uint32_t title, int32_t integer) : PRCAttributeEntry(title), type(KEPRCModellerAttributeTypeInt)
171   {
172     value.integer = integer;
173   }
PRCSingleAttribute(uint32_t title,double real)174 	PRCSingleAttribute(uint32_t title, double real) : PRCAttributeEntry(title), type(KEPRCModellerAttributeTypeReal)
175   {
176     value.real = real;
177   }
PRCSingleAttribute(uint32_t title,uint32_t time)178   PRCSingleAttribute(uint32_t title, uint32_t time) : PRCAttributeEntry(title), type(KEPRCModellerAttributeTypeTime)
179   {
180     value.time = time;
181   }
PRCSingleAttribute(uint32_t title,const std::string & text)182 	PRCSingleAttribute(uint32_t title, const std::string &text) : PRCAttributeEntry(title), type(KEPRCModellerAttributeTypeString)
183   {
184     value_text = text;
185   }
PRCSingleAttribute(const std::string title,int32_t integer)186 	PRCSingleAttribute(const std::string title, int32_t integer) : PRCAttributeEntry(title), type(KEPRCModellerAttributeTypeInt)
187   {
188     value.integer = integer;
189   }
PRCSingleAttribute(const std::string title,double real)190 	PRCSingleAttribute(const std::string title, double real) : PRCAttributeEntry(title), type(KEPRCModellerAttributeTypeReal)
191   {
192     value.real = real;
193   }
PRCSingleAttribute(const std::string title,uint32_t time)194   PRCSingleAttribute(const std::string title, uint32_t time) : PRCAttributeEntry(title), type(KEPRCModellerAttributeTypeTime)
195   {
196     value.time = time;
197   }
PRCSingleAttribute(const std::string title,const std::string & text)198 	PRCSingleAttribute(const std::string title, const std::string &text) : PRCAttributeEntry(title), type(KEPRCModellerAttributeTypeString)
199   {
200     value_text = text;
201   }
202   void serializeSingleAttribute(PRCbitStream&) const;
203   EPRCModellerAttributeType  type;
204   union PRCSingleAttributeData
205   {
206     int32_t integer;
207     double real;
208     uint32_t time;
209   } value;
210   std::string value_text;
211 };
212 
213 class PRCAttribute : public PRCAttributeEntry
214 {
215   public:
PRCAttribute()216   PRCAttribute() : PRCAttributeEntry() {}
PRCAttribute(uint32_t title)217 	PRCAttribute(uint32_t title) : PRCAttributeEntry(title) {}
PRCAttribute(const std::string title)218 	PRCAttribute(const std::string title) : PRCAttributeEntry(title) {}
219   void serializeAttribute(PRCbitStream &) const;
newKey()220   PRCSingleAttribute& newKey() { attribute_keys.resize(attribute_keys.size()+1); return attribute_keys.back(); }
addKey(const PRCSingleAttribute & key)221   void addKey(const PRCSingleAttribute &key) { attribute_keys.push_back(key); }
222   std::deque<PRCSingleAttribute> attribute_keys;
223 };
224 typedef std::list<PRCAttribute> PRCAttributeList;
225 
226 class PRCAttributes
227 {
228   public:
229   void serializeAttributes(PRCbitStream&) const;
newAttribute()230   PRCAttribute& newAttribute() { attributes.push_front(PRCAttribute()); return attributes.front(); }
addAttribute(const PRCAttribute & attribute)231   void addAttribute(const PRCAttribute &attribute) { attributes.push_front(attribute); }
232   PRCAttributeList attributes;
233 };
234 
235 bool type_eligible_for_reference(uint32_t type);
236 uint32_t makeCADID();
237 uint32_t makePRCID();
238 
239 class ContentPRCBase : public PRCAttributes
240 {
241   public:
242   ContentPRCBase(uint32_t t, std::string n="") :
type(t)243     type(t),name(n),CAD_identifier(0), CAD_persistent_identifier(0), PRC_unique_identifier(0)
244   {
245     if(type_eligible_for_reference(type))
246     {
247       CAD_identifier = makeCADID();
248       PRC_unique_identifier = makePRCID();
249     }
250   }
251   void serializeContentPRCBase(PRCbitStream&) const;
getPRCID()252   uint32_t getPRCID() const { return PRC_unique_identifier; }
getType()253   uint32_t getType() const { return type; }
254   uint32_t type;
255   std::string name;
256   uint32_t CAD_identifier, CAD_persistent_identifier, PRC_unique_identifier;
257 };
258 
259 class PRCReferenceUniqueIdentifier
260 {
261 public:
PRCReferenceUniqueIdentifier()262   PRCReferenceUniqueIdentifier() :
263     type(0), unique_identifier(m1) {}
264   void serializeReferenceUniqueIdentifier(PRCbitStream&);
265   uint32_t type;
266 // bool reference_in_same_file_structure;
267 // PRCUniqueId target_file_structure;
268   uint32_t unique_identifier;
269 };
270 
271 extern std::string currentName;
272 void writeName(PRCbitStream&,const std::string&);
273 void resetName();
274 
275 extern uint32_t current_layer_index;
276 extern uint32_t current_index_of_line_style;
277 extern uint16_t current_behaviour_bit_field;
278 
279 void writeGraphics(PRCbitStream&,uint32_t=m1,uint32_t=m1,uint16_t=1,bool=false);
280 void resetGraphics();
281 
282 void resetGraphicsAndName();
283 
284 struct PRCVector2d
285 {
PRCVector2dPRCVector2d286   PRCVector2d() :
287   x(0.0), y(0.0) {}
PRCVector2dPRCVector2d288   PRCVector2d(double X, double Y) :
289   x(X), y(Y) {}
290   void serializeVector2d(PRCbitStream&);
291   double x;
292   double y;
293   PRCVector2d(const double c[], double fx=0, double fy=0) :
294   x(c?c[0]:fx), y(c?c[1]:fy) {}
PRCVector2dPRCVector2d295   PRCVector2d(const PRCVector2d& sVector2d) :
296   x(sVector2d.x), y(sVector2d.y) {}
297 
SetPRCVector2d298   void Set(double fx, double fy)
299   { x = fx; y = fy; }
DotPRCVector2d300   double Dot(const PRCVector2d & sPt) const
301   { return(x*sPt.x)+(y*sPt.y); }
LengthSquaredPRCVector2d302   double LengthSquared()
303   { return(x*x+y*y); }
304 
305   friend PRCVector2d operator + (const PRCVector2d& a, const PRCVector2d& b)
306   { return PRCVector2d(a.x+b.x,a.y+b.y); }
307   friend PRCVector2d operator - (const PRCVector2d& a)
308   { return PRCVector2d(-a.x,-a.y); }
309   friend PRCVector2d operator - (const PRCVector2d& a, const PRCVector2d& b)
310   { return PRCVector2d(a.x-b.x,a.y-b.y); }
311   friend PRCVector2d operator * (const PRCVector2d& a, const double d)
312   { return PRCVector2d(a.x*d,a.y*d); }
313   friend PRCVector2d operator * (const double d, const PRCVector2d& a)
314   { return PRCVector2d(a.x*d,a.y*d); }
315   friend PRCVector2d operator / (const PRCVector2d& a, const double d)
316   { return PRCVector2d(a.x/d,a.y/d); }
317 
318   double Length();
319   bool Normalize();
320 
321   bool operator==(const PRCVector2d &v) const
322   {
323     return x==v.x && y==v.y;
324   }
325   bool operator!=(const PRCVector2d &v) const
326   {
327     return !(x==v.x && y==v.y);
328   }
329   bool operator<(const PRCVector2d &v) const
330   {
331     if(x!=v.x)
332       return (x<v.x);
333     return (y<v.y);
334   }
335   friend std::ostream& operator << (std::ostream& out, const PRCVector2d& v)
336   {
337     out << "(" << v.x << "," << v.y << ")";
338     return out;
339   }
340 };
341 
342 #define EQFLD(fld) fld==c.fld
343 #define COMPFLD(fld) \
344 if(fld != c.fld) \
345   return (fld < c.fld);
346 #define PRCMAP(PRCtype) \
347 struct PRCtype##Cmp : public std::binary_function <const PRCtype*, const PRCtype*, bool> \
348 { bool operator()(const PRCtype* Left, const PRCtype* Right) const  { return (*Left < *Right); } }; \
349 typedef std::map<PRCtype*,uint32_t,PRCtype##Cmp> PRCtype##Map;
350 #define PRCLIST(PRCtype) \
351 typedef std::deque <PRCtype*>  PRCtype##List;
352 
353 
354 struct PRCRgbColor
355 {
356   PRCRgbColor(double r=0.0, double g=0.0, double b=0.0) :
redPRCRgbColor357   red(r), green(g), blue(b) {}
358   double red,green,blue;
359   void serializeRgbColor(PRCbitStream&);
360 
361   bool operator==(const PRCRgbColor &c) const
362   {
363     return (EQFLD(red) &&
364             EQFLD(green) &&
365             EQFLD(blue)
366             );
367   }
368   bool operator!=(const PRCRgbColor &c) const
369   {
370     return !(EQFLD(red) &&
371              EQFLD(green) &&
372              EQFLD(blue)
373              );
374   }
375   bool operator<(const PRCRgbColor &c) const
376   {
377     COMPFLD(red)
378     COMPFLD(green)
379     COMPFLD(blue)
380     return false;
381   }
382 };
383 typedef std::map<PRCRgbColor,uint32_t> PRCRgbColorMap;
384 typedef std::deque<PRCRgbColor>  PRCRgbColorList;
385 
386 class PRCUncompressedFile
387 {
388 public:
PRCUncompressedFile()389   PRCUncompressedFile() {}
PRCUncompressedFile(uint32_t fs,uint8_t * d)390   PRCUncompressedFile(uint32_t fs, uint8_t *d) {
391     file_contents.assign( d, d + fs );
392   }
393 
394   std::vector<uint8_t> file_contents;
395 
396   void serializeUncompressedFile(std::ostream&) const;
397 
398   uint32_t getSize() const;
399 
400   bool operator==(const PRCUncompressedFile& c) const
401   {
402     return file_contents==c.file_contents;
403   }
404   bool operator<(const PRCUncompressedFile& c) const
405   {
406     return file_contents<c.file_contents;
407   }
408 };
409 PRCLIST(PRCUncompressedFile)
PRCMAP(PRCUncompressedFile)410 PRCMAP(PRCUncompressedFile)
411 
412 class PRCPicture : public ContentPRCBase
413 {
414 public:
415   PRCPicture(std::string n="") :
416   ContentPRCBase(PRC_TYPE_GRAPH_Picture,n), format(KEPRCPicture_PNG), uncompressed_file_index(m1), pixel_width(0), pixel_height(0) {}
417   void serializePicture(PRCbitStream&);
418   EPRCPictureDataFormat format;
419   uint32_t uncompressed_file_index;
420   uint32_t pixel_width;
421   uint32_t pixel_height;
422   bool operator==(const PRCPicture& c) const
423   {
424     return (EQFLD(format) &&
425             EQFLD(uncompressed_file_index) &&
426             EQFLD(pixel_width) &&
427             EQFLD(pixel_height) &&
428             EQFLD(name)
429             );
430   }
431   bool operator<(const PRCPicture& c) const
432   {
433     COMPFLD(format)
434     COMPFLD(uncompressed_file_index)
435     COMPFLD(pixel_width)
436     COMPFLD(pixel_height)
437     COMPFLD(name)
438     return false;
439   }
440 };
441 PRCLIST(PRCPicture)
PRCMAP(PRCPicture)442 PRCMAP(PRCPicture)
443 
444 
445 class PRCTextureDefinition : public ContentPRCBase
446 {
447 public:
448   PRCTextureDefinition(std::string n="") :
449     ContentPRCBase(PRC_TYPE_GRAPH_TextureDefinition,n), picture_index(m1), texture_mapping_attribute(PRC_TEXTURE_MAPPING_DIFFUSE),
450     texture_mapping_attribute_intensity(1.0), texture_mapping_attribute_components(PRC_TEXTURE_MAPPING_COMPONENTS_RGBA),
451     texture_function(KEPRCTextureFunction_Modulate), texture_applying_mode(PRC_TEXTURE_APPLYING_MODE_NONE),
452     texture_wrapping_mode_S(KEPRCTextureWrappingMode_Unknown), texture_wrapping_mode_T(KEPRCTextureWrappingMode_Unknown) // ,
453     // texture_transformation(false), texture_flip_S(false), texture_flip_T(false),
454     // behaviour(PRC_TRANSFORMATION_Identity), scale(1.0,1.0), uniform_scale(1.0)
455     {}
456   void serializeTextureDefinition(PRCbitStream&);
457   uint32_t picture_index;
458   uint32_t texture_mapping_attribute;
459   double texture_mapping_attribute_intensity;
460   uint8_t texture_mapping_attribute_components;
461   EPRCTextureFunction texture_function;
462   uint8_t texture_applying_mode;
463   EPRCTextureWrappingMode texture_wrapping_mode_S;
464   EPRCTextureWrappingMode texture_wrapping_mode_T;
465   // bool texture_transformation;
466   // bool texture_flip_S;
467   // bool texture_flip_T;
468   // uint8_t behaviour;
469   // PRCVector2d origin;
470   // PRCVector2d X;
471   // PRCVector2d Y;
472   // PRCVector2d scale;
473   // double uniform_scale;
474   // double X_homegeneous_coord;
475   // double Y_homegeneous_coord;
476   // double origin_homegeneous_coord;
477 
478   bool operator==(const PRCTextureDefinition& c) const
479   {
480     return (EQFLD(picture_index) &&
481             EQFLD(texture_mapping_attribute) &&
482             EQFLD(texture_mapping_attribute_intensity) &&
483             EQFLD(texture_mapping_attribute_components) &&
484             EQFLD(texture_function) &&
485             EQFLD(texture_applying_mode) &&
486             EQFLD(texture_wrapping_mode_S) &&
487             EQFLD(texture_wrapping_mode_T) &&
488             EQFLD(name)
489             );
490   }
491   bool operator<(const PRCTextureDefinition& c) const
492   {
493     COMPFLD(picture_index)
494     COMPFLD(texture_mapping_attribute)
495     COMPFLD(texture_mapping_attribute_intensity)
496     COMPFLD(texture_mapping_attribute_components)
497     COMPFLD(texture_function)
498     COMPFLD(texture_applying_mode)
499     COMPFLD(texture_wrapping_mode_S)
500     COMPFLD(texture_wrapping_mode_T)
501     COMPFLD(name)
502     return false;
503   }
504 
505 };
506 PRCLIST(PRCTextureDefinition)
PRCMAP(PRCTextureDefinition)507 PRCMAP(PRCTextureDefinition)
508 
509 class PRCMaterial
510 {
511 public:
512   virtual ~PRCMaterial() {}
513   virtual void serializeMaterial(PRCbitStream&) = 0;
514 };
PRCLIST(PRCMaterial)515 PRCLIST(PRCMaterial)
516 
517 class PRCMaterialGeneric : public ContentPRCBase, public PRCMaterial
518 {
519 public:
520   PRCMaterialGeneric(std::string n="") :
521     ContentPRCBase(PRC_TYPE_GRAPH_Material,n),
522     ambient(m1), diffuse(m1), emissive(m1), specular(m1),
523     shininess(0.0),
524     ambient_alpha(1.0), diffuse_alpha(1.0), emissive_alpha(1.0), specular_alpha(1.0)
525     {}
526   void serializeMaterialGeneric(PRCbitStream&);
527   void serializeMaterial(PRCbitStream &pbs) { serializeMaterialGeneric(pbs); }
528   uint32_t ambient;
529   uint32_t diffuse;
530   uint32_t emissive;
531   uint32_t specular;
532   double shininess;
533   double ambient_alpha;
534   double diffuse_alpha;
535   double emissive_alpha;
536   double specular_alpha;
537 
538   bool operator==(const PRCMaterialGeneric& c) const
539   {
540     return (EQFLD(ambient) &&
541             EQFLD(diffuse) &&
542             EQFLD(emissive) &&
543             EQFLD(specular) &&
544             EQFLD(shininess) &&
545             EQFLD(ambient_alpha) &&
546             EQFLD(diffuse_alpha) &&
547             EQFLD(emissive_alpha) &&
548             EQFLD(specular_alpha) &&
549             EQFLD(name)
550             );
551   }
552   bool operator<(const PRCMaterialGeneric& c) const
553   {
554     COMPFLD(ambient)
555     COMPFLD(diffuse)
556     COMPFLD(emissive)
557     COMPFLD(specular)
558     COMPFLD(shininess)
559     COMPFLD(ambient_alpha)
560     COMPFLD(diffuse_alpha)
561     COMPFLD(emissive_alpha)
562     COMPFLD(specular_alpha)
563     COMPFLD(name)
564     return false;
565   }
566 };
PRCMAP(PRCMaterialGeneric)567 PRCMAP(PRCMaterialGeneric)
568 
569 class PRCTextureApplication : public ContentPRCBase, public PRCMaterial
570 {
571 public:
572   PRCTextureApplication(std::string n="") :
573     ContentPRCBase(PRC_TYPE_GRAPH_TextureApplication,n),
574     material_generic_index(m1), texture_definition_index(m1),
575     next_texture_index(m1), UV_coordinates_index(0)
576     {}
577   void serializeTextureApplication(PRCbitStream&);
578   void serializeMaterial(PRCbitStream &pbs) { serializeTextureApplication(pbs); }
579   uint32_t material_generic_index;
580   uint32_t texture_definition_index;
581   uint32_t next_texture_index;
582   uint32_t UV_coordinates_index;
583 
584   bool operator==(const PRCTextureApplication& c) const
585   {
586     return (EQFLD(material_generic_index) &&
587             EQFLD(texture_definition_index) &&
588             EQFLD(next_texture_index) &&
589             EQFLD(UV_coordinates_index) &&
590             EQFLD(name)
591             );
592   }
593   bool operator<(const PRCTextureApplication& c) const
594   {
595     COMPFLD(material_generic_index)
596     COMPFLD(texture_definition_index)
597     COMPFLD(next_texture_index)
598     COMPFLD(UV_coordinates_index)
599     COMPFLD(name)
600     return false;
601   }
602 };
PRCMAP(PRCTextureApplication)603 PRCMAP(PRCTextureApplication)
604 
605 class PRCLinePattern : public ContentPRCBase
606 {
607 public:
608   PRCLinePattern(std::string n="") :
609   ContentPRCBase(PRC_TYPE_GRAPH_LinePattern,n),
610   phase(0), is_real_length(false) {}
611   void serializeLinePattern(PRCbitStream&);
612   std::vector<double> lengths;
613   double phase;
614   bool is_real_length;
615 };
616 typedef std::deque <PRCLinePattern*>  PRCLinePatternList;
617 
618 class PRCStyle : public ContentPRCBase
619 {
620 public:
621   PRCStyle(std::string n="") :
ContentPRCBase(PRC_TYPE_GRAPH_Style,n)622     ContentPRCBase(PRC_TYPE_GRAPH_Style,n), line_width(0.0), is_vpicture(false), line_pattern_vpicture_index(m1),
623     is_material(false), color_material_index(m1), is_transparency_defined(false), transparency(255), additional(0)
624     {}
625   void serializeCategory1LineStyle(PRCbitStream&);
626   double line_width;
627   bool is_vpicture;
628   uint32_t line_pattern_vpicture_index;
629   bool is_material;
630   uint32_t color_material_index;
631   bool is_transparency_defined;
632   uint8_t transparency;
633   uint8_t additional;
634   bool operator==(const PRCStyle& c) const
635   {
636     return (EQFLD(line_width) &&
637             EQFLD(is_vpicture) &&
638             EQFLD(line_pattern_vpicture_index) &&
639             EQFLD(is_material) &&
640             EQFLD(color_material_index) &&
641             EQFLD(is_transparency_defined) &&
642             EQFLD(transparency) &&
643             EQFLD(additional) &&
644             EQFLD(name)
645             );
646   }
647   bool operator<(const PRCStyle& c) const
648   {
649     COMPFLD(line_width)
650     COMPFLD(is_vpicture)
651     COMPFLD(line_pattern_vpicture_index)
652     COMPFLD(is_material)
653     COMPFLD(color_material_index)
654     COMPFLD(is_transparency_defined)
655     COMPFLD(transparency)
656     COMPFLD(additional)
657     COMPFLD(name)
658     return false;
659   }
660 
661 };
662 PRCLIST(PRCStyle)
PRCMAP(PRCStyle)663 PRCMAP(PRCStyle)
664 
665 #undef EQFLD
666 #undef COMPFLD
667 #undef PRCMAP
668 
669 
670 class PRCTessFace
671 {
672 public:
673   PRCTessFace() :
674   start_wire(0), used_entities_flag(0),
675   start_triangulated(0), number_of_texture_coordinate_indexes(0),
676   is_rgba(false), behaviour(PRC_GRAPHICS_Show)
677   {}
678   void serializeTessFace(PRCbitStream&);
679   std::vector<uint32_t> line_attributes;
680   uint32_t start_wire;			// specifing bounding wire seems not to work as of Acrobat/Reader 9.2
681   std::vector<uint32_t> sizes_wire;	// specifing bounding wire seems not to work as of Acrobat/Reader 9.2
682   uint32_t used_entities_flag;
683   uint32_t start_triangulated;
684   std::vector<uint32_t> sizes_triangulated;
685   uint32_t number_of_texture_coordinate_indexes;
686   bool is_rgba;
687   std::vector<uint8_t> rgba_vertices;
688   uint32_t behaviour;
689 };
690 typedef std::deque <PRCTessFace*>  PRCTessFaceList;
691 
692 class PRCContentBaseTessData
693 {
694 public:
PRCContentBaseTessData()695   PRCContentBaseTessData() :
696   is_calculated(false) {}
697   void serializeContentBaseTessData(PRCbitStream&);
698   bool is_calculated;
699   std::vector<double> coordinates;
700 };
701 
702 class PRCTess : public PRCContentBaseTessData
703 {
704 public:
~PRCTess()705   virtual ~PRCTess() {}
706   virtual void serializeBaseTessData(PRCbitStream &pbs) = 0;
707 };
708 typedef std::deque <PRCTess*>  PRCTessList;
709 
710 class PRC3DTess : public PRCTess
711 {
712 public:
PRC3DTess()713   PRC3DTess() :
714   has_faces(false), has_loops(false),
715   crease_angle(25.8419)  // arccos(0.9), default found in Acrobat output
716   {}
~PRC3DTess()717   ~PRC3DTess() { for(PRCTessFaceList::iterator it=face_tessellation.begin(); it!=face_tessellation.end(); ++it) delete *it; }
718   void serialize3DTess(PRCbitStream&);
serializeBaseTessData(PRCbitStream & pbs)719   void serializeBaseTessData(PRCbitStream &pbs) { serialize3DTess(pbs); }
720   void addTessFace(PRCTessFace*& pTessFace);
721 
722   bool has_faces;
723   bool has_loops;
724   double crease_angle;
725   std::vector<double> normal_coordinate;
726   std::vector<uint32_t> wire_index;		// specifing bounding wire seems not to work as of Acrobat/Reader 9.2
727   std::vector<uint32_t> triangulated_index;
728   PRCTessFaceList face_tessellation;
729   std::vector<double> texture_coordinate;
730 };
731 
732 class PRC3DWireTess : public PRCTess
733 {
734 public:
PRC3DWireTess()735   PRC3DWireTess() :
736   is_rgba(false), is_segment_color(false) {}
737   void serialize3DWireTess(PRCbitStream&);
serializeBaseTessData(PRCbitStream & pbs)738   void serializeBaseTessData(PRCbitStream &pbs) { serialize3DWireTess(pbs); }
739 
740   bool is_rgba;
741   bool is_segment_color;
742   std::vector<uint32_t> wire_indexes;
743   std::vector<uint8_t> rgba_vertices;
744 };
745 
746 class PRCMarkupTess : public PRCTess
747 {
748 public:
PRCMarkupTess()749   PRCMarkupTess() :
750   behaviour(0)
751   {}
752   void serializeMarkupTess(PRCbitStream&);
serializeBaseTessData(PRCbitStream & pbs)753   void serializeBaseTessData(PRCbitStream &pbs) { serializeMarkupTess(pbs); }
754 
755   std::vector<uint32_t> codes;
756   std::vector<std::string> texts;
757   std::string label;
758   uint8_t behaviour;
759 };
760 
761 class PRCGraphics
762 {
763 public:
PRCGraphics()764   PRCGraphics() : layer_index(m1), index_of_line_style(m1), behaviour_bit_field(PRC_GRAPHICS_Show) {}
765   void serializeGraphics(PRCbitStream&);
766   void serializeGraphicsForced(PRCbitStream&);
has_graphics()767   bool has_graphics() { return (index_of_line_style!=m1 || layer_index!=m1 || behaviour_bit_field!=PRC_GRAPHICS_Show) ; }
768   uint32_t layer_index;
769   uint32_t index_of_line_style;
770   uint16_t behaviour_bit_field;
771 };
772 typedef std::deque <PRCGraphics*>  PRCGraphicsList;
773 
774 void writeGraphics(PRCbitStream&,const PRCGraphics&,bool=false);
775 
776 class PRCMarkup: public PRCGraphics, public ContentPRCBase
777 {
778 public:
779   PRCMarkup(std::string n="") :
ContentPRCBase(PRC_TYPE_MKP_Markup,n)780     ContentPRCBase(PRC_TYPE_MKP_Markup,n),
781     type(KEPRCMarkupType_Unknown), sub_type(KEPRCMarkupSubType_Unknown), index_tessellation(m1) {}
782   void serializeMarkup(PRCbitStream&);
783   EPRCMarkupType type;
784   EPRCMarkupSubType sub_type;
785 // vector<PRCReferenceUniqueIdentifier> linked_items;
786 // vector<PRCReferenceUniqueIdentifier> leaders;
787   uint32_t index_tessellation;
788 };
789 typedef std::deque <PRCMarkup*>  PRCMarkupList;
790 
791 class PRCAnnotationItem: public PRCGraphics, public ContentPRCBase
792 {
793 public:
794   PRCAnnotationItem(std::string n="") :
ContentPRCBase(PRC_TYPE_MKP_AnnotationItem,n)795     ContentPRCBase(PRC_TYPE_MKP_AnnotationItem,n) {}
796   void serializeAnnotationItem(PRCbitStream&);
serializeAnnotationEntity(PRCbitStream & pbs)797   void serializeAnnotationEntity(PRCbitStream &pbs) { serializeAnnotationItem(pbs); }
798   PRCReferenceUniqueIdentifier markup;
799 };
800 typedef std::deque <PRCAnnotationItem*>  PRCAnnotationItemList;
801 
802 class PRCRepresentationItemContent: public PRCGraphics, public ContentPRCBase
803 {
804 public:
805   PRCRepresentationItemContent(uint32_t t, std::string n="") :
ContentPRCBase(t,n)806     ContentPRCBase(t,n),
807     index_local_coordinate_system(m1), index_tessellation(m1) {}
808   void serializeRepresentationItemContent(PRCbitStream&);
809   uint32_t index_local_coordinate_system;
810   uint32_t index_tessellation;
811 };
812 
813 class PRCRepresentationItem : public PRCRepresentationItemContent
814 {
815 public:
816   PRCRepresentationItem(uint32_t t, std::string n="") :
PRCRepresentationItemContent(t,n)817     PRCRepresentationItemContent(t,n) {}
~PRCRepresentationItem()818   virtual ~PRCRepresentationItem() {}
819   virtual void serializeRepresentationItem(PRCbitStream &pbs) = 0;
820 };
821 typedef std::deque <PRCRepresentationItem*>  PRCRepresentationItemList;
822 
823 class PRCBrepModel : public PRCRepresentationItem
824 {
825 public:
826   PRCBrepModel(std::string n="") :
PRCRepresentationItem(PRC_TYPE_RI_BrepModel,n)827     PRCRepresentationItem(PRC_TYPE_RI_BrepModel,n), has_brep_data(true), context_id(m1), body_id(m1), is_closed(false) {}
828   void serializeBrepModel(PRCbitStream&);
serializeRepresentationItem(PRCbitStream & pbs)829   void serializeRepresentationItem(PRCbitStream &pbs) { serializeBrepModel(pbs); }
830   bool has_brep_data;
831   uint32_t context_id;
832   uint32_t body_id;
833   bool is_closed;
834 };
835 
836 class PRCPolyBrepModel : public PRCRepresentationItem
837 {
838 public:
839   PRCPolyBrepModel(std::string n="") :
PRCRepresentationItem(PRC_TYPE_RI_PolyBrepModel,n)840     PRCRepresentationItem(PRC_TYPE_RI_PolyBrepModel,n), is_closed(false) {}
841   void serializePolyBrepModel(PRCbitStream&);
serializeRepresentationItem(PRCbitStream & pbs)842   void serializeRepresentationItem(PRCbitStream &pbs) { serializePolyBrepModel(pbs); }
843   bool is_closed;
844 };
845 
846 class PRCPointSet : public PRCRepresentationItem
847 {
848 public:
849   PRCPointSet(std::string n="") :
PRCRepresentationItem(PRC_TYPE_RI_PointSet,n)850     PRCRepresentationItem(PRC_TYPE_RI_PointSet,n) {}
851   void serializePointSet(PRCbitStream&);
serializeRepresentationItem(PRCbitStream & pbs)852   void serializeRepresentationItem(PRCbitStream &pbs) { serializePointSet(pbs); }
853   std::vector<PRCVector3d> point;
854 };
855 
856 class PRCWire : public PRCRepresentationItem
857 {
858 public:
859   PRCWire(std::string n="") :
PRCRepresentationItem(PRC_TYPE_RI_Curve,n)860     PRCRepresentationItem(PRC_TYPE_RI_Curve,n), has_wire_body(true), context_id(m1), body_id(m1) {}
861   void serializeWire(PRCbitStream&);
serializeRepresentationItem(PRCbitStream & pbs)862   void serializeRepresentationItem(PRCbitStream &pbs) { serializeWire(pbs); }
863   bool has_wire_body;
864   uint32_t context_id;
865   uint32_t body_id;
866 };
867 
868 class PRCPolyWire : public PRCRepresentationItem
869 {
870 public:
871   PRCPolyWire(std::string n="") :
PRCRepresentationItem(PRC_TYPE_RI_PolyWire,n)872     PRCRepresentationItem(PRC_TYPE_RI_PolyWire,n) {}
873   void serializePolyWire(PRCbitStream&);
serializeRepresentationItem(PRCbitStream & pbs)874   void serializeRepresentationItem(PRCbitStream &pbs) { serializePolyWire(pbs); }
875 };
876 
877 class PRCSet : public PRCRepresentationItem
878 {
879 public:
880   PRCSet(std::string n="") :
PRCRepresentationItem(PRC_TYPE_RI_Set,n)881     PRCRepresentationItem(PRC_TYPE_RI_Set,n) {}
~PRCSet()882   ~PRCSet() { for(PRCRepresentationItemList::iterator it=elements.begin(); it!=elements.end(); ++it) delete *it; }
883   void serializeSet(PRCbitStream&);
serializeRepresentationItem(PRCbitStream & pbs)884   void serializeRepresentationItem(PRCbitStream &pbs) { serializeSet(pbs); }
885   uint32_t addBrepModel(PRCBrepModel*& pBrepModel);
886   uint32_t addPolyBrepModel(PRCPolyBrepModel*& pPolyBrepModel);
887   uint32_t addPointSet(PRCPointSet*& pPointSet);
888   uint32_t addSet(PRCSet*& pSet);
889   uint32_t addWire(PRCWire*& pWire);
890   uint32_t addPolyWire(PRCPolyWire*& pPolyWire);
891   uint32_t addRepresentationItem(PRCRepresentationItem*& pRepresentationItem);
892   PRCRepresentationItemList elements;
893 };
894 
895 class PRCTransformation3d
896 {
897 public:
~PRCTransformation3d()898   virtual ~PRCTransformation3d() {}
899   virtual void serializeTransformation3d(PRCbitStream&) const =0;
900 };
901 typedef std::deque <PRCTransformation3d*> PRCTransformation3dList;
902 
903 class PRCGeneralTransformation3d : public PRCTransformation3d
904 {
905 public:
PRCGeneralTransformation3d()906   PRCGeneralTransformation3d()
907   {
908     setidentity();
909   }
PRCGeneralTransformation3d(const double t[])910   PRCGeneralTransformation3d(const double t[])
911   {
912     set(t);
913   }
914 
915   void serializeGeneralTransformation3d(PRCbitStream&) const;
serializeTransformation3d(PRCbitStream & pbs)916   void serializeTransformation3d(PRCbitStream& pbs)  const { serializeGeneralTransformation3d(pbs); }
917   double m_coef[16];
918   bool operator==(const PRCGeneralTransformation3d &t) const
919   {
920     for (size_t i=0;i<16;i++)
921         if(m_coef[i]!=t.m_coef[i])
922          return false;
923     return true;
924   }
925   bool operator<(const PRCGeneralTransformation3d &t) const
926   {
927     for (size_t i=0;i<16;i++)
928         if(m_coef[i]!=t.m_coef[i])
929         {
930           return (m_coef[i]<t.m_coef[i]);
931         }
932     return false;
933   }
set(const double t[])934   void set(const double t[])
935   {
936     if(t!=NULL)
937       for (size_t i=0;i<16;i++)
938           m_coef[i]=t[i];
939     else
940       setidentity();
941   }
set(const float t[])942   void set(const float t[])
943   {
944     if(t!=NULL)
945       for (size_t i=0;i<16;i++)
946         m_coef[i]=t[i];
947     else
948       setidentity();
949   }
setidentity()950   void setidentity()
951   {
952     m_coef[0]=1; m_coef[4]=0; m_coef[ 8]=0; m_coef[12]=0;
953     m_coef[1]=0; m_coef[5]=1; m_coef[ 9]=0; m_coef[13]=0;
954     m_coef[2]=0; m_coef[6]=0; m_coef[10]=1; m_coef[14]=0;
955     m_coef[3]=0; m_coef[7]=0; m_coef[11]=0; m_coef[15]=1;
956   }
isnotidtransform()957   bool isnotidtransform() const {
958     return(
959            m_coef[0]!=1 || m_coef[4]!=0 || m_coef[ 8]!=0 || m_coef[12]!=0 ||
960            m_coef[1]!=0 || m_coef[5]!=1 || m_coef[ 9]!=0 || m_coef[13]!=0 ||
961            m_coef[2]!=0 || m_coef[6]!=0 || m_coef[10]!=1 || m_coef[14]!=0 ||
962            m_coef[3]!=0 || m_coef[7]!=0 || m_coef[11]!=0 || m_coef[15]!=1 );
963   }
isidtransform()964   bool isidtransform() const {
965     return(
966            m_coef[0]==1 && m_coef[4]==0 && m_coef[ 8]==0 && m_coef[12]==0 &&
967            m_coef[1]==0 && m_coef[5]==1 && m_coef[ 9]==0 && m_coef[13]==0 &&
968            m_coef[2]==0 && m_coef[6]==0 && m_coef[10]==1 && m_coef[14]==0 &&
969            m_coef[3]==0 && m_coef[7]==0 && m_coef[11]==0 && m_coef[15]==1 );
970   }
M(size_t i,size_t j)971   double M(size_t i, size_t j) const {
972     return m_coef[i+j*4];
973   }
974 };
975 typedef std::deque <PRCGeneralTransformation3d> PRCGeneralTransformation3dList;
976 
977 class PRCCartesianTransformation3d : public PRCTransformation3d
978 {
979 public:
PRCCartesianTransformation3d()980   PRCCartesianTransformation3d() :
981     behaviour(PRC_TRANSFORMATION_Identity), origin(0.0,0.0,0.0), X(1.0,0.0,0.0), Y(0.0,1.0,0.0), Z(0.0,0.0,1.0),
982     scale(1.0,1.0,1.0), uniform_scale(1.0),
983     X_homogeneous_coord(0.0), Y_homogeneous_coord(0.0), Z_homogeneous_coord(0.0), origin_homogeneous_coord(1.0) {}
PRCCartesianTransformation3d(const double o[3],const double x[3],const double y[3],double sc)984   PRCCartesianTransformation3d(const double o[3], const double x[3], const double y[3], double sc) :
985     behaviour(PRC_TRANSFORMATION_Identity), origin(o,0.0,0.0,0.0), X(x,1.0,0.0,0.0), Y(y,0.0,1.0,0.0), Z(0.0,0.0,1.0),
986     scale(1.0,1.0,1.0), uniform_scale(sc),
987     X_homogeneous_coord(0.0), Y_homogeneous_coord(0.0), Z_homogeneous_coord(0.0), origin_homogeneous_coord(1.0)
988     {
989       if(origin!=PRCVector3d(0.0,0.0,0.0))
990         behaviour = behaviour | PRC_TRANSFORMATION_Translate;
991       if(X!=PRCVector3d(1.0,0.0,0.0) || Y!=PRCVector3d(0.0,1.0,0.0))
992         behaviour = behaviour | PRC_TRANSFORMATION_Rotate;
993       if(uniform_scale!=1)
994         behaviour = behaviour | PRC_TRANSFORMATION_Scale;
995     }
996   void serializeCartesianTransformation3d(PRCbitStream& pbs) const;
serializeTransformation3d(PRCbitStream & pbs)997   void serializeTransformation3d(PRCbitStream& pbs) const { serializeCartesianTransformation3d(pbs); }
998   uint8_t behaviour;
999   PRCVector3d origin;
1000   PRCVector3d X;
1001   PRCVector3d Y;
1002   PRCVector3d Z;
1003   PRCVector3d scale;
1004   double uniform_scale;
1005   double X_homogeneous_coord;
1006   double Y_homogeneous_coord;
1007   double Z_homogeneous_coord;
1008   double origin_homogeneous_coord;
1009   bool operator==(const PRCCartesianTransformation3d &t) const
1010   {
1011     return behaviour==t.behaviour && origin==t.origin && X==t.X && Y==t.Y && Z==t.Z && scale==t.scale && uniform_scale==t.uniform_scale &&
1012            X_homogeneous_coord==t.X_homogeneous_coord && Y_homogeneous_coord==t.Y_homogeneous_coord &&
1013            Z_homogeneous_coord==t.Z_homogeneous_coord && origin_homogeneous_coord==t.origin_homogeneous_coord;
1014   }
1015 };
1016 
1017 class PRCTransformation
1018 {
1019 public:
PRCTransformation()1020   PRCTransformation() :
1021     has_transformation(false), geometry_is_2D(false), behaviour(PRC_TRANSFORMATION_Identity),
1022     origin(0.0,0.0,0.0), x_axis(1.0,0.0,0.0), y_axis(0.0,1.0,0.0), scale(1) {}
1023   void serializeTransformation(PRCbitStream&);
1024   bool has_transformation;
1025   bool geometry_is_2D;
1026   uint8_t behaviour;
1027   PRCVector3d origin;
1028   PRCVector3d x_axis;
1029   PRCVector3d y_axis;
1030   double scale;
1031 };
1032 
1033 class PRCCoordinateSystem : public PRCRepresentationItem
1034 {
1035 public:
1036   PRCCoordinateSystem(std::string n="") :
PRCRepresentationItem(PRC_TYPE_RI_CoordinateSystem,n)1037   PRCRepresentationItem(PRC_TYPE_RI_CoordinateSystem,n), axis_set(NULL) {}
~PRCCoordinateSystem()1038   ~PRCCoordinateSystem() { delete axis_set; }
1039   void serializeCoordinateSystem(PRCbitStream&);
serializeRepresentationItem(PRCbitStream & pbs)1040   void serializeRepresentationItem(PRCbitStream &pbs) { serializeCoordinateSystem(pbs); }
setAxisSet(PRCGeneralTransformation3d * & transform)1041   void setAxisSet(PRCGeneralTransformation3d*& transform) { axis_set = transform; transform = NULL; }
setAxisSet(PRCCartesianTransformation3d * & transform)1042   void setAxisSet(PRCCartesianTransformation3d*& transform) { axis_set = transform; transform = NULL; }
1043   PRCTransformation3d *axis_set;
1044   bool operator==(const PRCCoordinateSystem &t) const
1045   {
1046     if(index_local_coordinate_system!=t.index_local_coordinate_system)
1047       return false;
1048     PRCGeneralTransformation3d*       axis_set_general = dynamic_cast<PRCGeneralTransformation3d*>(axis_set);
1049     PRCGeneralTransformation3d*     t_axis_set_general = dynamic_cast<PRCGeneralTransformation3d*>(t.axis_set);
1050     PRCCartesianTransformation3d*   axis_set_cartesian = dynamic_cast<PRCCartesianTransformation3d*>(axis_set);
1051     PRCCartesianTransformation3d* t_axis_set_cartesian = dynamic_cast<PRCCartesianTransformation3d*>(t.axis_set);
1052     if(axis_set_general!=NULL)
1053       return (t_axis_set_general!=NULL?(*axis_set_general==*t_axis_set_general):false);
1054     if(axis_set_cartesian!=NULL)
1055       return (t_axis_set_cartesian!=NULL?(*axis_set_cartesian==*t_axis_set_cartesian):false);
1056     return false;
1057   }
1058 };
1059 typedef std::deque <PRCCoordinateSystem*>  PRCCoordinateSystemList;
1060 
1061 struct PRCFontKey
1062 {
1063   uint32_t font_size;
1064   uint8_t  attributes;
1065 };
1066 
1067 class PRCFontKeysSameFont
1068 {
1069 public:
1070   void serializeFontKeysSameFont(PRCbitStream&);
1071   std::string font_name;
1072   uint32_t char_set;
1073   std::vector<PRCFontKey> font_keys;
1074 
1075 };
1076 
1077 // Topology
1078 class PRCBaseGeometry : public PRCAttributes
1079 {
1080 public:
PRCBaseGeometry()1081   PRCBaseGeometry() :
1082     base_information(false), identifier(0) {}
1083   PRCBaseGeometry(std::string n, uint32_t id = 0) :
base_information(true)1084     base_information(true),name(n),identifier(id) {}
1085   void serializeBaseGeometry(PRCbitStream&);
1086   bool base_information;
1087   std::string name;
1088   uint32_t identifier;
1089 };
1090 
1091 class PRCBoundingBox
1092 {
1093 public:
PRCBoundingBox()1094   PRCBoundingBox()	{min=PRCVector3d(0.0,0.0,0.0); max=PRCVector3d(0.0,0.0,0.0);}
PRCBoundingBox(const PRCVector3d & m,const PRCVector3d & M)1095   PRCBoundingBox(const PRCVector3d &m, const PRCVector3d& M) {min=PRCVector3d(m); max=PRCVector3d(M);}
1096   void serializeBoundingBox(PRCbitStream &pbs);
1097   PRCVector3d min;
1098   PRCVector3d max;
1099 };
1100 
1101 class PRCDomain
1102 {
1103 public:
1104   void serializeDomain(PRCbitStream &pbs);
1105   PRCVector2d min;
1106   PRCVector2d max;
1107 };
1108 
1109 class PRCInterval
1110 {
1111 public:
PRCInterval()1112   PRCInterval() { min=max=0;}
PRCInterval(double m,double M)1113   PRCInterval(double m, double M) {min=m;max=M;}
1114   void serializeInterval(PRCbitStream &pbs);
1115   double min;
1116   double max;
1117 };
1118 
1119 class PRCParameterization
1120 {
1121 public:
PRCParameterization()1122   PRCParameterization() : parameterization_coeff_a(1), parameterization_coeff_b(0) {}
PRCParameterization(double min,double max)1123   PRCParameterization(double min, double max) : interval(min, max), parameterization_coeff_a(1), parameterization_coeff_b(0) {}
1124   void serializeParameterization(PRCbitStream &pbs);
1125   PRCInterval interval;
1126   double parameterization_coeff_a;
1127   double parameterization_coeff_b;
1128 };
1129 
1130 class PRCUVParameterization
1131 {
1132 public:
PRCUVParameterization()1133   PRCUVParameterization() : swap_uv(false),
1134     parameterization_on_u_coeff_a(1), parameterization_on_v_coeff_a(1),
1135     parameterization_on_u_coeff_b(0), parameterization_on_v_coeff_b(0) {}
1136   void serializeUVParameterization(PRCbitStream &pbs);
1137   bool swap_uv;
1138   PRCDomain uv_domain;
1139   double parameterization_on_u_coeff_a;
1140   double parameterization_on_v_coeff_a;
1141   double parameterization_on_u_coeff_b;
1142   double parameterization_on_v_coeff_b;
1143 };
1144 
1145 class PRCControlPoint
1146 {
1147 public:
PRCControlPoint()1148   PRCControlPoint() :
1149    x(0), y(0), z(0), w(1) {}
1150   PRCControlPoint(double X, double Y, double Z=0, double W=1) :
x(X)1151    x(X), y(Y), z(Z), w(W) {}
PRCControlPoint(const PRCVector3d & v)1152   PRCControlPoint(const PRCVector3d &v) :
1153    x(v.x), y(v.y), z(v.z), w(1) {}
1154   void Set(double fx, double fy, double fz, double fw=1)
1155    { x = fx; y = fy; z = fz; w = fw; }
1156   double x;
1157   double y;
1158   double z;
1159   double w;
1160 };
1161 
1162 class PRCContentSurface: public PRCBaseGeometry
1163 {
1164 public:
PRCContentSurface()1165   PRCContentSurface() :
1166     PRCBaseGeometry(), extend_info(KEPRCExtendTypeNone) {}
PRCContentSurface(std::string n)1167   PRCContentSurface(std::string n) :
1168     PRCBaseGeometry(n,makeCADID()),extend_info(KEPRCExtendTypeNone) {}
1169   void serializeContentSurface(PRCbitStream&);
1170   EPRCExtendType extend_info;
1171 };
1172 
1173 class PRCSurface : public PRCContentSurface
1174 {
1175 public:
PRCSurface()1176   PRCSurface() :
1177     PRCContentSurface() {}
PRCSurface(std::string n)1178   PRCSurface(std::string n) :
1179     PRCContentSurface(n) {}
~PRCSurface()1180   virtual ~PRCSurface() {}
1181   virtual void  serializeSurface(PRCbitStream &pbs) = 0;
1182 };
1183 
1184 class PRCNURBSSurface : public PRCSurface
1185 {
1186 public:
PRCNURBSSurface()1187   PRCNURBSSurface() :
1188     PRCSurface(), knot_type(KEPRCKnotTypeUnspecified), surface_form(KEPRCBSplineSurfaceFormUnspecified) {}
PRCNURBSSurface(std::string n)1189   PRCNURBSSurface(std::string n) :
1190     PRCSurface(n), knot_type(KEPRCKnotTypeUnspecified), surface_form(KEPRCBSplineSurfaceFormUnspecified) {}
1191   void  serializeNURBSSurface(PRCbitStream &pbs);
serializeSurface(PRCbitStream & pbs)1192   void  serializeSurface(PRCbitStream &pbs) { serializeNURBSSurface(pbs); }
1193   bool is_rational;
1194   uint32_t degree_in_u;
1195   uint32_t degree_in_v;
1196   std::vector<PRCControlPoint> control_point;
1197   std::vector<double> knot_u;
1198   std::vector<double> knot_v;
1199   const EPRCKnotType knot_type;
1200   const EPRCBSplineSurfaceForm surface_form;
1201 };
1202 
1203 class PRCContentCurve: public PRCBaseGeometry
1204 {
1205 public:
PRCContentCurve()1206   PRCContentCurve() :
1207     PRCBaseGeometry(), extend_info(KEPRCExtendTypeNone), is_3d(true) {}
PRCContentCurve(std::string n)1208   PRCContentCurve(std::string n) :
1209     PRCBaseGeometry(n,makeCADID()),extend_info(KEPRCExtendTypeNone), is_3d(true) {}
1210   void serializeContentCurve(PRCbitStream&);
1211   EPRCExtendType extend_info;
1212   bool is_3d;
1213 };
1214 
1215 class PRCCurve : public PRCContentCurve
1216 {
1217 public:
PRCCurve()1218   PRCCurve() :
1219     PRCContentCurve() {}
PRCCurve(std::string n)1220   PRCCurve(std::string n) :
1221     PRCContentCurve(n) {}
~PRCCurve()1222   virtual ~PRCCurve() {}
1223   virtual void  serializeCurve(PRCbitStream &pbs) = 0;
1224 };
1225 typedef std::deque <PRCCurve*>  PRCCurveList;
1226 
1227 class PRCNURBSCurve : public PRCCurve
1228 {
1229 public:
PRCNURBSCurve()1230   PRCNURBSCurve() :
1231     PRCCurve(), knot_type(KEPRCKnotTypeUnspecified), curve_form(KEPRCBSplineCurveFormUnspecified) {}
PRCNURBSCurve(std::string n)1232   PRCNURBSCurve(std::string n) :
1233     PRCCurve(n), knot_type(KEPRCKnotTypeUnspecified), curve_form(KEPRCBSplineCurveFormUnspecified) {}
1234   void  serializeNURBSCurve(PRCbitStream &pbs);
serializeCurve(PRCbitStream & pbs)1235   void  serializeCurve(PRCbitStream &pbs) { serializeNURBSCurve(pbs); }
1236   bool is_rational;
1237   uint32_t degree;
1238   std::vector<PRCControlPoint> control_point;
1239   std::vector<double> knot;
1240   const EPRCKnotType knot_type;
1241   const EPRCBSplineCurveForm curve_form;
1242 };
1243 
1244 class PRCPolyLine : public PRCCurve, public PRCTransformation, public PRCParameterization
1245 {
1246 public:
PRCPolyLine()1247   PRCPolyLine() :
1248     PRCCurve() {}
PRCPolyLine(std::string n)1249   PRCPolyLine(std::string n) :
1250     PRCCurve(n) {}
1251   void  serializePolyLine(PRCbitStream &pbs);
serializeCurve(PRCbitStream & pbs)1252   void  serializeCurve(PRCbitStream &pbs) { serializePolyLine(pbs); }
1253   std::vector<PRCVector3d> point;
1254 };
1255 
1256 class PRCCircle : public PRCCurve, public PRCTransformation, public PRCParameterization
1257 {
1258 public:
PRCCircle()1259   PRCCircle() :
1260     PRCCurve(), PRCParameterization(0,2*pi) {}
PRCCircle(std::string n)1261   PRCCircle(std::string n) :
1262     PRCCurve(n), PRCParameterization(0,2*pi) {}
1263   void  serializeCircle(PRCbitStream &pbs);
serializeCurve(PRCbitStream & pbs)1264   void  serializeCurve(PRCbitStream &pbs) { serializeCircle(pbs); }
1265   double radius;
1266 };
1267 
1268 class PRCComposite : public PRCCurve, public PRCTransformation, public PRCParameterization
1269 {
1270 public:
PRCComposite()1271   PRCComposite() :
1272     PRCCurve() {}
PRCComposite(std::string n)1273   PRCComposite(std::string n) :
1274     PRCCurve(n) {}
1275   void  serializeComposite(PRCbitStream &pbs);
serializeCurve(PRCbitStream & pbs)1276   void  serializeCurve(PRCbitStream &pbs) { serializeComposite(pbs); }
1277   PRCCurveList base_curve;
1278   std::vector<bool> base_sense;
1279   bool is_closed;
1280 };
1281 
1282 class PRCBlend01 : public PRCSurface, public PRCTransformation, public PRCUVParameterization
1283 {
1284 public:
PRCBlend01()1285   PRCBlend01() :
1286     PRCSurface(), center_curve(NULL), origin_curve(NULL), tangent_curve(NULL) {}
PRCBlend01(std::string n)1287   PRCBlend01(std::string n) :
1288     PRCSurface(n), center_curve(NULL), origin_curve(NULL), tangent_curve(NULL) {}
~PRCBlend01()1289   ~PRCBlend01() { delete center_curve; delete origin_curve; delete tangent_curve; }
1290   void  serializeBlend01(PRCbitStream &pbs);
serializeSurface(PRCbitStream & pbs)1291   void  serializeSurface(PRCbitStream &pbs) { serializeBlend01(pbs); }
1292 // void  setCenterCurve (PRCCurve*& curve) { center_curve  = curve; curve = NULL; }
1293 // void  setOriginCurve (PRCCurve*& curve) { origin_curve  = curve; curve = NULL; }
1294 // void  setTangentCurve(PRCCurve*& curve) { tangent_curve = curve; curve = NULL; }
1295   PRCCurve* center_curve;
1296   PRCCurve* origin_curve;
1297   PRCCurve* tangent_curve;
1298 };
1299 
1300 class PRCRuled : public PRCSurface, public PRCTransformation, public PRCUVParameterization
1301 {
1302 public:
PRCRuled()1303   PRCRuled() :
1304     PRCSurface(), first_curve(NULL), second_curve(NULL) {}
PRCRuled(std::string n)1305   PRCRuled(std::string n) :
1306     PRCSurface(n) {}
~PRCRuled()1307   ~PRCRuled() { delete first_curve; delete second_curve; }
1308   void  serializeRuled(PRCbitStream &pbs);
serializeSurface(PRCbitStream & pbs)1309   void  serializeSurface(PRCbitStream &pbs) { serializeRuled(pbs); }
1310 // void  setFirstCurve(PRCCurve*&  curve) { first_curve  = curve; curve = NULL; }
1311 // void  setSecondCurve(PRCCurve*& curve) { second_curve = curve; curve = NULL; }
1312   PRCCurve* first_curve;
1313   PRCCurve* second_curve;
1314 };
1315 
1316 class PRCSphere : public PRCSurface, public PRCTransformation, public PRCUVParameterization
1317 {
1318 public:
PRCSphere()1319   PRCSphere() :
1320     PRCSurface() {}
PRCSphere(std::string n)1321   PRCSphere(std::string n) :
1322     PRCSurface(n) {}
1323   void  serializeSphere(PRCbitStream &pbs);
serializeSurface(PRCbitStream & pbs)1324   void  serializeSurface(PRCbitStream &pbs) { serializeSphere(pbs); }
1325   double radius;
1326 };
1327 
1328 class PRCCone : public PRCSurface, public PRCTransformation, public PRCUVParameterization
1329 {
1330 public:
PRCCone()1331   PRCCone() :
1332     PRCSurface() {}
PRCCone(std::string n)1333   PRCCone(std::string n) :
1334     PRCSurface(n) {}
1335   void  serializeCone(PRCbitStream &pbs);
serializeSurface(PRCbitStream & pbs)1336   void  serializeSurface(PRCbitStream &pbs) { serializeCone(pbs); }
1337   double bottom_radius;
1338   double semi_angle;
1339 };
1340 
1341 class PRCCylinder : public PRCSurface, public PRCTransformation, public PRCUVParameterization
1342 {
1343 public:
PRCCylinder()1344   PRCCylinder() :
1345     PRCSurface() {}
PRCCylinder(std::string n)1346   PRCCylinder(std::string n) :
1347     PRCSurface(n) {}
1348   void  serializeCylinder(PRCbitStream &pbs);
serializeSurface(PRCbitStream & pbs)1349   void  serializeSurface(PRCbitStream &pbs) { serializeCylinder(pbs); }
1350   double radius;
1351 };
1352 
1353 class PRCTorus : public PRCSurface, public PRCTransformation, public PRCUVParameterization
1354 {
1355 public:
PRCTorus()1356   PRCTorus() :
1357     PRCSurface() {}
PRCTorus(std::string n)1358   PRCTorus(std::string n) :
1359     PRCSurface(n) {}
1360   void  serializeTorus(PRCbitStream &pbs);
serializeSurface(PRCbitStream & pbs)1361   void  serializeSurface(PRCbitStream &pbs) { serializeTorus(pbs); }
1362   double major_radius;
1363   double minor_radius;
1364 };
1365 
1366 class PRCBaseTopology : public PRCAttributes
1367 {
1368 public:
PRCBaseTopology()1369   PRCBaseTopology() :
1370     base_information(false),identifier(0) {}
1371   PRCBaseTopology(std::string n, uint32_t id = 0) :
base_information(true)1372     base_information(true),name(n),identifier(id) {}
1373   void serializeBaseTopology(PRCbitStream&);
1374   bool base_information;
1375   std::string name;
1376   uint32_t identifier;
1377 };
1378 
1379 class PRCTopoItem
1380 {
1381 public:
~PRCTopoItem()1382   virtual ~PRCTopoItem() {}
1383   virtual void serializeTopoItem(PRCbitStream&)=0;
1384 };
1385 
1386 class PRCContentBody: public PRCBaseTopology
1387 {
1388 public:
PRCContentBody()1389   PRCContentBody() :
1390     PRCBaseTopology(), behavior(0) {}
PRCContentBody(std::string n)1391   PRCContentBody(std::string n) :
1392     PRCBaseTopology(n,makeCADID()), behavior(0) {}
1393   void serializeContentBody(PRCbitStream&);
1394   uint8_t behavior;
1395 };
1396 
1397 class PRCBody : public PRCContentBody, public PRCTopoItem
1398 {
1399 public:
PRCBody()1400   PRCBody() :
1401     PRCContentBody(), topo_item_type(PRC_TYPE_ROOT) {}
PRCBody(uint32_t tit)1402   PRCBody(uint32_t tit) :
1403     PRCContentBody(), topo_item_type(tit) {}
PRCBody(uint32_t tit,std::string n)1404   PRCBody(uint32_t tit, std::string n) :
1405     PRCContentBody(n), topo_item_type(tit) {}
~PRCBody()1406   virtual ~PRCBody() {}
1407   virtual void serializeBody(PRCbitStream &pbs) = 0;
serializeTopoItem(PRCbitStream & pbs)1408   void serializeTopoItem(PRCbitStream &pbs) { serializeBody(pbs); }
serialType()1409   uint32_t serialType() { return topo_item_type; }
serialTolerance()1410   virtual double serialTolerance() { return 0; }
1411   const uint32_t topo_item_type;
1412 };
1413 typedef std::deque <PRCBody*>  PRCBodyList;
1414 
1415 class PRCContentWireEdge : public PRCBaseTopology
1416 {
1417 public:
PRCContentWireEdge()1418   PRCContentWireEdge() :
1419     PRCBaseTopology(), curve_3d(NULL), has_curve_trim_interval(false) {}
PRCContentWireEdge(std::string n)1420   PRCContentWireEdge(std::string n) :
1421     PRCBaseTopology(n,makeCADID()), curve_3d(NULL), has_curve_trim_interval(false) {}
~PRCContentWireEdge()1422   ~PRCContentWireEdge() { delete curve_3d; }
1423   void serializeContentWireEdge(PRCbitStream &pbs);
1424 // void setCurve(PRCCurve*& curve) { curve_3d = curve; curve = NULL; }
1425   PRCCurve* curve_3d;
1426   bool has_curve_trim_interval;
1427   PRCInterval curve_trim_interval;
1428 };
1429 
1430 class PRCWireEdge : public PRCContentWireEdge, public PRCTopoItem
1431 {
1432 public:
1433   void serializeWireEdge(PRCbitStream &pbs);
serializeTopoItem(PRCbitStream & pbs)1434   void serializeTopoItem(PRCbitStream &pbs) { serializeWireEdge(pbs); }
1435 };
1436 
1437 class PRCSingleWireBody : public PRCBody
1438 {
1439 public:
PRCSingleWireBody()1440   PRCSingleWireBody() :
1441     PRCBody(PRC_TYPE_TOPO_SingleWireBody), wire_edge(NULL) {}
PRCSingleWireBody(std::string n)1442   PRCSingleWireBody(std::string n) :
1443     PRCBody(PRC_TYPE_TOPO_SingleWireBody, n), wire_edge(NULL) {}
~PRCSingleWireBody()1444   ~PRCSingleWireBody() { delete wire_edge; }
1445   void serializeSingleWireBody(PRCbitStream &pbs);
serializeBody(PRCbitStream & pbs)1446   void serializeBody(PRCbitStream &pbs) { serializeSingleWireBody(pbs); }
setWireEdge(PRCWireEdge * & wireEdge)1447   void setWireEdge(PRCWireEdge*& wireEdge) { wire_edge = wireEdge; wireEdge = NULL; }
1448   PRCWireEdge* wire_edge;
1449 };
1450 
1451 class PRCFace : public PRCBaseTopology, public PRCTopoItem, public PRCGraphics
1452 {
1453 public:
PRCFace()1454   PRCFace() :
1455     PRCBaseTopology(), base_surface(NULL), have_surface_trim_domain(false), have_tolerance(false), tolerance(0), number_of_loop(0), outer_loop_index(-1) {}
PRCFace(std::string n)1456   PRCFace(std::string n) :
1457     PRCBaseTopology(n,makeCADID()), base_surface(NULL), have_surface_trim_domain(false), have_tolerance(false), tolerance(0), number_of_loop(0), outer_loop_index(-1) {}
~PRCFace()1458   ~PRCFace() { delete base_surface; }
1459   void serializeFace(PRCbitStream &pbs);
serializeTopoItem(PRCbitStream & pbs)1460   void serializeTopoItem(PRCbitStream &pbs) { serializeFace(pbs); }
setBaseSurface(PRCSurface * & surface)1461   void setBaseSurface(PRCSurface*& surface) { base_surface = surface; surface = NULL; }
1462   PRCSurface *base_surface;
1463   const bool have_surface_trim_domain;
1464   PRCDomain surface_trim_domain;
1465   const bool have_tolerance;
1466   const double tolerance;
1467   const uint32_t number_of_loop;
1468   const int32_t outer_loop_index;
1469 // PRCLoopList loop;
1470 };
1471 typedef std::deque <PRCFace*>  PRCFaceList;
1472 
1473 class PRCShell : public PRCBaseTopology, public PRCTopoItem
1474 {
1475 public:
PRCShell()1476   PRCShell() :
1477     PRCBaseTopology(), shell_is_closed(false) {}
PRCShell(std::string n)1478   PRCShell(std::string n) :
1479     PRCBaseTopology(n,makeCADID()), shell_is_closed(false) {}
~PRCShell()1480   ~PRCShell() { for(PRCFaceList::iterator it=face.begin(); it!=face.end(); ++it) delete *it; }
1481   void serializeShell(PRCbitStream &pbs);
serializeTopoItem(PRCbitStream & pbs)1482   void serializeTopoItem(PRCbitStream &pbs) { serializeShell(pbs); }
1483   void addFace(PRCFace*& pFace, uint8_t orientation=2);
1484   bool shell_is_closed;
1485   PRCFaceList face;
1486   std::vector<uint8_t> orientation_surface_with_shell;
1487 };
1488 typedef std::deque <PRCShell*>  PRCShellList;
1489 
1490 class PRCConnex : public PRCBaseTopology, public PRCTopoItem
1491 {
1492 public:
PRCConnex()1493   PRCConnex() :
1494     PRCBaseTopology() {}
PRCConnex(std::string n)1495   PRCConnex(std::string n) :
1496     PRCBaseTopology(n,makeCADID()) {}
~PRCConnex()1497   ~PRCConnex() { for(PRCShellList::iterator it=shell.begin(); it!=shell.end(); ++it) delete *it; }
1498   void serializeConnex(PRCbitStream &pbs);
serializeTopoItem(PRCbitStream & pbs)1499   void serializeTopoItem(PRCbitStream &pbs) { serializeConnex(pbs); }
1500   void addShell(PRCShell*& pShell);
1501   PRCShellList shell;
1502 };
1503 typedef std::deque <PRCConnex*>  PRCConnexList;
1504 
1505 class PRCBrepData : public PRCBody, public PRCBoundingBox
1506 {
1507 public:
PRCBrepData()1508   PRCBrepData() :
1509     PRCBody(PRC_TYPE_TOPO_BrepData) {}
PRCBrepData(std::string n)1510   PRCBrepData(std::string n) :
1511     PRCBody(PRC_TYPE_TOPO_BrepData, n) {}
~PRCBrepData()1512   ~PRCBrepData() { for(PRCConnexList::iterator it=connex.begin(); it!=connex.end(); ++it) delete *it; }
1513   void serializeBrepData(PRCbitStream &pbs);
serializeBody(PRCbitStream & pbs)1514   void serializeBody(PRCbitStream &pbs) { serializeBrepData(pbs); }
1515   void addConnex(PRCConnex*& pConnex);
1516   PRCConnexList connex;
1517 };
1518 
1519 // For now - treat just the case of Bezier surfaces cubic 4x4 or linear 2x2
1520 class PRCCompressedFace : public PRCBaseTopology, public PRCGraphics
1521 {
1522 public:
PRCCompressedFace()1523   PRCCompressedFace() :
1524     PRCBaseTopology(), orientation_surface_with_shell(true), degree(0) {}
PRCCompressedFace(std::string n)1525   PRCCompressedFace(std::string n) :
1526     PRCBaseTopology(n,makeCADID()), orientation_surface_with_shell(true), degree(0) {}
1527   void serializeCompressedFace(PRCbitStream &pbs, double brep_data_compressed_tolerance);
1528   void serializeContentCompressedFace(PRCbitStream &pbs);
1529   void serializeCompressedAnaNurbs(PRCbitStream &pbs, double brep_data_compressed_tolerance);
1530   void serializeCompressedNurbs(PRCbitStream &pbs, double brep_data_compressed_tolerance);
1531   bool orientation_surface_with_shell;
1532   uint32_t degree;
1533   std::vector<PRCVector3d> control_point;
1534 };
1535 typedef std::deque <PRCCompressedFace*>  PRCCompressedFaceList;
1536 
1537 // For now - treat just the case of one connex/one shell
1538 class PRCCompressedBrepData : public PRCBody
1539 {
1540 public:
PRCCompressedBrepData()1541   PRCCompressedBrepData() :
1542     PRCBody(PRC_TYPE_TOPO_BrepDataCompress), serial_tolerance(0), brep_data_compressed_tolerance(0) {}
PRCCompressedBrepData(std::string n)1543   PRCCompressedBrepData(std::string n) :
1544     PRCBody(PRC_TYPE_TOPO_BrepDataCompress, n), serial_tolerance(0), brep_data_compressed_tolerance(0) {}
~PRCCompressedBrepData()1545   ~PRCCompressedBrepData() { for(PRCCompressedFaceList::iterator it=face.begin(); it!=face.end(); ++it) delete *it; }
1546   void serializeCompressedBrepData(PRCbitStream &pbs);
serializeBody(PRCbitStream & pbs)1547   void serializeBody(PRCbitStream &pbs) { serializeCompressedBrepData(pbs); }
1548   void serializeCompressedShell(PRCbitStream &pbs);
serialTolerance()1549   double serialTolerance() { return serial_tolerance; }
1550   double serial_tolerance;
1551   double brep_data_compressed_tolerance;
1552   PRCCompressedFaceList face;
1553 };
1554 
1555 class PRCTopoContext : public ContentPRCBase
1556 {
1557 public:
1558   PRCTopoContext(std::string n="") :
ContentPRCBase(PRC_TYPE_TOPO_Context,n)1559   ContentPRCBase(PRC_TYPE_TOPO_Context,n), behaviour(0), granularity(1), tolerance(0),
1560    have_smallest_face_thickness(false), smallest_thickness(0), have_scale(false), scale(1) {}
~PRCTopoContext()1561   ~PRCTopoContext() { for(PRCBodyList::iterator it=body.begin(); it!=body.end(); ++it) delete *it; }
1562   void serializeTopoContext(PRCbitStream&);
1563   void serializeContextAndBodies(PRCbitStream&);
1564   void serializeGeometrySummary(PRCbitStream&);
1565   void serializeContextGraphics(PRCbitStream&);
1566   uint32_t addSingleWireBody(PRCSingleWireBody*& body);
1567   uint32_t addBrepData(PRCBrepData*& body);
1568   uint32_t addCompressedBrepData(PRCCompressedBrepData*& body);
1569   uint8_t  behaviour;
1570   double granularity;
1571   double tolerance;
1572   bool have_smallest_face_thickness;
1573   double smallest_thickness;
1574   bool have_scale;
1575   double scale;
1576   PRCBodyList body;
1577 };
1578 typedef std::deque <PRCTopoContext*>  PRCTopoContextList;
1579 
1580 class PRCUniqueId
1581 {
1582 public:
PRCUniqueId()1583   PRCUniqueId() : id0(0), id1(0), id2(0), id3(0)  {}
1584   void serializeCompressedUniqueId(PRCbitStream&) const;
1585   void serializeFileStructureUncompressedUniqueId(std::ostream& out) const;
1586   uint32_t id0;
1587   uint32_t id1;
1588   uint32_t id2;
1589   uint32_t id3;
1590 };
1591 
1592 class PRCUnit
1593 {
1594 public:
PRCUnit()1595   PRCUnit() : unit_from_CAD_file(false), unit(1) {}
unit_from_CAD_file(ufcf)1596   PRCUnit(double u, bool ufcf=true) : unit_from_CAD_file(ufcf), unit(u) {}
1597   void serializeUnit(PRCbitStream&);
1598   bool unit_from_CAD_file;
1599   double unit;
1600 };
1601 
1602 class PRCProductOccurrence: public PRCGraphics, public ContentPRCBase
1603 {
1604 public:
1605   PRCProductOccurrence(std::string n="") :
ContentPRCBase(PRC_TYPE_ASM_ProductOccurence,n)1606     ContentPRCBase(PRC_TYPE_ASM_ProductOccurence,n),
1607     index_part(m1),
1608     index_prototype(m1), prototype_in_same_file_structure(true),
1609     index_external_data(m1), external_data_in_same_file_structure(true),
1610     product_behaviour(0), product_information_flags(0), product_load_status(KEPRCProductLoadStatus_Loaded),
1611     location(NULL) {}
~PRCProductOccurrence()1612   ~PRCProductOccurrence() { delete location; }
setLocation(PRCGeneralTransformation3d * & transform)1613   void setLocation(PRCGeneralTransformation3d*& transform) { location = transform; transform = NULL; }
1614   void serializeProductOccurrence(PRCbitStream&);
1615   uint32_t index_part;
1616   uint32_t index_prototype;
1617   bool prototype_in_same_file_structure;
1618   PRCUniqueId prototype_file_structure;
1619   uint32_t index_external_data;
1620   bool external_data_in_same_file_structure;
1621   PRCUniqueId external_data_file_structure;
1622   std::vector<uint32_t> index_son_occurrence;
1623   uint8_t product_behaviour;
1624   PRCUnit unit_information;
1625   uint8_t product_information_flags;
1626   EPRCProductLoadStatus product_load_status;
1627   PRCGeneralTransformation3d *location;
1628 };
1629 typedef std::deque <PRCProductOccurrence*>  PRCProductOccurrenceList;
1630 
1631 class PRCPartDefinition: public PRCGraphics, public ContentPRCBase, public PRCBoundingBox
1632 {
1633 public:
1634 	PRCPartDefinition(std::string n="") :
ContentPRCBase(PRC_TYPE_ASM_PartDefinition,n)1635     ContentPRCBase(PRC_TYPE_ASM_PartDefinition,n) {}
~PRCPartDefinition()1636   ~PRCPartDefinition() { for(PRCRepresentationItemList::iterator it=representation_item.begin(); it!=representation_item.end(); ++it) delete *it; }
1637 	void serializePartDefinition(PRCbitStream&);
1638 	uint32_t addBrepModel(PRCBrepModel*& pBrepModel);
1639 	uint32_t addPolyBrepModel(PRCPolyBrepModel*& pPolyBrepModel);
1640 	uint32_t addPointSet(PRCPointSet*& pPointSet);
1641 	uint32_t addSet(PRCSet*& pSet);
1642 	uint32_t addWire(PRCWire*& pWire);
1643 	uint32_t addPolyWire(PRCPolyWire*& pPolyWire);
1644 	uint32_t addRepresentationItem(PRCRepresentationItem*& pRepresentationItem);
1645 	PRCRepresentationItemList representation_item;
1646 };
1647 typedef std::deque <PRCPartDefinition*>  PRCPartDefinitionList;
1648 
1649 #endif //__WRITE_PRC_H
1650