WhipExamples/DataReading.cpp

00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 #include "whiptk/whip_toolkit.h"
00023 #include "whiptk/w2d_class_factory.h"
00024 
00025 class My_Class;
00026 WT_Result my_open  (WT_File &file);
00027 WT_Result my_close (WT_File &file);
00028 WT_Result my_read  (WT_File &file, int desired_bytes, int &
00029                     bytes_read, void * buffer);
00030 WT_Result my_seek  (WT_File &file, int distance, int &amount_seeked);
00031 WT_Result my_process_polyline (WT_Polyline &polyline, WT_File &file);
00032 
00033 
00034 void read_whip ( My_Class *my_stuff ) {
00035     WT_W2D_Class_Factory cf;
00036 
00037     WT_File * my_file = cf.Create_File();
00038     WT_Result result;
00039 
00040     my_file->set_stream_open_action (my_open);
00041     my_file->set_stream_close_action(my_close);
00042     my_file->set_stream_read_action (my_read);
00043     my_file->set_stream_seek_action (my_seek);
00044 
00045     my_file->set_filename("testfile.w2d");
00046     my_file->set_file_mode(WT_File::File_Read);
00047     my_file->open();
00048 
00049     my_file->heuristics().set_user_data(my_stuff);
00050     my_file->set_polyline_action(my_process_polyline);
00051     do {
00052         result = my_file->process_next_object();
00053     } while (result == WT_Result::Success);
00054 
00055     my_file->close();
00056     cf.Destroy(my_file);
00057 }
00058 
00059 #include <stdio.h>
00060 
00061 WT_Result my_open (WT_File &file)
00062 {
00063     FILE * fp = fopen(file.filename().ascii(), "rb");
00064     file.set_stream_user_data(fp);
00065     return WT_Result::Success;
00066 }
00067 
00068 WT_Result my_close (WT_File &file)
00069 {
00070     FILE * fp = (FILE *) file.stream_user_data();
00071     fclose (fp);
00072     file.set_stream_user_data(WD_Null);
00073     return WT_Result::Success;
00074 }
00075 
00076 WT_Result my_read (WT_File &file, int desired_bytes, int &bytes_read, void * buffer)
00077 {
00078     FILE * fp = (FILE *) file.stream_user_data();
00079     if (feof(fp))
00080         return WT_Result::End_Of_File_Error;
00081 
00082     bytes_read = (int) fread(buffer, sizeof(WT_Byte), desired_bytes, fp);
00083     if (!bytes_read)
00084         return WT_Result::Unknown_File_Read_Error;
00085 
00086     return WT_Result::Success;
00087 }
00088 
00089 WT_Result my_seek(WT_File &file, int distance, int &amount_seeked)
00090 {
00091     if (fseek((FILE *)file.stream_user_data(), distance, SEEK_CUR) == 0)
00092     {
00093         amount_seeked = distance;
00094         return WT_Result::Success;
00095     }
00096     else
00097     {
00098         amount_seeked = 0;
00099         return WT_Result::End_Of_File_Error;
00100     }
00101 }
00102 
00103 WT_Result my_process_polyline (WT_Polyline &polyline, WT_File &file)
00104 {
00105     My_Class * my_stuff = (My_Class*) file.heuristics().user_data();
00106     int color_index = file.rendition().color().index();
00107 
00108     //my_stuff->add_to_my_display_list (color_index,
00109     //                                 polyline.count(), polyline.points());
00110     return WT_Result::Success;
00111 }

Generated on Tue Jan 6 22:41:12 2009 for Autodesk DWF Whip 2D Toolkit by  doxygen 1.4.5