WhipExamples/DashPattern.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 extern WT_File *whip_file; //Assume this has been opened for writing elsewhere.
00026 
00027 WT_Result DashPattern()
00028 {
00029     WT_W2D_Class_Factory cf;
00030 
00031     //Define the pattern, pairs of values: dash length and gap length.
00032         int i, x=0, y=0;
00033     WT_Integer16 vN[12];
00034     for (i=0; i<6; i+=2)  //. . . dot dot dot
00035     {   vN[i] = 1;        //dash length
00036         vN[i+1] = 15;     //gap length
00037     }
00038     for (i=6; i<12; i+=2) //-- -- -- dash dash dash
00039     {   vN[i] = 15;       //dash length
00040         vN[i+1] = 15;     //gap length
00041     }
00042     //Store the previous dash pattern.
00043     WT_Dash_Pattern *previous_pattern = cf.Create_Dash_Pattern( whip_file->desired_rendition().dash_pattern() );
00044     if (previous_pattern == NULL)
00045         return WT_Result::Out_Of_Memory_Error;
00046         
00047     //Set the new dash pattern.
00048     WT_Dash_Pattern* pattern = cf.Create_Dash_Pattern(WT_Line_Pattern::Count+100/*ID*/, 12/*num values*/, vN);
00049     if (pattern == NULL)
00050         return WT_Result::Out_Of_Memory_Error;
00051 
00052     whip_file->desired_rendition().dash_pattern() = *pattern;
00053     cf.Destroy(pattern);
00054     
00055     //Define some geometry using the dash pattern.
00056     WT_Logical_Point vP[2];
00057     vP[0].m_x = x;
00058     vP[0].m_y = vP[1].m_y = y-50;
00059     vP[1].m_x = x+500;
00060     WT_Polyline *pline = cf.Create_Polyline(2, vP, WD_False);
00061     if (pline == NULL)
00062         return WT_Result::Out_Of_Memory_Error;
00063 
00064     //Serialize it.
00065     WD_CHECK(pline->serialize(*whip_file));
00066     cf.Destroy(pline);
00067     
00068     //Restore the previous dash pattern.
00069     whip_file->desired_rendition().dash_pattern() = *previous_pattern;
00070     cf.Destroy( previous_pattern );
00071 
00072     return WT_Result::Success;
00073 }

Generated on Tue Jan 6 22:40:01 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5