00001 /*! \file wx/canextobj/imageioh.h 00002 \author Klaas Holwerda 00003 00004 Copyright: 2000-2004 (c) Klaas Holwerda 00005 00006 Licence: wxWidgets Licence 00007 00008 RCS-ID: $Id: imageioh.h,v 1.17 2009/10/01 19:22:35 titato Exp $ 00009 */ 00010 00011 #ifndef __A2D_WXIMAGEIOH_H__ 00012 #define __A2D_WXIMAGEIOH_H__ 00013 00014 #ifndef WX_PRECOMP 00015 #include "wx/wx.h" 00016 #endif 00017 00018 #include "wx/canvas/canmod.h" 00019 #include "wx/editor/sttool.h" 00020 00021 00022 //! Input and output handler for a2dCanvasDocument to/from a wxImage 00023 /*! 00024 \ingroup fileio 00025 */ 00026 class A2DEDITORDLLEXP a2dCanvasDocumentIOHandlerImageIn : public a2dIOHandlerStrIn 00027 { 00028 public: 00029 //! Constructor. 00030 a2dCanvasDocumentIOHandlerImageIn( wxBitmapType type = wxBITMAP_TYPE_ANY ); 00031 00032 //! Destructor. 00033 ~a2dCanvasDocumentIOHandlerImageIn(); 00034 00035 //! test header of the file to see if it can be loaded 00036 virtual bool CanLoad( a2dDocumentInputStream& stream, const wxObject* obj = NULL, wxClassInfo* docClassInfo = NULL ); 00037 00038 //! load a complete document which contains an image 00039 /*! 00040 */ 00041 virtual bool Load( a2dDocumentInputStream& stream , wxObject* doc ); 00042 00043 //! Set the size of the image to create. 00044 void SetImageSize( const wxSize& size ) { m_imageSize = size; } 00045 00046 //! set the image type to load from, wxBITMAP_TYPE_ANY means outdetect from filename in CanSave(). 00047 void SetType( wxBitmapType type ) { m_type = type; } 00048 00049 //! return the image type to load from, wxBITMAP_TYPE_ANY means outdetect from filename in CanSave(). 00050 wxBitmapType GetType() { return m_type; } 00051 00052 protected: 00053 00054 //! for the stream, detect what image type it contains 00055 wxBitmapType DetectImageType(); 00056 00057 //! the document to store/load the data found into 00058 a2dCanvasDocument* m_doc; 00059 00060 //! image size that will be created. 00061 wxSize m_imageSize; 00062 00063 //! image type 00064 wxBitmapType m_type; 00065 00066 }; 00067 00068 //! Input and output handler for a2dCanvasDocument to/from a wxImage 00069 /*! 00070 This IoHandler is to render parts of a a2dCanvasDocument to an wxImage, and save this as 00071 a bitmap to a stream. The maximum size of the bitmap in X or Y is given upfront or else asked for. 00072 The a2dCanvasObject to display is set, or the root object of the a2dCanvasDocument is used. 00073 The part to display is set as a rectangle defined in world coordinates. That part seen from the 00074 m_showObject, is rendered to the image. The image is sized, taking into account the maximum size, such 00075 that the view rectangle fits it. The image size can be set upfront, in which case the drawing will be 00076 centered on that image size. 00077 00078 The rendering itself is done via a a2dDrawer2D, which can be set. The default is a2dMemDcDrawer. 00079 You can use a2dAggDrawer for antialiased drawing etc. 00080 00081 \ingroup fileio 00082 */ 00083 class A2DEDITORDLLEXP a2dCanvasDocumentIOHandlerImageOut : public a2dIOHandlerStrOut 00084 { 00085 public: 00086 //! Constructor. 00087 a2dCanvasDocumentIOHandlerImageOut( wxBitmapType type = wxBITMAP_TYPE_ANY ); 00088 00089 //! Destructor. 00090 ~a2dCanvasDocumentIOHandlerImageOut(); 00091 00092 //! this handler can also save as CVG 00093 bool CanSave( const wxObject* obj = NULL ); 00094 00095 //! save a2dCanvasDocument as image 00096 virtual bool Save( a2dDocumentOutputStream& stream, const wxObject* obj ); 00097 00098 //! document will be rendered as seen from this object, if NULL, the root of the document will be used. 00099 void SetShowObject( a2dCanvasObject* showObject ) { m_showObject = showObject; }; 00100 00101 //!return pointer of then currently shown object on the drawer. 00102 /*! 00103 \return pointer to the current object that is shown. 00104 */ 00105 a2dCanvasObject* GetShowObject() const { return m_showObject; } 00106 00107 //! render the document into an image. 00108 wxImage RenderImage( a2dCanvasDocument* document ); 00109 00110 //! Set the size of the image to create. 00111 void SetImageSize( const wxSize& size ) { m_imageSize = size; } 00112 00113 //! Give the virtual size to be rendered to an image. 00114 /*! 00115 Here you give the minimum and maximum in world coordinates, which must be displayed on the bitmap. 00116 00117 SetImageSize() is used for the image size itself. 00118 00119 \param minx minimum x coordinate of display area 00120 \param miny minimum y coordinate of display area 00121 \param maxx maximum x coordinate of display area 00122 \param maxy maximum y coordinate of display area 00123 00124 \remark these setting are only used when m_automaticScale is set false. 00125 */ 00126 void SetViewRectangle( double minx, double miny, double maxx, double maxy ); 00127 00128 //! Give the virtual size to be rendered to an image as boundingbox 00129 /*! 00130 Here you give the minimum and maximum in world coordinates, which must be displayed on the bitmap. 00131 00132 \param viewBox boundingbox in world coordinates to display 00133 */ 00134 void SetViewRectangle( a2dBoundingBox viewBox ) { m_viewBox = viewBox; } 00135 00136 //!set if the Yaxis goes up or down 00137 void SetYaxis(bool up) { m_yaxis = up; } 00138 00139 //!get y axis orientation 00140 inline bool GetYaxis() const { return m_yaxis; } 00141 00142 //! set the image type to save to, wxBITMAP_TYPE_ANY means outdetect from filename in CanSave(). 00143 void SetType( wxBitmapType type ) { m_type = type; } 00144 00145 //! return the image type to save to, wxBITMAP_TYPE_ANY means outdetect from filename in CanSave(). 00146 long GetType() const { return m_type; } 00147 00148 //! when image size is calculated, this is the maximum size possible 00149 void SetMaxWidthHeight( long maxWidthHeight ) { m_maxWidthHeight = maxWidthHeight; } 00150 00151 //! leafs a border of this amount of pixels around the drawing 00152 void SetBorder( wxUint16 border, bool percentual = true ); 00153 00154 //! set the internal m_drawer2D to be used for rendering the document 00155 void SetDrawer2D( a2dDrawer2D* drawer2d ); 00156 00157 //! get the internal m_drawer2D that is used for rendering the document 00158 a2dDrawer2D* GetDrawer2D() const { return m_drawer2D; } 00159 00160 protected: 00161 00162 //! the drawing engine to use 00163 a2dDrawer2D* m_drawer2D; 00164 00165 //! the document to store/load the data found into 00166 a2dCanvasDocument* m_doc; 00167 00168 //! image size that will be created. 00169 wxSize m_imageSize; 00170 00171 //! calculate image size as set by user when m_imageSize = (0,0) else eqauls m_imageSize 00172 wxSize m_imageSizeCalc; 00173 00174 //! render the document using this object as ShowObject. 00175 a2dCanvasObject* m_showObject; 00176 00177 //! create a border in this ammount of pixels. 00178 int m_border; 00179 00180 //! border is not in pixel but a percentage of the smallest height/width 00181 bool m_borderpercentual; 00182 00183 //! image type 00184 wxBitmapType m_type; 00185 00186 //! image type as detected in CanSave(), wil be used in Save() if m_type is wxBITMAP_TYPE_ANY 00187 wxBitmapType m_typeDetectedFromFilename; 00188 00189 //! axis is up or down 00190 bool m_yaxis; 00191 00192 //! viewing area in world coordinates to display on bitmap 00193 a2dBoundingBox m_viewBox; 00194 00195 long m_maxWidthHeight; 00196 }; 00197 00198 #endif 00199