Push tool framework base down into TOOL_HOLDER.

This allows us to use it outside of EDA_BASE_FRAMEs (in this case, in
PANEL_PREVIEW_3D.)
This commit is contained in:
Jeff Young 2020-03-24 01:01:23 +00:00
parent 14788eec94
commit d69ebfae49
54 changed files with 1069 additions and 973 deletions

View File

@ -4,7 +4,7 @@
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015-2020 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
@ -24,8 +24,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "panel_prev_model.h"
#include "panel_prev_3d.h"
#include <3d_canvas/eda_3d_canvas.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <tools/3d_actions.h>
#include <tools/3d_controller.h>
#include <base_units.h>
#include <bitmaps.h>
#include <class_board.h>
@ -37,42 +41,11 @@
PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule,
std::vector<MODULE_3D_SETTINGS> *aParentModelList ) :
PANEL_PREV_3D_BASE( aParent, wxID_ANY )
std::vector<MODULE_3D_SETTINGS>* aParentModelList ) :
PANEL_PREV_3D_BASE( aParent, wxID_ANY )
{
m_userUnits = aFrame->GetUserUnits();
initPanel();
m_parentModelList = aParentModelList;
m_dummyModule = new MODULE( *aModule );
m_dummyBoard->Add( m_dummyModule );
// Set 3d viewer configuration for preview
m_settings3Dviewer = new CINFO3D_VISU();
// Create the 3D canvas
m_previewPane = new EDA_3D_CANVAS( this, COGL_ATT_LIST::GetAttributesList( true ),
m_dummyBoard, *m_settings3Dviewer,
aFrame->Prj().Get3DCacheManager() );
loadCommonSettings();
m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 );
}
PANEL_PREV_3D::~PANEL_PREV_3D()
{
delete m_settings3Dviewer;
delete m_dummyBoard;
delete m_previewPane;
}
void PANEL_PREV_3D::initPanel()
{
m_dummyBoard = new BOARD();
m_selected = -1;
@ -100,6 +73,58 @@ void PANEL_PREV_3D::initPanel()
for( wxSpinButton* button : spinButtonList )
button->SetRange(INT_MIN, INT_MAX );
m_parentModelList = aParentModelList;
m_dummyModule = new MODULE( *aModule );
m_dummyBoard->Add( m_dummyModule );
// Set 3d viewer configuration for preview
m_settings3Dviewer = new EDA_3D_SETTINGS();
// Create the 3D canvas
m_previewPane = new EDA_3D_CANVAS( this, COGL_ATT_LIST::GetAttributesList( true ),
m_dummyBoard, *m_settings3Dviewer,
aFrame->Prj().Get3DCacheManager() );
loadCommonSettings();
// Create the manager
m_toolManager = new TOOL_MANAGER;
m_toolManager->SetEnvironment( m_dummyBoard, nullptr, nullptr, this );
m_actions = new EDA_3D_ACTIONS();
m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
m_previewPane->SetEventDispatcher( m_toolDispatcher );
// Register tools
m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
m_toolManager->InitTools();
// Run the viewer control tool, it is supposed to be always active
m_toolManager->InvokeTool( "3DViewer.Control" );
m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 );
for( wxEventType eventType : { wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT } )
Connect( eventType, wxMenuEventHandler( PANEL_PREV_3D::OnMenuEvent ), NULL, this );
}
PANEL_PREV_3D::~PANEL_PREV_3D()
{
delete m_settings3Dviewer;
delete m_dummyBoard;
delete m_previewPane;
}
void PANEL_PREV_3D::OnMenuEvent( wxMenuEvent& aEvent )
{
if( !m_toolDispatcher )
aEvent.Skip();
else
m_toolDispatcher->DispatchWxEvent( aEvent );
}
@ -127,12 +152,12 @@ static double rotationFromString( const wxString& aValue )
if( rotation > MAX_ROTATION )
{
int n = rotation / MAX_ROTATION;
int n = KiROUND( rotation / MAX_ROTATION );
rotation -= MAX_ROTATION * n;
}
else if( rotation < -MAX_ROTATION )
{
int n = -rotation / MAX_ROTATION;
int n = KiROUND( -rotation / MAX_ROTATION );
rotation += MAX_ROTATION * n;
}
@ -351,6 +376,7 @@ void PANEL_PREV_3D::onMouseWheelOffset( wxMouseEvent& event )
if( m_userUnits == EDA_UNITS::INCHES )
{
step = OFFSET_INCREMENT_MIL/1000.0;
if( event.ShiftDown( ) )
step = OFFSET_INCREMENT_MIL_FINE/1000.0;
}
@ -372,13 +398,10 @@ void PANEL_PREV_3D::UpdateDummyModule( bool aReloadRequired )
{
m_dummyModule->Models().clear();
for( size_t i = 0; i < m_parentModelList->size(); ++i )
for( MODULE_3D_SETTINGS& model : *m_parentModelList)
{
if( m_parentModelList->at( i ).m_Preview )
{
m_dummyModule->Models().insert( m_dummyModule->Models().end(),
m_parentModelList->at( i ) );
}
if( model.m_Preview )
m_dummyModule->Models().push_back( model );
}
if( aReloadRequired )

View File

@ -39,7 +39,7 @@
#include "panel_prev_3d_base.h"
#include <vector>
#include <tools_holder.h>
#include <3d_canvas/eda_3d_canvas.h>
#include <3d_viewer_id.h>
@ -66,20 +66,20 @@
class S3D_CACHE;
class FILENAME_RESOLVER;
class BOARD;
class CINFO3D_VISU;
class EDA_3D_SETTINGS;
class MODULE;
class PANEL_PREV_3D: public PANEL_PREV_3D_BASE
class PANEL_PREV_3D: public EDA_3D_SETTINGS_HOLDER, public TOOLS_HOLDER, public PANEL_PREV_3D_BASE
{
public:
PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* aModule,
std::vector<MODULE_3D_SETTINGS> *aParentModelList );
std::vector<MODULE_3D_SETTINGS>* aParentModelList );
~PANEL_PREV_3D();
private:
EDA_3D_CANVAS* m_previewPane;
CINFO3D_VISU* m_settings3Dviewer;
EDA_3D_SETTINGS* m_settings3Dviewer;
BOARD* m_dummyBoard;
MODULE* m_dummyModule;
@ -91,8 +91,6 @@ private:
// Methods of the class
private:
void initPanel();
/**
* Load 3D relevant settings from the user configuration
*/
@ -184,6 +182,15 @@ private:
}
public:
/**
* The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu
* events aren't captured by the menus themselves.
*/
void OnMenuEvent( wxMenuEvent& aEvent );
wxWindow* GetToolCanvas() const override { return m_previewPane; }
EDA_3D_SETTINGS* GetSettings() override { return m_settings3Dviewer; }
/**
* @brief SetModelDataIdx - Sets the currently selected index in the model list so that
* the scale/rotation/offset controls can be updated.

View File

@ -28,7 +28,7 @@
*/
#include "../3d_rendering/ccamera.h"
#include "cinfo3d_visu.h"
#include "3d_settings.h"
#include <3d_rendering/3d_render_raytracing/shapes2D/cpolygon2d.h>
#include <class_board.h>
#include <3d_math.h>
@ -44,17 +44,17 @@
* "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for
* more information.
*/
const wxChar *CINFO3D_VISU::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" );
const wxChar *EDA_3D_SETTINGS::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" );
CINFO3D_VISU G_null_CINFO3D_VISU;
EDA_3D_SETTINGS G_null_EDA_3D_SETTINGS;
CINFO3D_VISU::CINFO3D_VISU() :
EDA_3D_SETTINGS::EDA_3D_SETTINGS() :
m_currentCamera( m_trackBallCamera ),
m_trackBallCamera( RANGE_SCALE_3D )
{
wxLogTrace( m_logTrace, wxT( "CINFO3D_VISU::CINFO3D_VISU" ) );
wxLogTrace( m_logTrace, wxT( "EDA_3D_SETTINGS::EDA_3D_SETTINGS" ) );
m_board = NULL;
m_3d_model_manager = NULL;
@ -73,8 +73,6 @@ CINFO3D_VISU::CINFO3D_VISU() :
m_boardBoundingBox.Reset();
m_layers_container2D.clear();
m_layers_holes2D.clear();
m_through_holes_inner.Clear();
m_through_holes_outer.Clear();
@ -94,7 +92,6 @@ CINFO3D_VISU::CINFO3D_VISU() :
m_calc_seg_min_factor3DU = 0.0f;
m_calc_seg_max_factor3DU = 0.0f;
memset( m_layerZcoordTop, 0, sizeof( m_layerZcoordTop ) );
memset( m_layerZcoordBottom, 0, sizeof( m_layerZcoordBottom ) );
@ -122,13 +119,13 @@ CINFO3D_VISU::CINFO3D_VISU() :
}
CINFO3D_VISU::~CINFO3D_VISU()
EDA_3D_SETTINGS::~EDA_3D_SETTINGS()
{
destroyLayers();
}
bool CINFO3D_VISU::Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const
bool EDA_3D_SETTINGS::Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const
{
wxASSERT( aLayer < PCB_LAYER_ID_COUNT );
@ -211,7 +208,7 @@ bool CINFO3D_VISU::Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const
}
bool CINFO3D_VISU::GetFlag( DISPLAY3D_FLG aFlag ) const
bool EDA_3D_SETTINGS::GetFlag( DISPLAY3D_FLG aFlag ) const
{
wxASSERT( aFlag < FL_LAST );
@ -219,14 +216,14 @@ bool CINFO3D_VISU::GetFlag( DISPLAY3D_FLG aFlag ) const
}
void CINFO3D_VISU::SetFlag( DISPLAY3D_FLG aFlag, bool aState )
void EDA_3D_SETTINGS::SetFlag( DISPLAY3D_FLG aFlag, bool aState )
{
wxASSERT( aFlag < FL_LAST );
m_drawFlags[aFlag] = aState;
}
bool CINFO3D_VISU::ShouldModuleBeDisplayed( MODULE_ATTR_T aModuleAttributs ) const
bool EDA_3D_SETTINGS::ShouldModuleBeDisplayed( MODULE_ATTR_T aModuleAttributs ) const
{
if( ( ( aModuleAttributs == MOD_DEFAULT ) &&
GetFlag( FL_MODULE_ATTRIBUTES_NORMAL ) ) ||
@ -246,12 +243,12 @@ bool CINFO3D_VISU::ShouldModuleBeDisplayed( MODULE_ATTR_T aModuleAttributs ) con
#define COPPER_THICKNESS KiROUND( 0.035 * IU_PER_MM ) // for 35 um
#define TECH_LAYER_THICKNESS KiROUND( 0.04 * IU_PER_MM )
int CINFO3D_VISU::GetCopperThicknessBIU() const
int EDA_3D_SETTINGS::GetCopperThicknessBIU() const
{
return COPPER_THICKNESS;
}
unsigned int CINFO3D_VISU::GetNrSegmentsCircle( float aDiameter3DU ) const
unsigned int EDA_3D_SETTINGS::GetNrSegmentsCircle( float aDiameter3DU ) const
{
wxASSERT( aDiameter3DU > 0.0f );
@ -259,7 +256,7 @@ unsigned int CINFO3D_VISU::GetNrSegmentsCircle( float aDiameter3DU ) const
}
unsigned int CINFO3D_VISU::GetNrSegmentsCircle( int aDiameterBIU ) const
unsigned int EDA_3D_SETTINGS::GetNrSegmentsCircle( int aDiameterBIU ) const
{
wxASSERT( aDiameterBIU > 0 );
@ -268,7 +265,7 @@ unsigned int CINFO3D_VISU::GetNrSegmentsCircle( int aDiameterBIU ) const
}
double CINFO3D_VISU::GetCircleCorrectionFactor( int aNrSides ) const
double EDA_3D_SETTINGS::GetCircleCorrectionFactor( int aNrSides ) const
{
wxASSERT( aNrSides >= 3 );
@ -276,9 +273,9 @@ double CINFO3D_VISU::GetCircleCorrectionFactor( int aNrSides ) const
}
void CINFO3D_VISU::InitSettings( REPORTER* aStatusTextReporter, REPORTER* aWarningTextReporter )
void EDA_3D_SETTINGS::InitSettings( REPORTER* aStatusTextReporter, REPORTER* aWarningTextReporter )
{
wxLogTrace( m_logTrace, wxT( "CINFO3D_VISU::InitSettings" ) );
wxLogTrace( m_logTrace, wxT( "EDA_3D_SETTINGS::InitSettings" ) );
// Calculates the board bounding box
// First, use only the board outlines
@ -309,8 +306,7 @@ void CINFO3D_VISU::InitSettings( REPORTER* aStatusTextReporter, REPORTER* aWarni
// Calculate the convertion to apply to all positions.
m_biuTo3Dunits = RANGE_SCALE_3D / std::max( m_boardSize.x, m_boardSize.y );
m_epoxyThickness3DU = m_board->GetDesignSettings().GetBoardThickness() *
m_biuTo3Dunits;
m_epoxyThickness3DU = m_board->GetDesignSettings().GetBoardThickness() * m_biuTo3Dunits;
// !TODO: use value defined by user (currently use default values by ctor
m_copperThickness3DU = COPPER_THICKNESS * m_biuTo3Dunits;
@ -450,7 +446,7 @@ void CINFO3D_VISU::InitSettings( REPORTER* aStatusTextReporter, REPORTER* aWarni
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_stopCreateLayersTime = GetRunningMicroSecs();
printf( "CINFO3D_VISU::InitSettings times\n" );
printf( "EDA_3D_SETTINGS::InitSettings times\n" );
printf( " CreateBoardPoly: %.3f ms\n",
(float)( stats_stopCreateBoardPolyTime - stats_startCreateBoardPolyTime ) / 1e3 );
printf( " CreateLayers and holes: %.3f ms\n",
@ -460,7 +456,7 @@ void CINFO3D_VISU::InitSettings( REPORTER* aStatusTextReporter, REPORTER* aWarni
}
bool CINFO3D_VISU::createBoardPolygon()
bool EDA_3D_SETTINGS::createBoardPolygon()
{
m_board_poly.RemoveAllContours();
@ -470,7 +466,7 @@ bool CINFO3D_VISU::createBoardPolygon()
}
float CINFO3D_VISU::GetModulesZcoord3DIU( bool aIsFlipped ) const
float EDA_3D_SETTINGS::GetModulesZcoord3DIU( bool aIsFlipped ) const
{
if( aIsFlipped )
{
@ -489,23 +485,7 @@ float CINFO3D_VISU::GetModulesZcoord3DIU( bool aIsFlipped ) const
}
void CINFO3D_VISU::CameraSetType( CAMERA_TYPE aCameraType )
{
switch( aCameraType )
{
case CAMERA_TYPE::TRACKBALL:
m_currentCamera = m_trackBallCamera;
break;
default:
wxLogMessage( wxT( "CINFO3D_VISU::CameraSetType() error: unknown camera type %d" ),
(int)aCameraType );
break;
}
}
SFVEC3F CINFO3D_VISU::GetLayerColor( PCB_LAYER_ID aLayerId ) const
SFVEC3F EDA_3D_SETTINGS::GetLayerColor( PCB_LAYER_ID aLayerId ) const
{
wxASSERT( aLayerId < PCB_LAYER_ID_COUNT );
@ -515,13 +495,13 @@ SFVEC3F CINFO3D_VISU::GetLayerColor( PCB_LAYER_ID aLayerId ) const
}
SFVEC3F CINFO3D_VISU::GetItemColor( int aItemId ) const
SFVEC3F EDA_3D_SETTINGS::GetItemColor( int aItemId ) const
{
return GetColor( m_colors->GetColor( aItemId ) );
}
SFVEC3F CINFO3D_VISU::GetColor( COLOR4D aColor ) const
SFVEC3F EDA_3D_SETTINGS::GetColor( COLOR4D aColor ) const
{
return SFVEC3F( aColor.r, aColor.g, aColor.b );
}

View File

@ -22,13 +22,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file cinfo3d_visu.h
* @brief Handles data related with the board to be visualized
*/
#ifndef CINFO3D_VISU_H
#define CINFO3D_VISU_H
#ifndef EDA_3D_SETTINGS_H
#define EDA_3D_SETTINGS_H
#include <vector>
#include "../3d_rendering/3d_render_raytracing/accelerators/ccontainer2d.h"
@ -67,16 +62,16 @@ typedef std::map< PCB_LAYER_ID, SHAPE_POLY_SET *> MAP_POLY;
/**
* Class CINFO3D_VISU
* Class EDA_3D_SETTINGS
* Helper class to handle information needed to display 3D board
*/
class CINFO3D_VISU
class EDA_3D_SETTINGS
{
public:
CINFO3D_VISU();
EDA_3D_SETTINGS();
~CINFO3D_VISU();
~EDA_3D_SETTINGS();
/**
* @brief Set3DCacheManager - Update the Cache manager pointer
@ -203,12 +198,6 @@ class CINFO3D_VISU
*/
float GetModulesZcoord3DIU( bool aIsFlipped ) const ;
/**
* @brief CameraSetType - Set the camera type to use
* @param aCameraType: camera type to use in this canvas
*/
void CameraSetType( CAMERA_TYPE aCameraType );
/**
* @brief CameraGet - get current camera in use
* @return a camera
@ -283,14 +272,20 @@ class CINFO3D_VISU
* @param aLayerId: layer id
* @return position in 3D unities
*/
float GetLayerTopZpos3DU( PCB_LAYER_ID aLayerId ) const { return m_layerZcoordTop[aLayerId]; }
float GetLayerTopZpos3DU( PCB_LAYER_ID aLayerId ) const
{
return m_layerZcoordTop[aLayerId];
}
/**
* @brief GetLayerBottomZpos3DU - Get the bottom z position
* @param aLayerId: layer id
* @return position in 3D unities
*/
float GetLayerBottomZpos3DU( PCB_LAYER_ID aLayerId ) const { return m_layerZcoordBottom[aLayerId]; }
float GetLayerBottomZpos3DU( PCB_LAYER_ID aLayerId ) const
{
return m_layerZcoordBottom[aLayerId];
}
/**
* @brief GetMapLayers - Get the map of container that have the objects per layer
@ -320,8 +315,10 @@ class CINFO3D_VISU
* @brief GetThroughHole_Outer_poly_NPTH -
* @return
*/
const SHAPE_POLY_SET &GetThroughHole_Outer_poly_NPTH() const {
return m_through_outer_holes_poly_NPTH; }
const SHAPE_POLY_SET &GetThroughHole_Outer_poly_NPTH() const
{
return m_through_outer_holes_poly_NPTH;
}
/**
* @brief GetThroughHole_Vias_Outer -
@ -337,17 +334,19 @@ class CINFO3D_VISU
/**
* @brief GetThroughHole_Vias_Outer_poly -
* @return
*/
const SHAPE_POLY_SET &GetThroughHole_Vias_Outer_poly() const {
return m_through_outer_holes_vias_poly; }
const SHAPE_POLY_SET &GetThroughHole_Vias_Outer_poly() const
{
return m_through_outer_holes_vias_poly;
}
/**
* @brief GetThroughHole_Vias_Inner_poly -
* @return
*/
const SHAPE_POLY_SET &GetThroughHole_Vias_Inner_poly() const {
return m_through_inner_holes_vias_poly; }
const SHAPE_POLY_SET &GetThroughHole_Vias_Inner_poly() const
{
return m_through_inner_holes_vias_poly;
}
/**
* @brief GetThroughHole_Inner - Get the ThroughHole container
@ -680,7 +679,15 @@ private:
};
/// This is a dummy visualization configuration
extern CINFO3D_VISU G_null_CINFO3D_VISU;
#endif // CINFO3D_VISU_H
/// This is a dummy visualization configuration
extern EDA_3D_SETTINGS G_null_EDA_3D_SETTINGS;
class EDA_3D_SETTINGS_HOLDER
{
public:
virtual EDA_3D_SETTINGS* GetSettings() = 0;
};
#endif // EDA_3D_SETTINGS_H

View File

@ -30,7 +30,7 @@
* board_items_to_polygon_shape_transform.cpp
*/
#include "cinfo3d_visu.h"
#include "3d_settings.h"
#include "../3d_rendering/3d_render_raytracing/shapes2D/cring2d.h"
#include "../3d_rendering/3d_render_raytracing/shapes2D/cfilledcircle2d.h"
#include "../3d_rendering/3d_render_raytracing/shapes2D/croundsegment2d.h"
@ -87,10 +87,10 @@ void addTextSegmToContainer( int x0, int y0, int xf, int yf, void* aData )
// Based on
// void TEXTE_PCB::TransformShapeWithClearanceToPolygonSet
// board_items_to_polygon_shape_transform.cpp
void CINFO3D_VISU::AddShapeWithClearanceToContainer( const TEXTE_PCB* aText,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue )
void EDA_3D_SETTINGS::AddShapeWithClearanceToContainer( const TEXTE_PCB* aText,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue )
{
wxSize size = aText->GetTextSize();
@ -131,10 +131,10 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const TEXTE_PCB* aText,
}
void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DIMENSION* aDimension,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue )
void EDA_3D_SETTINGS::AddShapeWithClearanceToContainer( const DIMENSION* aDimension,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue )
{
AddShapeWithClearanceToContainer(&aDimension->Text(), aDstContainer, aLayerId, aClearanceValue);
@ -168,10 +168,10 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DIMENSION* aDimension
// Based on
// void MODULE::TransformGraphicShapesWithClearanceToPolygonSet
// board_items_to_polygon_shape_transform.cpp#L204
void CINFO3D_VISU::AddGraphicsShapesWithClearanceToContainer( const MODULE* aModule,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aInflateValue )
void EDA_3D_SETTINGS::AddGraphicsShapesWithClearanceToContainer( const MODULE* aModule,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aInflateValue )
{
std::vector<TEXTE_MODULE *> texts; // List of TEXTE_MODULE to convert
EDGE_MODULE* outline;
@ -234,8 +234,8 @@ void CINFO3D_VISU::AddGraphicsShapesWithClearanceToContainer( const MODULE* aMod
}
COBJECT2D *CINFO3D_VISU::createNewTrack( const TRACK* aTrack,
int aClearanceValue ) const
COBJECT2D *EDA_3D_SETTINGS::createNewTrack( const TRACK* aTrack,
int aClearanceValue ) const
{
SFVEC2F start3DU( aTrack->GetStart().x * m_biuTo3Dunits,
-aTrack->GetStart().y * m_biuTo3Dunits ); // y coord is inverted
@ -281,9 +281,9 @@ COBJECT2D *CINFO3D_VISU::createNewTrack( const TRACK* aTrack,
// Based on:
// void D_PAD:: TransformShapeWithClearanceToPolygon(
// board_items_to_polygon_shape_transform.cpp
void CINFO3D_VISU::createNewPadWithClearance( const D_PAD* aPad,
CGENERICCONTAINER2D *aDstContainer,
wxSize aClearanceValue ) const
void EDA_3D_SETTINGS::createNewPadWithClearance( const D_PAD* aPad,
CGENERICCONTAINER2D *aDstContainer,
wxSize aClearanceValue ) const
{
// note: for most of shapes, aClearanceValue.x = aClearanceValue.y
// only rectangular and oval shapes can have different values
@ -295,7 +295,7 @@ void CINFO3D_VISU::createNewPadWithClearance( const D_PAD* aPad,
if( !dx || !dy )
{
wxLogTrace( m_logTrace,
wxT( "CINFO3D_VISU::createNewPadWithClearance - found an invalid pad" ) );
wxT( "EDA_3D_SETTINGS::createNewPadWithClearance - found an invalid pad" ) );
return;
}
@ -517,13 +517,13 @@ void CINFO3D_VISU::createNewPadWithClearance( const D_PAD* aPad,
// Based on:
// BuildPadDrillShapePolygon
// board_items_to_polygon_shape_transform.cpp
COBJECT2D *CINFO3D_VISU::createNewPadDrill( const D_PAD* aPad, int aInflateValue )
COBJECT2D *EDA_3D_SETTINGS::createNewPadDrill( const D_PAD* aPad, int aInflateValue )
{
wxSize drillSize = aPad->GetDrillSize();
if( !drillSize.x || !drillSize.y )
{
wxLogTrace( m_logTrace, wxT( "CINFO3D_VISU::createNewPadDrill - found an invalid pad" ) );
wxLogTrace( m_logTrace, wxT( "EDA_3D_SETTINGS::createNewPadDrill - found an invalid pad" ) );
return NULL;
}
@ -568,11 +568,11 @@ COBJECT2D *CINFO3D_VISU::createNewPadDrill( const D_PAD* aPad, int aInflateValue
}
void CINFO3D_VISU::AddPadsShapesWithClearanceToContainer( const MODULE* aModule,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aInflateValue,
bool aSkipNPTHPadsWihNoCopper )
void EDA_3D_SETTINGS::AddPadsShapesWithClearanceToContainer( const MODULE* aModule,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aInflateValue,
bool aSkipNPTHPadsWihNoCopper )
{
wxSize margin;
@ -631,13 +631,13 @@ void CINFO3D_VISU::AddPadsShapesWithClearanceToContainer( const MODULE* aModule,
// based on TransformArcToPolygon function from
// common/convert_basic_shapes_to_polygon.cpp
void CINFO3D_VISU::TransformArcToSegments( const wxPoint &aCentre,
const wxPoint &aStart,
double aArcAngle,
int aCircleToSegmentsCount,
int aWidth,
CGENERICCONTAINER2D *aDstContainer,
const BOARD_ITEM &aBoardItem )
void EDA_3D_SETTINGS::TransformArcToSegments( const wxPoint &aCentre,
const wxPoint &aStart,
double aArcAngle,
int aCircleToSegmentsCount,
int aWidth,
CGENERICCONTAINER2D *aDstContainer,
const BOARD_ITEM &aBoardItem )
{
wxPoint arc_start, arc_end;
int delta = 3600 / aCircleToSegmentsCount; // rotate angle in 0.1 degree
@ -708,10 +708,10 @@ void CINFO3D_VISU::TransformArcToSegments( const wxPoint &aCentre,
// Based on
// TransformShapeWithClearanceToPolygon
// board_items_to_polygon_shape_transform.cpp#L431
void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSegment,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue )
void EDA_3D_SETTINGS::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSegment,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId,
int aClearanceValue )
{
// The full width of the lines to create
// The extra 1 protects the inner/outer radius values from degeneracy
@ -799,9 +799,9 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSeg
// Based on
// TransformSolidAreasShapesToPolygonSet
// board_items_to_polygon_shape_transform.cpp
void CINFO3D_VISU::AddSolidAreasShapesToContainer( const ZONE_CONTAINER* aZoneContainer,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId )
void EDA_3D_SETTINGS::AddSolidAreasShapesToContainer( const ZONE_CONTAINER* aZoneContainer,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId )
{
// Copy the polys list because we have to simplify it
SHAPE_POLY_SET polyList = SHAPE_POLY_SET( aZoneContainer->GetFilledPolysList(), true );
@ -880,9 +880,9 @@ void CINFO3D_VISU::AddSolidAreasShapesToContainer( const ZONE_CONTAINER* aZoneCo
void CINFO3D_VISU::buildPadShapeThickOutlineAsSegments( const D_PAD* aPad,
CGENERICCONTAINER2D *aDstContainer,
int aWidth )
void EDA_3D_SETTINGS::buildPadShapeThickOutlineAsSegments( const D_PAD* aPad,
CGENERICCONTAINER2D *aDstContainer,
int aWidth )
{
if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring
{

View File

@ -30,7 +30,7 @@
* board_items_to_polygon_shape_transform.cpp
*/
#include "cinfo3d_visu.h"
#include "3d_settings.h"
#include "../3d_rendering/3d_render_raytracing/shapes2D/cring2d.h"
#include "../3d_rendering/3d_render_raytracing/shapes2D/cfilledcircle2d.h"
#include "../3d_rendering/3d_render_raytracing/shapes2D/croundsegment2d.h"
@ -58,69 +58,44 @@
#include <profile.h>
void CINFO3D_VISU::destroyLayers()
void EDA_3D_SETTINGS::destroyLayers()
{
if( !m_layers_poly.empty() )
{
for( MAP_POLY::iterator ii = m_layers_poly.begin();
ii != m_layers_poly.end();
++ii )
{
delete ii->second;
ii->second = NULL;
}
for( auto& poly : m_layers_poly )
delete poly.second;
m_layers_poly.clear();
}
if( !m_layers_inner_holes_poly.empty() )
{
for( MAP_POLY::iterator ii = m_layers_inner_holes_poly.begin();
ii != m_layers_inner_holes_poly.end();
++ii )
{
delete ii->second;
ii->second = NULL;
}
for( auto& poly : m_layers_inner_holes_poly )
delete poly.second;
m_layers_inner_holes_poly.clear();
}
if( !m_layers_outer_holes_poly.empty() )
{
for( MAP_POLY::iterator ii = m_layers_outer_holes_poly.begin();
ii != m_layers_outer_holes_poly.end();
++ii )
{
delete ii->second;
ii->second = NULL;
}
for( auto& poly : m_layers_outer_holes_poly )
delete poly.second;
m_layers_outer_holes_poly.clear();
}
if( !m_layers_container2D.empty() )
{
for( MAP_CONTAINER_2D::iterator ii = m_layers_container2D.begin();
ii != m_layers_container2D.end();
++ii )
{
delete ii->second;
ii->second = NULL;
}
for( auto& poly : m_layers_container2D )
delete poly.second;
m_layers_container2D.clear();
}
if( !m_layers_holes2D.empty() )
{
for( MAP_CONTAINER_2D::iterator ii = m_layers_holes2D.begin();
ii != m_layers_holes2D.end();
++ii )
{
delete ii->second;
ii->second = NULL;
}
for( auto& poly : m_layers_holes2D )
delete poly.second;
m_layers_holes2D.clear();
}
@ -138,7 +113,7 @@ void CINFO3D_VISU::destroyLayers()
}
void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
void EDA_3D_SETTINGS::createLayers( REPORTER *aStatusTextReporter )
{
destroyLayers();
@ -146,14 +121,14 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Based on: https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L692
// /////////////////////////////////////////////////////////////////////////
#ifdef PRINT_STATISTICS_3D_VIEWER
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_startCopperLayersTime = GetRunningMicroSecs();
unsigned start_Time = stats_startCopperLayersTime;
#endif
PCB_LAYER_ID cu_seq[MAX_CU_LAYERS];
LSET cu_set = LSET::AllCuMask( m_copperLayersCount );
LSET cu_set = LSET::AllCuMask( m_copperLayersCount );
m_stats_nr_tracks = 0;
m_stats_track_med_width = 0;
@ -168,7 +143,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
trackList.clear();
trackList.reserve( m_board->Tracks().size() );
for( auto track : m_board->Tracks() )
for( TRACK* track : m_board->Tracks() )
{
if( !Is3DLayerEnabled( track->GetLayer() ) ) // Skip non enabled layers
continue;
@ -241,10 +216,8 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Create tracks as objects and add it to container
// /////////////////////////////////////////////////////////////////////////
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID curr_layer_id : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id];
@ -272,10 +245,8 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Create VIAS and THTs objects and add it to holes containers
// /////////////////////////////////////////////////////////////////////////
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID curr_layer_id : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
// ADD TRACKS
unsigned int nTracks = trackList.size();
@ -324,7 +295,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
hole_inner_radius + thickness,
*track ) );
}
else if( lIdx == 0 ) // it only adds once the THT holes
else if( curr_layer_id == layer_id[0] ) // it only adds once the THT holes
{
// Add through hole object
// /////////////////////////////////////////////////////////
@ -356,10 +327,8 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Create VIAS and THTs objects and add it to holes containers
// /////////////////////////////////////////////////////////////////////////
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID curr_layer_id : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
// ADD TRACKS
const unsigned int nTracks = trackList.size();
@ -420,7 +389,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
TransformCircleToPolygon( *layerInnerHolesPoly, via->GetStart(),
holediameter / 2, ARC_HIGH_DEF );
}
else if( lIdx == 0 ) // it only adds once the THT holes
else if( curr_layer_id == layer_id[0] ) // it only adds once the THT holes
{
const int holediameter = via->GetDrillValue();
const int hole_outer_radius = (holediameter / 2)+ GetCopperThicknessBIU();
@ -457,10 +426,8 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID curr_layer_id : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
SHAPE_POLY_SET *layerPoly = m_layers_poly[curr_layer_id];
@ -488,9 +455,9 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Add holes of modules
// /////////////////////////////////////////////////////////////////////////
for( auto module : m_board->Modules() )
for( MODULE* module : m_board->Modules() )
{
for( auto pad : module->Pads() )
for( D_PAD* pad : module->Pads() )
{
const wxSize padHole = pad->GetDrillSize();
@ -520,9 +487,9 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Add contours of the pad holes (pads can be Circle or Segment holes)
// /////////////////////////////////////////////////////////////////////////
for( auto module : m_board->Modules() )
for( MODULE* module : m_board->Modules() )
{
for( auto pad : module->Pads() )
for( D_PAD* pad : module->Pads() )
{
const wxSize padHole = pad->GetDrillSize();
@ -535,7 +502,6 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
if( pad->GetAttribute () != PAD_ATTRIB_HOLE_NOT_PLATED )
{
pad->BuildPadDrillShapePolygon( m_through_outer_holes_poly, inflate );
pad->BuildPadDrillShapePolygon( m_through_inner_holes_poly, 0 );
}
else
@ -553,16 +519,14 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Add modules PADs objects to containers
// /////////////////////////////////////////////////////////////////////////
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID curr_layer_id : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id];
// ADD PADS
for( auto module : m_board->Modules() )
for( MODULE* module : m_board->Modules() )
{
// Note: NPTH pads are not drawn on copper layers when the pad
// has same shape as its hole
@ -590,10 +554,8 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID curr_layer_id : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
SHAPE_POLY_SET *layerPoly = m_layers_poly[curr_layer_id];
@ -613,8 +575,9 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
true );
// Micro-wave modules may have items on copper layers
module->TransformGraphicTextWithClearanceToPolygonSet(
curr_layer_id, *layerPoly, 0 );
module->TransformGraphicTextWithClearanceToPolygonSet( curr_layer_id,
*layerPoly,
0 );
transformGraphicModuleEdgeToPolygonSet( module, curr_layer_id, *layerPoly );
}
@ -628,10 +591,8 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Add graphic item on copper layers to object containers
// /////////////////////////////////////////////////////////////////////////
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID curr_layer_id : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id];
@ -686,18 +647,16 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID cur_layer_id : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
wxASSERT( m_layers_poly.find( cur_layer_id ) != m_layers_poly.end() );
wxASSERT( m_layers_poly.find( curr_layer_id ) != m_layers_poly.end() );
SHAPE_POLY_SET *layerPoly = m_layers_poly[curr_layer_id];
SHAPE_POLY_SET *layerPoly = m_layers_poly[cur_layer_id];
// ADD GRAPHIC ITEMS ON COPPER LAYERS (texts)
for( auto item : m_board->Drawings() )
for( BOARD_ITEM* item : m_board->Drawings() )
{
if( !item->IsOnLayer( curr_layer_id ) )
if( !item->IsOnLayer( cur_layer_id ) )
continue;
switch( item->Type() )
@ -712,7 +671,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
default:
wxLogTrace( m_logTrace, wxT( "createLayers: item type: %d not implemented" ),
item->Type() );
item->Type() );
break;
}
}
@ -775,10 +734,8 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{
// ADD COPPER ZONES
for( int ii = 0; ii < m_board->GetAreaCount(); ++ii )
for( ZONE_CONTAINER* zone : m_board->Zones() )
{
const ZONE_CONTAINER* zone = m_board->GetArea( ii );
if( zone == nullptr )
break;
@ -844,21 +801,17 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
if( aStatusTextReporter )
aStatusTextReporter->Report( _( "Simplify holes contours" ) );
for( unsigned int lIdx = 0; lIdx < layer_id.size(); ++lIdx )
for( PCB_LAYER_ID layer : layer_id )
{
const PCB_LAYER_ID curr_layer_id = layer_id[lIdx];
if( m_layers_outer_holes_poly.find( curr_layer_id ) !=
m_layers_outer_holes_poly.end() )
if( m_layers_outer_holes_poly.find( layer ) != m_layers_outer_holes_poly.end() )
{
// found
SHAPE_POLY_SET *polyLayer = m_layers_outer_holes_poly[curr_layer_id];
SHAPE_POLY_SET *polyLayer = m_layers_outer_holes_poly[layer];
polyLayer->Simplify( SHAPE_POLY_SET::PM_FAST );
wxASSERT( m_layers_inner_holes_poly.find( curr_layer_id ) !=
m_layers_inner_holes_poly.end() );
wxASSERT( m_layers_inner_holes_poly.find( layer ) != m_layers_inner_holes_poly.end() );
polyLayer = m_layers_inner_holes_poly[curr_layer_id];
polyLayer = m_layers_inner_holes_poly[layer];
polyLayer->Simplify( SHAPE_POLY_SET::PM_FAST );
}
}
@ -919,7 +872,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
const PCB_LAYER_ID curr_layer_id = *seq;
if( !Is3DLayerEnabled( curr_layer_id ) )
continue;
continue;
CBVHCONTAINER2D *layerContainer = new CBVHCONTAINER2D;
m_layers_container2D[curr_layer_id] = layerContainer;
@ -929,7 +882,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Add drawing objects
// /////////////////////////////////////////////////////////////////////
for( auto item : m_board->Drawings() )
for( BOARD_ITEM* item : m_board->Drawings() )
{
if( !item->IsOnLayer( curr_layer_id ) )
continue;
@ -965,7 +918,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Add drawing contours
// /////////////////////////////////////////////////////////////////////
for( auto item : m_board->Drawings() )
for( BOARD_ITEM* item : m_board->Drawings() )
{
if( !item->IsOnLayer( curr_layer_id ) )
continue;
@ -988,13 +941,13 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Add modules tech layers - objects
// /////////////////////////////////////////////////////////////////////
for( auto module : m_board->Modules() )
for( MODULE* module : m_board->Modules() )
{
if( (curr_layer_id == F_SilkS) || (curr_layer_id == B_SilkS) )
{
int linewidth = g_DrawDefaultLineThickness;
for( auto pad : module->Pads() )
for( D_PAD* pad : module->Pads() )
{
if( !pad->IsOnLayer( curr_layer_id ) )
continue;
@ -1014,13 +967,13 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
// Add modules tech layers - contours
// /////////////////////////////////////////////////////////////////////
for( auto module : m_board->Modules() )
for( MODULE* module : m_board->Modules() )
{
if( (curr_layer_id == F_SilkS) || (curr_layer_id == B_SilkS) )
{
const int linewidth = g_DrawDefaultLineThickness;
for( auto pad : module->Pads() )
for( D_PAD* pad : module->Pads() )
{
if( !pad->IsOnLayer( curr_layer_id ) )
continue;
@ -1053,9 +1006,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
if( !zone->IsOnLayer( curr_layer_id ) )
continue;
AddSolidAreasShapesToContainer( zone,
layerContainer,
curr_layer_id );
AddSolidAreasShapesToContainer( zone, layerContainer, curr_layer_id );
}
for( int ii = 0; ii < m_board->GetAreaCount(); ++ii )
@ -1093,26 +1044,22 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter )
if( !m_layers_holes2D.empty() )
{
for( MAP_CONTAINER_2D::iterator ii = m_layers_holes2D.begin();
ii != m_layers_holes2D.end();
++ii )
{
((CBVHCONTAINER2D *)(ii->second))->BuildBVH();
}
for( auto& hole : m_layers_holes2D)
hole.second->BuildBVH();
}
// We only need the Solder mask to initialize the BVH
// because..?
if( (CBVHCONTAINER2D *)m_layers_container2D[B_Mask] )
((CBVHCONTAINER2D *)m_layers_container2D[B_Mask])->BuildBVH();
if( m_layers_container2D[B_Mask] )
m_layers_container2D[B_Mask]->BuildBVH();
if( (CBVHCONTAINER2D *)m_layers_container2D[F_Mask] )
((CBVHCONTAINER2D *)m_layers_container2D[F_Mask])->BuildBVH();
if( m_layers_container2D[F_Mask] )
m_layers_container2D[F_Mask]->BuildBVH();
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_endHolesBVHTime = GetRunningMicroSecs();
printf( "CINFO3D_VISU::createLayers times\n" );
printf( "EDA_3D_SETTINGS::createLayers times\n" );
printf( " Copper Layers: %.3f ms\n",
(float)( stats_endCopperLayersTime - stats_startCopperLayersTime ) / 1e3 );
printf( " Holes BVH creation: %.3f ms\n",

View File

@ -30,7 +30,7 @@
* board_items_to_polygon_shape_transform.cpp
*/
#include "cinfo3d_visu.h"
#include "3d_settings.h"
#include <convert_basic_shapes_to_polygon.h>
#include <class_edge_mod.h>
#include <class_module.h>
@ -38,9 +38,9 @@
// This is the same function as in board_items_to_polygon_shape_transform.cpp
// but it adds the rect/trapezoid shapes with a different winding
void CINFO3D_VISU::buildPadShapePolygon( const D_PAD* aPad,
SHAPE_POLY_SET& aCornerBuffer,
wxSize aInflateValue ) const
void EDA_3D_SETTINGS::buildPadShapePolygon( const D_PAD* aPad,
SHAPE_POLY_SET& aCornerBuffer,
wxSize aInflateValue ) const
{
wxPoint corners[4];
wxPoint PadShapePos = aPad->ShapePos(); /* Note: for pad having a shape offset,
@ -105,9 +105,9 @@ void CINFO3D_VISU::buildPadShapePolygon( const D_PAD* aPad,
}
void CINFO3D_VISU::buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
SHAPE_POLY_SET& aCornerBuffer,
int aWidth ) const
void EDA_3D_SETTINGS::buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
SHAPE_POLY_SET& aCornerBuffer,
int aWidth ) const
{
if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring
{
@ -139,10 +139,10 @@ void CINFO3D_VISU::buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
// Based on the same function name in board_items_to_polyshape_transform.cpp
// It was implemented here to allow dynamic segments count per pad shape
void CINFO3D_VISU::transformPadsShapesWithClearanceToPolygon( const PADS& aPads, PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer,
int aInflateValue,
bool aSkipNPTHPadsWihNoCopper ) const
void EDA_3D_SETTINGS::transformPadsShapesWithClearanceToPolygon( const PADS& aPads, PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer,
int aInflateValue,
bool aSkipNPTHPadsWihNoCopper ) const
{
wxSize margin;
for( auto pad : aPads )
@ -198,9 +198,9 @@ void CINFO3D_VISU::transformPadsShapesWithClearanceToPolygon( const PADS& aPads,
}
}
void CINFO3D_VISU::transformGraphicModuleEdgeToPolygonSet( const MODULE *aModule,
PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer ) const
void EDA_3D_SETTINGS::transformGraphicModuleEdgeToPolygonSet( const MODULE *aModule,
PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer ) const
{
for( auto item : aModule->GraphicalItems() )
{

View File

@ -85,7 +85,7 @@ END_EVENT_TABLE()
EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow *aParent, const int *aAttribList, BOARD *aBoard,
CINFO3D_VISU &aSettings , S3D_CACHE *a3DCachePointer ) :
EDA_3D_SETTINGS &aSettings , S3D_CACHE *a3DCachePointer ) :
HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE ),
m_eventDispatcher( nullptr ),
@ -153,10 +153,11 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow *aParent, const int *aAttribList, BOARD *
wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK,
wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK,
wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK,
wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, wxEVT_CHAR_HOOK
wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, wxEVT_CHAR_HOOK,
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
, wxEVT_MAGNIFY
wxEVT_MAGNIFY,
#endif
wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT
};
for( wxEventType eventType : events )

View File

@ -26,7 +26,7 @@
#define EDA_3D_CANVAS_H
#include "cinfo3d_visu.h"
#include "3d_settings.h"
#include "3d_rendering/c3d_render_base.h"
#include "3d_cache/3d_cache.h"
#include <gal/hidpi_gl_canvas.h>
@ -56,7 +56,7 @@ class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
EDA_3D_CANVAS( wxWindow *aParent,
const int *aAttribList = 0,
BOARD *aBoard = NULL,
CINFO3D_VISU &aSettings = G_null_CINFO3D_VISU,
EDA_3D_SETTINGS &aSettings = G_null_EDA_3D_SETTINGS,
S3D_CACHE *a3DCachePointer = NULL );
~EDA_3D_CANVAS();
@ -212,7 +212,7 @@ private:
float m_camera_moving_speed; // 1.0f will be 1:1
unsigned m_strtime_camera_movement; // Ticktime of camera movement start
CINFO3D_VISU& m_settings; // Pre-computed 3D information and visual
EDA_3D_SETTINGS& m_settings; // Pre-computed 3D information and visual
// settings to render the board
C3D_RENDER_BASE* m_3d_render;
C3D_RENDER_RAYTRACING* m_3d_render_raytracing;

View File

@ -44,7 +44,7 @@
*/
#define UNITS3D_TO_UNITSPCB (IU_PER_MM)
C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY( CINFO3D_VISU &aSettings ) :
C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY( EDA_3D_SETTINGS &aSettings ) :
C3D_RENDER_BASE( aSettings )
{
wxLogTrace( m_logTrace, wxT( "C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY" ) );

View File

@ -59,7 +59,7 @@ typedef std::map< wxString, C_OGL_3DMODEL * > MAP_3DMODEL;
class C3D_RENDER_OGL_LEGACY : public C3D_RENDER_BASE
{
public:
explicit C3D_RENDER_OGL_LEGACY( CINFO3D_VISU &aSettings );
explicit C3D_RENDER_OGL_LEGACY( EDA_3D_SETTINGS &aSettings );
~C3D_RENDER_OGL_LEGACY();

View File

@ -46,7 +46,7 @@
// convertLinearToSRGB
//#include <glm/gtc/color_space.hpp>
C3D_RENDER_RAYTRACING::C3D_RENDER_RAYTRACING( CINFO3D_VISU &aSettings ) :
C3D_RENDER_RAYTRACING::C3D_RENDER_RAYTRACING( EDA_3D_SETTINGS &aSettings ) :
C3D_RENDER_BASE( aSettings ),
m_postshader_ssao( aSettings.CameraGet() )
{

View File

@ -59,7 +59,7 @@ typedef enum
class C3D_RENDER_RAYTRACING : public C3D_RENDER_BASE
{
public:
explicit C3D_RENDER_RAYTRACING( CINFO3D_VISU &aSettings );
explicit C3D_RENDER_RAYTRACING( EDA_3D_SETTINGS &aSettings );
~C3D_RENDER_RAYTRACING();

View File

@ -40,7 +40,7 @@
const wxChar * C3D_RENDER_BASE::m_logTrace = wxT( "KI_TRACE_3D_RENDER" );
C3D_RENDER_BASE::C3D_RENDER_BASE(CINFO3D_VISU &aSettings) :
C3D_RENDER_BASE::C3D_RENDER_BASE( EDA_3D_SETTINGS &aSettings) :
m_settings( aSettings )
{
wxLogTrace( m_logTrace, wxT( "C3D_RENDER_BASE::C3D_RENDER_BASE" ) );

View File

@ -32,7 +32,7 @@
#include <pcb_base_frame.h>
#include "../3d_canvas/cinfo3d_visu.h"
#include "3d_canvas/3d_settings.h"
#include <reporter.h>
#include <widgets/busy_indicator.h>
@ -47,7 +47,7 @@ class C3D_RENDER_BASE
// Operations
public:
explicit C3D_RENDER_BASE( CINFO3D_VISU &aSettings );
explicit C3D_RENDER_BASE( EDA_3D_SETTINGS &aSettings );
virtual ~C3D_RENDER_BASE() = 0;
@ -107,7 +107,7 @@ protected:
std::unique_ptr<BUSY_INDICATOR> CreateBusyIndicator() const;
/// settings refrence in use for this render
CINFO3D_VISU &m_settings;
EDA_3D_SETTINGS &m_settings;
/// flag if the opengl specific for this render was already initialized
bool m_is_opengl_initialized;

View File

@ -24,7 +24,7 @@
#include "dialog_3D_view_option_base.h"
#include <3d_viewer/eda_3d_viewer.h>
#include <3d_canvas/cinfo3d_visu.h>
#include <3d_canvas/3d_settings.h>
#include <bitmaps.h>
class DIALOG_3D_VIEW_OPTIONS : public DIALOG_3D_VIEW_OPTIONS_BASE
@ -33,8 +33,8 @@ public:
explicit DIALOG_3D_VIEW_OPTIONS( EDA_3D_VIEWER* parent );
private:
EDA_3D_VIEWER* m_parent;
CINFO3D_VISU& m_3Dprms;
EDA_3D_VIEWER* m_parent;
EDA_3D_SETTINGS& m_settings;
void initDialog();
@ -58,7 +58,7 @@ void EDA_3D_VIEWER::Install3DViewOptionDialog( wxCommandEvent& event )
DIALOG_3D_VIEW_OPTIONS::DIALOG_3D_VIEW_OPTIONS( EDA_3D_VIEWER* parent )
:DIALOG_3D_VIEW_OPTIONS_BASE( parent ), m_3Dprms( parent->GetSettings() )
: DIALOG_3D_VIEW_OPTIONS_BASE( parent ), m_settings( *parent->GetSettings() )
{
m_parent = parent;
@ -94,23 +94,23 @@ void DIALOG_3D_VIEW_OPTIONS::initDialog()
bool DIALOG_3D_VIEW_OPTIONS::TransferDataToWindow()
{
// Check/uncheck checkboxes
m_checkBoxRealisticMode->SetValue( m_3Dprms.GetFlag( FL_USE_REALISTIC_MODE ) );
m_checkBoxBoardBody->SetValue( m_3Dprms.GetFlag( FL_SHOW_BOARD_BODY ) );
m_checkBoxCuThickness->SetValue( m_3Dprms.GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) );
m_checkBoxAreas->SetValue( m_3Dprms.GetFlag( FL_ZONE ) );
m_checkBoxBoundingBoxes->SetValue( m_3Dprms.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) );
m_checkBoxRealisticMode->SetValue( m_settings.GetFlag( FL_USE_REALISTIC_MODE ) );
m_checkBoxBoardBody->SetValue( m_settings.GetFlag( FL_SHOW_BOARD_BODY ) );
m_checkBoxCuThickness->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) );
m_checkBoxAreas->SetValue( m_settings.GetFlag( FL_ZONE ) );
m_checkBoxBoundingBoxes->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) );
m_checkBox3DshapesTH->SetValue( m_3Dprms.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL ) );
m_checkBox3DshapesSMD->SetValue( m_3Dprms.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT ) );
m_checkBox3DshapesVirtual->SetValue( m_3Dprms.GetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL ) );
m_checkBox3DshapesTH->SetValue( m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL ) );
m_checkBox3DshapesSMD->SetValue( m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT ) );
m_checkBox3DshapesVirtual->SetValue( m_settings.GetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL ) );
m_checkBoxSilkscreen->SetValue( m_3Dprms.GetFlag( FL_SILKSCREEN ) );
m_checkBoxSolderMask->SetValue( m_3Dprms.GetFlag( FL_SOLDERMASK ) );
m_checkBoxSolderpaste->SetValue( m_3Dprms.GetFlag( FL_SOLDERPASTE ) );
m_checkBoxAdhesive->SetValue( m_3Dprms.GetFlag( FL_ADHESIVE ) );
m_checkBoxComments->SetValue( m_3Dprms.GetFlag( FL_COMMENTS ) );
m_checkBoxECO->SetValue( m_3Dprms.GetFlag( FL_ECO ) );
m_checkBoxSubtractMaskFromSilk->SetValue( m_3Dprms.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) );
m_checkBoxSilkscreen->SetValue( m_settings.GetFlag( FL_SILKSCREEN ) );
m_checkBoxSolderMask->SetValue( m_settings.GetFlag( FL_SOLDERMASK ) );
m_checkBoxSolderpaste->SetValue( m_settings.GetFlag( FL_SOLDERPASTE ) );
m_checkBoxAdhesive->SetValue( m_settings.GetFlag( FL_ADHESIVE ) );
m_checkBoxComments->SetValue( m_settings.GetFlag( FL_COMMENTS ) );
m_checkBoxECO->SetValue( m_settings.GetFlag( FL_ECO ) );
m_checkBoxSubtractMaskFromSilk->SetValue( m_settings.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) );
return true;
}
@ -119,27 +119,27 @@ bool DIALOG_3D_VIEW_OPTIONS::TransferDataToWindow()
bool DIALOG_3D_VIEW_OPTIONS::TransferDataFromWindow()
{
// Set render mode
m_3Dprms.SetFlag( FL_USE_REALISTIC_MODE, m_checkBoxRealisticMode->GetValue() );
m_settings.SetFlag( FL_USE_REALISTIC_MODE, m_checkBoxRealisticMode->GetValue() );
// Set visibility of items
m_3Dprms.SetFlag( FL_SHOW_BOARD_BODY, m_checkBoxBoardBody->GetValue() );
m_3Dprms.SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, m_checkBoxCuThickness->GetValue() );
m_3Dprms.SetFlag( FL_ZONE, m_checkBoxAreas->GetValue() );
m_3Dprms.SetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, m_checkBoxBoundingBoxes->GetValue() );
m_3Dprms.SetFlag( FL_SUBTRACT_MASK_FROM_SILK, m_checkBoxSubtractMaskFromSilk->GetValue() );
m_settings.SetFlag( FL_SHOW_BOARD_BODY, m_checkBoxBoardBody->GetValue() );
m_settings.SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, m_checkBoxCuThickness->GetValue() );
m_settings.SetFlag( FL_ZONE, m_checkBoxAreas->GetValue() );
m_settings.SetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, m_checkBoxBoundingBoxes->GetValue() );
m_settings.SetFlag( FL_SUBTRACT_MASK_FROM_SILK, m_checkBoxSubtractMaskFromSilk->GetValue() );
// Set 3D shapes visibility
m_3Dprms.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, m_checkBox3DshapesTH->GetValue() );
m_3Dprms.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT, m_checkBox3DshapesSMD->GetValue() );
m_3Dprms.SetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL, m_checkBox3DshapesVirtual->GetValue() );
m_settings.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, m_checkBox3DshapesTH->GetValue() );
m_settings.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT, m_checkBox3DshapesSMD->GetValue() );
m_settings.SetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL, m_checkBox3DshapesVirtual->GetValue() );
// Set Layer visibility
m_3Dprms.SetFlag( FL_SILKSCREEN, m_checkBoxSilkscreen->GetValue() );
m_3Dprms.SetFlag( FL_SOLDERMASK, m_checkBoxSolderMask->GetValue() );
m_3Dprms.SetFlag( FL_SOLDERPASTE, m_checkBoxSolderpaste->GetValue() );
m_3Dprms.SetFlag( FL_ADHESIVE, m_checkBoxAdhesive->GetValue() );
m_3Dprms.SetFlag( FL_COMMENTS, m_checkBoxComments->GetValue() );
m_3Dprms.SetFlag( FL_ECO, m_checkBoxECO->GetValue( ) );
m_settings.SetFlag( FL_SILKSCREEN, m_checkBoxSilkscreen->GetValue() );
m_settings.SetFlag( FL_SOLDERMASK, m_checkBoxSolderMask->GetValue() );
m_settings.SetFlag( FL_SOLDERPASTE, m_checkBoxSolderpaste->GetValue() );
m_settings.SetFlag( FL_ADHESIVE, m_checkBoxAdhesive->GetValue() );
m_settings.SetFlag( FL_COMMENTS, m_checkBoxComments->GetValue() );
m_settings.SetFlag( FL_ECO, m_checkBoxECO->GetValue( ) );
return true;
}

View File

@ -33,13 +33,12 @@
#include <3d_viewer_id.h>
#include "../common_ogl/cogl_att_list.h"
#include <3d_viewer/tools/3d_actions.h>
#include <3d_viewer/tools/3d_viewer_control.h>
#include <3d_viewer/tools/3d_controller.h>
#include <bitmaps.h>
#include <board_stackup_manager/class_board_stackup.h>
#include <board_stackup_manager/stackup_predefined_prms.h>
#include <class_board.h>
#include <dpi_scaling.h>
#include <gestfich.h>
#include <layers_id_colors_and_visibility.h>
#include <pgm_base.h>
#include <project.h>
@ -131,7 +130,7 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent, const wxSt
// Register tools
m_toolManager->RegisterTool( new COMMON_CONTROL );
m_toolManager->RegisterTool( new EDA_3D_VIEWER_CONTROL );
m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
m_toolManager->InitTools();
// Run the viewer control tool, it is supposed to be always active
@ -218,8 +217,7 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
int id = event.GetId();
bool isChecked = event.IsChecked();
wxLogTrace( m_logTrace,
"EDA_3D_VIEWER::Process_Special_Functions id %d isChecked %d",
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::Process_Special_Functions id %d isChecked %d",
id, isChecked );
if( m_canvas == NULL )
@ -332,9 +330,7 @@ void EDA_3D_VIEWER::OnRenderEngineSelection( wxCommandEvent &event )
"OpenGL Legacy" );
if( old_engine != m_settings.RenderEngineGet() )
{
RenderEngineChanged();
}
}
@ -433,25 +429,16 @@ void EDA_3D_VIEWER::LoadSettings( APP_SETTINGS_BASE *aCfg )
m_settings.SetFlag( FL_AXIS, cfg->m_Render.show_axis );
m_settings.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, cfg->m_Render.show_footprints_normal );
m_settings.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT, cfg->m_Render.show_footprints_insert );
m_settings.SetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL, cfg->m_Render.show_footprints_virtual );
m_settings.SetFlag( FL_ZONE, cfg->m_Render.show_zones );
m_settings.SetFlag( FL_ADHESIVE, cfg->m_Render.show_adhesive );
m_settings.SetFlag( FL_SILKSCREEN, cfg->m_Render.show_silkscreen );
m_settings.SetFlag( FL_SOLDERMASK, cfg->m_Render.show_soldermask );
m_settings.SetFlag( FL_SOLDERPASTE, cfg->m_Render.show_solderpaste );
m_settings.SetFlag( FL_COMMENTS, cfg->m_Render.show_comments );
m_settings.SetFlag( FL_ECO, cfg->m_Render.show_eco );
m_settings.SetFlag( FL_SHOW_BOARD_BODY, cfg->m_Render.show_board_body );
m_settings.GridSet( static_cast<GRID3D_TYPE>( cfg->m_Render.grid_type ) );

View File

@ -4,7 +4,7 @@
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2020 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
@ -32,7 +32,7 @@
#ifndef EDA_3D_VIEWER_H
#define EDA_3D_VIEWER_H
#include "../3d_canvas/cinfo3d_visu.h"
#include "3d_canvas/3d_settings.h"
#include "../3d_canvas/eda_3d_canvas.h"
#include <kiway_player.h>
#include <wx/colourdata.h>
@ -62,7 +62,7 @@ enum EDA_3D_VIEWER_STATUSBAR
/**
* Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard
*/
class EDA_3D_VIEWER : public KIWAY_PLAYER
class EDA_3D_VIEWER : public EDA_3D_SETTINGS_HOLDER, public KIWAY_PLAYER
{
public:
@ -77,7 +77,7 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
BOARD* GetBoard() { return Parent()->GetBoard(); }
EDA_3D_CANVAS* GetCanvas() { return m_canvas; }
wxWindow* GetToolCanvas() const override { return m_canvas; }
/**
* Request reloading the 3D view. However the request will be executed
@ -104,7 +104,7 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
/**
* @return current settings
*/
CINFO3D_VISU &GetSettings() { return m_settings; }
EDA_3D_SETTINGS* GetSettings() override { return &m_settings; }
/**
* Get a SFVEC3D from a wx colour dialog
@ -209,7 +209,7 @@ private:
ACTION_TOOLBAR* m_mainToolBar;
EDA_3D_CANVAS* m_canvas;
CINFO3D_VISU m_settings;
EDA_3D_SETTINGS m_settings;
TOOL_DISPATCHER* m_toolDispatcher;

View File

@ -0,0 +1,327 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 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
*/
#include <tool/actions.h>
#include <tool/tool_manager.h>
#include <eda_3d_canvas.h>
#include <eda_3d_viewer.h>
#include <id.h>
#include <kiface_i.h>
#include <3d_viewer_id.h>
#include <tools/3d_controller.h>
#include "3d_actions.h"
bool EDA_3D_CONTROLLER::Init()
{
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
ctxMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EDA_3D_ACTIONS::viewTop, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::viewBottom, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EDA_3D_ACTIONS::viewRight, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::viewLeft, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EDA_3D_ACTIONS::viewFront, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::viewBack, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EDA_3D_ACTIONS::moveLeft, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::moveRight, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::moveUp, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::moveDown, SELECTION_CONDITIONS::ShowAlways );
return true;
}
void EDA_3D_CONTROLLER::Reset( RESET_REASON aReason )
{
TOOLS_HOLDER* holder = m_toolMgr->GetToolHolder();
m_canvas = dynamic_cast<EDA_3D_CANVAS*>( holder->GetToolCanvas() );
m_settings = dynamic_cast<EDA_3D_SETTINGS_HOLDER*>( holder )->GetSettings();
}
int EDA_3D_CONTROLLER::UpdateMenu( const TOOL_EVENT& aEvent )
{
ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
SELECTION dummySel;
if( conditionalMenu )
conditionalMenu->Evaluate( dummySel );
if( actionMenu )
actionMenu->UpdateAll();
return 0;
}
int EDA_3D_CONTROLLER::Main( const TOOL_EVENT& aEvent )
{
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
if( evt->IsClick( BUT_RIGHT ) )
m_menu.ShowContextMenu();
else
evt->SetPassEvent();
}
return 0;
}
int EDA_3D_CONTROLLER::ViewControl( const TOOL_EVENT& aEvent )
{
m_canvas->SetView3D( aEvent.Parameter<intptr_t>() );
return 0;
}
int EDA_3D_CONTROLLER::PanControl( const TOOL_EVENT& aEvent )
{
switch( aEvent.Parameter<intptr_t>() )
{
case ACTIONS::CURSOR_UP: m_canvas->SetView3D( WXK_UP ); break;
case ACTIONS::CURSOR_DOWN: m_canvas->SetView3D( WXK_DOWN ); break;
case ACTIONS::CURSOR_LEFT: m_canvas->SetView3D( WXK_LEFT ); break;
case ACTIONS::CURSOR_RIGHT: m_canvas->SetView3D( WXK_RIGHT ); break;
default: wxFAIL; break;
}
return 0;
}
#define ROT_ANGLE 10.0
int EDA_3D_CONTROLLER::RotateView( const TOOL_EVENT& aEvent )
{
switch( aEvent.Parameter<intptr_t>() )
{
case ID_ROTATE3D_X_NEG: m_settings->CameraGet().RotateX( -glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_X_POS: m_settings->CameraGet().RotateX( glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_Y_NEG: m_settings->CameraGet().RotateY( -glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_Y_POS: m_settings->CameraGet().RotateY( glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_Z_NEG: m_settings->CameraGet().RotateZ( -glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_Z_POS: m_settings->CameraGet().RotateZ( glm::radians( ROT_ANGLE ) ); break;
default: wxFAIL; break;
}
if( m_settings->RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY )
m_canvas->Request_refresh();
else
m_canvas->RenderRaytracingRequest();
return 0;
}
int EDA_3D_CONTROLLER::ToggleOrtho( const TOOL_EVENT& aEvent )
{
m_settings->CameraGet().ToggleProjection();
if( m_settings->RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY )
m_canvas->Request_refresh();
else
m_canvas->RenderRaytracingRequest();
return 0;
}
int EDA_3D_CONTROLLER::ToggleVisibility( const TOOL_EVENT& aEvent )
{
DISPLAY3D_FLG flag = aEvent.Parameter<DISPLAY3D_FLG>();
m_settings->SetFlag( flag, !m_settings->GetFlag( flag ) );
switch( flag )
{
case FL_RENDER_OPENGL_SHOW_MODEL_BBOX:
case FL_RENDER_RAYTRACING_SHADOWS:
case FL_RENDER_RAYTRACING_REFRACTIONS:
case FL_RENDER_RAYTRACING_REFLECTIONS:
case FL_RENDER_RAYTRACING_ANTI_ALIASING:
case FL_AXIS:
m_canvas->Request_refresh();
break;
default:
{
EDA_3D_VIEWER* viewer = dynamic_cast<EDA_3D_VIEWER*>( m_toolMgr->GetToolHolder() );
if( viewer )
viewer->NewDisplay( true );
else
m_canvas->Request_refresh();
break;
}
}
return 0;
}
int EDA_3D_CONTROLLER::On3DGridSelection( const TOOL_EVENT& aEvent )
{
GRID3D_TYPE grid = aEvent.Parameter<GRID3D_TYPE>();
m_settings->GridSet( grid );
if( m_canvas )
m_canvas->Request_refresh();
return 0;
}
int EDA_3D_CONTROLLER::ZoomRedraw( const TOOL_EVENT& aEvent )
{
m_canvas->Request_refresh();
return 0;
}
int EDA_3D_CONTROLLER::ZoomInOut( const TOOL_EVENT& aEvent )
{
bool direction = aEvent.IsAction( &ACTIONS::zoomIn );
return doZoomInOut( direction, true );
}
int EDA_3D_CONTROLLER::ZoomInOutCenter( const TOOL_EVENT& aEvent )
{
bool direction = aEvent.IsAction( &ACTIONS::zoomInCenter );
return doZoomInOut( direction, false );
}
int EDA_3D_CONTROLLER::doZoomInOut( bool aDirection, bool aCenterOnCursor )
{
if( m_canvas )
{
m_canvas->SetView3D( aDirection ? WXK_F1 : WXK_F2 );
m_canvas->DisplayStatus();
}
return 0;
}
int EDA_3D_CONTROLLER::ZoomFitScreen( const TOOL_EVENT& aEvent )
{
if( m_canvas )
{
m_canvas->SetView3D( WXK_HOME );
m_canvas->DisplayStatus();
}
return 0;
}
void EDA_3D_CONTROLLER::setTransitions()
{
Go( &EDA_3D_CONTROLLER::Main, EDA_3D_ACTIONS::controlActivate.MakeEvent() );
Go( &EDA_3D_CONTROLLER::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
// Pan control
Go( &EDA_3D_CONTROLLER::PanControl, ACTIONS::panUp.MakeEvent() );
Go( &EDA_3D_CONTROLLER::PanControl, ACTIONS::panDown.MakeEvent() );
Go( &EDA_3D_CONTROLLER::PanControl, ACTIONS::panLeft.MakeEvent() );
Go( &EDA_3D_CONTROLLER::PanControl, ACTIONS::panRight.MakeEvent() );
Go( &EDA_3D_CONTROLLER::PanControl, EDA_3D_ACTIONS::moveUp.MakeEvent() );
Go( &EDA_3D_CONTROLLER::PanControl, EDA_3D_ACTIONS::moveDown.MakeEvent() );
Go( &EDA_3D_CONTROLLER::PanControl, EDA_3D_ACTIONS::moveLeft.MakeEvent() );
Go( &EDA_3D_CONTROLLER::PanControl, EDA_3D_ACTIONS::moveRight.MakeEvent() );
// View rotation
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::viewTop.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::viewBottom.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::viewLeft.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::viewRight.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::viewFront.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::viewBack.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::pivotCenter.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::homeView.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ViewControl, EDA_3D_ACTIONS::resetView.MakeEvent() );
Go( &EDA_3D_CONTROLLER::RotateView, EDA_3D_ACTIONS::rotateXCW.MakeEvent() );
Go( &EDA_3D_CONTROLLER::RotateView, EDA_3D_ACTIONS::rotateXCCW.MakeEvent() );
Go( &EDA_3D_CONTROLLER::RotateView, EDA_3D_ACTIONS::rotateYCW.MakeEvent() );
Go( &EDA_3D_CONTROLLER::RotateView, EDA_3D_ACTIONS::rotateYCCW.MakeEvent() );
Go( &EDA_3D_CONTROLLER::RotateView, EDA_3D_ACTIONS::rotateZCW.MakeEvent() );
Go( &EDA_3D_CONTROLLER::RotateView, EDA_3D_ACTIONS::rotateZCCW.MakeEvent() );
// Zoom control
Go( &EDA_3D_CONTROLLER::ZoomRedraw, ACTIONS::zoomRedraw.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ZoomInOut, ACTIONS::zoomIn.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ZoomInOut, ACTIONS::zoomOut.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ZoomInOutCenter, ACTIONS::zoomInCenter.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ZoomInOutCenter, ACTIONS::zoomOutCenter.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ZoomFitScreen, ACTIONS::zoomFitScreen.MakeEvent() );
// Grid
Go( &EDA_3D_CONTROLLER::On3DGridSelection, EDA_3D_ACTIONS::noGrid.MakeEvent() );
Go( &EDA_3D_CONTROLLER::On3DGridSelection, EDA_3D_ACTIONS::show10mmGrid.MakeEvent() );
Go( &EDA_3D_CONTROLLER::On3DGridSelection, EDA_3D_ACTIONS::show5mmGrid.MakeEvent() );
Go( &EDA_3D_CONTROLLER::On3DGridSelection, EDA_3D_ACTIONS::show2_5mmGrid.MakeEvent() );
Go( &EDA_3D_CONTROLLER::On3DGridSelection, EDA_3D_ACTIONS::show1mmGrid.MakeEvent() );
// Visibility
Go( &EDA_3D_CONTROLLER::ToggleOrtho, EDA_3D_ACTIONS::toggleOrtho.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::attributesTHT.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::attributesSMD.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::attributesVirtual.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::showCopperThickness.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::showBoundingBoxes.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::renderShadows.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::proceduralTextures.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::addFloor.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::showRefractions.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::showReflections.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::antiAliasing.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::postProcessing.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleRealisticMode.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleBoardBody.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::showAxis.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleZones.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleAdhesive.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleSilk.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleSolderMask.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleSolderPaste.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleComments.MakeEvent() );
Go( &EDA_3D_CONTROLLER::ToggleVisibility, EDA_3D_ACTIONS::toggleECO.MakeEvent() );
}

View File

@ -27,22 +27,25 @@
#include <tool/tool_interactive.h>
class EDA_3D_VIEWER;
class EDA_3D_SETTINGS;
/**
* 3D_VIEWER_CONTROL
* EDA_3D_CONTROLLER
*
* Handles actions that are shared between different applications
* Handles view actions for various 3D canvases.
*/
class EDA_3D_VIEWER_CONTROL : public TOOL_INTERACTIVE
class EDA_3D_CONTROLLER : public TOOL_INTERACTIVE
{
public:
EDA_3D_VIEWER_CONTROL() :
EDA_3D_CONTROLLER() :
TOOL_INTERACTIVE( "3DViewer.Control" ),
m_frame( nullptr )
m_canvas( nullptr ),
m_settings( nullptr )
{ }
~EDA_3D_VIEWER_CONTROL() override { }
~EDA_3D_CONTROLLER() override { }
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init() override;
@ -73,10 +76,11 @@ private:
///> Sets up handlers for various events.
void setTransitions() override;
///> Pointer to the currently used edit frame.
EDA_3D_VIEWER* m_frame;
int doZoomInOut( bool aDirection, bool aCenterOnCursor );
private:
EDA_3D_CANVAS* m_canvas;
EDA_3D_SETTINGS* m_settings;
};
#endif

View File

@ -1,318 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 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
*/
#include <tool/actions.h>
#include <tool/tool_manager.h>
#include <eda_3d_viewer.h>
#include <id.h>
#include <kiface_i.h>
#include <3d_viewer_id.h>
#include "3d_viewer_control.h"
#include "3d_actions.h"
bool EDA_3D_VIEWER_CONTROL::Init()
{
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
ctxMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EDA_3D_ACTIONS::viewTop, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::viewBottom, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EDA_3D_ACTIONS::viewRight, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::viewLeft, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EDA_3D_ACTIONS::viewFront, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::viewBack, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddSeparator();
ctxMenu.AddItem( EDA_3D_ACTIONS::moveLeft, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::moveRight, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::moveUp, SELECTION_CONDITIONS::ShowAlways );
ctxMenu.AddItem( EDA_3D_ACTIONS::moveDown, SELECTION_CONDITIONS::ShowAlways );
return true;
}
void EDA_3D_VIEWER_CONTROL::Reset( RESET_REASON aReason )
{
m_frame = getEditFrame<EDA_3D_VIEWER>();
}
int EDA_3D_VIEWER_CONTROL::UpdateMenu( const TOOL_EVENT& aEvent )
{
ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
SELECTION dummySel;
if( conditionalMenu )
conditionalMenu->Evaluate( dummySel );
if( actionMenu )
actionMenu->UpdateAll();
return 0;
}
int EDA_3D_VIEWER_CONTROL::Main( const TOOL_EVENT& aEvent )
{
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
if( evt->IsClick( BUT_RIGHT ) )
m_menu.ShowContextMenu();
else
evt->SetPassEvent();
}
return 0;
}
int EDA_3D_VIEWER_CONTROL::ViewControl( const TOOL_EVENT& aEvent )
{
m_frame->GetCanvas()->SetView3D( aEvent.Parameter<intptr_t>() );
return 0;
}
int EDA_3D_VIEWER_CONTROL::PanControl( const TOOL_EVENT& aEvent )
{
switch( aEvent.Parameter<intptr_t>() )
{
case ACTIONS::CURSOR_UP: m_frame->GetCanvas()->SetView3D( WXK_UP ); break;
case ACTIONS::CURSOR_DOWN: m_frame->GetCanvas()->SetView3D( WXK_DOWN ); break;
case ACTIONS::CURSOR_LEFT: m_frame->GetCanvas()->SetView3D( WXK_LEFT ); break;
case ACTIONS::CURSOR_RIGHT: m_frame->GetCanvas()->SetView3D( WXK_RIGHT ); break;
default: wxFAIL; break;
}
return 0;
}
#define ROT_ANGLE 10.0
int EDA_3D_VIEWER_CONTROL::RotateView( const TOOL_EVENT& aEvent )
{
CINFO3D_VISU& settings = m_frame->GetSettings();
switch( aEvent.Parameter<intptr_t>() )
{
case ID_ROTATE3D_X_NEG: settings.CameraGet().RotateX( -glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_X_POS: settings.CameraGet().RotateX( glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_Y_NEG: settings.CameraGet().RotateY( -glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_Y_POS: settings.CameraGet().RotateY( glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_Z_NEG: settings.CameraGet().RotateZ( -glm::radians( ROT_ANGLE ) ); break;
case ID_ROTATE3D_Z_POS: settings.CameraGet().RotateZ( glm::radians( ROT_ANGLE ) ); break;
default: wxFAIL; break;
}
if( settings.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY )
m_frame->GetCanvas()->Request_refresh();
else
m_frame->GetCanvas()->RenderRaytracingRequest();
return 0;
}
int EDA_3D_VIEWER_CONTROL::ToggleOrtho( const TOOL_EVENT& aEvent )
{
m_frame->GetSettings().CameraGet().ToggleProjection();
if( m_frame->GetSettings().RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY )
m_frame->GetCanvas()->Request_refresh();
else
m_frame->GetCanvas()->RenderRaytracingRequest();
return 0;
}
int EDA_3D_VIEWER_CONTROL::ToggleVisibility( const TOOL_EVENT& aEvent )
{
DISPLAY3D_FLG flag = aEvent.Parameter<DISPLAY3D_FLG>();
CINFO3D_VISU& settings = m_frame->GetSettings();
settings.SetFlag( flag, !settings.GetFlag( flag ) );
switch( flag )
{
case FL_RENDER_OPENGL_SHOW_MODEL_BBOX:
case FL_RENDER_RAYTRACING_SHADOWS:
case FL_RENDER_RAYTRACING_REFRACTIONS:
case FL_RENDER_RAYTRACING_REFLECTIONS:
case FL_RENDER_RAYTRACING_ANTI_ALIASING:
case FL_AXIS:
m_frame->GetCanvas()->Request_refresh();
break;
default:
m_frame->NewDisplay( true );
break;
}
return 0;
}
int EDA_3D_VIEWER_CONTROL::On3DGridSelection( const TOOL_EVENT& aEvent )
{
GRID3D_TYPE grid = aEvent.Parameter<GRID3D_TYPE>();
m_frame->GetSettings().GridSet( grid );
if( m_frame->GetCanvas() )
m_frame->GetCanvas()->Request_refresh();
return 0;
}
int EDA_3D_VIEWER_CONTROL::ZoomRedraw( const TOOL_EVENT& aEvent )
{
m_frame->GetCanvas()->Request_refresh();
return 0;
}
int EDA_3D_VIEWER_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
{
bool direction = aEvent.IsAction( &ACTIONS::zoomIn );
return doZoomInOut( direction, true );
}
int EDA_3D_VIEWER_CONTROL::ZoomInOutCenter( const TOOL_EVENT& aEvent )
{
bool direction = aEvent.IsAction( &ACTIONS::zoomInCenter );
return doZoomInOut( direction, false );
}
int EDA_3D_VIEWER_CONTROL::doZoomInOut( bool aDirection, bool aCenterOnCursor )
{
if( m_frame->GetCanvas() )
{
m_frame->GetCanvas()->SetView3D( aDirection ? WXK_F1 : WXK_F2 );
m_frame->GetCanvas()->DisplayStatus();
}
return 0;
}
int EDA_3D_VIEWER_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
{
if( m_frame->GetCanvas() )
{
m_frame->GetCanvas()->SetView3D( WXK_HOME );
m_frame->GetCanvas()->DisplayStatus();
}
return 0;
}
void EDA_3D_VIEWER_CONTROL::setTransitions()
{
Go( &EDA_3D_VIEWER_CONTROL::Main, EDA_3D_ACTIONS::controlActivate.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
// Pan control
Go( &EDA_3D_VIEWER_CONTROL::PanControl, ACTIONS::panUp.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::PanControl, ACTIONS::panDown.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::PanControl, ACTIONS::panLeft.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::PanControl, ACTIONS::panRight.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::PanControl, EDA_3D_ACTIONS::moveUp.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::PanControl, EDA_3D_ACTIONS::moveDown.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::PanControl, EDA_3D_ACTIONS::moveLeft.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::PanControl, EDA_3D_ACTIONS::moveRight.MakeEvent() );
// View rotation
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::viewTop.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::viewBottom.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::viewLeft.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::viewRight.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::viewFront.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::viewBack.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::pivotCenter.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::homeView.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ViewControl, EDA_3D_ACTIONS::resetView.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::RotateView, EDA_3D_ACTIONS::rotateXCW.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::RotateView, EDA_3D_ACTIONS::rotateXCCW.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::RotateView, EDA_3D_ACTIONS::rotateYCW.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::RotateView, EDA_3D_ACTIONS::rotateYCCW.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::RotateView, EDA_3D_ACTIONS::rotateZCW.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::RotateView, EDA_3D_ACTIONS::rotateZCCW.MakeEvent() );
// Zoom control
Go( &EDA_3D_VIEWER_CONTROL::ZoomRedraw, ACTIONS::zoomRedraw.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ZoomInOut, ACTIONS::zoomIn.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ZoomInOut, ACTIONS::zoomOut.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ZoomInOutCenter, ACTIONS::zoomInCenter.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ZoomInOutCenter, ACTIONS::zoomOutCenter.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ZoomFitScreen, ACTIONS::zoomFitScreen.MakeEvent() );
// Grid
Go( &EDA_3D_VIEWER_CONTROL::On3DGridSelection, EDA_3D_ACTIONS::noGrid.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::On3DGridSelection, EDA_3D_ACTIONS::show10mmGrid.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::On3DGridSelection, EDA_3D_ACTIONS::show5mmGrid.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::On3DGridSelection, EDA_3D_ACTIONS::show2_5mmGrid.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::On3DGridSelection, EDA_3D_ACTIONS::show1mmGrid.MakeEvent() );
// Visibility
Go( &EDA_3D_VIEWER_CONTROL::ToggleOrtho, EDA_3D_ACTIONS::toggleOrtho.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::attributesTHT.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::attributesSMD.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::attributesVirtual.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::showCopperThickness.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::showBoundingBoxes.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::renderShadows.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::proceduralTextures.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::addFloor.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::showRefractions.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::showReflections.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::antiAliasing.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::postProcessing.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleRealisticMode.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleBoardBody.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::showAxis.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleZones.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleAdhesive.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleSilk.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleSolderMask.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleSolderPaste.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleComments.MakeEvent() );
Go( &EDA_3D_VIEWER_CONTROL::ToggleVisibility, EDA_3D_ACTIONS::toggleECO.MakeEvent() );
}

View File

@ -34,8 +34,8 @@ set(3D-VIEWER_SRCS
${DIR_DLG}/3d_cache_dialogs.cpp
${DIR_DLG}/dlg_select_3dmodel.cpp
${DIR_DLG}/panel_prev_3d_base.cpp
${DIR_DLG}/panel_prev_model.cpp
3d_canvas/cinfo3d_visu.cpp
${DIR_DLG}/panel_prev_3d.cpp
3d_canvas/3d_settings.cpp
3d_canvas/create_layer_items.cpp
3d_canvas/create_3Dgraphic_brd_items.cpp
3d_canvas/create_layer_poly.cpp
@ -86,14 +86,14 @@ set(3D-VIEWER_SRCS
3d_rendering/cpostshader.cpp
3d_rendering/cpostshader_ssao.cpp
3d_rendering/ctrack_ball.cpp
3d_viewer/3d_menubar.cpp
3d_rendering/test_cases.cpp
3d_rendering/trackball.cpp
3d_viewer/3d_menubar.cpp
3d_viewer/3d_toolbar.cpp
3d_viewer/dialogs/dialog_3D_view_option.cpp
3d_viewer/dialogs/dialog_3D_view_option_base.cpp
3d_viewer/tools/3d_actions.cpp
3d_viewer/tools/3d_viewer_control.cpp
3d_viewer/tools/3d_controller.cpp
3d_viewer/eda_3d_viewer.cpp
3d_viewer/3d_viewer_settings.cpp
common_ogl/cogl_att_list.cpp

View File

@ -151,13 +151,8 @@ BM2CMP_FRAME::BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
{
SetKiway( this, aKiway );
wxString unitList[] =
{
_("mm"), _("Inch"), _("DPI")
};
for( int ii = 0; ii < 3; ii++ )
m_PixelUnit->Append( unitList[ii] );
for( wxString unit : { _( "mm" ), _( "Inch" ), _( "DPI" ) } )
m_PixelUnit->Append( unit );
LoadSettings( config() );
@ -202,6 +197,12 @@ BM2CMP_FRAME::~BM2CMP_FRAME()
}
wxWindow* BM2CMP_FRAME::GetToolCanvas() const
{
return m_Notebook->GetCurrentPage();
}
void BM2CMP_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{
EDA_BASE_FRAME::LoadSettings( aCfg );

View File

@ -75,16 +75,15 @@ public:
int GetOutputDPI();
private:
EDA_UNITS m_unit; // The units for m_outputSize (mm, inch, dpi)
double m_outputSize; // The size in m_unit of the output image, depending on
// the user settings. Set to the initial image size
int m_originalDPI; // The image DPI if specified in file, or 0 if unknown
int m_originalSizePixels; // The original image size read from file, in pixels
EDA_UNITS m_unit; // The units for m_outputSize (mm, inch, dpi)
double m_outputSize; // The size in m_unit of the output image, depending on
// the user settings. Set to the initial image size
int m_originalDPI; // The image DPI if specified in file, or 0 if unknown
int m_originalSizePixels; // The original image size read from file, in pixels
};
class BM2CMP_FRAME : public BM2CMP_FRAME_BASE
{
public:
BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent );
~BM2CMP_FRAME();
@ -155,20 +154,22 @@ private:
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
wxWindow* GetToolCanvas() const override;
private:
wxImage m_Pict_Image;
wxBitmap m_Pict_Bitmap;
wxImage m_Greyscale_Image;
wxBitmap m_Greyscale_Bitmap;
wxImage m_NB_Image;
wxBitmap m_BN_Bitmap;
IMAGE_SIZE m_outputSizeX;
IMAGE_SIZE m_outputSizeY;
bool m_Negative;
wxString m_BitmapFileName;
wxString m_ConvertedFileName;
bool m_exportToClipboard;
bool m_AspectRatioLocked;
double m_AspectRatio;
wxImage m_Pict_Image;
wxBitmap m_Pict_Bitmap;
wxImage m_Greyscale_Image;
wxBitmap m_Greyscale_Bitmap;
wxImage m_NB_Image;
wxBitmap m_BN_Bitmap;
IMAGE_SIZE m_outputSizeX;
IMAGE_SIZE m_outputSizeY;
bool m_Negative;
wxString m_BitmapFileName;
wxString m_ConvertedFileName;
bool m_exportToClipboard;
bool m_AspectRatioLocked;
double m_AspectRatio;
};
#endif// BITMOP2CMP_GUI_H_

View File

@ -335,6 +335,7 @@ set( COMMON_SRCS
searchhelpfilefullpath.cpp
status_popup.cpp
systemdirsappend.cpp
tools_holder.cpp
trace_helpers.cpp
undo_redo_container.cpp
utf8.cpp

View File

@ -102,7 +102,7 @@ int KiIconScale( wxWindow* aWindow )
}
static int get_scale_factor( EDA_BASE_FRAME* aWindow )
static int get_scale_factor( wxWindow* aWindow )
{
int requested_scale = Pgm().GetCommonSettings()->m_Appearance.icon_scale;
@ -113,7 +113,7 @@ static int get_scale_factor( EDA_BASE_FRAME* aWindow )
}
wxBitmap KiScaledBitmap( BITMAP_DEF aBitmap, EDA_BASE_FRAME* aWindow )
wxBitmap KiScaledBitmap( BITMAP_DEF aBitmap, wxWindow* aWindow )
{
// Bitmap conversions are cached because they can be slow.
static std::unordered_map<SCALED_BITMAP_ID, wxBitmap> bitmap_cache;
@ -145,7 +145,7 @@ wxBitmap KiScaledBitmap( BITMAP_DEF aBitmap, EDA_BASE_FRAME* aWindow )
}
wxBitmap KiScaledBitmap( const wxBitmap& aBitmap, EDA_BASE_FRAME* aWindow )
wxBitmap KiScaledBitmap( const wxBitmap& aBitmap, wxWindow* aWindow )
{
const int scale = get_scale_factor( aWindow );
@ -164,7 +164,7 @@ wxBitmap KiScaledBitmap( const wxBitmap& aBitmap, EDA_BASE_FRAME* aWindow )
}
void KiScaledSeparator( wxAuiToolBar* aToolbar, EDA_BASE_FRAME* aWindow )
void KiScaledSeparator( wxAuiToolBar* aToolbar, wxWindow* aWindow )
{
const int scale = get_scale_factor( aWindow );

View File

@ -40,6 +40,7 @@
#include <tool/actions.h>
#include <tool/common_control.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <trace_helpers.h>
#include <widgets/paged_dialog.h>
#include <wx/display.h>
@ -57,9 +58,9 @@ BEGIN_EVENT_TABLE( EDA_BASE_FRAME, wxFrame )
EVT_MENU( wxID_PREFERENCES, EDA_BASE_FRAME::OnPreferences )
EVT_CHAR_HOOK( EDA_BASE_FRAME::OnCharHook )
EVT_MENU_OPEN( EDA_BASE_FRAME::OnMenuOpen )
EVT_MENU_CLOSE( EDA_BASE_FRAME::OnMenuOpen )
EVT_MENU_HIGHLIGHT_ALL( EDA_BASE_FRAME::OnMenuOpen )
EVT_MENU_OPEN( EDA_BASE_FRAME::OnMenuEvent )
EVT_MENU_CLOSE( EDA_BASE_FRAME::OnMenuEvent )
EVT_MENU_HIGHLIGHT_ALL( EDA_BASE_FRAME::OnMenuEvent )
EVT_MOVE( EDA_BASE_FRAME::OnMove )
END_EVENT_TABLE()
@ -68,10 +69,6 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
long aStyle, const wxString& aFrameName, KIWAY* aKiway ) :
wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ),
m_actions( nullptr ),
m_immediateActions( true ),
m_dragSelects( true ),
m_moveWarpsCursor( true ),
m_userUnits( EDA_UNITS::MILLIMETRES )
{
m_Ident = aFrameType;
@ -193,80 +190,6 @@ void EDA_BASE_FRAME::SetShutdownBlockReason( const wxString& aReason )
}
// TODO: Implement an RAII mechanism for the stack PushTool/PopTool pairs
void EDA_BASE_FRAME::PushTool( const std::string& actionName )
{
m_toolStack.push_back( actionName );
// Human cognitive stacking is very shallow; deeper tool stacks just get annoying
if( m_toolStack.size() > 3 )
m_toolStack.erase( m_toolStack.begin() );
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( actionName );
if( action )
DisplayToolMsg( action->GetLabel() );
else
DisplayToolMsg( actionName );
}
void EDA_BASE_FRAME::PopTool( const std::string& actionName )
{
// Push/pop events can get out of order (such as when they're generated by the Simulator
// frame but not processed until the mouse is back in the Schematic frame), so make sure
// we're popping the right stack frame.
for( int i = m_toolStack.size() - 1; i >= 0; --i )
{
if( m_toolStack[ i ] == actionName )
{
m_toolStack.erase( m_toolStack.begin() + i );
// If there's something underneath us, and it's now the top of the stack, then
// re-activate it
if( ( --i ) >= 0 && i == (int)m_toolStack.size() - 1 )
{
std::string back = m_toolStack[ i ];
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( back );
if( action )
{
// Pop the action as running it will push it back onto the stack
m_toolStack.pop_back();
TOOL_EVENT evt = action->MakeEvent();
evt.SetHasPosition( false );
GetToolManager()->PostEvent( evt );
}
}
else
DisplayToolMsg( ACTIONS::selectionTool.GetLabel() );
return;
}
}
}
std::string EDA_BASE_FRAME::CurrentToolName() const
{
if( m_toolStack.empty() )
return ACTIONS::selectionTool.GetName();
else
return m_toolStack.back();
}
bool EDA_BASE_FRAME::IsCurrentTool( const TOOL_ACTION& aAction ) const
{
if( m_toolStack.empty() )
return &aAction == &ACTIONS::selectionTool;
else
return m_toolStack.back() == aAction.GetName();
}
bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
{
#ifdef __WXMAC__
@ -347,45 +270,12 @@ void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& event )
}
void EDA_BASE_FRAME::OnMenuOpen( wxMenuEvent& event )
void EDA_BASE_FRAME::OnMenuEvent( wxMenuEvent& aEvent )
{
//
// wxWidgets has several issues that we have to work around:
//
// 1) wxWidgets 3.0.x Windows has a bug where wxEVT_MENU_OPEN and wxEVT_MENU_HIGHLIGHT
// events are not captured by the ACTON_MENU menus. So we forward them here.
// (FWIW, this one is fixed in wxWidgets 3.1.x.)
//
// 2) wxWidgets doesn't pass the menu pointer for wxEVT_MENU_HIGHLIGHT events. So we
// store the menu pointer from the wxEVT_MENU_OPEN call.
//
// 3) wxWidgets has no way to tell whether a command is from a menu selection or a
// hotkey. So we keep track of menu highlighting so we can differentiate.
//
static ACTION_MENU* currentMenu;
if( event.GetEventType() == wxEVT_MENU_OPEN )
{
currentMenu = dynamic_cast<ACTION_MENU*>( event.GetMenu() );
if( currentMenu )
currentMenu->OnMenuEvent( event );
}
else if( event.GetEventType() == wxEVT_MENU_HIGHLIGHT )
{
if( currentMenu )
currentMenu->OnMenuEvent( event );
}
else if( event.GetEventType() == wxEVT_MENU_CLOSE )
{
if( currentMenu )
currentMenu->OnMenuEvent( event );
currentMenu = nullptr;
}
event.Skip();
if( !m_toolDispatcher )
aEvent.Skip();
else
m_toolDispatcher->DispatchWxEvent( aEvent );
}
@ -425,8 +315,7 @@ void EDA_BASE_FRAME::ShowChangedLanguage()
void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
{
if( GetToolManager() )
GetToolManager()->GetActionManager()->UpdateHotKeys( false );
TOOLS_HOLDER::CommonSettingsChanged( aEnvVarsChanged );
if( GetMenuBar() )
{
@ -434,12 +323,6 @@ void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
ReCreateMenuBar();
GetMenuBar()->Refresh();
}
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
m_moveWarpsCursor = settings->m_Input.warp_mouse_on_move;
m_dragSelects = settings->m_Input.prefer_select_to_drag;
m_immediateActions = settings->m_Input.immediate_actions;
}
@ -512,11 +395,7 @@ void EDA_BASE_FRAME::LoadWindowSettings( WINDOW_SETTINGS* aCfg )
m_perspective = aCfg->perspective;
m_mruPath = aCfg->mru_path;
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
m_moveWarpsCursor = settings->m_Input.warp_mouse_on_move;
m_dragSelects = settings->m_Input.prefer_select_to_drag;
m_immediateActions = settings->m_Input.immediate_actions;
TOOLS_HOLDER::CommonSettingsChanged( false );
}

View File

@ -92,6 +92,8 @@
class APP_SETTINGS_BASE;
class TOOL_INTERACTIVE;
class PARAM_CFG;
class EDA_BASE_FRAME;
class LIB_TREE_MODEL_ADAPTER: public wxDataViewModel
{

View File

@ -200,9 +200,9 @@ void ACTION_MANAGER::UpdateHotKeys( bool aFullUpdate )
m_actionHotKeys.clear();
m_hotkeys.clear();
if( aFullUpdate && m_toolMgr->GetEditFrame() )
if( aFullUpdate && m_toolMgr->GetToolHolder() )
{
ReadLegacyHotkeyConfig( m_toolMgr->GetEditFrame()->ConfigBaseName(), legacyHotKeyMap );
ReadLegacyHotkeyConfig( m_toolMgr->GetToolHolder()->ConfigBaseName(), legacyHotKeyMap );
ReadHotKeyConfig( wxEmptyString, userHotKeyMap );
}

View File

@ -73,7 +73,7 @@ void ACTION_MENU::SetIcon( const BITMAP_OPAQUE* aIcon )
void ACTION_MENU::setupEvents()
{
// See wxWidgets hack in EDA_BASE_FRAME::OnMenuOpen().
// See wxWidgets hack in TOOL_DISPATCHER::DispatchWxEvent().
// Connect( wxEVT_MENU_OPEN, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
// Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
// Connect( wxEVT_MENU_CLOSE, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );

View File

@ -42,10 +42,10 @@ ACTION_TOOLBAR::ACTION_TOOLBAR( EDA_BASE_FRAME* parent, wxWindowID id, const wxP
void ACTION_TOOLBAR::Add( const TOOL_ACTION& aAction, bool aIsToggleEntry )
{
EDA_BASE_FRAME* editFrame = m_toolManager->GetEditFrame();
int toolId = aAction.GetId() + ACTION_ID;
wxWindow* parent = dynamic_cast<wxWindow*>( m_toolManager->GetToolHolder() );
int toolId = aAction.GetId() + ACTION_ID;
AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), editFrame ),
AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), parent ),
aAction.GetDescription(), aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL );
m_toolKinds[ toolId ] = aIsToggleEntry;
@ -55,10 +55,10 @@ void ACTION_TOOLBAR::Add( const TOOL_ACTION& aAction, bool aIsToggleEntry )
void ACTION_TOOLBAR::AddButton( const TOOL_ACTION& aAction )
{
EDA_BASE_FRAME* editFrame = m_toolManager->GetEditFrame();
int toolId = aAction.GetId() + ACTION_ID;
wxWindow* parent = dynamic_cast<wxWindow*>( m_toolManager->GetToolHolder() );
int toolId = aAction.GetId() + ACTION_ID;
AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), editFrame ),
AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), parent ),
aAction.GetName(), wxITEM_NORMAL );
m_toolKinds[ toolId ] = false;

View File

@ -45,9 +45,9 @@ KIGFX::VIEW_CONTROLS* TOOL_BASE::getViewControls() const
}
EDA_BASE_FRAME* TOOL_BASE::getEditFrameInt() const
TOOLS_HOLDER* TOOL_BASE::getToolHolderInt() const
{
return m_toolMgr->GetEditFrame();
return m_toolMgr->GetToolHolder();
}

View File

@ -29,6 +29,7 @@
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <tool/actions.h>
#include <tool/action_menu.h>
#include <view/view.h>
#include <view/wx_view_controls.h>
@ -340,7 +341,12 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
// In this case, give the focus to the parent frame (GAL canvas itself does not accept the
// focus when iconized for some obscure reason)
if( wxWindow::FindFocus() == nullptr )
m_toolMgr->GetEditFrame()->SetFocus();
{
wxWindow* window = dynamic_cast<wxWindow*>( m_toolMgr->GetToolHolder() );
if( window )
window->SetFocus();
}
// Mouse handling
// Note: wxEVT_LEFT_DOWN event must always be skipped.
@ -387,10 +393,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
// after second LMB click and currently I have no means to do better debugging
if( type == wxEVT_LEFT_UP )
{
EDA_DRAW_FRAME* drawFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_toolMgr->GetEditFrame() );
if( drawFrame )
drawFrame->GetCanvas()->SetFocus();
if( m_toolMgr->GetToolHolder() && m_toolMgr->GetToolHolder()->GetToolCanvas() )
m_toolMgr->GetToolHolder()->GetToolCanvas()->SetFocus();
}
#endif /* __APPLE__ */
}
@ -470,6 +474,48 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
else
evt = TOOL_EVENT( TC_KEYBOARD, TA_KEY_PRESSED, key | mods );
}
else if( type == wxEVT_MENU_OPEN || type == wxEVT_MENU_CLOSE || type == wxEVT_MENU_HIGHLIGHT )
{
//
// wxWidgets has several issues that we have to work around:
//
// 1) wxWidgets 3.0.x Windows has a bug where wxEVT_MENU_OPEN and wxEVT_MENU_HIGHLIGHT
// events are not captured by the ACTON_MENU menus. So we forward them here.
// (FWIW, this one is fixed in wxWidgets 3.1.x.)
//
// 2) wxWidgets doesn't pass the menu pointer for wxEVT_MENU_HIGHLIGHT events. So we
// store the menu pointer from the wxEVT_MENU_OPEN call.
//
// 3) wxWidgets has no way to tell whether a command is from a menu selection or a
// hotkey. So we keep track of menu highlighting so we can differentiate.
//
static ACTION_MENU* currentMenu;
wxMenuEvent& menuEvent = *dynamic_cast<wxMenuEvent*>( &aEvent );
if( type == wxEVT_MENU_OPEN )
{
currentMenu = dynamic_cast<ACTION_MENU*>( menuEvent.GetMenu() );
if( currentMenu )
currentMenu->OnMenuEvent( menuEvent );
}
else if( type == wxEVT_MENU_HIGHLIGHT )
{
if( currentMenu )
currentMenu->OnMenuEvent( menuEvent );
}
else if( type == wxEVT_MENU_CLOSE )
{
if( currentMenu )
currentMenu->OnMenuEvent( menuEvent );
currentMenu = nullptr;
}
aEvent.Skip();
}
bool handled = false;

View File

@ -846,7 +846,7 @@ void TOOL_MANAGER::DispatchContextMenu( const TOOL_EVENT& aEvent )
m_menuOwner = toolId;
m_menuActive = true;
if( auto frame = dynamic_cast<wxFrame*>( m_frame ) )
if( wxWindow* frame = dynamic_cast<wxWindow*>( m_frame ) )
frame->PopupMenu( menu.get() );
// Warp the cursor if a menu item was selected
@ -937,11 +937,8 @@ bool TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent )
if( m_view && m_view->IsDirty() )
{
auto frame = GetEditFrame();
if( frame )
{
frame->RefreshCanvas();
}
if( GetToolHolder() )
GetToolHolder()->RefreshCanvas();
#if defined( __WXMAC__ ) || defined( __WINDOWS__ )
wxTheApp->ProcessPendingEvents(); // required for updating brightening behind a popup menu
@ -1017,7 +1014,7 @@ TOOL_ID TOOL_MANAGER::MakeToolId( const std::string& aToolName )
void TOOL_MANAGER::SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView,
KIGFX::VIEW_CONTROLS* aViewControls, EDA_BASE_FRAME* aFrame )
KIGFX::VIEW_CONTROLS* aViewControls, TOOLS_HOLDER* aFrame )
{
m_model = aModel;
m_view = aView;
@ -1094,11 +1091,11 @@ bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent )
TOOL_EVENT mod_event( aEvent );
// Only immediate actions get the position. Otherwise clear for tool activation
if( GetEditFrame() && !GetEditFrame()->GetDoImmediateActions() )
if( GetToolHolder() && !GetToolHolder()->GetDoImmediateActions() )
{
// An tool-selection-event has no position
if( mod_event.GetCommandStr().is_initialized()
&& mod_event.GetCommandStr().get() != GetEditFrame()->CurrentToolName() )
&& mod_event.GetCommandStr().get() != GetToolHolder()->CurrentToolName() )
{
mod_event.SetHasPosition( false );
}
@ -1149,7 +1146,7 @@ bool TOOL_MANAGER::IsToolActive( TOOL_ID aId ) const
void TOOL_MANAGER::UpdateUI( const TOOL_EVENT& aEvent )
{
EDA_BASE_FRAME* frame = GetEditFrame();
EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( GetToolHolder() );
if( frame )
{

128
common/tools_holder.cpp Normal file
View File

@ -0,0 +1,128 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 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
*/
#include <pgm_base.h>
#include <settings/common_settings.h>
#include <tool/action_manager.h>
#include <tool/action_menu.h>
#include <tool/actions.h>
#include <tool/tool_manager.h>
#include <tools_holder.h>
TOOLS_HOLDER::TOOLS_HOLDER() :
m_toolManager( nullptr ),
m_actions( nullptr ),
m_toolDispatcher( nullptr ),
m_immediateActions( true ),
m_dragSelects( true ),
m_moveWarpsCursor( true )
{ }
// TODO: Implement an RAII mechanism for the stack PushTool/PopTool pairs
void TOOLS_HOLDER::PushTool( const std::string& actionName )
{
m_toolStack.push_back( actionName );
// Human cognitive stacking is very shallow; deeper tool stacks just get annoying
if( m_toolStack.size() > 3 )
m_toolStack.erase( m_toolStack.begin() );
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( actionName );
if( action )
DisplayToolMsg( action->GetLabel() );
else
DisplayToolMsg( actionName );
}
void TOOLS_HOLDER::PopTool( const std::string& actionName )
{
// Push/pop events can get out of order (such as when they're generated by the Simulator
// frame but not processed until the mouse is back in the Schematic frame), so make sure
// we're popping the right stack frame.
for( int i = (int) m_toolStack.size() - 1; i >= 0; --i )
{
if( m_toolStack[ i ] == actionName )
{
m_toolStack.erase( m_toolStack.begin() + i );
// If there's something underneath us, and it's now the top of the stack, then
// re-activate it
if( ( --i ) >= 0 && i == (int)m_toolStack.size() - 1 )
{
std::string back = m_toolStack[ i ];
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( back );
if( action )
{
// Pop the action as running it will push it back onto the stack
m_toolStack.pop_back();
TOOL_EVENT evt = action->MakeEvent();
evt.SetHasPosition( false );
GetToolManager()->PostEvent( evt );
}
}
else
DisplayToolMsg( ACTIONS::selectionTool.GetLabel() );
return;
}
}
}
std::string TOOLS_HOLDER::CurrentToolName() const
{
if( m_toolStack.empty() )
return ACTIONS::selectionTool.GetName();
else
return m_toolStack.back();
}
bool TOOLS_HOLDER::IsCurrentTool( const TOOL_ACTION& aAction ) const
{
if( m_toolStack.empty() )
return &aAction == &ACTIONS::selectionTool;
else
return m_toolStack.back() == aAction.GetName();
}
void TOOLS_HOLDER::CommonSettingsChanged( bool aEnvVarsChanged )
{
if( GetToolManager() )
GetToolManager()->GetActionManager()->UpdateHotKeys( false );
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
m_moveWarpsCursor = settings->m_Input.warp_mouse_on_move;
m_dragSelects = settings->m_Input.prefer_select_to_drag;
m_immediateActions = settings->m_Input.immediate_actions;
}

View File

@ -958,7 +958,7 @@ std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
}
DISPLAY_FOOTPRINTS_FRAME* CVPCB_MAINFRAME::GetFootprintViewerFrame()
DISPLAY_FOOTPRINTS_FRAME* CVPCB_MAINFRAME::GetFootprintViewerFrame() const
{
// returns the Footprint Viewer frame, if exists, or NULL
return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>
@ -966,6 +966,12 @@ DISPLAY_FOOTPRINTS_FRAME* CVPCB_MAINFRAME::GetFootprintViewerFrame()
}
wxWindow* CVPCB_MAINFRAME::GetToolCanvas() const
{
return GetFootprintViewerFrame();
}
CVPCB_MAINFRAME::CONTROL_TYPE CVPCB_MAINFRAME::GetFocusedControl()
{
if( m_libListBox->HasFocus() )

View File

@ -150,7 +150,9 @@ public:
/**
* @return a pointer on the Footprint Viewer frame, if exists, or NULL
*/
DISPLAY_FOOTPRINTS_FRAME* GetFootprintViewerFrame();
DISPLAY_FOOTPRINTS_FRAME* GetFootprintViewerFrame() const;
wxWindow* GetToolCanvas() const override;
/**
* Find out which control currently has focus.

View File

@ -196,6 +196,9 @@ public:
WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ) override;
// Simulator doesn't host a tool framework
wxWindow* GetToolCanvas() const override { return nullptr; }
private:
/** Give icons to menuitems of the main menubar

View File

@ -696,7 +696,7 @@ static VECTOR2D CLEAR;
// TODO(JE) Probably use netcode rather than connection name here eventually
static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
{
SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
EE_SELECTION_TOOL* selTool = aToolMgr->GetTool<EE_SELECTION_TOOL>();
SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
wxString netName;

View File

@ -106,7 +106,7 @@ protected:
private:
void update() override
{
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) getToolManager()->GetEditFrame();
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) getToolManager()->GetToolHolder();
EE_SELECTION_TOOL* selTool = getToolManager()->GetTool<EE_SELECTION_TOOL>();
KICAD_T busType[] = { SCH_LINE_LOCATE_BUS_T, EOT };
EE_SELECTION& selection = selTool->RequestSelection( busType );

View File

@ -30,7 +30,6 @@
// test if it works under stable release
// #include <wx/bitmap.h> // only to define wxBitmap
class wxBitmap; // only to define wxBitmap
class EDA_BASE_FRAME;
class EDA_DRAW_FRAME;
class wxWindow;
class wxAuiToolBar;
@ -55,7 +54,7 @@ wxBitmap KiBitmap( BITMAP_DEF aBitmap );
* @param aBitmap bitmap definition
* @param aWindow target window for scaling context
*/
wxBitmap KiScaledBitmap( BITMAP_DEF aBitmap, EDA_BASE_FRAME* aWindow );
wxBitmap KiScaledBitmap( BITMAP_DEF aBitmap, wxWindow* aWindow );
/**
* Overload of the above function that takes another wxBitmap as a parameter.
@ -63,12 +62,12 @@ wxBitmap KiScaledBitmap( BITMAP_DEF aBitmap, EDA_BASE_FRAME* aWindow );
* @param aBitmap bitmap definition
* @param aWindow target window for scaling context
*/
wxBitmap KiScaledBitmap( const wxBitmap& aBitmap, EDA_BASE_FRAME* aWindow );
wxBitmap KiScaledBitmap( const wxBitmap& aBitmap, wxWindow* aWindow );
/**
* Add a separator to the given toolbar scaled the same way as KiScaledBitmap.
*/
void KiScaledSeparator( wxAuiToolBar* aToolbar, EDA_BASE_FRAME* aWindow );
void KiScaledSeparator( wxAuiToolBar* aToolbar, wxWindow* aWindow );
/**
* Return the automatic scale factor that would be used for a given window by

View File

@ -46,6 +46,7 @@
#include <frame_type.h>
#include <hotkeys_basic.h>
#include <kiway_holder.h>
#include <tools_holder.h>
#include <widgets/ui_common.h>
// Option for main frames
@ -100,7 +101,7 @@ enum id_librarytype {
* and that class is not a player.
* </p>
*/
class EDA_BASE_FRAME : public wxFrame, public KIWAY_HOLDER
class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER
{
/**
* (with its unexpected name so it does not collide with the real OnWindowClose()
@ -124,35 +125,21 @@ protected:
wxString m_AboutTitle; // Name of program displayed in About.
wxAuiManager m_auimgr;
wxString m_perspective; // wxAuiManager perspective.
wxString m_configName; // Prefix used to identify some params (frame size...)
// and to name some config files (legacy hotkey files)
SETTINGS_MANAGER* m_settingsManager;
TOOL_MANAGER* m_toolManager;
ACTIONS* m_actions;
std::vector<std::string> m_toolStack; // Stack of user-level "tools". Not to be confused
// with TOOL_BASE-derived instances, many of which
// implement multiple user-level "tools". The user-
// level "tools" are TOOL_ACTIONSs internally.
bool m_immediateActions; // Preference for immediate actions. If false, the
// first invocation of a hotkey will just select the
// relevant tool.
bool m_dragSelects; // Prefer selection to dragging.
bool m_moveWarpsCursor; // cursor is warped to move/drag origin
bool m_hasAutoSave;
bool m_autoSaveState;
int m_autoSaveInterval; // The auto save interval time in seconds.
wxTimer* m_autoSaveTimer;
wxString m_perspective; // wxAuiManager perspective.
wxString m_mruPath; // Most recently used path.
EDA_UNITS m_userUnits;
EDA_UNITS m_userUnits;
///> Default style flags used for wxAUI toolbars
static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
@ -232,44 +219,6 @@ public:
virtual int GetSeverity( int aErrorCode ) const { return RPT_SEVERITY_UNDEFINED; }
/**
* Return the MVC controller.
*/
TOOL_MANAGER* GetToolManager() const { return m_toolManager; }
/**
* NB: the definition of "tool" is different at the user level. The implementation uses
* a single TOOL_BASE derived class to implement several user "tools", such as rectangle
* and circle, or wire and bus. So each user-level tool is actually a TOOL_ACTION.
*/
virtual void PushTool( const std::string& actionName );
virtual void PopTool( const std::string& actionName );
bool ToolStackIsEmpty() { return m_toolStack.empty(); }
std::string CurrentToolName() const;
bool IsCurrentTool( const TOOL_ACTION& aAction ) const;
virtual void DisplayToolMsg( const wxString& msg ) {};
/**
* Indicates that hotkeys should perform an immediate action even if another tool is
* currently active. If false, the first hotkey should select the relevant tool.
*/
bool GetDoImmediateActions() const { return m_immediateActions; }
/**
* Indicates that a drag should draw a selection rectangle, even when started over an
* item.
*/
bool GetDragSelects() const { return m_dragSelects; }
/**
* Indicates that a move operation should warp the mouse pointer to the origin of the
* move object. This improves snapping, but some users are alergic to mouse warping.
*/
bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
/**
* Override the default process event handler to implement the auto save feature.
*
@ -288,10 +237,10 @@ public:
virtual void OnCharHook( wxKeyEvent& event );
/**
* Workaround some issues in wxWidgets where the menu events aren't captured by the
* menus themselves.
* The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu
* events aren't captured by the menus themselves.
*/
void OnMenuOpen( wxMenuEvent& event );
void OnMenuEvent( wxMenuEvent& event );
virtual void OnMove( wxMoveEvent& aEvent )
{
@ -376,7 +325,7 @@ public:
* modes in which case the m_configName must be set to the base name so that a single
* config can be used.
*/
wxString ConfigBaseName()
wxString ConfigBaseName() override
{
wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
return baseCfgName;
@ -507,12 +456,7 @@ public:
* Notification event that some of the common (suite-wide) settings have changed.
* Update menus, toolbars, local variables, etc.
*/
virtual void CommonSettingsChanged( bool aEnvVarsChanged );
/**
* Notification to refresh the drawing canvas (if any).
*/
virtual void RefreshCanvas() { };
void CommonSettingsChanged( bool aEnvVarsChanged ) override;
const wxString& GetAboutTitle() const { return m_AboutTitle; }

View File

@ -470,6 +470,8 @@ public:
virtual EDA_DRAW_PANEL_GAL* GetCanvas() const { return m_canvas; }
void SetCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_canvas = aPanel; }
wxWindow* GetToolCanvas() const override { return GetCanvas(); }
/**
* Return a reference to the gal rendering options used by GAL for rendering.
*/

View File

@ -29,7 +29,7 @@
#include <wx/aui/auibar.h>
#include <tool/tool_event.h>
class EDA_DRAW_FRAME;
class EDA_BASE_FRAME;
class TOOL_MANAGER;
class TOOL_ACTION;

View File

@ -35,6 +35,7 @@
class EDA_ITEM;
class TOOL_MANAGER;
class TOOLS_HOLDER;
namespace KIGFX
{
@ -186,9 +187,9 @@ protected:
T* getEditFrame() const
{
#if !defined( QA_TEST ) // Dynamic casts give the linker a siezure in the test framework
wxASSERT( dynamic_cast<T*>( getEditFrameInt() ) );
wxASSERT( dynamic_cast<T*>( getToolHolderInt() ) );
#endif
return static_cast<T*>( getEditFrameInt() );
return static_cast<T*>( getToolHolderInt() );
}
/**
@ -222,7 +223,7 @@ private:
// hide the implementation to avoid spreading half of
// kicad and wxWidgets headers to the tools that may not need them at all!
EDA_ITEM* getModelInt() const;
EDA_BASE_FRAME* getEditFrameInt() const;
TOOLS_HOLDER* getToolHolderInt() const;
};
#endif

View File

@ -34,10 +34,10 @@
#include <tool/tool_base.h>
#include <view/view_controls.h>
class TOOLS_HOLDER;
class TOOL_BASE;
class ACTION_MANAGER;
class ACTION_MENU;
class EDA_BASE_FRAME;
/**
@ -274,7 +274,7 @@ public:
* These are made available to the tool. Called by the parent frame when it is set up.
*/
void SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView,
KIGFX::VIEW_CONTROLS* aViewControls, EDA_BASE_FRAME* aFrame );
KIGFX::VIEW_CONTROLS* aViewControls, TOOLS_HOLDER* aFrame );
/* Accessors for the environment objects (view, model, etc.) */
KIGFX::VIEW* GetView() const
@ -295,10 +295,7 @@ public:
return m_model;
}
inline EDA_BASE_FRAME* GetEditFrame() const
{
return m_frame;
}
inline TOOLS_HOLDER* GetToolHolder() const { return m_frame; }
/**
* Returns id of the tool that is on the top of the active tools stack
@ -561,10 +558,10 @@ private:
/// Original cursor position, if overridden by the context menu handler
std::map<TOOL_ID, OPT<VECTOR2D>> m_cursorSettings;
EDA_ITEM* m_model;
KIGFX::VIEW* m_view;
EDA_ITEM* m_model;
KIGFX::VIEW* m_view;
KIGFX::VIEW_CONTROLS* m_viewControls;
EDA_BASE_FRAME* m_frame;
TOOLS_HOLDER* m_frame;
/// Queue that stores events to be processed at the end of the event processing cycle.
std::list<TOOL_EVENT> m_eventQueue;

112
include/tools_holder.h Normal file
View File

@ -0,0 +1,112 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 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
*/
#ifndef TOOL_HOLDER_H
#define TOOL_HOLDER_H
#include <vector>
#include <fctsys.h>
#include <common.h>
#include <tool/tool_action.h>
class TOOL_MANAGER;
class TOOL_DISPATCHER;
class ACTIONS;
class TOOLS_HOLDER
{
protected:
TOOL_MANAGER* m_toolManager;
ACTIONS* m_actions;
TOOL_DISPATCHER* m_toolDispatcher;
std::vector<std::string> m_toolStack; // Stack of user-level "tools". Not to be confused
// with TOOL_BASE-derived instances, many of which
// implement multiple user-level "tools". The user-
// level "tools" are TOOL_ACTIONSs internally.
bool m_immediateActions; // Preference for immediate actions. If false, the
// first invocation of a hotkey will just select the
// relevant tool.
bool m_dragSelects; // Prefer selection to dragging.
bool m_moveWarpsCursor; // cursor is warped to move/drag origin
public:
TOOLS_HOLDER();
/**
* Return the MVC controller.
*/
TOOL_MANAGER* GetToolManager() const { return m_toolManager; }
/**
* NB: the definition of "tool" is different at the user level. The implementation uses
* a single TOOL_BASE derived class to implement several user "tools", such as rectangle
* and circle, or wire and bus. So each user-level tool is actually a TOOL_ACTION.
*/
virtual void PushTool( const std::string& actionName );
virtual void PopTool( const std::string& actionName );
bool ToolStackIsEmpty() { return m_toolStack.empty(); }
std::string CurrentToolName() const;
bool IsCurrentTool( const TOOL_ACTION& aAction ) const;
virtual void DisplayToolMsg( const wxString& msg ) {};
/**
* Indicates that hotkeys should perform an immediate action even if another tool is
* currently active. If false, the first hotkey should select the relevant tool.
*/
bool GetDoImmediateActions() const { return m_immediateActions; }
/**
* Indicates that a drag should draw a selection rectangle, even when started over an
* item.
*/
bool GetDragSelects() const { return m_dragSelects; }
/**
* Indicates that a move operation should warp the mouse pointer to the origin of the
* move object. This improves snapping, but some users are alergic to mouse warping.
*/
bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
/**
* Notification event that some of the common (suite-wide) settings have changed.
* Update hotkeys, preferences, etc.
*/
virtual void CommonSettingsChanged( bool aEnvVarsChanged );
/**
* Canvas access.
*/
virtual wxWindow* GetToolCanvas() const = 0;
virtual void RefreshCanvas() { }
virtual wxString ConfigBaseName() { return wxEmptyString; }
};
#endif // TOOL_HOLDER_H

View File

@ -179,6 +179,12 @@ KICAD_MANAGER_FRAME::~KICAD_MANAGER_FRAME()
}
wxWindow* KICAD_MANAGER_FRAME::GetToolCanvas() const
{
return m_leftWin;
}
APP_SETTINGS_BASE* KICAD_MANAGER_FRAME::config()
{
APP_SETTINGS_BASE* ret = PgmTop().PgmSettings();

View File

@ -161,6 +161,8 @@ public:
void ReCreateTreePrj();
wxWindow* GetToolCanvas() const override;
DECLARE_EVENT_TABLE()
private:

View File

@ -379,6 +379,8 @@ public:
void OnBoardClassesUnitsSelection( wxCommandEvent& event ) override;
void BoardClassesUpdateData( double aUnitScale );
// Calculator doesn't host a tool framework
wxWindow* GetToolCanvas() const override { return nullptr; }
};

View File

@ -87,7 +87,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a
PICKED_ITEMS_LIST undoList;
KIGFX::VIEW* view = m_toolMgr->GetView();
BOARD* board = (BOARD*) m_toolMgr->GetModel();
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetEditFrame();
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetToolHolder();
auto connectivity = board->GetConnectivity();
std::set<EDA_ITEM*> savedModules;
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();

View File

@ -44,7 +44,7 @@
#include <widgets/wx_grid.h>
#include "3d_cache/dialogs/3d_cache_dialogs.h"
#include "3d_cache/dialogs/panel_prev_model.h"
#include "3d_cache/dialogs/panel_prev_3d.h"
#include <dialog_edit_footprint_for_BoardEditor.h>

View File

@ -43,7 +43,7 @@
#include <dialog_edit_footprint_for_fp_editor.h>
#include "filename_resolver.h"
#include <pgm_base.h>
#include "3d_cache/dialogs/panel_prev_model.h"
#include "3d_cache/dialogs/panel_prev_3d.h"
#include "3d_cache/dialogs/3d_cache_dialogs.h"
#include <fp_lib_table.h>

View File

@ -237,7 +237,7 @@ void DIALOG_POSITION_RELATIVE::OnUseGridOriginClick( wxCommandEvent& event )
void DIALOG_POSITION_RELATIVE::OnUseUserOriginClick( wxCommandEvent& event )
{
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetEditFrame();
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetToolHolder();
m_anchor_position = (wxPoint) frame->GetScreen()->m_LocalOrigin;
m_referenceInfo->SetLabel( _( "Reference location: local coordinates origin" ) );