info3d_visu.h 6.55 KB
Newer Older
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
jean-pierre charras's avatar
jean-pierre charras committed
4
 * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * 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
 */

/**
jean-pierre charras's avatar
jean-pierre charras committed
27
 * @file info3d_visu.h
28 29 30 31 32
 */

#ifndef __INFO3D_VISU_H__
#define __INFO3D_VISU_H__

33
#include <wxBasePcbFrame.h>                     // m_auimanager member.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#include <layers_id_colors_and_visibility.h>    // Layers id definitions

#include <wx/glcanvas.h>

#ifdef __WXMAC__
#  ifdef __DARWIN__
#    include <OpenGL/glu.h>
#  else
#    include <glu.h>
#  endif
#else
#  include <GL/glu.h>
#endif

#include <3d_struct.h>

50 51 52 53 54 55 56 57 58 59 60 61 62 63
#define m_ROTX  m_Rot[0]
#define m_ROTY  m_Rot[1]
#define m_ROTZ  m_Rot[2]


class S3D_COLOR     /* 3D color (R, G, B) 3 floats range 0 to 1.0*/
{
public:
    double m_Red, m_Green, m_Blue;
public: S3D_COLOR()
    {
        m_Red = m_Green = m_Blue = 0;
    }
};
64 65 66 67 68

/* information needed to display 3D board */
class INFO3D_VISU
{
public:
69 70 71
    enum DISPLAY3D_FLG {
        FL_AXIS=0, FL_MODULE, FL_ZONE,
        FL_COMMENTS, FL_DRAWINGS, FL_ECO1, FL_ECO2,
72
        FL_GRID,
jean-pierre charras's avatar
jean-pierre charras committed
73
        FL_USE_COPPER_THICKNESS,
74 75 76
        FL_LAST
    };

jean-pierre charras's avatar
jean-pierre charras committed
77 78 79 80
    double      m_Beginx, m_Beginy;                 // position of mouse (used in drag commands)
    double      m_Quat[4];                          // orientation of 3D view
    double      m_Rot[4];                           // rotation parameters of 3D view
    double      m_Zoom;                             // 3D zoom value
81
    double      m_3D_Grid;                          // 3D grid value, in mm
82
    S3D_COLOR   m_BgColor;
jean-pierre charras's avatar
jean-pierre charras committed
83 84 85
    bool        m_DrawFlags[FL_LAST];               // Enable/disable flags (see DISPLAY3D_FLG list)
    wxPoint     m_BoardPos;                         // center board actual position in board units
    wxSize      m_BoardSize;                        // board actual size in board units
86
    int         m_CopperLayersCount;                // Number of copper layers actually used by the board
87 88 89

    const BOARD_DESIGN_SETTINGS* m_BoardSettings;   // Link to current board design settings

jean-pierre charras's avatar
jean-pierre charras committed
90 91 92 93 94 95
    double  m_BiuTo3Dunits;                         // Normalization scale to convert board
                                                    // internal units to 3D units
                                                    // to scale 3D units between -1.0 and +1.0
    double  m_CurrentZpos;                          // temporary storage of current value of Z position,
                                                    // used in some calculation
private:
96
    double  m_LayerZcoord[LAYER_COUNT];             // Z position of each layer (normalized)
jean-pierre charras's avatar
jean-pierre charras committed
97
    double  m_CopperThickness;                      // Copper thickness (normalized)
98 99
    double  m_EpoxyThickness;                       // Epoxy thickness (normalized)
    double  m_NonCopperLayerThickness;              // Non copper layers thickness
100 101 102

public: INFO3D_VISU();
    ~INFO3D_VISU();
jean-pierre charras's avatar
jean-pierre charras committed
103 104 105 106 107 108 109 110

