2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-17 15:31:21 +00:00
|
|
|
/**
|
|
|
|
* @file 3d_viewer.h
|
|
|
|
*/
|
2011-11-10 15:55:05 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
#ifndef __3D_VIEWER_H__
|
|
|
|
#define __3D_VIEWER_H__
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wxBasePcbFrame.h> // m_auimanager member.
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error Please set wxUSE_GLCANVAS to 1 in setup.h.
|
|
|
|
#endif
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/glcanvas.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
# ifdef __DARWIN__
|
|
|
|
# include <OpenGL/glu.h>
|
|
|
|
# else
|
|
|
|
# include <glu.h>
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# include <GL/glu.h>
|
|
|
|
#endif
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <3d_struct.h>
|
|
|
|
#include <id.h>
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
class BOARD_DESIGN_SETTINGS;
|
|
|
|
class TRACK;
|
|
|
|
class TEXTE_PCB;
|
|
|
|
class DRAWSEGMENT;
|
|
|
|
class ZONE_CONTAINER;
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
#define KICAD_DEFAULT_3D_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
|
2008-10-26 17:39:17 +00:00
|
|
|
|
2007-10-27 12:24:09 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
#define LIB3D_PATH wxT( "packages3d" )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
/**
|
|
|
|
* Command IDs for the 3D viewer.
|
|
|
|
*
|
|
|
|
* Please add IDs that are unique to the 3D viewer here and not in the global
|
|
|
|
* id.h file. This will prevent the entire project from being rebuilt when
|
|
|
|
* adding new commands to the 3D viewer.
|
|
|
|
*/
|
|
|
|
enum id_3dview_frm
|
|
|
|
{
|
|
|
|
ID_START_COMMAND_3D = ID_END_LIST,
|
|
|
|
ID_ROTATE3D_X_NEG,
|
|
|
|
ID_ROTATE3D_X_POS,
|
|
|
|
ID_ROTATE3D_Y_NEG,
|
|
|
|
ID_ROTATE3D_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,
|
|
|
|
ID_POPUP_3D_VIEW_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-17 15:31:21 +00:00
|
|
|
class EDA_3D_CANVAS;
|
2011-08-03 15:09:39 +00:00
|
|
|
class EDA_3D_FRAME;
|
2007-06-05 12:10:51 +00:00
|
|
|
class Info_3D_Visu;
|
|
|
|
class S3D_Vertex;
|
|
|
|
class SEGVIA;
|
|
|
|
|
|
|
|
|
|
|
|
#define m_ROTX m_Rot[0]
|
|
|
|
#define m_ROTY m_Rot[1]
|
|
|
|
#define m_ROTZ m_Rot[2]
|
|
|
|
|
|
|
|
/* information needed to display 3D board */
|
|
|
|
class Info_3D_Visu
|
|
|
|
{
|
|
|
|
public:
|
2009-11-04 20:46:53 +00:00
|
|
|
double m_Beginx, m_Beginy; /* position of mouse */
|
|
|
|
double m_Quat[4]; /* orientation of object */
|
|
|
|
double m_Rot[4]; /* man rotation of object */
|
|
|
|
double m_Zoom; /* field of view in degrees */
|
2009-04-05 20:49:15 +00:00
|
|
|
S3D_Color m_BgColor;
|
2009-11-04 20:46:53 +00:00
|
|
|
bool m_Draw3DAxis;
|
|
|
|
bool m_Draw3DModule;
|
|
|
|
bool m_Draw3DZone;
|
|
|
|
bool m_Draw3DComments;
|
|
|
|
bool m_Draw3DDrawings;
|
|
|
|
bool m_Draw3DEco1;
|
|
|
|
bool m_Draw3DEco2;
|
|
|
|
wxPoint m_BoardPos;
|
|
|
|
wxSize m_BoardSize;
|
|
|
|
int m_Layers;
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
|
|
|
|
const BOARD_DESIGN_SETTINGS* m_BoardSettings; // Link to current board design settings
|
|
|
|
|
|
|
|
double m_Epoxy_Width; // Epoxy thickness (normalized)
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
double m_BoardScale; /* Normalization scale for coordinates:
|
|
|
|
* when scaled between -1.0 and +1.0 */
|
|
|
|
double m_LayerZcoord[32];
|
2011-11-10 15:55:05 +00:00
|
|
|
double m_ActZpos;
|
2011-08-03 15:09:39 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
public: Info_3D_Visu();
|
2009-04-05 20:49:15 +00:00
|
|
|
~Info_3D_Visu();
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-17 15:31:21 +00:00
|
|
|
class EDA_3D_CANVAS : public wxGLCanvas
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
private:
|
2012-02-25 19:55:40 +00:00
|
|
|
bool m_init;
|
|
|
|
GLuint m_gllist;
|
2010-10-04 12:58:07 +00:00
|
|
|
/// Tracks whether to use Orthographic or Perspective projection
|
2012-02-25 19:55:40 +00:00
|
|
|
// TODO: Does this belong here, or in EDA_3D_FRAME ???
|
|
|
|
bool m_ortho;
|
|
|
|
wxGLContext* m_glRC;
|
|
|
|
wxRealPoint m_draw3dOffset; // offset to draw the 3 mesh.
|
|
|
|
double m_ZBottom; // position of the back layer
|
|
|
|
double m_ZTop; // position of the front layer
|
2011-08-03 15:09:39 +00:00
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
public:
|
2011-09-17 15:31:21 +00:00
|
|
|
EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 );
|
|
|
|
~EDA_3D_CANVAS();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-02-25 19:55:40 +00:00
|
|
|
EDA_3D_FRAME* Parent() { return (EDA_3D_FRAME*)GetParent(); }
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
void ClearLists();
|
|
|
|
|
2012-02-25 19:55:40 +00:00
|
|
|
// Event functions:
|
2009-11-04 20:46:53 +00:00
|
|
|
void OnPaint( wxPaintEvent& event );
|
|
|
|
void OnEraseBackground( wxEraseEvent& event );
|
|
|
|
void OnChar( wxKeyEvent& event );
|
2010-01-11 14:44:49 +00:00
|
|
|
void OnMouseWheel( wxMouseEvent& event );
|
|
|
|
void OnMouseMove( wxMouseEvent& event );
|
2009-11-04 20:46:53 +00:00
|
|
|
void OnRightClick( wxMouseEvent& event );
|
|
|
|
void OnPopUpMenu( wxCommandEvent& event );
|
|
|
|
void TakeScreenshot( wxCommandEvent& event );
|
2012-02-25 19:55:40 +00:00
|
|
|
void OnEnterWindow( wxMouseEvent& event );
|
|
|
|
|
|
|
|
// Display functions
|
|
|
|
GLuint DisplayCubeforTest(); // Just a test function
|
2009-11-04 20:46:53 +00:00
|
|
|
void SetView3D( int keycode );
|
|
|
|
void DisplayStatus();
|
|
|
|
void Redraw( bool finish = false );
|
|
|
|
void Render();
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function CreateDrawGL_List
|
|
|
|
* creates the OpenGL draw list items.
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
GLuint CreateDrawGL_List();
|
2009-11-04 20:46:53 +00:00
|
|
|
void InitGL();
|
|
|
|
void SetLights();
|
2012-02-25 19:55:40 +00:00
|
|
|
void SetOffset(double aPosX, double aPosY)
|
|
|
|
{
|
|
|
|
m_draw3dOffset.x = aPosX;
|
|
|
|
m_draw3dOffset.y = aPosY;
|
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
void Draw3D_Track( TRACK* track );
|
2011-08-03 15:09:39 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function Draw3D_SolidPolygonsInZones
|
2011-08-03 15:09:39 +00:00
|
|
|
* draw all solid polygons used as filled areas in a zone
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aZone = the zone to draw
|
2009-11-16 13:18:20 +00:00
|
|
|
*/
|
2010-12-29 17:47:32 +00:00
|
|
|
void Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone );
|
2010-08-19 14:21:05 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function Draw3D_Polygon
|
2010-08-19 14:21:05 +00:00
|
|
|
* draw one solid polygon
|
2011-08-03 15:09:39 +00:00
|
|
|
* @param aCornersList = a std::vector<wxPoint> list of corners, in physical coordinates
|
2010-08-19 14:21:05 +00:00
|
|
|
* @param aZpos = the z position in 3D units
|
|
|
|
*/
|
|
|
|
void Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Draw3D_Via
|
|
|
|
* draws 3D via as a cylinder and filled circles.
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
void Draw3D_Via( SEGVIA* via );
|
|
|
|
void Draw3D_DrawSegment( DRAWSEGMENT* segment );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Draw3D_DrawText
|
|
|
|
* draws 3D segments to create text objects.
|
|
|
|
* When DrawGraphicText is called to draw a text to an OpenGL DC
|
|
|
|
* it calls Draw3dTextSegm to each segment to draw.
|
|
|
|
* 2 parameters used by Draw3D_FilledSegment are not handled by DrawGraphicText
|
|
|
|
* but are used in Draw3D_FilledSegment().
|
|
|
|
* they are 2 local variables. This is an ugly, but trivial code.
|
|
|
|
* Using DrawGraphicText to draw all texts ensure texts have the same shape
|
|
|
|
* in all contexts
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
void Draw3D_DrawText( TEXTE_PCB* text );
|
2010-11-12 15:17:10 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/// Toggles orthographic projection on and off
|
2010-10-04 12:58:07 +00:00
|
|
|
void ToggleOrtho(){ m_ortho = !m_ortho ; Refresh(true);};
|
2011-08-03 15:09:39 +00:00
|
|
|
|
2010-10-04 12:58:07 +00:00
|
|
|
/// Returns the orthographic projection flag
|
|
|
|
bool ModeIsOrtho() { return m_ortho ;};
|
2010-11-12 15:17:10 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
//int Get3DLayerEnable(int act_layer);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-03 15:09:39 +00:00
|
|
|
class EDA_3D_FRAME : public wxFrame
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-05-01 12:46:33 +00:00
|
|
|
private:
|
2012-02-25 19:55:40 +00:00
|
|
|
wxString m_FrameName; // name used for writing and reading setup. It is "Frame3D"
|
2011-09-17 15:31:21 +00:00
|
|
|
EDA_3D_CANVAS* m_Canvas;
|
2011-12-16 13:32:23 +00:00
|
|
|
wxAuiToolBar* m_HToolBar;
|
|
|
|
wxAuiToolBar* m_VToolBar;
|
2011-04-13 19:30:27 +00:00
|
|
|
int m_InternalUnits;
|
|
|
|
wxPoint m_FramePos;
|
|
|
|
wxSize m_FrameSize;
|
|
|
|
wxAuiManager m_auimgr;
|
|
|
|
bool m_reloadRequest;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2011-08-03 15:09:39 +00:00
|
|
|
EDA_3D_FRAME( PCB_BASE_FRAME* parent, const wxString& title,
|
|
|
|
long style = KICAD_DEFAULT_3D_DRAWFRAME_STYLE );
|
|
|
|
~EDA_3D_FRAME()
|
2010-05-01 12:46:33 +00:00
|
|
|
{
|
|
|
|
m_auimgr.UnInit();
|
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-02-25 19:55:40 +00:00
|
|
|
PCB_BASE_FRAME* Parent() { return (PCB_BASE_FRAME*)GetParent(); }
|
2009-11-04 20:46:53 +00:00
|
|
|
void Exit3DFrame( wxCommandEvent& event );
|
|
|
|
void OnCloseWindow( wxCloseEvent& Event );
|
2009-04-05 20:49:15 +00:00
|
|
|
void ReCreateMenuBar();
|
|
|
|
void ReCreateHToolbar();
|
|
|
|
void ReCreateVToolbar();
|
|
|
|
void SetToolbars();
|
|
|
|
void GetSettings();
|
|
|
|
void SaveSettings();
|
2011-08-03 15:09:39 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function ReloadRequest
|
2010-05-01 12:46:33 +00:00
|
|
|
* must be called when reloading data from Pcbnew is needed
|
2011-09-17 15:31:21 +00:00
|
|
|
* mainly after edition of the board or footprint being displayed.
|
2010-10-04 12:58:07 +00:00
|
|
|
* mainly for the module editor.
|
2010-05-01 12:46:33 +00:00
|
|
|
*/
|
|
|
|
void ReloadRequest( )
|
|
|
|
{
|
|
|
|
m_reloadRequest = true;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
|
|
|
|
void OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu );
|
|
|
|
void OnKeyEvent( wxKeyEvent& event );
|
2011-07-05 12:46:14 +00:00
|
|
|
double BestZoom();
|
2009-11-04 20:46:53 +00:00
|
|
|
void RedrawActiveWindow( wxDC* DC, bool EraseBg );
|
|
|
|
void Process_Special_Functions( wxCommandEvent& event );
|
|
|
|
void Process_Zoom( wxCommandEvent& event );
|
2010-04-29 09:06:01 +00:00
|
|
|
void OnActivate( wxActivateEvent& event );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
void NewDisplay();
|
|
|
|
void Set3DBgColor();
|
|
|
|
void Set3DAxisOnOff();
|
|
|
|
void Set3DModuleOnOff();
|
|
|
|
void Set3DPlaceOnOff();
|
|
|
|
void Set3DZoneOnOff();
|
|
|
|
void Set3DCommentsOnOff();
|
|
|
|
void Set3DDrawingsOnOff();
|
|
|
|
void Set3DEco1OnOff();
|
|
|
|
void Set3DEco2OnOff();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
void SetGLColor( int color );
|
|
|
|
void Set_Object_Data( std::vector< S3D_Vertex >& aVertices );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
extern Info_3D_Visu g_Parm_3D_Visu;
|
2009-11-04 20:46:53 +00:00
|
|
|
extern double DataScale3D; // 3D scale units.
|
2009-05-06 11:55:36 +00:00
|
|
|
|
|
|
|
#endif /* __3D_VIEWER_H__ */
|