Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HW2DReaderCommon.h
00001 #ifndef HW2DREADERCOMMON_H
00002 #define HW2DREADERCOMMON_H
00003 
00004 #include "hc.h"
00005 #include "HBaseView.h"
00006 #include "HIOManager.h"
00007 #include "HUtility.h"
00008 #include "tempfile_utils.h"
00009 
00010 #include <string>
00011 
00012 #include "dwf/whiptk/fileext.h"
00013 #include "dwf/package/GlobalSection.h"
00014 #include "dwf/package/EPlotSection.h"
00015 
00016 #if !defined(TWO_PI)
00017 #define TWO_PI                  6.283185307179586476925286766559
00018 #endif
00019 
00020 #define HK_Two_Pi TWO_PI
00021 
00022 #define DWFIO_EPSILON 1e-05     // Define your own tolerance
00023 #define DWFIO_FLOAT_EQ(x,v) (((v - DWFIO_EPSILON) < x) && (x <( v + DWFIO_EPSILON)))
00024 
00025 struct HColor
00026 {
00027     float red;
00028     float green;
00029     float blue;
00030 };
00031 
00032 // Common class which handles both reading of regular DWF file and DWFx files
00033 class HW2DReaderCommon
00034 {
00035 public:
00036 
00037     std::map<int, H_FORMAT_TEXT> lay_num_map;
00038 
00039     enum CoordinateMode
00040     {
00041         logical_coords = 0,
00042         application_coords,
00043         recentered_coords
00044     };
00045 
00046     // typically used when reading legacy DWF files
00047     HW2DReaderCommon(WT_File * whip_file,
00048                      DWFInputStream * rW2DStream,
00049                      HInputHandlerOptions * pInputHandlerOptions, 
00050                      HC_KEY model_key,
00051                      bool rebaseModel,
00052                      HInputHandler * m,
00053                      CoordinateMode coord_mode = recentered_coords);
00054 
00055     // used when reading w2d files embedded in DWF files
00056     HW2DReaderCommon(WT_File * whip_file,
00057                     DWFToolkit::DWFResource * pResource,
00058                     HInputHandlerOptions * pInputHandlerOptions, 
00059                     HC_KEY model_key,
00060                     bool rebaseModel,
00061                     HInputHandler * m,
00062                     CoordinateMode coord_mode = recentered_coords);
00063 
00064     // used when reading xml w2d files embedded in DWFx files
00065     HW2DReaderCommon(WT_File * whip_file,
00066                     DWFToolkit::DWFResource * pResource,
00067                     DWFToolkit::DWFSection * pSection, 
00068                     HInputHandlerOptions * pInputHandlerOptions,
00069                     HC_KEY model_key,
00070                     bool rebaseModel, 
00071                     bool is_dwfx,
00072                     HInputHandler * m,
00073                     CoordinateMode coord_mode = recentered_coords);
00074 
00075     ~HW2DReaderCommon();
00076 
00077     void init();
00078 
00079     //Process Geometry
00080     static WT_Result _processPolyMarker(WT_Polymarker & polymarker, WT_File & file);
00081     static WT_Result _processPolytriangle(WT_Polytriangle & polytriangle, WT_File & file);
00082     static WT_Result _processText(WT_Text & text, WT_File & file);
00083     static WT_Result _processContourNode(WT_Contour_Set & contour_set, WT_File & file);
00084     static WT_Result _processEllipse(WT_Outline_Ellipse & e, WT_File & file);
00085     static WT_Result _processPolyline(WT_Polyline & polyline, WT_File & file );
00086     static WT_Result _processPolygon(WT_Polygon & polygon, WT_File & file);
00087     static WT_Result _processImage(WT_Image & image, WT_File & file);
00088     static WT_Result _processPNG_Group4_Image(WT_PNG_Group4_Image & image, WT_File & file);
00089 
00090     //Process Attributes
00091     static WT_Result _processColorMap(WT_Color_Map & color_map, WT_File & file);
00092     static WT_Result _processURL(WT_URL & named_url, WT_File & file);
00093     static WT_Result _processLineWeight(WT_Line_Weight & lw, WT_File & file);
00094     static WT_Result _processFill(WT_Fill  & rFill, WT_File & file);
00095     static WT_Result _processColor(WT_Color & rColor, WT_File & file);
00096     static WT_Result _processViewport(WT_Viewport & viewport, WT_File & file);
00097     static WT_Result _processView(WT_View & view,  WT_File & file);
00098     static WT_Result _processFont(WT_Font & font, WT_File & file);
00099     static WT_Result _processVisibility(WT_Visibility & visibility,  WT_File & file);
00100     static WT_Result _processBackground(WT_Background & background,  WT_File & file);
00101     static WT_Result _processHAlignment(WT_Text_HAlign & hAln,  WT_File & file);
00102     static WT_Result _processObjectNode(WT_Object_Node & object_node, WT_File & file);
00103     static WT_Result _processPlotInfo(WT_Plot_Info & plot_info, WT_File & file);
00104     static WT_Result _processInkedArea(WT_Inked_Area & inked_area, WT_File & file);
00105     static WT_Result _processNamedView(WT_Named_View & named_view, WT_File & file);
00106     static WT_Result _processLayer(WT_Layer & layer, WT_File & file); 
00107     static WT_Result _processUnits(WT_Units & units, WT_File & file);
00108 
00109     bool compute_extents(DWFInputStream & input_stream);
00110     WT_Result read(double z_separation, double depth_range_separation);
00111     int incrementImageCount();
00112     void setFillMode(bool val);
00113     bool fillMode() { return m_bFill; }
00114 
00115     WT_Result process_stream_close() { return WT_Result::Success; }
00116     WT_Result process_stream_end_seek(){ return WT_Result::Success; }
00117     WT_Result process_stream_open();
00118     WT_Result process_stream_read(int desired_bytes, int & bytes_read, void * buffer);
00119     WT_Result process_stream_seek(int distance, int & amount_seeked);
00120     WT_Result process_stream_tell(unsigned long * current_file_pointer_position);
00121     WT_Result process_stream_write(int size, void const * buffer) { return WT_Result::Toolkit_Usage_Error; }
00122 
00123     //Import Geometry
00124     WT_Result _importPolytriangle (WT_Polytriangle & polytriangle);
00125     WT_Result _importText(WT_Text & text);
00126     bool is_this_face_really_a_hole(int point_count, HPoint const * points);
00127     WT_Result _importContourNode(WT_Contour_Set & contour_set);
00128     WT_Result _importEllipse(WT_Outline_Ellipse & e);
00129     WT_Result _importPolyline(WT_Polyline & polyline);
00130     WT_Result _importPolygon(WT_Polygon & polygon);
00131     WT_Result _importImage(WT_Image & image);
00132     WT_Result _importPNG_Group4_Image(WT_PNG_Group4_Image & image);
00133 
00134     //Import Attributes
00135     WT_Result import_line_weight (WT_Line_Weight & lw);
00136     WT_Result _importLineWeight (WT_Line_Weight & lw) { return import_line_weight(lw); }
00137     WT_Result _importFill (WT_Fill  & rFill);
00138     void apply_object_attrs(HC_KEY key);
00139     WT_Result _importColor(WT_Color & rColor);
00140     WT_Result _importViewport(WT_Viewport & viewport);
00141     WT_Result _importLayer(WT_Layer & layer); 
00142     WT_Result _importColorMap(WT_Color_Map & color_map);
00143     WT_Result _importObjectNode(WT_Object_Node & object_node);
00144     WT_Result _importPlotInfo(WT_Plot_Info & plot_info, WT_File & file);
00145     WT_Result _importInkedArea(WT_Inked_Area & inked_area, WT_File & file) { return WT_Result::Success; }
00146     WT_Result _importNamedView(WT_Named_View & named_view);
00147     WT_Result _importFont(WT_Font & font);
00148     WT_Result _importVisibility(WT_Visibility & visibility);
00149     WT_Result _importHAlignment(WT_Text_HAlign & hAln);
00150     WT_Result _importUnits(WT_Units & units);
00151     WT_Result _importURL(WT_URL & named_url);
00152     WT_Result _importView(WT_View & view);
00153     WT_Result _importBackground(WT_Background & background);
00154 
00155     //Scene graph utility functions
00156     void resort_start();
00157     void resort_finish();
00158     void resort_close();
00159     void resort_open();
00160     void resort_segment();
00161 
00162 private:
00163     HInputHandler * m_console;
00164 
00165     struct ViewportInfo
00166     {
00167         ViewportInfo(WT_String vName, WT_String vUnits, double scale)
00168             : measurementScalingFactor(scale)
00169         {
00170             if (vName.ascii())
00171                 strcpy(viewportName, vName.ascii());
00172             else
00173                 strcpy(viewportName, H_FORMAT_TEXT("viewport_%d", anonymousViewportCount++));
00174 
00175             if (vUnits.ascii())
00176                 strcpy(viewportMeasuringUnits, vUnits.ascii());
00177             else
00178                 strcpy(viewportMeasuringUnits, "no_units");
00179         }
00180 
00181         char    viewportName[MVO_BUFFER_SIZE];              //name of the viewport
00182         char    viewportMeasuringUnits[MVO_BUFFER_SIZE];    //viewport units (i.e. 'millimeters', 'inches'...)
00183         double  measurementScalingFactor;                   //scale to apply to world coordinates to obtain the correct measurement
00184     };
00185 
00186     ViewportInfo * m_currentViewport;
00187     bool m_bisViewportOpen;
00188     static int anonymousViewportCount;
00189 
00190     std::set<HC_KEY> m_viewportSegments;
00191 
00192     size_t              m_nBytesAvailable;
00193     DWFString           m_zContent;
00194     DWFInputStream *    m_rW2DStream;
00195     bool                m_bFreeInputStream;
00196     bool                m_bColorMapExist;
00197     bool                m_bIsDWFx;
00198     WT_File *           m_pWT_File;
00199     DWFToolkit::DWFResource * m_pResource;
00200     DWFToolkit::DWFSection * m_pSection;
00201 
00202     WT_Result import_image( int size, const WT_Byte * image_data, const char * type,
00203                             WT_Logical_Point const & min_corner, WT_Logical_Point const & max_corner);
00204     WT_Result import_Other_Formats(WT_Image & image);
00205     WT_Result insert_Image_Mesh(char * image_name, WT_Logical_Point const & min_corner, WT_Logical_Point const & max_corner);
00206 
00207 
00208     // removes all the 2*Pi surpluses from the angle and returns the remainder.
00209     // if the angle is exactly 2*Pi or multiples of it, then it makes it 2*Pi
00210     // NOTE: Should the start_angle be set to 0 when it is exactly 2*Pi (or multiples of it)
00211     // instead of making it 2*Pi?
00212     static inline float unwind_loops(float arc_angle)
00213     {
00214         if( arc_angle <= HK_Two_Pi )
00215             return arc_angle;
00216 
00217         float fmod_arc_angle = fmod(arc_angle, (float) HK_Two_Pi);
00218         if( (arc_angle >= HK_Two_Pi) && DWFIO_FLOAT_EQ(0.0f, fmod_arc_angle) )
00219             // rare case where it is exactly divisible by 2PI
00220             return (float) HK_Two_Pi;
00221         else
00222             return fmod_arc_angle;
00223     }
00224 
00225 public:
00226     H_FORMAT_TEXT m_layerName;
00227     bool m_layer_visibility;
00228     double m_z_plane;
00229     double m_z_separation;
00230     double m_use_depth_range;
00231     double m_depth_range;
00232 
00233     CoordinateMode m_CoordMode;
00234     WT_Units* m_pWhipUnits;
00235     double m_x_extents;
00236     double m_y_extents;
00237     int m_layer_stack;
00238     bool m_unmark_detector;
00239     H_UTF8 m_current_url;
00240 
00241     /* HOOPS Attributes affecting geometry*/
00242     HColor m_Color;
00243     HPoint m_text_path;
00244     char m_font[MVO_BUFFER_SIZE];
00245     char m_fontName[100];
00246     char m_backupFont[100];
00247     char m_fontStyle[100];
00248     char m_fontHeight[100];
00249     char m_fontScale[100];
00250     char m_fontOblique[100];
00251     double m_line_edge_weight;
00252     bool m_visible;
00253     char m_hAlignment[4];
00254     bool m_resort;
00255 
00256     char m_object_id[MVO_BUFFER_SIZE];
00257     bool m_bDisableDWFDrawOrder;
00258     double m_priority;
00259     bool  m_bImportThumbnail;
00260 
00261     /* background stuff */
00262     HColor m_backgroundColor;
00263     HPoint m_plotInfoMin;
00264     HPoint m_plotInfoMax;
00265     int m_plotInfoUnits;
00266     int m_pageWidth;
00267     int m_pageHeight;
00268 
00269 protected:
00270     bool segment_open;
00271     bool m_bFill;
00272     static int m_image_count;
00273     HC_KEY m_modelkey;
00274     //Please refer issue no :13552 ( Internal Note 1 ) for more details.
00275     HC_KEY m_stylekey;
00276 
00277     HInputHandlerOptions * m_pInputHandlerOptions;
00278 
00279 };
00280 
00281 #endif //HW2DREADERCOMMON_H