HW2DReaderCommon.h
1 #ifndef HW2DREADERCOMMON_H
2 #define HW2DREADERCOMMON_H
3 
4 #include "hc.h"
5 #include "HBaseView.h"
6 #include "HIOManager.h"
7 #include "HUtility.h"
8 #include "tempfile_utils.h"
9 
10 #include <string>
11 
12 #include "dwf/whiptk/fileext.h"
13 #include "dwf/package/GlobalSection.h"
14 #include "dwf/package/EPlotSection.h"
15 
16 #if !defined(TWO_PI)
17 #define TWO_PI 6.283185307179586476925286766559
18 #endif
19 
20 #define HK_Two_Pi TWO_PI
21 
22 #define DWFIO_EPSILON 1e-05 // Define your own tolerance
23 #define DWFIO_FLOAT_EQ(x,v) (((v - DWFIO_EPSILON) < x) && (x <( v + DWFIO_EPSILON)))
24 
25 struct HColor
26 {
27  float red;
28  float green;
29  float blue;
30 };
31 
32 // Common class which handles both reading of regular DWF file and DWFx files
34 {
35 public:
36 
37  std::map<int, H_FORMAT_TEXT> lay_num_map;
38 
39  enum CoordinateMode
40  {
41  logical_coords = 0,
42  application_coords,
43  recentered_coords
44  };
45 
46  // typically used when reading legacy DWF files
47  HW2DReaderCommon(WT_File * whip_file,
48  DWFInputStream * rW2DStream,
49  HInputHandlerOptions * pInputHandlerOptions,
50  HC_KEY model_key,
51  bool rebaseModel,
52  HInputHandler * m,
53  CoordinateMode coord_mode = recentered_coords);
54 
55  // used when reading w2d files embedded in DWF files
56  HW2DReaderCommon(WT_File * whip_file,
57  DWFToolkit::DWFResource * pResource,
58  HInputHandlerOptions * pInputHandlerOptions,
59  HC_KEY model_key,
60  bool rebaseModel,
61  HInputHandler * m,
62  CoordinateMode coord_mode = recentered_coords);
63 
64  // used when reading xml w2d files embedded in DWFx files
65  HW2DReaderCommon(WT_File * whip_file,
66  DWFToolkit::DWFResource * pResource,
67  DWFToolkit::DWFSection * pSection,
68  HInputHandlerOptions * pInputHandlerOptions,
69  HC_KEY model_key,
70  bool rebaseModel,
71  bool is_dwfx,
72  HInputHandler * m,
73  CoordinateMode coord_mode = recentered_coords);
74 
76 
77  void init();
78 
79  //Process Geometry
80  static WT_Result _processPolyMarker(WT_Polymarker & polymarker, WT_File & file);
81  static WT_Result _processPolytriangle(WT_Polytriangle & polytriangle, WT_File & file);
82  static WT_Result _processText(WT_Text & text, WT_File & file);
83  static WT_Result _processContourNode(WT_Contour_Set & contour_set, WT_File & file);
84  static WT_Result _processEllipse(WT_Outline_Ellipse & e, WT_File & file);
85  static WT_Result _processPolyline(WT_Polyline & polyline, WT_File & file );
86  static WT_Result _processPolygon(WT_Polygon & polygon, WT_File & file);
87  static WT_Result _processImage(WT_Image & image, WT_File & file);
88  static WT_Result _processPNG_Group4_Image(WT_PNG_Group4_Image & image, WT_File & file);
89 
90  //Process Attributes
91  static WT_Result _processColorMap(WT_Color_Map & color_map, WT_File & file);
92  static WT_Result _processURL(WT_URL & named_url, WT_File & file);
93  static WT_Result _processLineWeight(WT_Line_Weight & lw, WT_File & file);
94  static WT_Result _processFill(WT_Fill & rFill, WT_File & file);
95  static WT_Result _processColor(WT_Color & rColor, WT_File & file);
96  static WT_Result _processViewport(WT_Viewport & viewport, WT_File & file);
97  static WT_Result _processView(WT_View & view, WT_File & file);
98  static WT_Result _processFont(WT_Font & font, WT_File & file);
99  static WT_Result _processVisibility(WT_Visibility & visibility, WT_File & file);
100  static WT_Result _processBackground(WT_Background & background, WT_File & file);
101  static WT_Result _processHAlignment(WT_Text_HAlign & hAln, WT_File & file);
102  static WT_Result _processObjectNode(WT_Object_Node & object_node, WT_File & file);
103  static WT_Result _processPlotInfo(WT_Plot_Info & plot_info, WT_File & file);
104  static WT_Result _processInkedArea(WT_Inked_Area & inked_area, WT_File & file);
105  static WT_Result _processNamedView(WT_Named_View & named_view, WT_File & file);
106  static WT_Result _processLayer(WT_Layer & layer, WT_File & file);
107  static WT_Result _processUnits(WT_Units & units, WT_File & file);
108 
109  bool compute_extents(DWFInputStream & input_stream);
110  WT_Result read(double z_separation, double depth_range_separation);
111  int incrementImageCount();
112  void setFillMode(bool val);
113  bool fillMode() { return m_bFill; }
114 
115  WT_Result process_stream_close() { return WT_Result::Success; }
116  WT_Result process_stream_end_seek(){ return WT_Result::Success; }
117  WT_Result process_stream_open();
118  WT_Result process_stream_read(int desired_bytes, int & bytes_read, void * buffer);
119  WT_Result process_stream_seek(int distance, int & amount_seeked);
120  WT_Result process_stream_tell(unsigned long * current_file_pointer_position);
121  WT_Result process_stream_write(int size, void const * buffer) { return WT_Result::Toolkit_Usage_Error; }
122 
123  //Import Geometry
124  WT_Result _importPolytriangle (WT_Polytriangle & polytriangle);
125  WT_Result _importText(WT_Text & text);
126  bool is_this_face_really_a_hole(int point_count, HPoint const * points);
127  WT_Result _importContourNode(WT_Contour_Set & contour_set);
128  WT_Result _importEllipse(WT_Outline_Ellipse & e);
129  WT_Result _importPolyline(WT_Polyline & polyline);
130  WT_Result _importPolygon(WT_Polygon & polygon);
131  WT_Result _importImage(WT_Image & image);
132  WT_Result _importPNG_Group4_Image(WT_PNG_Group4_Image & image);
133 
134  //Import Attributes
135  WT_Result import_line_weight (WT_Line_Weight & lw);
136  WT_Result _importLineWeight (WT_Line_Weight & lw) { return import_line_weight(lw); }
137  WT_Result _importFill (WT_Fill & rFill);
138  void apply_object_attrs(HC_KEY key);
139  WT_Result _importColor(WT_Color & rColor);
140  WT_Result _importViewport(WT_Viewport & viewport);
141  WT_Result _importLayer(WT_Layer & layer);
142  WT_Result _importColorMap(WT_Color_Map & color_map);
143  WT_Result _importObjectNode(WT_Object_Node & object_node);
144  WT_Result _importPlotInfo(WT_Plot_Info & plot_info, WT_File & file);
145  WT_Result _importInkedArea(WT_Inked_Area & inked_area, WT_File & file) { return WT_Result::Success; }
146  WT_Result _importNamedView(WT_Named_View & named_view);
147  WT_Result _importFont(WT_Font & font);
148  WT_Result _importVisibility(WT_Visibility & visibility);
149  WT_Result _importHAlignment(WT_Text_HAlign & hAln);
150  WT_Result _importUnits(WT_Units & units);
151  WT_Result _importURL(WT_URL & named_url);
152  WT_Result _importView(WT_View & view);
153  WT_Result _importBackground(WT_Background & background);
154 
155  //Scene graph utility functions
156  void resort_start();
157  void resort_finish();
158  void resort_close();
159  void resort_open();
160  void resort_segment();
161 
162 private:
163  HInputHandler * m_console;
164 
165  struct ViewportInfo
166  {
167  ViewportInfo(WT_String vName, WT_String vUnits, double scale)
168  : measurementScalingFactor(scale)
169  {
170  if (vName.ascii())
171  strcpy(viewportName, vName.ascii());
172  else
173  strcpy(viewportName, H_FORMAT_TEXT("viewport_%d", anonymousViewportCount++));
174 
175  if (vUnits.ascii())
176  strcpy(viewportMeasuringUnits, vUnits.ascii());
177  else
178  strcpy(viewportMeasuringUnits, "no_units");
179  }
180 
181  char viewportName[MVO_BUFFER_SIZE]; //name of the viewport
182  char viewportMeasuringUnits[MVO_BUFFER_SIZE]; //viewport units (i.e. 'millimeters', 'inches'...)
183  double measurementScalingFactor; //scale to apply to world coordinates to obtain the correct measurement
184  };
185 
186  ViewportInfo * m_currentViewport;
187  bool m_bisViewportOpen;
188  static int anonymousViewportCount;
189 
190  std::set<HC_KEY> m_viewportSegments;
191 
192  size_t m_nBytesAvailable;
193  DWFString m_zContent;
194  DWFInputStream * m_rW2DStream;
195  bool m_bFreeInputStream;
196  bool m_bColorMapExist;
197  bool m_bIsDWFx;
198  WT_File * m_pWT_File;
199  DWFToolkit::DWFResource * m_pResource;
200  DWFToolkit::DWFSection * m_pSection;
201 
202  WT_Result import_image( int size, const WT_Byte * image_data, const char * type,
203  WT_Logical_Point const & min_corner, WT_Logical_Point const & max_corner);
204  WT_Result import_Other_Formats(WT_Image & image);
205  WT_Result insert_Image_Mesh(char * image_name, WT_Logical_Point const & min_corner, WT_Logical_Point const & max_corner);
206 
207 
208  // removes all the 2*Pi surpluses from the angle and returns the remainder.
209  // if the angle is exactly 2*Pi or multiples of it, then it makes it 2*Pi
210  // NOTE: Should the start_angle be set to 0 when it is exactly 2*Pi (or multiples of it)
211  // instead of making it 2*Pi?
212  static inline float unwind_loops(float arc_angle)
213  {
214  if( arc_angle <= HK_Two_Pi )
215  return arc_angle;
216 
217  float fmod_arc_angle = fmod(arc_angle, (float) HK_Two_Pi);
218  if( (arc_angle >= HK_Two_Pi) && DWFIO_FLOAT_EQ(0.0f, fmod_arc_angle) )
219  // rare case where it is exactly divisible by 2PI
220  return (float) HK_Two_Pi;
221  else
222  return fmod_arc_angle;
223  }
224 
225 public:
226  H_FORMAT_TEXT m_layerName;
227  bool m_layer_visibility;
228  double m_z_plane;
229  double m_z_separation;
230  double m_use_depth_range;
231  double m_depth_range;
232 
233  CoordinateMode m_CoordMode;
234  WT_Units* m_pWhipUnits;
235  double m_x_extents;
236  double m_y_extents;
237  int m_layer_stack;
238  bool m_unmark_detector;
239  H_UTF8 m_current_url;
240 
241  /* HOOPS Attributes affecting geometry*/
242  HColor m_Color;
243  HPoint m_text_path;
244  char m_font[MVO_BUFFER_SIZE];
245  char m_fontName[100];
246  char m_backupFont[100];
247  char m_fontStyle[100];
248  char m_fontHeight[100];
249  char m_fontScale[100];
250  char m_fontOblique[100];
251  double m_line_edge_weight;
252  bool m_visible;
253  char m_hAlignment[4];
254  bool m_resort;
255 
256  char m_object_id[MVO_BUFFER_SIZE];
257  bool m_bDisableDWFDrawOrder;
258  double m_priority;
259  bool m_bImportThumbnail;
260 
261  /* background stuff */
262  HColor m_backgroundColor;
263  HPoint m_plotInfoMin;
264  HPoint m_plotInfoMax;
265  int m_plotInfoUnits;
266  int m_pageWidth;
267  int m_pageHeight;
268 
269 protected:
270  bool segment_open;
271  bool m_bFill;
272  static int m_image_count;
273  HC_KEY m_modelkey;
274  //Please refer issue no :13552 ( Internal Note 1 ) for more details.
275  HC_KEY m_stylekey;
276 
277  HInputHandlerOptions * m_pInputHandlerOptions;
278 
279 };
280 
281 #endif //HW2DREADERCOMMON_H
HInputHandler an abstract base class for model and image input.
Definition: HIOManager.h:671
Definition: HW2DReaderCommon.h:25
The HPoint class is the data type of a three-dimensional point.
Definition: HGlobals.h:121
Definition: HIOManager.h:246
A header file containing the HIO classes for passing to HBaseView::FileInput and HBaseView::FileOutpu...
Definition: HW2DReaderCommon.h:33