class_bitmap_base.h 6.67 KB
Newer Older
1 2 3 4 5 6
/**
 * @file class_bitmap_base.h
 *
 */

/*
7
 * This program source code file is part of KiCad, a free EDA CAD application.
8 9
 *
 * Copyright (C) 2011 jean-pierre.charras
10
 * Copyright (C) 2011 KiCad Developers, see change_log.txt for contributors.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#ifndef _BITMAP_BASE_H_
#define _BITMAP_BASE_H_


34
#include <sch_item_struct.h>
35 36

/**
37
 * This class handle bitmap images in KiCad.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
 * It is not intended to be used alone, but inside an other class,
 * so all methods are protected ( or private )
 * It is used in SCH_BITMAP class  (and other in futute)
 *
 * Remember not all plotters are able to plot a bitmap
 * Mainly GERBER plotters cannot.
 */
class BITMAP_BASE
{
public:
    double    m_Scale;              // The scaling factor of the bitmap
                                    // With m_pixelScaleFactor, controls the actual draw size
private:
    wxImage*  m_image;              // the raw image data (png format)
    wxBitmap* m_bitmap;             // the bitmap used to draw/plot image
    double    m_pixelScaleFactor;   // The scaling factor of the bitmap
                                    // to convert the bitmap size (in pixels)
55
                                    // to internal KiCad units
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
                                    // Usually does not change


public: BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );

    BITMAP_BASE( const BITMAP_BASE& aSchBitmap );

    ~BITMAP_BASE()
    {
        delete m_bitmap;
        delete m_image;
    }


    /*
     * Accessors:
     */
    double GetPixelScaleFactor() { return m_pixelScaleFactor; }
    void SetPixelScaleFactor( double aSF ) { m_pixelScaleFactor = aSF; }
75 76 77 78 79 80 81 82
    wxImage* GetImageData() { return m_image; }

    /*
     * Function RebuildBitmap
     * Rebuild the internal bitmap used to draw/plot image
     * must be called after a m_image change
     */
    void RebuildBitmap() { *m_bitmap = wxBitmap( *m_image ); }
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

    /**
     * Function ImportData
     * Copy aItem image to me and update m_bitmap
     */
    void ImportData( BITMAP_BASE* aItem );

    /**
     * Function GetScalingFactor
     * @return the scaling factor from pixel size to actual draw size
     * this scaling factor  depend on m_pixelScaleFactor and m_Scale
     * m_pixelScaleFactor gives the scaling factor between a pixel size and
     * the internal schematic units
     * m_Scale is an user dependant value, and gives the "zoom" value
     *  m_Scale = 1.0 = original size of bitmap.
     *  m_Scale < 1.0 = the bitmap is drawn smaller than its original size.
     *  m_Scale > 1.0 = the bitmap is drawn bigger than its original size.
     */
    double GetScalingFactor() const
    {
        return m_pixelScaleFactor * m_Scale;
    }


    /**
     * Function GetSize
     * @returns the actual size (in user units, not in pixels) of the image
     */
    wxSize   GetSize() const;

113 114 115 116 117 118 119 120 121 122 123 124
    /**
     * Function GetSizePixels
     * @returns the size in pixels of the image
     */
    wxSize GetSizePixels() const
    {
        if( m_image )
            return wxSize( m_image->GetWidth(), m_image->GetHeight() );
        else
            return wxSize(0,0);
    }

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    /**
     * Function GetBoundingBox
     * returns the orthogonal, bounding box of this object for display
     * purposes.  This box should be an enclosing perimeter for visible
     * components of this object, and the units should be in the pcb or
     * schematic coordinate system.  It is OK to overestimate the size
     * by a few counts.
     */
    EDA_RECT GetBoundingBox() const;

    void     DrawBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPos );

    /**
     * Function ReadImageFile
     * Reads and stores an image file. Init the bitmap used to draw this item
     * format.
     * supported images formats are format supported by wxImage
     * if all handlers are loaded
     * by default, .png, .jpeg are alway loaded
     * @param aFullFilename The full filename of the image file to read.
     * @return bool - true if success reading else false.
     */
    bool     ReadImageFile( const wxString& aFullFilename );

    /**
     * Function
     * writes the bitmap data to aFile
     * The format is png, in Hexadecimal form:
     * If the hexadecimal data is converted to binary it gives exactly a .png image data
     * @param aFile The FILE to write to.
     * @return bool - true if success writing else false.
     */
    bool     SaveData( FILE* aFile ) const;

    /**
     * Load an image data saved by SaveData (png, in Hexadecimal form)
     * @param aLine - Essentially this is file to read schematic junction from.
     * @param aErrorMsg - Description of the error if an error occurs while loading the
     *                    png bimap data.
     * @return true if the bitmap loaded successfully.
     */
    bool     LoadData( LINE_READER& aLine, wxString& aErrorMsg );


    /**
     * Function Mirror
     * Mirror image vertically (i.e. relative to its horizontal X axis )
     *  or horizontally (i.e relative to its vertical Y axis)
     * @param aVertically = false to mirror horizontally
     *                      or true to mirror vertically
     */
    void     Mirror( bool aVertically );

    /**
     * Function Rotate
     * Rotate image CW or CCW.
     * @param aRotateCCW = true to rotate CCW
     */
    void     Rotate( bool aRotateCCW );

    /**
     * Function PlotImage
     * Plot bitmap on plotter.
     * If the plotter does not support bitmaps, plot a
     * @param aPlotter = the plotter to use
     * @param aPos = the position od the center of the bitmap
     * @param aDefaultColor = the color used to plot the rectangle when bitmap is not supported
     * @param aDefaultPensize = the pen size used to plot the rectangle when bitmap is not supported
     */
194 195
    void     PlotImage( PLOTTER* aPlotter, const wxPoint& aPos, 
		        EDA_COLOR_T aDefaultColor, int aDefaultPensize );
196 197 198 199
};


#endif    // _BITMAP_BASE_H_