2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2020-03-18 22:48:36 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* 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 EDA_3D_CANVAS_H
|
|
|
|
#define EDA_3D_CANVAS_H
|
|
|
|
|
2020-11-03 00:13:31 +00:00
|
|
|
#include <atomic>
|
2020-03-26 14:05:20 +00:00
|
|
|
#include "board_adapter.h"
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "3d_rendering/3d_render_raytracing/accelerators/accelerator_3d.h"
|
|
|
|
#include "3d_rendering/render_3d_base.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
#include "3d_cache/3d_cache.h"
|
2017-12-07 15:57:47 +00:00
|
|
|
#include <gal/hidpi_gl_canvas.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <wx/image.h>
|
|
|
|
#include <wx/timer.h>
|
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
class WX_INFOBAR;
|
2020-03-18 22:48:36 +00:00
|
|
|
class wxStatusBar;
|
|
|
|
class BOARD;
|
2021-01-02 21:05:29 +00:00
|
|
|
class RENDER_3D_RAYTRACE;
|
|
|
|
class RENDER_3D_LEGACY;
|
2020-01-06 13:43:18 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement a canvas based on a wxGLCanvas
|
|
|
|
*/
|
2017-12-07 15:57:47 +00:00
|
|
|
class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-16 22:10:42 +00:00
|
|
|
public:
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Create a new 3D Canvas with an attribute list.
|
|
|
|
*
|
|
|
|
* @param aParent the parent creator of this canvas.
|
|
|
|
* @param aAttribList a list of openGL options created by GetOpenGL_AttributesList.
|
|
|
|
* @param aBoard The board.
|
|
|
|
* @param aSettings the settings options to be used by this canvas.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
2021-07-18 15:44:54 +00:00
|
|
|
EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList,
|
2021-01-02 21:05:29 +00:00
|
|
|
BOARD_ADAPTER& aSettings, CAMERA& aCamera, S3D_CACHE* a3DCachePointer );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
~EDA_3D_CANVAS();
|
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Set a dispatcher that processes events and forwards them to tools.
|
|
|
|
*
|
|
|
|
* #DRAW_PANEL_GAL does not take over the ownership. Passing NULL disconnects all event
|
2020-03-18 22:48:36 +00:00
|
|
|
* handlers from the DRAW_PANEL_GAL and parent frame.
|
2020-12-16 22:10:42 +00:00
|
|
|
*
|
|
|
|
* @param aEventDispatcher is the object that will be used for dispatching events.
|
2020-03-18 22:48:36 +00:00
|
|
|
*/
|
|
|
|
void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
void SetStatusBar( wxStatusBar* aStatusBar )
|
|
|
|
{
|
|
|
|
m_parentStatusBar = aStatusBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetInfoBar( WX_INFOBAR* aInfoBar )
|
|
|
|
{
|
|
|
|
m_parentInfoBar = aInfoBar;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void ReloadRequest( BOARD* aBoard = nullptr, S3D_CACHE* aCachePointer = nullptr );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Query if there is a pending reload request.
|
|
|
|
*
|
|
|
|
* @return true if it wants to reload, false if there is no reload pending.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
bool IsReloadRequestPending() const
|
|
|
|
{
|
|
|
|
if( m_3d_render )
|
|
|
|
return m_3d_render->IsReloadRequestPending();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-16 14:28:46 +00:00
|
|
|
/**
|
|
|
|
* @return the current render ( a RENDER_3D_RAYTRACE* or a RENDER_3D_LEGACY* render )
|
|
|
|
*/
|
|
|
|
RENDER_3D_BASE* GetCurrentRender() const { return m_3d_render; }
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Request to render the current view in Raytracing mode.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void RenderRaytracingRequest();
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Request a screenshot and output it to the \a aDstImage
|
|
|
|
*
|
2016-07-19 17:35:25 +00:00
|
|
|
* @param aDstImage - Screenshot destination image
|
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
void GetScreenshot( wxImage& aDstImage );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Helper function to call view commands.
|
|
|
|
*
|
|
|
|
* @param aKeycode ascii key commands.
|
|
|
|
* @return true if the key code was handled, false if no command found for this code.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
2018-04-15 12:07:33 +00:00
|
|
|
bool SetView3D( int aKeycode );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-04-24 23:58:50 +00:00
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Enable or disable camera animation when switching to a pre-defined view.
|
2020-04-24 23:58:50 +00:00
|
|
|
*/
|
2021-06-17 11:21:06 +00:00
|
|
|
void SetAnimationEnabled( bool aEnable ) { m_animation_enabled = aEnable; }
|
|
|
|
bool GetAnimationEnabled() const { return m_animation_enabled; }
|
2020-04-24 23:58:50 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Set the camera animation moving speed multiplier option.
|
|
|
|
*
|
2021-06-17 11:21:06 +00:00
|
|
|
* @param aMultiplier one of the possible integer options: [1,2,3,4,5].
|
2020-04-24 23:58:50 +00:00
|
|
|
*/
|
2021-06-17 11:21:06 +00:00
|
|
|
void SetMovingSpeedMultiplier( int aMultiplier ) { m_moving_speed_multiplier = aMultiplier; }
|
|
|
|
int GetMovingSpeedMultiplier() const { return m_moving_speed_multiplier; }
|
2020-04-24 23:58:50 +00:00
|
|
|
|
2021-06-17 11:21:06 +00:00
|
|
|
int GetProjectionMode() const { return (int) m_camera.GetProjection(); };
|
|
|
|
void SetProjectionMode( int aMode ) { m_camera.SetProjection( (PROJECTION_TYPE) aMode ); }
|
2020-04-24 23:58:50 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Notify that the render engine was changed.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void RenderEngineChanged();
|
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Update the status bar with the position information.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void DisplayStatus();
|
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Schedule a refresh update of the canvas.
|
|
|
|
*
|
|
|
|
* @param aRedrawImmediately true will request a redraw, false will schedule a redraw
|
|
|
|
* after a short timeout.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void Request_refresh( bool aRedrawImmediately = true );
|
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
/**
|
|
|
|
* Used to forward events to the canvas from popups, etc.
|
|
|
|
*/
|
|
|
|
void OnEvent( wxEvent& aEvent );
|
2019-01-19 13:02:10 +00:00
|
|
|
|
|
|
|
private:
|
2020-12-16 22:10:42 +00:00
|
|
|
/**
|
|
|
|
* Called by a wxPaintEvent event
|
2020-07-14 13:52:01 +00:00
|
|
|
*/
|
|
|
|
void OnPaint( wxPaintEvent& aEvent );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 13:52:01 +00:00
|
|
|
/**
|
|
|
|
* The actual function to repaint the canvas.
|
2020-12-16 22:10:42 +00:00
|
|
|
*
|
|
|
|
* It is usually called by OnPaint() but because it does not use a wxPaintDC it can be
|
|
|
|
* called outside a wxPaintEvent
|
2020-07-14 13:52:01 +00:00
|
|
|
*/
|
|
|
|
void DoRePaint();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void OnEraseBackground( wxEraseEvent& event );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 13:52:01 +00:00
|
|
|
void OnRefreshRequest( wxEvent& aEvent );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void OnMouseWheel( wxMouseEvent& event );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
|
|
|
|
void OnMagnify( wxMouseEvent& event );
|
|
|
|
#endif
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void OnMouseMove( wxMouseEvent& event );
|
|
|
|
void OnLeftDown( wxMouseEvent& event );
|
|
|
|
void OnLeftUp( wxMouseEvent& event );
|
|
|
|
void OnMiddleUp( wxMouseEvent& event );
|
|
|
|
void OnMiddleDown( wxMouseEvent& event );
|
2016-07-19 17:35:25 +00:00
|
|
|
void OnTimerTimeout_Editing( wxTimerEvent& event );
|
2021-01-02 21:05:29 +00:00
|
|
|
void OnCloseWindow( wxCloseEvent& event );
|
|
|
|
void OnResize( wxSizeEvent& event );
|
2016-07-19 17:35:25 +00:00
|
|
|
void OnTimerTimeout_Redraw( wxTimerEvent& event );
|
|
|
|
|
2017-11-02 20:41:29 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
*Stop the editing time so it will not timeout.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void stop_editingTimeOut_Timer();
|
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Reset the editing timer.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void restart_editingTimeOut_Timer();
|
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Start a camera movement.
|
|
|
|
*
|
|
|
|
* @param aMovingSpeed the time speed.
|
|
|
|
* @param aRenderPivot if it should display pivot cursor while move.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
2020-03-18 22:48:36 +00:00
|
|
|
void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* This function hits a ray to the board and start a movement.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void move_pivot_based_on_cur_mouse_position();
|
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Render the pivot cursor.
|
|
|
|
*
|
|
|
|
* @param t time between 0.0 and 1.0.
|
|
|
|
* @param aScale scale to apply on the cursor.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void render_pivot( float t, float aScale );
|
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* @return true if OpenGL initialization succeeded.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
bool initializeOpenGL();
|
|
|
|
|
|
|
|
/**
|
2020-12-16 22:10:42 +00:00
|
|
|
* Free created targets and openGL context.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void releaseOpenGL();
|
|
|
|
|
2020-09-04 00:00:56 +00:00
|
|
|
RAY getRayAtCurrrentMousePosition();
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
private:
|
2020-03-18 22:48:36 +00:00
|
|
|
TOOL_DISPATCHER* m_eventDispatcher;
|
|
|
|
wxStatusBar* m_parentStatusBar; // Parent statusbar to report progress
|
2020-06-03 23:00:40 +00:00
|
|
|
WX_INFOBAR* m_parentInfoBar;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
wxGLContext* m_glRC; // Current OpenGL context
|
|
|
|
bool m_is_opengl_initialized;
|
2020-10-05 00:06:53 +00:00
|
|
|
bool m_is_opengl_version_supported;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
wxTimer m_editing_timeout_timer; // Expires after some time signaling that
|
2020-03-18 22:48:36 +00:00
|
|
|
// the mouse / keyboard movements are over
|
|
|
|
wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
|
2020-11-03 00:13:31 +00:00
|
|
|
std::atomic_flag m_is_currently_painting; // Avoid drawing twice at the same time
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
bool m_mouse_is_moving; // Mouse activity is in progress
|
|
|
|
bool m_mouse_was_moved;
|
|
|
|
bool m_camera_is_moving; // Camera animation is ongoing
|
|
|
|
bool m_render_pivot; // Render the pivot while camera moving
|
|
|
|
float m_camera_moving_speed; // 1.0f will be 1:1
|
|
|
|
unsigned m_strtime_camera_movement; // Ticktime of camera movement start
|
2020-04-24 23:58:50 +00:00
|
|
|
bool m_animation_enabled; // Camera animation enabled
|
|
|
|
int m_moving_speed_multiplier; // Camera animation speed multiplier option
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
|
2021-01-02 21:05:29 +00:00
|
|
|
CAMERA& m_camera;
|
|
|
|
RENDER_3D_BASE* m_3d_render;
|
|
|
|
RENDER_3D_RAYTRACE* m_3d_render_raytracing;
|
|
|
|
RENDER_3D_LEGACY* m_3d_render_ogl_legacy;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
static const float m_delta_move_step_factor; // Step factor to used with cursor on
|
|
|
|
// relation to the current zoom
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
bool m_opengl_supports_raytracing;
|
|
|
|
bool m_render_raytracing_was_requested;
|
2019-01-13 19:04:34 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
ACCELERATOR_3D* m_accelerator3DShapes; // used for mouse over searching
|
2020-09-04 00:00:56 +00:00
|
|
|
|
2021-05-11 19:52:28 +00:00
|
|
|
BOARD_ITEM* m_currentRollOverItem;
|
2020-09-04 00:00:56 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
|
|
|
* Trace mask used to enable or disable the trace output of this class.
|
|
|
|
* The debug output can be turned on by setting the WXTRACE environment variable to
|
|
|
|
* "KI_TRACE_EDA_3D_CANVAS". See the wxWidgets documentation on wxLogTrace for
|
|
|
|
* more information.
|
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
static const wxChar* m_logTrace;
|
2016-07-19 17:35:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // EDA_3D_CANVAS_H
|