WhipExamples/WriteRedline.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 void write_my_dwf(RECT rect, double paper_scale, double paper_offset)
00026 {
00027     WT_W2D_Class_Factory cf;
00028 
00029     WT_File *my_file = cf.Create_File();
00030     if (my_file == NULL)
00031         return;
00032     my_file->set_filename("testfile.dwf");
00033     my_file->heuristics().set_target_version(55);
00034     my_file->set_file_mode(WT_File::Block_Write);
00035     my_file->open();
00036 
00037     WT_File *redline_hdr_block = cf.Create_File();
00038     if (redline_hdr_block == NULL)
00039         return;
00040     redline_hdr_block->set_filename("redline_hdr_block_file.dwf"); 
00041 
00042     GUID _guid;
00043 
00044     CoCreateGuid(&_guid);
00045     WD_GUID redline_hdr_guid;
00046     memcpy(&redline_hdr_guid,&_guid,sizeof(redline_hdr_guid));
00047 
00048     CoCreateGuid(&_guid);
00049     WD_GUID redline_guid;
00050     memcpy(&redline_guid,&_guid,sizeof(redline_guid));
00051 
00052     FILETIME ft;
00053     GetSystemTimeAsFileTime(&ft);
00054 
00055     WT_FileTime current_time;
00056     current_time.set_low_date_time(ft.dwLowDateTime);
00057     current_time.set_high_date_time(ft.dwHighDateTime);
00058 
00059     //do the redline_hdr first
00060     WT_BlockRef redline_hdr;
00061     redline_hdr.set_format(WT_BlockRef::Redline_Hdr);
00062     redline_hdr.set_block_guid(redline_hdr_guid);
00063     redline_hdr.set_parent_block_guid(redline_guid);
00064     redline_hdr.set_creation_time(current_time);
00065     redline_hdr.set_modification_time(current_time);
00066     redline_hdr.set_encryption(WT_Encryption());
00067     redline_hdr.set_validity(WD_True);
00068     redline_hdr.set_visibility(WD_True);
00069     redline_hdr.set_scan_flag(WD_False);
00070     redline_hdr.set_mirror_flag(WD_False);
00071     redline_hdr.set_inversion_flag(WD_False);
00072     redline_hdr.set_orientation(WT_Orientation());
00073     redline_hdr.set_rotation(0);
00074     redline_hdr.set_alignment(WT_Alignment());
00075     double inked_area[2] = {rect.right-rect.left,rect.bottom-rect.top};
00076     redline_hdr.set_inked_area(inked_area);
00077     redline_hdr.set_dpi_resolution((WT_Integer16)(1/paper_scale));
00078 
00079     WT_Logical_Point clip_rectangle[2] = 
00080     {
00081            WT_Logical_Point(rect.left,rect.top),
00082            WT_Logical_Point(rect.right,rect.bottom)
00083     };
00084     redline_hdr.set_clip_rectangle(clip_rectangle);
00085     redline_hdr.set_password("");
00086 
00087     redline_hdr.set_paper_scale(paper_scale);
00088     redline_hdr.set_paper_offset(&paper_offset);
00089     my_file->desired_rendition().blockref() = redline_hdr;
00090     my_file->write_block(*redline_hdr_block);
00091 
00092     //serialize a visibility opcode. redline_hdr gets written this way
00093     WT_Visibility *V = cf.Create_Visibility(WD_True);
00094     if (V == NULL)
00095         return;
00096     V->serialize(*my_file);
00097     
00098     WT_File *redline_block = cf.Create_File();
00099     if (redline_block == NULL)
00100         return;
00101     redline_block->heuristics().set_target_version(55);
00102     redline_block->set_filename("redline_block_file.dwf");
00103 
00104     //prepare and serialize the actual redline block
00105     WT_BlockRef redline;
00106     redline.set_format(WT_BlockRef::Redline);
00107     redline.set_block_guid(redline_guid);
00108     redline.set_creation_time(current_time);
00109     redline.set_modification_time(current_time);
00110     redline.set_validity(WD_True);
00111     my_file->desired_rendition().blockref() = redline;
00112 
00113     //Avoid making the viewport opcode as the first opcode to be serialized as
00114     //part of the new redline header compressed block. Since the viewport opcode
00115     //is always serialized ASCII, this would cause confusion for the WHIP! Toolkit
00116     //to start the compressor.
00117 
00118     WT_Visibility *V1 = cf.Create_Visibility(WD_True);
00119     if (V1 == NULL)
00120         return;
00121     V1->serialize(*my_file);
00122 
00123     //Create a viewport, so that pre-existing viewports don't clip our markups
00124     //out of existence.
00125 
00126     WT_Logical_Point points[4] = 
00127     {
00128            WT_Logical_Point(rect.left,rect.top),
00129            WT_Logical_Point(rect.right,rect.top),
00130            WT_Logical_Point(rect.right,rect.bottom),
00131            WT_Logical_Point(rect.left,rect.bottom)
00132     };
00133     WT_Viewport *vp = cf.Create_Viewport(*my_file,"",4,points,WD_True);
00134     my_file->desired_rendition().viewport() = *vp;
00135     my_file->write_block(*redline_block);
00136     my_file->close();
00137     
00138     cf.Destroy(my_file);
00139     cf.Destroy(redline_hdr_block);
00140     cf.Destroy(V);
00141     cf.Destroy(V1);
00142     cf.Destroy(vp);
00143 }

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