    /**
     * Function InitSettings
     * Initialize info 3D Parameters from aBoard
     * @param aBoard: the board to display
     */
    void InitSettings( BOARD* aBoard );

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    /**
     * function GetModulesZcoord3DIU
     * @return the Z coordinate of the module, in 3D Units
     * @param aIsFlipped: true for modules on Front (top) layer, false
     * if on back (bottom) layer
     * Used to know the Z position of 3D shapes
     */
    double GetModulesZcoord3DIU( bool aIsFlipped )
    {
        if(  aIsFlipped )
            return m_LayerZcoord[ADHESIVE_N_BACK] - m_NonCopperLayerThickness;
        else
            return m_LayerZcoord[ADHESIVE_N_FRONT] + m_NonCopperLayerThickness;
    }

jean-pierre charras's avatar
jean-pierre charras committed
126
    /**
127
     * function GetLayerZcoordBIU
jean-pierre charras's avatar
jean-pierre charras committed
128
     * @return the Z coordinate of the layer aLayer, in Board Internal Units
129
     * @param aLayerId: the layer number
jean-pierre charras's avatar
jean-pierre charras committed
130
     */
131
    int GetLayerZcoordBIU( int aLayerId )
jean-pierre charras's avatar
jean-pierre charras committed
132
    {
133
        return (int) (m_LayerZcoord[aLayerId] / m_BiuTo3Dunits );
jean-pierre charras's avatar
jean-pierre charras committed
134 135
    }

136 137 138 139 140 141 142 143
    /**
     * function GetCopperThicknessBIU
     * @return the thickness (Z size) of the copper, in Board Internal Units
     * note: the thickness (Z size) of the copper is not the thickness
     * of the layer (the thickness of the layer is the epoxy thickness / layer count)
     *
     * Note: if m_DrawFlags[FL_USE_COPPER_THICKNESS] is not set, returns 0
     */
jean-pierre charras's avatar
jean-pierre charras committed
144 145 146 147 148 149 150
    int GetCopperThicknessBIU() const
    {
        return m_DrawFlags[FL_USE_COPPER_THICKNESS] ?
            (int) (m_CopperThickness / m_BiuTo3Dunits )
            : 0;
    }

151 152 153 154
    /**
     * function GetEpoxyThicknessBIU
     * @return the thickness (Z size) of the epoxy board, in Board Internal Units
     */
jean-pierre charras's avatar
jean-pierre charras committed
155 156 157 158 159
    int GetEpoxyThicknessBIU() const
    {
        return (int) (m_EpoxyThickness / m_BiuTo3Dunits );
    }

160 161 162 163 164 165 166
    /**
     * function GetNonCopperLayerThicknessBIU
     * @return the thickness (Z size) of a technical layer,
     *  in Board Internal Units
     *
     * Note: if m_DrawFlags[FL_USE_COPPER_THICKNESS] is not set, returns 0
     */
jean-pierre charras's avatar
jean-pierre charras committed
167 168 169 170 171 172
    int GetNonCopperLayerThicknessBIU() const
    {
        return  m_DrawFlags[FL_USE_COPPER_THICKNESS] ?
            (int) (m_NonCopperLayerThickness / m_BiuTo3Dunits )
            : 0;
    }
173 174 175 176 177 178 179 180 181 182 183 184 185 186

    /**
     * function GetNonCopperLayerThicknessBIU
     * @return the thickness (Z size) of the copper or a technical layer,
     *  in Board Internal Units, depending on the layer id
     *
     * Note: if m_DrawFlags[FL_USE_COPPER_THICKNESS] is not set, returns 0
     */
    int GetLayerObjectThicknessBIU( int aLayerId) const
    {
        return aLayerId >= FIRST_NO_COPPER_LAYER ?
                        GetNonCopperLayerThicknessBIU() :
                        GetCopperThicknessBIU();
    }
187 188
};

jean-pierre charras's avatar
jean-pierre charras committed
189
extern INFO3D_VISU g_Parm_3D_Visu;
190

191
#endif /*  __INFO3D_VISU_H__ */