3D viewer code cleaning round 5.

This commit is contained in:
Wayne Stambaugh 2020-12-16 17:10:42 -05:00
parent 1ca75c8fda
commit f8efe4a65a
16 changed files with 801 additions and 758 deletions

View File

@ -43,6 +43,8 @@
* The debug output can be turned on by setting the WXTRACE environment variable to * The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for * "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for
* more information. * more information.
*
* @ingroup trace_env_vars
*/ */
const wxChar *BOARD_ADAPTER::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" ); const wxChar *BOARD_ADAPTER::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" );
@ -238,6 +240,7 @@ void BOARD_ADAPTER::SetFlag( DISPLAY3D_FLG aFlag, bool aState )
m_drawFlags[aFlag] = aState; m_drawFlags[aFlag] = aState;
} }
bool BOARD_ADAPTER::ShouldFPBeDisplayed( FOOTPRINT_ATTR_T aFPAttributes ) const bool BOARD_ADAPTER::ShouldFPBeDisplayed( FOOTPRINT_ATTR_T aFPAttributes ) const
{ {
if( aFPAttributes & FP_SMD ) if( aFPAttributes & FP_SMD )
@ -253,11 +256,13 @@ bool BOARD_ADAPTER::ShouldFPBeDisplayed( FOOTPRINT_ATTR_T aFPAttributes ) const
#define COPPER_THICKNESS KiROUND( 0.035 * IU_PER_MM ) // for 35 um #define COPPER_THICKNESS KiROUND( 0.035 * IU_PER_MM ) // for 35 um
#define TECH_LAYER_THICKNESS KiROUND( 0.04 * IU_PER_MM ) #define TECH_LAYER_THICKNESS KiROUND( 0.04 * IU_PER_MM )
int BOARD_ADAPTER::GetHolePlatingThicknessBIU() const noexcept int BOARD_ADAPTER::GetHolePlatingThicknessBIU() const noexcept
{ {
return m_board->GetDesignSettings().GetHolePlatingThickness(); return m_board->GetDesignSettings().GetHolePlatingThickness();
} }
unsigned int BOARD_ADAPTER::GetNrSegmentsCircle( float aDiameter3DU ) const unsigned int BOARD_ADAPTER::GetNrSegmentsCircle( float aDiameter3DU ) const
{ {
wxASSERT( aDiameter3DU > 0.0f ); wxASSERT( aDiameter3DU > 0.0f );
@ -295,7 +300,6 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR
// Calculates the board bounding box (board outlines + items) // Calculates the board bounding box (board outlines + items)
// to ensure any item, even outside the board outlines can be seen // to ensure any item, even outside the board outlines can be seen
bool boardEdgesOnly = true; bool boardEdgesOnly = true;
if( m_board->IsFootprintHolder() || !GetFlag( FL_USE_REALISTIC_MODE ) if( m_board->IsFootprintHolder() || !GetFlag( FL_USE_REALISTIC_MODE )
@ -322,7 +326,7 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR
if( m_copperLayersCount < 2 ) if( m_copperLayersCount < 2 )
m_copperLayersCount = 2; m_copperLayersCount = 2;
// Calculate the convertion to apply to all positions. // Calculate the conversion to apply to all positions.
m_biuTo3Dunits = RANGE_SCALE_3D / std::max( m_boardSize.x, m_boardSize.y ); 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;
@ -423,17 +427,14 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR
m_layerZcoordBottom[layer_id] = zposBottom; m_layerZcoordBottom[layer_id] = zposBottom;
} }
m_boardCenter = SFVEC3F( m_boardPos.x * m_biuTo3Dunits, m_boardCenter = SFVEC3F( m_boardPos.x * m_biuTo3Dunits, m_boardPos.y * m_biuTo3Dunits, 0.0f );
m_boardPos.y * m_biuTo3Dunits,
0.0f );
SFVEC3F boardSize = SFVEC3F( m_boardSize.x * m_biuTo3Dunits, SFVEC3F boardSize = SFVEC3F( m_boardSize.x * m_biuTo3Dunits, m_boardSize.y * m_biuTo3Dunits,
m_boardSize.y * m_biuTo3Dunits,
0.0f ); 0.0f );
boardSize /= 2.0f; boardSize /= 2.0f;
SFVEC3F boardMin = (m_boardCenter - boardSize); SFVEC3F boardMin = ( m_boardCenter - boardSize );
SFVEC3F boardMax = (m_boardCenter + boardSize); SFVEC3F boardMax = ( m_boardCenter + boardSize );
boardMin.z = m_layerZcoordTop[B_Adhes]; boardMin.z = m_layerZcoordTop[B_Adhes];
boardMax.z = m_layerZcoordTop[F_Adhes]; boardMax.z = m_layerZcoordTop[F_Adhes];

View File

@ -62,20 +62,19 @@ typedef std::map< PCB_LAYER_ID, SHAPE_POLY_SET *> MAP_POLY;
/** /**
* Class BOARD_ADAPTER * Helper class to handle information needed to display 3D board.
* Helper class to handle information needed to display 3D board
*/ */
class BOARD_ADAPTER class BOARD_ADAPTER
{ {
public: public:
BOARD_ADAPTER(); BOARD_ADAPTER();
~BOARD_ADAPTER(); ~BOARD_ADAPTER();
/** /**
* @brief Set3DCacheManager - Update the Cache manager pointer * Update the cache manager pointer.
* @param aCachePointer: the pointer to the 3d cache manager *
* @param aCachePointer: the pointer to the 3D cache manager.
*/ */
void Set3DCacheManager( S3D_CACHE *aCachePointer ) noexcept void Set3DCacheManager( S3D_CACHE *aCachePointer ) noexcept
{ {
@ -83,8 +82,7 @@ class BOARD_ADAPTER
} }
/** /**
* @brief Get3DCacheManager - Return the 3d cache manager pointer * Return the 3D cache manager pointer.
* @return
*/ */
S3D_CACHE *Get3DCacheManager( ) const noexcept S3D_CACHE *Get3DCacheManager( ) const noexcept
{ {
@ -92,34 +90,37 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetFlag - get a configuration status of a flag * Get a configuration status of a flag.
* @param aFlag: the flag to get the status *
* @return true if flag is set, false if not * @param aFlag the flag to get the status.
* @return true if flag is set, false if not.
*/ */
bool GetFlag( DISPLAY3D_FLG aFlag ) const ; bool GetFlag( DISPLAY3D_FLG aFlag ) const ;
/** /**
* @brief SetFlag - set the status of a flag * Set the status of a flag.
* @param aFlag: the flag to get the status *
* @param aState: status to set * @param aFlag the flag to set the status
* @param aState status to set.
*/ */
void SetFlag( DISPLAY3D_FLG aFlag, bool aState ); void SetFlag( DISPLAY3D_FLG aFlag, bool aState );
/** /**
* @brief Is3DLayerEnabled - Check if a layer is enabled * Check if a layer is enabled.
* @param aLayer: layer ID to get status *
* @param aLayer layer ID to get status.
*/ */
bool Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const; bool Is3DLayerEnabled( PCB_LAYER_ID aLayer ) const;
/** /**
* @brief ShouldFPBeDisplayed - Test if footprint should be displayed in relation to * Test if footprint should be displayed in relation to attributes and the flags.
* attributes and the flags
*/ */
bool ShouldFPBeDisplayed( FOOTPRINT_ATTR_T aFPAttributes ) const; bool ShouldFPBeDisplayed( FOOTPRINT_ATTR_T aFPAttributes ) const;
/** /**
* @brief SetBoard - Set current board to be rendered * Set current board to be rendered.
* @param aBoard: board to process *
* @param aBoard board to process.
*/ */
void SetBoard( BOARD *aBoard ) noexcept void SetBoard( BOARD *aBoard ) noexcept
{ {
@ -127,7 +128,8 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetBoard - Get current board to be rendered * Get current board to be rendered.
*
* @return BOARD pointer * @return BOARD pointer
*/ */
const BOARD *GetBoard() const noexcept const BOARD *GetBoard() const noexcept
@ -141,16 +143,17 @@ class BOARD_ADAPTER
} }
/** /**
* @brief InitSettings - Function to be called by the render when it need to * Function to be called by the render when it need to reload the settings for the board.
* reload the settings for the board. *
* @param aStatusReporter: the pointer for the status reporter * @param aStatusReporter the pointer for the status reporter.
* @param aWarningReporter: pointer for the warning reporter * @param aWarningReporter pointer for the warning reporter.
*/ */
void InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningReporter ); void InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
/** /**
* @brief BiuTo3Dunits - Board integer units To 3D units * Board integer units To 3D units.
* @return the conversion factor to transform a position from the board to 3d units *
* @return the conversion factor to transform a position from the board to 3D units.
*/ */
double BiuTo3Dunits() const noexcept double BiuTo3Dunits() const noexcept
{ {
@ -158,8 +161,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetBBox3DU - Get the bbox of the pcb board * Get the bbox of the pcb board.
* @return the board bbox in 3d units *
* @return the board bbox in 3D units.
*/ */
const CBBOX &GetBBox3DU() const noexcept const CBBOX &GetBBox3DU() const noexcept
{ {
@ -167,8 +171,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetEpoxyThickness3DU - Get the current epoxy thickness * Get the current epoxy thickness.
* @return thickness in 3d units *
* @return thickness in 3D units.
*/ */
float GetEpoxyThickness3DU() const noexcept float GetEpoxyThickness3DU() const noexcept
{ {
@ -176,8 +181,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetNonCopperLayerThickness3DU - Get the current non copper layers thickness * Get the current non copper layers thickness.
* @return thickness in 3d units of non copperlayers *
* @return thickness in 3D units of non copperlayers.
*/ */
float GetNonCopperLayerThickness3DU() const noexcept float GetNonCopperLayerThickness3DU() const noexcept
{ {
@ -185,8 +191,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetCopperThickness3DU - Get the current copper layer thickness * Get the current copper layer thickness.
* @return thickness in 3d units of copperlayers *
* @return thickness in 3D units of copperlayers.
*/ */
float GetCopperThickness3DU() const noexcept float GetCopperThickness3DU() const noexcept
{ {
@ -194,14 +201,16 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetCopperThicknessBIU - Get the current copper layer thickness * Get the current copper layer thickness.
* @return thickness in board units *
* @return thickness in board units.
*/ */
int GetHolePlatingThicknessBIU() const noexcept; int GetHolePlatingThicknessBIU() const noexcept;
/** /**
* @brief GetBoardSizeBIU - Get the board size * Get the board size.
* @return size in BIU units *
* @return size in BIU units.
*/ */
wxSize GetBoardSizeBIU() const noexcept wxSize GetBoardSizeBIU() const noexcept
{ {
@ -209,8 +218,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetBoardPosBIU - Get the board center * Get the board center.
* @return position in BIU units *
* @return position in BIU units.
*/ */
wxPoint GetBoardPosBIU() const noexcept wxPoint GetBoardPosBIU() const noexcept
{ {
@ -218,8 +228,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetBoardCenter - the board center position in 3d units * The board center position in 3D units.
* @return board center vector position in 3d units *
* @return board center vector position in 3D units.
*/ */
const SFVEC3F &GetBoardCenter3DU() const noexcept const SFVEC3F &GetBoardCenter3DU() const noexcept
{ {
@ -227,17 +238,18 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetModulesZcoord3DIU - Get the position of the footprint in 3d integer units * Get the position of the footprint in 3d integer units considering if it is flipped or not.
* considering if it is flipped or not. *
* @param aIsFlipped: true for use in footprints on Front (top) layer, false * @param aIsFlipped true for use in footprints on Front (top) layer, false
* if footprint is on back (bottom) layer * if footprint is on back (bottom) layer.
* @return the Z position of 3D shapes, in 3D integer units * @return the Z position of 3D shapes, in 3D integer units.
*/ */
float GetModulesZcoord3DIU( bool aIsFlipped ) const ; float GetModulesZcoord3DIU( bool aIsFlipped ) const ;
/** /**
* @brief GridGet - get the current grid * Get the current grid.
* @return space type of the grid *
* @return space type of the grid.
*/ */
GRID3D_TYPE GridGet() const noexcept GRID3D_TYPE GridGet() const noexcept
{ {
@ -245,8 +257,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GridSet - set the current grid * Set the current grid.
* @param aGridType = the type space of the grid *
* @param aGridType the type space of the grid.
*/ */
void GridSet( GRID3D_TYPE aGridType ) noexcept void GridSet( GRID3D_TYPE aGridType ) noexcept
{ {
@ -254,20 +267,21 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GridGet - get the current antialiasing mode value * Get the current antialiasing mode value.
*
* @return antialiasing mode value * @return antialiasing mode value
*/ */
ANTIALIASING_MODE AntiAliasingGet() const { return m_antialiasing_mode; } ANTIALIASING_MODE AntiAliasingGet() const { return m_antialiasing_mode; }
/** /**
* @brief AntiAliasingSet - set the current antialiasing mode value * Set the current antialiasing mode value.
* @param aAAmode = antialiasing mode value *
* @param aAAmode antialiasing mode value.
*/ */
void AntiAliasingSet( ANTIALIASING_MODE aAAmode ) { m_antialiasing_mode = aAAmode; } void AntiAliasingSet( ANTIALIASING_MODE aAAmode ) { m_antialiasing_mode = aAAmode; }
/** /**
* @brief RenderEngineSet * @param aRenderEngine the render engine mode selected.
* @param aRenderEngine = the render engine mode selected
*/ */
void RenderEngineSet( RENDER_ENGINE aRenderEngine ) noexcept void RenderEngineSet( RENDER_ENGINE aRenderEngine ) noexcept
{ {
@ -275,8 +289,7 @@ class BOARD_ADAPTER
} }
/** /**
* @brief RenderEngineGet * @return render engine on use.
* @return render engine on use
*/ */
RENDER_ENGINE RenderEngineGet() const noexcept RENDER_ENGINE RenderEngineGet() const noexcept
{ {
@ -284,8 +297,7 @@ class BOARD_ADAPTER
} }
/** /**
* @brief MaterialModeSet * @param aMaterialMode the render material mode.
* @param aMaterialMode = the render material mode
*/ */
void MaterialModeSet( MATERIAL_MODE aMaterialMode ) noexcept void MaterialModeSet( MATERIAL_MODE aMaterialMode ) noexcept
{ {
@ -293,8 +305,7 @@ class BOARD_ADAPTER
} }
/** /**
* @brief MaterialModeGet * @return material rendering mode.
* @return material rendering mode
*/ */
MATERIAL_MODE MaterialModeGet() const noexcept MATERIAL_MODE MaterialModeGet() const noexcept
{ {
@ -302,7 +313,8 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetBoardPoly - Get the current polygon of the epoxy board * Get the current polygon of the epoxy board.
*
* @return the shape polygon * @return the shape polygon
*/ */
const SHAPE_POLY_SET &GetBoardPoly() const noexcept const SHAPE_POLY_SET &GetBoardPoly() const noexcept
@ -311,30 +323,32 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetLayerColor - get the technical color of a layer * Get the technical color of a layer.
* @param aLayerId: the layer to get the color information *
* @return the color in SFVEC3F format * @param aLayerId the layer to get the color information.
* @return the color in SFVEC3F format.
*/ */
SFVEC4F GetLayerColor( PCB_LAYER_ID aLayerId ) const; SFVEC4F GetLayerColor( PCB_LAYER_ID aLayerId ) const;
/** /**
* @brief GetItemColor - get the technical color of a layer * Get the technical color of a layer.
* @param aItemId: the item id to get the color information *
* @return the color in SFVEC3F format * @param aItemId the item id to get the color information.
* @return the color in SFVEC3F format.
*/ */
SFVEC4F GetItemColor( int aItemId ) const; SFVEC4F GetItemColor( int aItemId ) const;
/** /**
* @brief GetColor * @param aColor the color mapped.
* @param aColor: the color mapped
* @return the color in SFVEC3F format * @return the color in SFVEC3F format
*/ */
SFVEC4F GetColor( COLOR4D aColor ) const; SFVEC4F GetColor( COLOR4D aColor ) const;
/** /**
* @brief GetLayerTopZpos3DU - Get the top z position * Get the top z position.
* @param aLayerId: layer id *
* @return position in 3D units * @param aLayerId layer id.
* @return position in 3D units.
*/ */
float GetLayerTopZpos3DU( PCB_LAYER_ID aLayerId ) const noexcept float GetLayerTopZpos3DU( PCB_LAYER_ID aLayerId ) const noexcept
{ {
@ -342,9 +356,10 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetLayerBottomZpos3DU - Get the bottom z position * Get the bottom z position.
* @param aLayerId: layer id *
* @return position in 3D units * @param aLayerId layer id.
* @return position in 3D units.
*/ */
float GetLayerBottomZpos3DU( PCB_LAYER_ID aLayerId ) const noexcept float GetLayerBottomZpos3DU( PCB_LAYER_ID aLayerId ) const noexcept
{ {
@ -352,7 +367,8 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetMapLayers - Get the map of container that have the objects per layer * Get the map of container that have the objects per layer.
*
* @return the map containers of this board * @return the map containers of this board
*/ */
const MAP_CONTAINER_2D &GetMapLayers() const noexcept const MAP_CONTAINER_2D &GetMapLayers() const noexcept
@ -371,8 +387,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetMapLayersHoles -Get the map of container that have the holes per layer * Get the map of container that have the holes per layer.
* @return the map containers of holes from this board *
* @return the map containers of holes from this board.
*/ */
const MAP_CONTAINER_2D &GetMapLayersHoles() const noexcept const MAP_CONTAINER_2D &GetMapLayersHoles() const noexcept
{ {
@ -380,8 +397,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetThroughHole_Outer - Get the inflated ThroughHole container * Get the inflated ThroughHole container.
* @return a container with holes *
* @return a container with holes.
*/ */
const CBVHCONTAINER2D &GetThroughHole_Outer() const noexcept const CBVHCONTAINER2D &GetThroughHole_Outer() const noexcept
{ {
@ -389,8 +407,8 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetThroughHole_Outer_Ring - Get the ThroughHole container that * Get the ThroughHole container that include the width of the annular ring.
* include the width of the annular ring. *
* @return a container with holes. * @return a container with holes.
*/ */
const CBVHCONTAINER2D& GetThroughHole_Outer_Ring() const noexcept const CBVHCONTAINER2D& GetThroughHole_Outer_Ring() const noexcept
@ -414,8 +432,7 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetThroughHole_Vias_Outer - * @return a container with via THT holes only.
* @return a container with via THT holes only
*/ */
const CBVHCONTAINER2D &GetThroughHole_Vias_Outer() const noexcept const CBVHCONTAINER2D &GetThroughHole_Vias_Outer() const noexcept
{ {
@ -428,8 +445,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetThroughHole_Inner - Get the ThroughHole container * Get the ThroughHole container.
* @return a container with holes *
* @return a container with holes.
*/ */
const CBVHCONTAINER2D &GetThroughHole_Inner() const noexcept const CBVHCONTAINER2D &GetThroughHole_Inner() const noexcept
{ {
@ -437,8 +455,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetStats_Nr_Vias - Get statistics of the nr of vias * Get statistics of the nr of vias.
* @return number of vias *
* @return number of vias.
*/ */
unsigned int GetStats_Nr_Vias() const noexcept unsigned int GetStats_Nr_Vias() const noexcept
{ {
@ -446,8 +465,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetStats_Nr_Holes - Get statistics of the nr of holes * Get statistics of the nr of holes.
* @return number of holes *
* @return number of holes.
*/ */
unsigned int GetStats_Nr_Holes() const noexcept unsigned int GetStats_Nr_Holes() const noexcept
{ {
@ -455,8 +475,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetStats_Med_Via_Hole_Diameter3DU - Average diameter of the via holes * Average diameter of the via holes.
* @return dimension in 3D units *
* @return dimension in 3D units.
*/ */
float GetStats_Med_Via_Hole_Diameter3DU() const noexcept float GetStats_Med_Via_Hole_Diameter3DU() const noexcept
{ {
@ -464,8 +485,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetStats_Med_Hole_Diameter3DU - Average diameter of holes * average diameter of holes.
* @return dimension in 3D units *
* @return dimension in 3D units.
*/ */
float GetStats_Med_Hole_Diameter3DU() const noexcept float GetStats_Med_Hole_Diameter3DU() const noexcept
{ {
@ -473,8 +495,9 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetStats_Med_Track_Width - Average width of the tracks * Average width of the tracks.
* @return dimensions in 3D units *
* @return dimensions in 3D units.
*/ */
float GetStats_Med_Track_Width() const noexcept float GetStats_Med_Track_Width() const noexcept
{ {
@ -482,22 +505,21 @@ class BOARD_ADAPTER
} }
/** /**
* @brief GetNrSegmentsCircle * @param aDiameter3DU diameter in 3DU.
* @param aDiameter3DU: diameter in 3DU * @return number of sides that should be used in that circle.
* @return number of sides that should be used in that circle
*/ */
unsigned int GetNrSegmentsCircle( float aDiameter3DU ) const; unsigned int GetNrSegmentsCircle( float aDiameter3DU ) const;
/** /**
* @brief GetNrSegmentsCircle * @param aDiameterBIU diameter in board internal units.
* @param aDiameterBIU: diameter in board internal units * @return number of sides that should be used in that circle.
* @return number of sides that should be used in that circle
*/ */
unsigned int GetNrSegmentsCircle( int aDiameterBIU ) const; unsigned int GetNrSegmentsCircle( int aDiameterBIU ) const;
/** /**
* @brief GetPolyMap - Get maps of polygons's layers * Get maps of polygon's layers.
* @return the map with polygons's layers *
* @return the map with polygon's layers.
*/ */
const MAP_POLY &GetPolyMap() const noexcept const MAP_POLY &GetPolyMap() const noexcept
{ {
@ -618,7 +640,6 @@ public:
int m_raytrace_recursivelevel_refractions; int m_raytrace_recursivelevel_refractions;
private: private:
BOARD* m_board; BOARD* m_board;
S3D_CACHE* m_3d_model_manager; S3D_CACHE* m_3d_model_manager;
COLOR_SETTINGS* m_colors; COLOR_SETTINGS* m_colors;
@ -689,7 +710,7 @@ private:
MAP_CONTAINER_2D m_layers_holes2D; MAP_CONTAINER_2D m_layers_holes2D;
/// It contains the list of throughHoles of the board, /// It contains the list of throughHoles of the board,
/// the radius of the hole is inflated with the copper tickness /// the radius of the hole is inflated with the copper thickness
CBVHCONTAINER2D m_through_holes_outer; CBVHCONTAINER2D m_through_holes_outer;
/// It contains the list of throughHoles of the board, /// It contains the list of throughHoles of the board,
@ -701,7 +722,7 @@ private:
CBVHCONTAINER2D m_through_holes_inner; CBVHCONTAINER2D m_through_holes_inner;
/// It contains the list of throughHoles vias of the board, /// It contains the list of throughHoles vias of the board,
/// the radius of the hole is inflated with the copper tickness /// the radius of the hole is inflated with the copper thickness
CBVHCONTAINER2D m_through_holes_vias_outer; CBVHCONTAINER2D m_through_holes_vias_outer;
/// It contains the list of throughHoles vias of the board, /// It contains the list of throughHoles vias of the board,
@ -733,10 +754,10 @@ private:
/// Non copper layers thickness /// Non copper layers thickness
float m_nonCopperLayerThickness3DU; float m_nonCopperLayerThickness3DU;
/// min factor used for cicle segment approximation calculation /// min factor used for circle segment approximation calculation
float m_calc_seg_min_factor3DU; float m_calc_seg_min_factor3DU;
/// max factor used for cicle segment approximation calculation /// max factor used for circle segment approximation calculation
float m_calc_seg_max_factor3DU; float m_calc_seg_max_factor3DU;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2018 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -59,9 +59,10 @@
// But addTextSegmToContainer is a call-back function, // But addTextSegmToContainer is a call-back function,
// so we cannot send them as arguments. // so we cannot send them as arguments.
static int s_textWidth; static int s_textWidth;
static CGENERICCONTAINER2D *s_dstcontainer = NULL; static CGENERICCONTAINER2D* s_dstcontainer = nullptr;
static float s_biuTo3Dunits; static float s_biuTo3Dunits;
static const BOARD_ITEM *s_boardItem = NULL; static const BOARD_ITEM* s_boardItem = nullptr;
// This is a call back function, used by GRText to draw the 3D text shape: // This is a call back function, used by GRText to draw the 3D text shape:
void addTextSegmToContainer( int x0, int y0, int xf, int yf, void* aData ) void addTextSegmToContainer( int x0, int y0, int xf, int yf, void* aData )
@ -70,13 +71,10 @@ void addTextSegmToContainer( int x0, int y0, int xf, int yf, void* aData )
const SFVEC2F end3DU ( xf * s_biuTo3Dunits, -yf * s_biuTo3Dunits ); const SFVEC2F end3DU ( xf * s_biuTo3Dunits, -yf * s_biuTo3Dunits );
if( Is_segment_a_circle( start3DU, end3DU ) ) if( Is_segment_a_circle( start3DU, end3DU ) )
s_dstcontainer->Add( new CFILLEDCIRCLE2D( start3DU, s_dstcontainer->Add( new CFILLEDCIRCLE2D( start3DU, ( s_textWidth / 2 ) * s_biuTo3Dunits,
( s_textWidth / 2 ) * s_biuTo3Dunits,
*s_boardItem) ); *s_boardItem) );
else else
s_dstcontainer->Add( new CROUNDSEGMENT2D( start3DU, s_dstcontainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, s_textWidth * s_biuTo3Dunits,
end3DU,
s_textWidth * s_biuTo3Dunits,
*s_boardItem ) ); *s_boardItem ) );
} }
@ -85,9 +83,8 @@ void addTextSegmToContainer( int x0, int y0, int xf, int yf, void* aData )
// void PCB_TEXT::TransformTextShapeWithClearanceToPolygon // void PCB_TEXT::TransformTextShapeWithClearanceToPolygon
// board_items_to_polygon_shape_transform.cpp // board_items_to_polygon_shape_transform.cpp
void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_TEXT* aText, void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_TEXT* aText,
CGENERICCONTAINER2D *aDstContainer, CGENERICCONTAINER2D* aDstContainer,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId, int aClearanceValue )
int aClearanceValue )
{ {
wxSize size = aText->GetTextSize(); wxSize size = aText->GetTextSize();
@ -131,12 +128,13 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_TEXT* aText,
void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDimension, void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDimension,
CGENERICCONTAINER2D *aDstContainer, CGENERICCONTAINER2D* aDstContainer,
PCB_LAYER_ID aLayerId, int aClearanceValue ) PCB_LAYER_ID aLayerId, int aClearanceValue )
{ {
AddShapeWithClearanceToContainer(&aDimension->Text(), aDstContainer, aLayerId, aClearanceValue); AddShapeWithClearanceToContainer( &aDimension->Text(), aDstContainer, aLayerId,
aClearanceValue );
const int linewidth = aDimension->GetLineThickness() + (2 * aClearanceValue); const int linewidth = aDimension->GetLineThickness() + ( 2 * aClearanceValue );
for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() ) for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
{ {
@ -146,15 +144,11 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDim
{ {
const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg(); const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
const SFVEC2F start3DU( seg.A.x * m_biuTo3Dunits, const SFVEC2F start3DU( seg.A.x * m_biuTo3Dunits, -seg.A.y * m_biuTo3Dunits );
-seg.A.y * m_biuTo3Dunits );
const SFVEC2F end3DU ( seg.B.x * m_biuTo3Dunits, const SFVEC2F end3DU( seg.B.x * m_biuTo3Dunits, -seg.B.y * m_biuTo3Dunits );
-seg.B.y * m_biuTo3Dunits );
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, linewidth * m_biuTo3Dunits,
end3DU,
linewidth * m_biuTo3Dunits,
*aDimension ) ); *aDimension ) );
break; break;
} }
@ -186,7 +180,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDim
// void FOOTPRINT::TransformFPShapesWithClearanceToPolygonSet // void FOOTPRINT::TransformFPShapesWithClearanceToPolygonSet
// board_items_to_polygon_shape_transform.cpp#L204 // board_items_to_polygon_shape_transform.cpp#L204
void BOARD_ADAPTER::AddFPShapesWithClearanceToContainer( const FOOTPRINT* aFootprint, void BOARD_ADAPTER::AddFPShapesWithClearanceToContainer( const FOOTPRINT* aFootprint,
CGENERICCONTAINER2D *aDstContainer, CGENERICCONTAINER2D* aDstContainer,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId,
int aInflateValue ) int aInflateValue )
{ {
@ -224,7 +218,7 @@ void BOARD_ADAPTER::AddFPShapesWithClearanceToContainer( const FOOTPRINT* aFootp
} }
} }
// Convert texts sur footprints // Convert texts for footprints
if( aFootprint->Reference().GetLayer() == aLayerId && aFootprint->Reference().IsVisible() ) if( aFootprint->Reference().GetLayer() == aLayerId && aFootprint->Reference().IsVisible() )
texts.push_back( &aFootprint->Reference() ); texts.push_back( &aFootprint->Reference() );
@ -245,84 +239,85 @@ void BOARD_ADAPTER::AddFPShapesWithClearanceToContainer( const FOOTPRINT* aFootp
if( text->IsMirrored() ) if( text->IsMirrored() )
size.x = -size.x; size.x = -size.x;
GRText( NULL, text->GetTextPos(), BLACK, text->GetShownText(), text->GetDrawRotation(), GRText( nullptr, text->GetTextPos(), BLACK, text->GetShownText(), text->GetDrawRotation(),
size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(), size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(),
forceBold, addTextSegmToContainer ); forceBold, addTextSegmToContainer );
} }
} }
void BOARD_ADAPTER::createNewTrack( const TRACK* aTrack, CGENERICCONTAINER2D *aDstContainer, void BOARD_ADAPTER::createNewTrack( const TRACK* aTrack, CGENERICCONTAINER2D* aDstContainer,
int aClearanceValue ) int aClearanceValue )
{ {
SFVEC2F start3DU( aTrack->GetStart().x * m_biuTo3Dunits, SFVEC2F start3DU( aTrack->GetStart().x * m_biuTo3Dunits,
-aTrack->GetStart().y * m_biuTo3Dunits ); // y coord is inverted -aTrack->GetStart().y * m_biuTo3Dunits ); // y coord is inverted
switch( aTrack->Type() ) switch( aTrack->Type() )
{ {
case PCB_VIA_T: case PCB_VIA_T:
{ {
const float radius = ( ( aTrack->GetWidth() / 2 ) + aClearanceValue ) * m_biuTo3Dunits; const float radius = ( ( aTrack->GetWidth() / 2 ) + aClearanceValue ) * m_biuTo3Dunits;
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, *aTrack ) ); aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, *aTrack ) );
}
break; break;
}
case PCB_ARC_T: case PCB_ARC_T:
{ {
const ARC* arc = static_cast<const ARC*>( aTrack ); const ARC* arc = static_cast<const ARC*>( aTrack );
VECTOR2D center( arc->GetCenter() ); VECTOR2D center( arc->GetCenter() );
double arc_angle = arc->GetAngle(); double arc_angle = arc->GetAngle();
double radius = arc->GetRadius(); double radius = arc->GetRadius();
int arcsegcount = GetArcToSegmentCount( radius, Millimeter2iu( 0.005), arc_angle/10 ); int arcsegcount = GetArcToSegmentCount( radius, Millimeter2iu( 0.005), arc_angle/10 );
int circlesegcount; int circlesegcount;
// We need a circle to segment count. However, the arc angle can be small, and the // We need a circle to segment count. However, the arc angle can be small, and the
// radius very big. so we calculate a reasonable value for circlesegcount. // radius very big. so we calculate a reasonable value for circlesegcount.
if( arcsegcount <= 1 ) // The arc will be approximated by a segment if( arcsegcount <= 1 ) // The arc will be approximated by a segment
circlesegcount = 1; circlesegcount = 1;
else
{
double cnt = arcsegcount * 3600/std::abs( arc_angle );
#define SEG_CNT_MAX 128
if( cnt < SEG_CNT_MAX )
{
circlesegcount = (int)cnt;
if( circlesegcount == 0 )
circlesegcount = 1;
}
else else
{ {
double cnt = arcsegcount * 3600/std::abs( arc_angle ); circlesegcount = SEG_CNT_MAX;
#define SEG_CNT_MAX 128
if( cnt < SEG_CNT_MAX )
{
circlesegcount = (int)cnt;
if( circlesegcount == 0 )
circlesegcount = 1;
}
else
circlesegcount = SEG_CNT_MAX;
} }
TransformArcToSegments( wxPoint( center.x, center.y ), arc->GetStart(),
arc_angle, circlesegcount,
arc->GetWidth() + 2 * aClearanceValue, aDstContainer,
*arc );
} }
TransformArcToSegments( wxPoint( center.x, center.y ), arc->GetStart(),
arc_angle, circlesegcount,
arc->GetWidth() + 2 * aClearanceValue, aDstContainer, *arc );
break; break;
}
case PCB_TRACE_T: // Track is a usual straight segment case PCB_TRACE_T: // Track is a usual straight segment
{
SFVEC2F end3DU( aTrack->GetEnd().x * m_biuTo3Dunits, -aTrack->GetEnd().y * m_biuTo3Dunits );
// Cannot add segments that have the same start and end point
if( Is_segment_a_circle( start3DU, end3DU ) )
{ {
SFVEC2F end3DU ( aTrack->GetEnd().x * m_biuTo3Dunits, const float radius = ((aTrack->GetWidth() / 2) + aClearanceValue) * m_biuTo3Dunits;
-aTrack->GetEnd().y * m_biuTo3Dunits );
// Cannot add segments that have the same start and end point aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, *aTrack ) );
if( Is_segment_a_circle( start3DU, end3DU ) )
{
const float radius = ((aTrack->GetWidth() / 2) + aClearanceValue) * m_biuTo3Dunits;
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, *aTrack ) );
}
else
{
const float width = (aTrack->GetWidth() + 2 * aClearanceValue ) * m_biuTo3Dunits;
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, width, *aTrack ) );
}
} }
else
{
const float width = (aTrack->GetWidth() + 2 * aClearanceValue ) * m_biuTo3Dunits;
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, width, *aTrack ) );
}
break; break;
}
default: default:
break; break;
@ -330,15 +325,13 @@ void BOARD_ADAPTER::createNewTrack( const TRACK* aTrack, CGENERICCONTAINER2D *aD
} }
void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad, void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad, CGENERICCONTAINER2D* aDstContainer,
CGENERICCONTAINER2D *aDstContainer, PCB_LAYER_ID aLayer, wxSize aClearanceValue ) const
PCB_LAYER_ID aLayer,
wxSize aClearanceValue ) const
{ {
SHAPE_POLY_SET poly; SHAPE_POLY_SET poly;
// Our shape-based builder can't handle negative or differing x:y clearance values (the // Our shape-based builder can't handle negative or differing x:y clearance values (the
// former are common for solder paste whiel the later get generated when a relative paste // former are common for solder paste while the later get generated when a relative paste
// margin is used with an oblong pad). So we apply this huge hack and fake a larger pad to // margin is used with an oblong pad). So we apply this huge hack and fake a larger pad to
// run the general-purpose polygon builder on. // run the general-purpose polygon builder on.
// Of course being a hack it falls down when dealing with custom shape pads (where the size // Of course being a hack it falls down when dealing with custom shape pads (where the size
@ -390,7 +383,7 @@ void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad,
const SHAPE_CIRCLE* circle = (SHAPE_CIRCLE*) shape; const SHAPE_CIRCLE* circle = (SHAPE_CIRCLE*) shape;
const int radius = circle->GetRadius() + aClearanceValue.x; const int radius = circle->GetRadius() + aClearanceValue.x;
const SFVEC2F center( circle->GetCenter().x * m_biuTo3Dunits, const SFVEC2F center( circle->GetCenter().x * m_biuTo3Dunits,
-circle->GetCenter().y * m_biuTo3Dunits ); -circle->GetCenter().y * m_biuTo3Dunits );
aDstContainer->Add( new CFILLEDCIRCLE2D( center, radius * m_biuTo3Dunits, *aPad ) ); aDstContainer->Add( new CFILLEDCIRCLE2D( center, radius * m_biuTo3Dunits, *aPad ) );
} }
@ -435,19 +428,19 @@ void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad,
} }
COBJECT2D *BOARD_ADAPTER::createNewPadDrill( const PAD* aPad, int aInflateValue ) COBJECT2D* BOARD_ADAPTER::createNewPadDrill( const PAD* aPad, int aInflateValue )
{ {
wxSize drillSize = aPad->GetDrillSize(); wxSize drillSize = aPad->GetDrillSize();
if( !drillSize.x || !drillSize.y ) if( !drillSize.x || !drillSize.y )
{ {
wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::createNewPadDrill - found an invalid pad" ) ); wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::createNewPadDrill - found an invalid pad" ) );
return NULL; return nullptr;
} }
if( drillSize.x == drillSize.y ) // usual round hole if( drillSize.x == drillSize.y ) // usual round hole
{ {
const int radius = (drillSize.x / 2) + aInflateValue; const int radius = ( drillSize.x / 2 ) + aInflateValue;
const SFVEC2F center( aPad->GetPosition().x * m_biuTo3Dunits, const SFVEC2F center( aPad->GetPosition().x * m_biuTo3Dunits,
-aPad->GetPosition().y * m_biuTo3Dunits ); -aPad->GetPosition().y * m_biuTo3Dunits );
@ -469,12 +462,12 @@ COBJECT2D *BOARD_ADAPTER::createNewPadDrill( const PAD* aPad, int aInflateValue
return new CROUNDSEGMENT2D( start3DU, end3DU, width * m_biuTo3Dunits, *aPad ); return new CROUNDSEGMENT2D( start3DU, end3DU, width * m_biuTo3Dunits, *aPad );
} }
return NULL; return nullptr;
} }
void BOARD_ADAPTER::AddPadsWithClearanceToContainer( const FOOTPRINT* aFootprint, void BOARD_ADAPTER::AddPadsWithClearanceToContainer( const FOOTPRINT* aFootprint,
CGENERICCONTAINER2D *aDstContainer, CGENERICCONTAINER2D* aDstContainer,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId,
int aInflateValue, int aInflateValue,
bool aSkipNPTHPadsWihNoCopper, bool aSkipNPTHPadsWihNoCopper,
@ -546,15 +539,13 @@ void BOARD_ADAPTER::AddPadsWithClearanceToContainer( const FOOTPRINT* aFootprint
} }
} }
// based on TransformArcToPolygon function from // based on TransformArcToPolygon function from
// common/convert_basic_shapes_to_polygon.cpp // common/convert_basic_shapes_to_polygon.cpp
void BOARD_ADAPTER::TransformArcToSegments( const wxPoint &aCentre, void BOARD_ADAPTER::TransformArcToSegments( const wxPoint& aCentre, const wxPoint& aStart,
const wxPoint &aStart, double aArcAngle, int aCircleToSegmentsCount,
double aArcAngle, int aWidth, CGENERICCONTAINER2D* aDstContainer,
int aCircleToSegmentsCount, const BOARD_ITEM& aBoardItem )
int aWidth,
CGENERICCONTAINER2D *aDstContainer,
const BOARD_ITEM &aBoardItem )
{ {
wxPoint arc_start, arc_end; wxPoint arc_start, arc_end;
int delta = 3600 / aCircleToSegmentsCount; // rotate angle in 0.1 degree int delta = 3600 / aCircleToSegmentsCount; // rotate angle in 0.1 degree
@ -605,25 +596,23 @@ void BOARD_ADAPTER::TransformArcToSegments( const wxPoint &aCentre,
if( Is_segment_a_circle( start3DU, end3DU ) ) if( Is_segment_a_circle( start3DU, end3DU ) )
{ {
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits,
( aWidth / 2 ) * m_biuTo3Dunits,
aBoardItem ) ); aBoardItem ) );
} }
else else
{ {
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, aWidth * m_biuTo3Dunits,
end3DU,
aWidth * m_biuTo3Dunits,
aBoardItem ) ); aBoardItem ) );
} }
} }
} }
// Based on // Based on
// TransformShapeWithClearanceToPolygon // TransformShapeWithClearanceToPolygon
// board_items_to_polygon_shape_transform.cpp#L431 // board_items_to_polygon_shape_transform.cpp#L431
void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape, void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape,
CGENERICCONTAINER2D *aDstContainer, CGENERICCONTAINER2D* aDstContainer,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId,
int aClearanceValue ) int aClearanceValue )
{ {
@ -744,7 +733,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape,
// TransformSolidAreasShapesToPolygonSet // TransformSolidAreasShapesToPolygonSet
// board_items_to_polygon_shape_transform.cpp // board_items_to_polygon_shape_transform.cpp
void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer, void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer,
CGENERICCONTAINER2D *aDstContainer, CGENERICCONTAINER2D* aDstContainer,
PCB_LAYER_ID aLayerId ) PCB_LAYER_ID aLayerId )
{ {
// Copy the polys list because we have to simplify it // Copy the polys list because we have to simplify it
@ -779,8 +768,7 @@ void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer,
float radius = line_thickness/2; float radius = line_thickness/2;
if( radius > 0.0 ) // degenerated circles crash 3D viewer if( radius > 0.0 ) // degenerated circles crash 3D viewer
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, *aZoneContainer ) );
*aZoneContainer ) );
} }
else else
{ {
@ -821,14 +809,13 @@ void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer,
} }
void BOARD_ADAPTER::buildPadShapeThickOutlineAsSegments( const PAD* aPad,
void BOARD_ADAPTER::buildPadShapeThickOutlineAsSegments( const PAD* aPad, CGENERICCONTAINER2D* aDstContainer,
CGENERICCONTAINER2D *aDstContainer,
int aWidth ) int aWidth )
{ {
if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring
{ {
const SFVEC2F center3DU( aPad->ShapePos().x * m_biuTo3Dunits, const SFVEC2F center3DU( aPad->ShapePos().x * m_biuTo3Dunits,
-aPad->ShapePos().y * m_biuTo3Dunits ); -aPad->ShapePos().y * m_biuTo3Dunits );
const int radius = aPad->GetSize().x / 2; const int radius = aPad->GetSize().x / 2;

View File

@ -25,6 +25,7 @@
/** /**
* @file create_layer_items.cpp * @file create_layer_items.cpp
* @brief This file implements the creation of the pcb board. * @brief This file implements the creation of the pcb board.
*
* It is based on the function found in the files: * It is based on the function found in the files:
* board_items_to_polygon_shape_transform.cpp * board_items_to_polygon_shape_transform.cpp
* board_items_to_polygon_shape_transform.cpp * board_items_to_polygon_shape_transform.cpp
@ -126,8 +127,8 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
destroyLayers(); destroyLayers();
// Build Copper layers // Build Copper layers
// Based on: https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L692 // 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 stats_startCopperLayersTime = GetRunningMicroSecs();
@ -146,7 +147,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
m_stats_hole_med_diameter = 0; m_stats_hole_med_diameter = 0;
// Prepare track list, convert in a vector. Calc statistic for the holes // Prepare track list, convert in a vector. Calc statistic for the holes
// /////////////////////////////////////////////////////////////////////////
std::vector< const TRACK *> trackList; std::vector< const TRACK *> trackList;
trackList.clear(); trackList.clear();
trackList.reserve( m_board->Tracks().size() ); trackList.reserve( m_board->Tracks().size() );
@ -181,7 +181,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
m_stats_via_med_hole_diameter /= (float)m_stats_nr_vias; m_stats_via_med_hole_diameter /= (float)m_stats_nr_vias;
// Prepare copper layers index and containers // Prepare copper layers index and containers
// /////////////////////////////////////////////////////////////////////////
std::vector< PCB_LAYER_ID > layer_id; std::vector< PCB_LAYER_ID > layer_id;
layer_id.clear(); layer_id.clear();
layer_id.reserve( m_copperLayersCount ); layer_id.reserve( m_copperLayersCount );
@ -202,15 +201,14 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
m_layers_container2D[curr_layer_id] = layerContainer; m_layers_container2D[curr_layer_id] = layerContainer;
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) ) && ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{ {
SHAPE_POLY_SET* layerPoly = new SHAPE_POLY_SET; SHAPE_POLY_SET* layerPoly = new SHAPE_POLY_SET;
m_layers_poly[curr_layer_id] = layerPoly; m_layers_poly[curr_layer_id] = layerPoly;
} }
} }
if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && GetFlag( FL_USE_REALISTIC_MODE ) )
GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
m_F_Cu_PlatedPads_poly = new SHAPE_POLY_SET; m_F_Cu_PlatedPads_poly = new SHAPE_POLY_SET;
m_B_Cu_PlatedPads_poly = new SHAPE_POLY_SET; m_B_Cu_PlatedPads_poly = new SHAPE_POLY_SET;
@ -224,7 +222,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
aStatusReporter->Report( _( "Create tracks and vias" ) ); aStatusReporter->Report( _( "Create tracks and vias" ) );
// Create tracks as objects and add it to container // Create tracks as objects and add it to container
// /////////////////////////////////////////////////////////////////////////
for( PCB_LAYER_ID curr_layer_id : layer_id ) for( PCB_LAYER_ID curr_layer_id : layer_id )
{ {
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() ); wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
@ -254,7 +251,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
// Create VIAS and THTs objects and add it to holes containers // Create VIAS and THTs objects and add it to holes containers
// /////////////////////////////////////////////////////////////////////////
for( PCB_LAYER_ID curr_layer_id : layer_id ) for( PCB_LAYER_ID curr_layer_id : layer_id )
{ {
// ADD TRACKS // ADD TRACKS
@ -277,15 +273,13 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
const float hole_inner_radius = ( holediameter / 2.0f ); const float hole_inner_radius = ( holediameter / 2.0f );
const float ring_radius = via->GetWidth() * BiuTo3Dunits() / 2.0f; const float ring_radius = via->GetWidth() * BiuTo3Dunits() / 2.0f;
const SFVEC2F via_center( const SFVEC2F via_center( via->GetStart().x * m_biuTo3Dunits,
via->GetStart().x * m_biuTo3Dunits, -via->GetStart().y * m_biuTo3Dunits ); -via->GetStart().y * m_biuTo3Dunits );
if( viatype != VIATYPE::THROUGH ) if( viatype != VIATYPE::THROUGH )
{ {
// Add hole objects // Add hole objects
// /////////////////////////////////////////////////////////
CBVHCONTAINER2D *layerHoleContainer = NULL; CBVHCONTAINER2D *layerHoleContainer = NULL;
// Check if the layer is already created // Check if the layer is already created
@ -309,13 +303,11 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
else if( curr_layer_id == layer_id[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 // Add through hole object
// /////////////////////////////////////////////////////////
m_through_holes_outer.Add( new CFILLEDCIRCLE2D( via_center, m_through_holes_outer.Add( new CFILLEDCIRCLE2D( via_center,
hole_inner_radius + thickness, hole_inner_radius + thickness,
*track ) ); *track ) );
m_through_holes_vias_outer.Add( m_through_holes_vias_outer.Add(
new CFILLEDCIRCLE2D( via_center, new CFILLEDCIRCLE2D( via_center, hole_inner_radius + thickness,
hole_inner_radius + thickness,
*track ) ); *track ) );
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) &&
@ -326,8 +318,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
*track ) ); *track ) );
} }
m_through_holes_inner.Add( new CFILLEDCIRCLE2D( via_center, m_through_holes_inner.Add( new CFILLEDCIRCLE2D( via_center, hole_inner_radius,
hole_inner_radius,
*track ) ); *track ) );
//m_through_holes_vias_inner.Add( new CFILLEDCIRCLE2D( via_center, //m_through_holes_vias_inner.Add( new CFILLEDCIRCLE2D( via_center,
@ -339,7 +330,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
// Create VIAS and THTs objects and add it to holes containers // Create VIAS and THTs objects and add it to holes containers
// /////////////////////////////////////////////////////////////////////////
for( PCB_LAYER_ID curr_layer_id : layer_id ) for( PCB_LAYER_ID curr_layer_id : layer_id )
{ {
// ADD TRACKS // ADD TRACKS
@ -360,7 +350,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
if( viatype != VIATYPE::THROUGH ) if( viatype != VIATYPE::THROUGH )
{ {
// Add VIA hole contourns // Add VIA hole contours
// Add outer holes of VIAs // Add outer holes of VIAs
SHAPE_POLY_SET *layerOuterHolesPoly = NULL; SHAPE_POLY_SET *layerOuterHolesPoly = NULL;
@ -406,18 +396,15 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
const int hole_outer_radius = (holediameter / 2) + GetHolePlatingThicknessBIU(); const int hole_outer_radius = (holediameter / 2) + GetHolePlatingThicknessBIU();
const int hole_outer_ring_radius = via->GetWidth() / 2.0f; const int hole_outer_ring_radius = via->GetWidth() / 2.0f;
// Add through hole contourns // Add through hole contours
// /////////////////////////////////////////////////////////
TransformCircleToPolygon( m_through_outer_holes_poly, via->GetStart(), TransformCircleToPolygon( m_through_outer_holes_poly, via->GetStart(),
hole_outer_radius, ARC_HIGH_DEF, ERROR_INSIDE ); hole_outer_radius, ARC_HIGH_DEF, ERROR_INSIDE );
// Add same thing for vias only // Add same thing for vias only
TransformCircleToPolygon( m_through_outer_holes_vias_poly, via->GetStart(), TransformCircleToPolygon( m_through_outer_holes_vias_poly, via->GetStart(),
hole_outer_radius, ARC_HIGH_DEF, ERROR_INSIDE ); hole_outer_radius, ARC_HIGH_DEF, ERROR_INSIDE );
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && GetFlag( FL_USE_REALISTIC_MODE ) )
GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
TransformCircleToPolygon( m_through_outer_ring_holes_poly, TransformCircleToPolygon( m_through_outer_ring_holes_poly,
via->GetStart(), hole_outer_ring_radius, via->GetStart(), hole_outer_ring_radius,
@ -429,9 +416,8 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
// Creates vertical outline contours of the tracks and add it to the poly of the layer // Creates vertical outline contours of the tracks and add it to the poly of the layer
// /////////////////////////////////////////////////////////////////////////
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) ) && ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{ {
for( PCB_LAYER_ID curr_layer_id : layer_id ) for( PCB_LAYER_ID curr_layer_id : layer_id )
{ {
@ -463,7 +449,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
// Add holes of footprints // Add holes of footprints
// /////////////////////////////////////////////////////////////////////////
for( FOOTPRINT* footprint : m_board->Footprints() ) for( FOOTPRINT* footprint : m_board->Footprints() )
{ {
for( PAD* pad : footprint->Pads() ) for( PAD* pad : footprint->Pads() )
@ -483,8 +468,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
m_through_holes_outer.Add( createNewPadDrill( pad, inflate ) ); m_through_holes_outer.Add( createNewPadDrill( pad, inflate ) );
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && GetFlag( FL_USE_REALISTIC_MODE ) )
GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
m_through_holes_outer_ring.Add( createNewPadDrill( pad, inflate ) ); m_through_holes_outer_ring.Add( createNewPadDrill( pad, inflate ) );
} }
@ -497,7 +481,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
m_stats_hole_med_diameter /= (float)m_stats_nr_holes; m_stats_hole_med_diameter /= (float)m_stats_nr_holes;
// Add contours of the pad holes (pads can be Circle or Segment holes) // Add contours of the pad holes (pads can be Circle or Segment holes)
// /////////////////////////////////////////////////////////////////////////
for( FOOTPRINT* footprint : m_board->Footprints() ) for( FOOTPRINT* footprint : m_board->Footprints() )
{ {
for( PAD* pad : footprint->Pads() ) for( PAD* pad : footprint->Pads() )
@ -512,12 +495,10 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
if( pad->GetAttribute () != PAD_ATTRIB_NPTH ) if( pad->GetAttribute () != PAD_ATTRIB_NPTH )
{ {
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && GetFlag( FL_USE_REALISTIC_MODE ) )
GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
pad->TransformHoleWithClearanceToPolygon( m_through_outer_ring_holes_poly, pad->TransformHoleWithClearanceToPolygon( m_through_outer_ring_holes_poly,
inflate, inflate, ARC_HIGH_DEF, ERROR_INSIDE );
ARC_HIGH_DEF, ERROR_INSIDE );
} }
pad->TransformHoleWithClearanceToPolygon( m_through_outer_holes_poly, inflate, pad->TransformHoleWithClearanceToPolygon( m_through_outer_holes_poly, inflate,
@ -526,8 +507,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
else else
{ {
// If not plated, no copper. // If not plated, no copper.
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && GetFlag( FL_USE_REALISTIC_MODE ) )
GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
pad->TransformHoleWithClearanceToPolygon( m_through_outer_ring_holes_poly, 0, pad->TransformHoleWithClearanceToPolygon( m_through_outer_ring_holes_poly, 0,
ARC_HIGH_DEF, ERROR_INSIDE ); ARC_HIGH_DEF, ERROR_INSIDE );
@ -578,9 +558,9 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
m_platedpads_container2D_B_Cu->BuildBVH(); m_platedpads_container2D_B_Cu->BuildBVH();
} }
// Add footprints PADs poly contourns (vertical outlines) // Add footprints PADs poly contours (vertical outlines)
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) ) && ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{ {
for( PCB_LAYER_ID curr_layer_id : layer_id ) for( PCB_LAYER_ID curr_layer_id : layer_id )
{ {
@ -604,7 +584,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
if( renderPlatedPadsAsPlated ) if( renderPlatedPadsAsPlated )
{ {
// ADD PLATED PADS contourns // ADD PLATED PADS contours
for( FOOTPRINT* footprint : m_board->Footprints() ) for( FOOTPRINT* footprint : m_board->Footprints() )
{ {
footprint->TransformPadsWithClearanceToPolygon( *m_F_Cu_PlatedPads_poly, F_Cu, footprint->TransformPadsWithClearanceToPolygon( *m_F_Cu_PlatedPads_poly, F_Cu,
@ -622,7 +602,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
} }
// Add graphic item on copper layers to object containers // Add graphic item on copper layers to object containers
for( PCB_LAYER_ID curr_layer_id : layer_id ) for( PCB_LAYER_ID curr_layer_id : layer_id )
{ {
@ -664,9 +643,9 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
} }
// Add graphic item on copper layers to poly contourns (vertical outlines) // Add graphic item on copper layers to poly contours (vertical outlines)
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) ) && ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{ {
for( PCB_LAYER_ID cur_layer_id : layer_id ) for( PCB_LAYER_ID cur_layer_id : layer_id )
{ {
@ -719,11 +698,11 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
// Add zones objects // Add zones objects
// /////////////////////////////////////////////////////////////////////
std::atomic<size_t> nextZone( 0 ); std::atomic<size_t> nextZone( 0 );
std::atomic<size_t> threadsFinished( 0 ); std::atomic<size_t> threadsFinished( 0 );
size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 ); size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 );
for( size_t ii = 0; ii < parallelThreadCount; ++ii ) for( size_t ii = 0; ii < parallelThreadCount; ++ii )
{ {
std::thread t = std::thread( [&]() std::thread t = std::thread( [&]()
@ -757,7 +736,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
if( GetFlag( FL_ZONE ) && GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) if( GetFlag( FL_ZONE ) && GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) ) && ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{ {
// Add copper zones // Add copper zones
for( ZONE* zone : m_board->Zones() ) for( ZONE* zone : m_board->Zones() )
@ -781,10 +760,9 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
aStatusReporter->Report( _( "Simplifying copper layers polygons" ) ); aStatusReporter->Report( _( "Simplifying copper layers polygons" ) );
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
&& ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) ) && ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) )
{ {
if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && GetFlag( FL_USE_REALISTIC_MODE ) )
GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
if( m_F_Cu_PlatedPads_poly && ( m_layers_poly.find( F_Cu ) != m_layers_poly.end() ) ) if( m_F_Cu_PlatedPads_poly && ( m_layers_poly.find( F_Cu ) != m_layers_poly.end() ) )
{ {
@ -806,16 +784,14 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
std::vector< PCB_LAYER_ID > &selected_layer_id = layer_id; std::vector< PCB_LAYER_ID > &selected_layer_id = layer_id;
std::vector< PCB_LAYER_ID > layer_id_without_F_and_B; std::vector< PCB_LAYER_ID > layer_id_without_F_and_B;
if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && GetFlag( FL_USE_REALISTIC_MODE ) )
GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
layer_id_without_F_and_B.clear(); layer_id_without_F_and_B.clear();
layer_id_without_F_and_B.reserve( layer_id.size() ); layer_id_without_F_and_B.reserve( layer_id.size() );
for( size_t i = 0; i < layer_id.size(); ++i ) for( size_t i = 0; i < layer_id.size(); ++i )
{ {
if( ( layer_id[i] != F_Cu ) && if( ( layer_id[i] != F_Cu ) && ( layer_id[i] != B_Cu ) )
( layer_id[i] != B_Cu ) )
layer_id_without_F_and_B.push_back( layer_id[i] ); layer_id_without_F_and_B.push_back( layer_id[i] );
} }
@ -859,7 +835,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
// Simplify holes polygon contours // Simplify holes polygon contours
// /////////////////////////////////////////////////////////////////////////
if( aStatusReporter ) if( aStatusReporter )
aStatusReporter->Report( _( "Simplify holes contours" ) ); aStatusReporter->Report( _( "Simplify holes contours" ) );
@ -880,15 +855,15 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
// End Build Copper layers // End Build Copper layers
// This will make a union of all added contourns // This will make a union of all added contours
m_through_outer_holes_poly.Simplify( SHAPE_POLY_SET::PM_FAST ); m_through_outer_holes_poly.Simplify( SHAPE_POLY_SET::PM_FAST );
m_through_outer_holes_poly_NPTH.Simplify( SHAPE_POLY_SET::PM_FAST ); m_through_outer_holes_poly_NPTH.Simplify( SHAPE_POLY_SET::PM_FAST );
m_through_outer_holes_vias_poly.Simplify( SHAPE_POLY_SET::PM_FAST ); m_through_outer_holes_vias_poly.Simplify( SHAPE_POLY_SET::PM_FAST );
m_through_outer_ring_holes_poly.Simplify( SHAPE_POLY_SET::PM_FAST ); m_through_outer_ring_holes_poly.Simplify( SHAPE_POLY_SET::PM_FAST );
// Build Tech layers // Build Tech layers
// Based on: https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L1059 // Based on:
// ///////////////////////////////////////////////////////////////////////// // https://github.com/KiCad/kicad-source-mirror/blob/master/3d-viewer/3d_draw.cpp#L1059
if( aStatusReporter ) if( aStatusReporter )
aStatusReporter->Report( _( "Build Tech layers" ) ); aStatusReporter->Report( _( "Build Tech layers" ) );
@ -959,7 +934,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
} }
// Add drawing contours // Add drawing contours
for( BOARD_ITEM* item : m_board->Drawings() ) for( BOARD_ITEM* item : m_board->Drawings() )
{ {
@ -987,12 +961,10 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
} }
// Add footprints tech layers - objects // Add footprints tech layers - objects
// /////////////////////////////////////////////////////////////////////
for( FOOTPRINT* footprint : m_board->Footprints() ) for( FOOTPRINT* footprint : m_board->Footprints() )
{ {
if( (curr_layer_id == F_SilkS) || (curr_layer_id == B_SilkS) ) if( ( curr_layer_id == F_SilkS ) || ( curr_layer_id == B_SilkS ) )
{ {
int linewidth = g_DrawDefaultLineThickness; int linewidth = g_DrawDefaultLineThickness;
@ -1017,7 +989,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
// Add footprints tech layers - contours // Add footprints tech layers - contours
for( FOOTPRINT* footprint : m_board->Footprints() ) for( FOOTPRINT* footprint : m_board->Footprints() )
{ {
if( (curr_layer_id == F_SilkS) || (curr_layer_id == B_SilkS) ) if( ( curr_layer_id == F_SilkS ) || ( curr_layer_id == B_SilkS ) )
{ {
const int linewidth = g_DrawDefaultLineThickness; const int linewidth = g_DrawDefaultLineThickness;

View File

@ -60,7 +60,7 @@ void BOARD_ADAPTER::buildPadShapeThickOutlineAsPolygon( const PAD* aPad,
} }
void BOARD_ADAPTER::transformFPShapesToPolygon( const FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer, void BOARD_ADAPTER::transformFPShapesToPolygon( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer ) const SHAPE_POLY_SET& aCornerBuffer ) const
{ {
for( BOARD_ITEM* item : aFootprint->GraphicalItems() ) for( BOARD_ITEM* item : aFootprint->GraphicalItems() )

View File

@ -62,6 +62,7 @@ const wxChar * EDA_3D_CANVAS::m_logTrace = wxT( "KI_TRACE_EDA_3D_CANVAS" );
const float EDA_3D_CANVAS::m_delta_move_step_factor = 0.7f; const float EDA_3D_CANVAS::m_delta_move_step_factor = 0.7f;
// A custom event, used to call DoRePaint during an idle time // A custom event, used to call DoRePaint during an idle time
wxDEFINE_EVENT( wxEVT_REFRESH_CUSTOM_COMMAND, wxEvent); wxDEFINE_EVENT( wxEVT_REFRESH_CUSTOM_COMMAND, wxEvent);
@ -287,8 +288,7 @@ bool EDA_3D_CANVAS::initializeOpenGL()
if( ( major == 1 ) && ( minor < 5 ) ) if( ( major == 1 ) && ( minor < 5 ) )
{ {
wxLogTrace( m_logTrace, "EDA_3D_CANVAS::%s OpenGL not supported.", wxLogTrace( m_logTrace, "EDA_3D_CANVAS::%s OpenGL not supported.", __WXFUNCTION__ );
__WXFUNCTION__ );
m_is_opengl_version_supported = false; m_is_opengl_version_supported = false;
} }
@ -414,7 +414,6 @@ void EDA_3D_CANVAS::DoRePaint()
const bool windows_size_changed = m_camera.SetCurWindowSize( clientSize ); const bool windows_size_changed = m_camera.SetCurWindowSize( clientSize );
// Initialize openGL if need // Initialize openGL if need
// /////////////////////////////////////////////////////////////////////////
if( !m_is_opengl_initialized ) if( !m_is_opengl_initialized )
{ {
if( !initializeOpenGL() ) if( !initializeOpenGL() )
@ -427,8 +426,8 @@ void EDA_3D_CANVAS::DoRePaint()
if( !m_is_opengl_version_supported ) if( !m_is_opengl_version_supported )
{ {
warningReporter.Report( _( "Your OpenGL version is not supported. Minimum required is 1.5" ), warningReporter.Report( _( "Your OpenGL version is not supported. Minimum required "
RPT_SEVERITY_ERROR ); "is 1.5" ), RPT_SEVERITY_ERROR );
warningReporter.Finalize(); warningReporter.Finalize();
} }
@ -462,11 +461,9 @@ void EDA_3D_CANVAS::DoRePaint()
// It reverts back to OpenGL mode if it was requested a raytracing // It reverts back to OpenGL mode if it was requested a raytracing
// render of the current scene. AND the mouse / camera is moving // render of the current scene. AND the mouse / camera is moving
if( ( m_mouse_is_moving if( ( m_mouse_is_moving || m_camera_is_moving || was_camera_changed
|| m_camera_is_moving || windows_size_changed )
|| was_camera_changed && m_render_raytracing_was_requested )
|| windows_size_changed )
&& m_render_raytracing_was_requested )
{ {
m_render_raytracing_was_requested = false; m_render_raytracing_was_requested = false;
m_3d_render = m_3d_render_ogl_legacy; m_3d_render = m_3d_render_ogl_legacy;
@ -508,7 +505,7 @@ void EDA_3D_CANVAS::DoRePaint()
bool reloadRaytracingForIntersectionCalculations = false; bool reloadRaytracingForIntersectionCalculations = false;
if( ( m_boardAdapter.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY ) if( ( m_boardAdapter.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY )
&& m_3d_render_ogl_legacy->IsReloadRequestPending() ) && m_3d_render_ogl_legacy->IsReloadRequestPending() )
{ {
reloadRaytracingForIntersectionCalculations = true; reloadRaytracingForIntersectionCalculations = true;
} }
@ -748,58 +745,58 @@ void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent &event )
switch( intersectedBoardItem->Type() ) switch( intersectedBoardItem->Type() )
{ {
case PCB_PAD_T: case PCB_PAD_T:
{ {
PAD* pad = dynamic_cast<PAD*>( intersectedBoardItem ); PAD* pad = dynamic_cast<PAD*>( intersectedBoardItem );
if( pad && pad->IsOnCopperLayer() ) if( pad && pad->IsOnCopperLayer() )
{ {
reporter.Report( wxString::Format( _( "Net %s\tNetClass %s\tPadName %s" ), reporter.Report( wxString::Format( _( "Net %s\tNetClass %s\tPadName %s" ),
pad->GetNet()->GetNetname(), pad->GetNet()->GetNetname(),
pad->GetNet()->GetNetClassName(), pad->GetNet()->GetNetClassName(),
pad->GetName() ) ); pad->GetName() ) );
}
} }
}
break; break;
case PCB_FOOTPRINT_T: case PCB_FOOTPRINT_T:
{ {
FOOTPRINT* footprint = dynamic_cast<FOOTPRINT *>( intersectedBoardItem ); FOOTPRINT* footprint = dynamic_cast<FOOTPRINT *>( intersectedBoardItem );
if( footprint ) if( footprint )
reporter.Report( footprint->GetReference() ); reporter.Report( footprint->GetReference() );
} }
break; break;
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_VIA_T: case PCB_VIA_T:
case PCB_ARC_T: case PCB_ARC_T:
{ {
TRACK* track = dynamic_cast<TRACK *>( intersectedBoardItem ); TRACK* track = dynamic_cast<TRACK *>( intersectedBoardItem );
if( track ) if( track )
{ {
reporter.Report( wxString::Format( _( "Net %s\tNetClass %s" ), reporter.Report( wxString::Format( _( "Net %s\tNetClass %s" ),
track->GetNet()->GetNetname(), track->GetNet()->GetNetname(),
track->GetNet()->GetNetClassName() ) ); track->GetNet()->GetNetClassName() ) );
}
} }
}
break; break;
case PCB_ZONE_T: case PCB_ZONE_T:
{ {
ZONE* zone = dynamic_cast<ZONE*>( intersectedBoardItem ); ZONE* zone = dynamic_cast<ZONE*>( intersectedBoardItem );
if( zone && zone->IsOnCopperLayer() ) if( zone && zone->IsOnCopperLayer() )
{ {
reporter.Report( wxString::Format( _( "Net %s\tNetClass %s" ), reporter.Report( wxString::Format( _( "Net %s\tNetClass %s" ),
zone->GetNet()->GetNetname(), zone->GetNet()->GetNetname(),
zone->GetNet()->GetNetClassName() ) ); zone->GetNet()->GetNetClassName() ) );
}
} }
}
break; break;
default: default:
break; break;
} }
} }
@ -941,7 +938,7 @@ void EDA_3D_CANVAS::request_start_moving_camera( float aMovingSpeed, bool aRende
return; return;
} }
// Map speed multipler option to actual multiplier value // Map speed multiplier option to actual multiplier value
// [1,2,3,4,5] -> [0.25, 0.5, 1, 2, 4] // [1,2,3,4,5] -> [0.25, 0.5, 1, 2, 4]
aMovingSpeed *= ( 1 << m_moving_speed_multiplier ) / 8.0f; aMovingSpeed *= ( 1 << m_moving_speed_multiplier ) / 8.0f;

View File

@ -47,13 +47,14 @@ class C3D_RENDER_OGL_LEGACY;
*/ */
class EDA_3D_CANVAS : public HIDPI_GL_CANVAS class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
{ {
public: public:
/** /**
* @brief EDA_3D_CANVAS - Creates a new 3D Canvas with a attribute list * Create a new 3D Canvas with an attribute list.
* @param aParent: the parent creator of this canvas *
* @param aAttribList: a list of openGL options created by GetOpenGL_AttributesList * @param aParent the parent creator of this canvas.
* @param aBoard: The board * @param aAttribList a list of openGL options created by GetOpenGL_AttributesList.
* @param aSettings: the settings options to be used by this canvas * @param aBoard The board.
* @param aSettings the settings options to be used by this canvas.
*/ */
EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard, EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard,
BOARD_ADAPTER& aSettings, CCAMERA& aCamera, S3D_CACHE* a3DCachePointer ); BOARD_ADAPTER& aSettings, CCAMERA& aCamera, S3D_CACHE* a3DCachePointer );
@ -61,11 +62,12 @@ class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
~EDA_3D_CANVAS(); ~EDA_3D_CANVAS();
/** /**
* Function SetEventDispatcher() * Set a dispatcher that processes events and forwards them to tools.
* Sets a dispatcher that processes events and forwards them to tools. *
* @param aEventDispatcher is the object that will be used for dispatching events. * #DRAW_PANEL_GAL does not take over the ownership. Passing NULL disconnects all event
* DRAW_PANEL_GAL does not take over the ownership. Passing NULL disconnects all event
* handlers from the DRAW_PANEL_GAL and parent frame. * handlers from the DRAW_PANEL_GAL and parent frame.
*
* @param aEventDispatcher is the object that will be used for dispatching events.
*/ */
void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher ); void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
@ -82,8 +84,9 @@ class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
void ReloadRequest( BOARD *aBoard = NULL, S3D_CACHE *aCachePointer = NULL ); void ReloadRequest( BOARD *aBoard = NULL, S3D_CACHE *aCachePointer = NULL );
/** /**
* @brief IsReloadRequestPending - Query if there is a pending reload request * Query if there is a pending reload request.
* @return true if it wants to reload, false if there is no reload pending *
* @return true if it wants to reload, false if there is no reload pending.
*/ */
bool IsReloadRequestPending() const bool IsReloadRequestPending() const
{ {
@ -94,7 +97,7 @@ class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
} }
/** /**
* @brief RenderRaytracingRequest - Request to render the current view in Raytracing mode * Request to render the current view in Raytracing mode.
*/ */
void RenderRaytracingRequest(); void RenderRaytracingRequest();
@ -105,51 +108,59 @@ class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
void GetScreenshot( wxImage &aDstImage ); void GetScreenshot( wxImage &aDstImage );
/** /**
* @brief SetView3D - Helper function to call view commands * Helper function to call view commands.
* @param aKeycode: ascii key commands *
* @return true if the key code was handled, * @param aKeycode ascii key commands.
* false if no command found for this code. * @return true if the key code was handled, false if no command found for this code.
*/ */
bool SetView3D( int aKeycode ); bool SetView3D( int aKeycode );
/** /**
* @brief AnimationEnabledSet - Enable or disable camera animation when switching to a pre-defined view * Enable or disable camera animation when switching to a pre-defined view.
* @param aAnimationEnabled: Animation enabled state to set *
* @param aAnimationEnabled animation enabled state to set.
*/ */
void AnimationEnabledSet( bool aAnimationEnabled ) { m_animation_enabled = aAnimationEnabled; } void AnimationEnabledSet( bool aAnimationEnabled ) { m_animation_enabled = aAnimationEnabled; }
/** /**
* @brief AnimationEnabledGet - Returns whether camera animation is enabled when switching to a pre-defined view * Return whether camera animation is enabled when switching to a pre-defined view.
* @return true if animation is enabled *
* @return true if animation is enabled.
*/ */
bool AnimationEnabledGet() const { return m_animation_enabled; } bool AnimationEnabledGet() const { return m_animation_enabled; }
/** /**
* @brief MovingSpeedMultiplierSet - Set the camera animation moving speed multiplier option * Set the camera animation moving speed multiplier option.
* @param aMovingSpeedMultiplier: One of the possible integer options: [1,2,3,4,5] *
* @param aMovingSpeedMultiplier one of the possible integer options: [1,2,3,4,5].
*/ */
void MovingSpeedMultiplierSet( int aMovingSpeedMultiplier ) { m_moving_speed_multiplier = aMovingSpeedMultiplier; } void MovingSpeedMultiplierSet( int aMovingSpeedMultiplier )
{
m_moving_speed_multiplier = aMovingSpeedMultiplier;
}
/** /**
* @brief MovingSpeedMultiplierGet - Return the current camera animation moving speed multiplier option * Return the current camera animation moving speed multiplier option.
* @return current moving speed multiplier option, one of [1,2,3,4,5] *
* @return current moving speed multiplier option, one of [1,2,3,4,5].
*/ */
int MovingSpeedMultiplierGet() const { return m_moving_speed_multiplier; } int MovingSpeedMultiplierGet() const { return m_moving_speed_multiplier; }
/** /**
* @brief RenderEngineChanged - Notify that the render engine was changed * Notify that the render engine was changed.
*/ */
void RenderEngineChanged(); void RenderEngineChanged();
/** /**
* @brief DisplayStatus - Update the status bar with the position information * Update the status bar with the position information.
*/ */
void DisplayStatus(); void DisplayStatus();
/** /**
* @brief Request_refresh - Schedule a refresh update of the canvas * Schedule a refresh update of the canvas.
* @param aRedrawImmediately - true will request a redraw, false will *
* schedule a redraw, after a short timeout. * @param aRedrawImmediately true will request a redraw, false will schedule a redraw
* after a short timeout.
*/ */
void Request_refresh( bool aRedrawImmediately = true ); void Request_refresh( bool aRedrawImmediately = true );
@ -159,14 +170,16 @@ class EDA_3D_CANVAS : public HIDPI_GL_CANVAS
void OnEvent( wxEvent& aEvent ); void OnEvent( wxEvent& aEvent );
private: private:
/** Called by a wxPaintEvent event /**
* Called by a wxPaintEvent event
*/ */
void OnPaint( wxPaintEvent& aEvent ); void OnPaint( wxPaintEvent& aEvent );
/** /**
* The actual function to repaint the canvas. * The actual function to repaint the canvas.
* It is usually called by OnPaint() but because it does not use a wxPaintDC *
* it can be called outside a wxPaintEvent * It is usually called by OnPaint() but because it does not use a wxPaintDC it can be
* called outside a wxPaintEvent
*/ */
void DoRePaint(); void DoRePaint();
@ -192,52 +205,50 @@ private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
private:
/** /**
* @brief stop_editingTimeOut_Timer - stop the editing time, so it will not timeout *Stop the editing time so it will not timeout.
*/ */
void stop_editingTimeOut_Timer(); void stop_editingTimeOut_Timer();
/** /**
* @brief restart_editingTimeOut_Timer - reset the editing timer * Reset the editing timer.
*/ */
void restart_editingTimeOut_Timer(); void restart_editingTimeOut_Timer();
/** /**
* @brief request_start_moving_camera - start a camera movement * Start a camera movement.
* @param aMovingSpeed: the time speed *
* @param aRenderPivot: if it should display pivot cursor while move * @param aMovingSpeed the time speed.
* @param aRenderPivot if it should display pivot cursor while move.
*/ */
void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true ); void request_start_moving_camera( float aMovingSpeed = 2.0f, bool aRenderPivot = true );
/** /**
* @brief move_pivot_based_on_cur_mouse_position - * This function hits a ray to the board and start a movement.
* This function hits a ray to the board and start a moviment
*/ */
void move_pivot_based_on_cur_mouse_position(); void move_pivot_based_on_cur_mouse_position();
/** /**
* @brief render_pivot - render the pivot cursor * Render the pivot cursor.
* @param t: time between 0.0 and 1.0 *
* @param aScale: scale to apply on the cursor * @param t time between 0.0 and 1.0.
* @param aScale scale to apply on the cursor.
*/ */
void render_pivot( float t, float aScale ); void render_pivot( float t, float aScale );
/** /**
* @brief initializeOpenGL * @return true if OpenGL initialization succeeded.
* @return if OpenGL initialization succeed
*/ */
bool initializeOpenGL(); bool initializeOpenGL();
/** /**
* @brief releaseOpenGL - free created targets and openGL context * Free created targets and openGL context.
*/ */
void releaseOpenGL(); void releaseOpenGL();
RAY getRayAtCurrrentMousePosition(); RAY getRayAtCurrrentMousePosition();
private: private:
TOOL_DISPATCHER* m_eventDispatcher; TOOL_DISPATCHER* m_eventDispatcher;
wxStatusBar* m_parentStatusBar; // Parent statusbar to report progress wxStatusBar* m_parentStatusBar; // Parent statusbar to report progress
WX_INFOBAR* m_parentInfoBar; WX_INFOBAR* m_parentInfoBar;
@ -246,7 +257,7 @@ private:
bool m_is_opengl_initialized; bool m_is_opengl_initialized;
bool m_is_opengl_version_supported; bool m_is_opengl_version_supported;
wxTimer m_editing_timeout_timer; // Expires after some time signalling that wxTimer m_editing_timeout_timer; // Expires after some time signaling that
// the mouse / keyboard movements are over // the mouse / keyboard movements are over
wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event wxTimer m_redraw_trigger_timer; // Used to schedule a redraw event
std::atomic_flag m_is_currently_painting; // Avoid drawing twice at the same time std::atomic_flag m_is_currently_painting; // Avoid drawing twice at the same time

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -35,26 +35,26 @@
static void pivot_render_triangles( float t ) static void pivot_render_triangles( float t )
{ {
wxASSERT( t >= 0.0f ); wxASSERT( t >= 0.0f );
SFVEC3F vertexPointer[12]; SFVEC3F vertexPointer[12];
const float u = 1.0f / 6.0f; const float u = 1.0f / 6.0f;
vertexPointer[0] = SFVEC3F( (-3.0f + t) * u, -2.0f * u, 0.0f ); vertexPointer[0] = SFVEC3F( ( -3.0f + t ) * u, -2.0f * u, 0.0f );
vertexPointer[1] = SFVEC3F( (-3.0f + t) * u, 2.0f * u, 0.0f ); vertexPointer[1] = SFVEC3F( ( -3.0f + t ) * u, 2.0f * u, 0.0f );
vertexPointer[2] = SFVEC3F( (-1.0f + t) * u, 0.0f * u, 0.0f ); vertexPointer[2] = SFVEC3F( ( -1.0f + t ) * u, 0.0f * u, 0.0f );
vertexPointer[3] = SFVEC3F( -2.0f * u, (-3.0f + t) * u, 0.0f ); vertexPointer[3] = SFVEC3F( -2.0f * u, ( -3.0f + t ) * u, 0.0f );
vertexPointer[4] = SFVEC3F( 2.0f * u, (-3.0f + t) * u, 0.0f ); vertexPointer[4] = SFVEC3F( 2.0f * u, ( -3.0f + t ) * u, 0.0f );
vertexPointer[5] = SFVEC3F( 0.0f * u, (-1.0f + t) * u, 0.0f ); vertexPointer[5] = SFVEC3F( 0.0f * u, ( -1.0f + t ) * u, 0.0f );
vertexPointer[6] = SFVEC3F( (3.0f - t) * u, -2.0f * u, 0.0f ); vertexPointer[6] = SFVEC3F( ( 3.0f - t ) * u, -2.0f * u, 0.0f );
vertexPointer[7] = SFVEC3F( (3.0f - t) * u, 2.0f * u, 0.0f ); vertexPointer[7] = SFVEC3F( ( 3.0f - t ) * u, 2.0f * u, 0.0f );
vertexPointer[8] = SFVEC3F( (1.0f - t) * u, 0.0f * u, 0.0f ); vertexPointer[8] = SFVEC3F( ( 1.0f - t ) * u, 0.0f * u, 0.0f );
vertexPointer[9] = SFVEC3F( 2.0f * u, (3.0f - t) * u, 0.0f ); vertexPointer[9] = SFVEC3F( 2.0f * u, ( 3.0f - t ) * u, 0.0f );
vertexPointer[10] = SFVEC3F( -2.0f * u, (3.0f - t) * u, 0.0f ); vertexPointer[10] = SFVEC3F( -2.0f * u, ( 3.0f - t ) * u, 0.0f );
vertexPointer[11] = SFVEC3F( 0.0f * u, (1.0f - t) * u, 0.0f ); vertexPointer[11] = SFVEC3F( 0.0f * u, ( 1.0f - t ) * u, 0.0f );
glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_COLOR_ARRAY ); glDisableClientState( GL_COLOR_ARRAY );
@ -88,7 +88,6 @@ void EDA_3D_CANVAS::render_pivot( float t , float aScale )
glDisable( GL_CULL_FACE ); glDisable( GL_CULL_FACE );
// Set projection and modelview matrixes // Set projection and modelview matrixes
// /////////////////////////////////////////////////////////////////////////
glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION );
glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) ); glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
@ -101,7 +100,7 @@ void EDA_3D_CANVAS::render_pivot( float t , float aScale )
// Translate to the look at position // Translate to the look at position
glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z ); glTranslatef( lookAtPos.x, lookAtPos.y, lookAtPos.z );
glScalef( aScale, aScale, aScale ); glScalef( aScale, aScale, aScale );
pivot_render_triangles( t * 0.5f ); pivot_render_triangles( t * 0.5f );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,9 +33,9 @@
#include <plugins/3dapi/xv3d_types.h> #include <plugins/3dapi/xv3d_types.h>
#include "3d_fastmath.h" #include "3d_fastmath.h"
// https://en.wikipedia.org/wiki/Spherical_coordinate_system
/** /**
* @brief SphericalToCartesian * https://en.wikipedia.org/wiki/Spherical_coordinate_system
*
* @param aInclination θ [0, π] * @param aInclination θ [0, π]
* @param aAzimuth φ [0, 2π] * @param aAzimuth φ [0, 2π]
* @return Cartesian cordinates * @return Cartesian cordinates
@ -43,34 +43,33 @@
inline SFVEC3F SphericalToCartesian( float aInclination, float aAzimuth ) inline SFVEC3F SphericalToCartesian( float aInclination, float aAzimuth )
{ {
float sinInc = glm::sin( aInclination ); float sinInc = glm::sin( aInclination );
return SFVEC3F( sinInc * glm::cos( aAzimuth ),
sinInc * glm::sin( aAzimuth ), return SFVEC3F( sinInc * glm::cos( aAzimuth ), sinInc * glm::sin( aAzimuth ),
glm::cos( aInclination ) ); glm::cos( aInclination ) );
} }
// https://pathtracing.wordpress.com/2011/03/03/cosine-weighted-hemisphere/ /**
// !TODO: this is not correct because it is not a gaussian random * @todo This is not correct because it is not a gaussian random.
inline SFVEC3F UniformRandomHemisphereDirection( ) */
inline SFVEC3F UniformRandomHemisphereDirection()
{ {
// It was experienced that this function is slow! do not use it :/ // It was experienced that this function is slow! do not use it :/
// SFVEC3F b( (rand()/(float)RAND_MAX) - 0.5f, // SFVEC3F b( (rand()/(float)RAND_MAX) - 0.5f,
// (rand()/(float)RAND_MAX) - 0.5f, // (rand()/(float)RAND_MAX) - 0.5f,
// (rand()/(float)RAND_MAX) - 0.5f ); // (rand()/(float)RAND_MAX) - 0.5f );
SFVEC3F b( Fast_RandFloat() * 0.5f, SFVEC3F b( Fast_RandFloat() * 0.5f, Fast_RandFloat() * 0.5f, Fast_RandFloat() * 0.5f );
Fast_RandFloat() * 0.5f,
Fast_RandFloat() * 0.5f );
return b; return b;
} }
// https://pathtracing.wordpress.com/2011/03/03/cosine-weighted-hemisphere/ // https://pathtracing.wordpress.com/2011/03/03/cosine-weighted-hemisphere/
inline SFVEC3F CosWeightedRandomHemisphereDirection( const SFVEC3F &n ) inline SFVEC3F CosWeightedRandomHemisphereDirection( const SFVEC3F& n )
{ {
const float Xi1 = (float)rand() / (float)RAND_MAX; const float Xi1 = (float) rand() / (float) RAND_MAX;
const float Xi2 = (float)rand() / (float)RAND_MAX; const float Xi2 = (float) rand() / (float) RAND_MAX;
const float theta = acos( sqrt( 1.0f - Xi1 ) ); const float theta = acos( sqrt( 1.0f - Xi1 ) );
const float phi = 2.0f * glm::pi<float>() * Xi2; const float phi = 2.0f * glm::pi<float>() * Xi2;
@ -99,21 +98,19 @@ inline SFVEC3F CosWeightedRandomHemisphereDirection( const SFVEC3F &n )
/** /**
* @brief Refract
* Based on: * Based on:
* https://github.com/mmp/pbrt-v3/blob/master/src/core/reflection.h * https://github.com/mmp/pbrt-v3/blob/master/src/core/reflection.h
* See also: * See also:
* http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_3_Refractions_and_Beers_Law.shtml * http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_3_Refractions_and_Beers_Law.shtml
* @param aInVector incoming vector *
* @param aNormal normal in the intersection point * @param aInVector incoming vector.
* @param aRin_over_Rout incoming refraction index / out refraction index * @param aNormal normal in the intersection point.
* @param aOutVector the refracted vector * @param aRin_over_Rout incoming refraction index / out refraction index.
* @param aOutVector the refracted vector.
* @return true * @return true
*/ */
inline bool Refract( const SFVEC3F &aInVector, inline bool Refract( const SFVEC3F &aInVector, const SFVEC3F &aNormal, float aRin_over_Rout,
const SFVEC3F &aNormal, SFVEC3F& aOutVector )
float aRin_over_Rout,
SFVEC3F &aOutVector )
{ {
float cosThetaI = -glm::dot( aNormal, aInVector ); float cosThetaI = -glm::dot( aNormal, aInVector );
float sin2ThetaI = glm::max( 0.0f, 1.0f - cosThetaI * cosThetaI ); float sin2ThetaI = glm::max( 0.0f, 1.0f - cosThetaI * cosThetaI );
@ -133,11 +130,7 @@ inline bool Refract( const SFVEC3F &aInVector,
} }
inline float mapf( float x, inline float mapf( float x, float in_min, float in_max, float out_min, float out_max )
float in_min,
float in_max,
float out_min,
float out_max)
{ {
x = glm::clamp( x, in_min, in_max ); x = glm::clamp( x, in_min, in_max );
@ -154,17 +147,15 @@ inline float RGBtoGray( const SFVEC3F &aColor )
inline SFVEC3F MaterialDiffuseToColorCAD( const SFVEC3F &aDiffuseColor ) inline SFVEC3F MaterialDiffuseToColorCAD( const SFVEC3F &aDiffuseColor )
{ {
// convert to a discret scale of grays // convert to a discret scale of grays
const float luminance = glm::min( (((float)((unsigned int) ( 4.0f * const float luminance = glm::min(
RGBtoGray( aDiffuseColor ) ) ) + 0.5f) / ( ( (float) ( (unsigned int) ( 4.0f * RGBtoGray( aDiffuseColor ) ) ) + 0.5f ) / 4.0f )
4.0f) * 1.0f, * 1.0f,
1.0f ); 1.0f );
const float maxValue = glm::max( glm::max( glm::max( aDiffuseColor.r, const float maxValue = glm::max( glm::max( glm::max( aDiffuseColor.r, aDiffuseColor.g ),
aDiffuseColor.g), aDiffuseColor.b ), FLT_EPSILON );
aDiffuseColor.b ),
FLT_EPSILON );
return (aDiffuseColor / SFVEC3F(maxValue) ) * 0.125f + luminance* 0.875f; return ( aDiffuseColor / SFVEC3F( maxValue ) ) * 0.125f + luminance * 0.875f;
} }
@ -179,7 +170,7 @@ inline float QuadricEasingInOut( float t )
{ {
t = t - 1.0f; t = t - 1.0f;
return -2.0f * (t * t) + 1.0f; return -2.0f * ( t * t ) + 1.0f;
} }
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2017 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -40,17 +40,19 @@
#include <gl_context_mgr.h> #include <gl_context_mgr.h>
/** /**
* Scale convertion from 3d model units to pcb units * Scale conversion from 3d model units to pcb units
*/ */
#define UNITS3D_TO_UNITSPCB (IU_PER_MM) #define UNITS3D_TO_UNITSPCB (IU_PER_MM)
/** /**
* Trace mask used to enable or disable the trace output of this class. * Trace mask used to enable or disable the trace output of this class.
* The debug output can be turned on by setting the WXTRACE environment variable to * The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for * "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for
* more information. * more information.
*
* @ingroup trace_env_vars
*/ */
const wxChar * C3D_MODEL_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_MODEL_VIEWER" ); const wxChar* C3D_MODEL_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_MODEL_VIEWER" );
BEGIN_EVENT_TABLE( C3D_MODEL_VIEWER, wxGLCanvas ) BEGIN_EVENT_TABLE( C3D_MODEL_VIEWER, wxGLCanvas )
@ -80,27 +82,21 @@ END_EVENT_TABLE()
#define RANGE_SCALE_3D 8.0f #define RANGE_SCALE_3D 8.0f
C3D_MODEL_VIEWER::C3D_MODEL_VIEWER(wxWindow *aParent, C3D_MODEL_VIEWER::C3D_MODEL_VIEWER( wxWindow* aParent, const int* aAttribList,
const int *aAttribList , S3D_CACHE *aCacheManager) : S3D_CACHE* aCacheManager ) :
HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
HIDPI_GL_CANVAS( aParent, wxFULL_REPAINT_ON_RESIZE ),
wxID_ANY, m_trackBallCamera( RANGE_SCALE_3D * 2.0f ), m_cacheManager( aCacheManager )
aAttribList,
wxDefaultPosition,
wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE ),
m_trackBallCamera( RANGE_SCALE_3D * 2.0f ),
m_cacheManager(aCacheManager)
{ {
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::C3D_MODEL_VIEWER" ) ); wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::C3D_MODEL_VIEWER" ) );
m_ogl_initialized = false; m_ogl_initialized = false;
m_reload_is_needed = false; m_reload_is_needed = false;
m_ogl_3dmodel = NULL; m_ogl_3dmodel = nullptr;
m_3d_model = NULL; m_3d_model = nullptr;
m_BiuTo3Dunits = 1.0; m_BiuTo3Dunits = 1.0;
m_glRC = NULL; m_glRC = nullptr;
} }
@ -113,7 +109,7 @@ C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER()
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this ); GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
delete m_ogl_3dmodel; delete m_ogl_3dmodel;
m_ogl_3dmodel = NULL; m_ogl_3dmodel = nullptr;
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC ); GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC ); GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC );
@ -126,19 +122,19 @@ void C3D_MODEL_VIEWER::Set3DModel( const S3DMODEL &a3DModel )
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) ); wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) );
// Validate a3DModel pointers // Validate a3DModel pointers
wxASSERT( a3DModel.m_Materials != NULL ); wxASSERT( a3DModel.m_Materials != nullptr );
wxASSERT( a3DModel.m_Meshes != NULL ); wxASSERT( a3DModel.m_Meshes != nullptr );
wxASSERT( a3DModel.m_MaterialsSize > 0 ); wxASSERT( a3DModel.m_MaterialsSize > 0 );
wxASSERT( a3DModel.m_MeshesSize > 0 ); wxASSERT( a3DModel.m_MeshesSize > 0 );
// Delete the old model // Delete the old model
delete m_ogl_3dmodel; delete m_ogl_3dmodel;
m_ogl_3dmodel = NULL; m_ogl_3dmodel = nullptr;
m_3d_model = NULL; m_3d_model = nullptr;
if( (a3DModel.m_Materials != NULL) && (a3DModel.m_Meshes != NULL) && if( ( a3DModel.m_Materials != nullptr ) && ( a3DModel.m_Meshes != nullptr )
(a3DModel.m_MaterialsSize > 0) && (a3DModel.m_MeshesSize > 0) ) && ( a3DModel.m_MaterialsSize > 0 ) && ( a3DModel.m_MeshesSize > 0 ) )
{ {
m_3d_model = &a3DModel; m_3d_model = &a3DModel;
m_reload_is_needed = true; m_reload_is_needed = true;
@ -170,9 +166,9 @@ void C3D_MODEL_VIEWER::Clear3DModel()
m_reload_is_needed = false; m_reload_is_needed = false;
delete m_ogl_3dmodel; delete m_ogl_3dmodel;
m_ogl_3dmodel = NULL; m_ogl_3dmodel = nullptr;
m_3d_model = NULL; m_3d_model = nullptr;
Refresh(); Refresh();
} }
@ -194,7 +190,6 @@ void C3D_MODEL_VIEWER::ogl_initialize()
// Setup light // Setup light
// https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml // https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
// /////////////////////////////////////////////////////////////////////////
const GLfloat ambient[] = { 0.01f, 0.01f, 0.01f, 1.0f }; const GLfloat ambient[] = { 0.01f, 0.01f, 0.01f, 1.0f };
const GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; const GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; const GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
@ -238,7 +233,7 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
// "Makes the OpenGL state that is represented by the OpenGL rendering // "Makes the OpenGL state that is represented by the OpenGL rendering
// context context current, i.e. it will be used by all subsequent OpenGL calls. // context context current, i.e. it will be used by all subsequent OpenGL calls.
// This function may only be called when the window is shown on screen" // This function may only be called when the window is shown on screen"
if( m_glRC == NULL ) if( m_glRC == nullptr )
m_glRC = GL_CONTEXT_MANAGER::Get().CreateCtx( this ); m_glRC = GL_CONTEXT_MANAGER::Get().CreateCtx( this );
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this ); GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
@ -266,9 +261,9 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
// It convert a model as it was a board, so get the max size dimension of the board // It convert a model as it was a board, so get the max size dimension of the board
// and compute the conversion scale // and compute the conversion scale
m_BiuTo3Dunits = (double)RANGE_SCALE_3D / m_BiuTo3Dunits =
( (double)m_ogl_3dmodel->GetBBox().GetMaxDimension() * (double) RANGE_SCALE_3D
UNITS3D_TO_UNITSPCB ); / ( (double) m_ogl_3dmodel->GetBBox().GetMaxDimension() * UNITS3D_TO_UNITSPCB );
} }
glViewport( 0, 0, clientSize.x, clientSize.y ); glViewport( 0, 0, clientSize.x, clientSize.y );
@ -276,21 +271,16 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
m_trackBallCamera.SetCurWindowSize( clientSize ); m_trackBallCamera.SetCurWindowSize( clientSize );
// clear color and depth buffers // clear color and depth buffers
// /////////////////////////////////////////////////////////////////////////
glEnable( GL_DEPTH_TEST ); glEnable( GL_DEPTH_TEST );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
glClearDepth( 1.0f ); glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// Set projection and modelview matrixes // Set projection and modelview matrices
// /////////////////////////////////////////////////////////////////////////
glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION );
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) ); glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) );
glMatrixMode( GL_MODELVIEW ); glMatrixMode( GL_MODELVIEW );
glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) ); glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) );
glEnable( GL_LIGHTING ); glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT0 );
@ -301,8 +291,7 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
double modelunit_to_3d_units_factor = m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB; double modelunit_to_3d_units_factor = m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;
glScaled( modelunit_to_3d_units_factor, glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor,
modelunit_to_3d_units_factor,
modelunit_to_3d_units_factor ); modelunit_to_3d_units_factor );
// Center model in the render viewport // Center model in the render viewport
@ -320,7 +309,6 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
glPopMatrix(); glPopMatrix();
} }
// YxY squared view port // YxY squared view port
glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 ); glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 );
glClear( GL_DEPTH_BUFFER_BIT ); glClear( GL_DEPTH_BUFFER_BIT );
@ -342,18 +330,15 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
ogl_set_arrow_material(); ogl_set_arrow_material();
glColor3f( 0.9f, 0.0f, 0.0f ); glColor3f( 0.9f, 0.0f, 0.0f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
0.275f ); 0.275f );
glColor3f( 0.0f, 0.9f, 0.0f ); glColor3f( 0.0f, 0.9f, 0.0f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
0.275f ); 0.275f );
glColor3f( 0.0f, 0.0f, 0.9f ); glColor3f( 0.0f, 0.0f, 0.9f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
0.275f ); 0.275f );
// "Swaps the double-buffer of this window, making the back-buffer the // "Swaps the double-buffer of this window, making the back-buffer the

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,9 +24,10 @@
/** /**
* @file c3d_model_viewer.h * @file c3d_model_viewer.h
* @brief Implements a model viewer canvas. The propose of model viewer is to * @brief Implements a model viewer canvas.
* render 3d models that come in the original data from the files without any *
* transformations. * The purpose of model viewer is to render 3d models that come in the original data from
* the files without any transformations.
*/ */
#ifndef _C3D_MODEL_VIEWER_H_ #ifndef _C3D_MODEL_VIEWER_H_
@ -39,41 +40,38 @@ class S3D_CACHE;
class C_OGL_3DMODEL; class C_OGL_3DMODEL;
/** /**
* Class C3D_MODEL_VIEWER * Implement a canvas based on a wxGLCanvas.
* Implement a canvas based on a wxGLCanvas
*/ */
class C3D_MODEL_VIEWER : public HIDPI_GL_CANVAS class C3D_MODEL_VIEWER : public HIDPI_GL_CANVAS
{ {
public: public:
/** /**
* Creates a new 3D Canvas with a attribute list * Create a new 3D Canvas with a attribute list.
* @param aParent = the parent creator of this canvas *
* @param aAttribList = a list of openGL options created by * @param aParent the parent creator of this canvas.
* COGL_ATT_LIST::GetAttributesList * @param aAttribList a list of openGL options created by #COGL_ATT_LIST::GetAttributesList.
*/ */
C3D_MODEL_VIEWER( wxWindow *aParent, C3D_MODEL_VIEWER( wxWindow* aParent, const int* aAttribList = 0,
const int *aAttribList = 0, S3D_CACHE* aCacheManager = nullptr );
S3D_CACHE *aCacheManager = NULL );
~C3D_MODEL_VIEWER(); ~C3D_MODEL_VIEWER();
/** /**
* @brief Set3DModel - Set this model to be displayed * Set this model to be displayed.
* @param a3DModel - 3d model data *
* @param a3DModel 3D model data.
*/ */
void Set3DModel( const S3DMODEL &a3DModel ); void Set3DModel( const S3DMODEL& a3DModel );
/** /**
* @brief Set3DModel - Set this model to be displayed * Set this model to be displayed.
* @param aModelPathName - 3d model path name *
* @param aModelPathName 3D model path name.
*/ */
void Set3DModel( wxString const& aModelPathName ); void Set3DModel( wxString const& aModelPathName );
/** /**
* @brief Clear3DModel - Unloads the displayed 3d model * Unload the displayed 3D model.
*/ */
void Clear3DModel(); void Clear3DModel();
@ -81,45 +79,41 @@ private:
void ogl_initialize(); void ogl_initialize();
void ogl_set_arrow_material(); void ogl_set_arrow_material();
private: void OnPaint( wxPaintEvent& event );
void OnPaint( wxPaintEvent &event ); void OnEraseBackground( wxEraseEvent& event );
void OnEraseBackground( wxEraseEvent &event ); void OnMouseWheel( wxMouseEvent& event );
void OnMouseWheel( wxMouseEvent &event );
#ifdef USE_OSX_MAGNIFY_EVENT #ifdef USE_OSX_MAGNIFY_EVENT
void OnMagnify( wxMouseEvent& event ); void OnMagnify( wxMouseEvent& event );
#endif #endif
void OnMouseMove( wxMouseEvent &event ); void OnMouseMove( wxMouseEvent& event );
void OnLeftDown( wxMouseEvent &event ); void OnLeftDown( wxMouseEvent& event );
void OnLeftUp( wxMouseEvent &event ); void OnLeftUp( wxMouseEvent& event );
void OnMiddleUp( wxMouseEvent &event ); void OnMiddleUp( wxMouseEvent& event );
void OnMiddleDown( wxMouseEvent &event ); void OnMiddleDown( wxMouseEvent& event );
void OnRightClick( wxMouseEvent &event ); void OnRightClick( wxMouseEvent& event );
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
private:
/// openGL context /// openGL context
wxGLContext *m_glRC; wxGLContext* m_glRC;
/// Camera used in this canvas /// Camera used in this canvas
CTRACK_BALL m_trackBallCamera; CTRACK_BALL m_trackBallCamera;
/// Original 3d model data /// Original 3d model data
const S3DMODEL *m_3d_model; const S3DMODEL* m_3d_model;
/// Class holder for 3d model to display on openGL /// Class holder for 3d model to display on openGL
C_OGL_3DMODEL *m_ogl_3dmodel; C_OGL_3DMODEL* m_ogl_3dmodel;
/// Flag that we have a new model and it need to be reloaded when the paint is called /// Flag that we have a new model and it need to be reloaded when the paint is called
bool m_reload_is_needed; bool m_reload_is_needed;
@ -141,7 +135,7 @@ private:
* "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for * "KI_TRACE_EDA_3D_MODEL_VIEWER". See the wxWidgets documentation on wxLogTrace for
* more information. * more information.
*/ */
static const wxChar *m_logTrace; static const wxChar* m_logTrace;
}; };
#endif // _C3D_MODEL_VIEWER_H_ #endif // _C3D_MODEL_VIEWER_H_

View File

@ -39,10 +39,6 @@ public:
return static_cast<EDA_3D_VIEWER*>( DIALOG_SHIM::GetParent() ); return static_cast<EDA_3D_VIEWER*>( DIALOG_SHIM::GetParent() );
} }
private:
BOARD_ADAPTER& m_settings;
EDA_3D_CANVAS* m_canvas;
void initDialog(); void initDialog();
void OnCheckEnableAnimation( wxCommandEvent& WXUNUSED( event ) ) override; void OnCheckEnableAnimation( wxCommandEvent& WXUNUSED( event ) ) override;
@ -55,6 +51,10 @@ private:
bool TransferDataToWindow() override; bool TransferDataToWindow() override;
void TransferColorDataToWindow(); void TransferColorDataToWindow();
private:
BOARD_ADAPTER& m_settings;
EDA_3D_CANVAS* m_canvas;
}; };
@ -103,12 +103,14 @@ void DIALOG_3D_VIEW_OPTIONS::initDialog()
m_bitmapClipSilkOnViaAnnulus->SetBitmap( KiBitmap( use_3D_copper_thickness_xpm ) ); m_bitmapClipSilkOnViaAnnulus->SetBitmap( KiBitmap( use_3D_copper_thickness_xpm ) );
} }
void DIALOG_3D_VIEW_OPTIONS::OnCheckEnableAnimation( wxCommandEvent& event ) void DIALOG_3D_VIEW_OPTIONS::OnCheckEnableAnimation( wxCommandEvent& event )
{ {
m_staticAnimationSpeed->Enable( m_checkBoxEnableAnimation->GetValue() ); m_staticAnimationSpeed->Enable( m_checkBoxEnableAnimation->GetValue() );
m_sliderAnimationSpeed->Enable( m_checkBoxEnableAnimation->GetValue() ); m_sliderAnimationSpeed->Enable( m_checkBoxEnableAnimation->GetValue() );
} }
void DIALOG_3D_VIEW_OPTIONS::OnLightsResetToDefaults( wxCommandEvent& event ) void DIALOG_3D_VIEW_OPTIONS::OnLightsResetToDefaults( wxCommandEvent& event )
{ {
m_settings.m_raytrace_lightColorCamera = SFVEC3F( 0.2f ); m_settings.m_raytrace_lightColorCamera = SFVEC3F( 0.2f );
@ -129,7 +131,8 @@ void DIALOG_3D_VIEW_OPTIONS::OnLightsResetToDefaults( wxCommandEvent& event )
{ {
m_settings.m_raytrace_lightColor[i] = SFVEC3F( 0.168f ); m_settings.m_raytrace_lightColor[i] = SFVEC3F( 0.168f );
m_settings.m_raytrace_lightSphericalCoords[i].x = ( (float)default_elevation[i] + 90.0f ) / 180.0f; m_settings.m_raytrace_lightSphericalCoords[i].x =
( (float)default_elevation[i] + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[i].y = (float)default_azimuth[i] / 180.0f; m_settings.m_raytrace_lightSphericalCoords[i].y = (float)default_azimuth[i] / 180.0f;
} }
@ -137,13 +140,12 @@ void DIALOG_3D_VIEW_OPTIONS::OnLightsResetToDefaults( wxCommandEvent& event )
TransferColorDataToWindow(); TransferColorDataToWindow();
} }
void DIALOG_3D_VIEW_OPTIONS::TransferColorDataToWindow() void DIALOG_3D_VIEW_OPTIONS::TransferColorDataToWindow()
{ {
auto Transfer_color = [] ( const SFVEC3F& aSource, wxColourPickerCtrl *aTarget ) auto Transfer_color = [] ( const SFVEC3F& aSource, wxColourPickerCtrl *aTarget )
{ {
aTarget->SetColour( wxColour( aSource.r * 255, aTarget->SetColour( wxColour( aSource.r * 255, aSource.g * 255, aSource.b * 255, 255 ) );
aSource.g * 255,
aSource.b * 255, 255 ) );
}; };
Transfer_color( m_settings.m_raytrace_lightColorCamera, m_colourPickerCameraLight ); Transfer_color( m_settings.m_raytrace_lightColorCamera, m_colourPickerCameraLight );
@ -162,25 +164,42 @@ void DIALOG_3D_VIEW_OPTIONS::TransferColorDataToWindow()
Transfer_color( m_settings.m_opengl_selectionColor, m_colourPickerSelection ); Transfer_color( m_settings.m_opengl_selectionColor, m_colourPickerSelection );
m_spinCtrlLightElevation1->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[0].x * 180.0f - 90.0f ) ); m_spinCtrlLightElevation1->SetValue(
m_spinCtrlLightElevation2->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[1].x * 180.0f - 90.0f ) ); (int)( m_settings.m_raytrace_lightSphericalCoords[0].x * 180.0f - 90.0f ) );
m_spinCtrlLightElevation3->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[2].x * 180.0f - 90.0f ) ); m_spinCtrlLightElevation2->SetValue(
m_spinCtrlLightElevation4->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[3].x * 180.0f - 90.0f ) ); (int)( m_settings.m_raytrace_lightSphericalCoords[1].x * 180.0f - 90.0f ) );
m_spinCtrlLightElevation5->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[4].x * 180.0f - 90.0f ) ); m_spinCtrlLightElevation3->SetValue(
m_spinCtrlLightElevation6->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[5].x * 180.0f - 90.0f ) ); (int)( m_settings.m_raytrace_lightSphericalCoords[2].x * 180.0f - 90.0f ) );
m_spinCtrlLightElevation7->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[6].x * 180.0f - 90.0f ) ); m_spinCtrlLightElevation4->SetValue(
m_spinCtrlLightElevation8->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[7].x * 180.0f - 90.0f ) ); (int)( m_settings.m_raytrace_lightSphericalCoords[3].x * 180.0f - 90.0f ) );
m_spinCtrlLightElevation5->SetValue(
(int)( m_settings.m_raytrace_lightSphericalCoords[4].x * 180.0f - 90.0f ) );
m_spinCtrlLightElevation6->SetValue(
(int)( m_settings.m_raytrace_lightSphericalCoords[5].x * 180.0f - 90.0f ) );
m_spinCtrlLightElevation7->SetValue(
(int)( m_settings.m_raytrace_lightSphericalCoords[6].x * 180.0f - 90.0f ) );
m_spinCtrlLightElevation8->SetValue(
(int)( m_settings.m_raytrace_lightSphericalCoords[7].x * 180.0f - 90.0f ) );
m_spinCtrlLightAzimuth1->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[0].y * 180.0f ) ); m_spinCtrlLightAzimuth1->SetValue(
m_spinCtrlLightAzimuth2->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[1].y * 180.0f ) ); (int)( m_settings.m_raytrace_lightSphericalCoords[0].y * 180.0f ) );
m_spinCtrlLightAzimuth3->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[2].y * 180.0f ) ); m_spinCtrlLightAzimuth2->SetValue(
m_spinCtrlLightAzimuth4->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[3].y * 180.0f ) ); (int)( m_settings.m_raytrace_lightSphericalCoords[1].y * 180.0f ) );
m_spinCtrlLightAzimuth5->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[4].y * 180.0f ) ); m_spinCtrlLightAzimuth3->SetValue(
m_spinCtrlLightAzimuth6->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[5].y * 180.0f ) ); (int)( m_settings.m_raytrace_lightSphericalCoords[2].y * 180.0f ) );
m_spinCtrlLightAzimuth7->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[6].y * 180.0f ) ); m_spinCtrlLightAzimuth4->SetValue(
m_spinCtrlLightAzimuth8->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[7].y * 180.0f ) ); (int)( m_settings.m_raytrace_lightSphericalCoords[3].y * 180.0f ) );
m_spinCtrlLightAzimuth5->SetValue(
(int)( m_settings.m_raytrace_lightSphericalCoords[4].y * 180.0f ) );
m_spinCtrlLightAzimuth6->SetValue(
(int)( m_settings.m_raytrace_lightSphericalCoords[5].y * 180.0f ) );
m_spinCtrlLightAzimuth7->SetValue(
(int)( m_settings.m_raytrace_lightSphericalCoords[6].y * 180.0f ) );
m_spinCtrlLightAzimuth8->SetValue(
(int)( m_settings.m_raytrace_lightSphericalCoords[7].y * 180.0f ) );
} }
bool DIALOG_3D_VIEW_OPTIONS::TransferDataToWindow() bool DIALOG_3D_VIEW_OPTIONS::TransferDataToWindow()
{ {
// Check/uncheck checkboxes // Check/uncheck checkboxes
@ -200,36 +219,51 @@ bool DIALOG_3D_VIEW_OPTIONS::TransferDataToWindow()
m_checkBoxECO->SetValue( m_settings.GetFlag( FL_ECO ) ); m_checkBoxECO->SetValue( m_settings.GetFlag( FL_ECO ) );
m_checkBoxSubtractMaskFromSilk->SetValue( m_settings.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) ); m_checkBoxSubtractMaskFromSilk->SetValue( m_settings.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) );
m_checkBoxClipSilkOnViaAnnulus->SetValue( m_settings.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) ); m_checkBoxClipSilkOnViaAnnulus->SetValue( m_settings.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) );
m_checkBoxRenderPlatedPadsAsPlated->SetValue( m_settings.GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) ); m_checkBoxRenderPlatedPadsAsPlated->SetValue(
m_settings.GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) );
// OpenGL options // OpenGL options
m_checkBoxCuThickness->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) ); m_checkBoxCuThickness->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) );
m_checkBoxBoundingBoxes->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) ); m_checkBoxBoundingBoxes->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) );
m_checkBoxDisableAAMove->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE ) ); m_checkBoxDisableAAMove->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE ) );
m_checkBoxDisableMoveThickness->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE ) ); m_checkBoxDisableMoveThickness->SetValue(
m_checkBoxDisableMoveVias->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE ) ); m_settings.GetFlag( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE ) );
m_checkBoxDisableMoveHoles->SetValue( m_settings.GetFlag( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE ) ); m_checkBoxDisableMoveVias->SetValue(
m_settings.GetFlag( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE ) );
m_checkBoxDisableMoveHoles->SetValue(
m_settings.GetFlag( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE ) );
m_choiceAntiAliasing->SetSelection( static_cast<int>( m_settings.AntiAliasingGet() ) ); m_choiceAntiAliasing->SetSelection( static_cast<int>( m_settings.AntiAliasingGet() ) );
// Raytracing options // Raytracing options
m_checkBoxRaytracing_renderShadows->SetValue( m_settings.GetFlag( FL_RENDER_RAYTRACING_SHADOWS ) ); m_checkBoxRaytracing_renderShadows->SetValue(
m_settings.GetFlag( FL_RENDER_RAYTRACING_SHADOWS ) );
m_checkBoxRaytracing_addFloor->SetValue( m_settings.GetFlag( FL_RENDER_RAYTRACING_BACKFLOOR ) ); m_checkBoxRaytracing_addFloor->SetValue( m_settings.GetFlag( FL_RENDER_RAYTRACING_BACKFLOOR ) );
m_checkBoxRaytracing_showRefractions->SetValue( m_settings.GetFlag( FL_RENDER_RAYTRACING_REFRACTIONS ) ); m_checkBoxRaytracing_showRefractions->SetValue(
m_checkBoxRaytracing_showReflections->SetValue( m_settings.GetFlag( FL_RENDER_RAYTRACING_REFLECTIONS ) ); m_settings.GetFlag( FL_RENDER_RAYTRACING_REFRACTIONS ) );
m_checkBoxRaytracing_postProcessing->SetValue( m_settings.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) ); m_checkBoxRaytracing_showReflections->SetValue(
m_checkBoxRaytracing_antiAliasing->SetValue( m_settings.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) ); m_settings.GetFlag( FL_RENDER_RAYTRACING_REFLECTIONS ) );
m_checkBoxRaytracing_proceduralTextures->SetValue( m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) ); m_checkBoxRaytracing_postProcessing->SetValue(
m_settings.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) );
m_checkBoxRaytracing_antiAliasing->SetValue(
m_settings.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) );
m_checkBoxRaytracing_proceduralTextures->SetValue(
m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) );
m_spinCtrl_NrSamples_Shadows->SetValue( m_settings.m_raytrace_nrsamples_shadows ); m_spinCtrl_NrSamples_Shadows->SetValue( m_settings.m_raytrace_nrsamples_shadows );
m_spinCtrl_NrSamples_Reflections->SetValue( m_settings.m_raytrace_nrsamples_reflections ); m_spinCtrl_NrSamples_Reflections->SetValue( m_settings.m_raytrace_nrsamples_reflections );
m_spinCtrl_NrSamples_Refractions->SetValue( m_settings.m_raytrace_nrsamples_refractions ); m_spinCtrl_NrSamples_Refractions->SetValue( m_settings.m_raytrace_nrsamples_refractions );
m_spinCtrlDouble_SpreadFactor_Shadows->SetValue( m_settings.m_raytrace_spread_shadows * 100.0f ); m_spinCtrlDouble_SpreadFactor_Shadows->SetValue(
m_spinCtrlDouble_SpreadFactor_Reflections->SetValue( m_settings.m_raytrace_spread_reflections * 100.0f ); m_settings.m_raytrace_spread_shadows * 100.0f );
m_spinCtrlDouble_SpreadFactor_Refractions->SetValue( m_settings.m_raytrace_spread_refractions * 100.0f ); m_spinCtrlDouble_SpreadFactor_Reflections->SetValue(
m_settings.m_raytrace_spread_reflections * 100.0f );
m_spinCtrlDouble_SpreadFactor_Refractions->SetValue(
m_settings.m_raytrace_spread_refractions * 100.0f );
m_spinCtrlRecursiveLevel_Reflections->SetValue( m_settings.m_raytrace_recursivelevel_reflections ); m_spinCtrlRecursiveLevel_Reflections->SetValue(
m_spinCtrlRecursiveLevel_Refractions->SetValue( m_settings.m_raytrace_recursivelevel_refractions ); m_settings.m_raytrace_recursivelevel_reflections );
m_spinCtrlRecursiveLevel_Refractions->SetValue(
m_settings.m_raytrace_recursivelevel_refractions );
TransferColorDataToWindow(); TransferColorDataToWindow();
@ -256,7 +290,8 @@ bool DIALOG_3D_VIEW_OPTIONS::TransferDataFromWindow()
m_settings.SetFlag( FL_ZONE, m_checkBoxAreas->GetValue() ); m_settings.SetFlag( FL_ZONE, m_checkBoxAreas->GetValue() );
m_settings.SetFlag( FL_SUBTRACT_MASK_FROM_SILK, m_checkBoxSubtractMaskFromSilk->GetValue() ); m_settings.SetFlag( FL_SUBTRACT_MASK_FROM_SILK, m_checkBoxSubtractMaskFromSilk->GetValue() );
m_settings.SetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS, m_checkBoxClipSilkOnViaAnnulus->GetValue() ); m_settings.SetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS, m_checkBoxClipSilkOnViaAnnulus->GetValue() );
m_settings.SetFlag( FL_RENDER_PLATED_PADS_AS_PLATED, m_checkBoxRenderPlatedPadsAsPlated->GetValue() ); m_settings.SetFlag( FL_RENDER_PLATED_PADS_AS_PLATED,
m_checkBoxRenderPlatedPadsAsPlated->GetValue() );
// Set 3D shapes visibility // Set 3D shapes visibility
m_settings.SetFlag( FL_FP_ATTRIBUTES_NORMAL, m_checkBox3DshapesTH->GetValue() ); m_settings.SetFlag( FL_FP_ATTRIBUTES_NORMAL, m_checkBox3DshapesTH->GetValue() );
@ -275,38 +310,52 @@ bool DIALOG_3D_VIEW_OPTIONS::TransferDataFromWindow()
m_settings.SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, m_checkBoxCuThickness->GetValue() ); m_settings.SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, m_checkBoxCuThickness->GetValue() );
m_settings.SetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, m_checkBoxBoundingBoxes->GetValue() ); m_settings.SetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, m_checkBoxBoundingBoxes->GetValue() );
m_settings.SetFlag( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE, m_checkBoxDisableAAMove->GetValue() ); m_settings.SetFlag( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE, m_checkBoxDisableAAMove->GetValue() );
m_settings.SetFlag( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE, m_checkBoxDisableMoveThickness->GetValue() ); m_settings.SetFlag( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE,
m_settings.SetFlag( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE, m_checkBoxDisableMoveVias->GetValue() ); m_checkBoxDisableMoveThickness->GetValue() );
m_settings.SetFlag( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE, m_checkBoxDisableMoveHoles->GetValue() ); m_settings.SetFlag( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE,
m_settings.AntiAliasingSet( static_cast<ANTIALIASING_MODE>( m_choiceAntiAliasing->GetSelection() ) ); m_checkBoxDisableMoveVias->GetValue() );
m_settings.SetFlag( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE,
m_checkBoxDisableMoveHoles->GetValue() );
m_settings.AntiAliasingSet(
static_cast<ANTIALIASING_MODE>( m_choiceAntiAliasing->GetSelection() ) );
// Raytracing options // Raytracing options
m_settings.SetFlag( FL_RENDER_RAYTRACING_SHADOWS, m_checkBoxRaytracing_renderShadows->GetValue() ); m_settings.SetFlag( FL_RENDER_RAYTRACING_SHADOWS,
m_settings.SetFlag( FL_RENDER_RAYTRACING_BACKFLOOR, m_checkBoxRaytracing_addFloor->GetValue() ); m_checkBoxRaytracing_renderShadows->GetValue() );
m_settings.SetFlag( FL_RENDER_RAYTRACING_REFRACTIONS, m_checkBoxRaytracing_showRefractions->GetValue() ); m_settings.SetFlag( FL_RENDER_RAYTRACING_BACKFLOOR,
m_settings.SetFlag( FL_RENDER_RAYTRACING_REFLECTIONS, m_checkBoxRaytracing_showReflections->GetValue() ); m_checkBoxRaytracing_addFloor->GetValue() );
m_settings.SetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING, m_checkBoxRaytracing_postProcessing->GetValue() ); m_settings.SetFlag( FL_RENDER_RAYTRACING_REFRACTIONS,
m_settings.SetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING, m_checkBoxRaytracing_antiAliasing->GetValue() ); m_checkBoxRaytracing_showRefractions->GetValue() );
m_settings.SetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, m_checkBoxRaytracing_proceduralTextures->GetValue() ); m_settings.SetFlag( FL_RENDER_RAYTRACING_REFLECTIONS,
m_checkBoxRaytracing_showReflections->GetValue() );
m_settings.SetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING,
m_checkBoxRaytracing_postProcessing->GetValue() );
m_settings.SetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING,
m_checkBoxRaytracing_antiAliasing->GetValue() );
m_settings.SetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES,
m_checkBoxRaytracing_proceduralTextures->GetValue() );
m_settings.m_raytrace_nrsamples_shadows = m_spinCtrl_NrSamples_Shadows->GetValue(); m_settings.m_raytrace_nrsamples_shadows = m_spinCtrl_NrSamples_Shadows->GetValue();
m_settings.m_raytrace_nrsamples_reflections = m_spinCtrl_NrSamples_Reflections->GetValue(); m_settings.m_raytrace_nrsamples_reflections = m_spinCtrl_NrSamples_Reflections->GetValue();
m_settings.m_raytrace_nrsamples_refractions= m_spinCtrl_NrSamples_Refractions->GetValue(); m_settings.m_raytrace_nrsamples_refractions= m_spinCtrl_NrSamples_Refractions->GetValue();
m_settings.m_raytrace_spread_shadows = static_cast<float>( m_spinCtrlDouble_SpreadFactor_Shadows->GetValue() ) / 100.0f; m_settings.m_raytrace_spread_shadows =
m_settings.m_raytrace_spread_reflections = static_cast<float>( m_spinCtrlDouble_SpreadFactor_Reflections->GetValue() ) / 100.0f; static_cast<float>( m_spinCtrlDouble_SpreadFactor_Shadows->GetValue() ) / 100.0f;
m_settings.m_raytrace_spread_refractions = static_cast<float>( m_spinCtrlDouble_SpreadFactor_Refractions->GetValue() ) / 100.0f; m_settings.m_raytrace_spread_reflections =
static_cast<float>( m_spinCtrlDouble_SpreadFactor_Reflections->GetValue() ) / 100.0f;
m_settings.m_raytrace_spread_refractions =
static_cast<float>( m_spinCtrlDouble_SpreadFactor_Refractions->GetValue() ) / 100.0f;
m_settings.m_raytrace_recursivelevel_reflections = m_spinCtrlRecursiveLevel_Reflections->GetValue(); m_settings.m_raytrace_recursivelevel_reflections =
m_settings.m_raytrace_recursivelevel_refractions = m_spinCtrlRecursiveLevel_Refractions->GetValue(); m_spinCtrlRecursiveLevel_Reflections->GetValue();
m_settings.m_raytrace_recursivelevel_refractions =
m_spinCtrlRecursiveLevel_Refractions->GetValue();
auto Transfer_color = [] ( SFVEC3F& aTarget, wxColourPickerCtrl *aSource ) auto Transfer_color = [] ( SFVEC3F& aTarget, wxColourPickerCtrl *aSource )
{ {
const wxColour color = aSource->GetColour(); const wxColour color = aSource->GetColour();
aTarget = SFVEC3F( color.Red() / 255.0f, aTarget = SFVEC3F( color.Red() / 255.0f, color.Green() / 255.0f, color.Blue() / 255.0f );
color.Green() / 255.0f,
color.Blue() / 255.0f );
}; };
Transfer_color( m_settings.m_raytrace_lightColorCamera, m_colourPickerCameraLight ); Transfer_color( m_settings.m_raytrace_lightColorCamera, m_colourPickerCameraLight );
@ -324,14 +373,22 @@ bool DIALOG_3D_VIEW_OPTIONS::TransferDataFromWindow()
Transfer_color( m_settings.m_opengl_selectionColor, m_colourPickerSelection ); Transfer_color( m_settings.m_opengl_selectionColor, m_colourPickerSelection );
m_settings.m_raytrace_lightSphericalCoords[0].x = ( m_spinCtrlLightElevation1->GetValue() + 90.0f ) / 180.0f; m_settings.m_raytrace_lightSphericalCoords[0].x =
m_settings.m_raytrace_lightSphericalCoords[1].x = ( m_spinCtrlLightElevation2->GetValue() + 90.0f ) / 180.0f; ( m_spinCtrlLightElevation1->GetValue() + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[2].x = ( m_spinCtrlLightElevation3->GetValue() + 90.0f ) / 180.0f; m_settings.m_raytrace_lightSphericalCoords[1].x =
m_settings.m_raytrace_lightSphericalCoords[3].x = ( m_spinCtrlLightElevation4->GetValue() + 90.0f ) / 180.0f; ( m_spinCtrlLightElevation2->GetValue() + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[4].x = ( m_spinCtrlLightElevation5->GetValue() + 90.0f ) / 180.0f; m_settings.m_raytrace_lightSphericalCoords[2].x =
m_settings.m_raytrace_lightSphericalCoords[5].x = ( m_spinCtrlLightElevation6->GetValue() + 90.0f ) / 180.0f; ( m_spinCtrlLightElevation3->GetValue() + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[6].x = ( m_spinCtrlLightElevation7->GetValue() + 90.0f ) / 180.0f; m_settings.m_raytrace_lightSphericalCoords[3].x =
m_settings.m_raytrace_lightSphericalCoords[7].x = ( m_spinCtrlLightElevation8->GetValue() + 90.0f ) / 180.0f; ( m_spinCtrlLightElevation4->GetValue() + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[4].x =
( m_spinCtrlLightElevation5->GetValue() + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[5].x =
( m_spinCtrlLightElevation6->GetValue() + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[6].x =
( m_spinCtrlLightElevation7->GetValue() + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[7].x =
( m_spinCtrlLightElevation8->GetValue() + 90.0f ) / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[0].y = m_spinCtrlLightAzimuth1->GetValue() / 180.0f; m_settings.m_raytrace_lightSphericalCoords[0].y = m_spinCtrlLightAzimuth1->GetValue() / 180.0f;
m_settings.m_raytrace_lightSphericalCoords[1].y = m_spinCtrlLightAzimuth2->GetValue() / 180.0f; m_settings.m_raytrace_lightSphericalCoords[1].y = m_spinCtrlLightAzimuth2->GetValue() / 180.0f;
@ -344,11 +401,11 @@ bool DIALOG_3D_VIEW_OPTIONS::TransferDataFromWindow()
for( size_t i = 0; i < m_settings.m_raytrace_lightSphericalCoords.size(); ++i ) for( size_t i = 0; i < m_settings.m_raytrace_lightSphericalCoords.size(); ++i )
{ {
m_settings.m_raytrace_lightSphericalCoords[i].x = glm::clamp( m_settings.m_raytrace_lightSphericalCoords[i].x, m_settings.m_raytrace_lightSphericalCoords[i].x =
0.0f, 1.0f ); glm::clamp( m_settings.m_raytrace_lightSphericalCoords[i].x, 0.0f, 1.0f );
m_settings.m_raytrace_lightSphericalCoords[i].y = glm::clamp( m_settings.m_raytrace_lightSphericalCoords[i].y, m_settings.m_raytrace_lightSphericalCoords[i].y =
0.0f, 2.0f ); glm::clamp( m_settings.m_raytrace_lightSphericalCoords[i].y, 0.0f, 2.0f );
} }
// Camera Options // Camera Options

View File

@ -61,7 +61,7 @@
* *
* @ingroup trace_env_vars * @ingroup trace_env_vars
*/ */
const wxChar * EDA_3D_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_VIEWER" ); const wxChar* EDA_3D_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_VIEWER" );
BEGIN_EVENT_TABLE( EDA_3D_VIEWER, EDA_BASE_FRAME ) BEGIN_EVENT_TABLE( EDA_3D_VIEWER, EDA_BASE_FRAME )
@ -107,7 +107,8 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent, const wxSt
wxStatusBar *status_bar = CreateStatusBar( arrayDim( status_dims ) ); wxStatusBar *status_bar = CreateStatusBar( arrayDim( status_dims ) );
SetStatusWidths( arrayDim( status_dims ), status_dims ); SetStatusWidths( arrayDim( status_dims ), status_dims );
m_canvas = new EDA_3D_CANVAS( this, COGL_ATT_LIST::GetAttributesList( m_boardAdapter.AntiAliasingGet() ), m_canvas = new EDA_3D_CANVAS( this,
COGL_ATT_LIST::GetAttributesList( m_boardAdapter.AntiAliasingGet() ),
aParent->GetBoard(), m_boardAdapter, m_currentCamera, aParent->GetBoard(), m_boardAdapter, m_currentCamera,
Prj().Get3DCacheManager() ); Prj().Get3DCacheManager() );
@ -143,10 +144,8 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent, const wxSt
m_auimgr.SetManagedWindow( this ); m_auimgr.SetManagedWindow( this );
m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ) m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer( 6 ) );
.Top().Layer( 6 ) ); m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" )
.Center() );
// Call Update() to fix all pane default sizes. // Call Update() to fix all pane default sizes.
m_auimgr.Update(); m_auimgr.Update();
@ -260,6 +259,7 @@ void EDA_3D_VIEWER::NewDisplay( bool aForceImmediateRedraw )
m_canvas->Refresh(); m_canvas->Refresh();
} }
void EDA_3D_VIEWER::Redraw() void EDA_3D_VIEWER::Redraw()
{ {
// Only update in OpenGL for an interactive interaction // Only update in OpenGL for an interactive interaction
@ -267,6 +267,7 @@ void EDA_3D_VIEWER::Redraw()
m_canvas->Request_refresh( true ); m_canvas->Request_refresh( true );
} }
void EDA_3D_VIEWER::refreshRender() void EDA_3D_VIEWER::refreshRender()
{ {
if( m_boardAdapter.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY ) if( m_boardAdapter.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY )
@ -275,6 +276,7 @@ void EDA_3D_VIEWER::refreshRender()
NewDisplay( true ); NewDisplay( true );
} }
void EDA_3D_VIEWER::Exit3DFrame( wxCommandEvent &event ) void EDA_3D_VIEWER::Exit3DFrame( wxCommandEvent &event )
{ {
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::Exit3DFrame" ); wxLogTrace( m_logTrace, "EDA_3D_VIEWER::Exit3DFrame" );
@ -329,7 +331,8 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
return; return;
case ID_MENU3D_BGCOLOR_TOP: case ID_MENU3D_BGCOLOR_TOP:
if( Set3DColorFromUser( m_boardAdapter.m_BgColorTop, _( "Background Color, Top" ), nullptr ) ) if( Set3DColorFromUser( m_boardAdapter.m_BgColorTop, _( "Background Color, Top" ),
nullptr ) )
refreshRender(); refreshRender();
return; return;
@ -455,30 +458,37 @@ void EDA_3D_VIEWER::LoadSettings( APP_SETTINGS_BASE *aCfg )
}; };
set_color( colors->GetColor( LAYER_3D_BACKGROUND_BOTTOM ), m_boardAdapter.m_BgColorBot ); set_color( colors->GetColor( LAYER_3D_BACKGROUND_BOTTOM ), m_boardAdapter.m_BgColorBot );
set_color( colors->GetColor( LAYER_3D_BACKGROUND_TOP ), m_boardAdapter.m_BgColorTop ); set_color( colors->GetColor( LAYER_3D_BACKGROUND_TOP ), m_boardAdapter.m_BgColorTop );
set_color( colors->GetColor( LAYER_3D_BOARD ), m_boardAdapter.m_BoardBodyColor ); set_color( colors->GetColor( LAYER_3D_BOARD ), m_boardAdapter.m_BoardBodyColor );
set_color( colors->GetColor( LAYER_3D_COPPER ), m_boardAdapter.m_CopperColor ); set_color( colors->GetColor( LAYER_3D_COPPER ), m_boardAdapter.m_CopperColor );
set_color( colors->GetColor( LAYER_3D_SILKSCREEN_BOTTOM ), m_boardAdapter.m_SilkScreenColorBot ); set_color( colors->GetColor( LAYER_3D_SILKSCREEN_BOTTOM ),
set_color( colors->GetColor( LAYER_3D_SILKSCREEN_TOP ), m_boardAdapter.m_SilkScreenColorTop ); m_boardAdapter.m_SilkScreenColorBot );
set_color( colors->GetColor( LAYER_3D_SOLDERMASK ), m_boardAdapter.m_SolderMaskColorBot ); set_color( colors->GetColor( LAYER_3D_SILKSCREEN_TOP ), m_boardAdapter.m_SilkScreenColorTop );
set_color( colors->GetColor( LAYER_3D_SOLDERMASK ), m_boardAdapter.m_SolderMaskColorTop ); set_color( colors->GetColor( LAYER_3D_SOLDERMASK ), m_boardAdapter.m_SolderMaskColorBot );
set_color( colors->GetColor( LAYER_3D_SOLDERPASTE ), m_boardAdapter.m_SolderPasteColor ); set_color( colors->GetColor( LAYER_3D_SOLDERMASK ), m_boardAdapter.m_SolderMaskColorTop );
set_color( colors->GetColor( LAYER_3D_SOLDERPASTE ), m_boardAdapter.m_SolderPasteColor );
if( cfg ) if( cfg )
{ {
m_boardAdapter.m_raytrace_lightColorCamera = m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorCamera ); m_boardAdapter.m_raytrace_lightColorCamera =
m_boardAdapter.m_raytrace_lightColorTop = m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorTop ); m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorCamera );
m_boardAdapter.m_raytrace_lightColorBottom = m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorBottom ); m_boardAdapter.m_raytrace_lightColorTop =
m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorTop );
m_boardAdapter.m_raytrace_lightColorBottom =
m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorBottom );
m_boardAdapter.m_raytrace_lightColor.resize( cfg->m_Render.raytrace_lightColor.size() ); m_boardAdapter.m_raytrace_lightColor.resize( cfg->m_Render.raytrace_lightColor.size() );
m_boardAdapter.m_raytrace_lightSphericalCoords.resize( cfg->m_Render.raytrace_lightColor.size() ); m_boardAdapter.m_raytrace_lightSphericalCoords.resize(
cfg->m_Render.raytrace_lightColor.size() );
for( size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i ) for( size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i )
{ {
m_boardAdapter.m_raytrace_lightColor[i] = m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColor[i] ); m_boardAdapter.m_raytrace_lightColor[i] =
m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColor[i] );
SFVEC2F sphericalCoord = SFVEC2F( ( cfg->m_Render.raytrace_lightElevation[i] + 90.0f ) / 180.0f, SFVEC2F sphericalCoord =
cfg->m_Render.raytrace_lightAzimuth[i] / 180.0f ); SFVEC2F( ( cfg->m_Render.raytrace_lightElevation[i] + 90.0f ) / 180.0f,
cfg->m_Render.raytrace_lightAzimuth[i] / 180.0f );
sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f ); sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f );
sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f ); sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f );
@ -495,7 +505,8 @@ void EDA_3D_VIEWER::LoadSettings( APP_SETTINGS_BASE *aCfg )
TRANSFER_SETTING( FL_RENDER_OPENGL_COPPER_THICKNESS, opengl_copper_thickness ); TRANSFER_SETTING( FL_RENDER_OPENGL_COPPER_THICKNESS, opengl_copper_thickness );
TRANSFER_SETTING( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, opengl_show_model_bbox ); TRANSFER_SETTING( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, opengl_show_model_bbox );
TRANSFER_SETTING( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE, opengl_AA_disableOnMove ); TRANSFER_SETTING( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE, opengl_AA_disableOnMove );
TRANSFER_SETTING( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE, opengl_thickness_disableOnMove ); TRANSFER_SETTING( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE,
opengl_thickness_disableOnMove );
TRANSFER_SETTING( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE, opengl_vias_disableOnMove ); TRANSFER_SETTING( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE, opengl_vias_disableOnMove );
TRANSFER_SETTING( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE, opengl_holes_disableOnMove ); TRANSFER_SETTING( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE, opengl_holes_disableOnMove );
@ -524,20 +535,26 @@ void EDA_3D_VIEWER::LoadSettings( APP_SETTINGS_BASE *aCfg )
TRANSFER_SETTING( FL_RENDER_PLATED_PADS_AS_PLATED, renderPlatedPadsAsPlated ); TRANSFER_SETTING( FL_RENDER_PLATED_PADS_AS_PLATED, renderPlatedPadsAsPlated );
m_boardAdapter.GridSet( static_cast<GRID3D_TYPE>( cfg->m_Render.grid_type ) ); m_boardAdapter.GridSet( static_cast<GRID3D_TYPE>( cfg->m_Render.grid_type ) );
m_boardAdapter.AntiAliasingSet( static_cast<ANTIALIASING_MODE>( cfg->m_Render.opengl_AA_mode ) ); m_boardAdapter.AntiAliasingSet(
static_cast<ANTIALIASING_MODE>( cfg->m_Render.opengl_AA_mode ) );
m_boardAdapter.m_opengl_selectionColor = m_boardAdapter.GetColor( cfg->m_Render.opengl_selection_color ); m_boardAdapter.m_opengl_selectionColor =
m_boardAdapter.GetColor( cfg->m_Render.opengl_selection_color );
m_boardAdapter.m_raytrace_nrsamples_shadows = cfg->m_Render.raytrace_nrsamples_shadows; m_boardAdapter.m_raytrace_nrsamples_shadows = cfg->m_Render.raytrace_nrsamples_shadows;
m_boardAdapter.m_raytrace_nrsamples_reflections = cfg->m_Render.raytrace_nrsamples_reflections; m_boardAdapter.m_raytrace_nrsamples_reflections =
m_boardAdapter.m_raytrace_nrsamples_refractions = cfg->m_Render.raytrace_nrsamples_refractions; cfg->m_Render.raytrace_nrsamples_reflections;
m_boardAdapter.m_raytrace_nrsamples_refractions =
cfg->m_Render.raytrace_nrsamples_refractions;
m_boardAdapter.m_raytrace_spread_shadows = cfg->m_Render.raytrace_spread_shadows; m_boardAdapter.m_raytrace_spread_shadows = cfg->m_Render.raytrace_spread_shadows;
m_boardAdapter.m_raytrace_spread_reflections = cfg->m_Render.raytrace_spread_reflections; m_boardAdapter.m_raytrace_spread_reflections = cfg->m_Render.raytrace_spread_reflections;
m_boardAdapter.m_raytrace_spread_refractions = cfg->m_Render.raytrace_spread_refractions; m_boardAdapter.m_raytrace_spread_refractions = cfg->m_Render.raytrace_spread_refractions;
m_boardAdapter.m_raytrace_recursivelevel_refractions = cfg->m_Render.raytrace_recursivelevel_refractions; m_boardAdapter.m_raytrace_recursivelevel_refractions =
m_boardAdapter.m_raytrace_recursivelevel_reflections = cfg->m_Render.raytrace_recursivelevel_reflections; cfg->m_Render.raytrace_recursivelevel_refractions;
m_boardAdapter.m_raytrace_recursivelevel_reflections =
cfg->m_Render.raytrace_recursivelevel_reflections;
// When opening the 3D viewer, we use the opengl mode, not the ray tracing engine // When opening the 3D viewer, we use the opengl mode, not the ray tracing engine
// because the ray tracing is very time consumming, and can be seen as not working // because the ray tracing is very time consumming, and can be seen as not working
@ -582,13 +599,14 @@ void EDA_3D_VIEWER::SaveSettings( APP_SETTINGS_BASE *aCfg )
// in config file, that appears always modified. // in config file, that appears always modified.
// So we must compare the SFVEC4F old and new values and update only // So we must compare the SFVEC4F old and new values and update only
// actual changes. // actual changes.
SFVEC4F newSFVEC4Fcolor( float(colors->GetColor( aTarget ).r), SFVEC4F newSFVEC4Fcolor( float( colors->GetColor( aTarget ).r ),
float(colors->GetColor( aTarget ).g), float( colors->GetColor( aTarget ).g ),
float(colors->GetColor( aTarget ).b), float( colors->GetColor( aTarget ).b ),
float(colors->GetColor( aTarget ).a) ); float( colors->GetColor( aTarget ).a ) );
if( aSource != newSFVEC4Fcolor ) if( aSource != newSFVEC4Fcolor )
colors->SetColor( aTarget, COLOR4D( aSource.r, aSource.g, aSource.b, aSource.a ) ); colors->SetColor( aTarget, COLOR4D( aSource.r, aSource.g, aSource.b,
aSource.a ) );
}; };
save_color( m_boardAdapter.m_BgColorBot, LAYER_3D_BACKGROUND_BOTTOM ); save_color( m_boardAdapter.m_BgColorBot, LAYER_3D_BACKGROUND_BOTTOM );
@ -615,29 +633,39 @@ void EDA_3D_VIEWER::SaveSettings( APP_SETTINGS_BASE *aCfg )
aTarget = COLOR4D( aSource.r, aSource.g, aSource.b, 1.0 ); aTarget = COLOR4D( aSource.r, aSource.g, aSource.b, 1.0 );
}; };
save_color( m_boardAdapter.m_raytrace_lightColorCamera, cfg->m_Render.raytrace_lightColorCamera ); save_color( m_boardAdapter.m_raytrace_lightColorCamera,
cfg->m_Render.raytrace_lightColorCamera );
save_color( m_boardAdapter.m_raytrace_lightColorTop, cfg->m_Render.raytrace_lightColorTop ); save_color( m_boardAdapter.m_raytrace_lightColorTop,
save_color( m_boardAdapter.m_raytrace_lightColorBottom, cfg->m_Render.raytrace_lightColorBottom ); cfg->m_Render.raytrace_lightColorTop );
save_color( m_boardAdapter.m_raytrace_lightColorBottom,
cfg->m_Render.raytrace_lightColorBottom );
for( size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i ) for( size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i )
{ {
save_color( m_boardAdapter.m_raytrace_lightColor[i], cfg->m_Render.raytrace_lightColor[i] ); save_color( m_boardAdapter.m_raytrace_lightColor[i],
cfg->m_Render.raytrace_lightColor[i] );
cfg->m_Render.raytrace_lightElevation[i] = (int)( m_boardAdapter.m_raytrace_lightSphericalCoords[i].x * 180.0f - 90.0f ); cfg->m_Render.raytrace_lightElevation[i] =
cfg->m_Render.raytrace_lightAzimuth[i] = (int)( m_boardAdapter.m_raytrace_lightSphericalCoords[i].y * 180.0f ); (int)( m_boardAdapter.m_raytrace_lightSphericalCoords[i].x * 180.0f - 90.0f );
cfg->m_Render.raytrace_lightAzimuth[i] =
(int)( m_boardAdapter.m_raytrace_lightSphericalCoords[i].y * 180.0f );
} }
cfg->m_Render.raytrace_nrsamples_shadows = m_boardAdapter.m_raytrace_nrsamples_shadows; cfg->m_Render.raytrace_nrsamples_shadows = m_boardAdapter.m_raytrace_nrsamples_shadows;
cfg->m_Render.raytrace_nrsamples_reflections = m_boardAdapter.m_raytrace_nrsamples_reflections; cfg->m_Render.raytrace_nrsamples_reflections =
cfg->m_Render.raytrace_nrsamples_refractions = m_boardAdapter.m_raytrace_nrsamples_refractions; m_boardAdapter.m_raytrace_nrsamples_reflections;
cfg->m_Render.raytrace_nrsamples_refractions =
m_boardAdapter.m_raytrace_nrsamples_refractions;
cfg->m_Render.raytrace_spread_shadows = m_boardAdapter.m_raytrace_spread_shadows; cfg->m_Render.raytrace_spread_shadows = m_boardAdapter.m_raytrace_spread_shadows;
cfg->m_Render.raytrace_spread_reflections = m_boardAdapter.m_raytrace_spread_reflections; cfg->m_Render.raytrace_spread_reflections = m_boardAdapter.m_raytrace_spread_reflections;
cfg->m_Render.raytrace_spread_refractions = m_boardAdapter.m_raytrace_spread_refractions; cfg->m_Render.raytrace_spread_refractions = m_boardAdapter.m_raytrace_spread_refractions;
cfg->m_Render.raytrace_recursivelevel_refractions = m_boardAdapter.m_raytrace_recursivelevel_refractions; cfg->m_Render.raytrace_recursivelevel_refractions =
cfg->m_Render.raytrace_recursivelevel_reflections = m_boardAdapter.m_raytrace_recursivelevel_reflections; m_boardAdapter.m_raytrace_recursivelevel_refractions;
cfg->m_Render.raytrace_recursivelevel_reflections =
m_boardAdapter.m_raytrace_recursivelevel_reflections;
#define TRANSFER_SETTING( field, flag ) cfg->m_Render.field = m_boardAdapter.GetFlag( flag ) #define TRANSFER_SETTING( field, flag ) cfg->m_Render.field = m_boardAdapter.GetFlag( flag )
@ -657,7 +685,8 @@ void EDA_3D_VIEWER::SaveSettings( APP_SETTINGS_BASE *aCfg )
TRANSFER_SETTING( opengl_AA_disableOnMove, FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE ); TRANSFER_SETTING( opengl_AA_disableOnMove, FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE );
TRANSFER_SETTING( opengl_copper_thickness, FL_RENDER_OPENGL_COPPER_THICKNESS ); TRANSFER_SETTING( opengl_copper_thickness, FL_RENDER_OPENGL_COPPER_THICKNESS );
TRANSFER_SETTING( opengl_show_model_bbox, FL_RENDER_OPENGL_SHOW_MODEL_BBOX ); TRANSFER_SETTING( opengl_show_model_bbox, FL_RENDER_OPENGL_SHOW_MODEL_BBOX );
TRANSFER_SETTING( opengl_thickness_disableOnMove, FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE ); TRANSFER_SETTING( opengl_thickness_disableOnMove,
FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE );
TRANSFER_SETTING( opengl_vias_disableOnMove, FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE ); TRANSFER_SETTING( opengl_vias_disableOnMove, FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE );
TRANSFER_SETTING( opengl_holes_disableOnMove, FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE ); TRANSFER_SETTING( opengl_holes_disableOnMove, FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE );
@ -696,6 +725,7 @@ void EDA_3D_VIEWER::SynchroniseColoursWithBoard()
BOARD* brd = GetBoard(); BOARD* brd = GetBoard();
const FAB_LAYER_COLOR* stdColors = GetColorStandardList(); const FAB_LAYER_COLOR* stdColors = GetColorStandardList();
wxColour color; wxColour color;
if( brd ) if( brd )
{ {
const BOARD_STACKUP& stckp = brd->GetDesignSettings().GetStackupDescriptor(); const BOARD_STACKUP& stckp = brd->GetDesignSettings().GetStackupDescriptor();
@ -856,7 +886,7 @@ void EDA_3D_VIEWER::takeScreenshot( wxCommandEvent& event )
else else
{ {
if( !screenshotImage.SaveFile( fullFileName, if( !screenshotImage.SaveFile( fullFileName,
fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) ) fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
wxMessageBox( _( "Can't save file" ) ); wxMessageBox( _( "Can't save file" ) );
screenshotImage.Destroy(); screenshotImage.Destroy();
@ -882,7 +912,8 @@ bool EDA_3D_VIEWER::Set3DColorFromUser( SFVEC4F &aColor, const wxString& aTitle,
KIGFX::COLOR4D newcolor; KIGFX::COLOR4D newcolor;
KIGFX::COLOR4D oldcolor( aColor.r,aColor.g, aColor.b, aColor.a ); KIGFX::COLOR4D oldcolor( aColor.r,aColor.g, aColor.b, aColor.a );
DIALOG_COLOR_PICKER picker( this, oldcolor, aAllowOpacityControl, aPredefinedColors, aDefaultColor ); DIALOG_COLOR_PICKER picker( this, oldcolor, aAllowOpacityControl, aPredefinedColors,
aDefaultColor );
if( picker.ShowModal() != wxID_OK ) if( picker.ShowModal() != wxID_OK )
return false; return false;
@ -908,7 +939,8 @@ bool EDA_3D_VIEWER::Set3DSilkScreenColorFromUser()
colors.push_back( CUSTOM_COLOR_ITEM( 241.0/255.0, 241.0/255.0, 241.0/255.0, "White" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 241.0/255.0, 241.0/255.0, 241.0/255.0, "White" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 4.0/255.0, 18.0/255.0, 21.0/255.0, "Dark" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 4.0/255.0, 18.0/255.0, 21.0/255.0, "Dark" ) );
if( Set3DColorFromUser( m_boardAdapter.m_SilkScreenColorTop, _( "Silkscreen Color" ), &colors, false, colors[0].m_Color ) ) if( Set3DColorFromUser( m_boardAdapter.m_SilkScreenColorTop, _( "Silkscreen Color" ),
&colors, false, colors[0].m_Color ) )
{ {
m_boardAdapter.m_SilkScreenColorBot = m_boardAdapter.m_SilkScreenColorTop; m_boardAdapter.m_SilkScreenColorBot = m_boardAdapter.m_SilkScreenColorTop;
@ -927,20 +959,24 @@ bool EDA_3D_VIEWER::Set3DSolderMaskColorFromUser()
colors.push_back( CUSTOM_COLOR_ITEM( 20/255.0, 51/255.0, 36/255.0, 0.83, "Green" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 20/255.0, 51/255.0, 36/255.0, 0.83, "Green" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 91/255.0, 168/255.0, 12/255.0, 0.83, "Light Green" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 91/255.0, 168/255.0, 12/255.0, 0.83, "Light Green" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 13/255.0, 104/255.0, 11/255.0, 0.83, "Saturated Green" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 13/255.0, 104/255.0, 11/255.0, 0.83,
"Saturated Green" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 181/255.0, 19/255.0, 21/255.0, 0.83, "Red" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 181/255.0, 19/255.0, 21/255.0, 0.83, "Red" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 239/255.0, 53/255.0, 41/255.0, 0.83, "Red Light Orange" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 239/255.0, 53/255.0, 41/255.0, 0.83,
"Red Light Orange" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 210/255.0, 40/255.0, 14/255.0, 0.83, "Red 2" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 210/255.0, 40/255.0, 14/255.0, 0.83, "Red 2" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 2/255.0, 59/255.0, 162/255.0, 0.83, "Blue" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 2/255.0, 59/255.0, 162/255.0, 0.83, "Blue" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 54/255.0, 79/255.0, 116/255.0, 0.83, "Light blue 1" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 54/255.0, 79/255.0, 116/255.0, 0.83, "Light blue 1" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 61/255.0, 85/255.0, 130/255.0, 0.83, "Light blue 2" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 61/255.0, 85/255.0, 130/255.0, 0.83, "Light blue 2" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 21/255.0, 70/255.0, 80/255.0, 0.83, "Green blue (dark)" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 21/255.0, 70/255.0, 80/255.0, 0.83,
"Green blue (dark)" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 11/255.0, 11/255.0, 11/255.0, 0.83, "Black" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 11/255.0, 11/255.0, 11/255.0, 0.83, "Black" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 245/255.0, 245/255.0, 245/255.0, 0.83, "White" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 245/255.0, 245/255.0, 245/255.0, 0.83, "White" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 119/255.0, 31/255.0, 91/255.0, 0.83, "Purple" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 119/255.0, 31/255.0, 91/255.0, 0.83, "Purple" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 32/255.0, 2/255.0, 53/255.0, 0.83, "Purple Dark" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 32/255.0, 2/255.0, 53/255.0, 0.83, "Purple Dark" ) );
if( Set3DColorFromUser( m_boardAdapter.m_SolderMaskColorTop, _( "Solder Mask Color" ), &colors, true, colors[0].m_Color ) ) if( Set3DColorFromUser( m_boardAdapter.m_SolderMaskColorTop, _( "Solder Mask Color" ),
&colors, true, colors[0].m_Color ) )
{ {
m_boardAdapter.m_SolderMaskColorBot = m_boardAdapter.m_SolderMaskColorTop; m_boardAdapter.m_SolderMaskColorBot = m_boardAdapter.m_SolderMaskColorTop;
@ -962,7 +998,8 @@ bool EDA_3D_VIEWER::Set3DCopperColorFromUser()
colors.push_back( CUSTOM_COLOR_ITEM( 213/255.0, 213/255.0, 213/255.0, "Silver" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 213/255.0, 213/255.0, 213/255.0, "Silver" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 160/255.0, 160/255.0, 160/255.0, "Tin" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 160/255.0, 160/255.0, 160/255.0, "Tin" ) );
if( Set3DColorFromUser( m_boardAdapter.m_CopperColor, _( "Copper Color" ), &colors, false, colors[0].m_Color ) ) if( Set3DColorFromUser( m_boardAdapter.m_CopperColor, _( "Copper Color" ), &colors, false,
colors[0].m_Color ) )
{ {
refreshRender(); refreshRender();
@ -977,7 +1014,8 @@ bool EDA_3D_VIEWER::Set3DBoardBodyColorFromUser()
{ {
CUSTOM_COLORS_LIST colors; CUSTOM_COLORS_LIST colors;
colors.push_back( CUSTOM_COLOR_ITEM( 51/255.0, 43/255.0, 22/255.0, 0.9, "FR4 natural, dark" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 51/255.0, 43/255.0, 22/255.0, 0.9,
"FR4 natural, dark" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 109/255.0, 116/255.0, 75/255.0, 0.9, "FR4 natural" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 109/255.0, 116/255.0, 75/255.0, 0.9, "FR4 natural" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 78/255.0, 14/255.0, 5/255.0, 0.9, "brown/red" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 78/255.0, 14/255.0, 5/255.0, 0.9, "brown/red" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 146/255.0, 99/255.0, 47/255.0, 0.9, "brown 1" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 146/255.0, 99/255.0, 47/255.0, 0.9, "brown 1" ) );
@ -986,7 +1024,8 @@ bool EDA_3D_VIEWER::Set3DBoardBodyColorFromUser()
colors.push_back( CUSTOM_COLOR_ITEM( 63/255.0, 126/255.0, 71/255.0, 0.9, "green 1" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 63/255.0, 126/255.0, 71/255.0, 0.9, "green 1" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 117/255.0, 122/255.0, 90/255.0, 0.9, "green 2" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 117/255.0, 122/255.0, 90/255.0, 0.9, "green 2" ) );
if( Set3DColorFromUser( m_boardAdapter.m_BoardBodyColor, _( "Board Body Color" ), &colors, true, colors[0].m_Color ) ) if( Set3DColorFromUser( m_boardAdapter.m_BoardBodyColor, _( "Board Body Color" ), &colors,
true, colors[0].m_Color ) )
{ {
refreshRender(); refreshRender();
@ -1005,7 +1044,8 @@ bool EDA_3D_VIEWER::Set3DSolderPasteColorFromUser()
colors.push_back( CUSTOM_COLOR_ITEM( 213/255.0, 213/255.0, 213/255.0, "Silver" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 213/255.0, 213/255.0, 213/255.0, "Silver" ) );
colors.push_back( CUSTOM_COLOR_ITEM( 90/255.0, 90/255.0, 90/255.0, "grey 2" ) ); colors.push_back( CUSTOM_COLOR_ITEM( 90/255.0, 90/255.0, 90/255.0, "grey 2" ) );
if( Set3DColorFromUser( m_boardAdapter.m_SolderPasteColor, _( "Solder Paste Color" ), &colors, false, colors[0].m_Color ) ) if( Set3DColorFromUser( m_boardAdapter.m_SolderPasteColor, _( "Solder Paste Color" ), &colors,
false, colors[0].m_Color ) )
{ {
refreshRender(); refreshRender();

View File

@ -60,15 +60,12 @@ enum EDA_3D_VIEWER_STATUSBAR
}; };
/** /**
* Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard * Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard
*/ */
class EDA_3D_VIEWER : public EDA_3D_BOARD_HOLDER, public KIWAY_PLAYER class EDA_3D_VIEWER : public EDA_3D_BOARD_HOLDER, public KIWAY_PLAYER
{ {
public:
public: EDA_3D_VIEWER( KIWAY* aKiway, PCB_BASE_FRAME* aParent, const wxString& aTitle,
EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent,
const wxString &aTitle,
long style = KICAD_DEFAULT_3D_DRAWFRAME_STYLE ); long style = KICAD_DEFAULT_3D_DRAWFRAME_STYLE );
~EDA_3D_VIEWER(); ~EDA_3D_VIEWER();
@ -80,24 +77,26 @@ class EDA_3D_VIEWER : public EDA_3D_BOARD_HOLDER, public KIWAY_PLAYER
wxWindow* GetToolCanvas() const override { return m_canvas; } wxWindow* GetToolCanvas() const override { return m_canvas; }
/** /**
* Request reloading the 3D view. However the request will be executed * Request reloading the 3D view.
* only when the 3D canvas is refreshed. *
* It allows one to prepare changes and request for 3D rebuild only when all * However the request will be executed only when the 3D canvas is refreshed. It allows
* changes are committed. * one to prepare changes and request for 3D rebuild only when all changes are committed.
* This is made because the 3D rebuild can take a long time, and this rebuild * This is made because the 3D rebuild can take a long time, and this rebuild cannot
* cannot always made after each change, for calculation time reason. * always made after each change, for calculation time reason.
*/ */
void ReloadRequest(); void ReloadRequest();
// !TODO: review this function: it need a way to tell what changed, // !TODO: review this function: it need a way to tell what changed,
// to only reload/rebuild things that have really changed // to only reload/rebuild things that have really changed
/** /**
* Reload and refresh (rebuild) the 3D scene. * Reload and refresh (rebuild) the 3D scene.
* Warning: rebuilding the 3D scene can take a bit of time, so *
* rebuilding the scene can be immediate, or made later, during * @warning Rebuilding the 3D scene can take a bit of time, so rebuilding the scene can
* the next 3D canvas refresh (on zoom for instance) * be immediate, or made later, during the next 3D canvas refresh (on zoom for
* @param aForceImmediateRedraw = true to immediately rebuild the 3D scene, * instance).
* false to wait a refresh later. *
* @param aForceImmediateRedraw true to immediately rebuild the 3D scene or false to wait
* refresh later.
*/ */
void NewDisplay( bool aForceImmediateRedraw = false ); void NewDisplay( bool aForceImmediateRedraw = false );
@ -109,44 +108,50 @@ class EDA_3D_VIEWER : public EDA_3D_BOARD_HOLDER, public KIWAY_PLAYER
EDA_3D_CANVAS* GetCanvas() { return m_canvas; } EDA_3D_CANVAS* GetCanvas() { return m_canvas; }
/** /**
* Get a SFVEC3D from a wx colour dialog * Get a SFVEC3D from a color dialog.
* @param aColor is the SFVEC3D to change *
* @param aTitle is the title displayed in the colordialog selector * @param aColor is the SFVEC3D to change.
* @param aPredefinedColors is a reference to a CUSTOM_COLOR_ITEM list which contains * @param aTitle is the title displayed in the colordialog selector.
* a few predefined colors * @param aPredefinedColors is a reference to a CUSTOM_COLOR_ITEM list which contains.
* a few predefined colors
*/ */
bool Set3DColorFromUser( SFVEC4F &aColor, const wxString& aTitle, bool Set3DColorFromUser( SFVEC4F& aColor, const wxString& aTitle,
CUSTOM_COLORS_LIST* aPredefinedColors, CUSTOM_COLORS_LIST* aPredefinedColors,
bool aAllowOpacityControl = false, bool aAllowOpacityControl = false,
KIGFX::COLOR4D aDefaultColor = KIGFX::COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); KIGFX::COLOR4D aDefaultColor = KIGFX::COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
/** /**
* Set the solder mask color from a set of colors * Set the solder mask color from a set of colors.
* @return true if a new color is chosen, false if no change or aborted by user *
* @return true if a new color is chosen, false if no change or aborted by user.
*/ */
bool Set3DSolderMaskColorFromUser(); bool Set3DSolderMaskColorFromUser();
/** /**
* Set the solder mask color from a set of colors * Set the solder mask color from a set of colors.
* @return true if a new color is chosen, false if no change or aborted by user *
* @return true if a new color is chosen, false if no change or aborted by user.
*/ */
bool Set3DSolderPasteColorFromUser(); bool Set3DSolderPasteColorFromUser();
/** /**
* Set the copper color from a set of colors * Set the copper color from a set of colors.
* @return true if a new color is chosen, false if no change or aborted by user *
* @return true if a new color is chosen, false if no change or aborted by user.
*/ */
bool Set3DCopperColorFromUser(); bool Set3DCopperColorFromUser();
/** /**
* Set the copper color from a set of colors * Set the copper color from a set of colors.
* @return true if a new color is chosen, false if no change or aborted by user *
* @return true if a new color is chosen, false if no change or aborted by user.
*/ */
bool Set3DBoardBodyColorFromUser(); bool Set3DBoardBodyColorFromUser();
/** /**
* Set the silkscreen color from a set of colors * Set the silkscreen color from a set of colors.
* @return true if a new color is chosen, false if no change or aborted by user *
* @return true if a new color is chosen, false if no change or aborted by user.
*/ */
bool Set3DSilkScreenColorFromUser(); bool Set3DSilkScreenColorFromUser();
@ -166,27 +171,27 @@ protected:
private: private:
/// Called when user press the File->Exit /// Called when user press the File->Exit
void Exit3DFrame( wxCommandEvent &event ); void Exit3DFrame( wxCommandEvent& event );
void OnCloseWindow( wxCloseEvent &event ); void OnCloseWindow( wxCloseEvent& event );
void Process_Special_Functions( wxCommandEvent &event ); void Process_Special_Functions( wxCommandEvent& event );
void OnRenderEngineSelection( wxCommandEvent &event ); void OnRenderEngineSelection( wxCommandEvent& event );
void OnDisableRayTracing( wxCommandEvent& aEvent ); void OnDisableRayTracing( wxCommandEvent& aEvent );
void OnActivate( wxActivateEvent &event ); void OnActivate( wxActivateEvent& event );
void OnSetFocus( wxFocusEvent &event ); void OnSetFocus( wxFocusEvent& event );
void Install3DViewOptionDialog( wxCommandEvent &event ); void Install3DViewOptionDialog( wxCommandEvent& event );
void CreateMenuBar(); void CreateMenuBar();
void ReCreateMainToolbar(); void ReCreateMainToolbar();
void SaveSettings( APP_SETTINGS_BASE *aCfg ) override; void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
void LoadSettings( APP_SETTINGS_BASE *aCfg ) override; void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
/** /**
* Create a Screenshot of the current 3D view. * Create a Screenshot of the current 3D view.
@ -203,8 +208,6 @@ private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
private:
/** /**
* Load configuration from common settings. * Load configuration from common settings.
*/ */

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,7 +33,7 @@
#include "ogl_utils.h" #include "ogl_utils.h"
void OGL_GetScreenshot( wxImage &aDstImage ) void OGL_GetScreenshot( wxImage& aDstImage )
{ {
struct viewport_params struct viewport_params
{ {
@ -45,8 +45,7 @@ void OGL_GetScreenshot( wxImage &aDstImage )
glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport ); glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport );
unsigned char* pixelbuffer = (unsigned char*) malloc( viewport.x * unsigned char* pixelbuffer = (unsigned char*) malloc( viewport.x * viewport.y * 3 );
viewport.y * 3 );
// Alphabuffer was causing some transparency problems on some systems (Windows) // Alphabuffer was causing some transparency problems on some systems (Windows)
// unsigned char* alphabuffer = (unsigned char*) malloc( viewport.x * viewport.y ); // unsigned char* alphabuffer = (unsigned char*) malloc( viewport.x * viewport.y );
@ -57,9 +56,8 @@ void OGL_GetScreenshot( wxImage &aDstImage )
glPixelStorei( GL_PACK_ALIGNMENT, 1 ); glPixelStorei( GL_PACK_ALIGNMENT, 1 );
glReadBuffer( GL_BACK_LEFT ); glReadBuffer( GL_BACK_LEFT );
glReadPixels( viewport.originX, viewport.originY, glReadPixels( viewport.originX, viewport.originY, viewport.x, viewport.y, GL_RGB,
viewport.x, viewport.y, GL_UNSIGNED_BYTE, pixelbuffer );
GL_RGB, GL_UNSIGNED_BYTE, pixelbuffer );
// glReadPixels( viewport.originX, viewport.originY, // glReadPixels( viewport.originX, viewport.originY,
// viewport.x, viewport.y, // viewport.x, viewport.y,
@ -78,7 +76,7 @@ void OGL_GetScreenshot( wxImage &aDstImage )
} }
GLuint OGL_LoadTexture( const CIMAGE &aImage ) GLuint OGL_LoadTexture( const CIMAGE& aImage )
{ {
unsigned char* rgbaBuffer = (unsigned char*) malloc( aImage.GetWidth() * unsigned char* rgbaBuffer = (unsigned char*) malloc( aImage.GetWidth() *
aImage.GetHeight() * 4 ); aImage.GetHeight() * 4 );
@ -114,15 +112,8 @@ GLuint OGL_LoadTexture( const CIMAGE &aImage )
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
rgbaBuffer );*/ rgbaBuffer );*/
glTexImage2D( GL_TEXTURE_2D, glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aImage.GetWidth(), aImage.GetHeight(), 0, GL_RGBA,
0, GL_UNSIGNED_BYTE, rgbaBuffer );
GL_RGBA,
aImage.GetWidth(),
aImage.GetHeight(),
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
rgbaBuffer );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); //glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
@ -142,7 +133,8 @@ GLuint OGL_LoadTexture( const CIMAGE &aImage )
} }
void OGL_SetMaterial( const SMATERIAL & aMaterial, float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor ) void OGL_SetMaterial( const SMATERIAL& aMaterial, float aOpacity, bool aUseSelectedMaterial,
SFVEC3F aSelectionColor )
{ {
const SFVEC4F ambient = SFVEC4F( aMaterial.m_Ambient, 1.0f ); const SFVEC4F ambient = SFVEC4F( aMaterial.m_Ambient, 1.0f );
@ -154,9 +146,8 @@ void OGL_SetMaterial( const SMATERIAL & aMaterial, float aOpacity, bool aUseSele
const SFVEC4F specular = SFVEC4F( aMaterial.m_Specular, 1.0f ); const SFVEC4F specular = SFVEC4F( aMaterial.m_Specular, 1.0f );
const SFVEC4F emissive = SFVEC4F( aMaterial.m_Emissive, 1.0f ); const SFVEC4F emissive = SFVEC4F( aMaterial.m_Emissive, 1.0f );
const float shininess = 128.0f * ( (aMaterial.m_Shininess > 1.0f)? const float shininess =
1.0f: 128.0f * ( (aMaterial.m_Shininess > 1.0f) ? 1.0f : aMaterial.m_Shininess );
aMaterial.m_Shininess );
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r ); glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r ); glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
@ -181,7 +172,7 @@ void OGL_SetDiffuseOnlyMaterial( const SFVEC3F &aMaterialDiffuse, float aOpacity
} }
void OGL_DrawBackground( const SFVEC3F &aTopColor, const SFVEC3F &aBotColor ) void OGL_DrawBackground( const SFVEC3F& aTopColor, const SFVEC3F& aBotColor )
{ {
glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION );
glLoadIdentity(); glLoadIdentity();

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -23,8 +23,9 @@
*/ */
/** /**
* @file ogl_utils.h * @file ogl_utils.h
* @brief implements generic openGL functions that are common to any openGL target *
* Implements generic OpenGL functions that are common to any OpenGL target.
*/ */
#ifndef OGL_UTILS_H_ #ifndef OGL_UTILS_H_
@ -34,52 +35,45 @@
#include "3d_rendering/cimage.h" #include "3d_rendering/cimage.h"
#include <plugins/3dapi/c3dmodel.h> #include <plugins/3dapi/c3dmodel.h>
/** /**
* @brief OGL_SetMaterial - Set OpenGL materials * Set OpenGL materials.
* @param aMaterial: a material structure with parameters to set *
* @param aOpacity: main model opacity 0.0 full transparente, 1.0 full opaque * @param aMaterial a material structure with parameters to set.
* @param aUseSelectedMaterial: if material should be set for selection mode * @param aOpacity main model opacity 0.0 full transparent, 1.0 full opaque.
* @param aSelectionColor: material to use for selection in case it is enabled * @param aUseSelectedMaterial if material should be set for selection mode.
* @param aSelectionColor material to use for selection in case it is enabled.
*/ */
void OGL_SetMaterial( const SMATERIAL & aMaterial, float aOpacity, bool aUseSelectedMaterial = false, SFVEC3F aSelectionColor = SFVEC3F( 0.0f ) ); void OGL_SetMaterial( const SMATERIAL& aMaterial, float aOpacity,
bool aUseSelectedMaterial = false,
SFVEC3F aSelectionColor = SFVEC3F( 0.0f ) );
/** /**
* @brief OGL_SetDiffuseOnlyMaterial - sets only the diffuse color and keep other * Sets only the diffuse color and keep other parameters with default values.
* parameters with default values *
* @param aMaterialDiffuse: the diffese color to assign to material properties * @param aMaterialDiffuse the diffuse color to assign to material properties.
*/ */
void OGL_SetDiffuseOnlyMaterial( const SFVEC3F &aMaterialDiffuse, float aOpacity ); void OGL_SetDiffuseOnlyMaterial( const SFVEC3F& aMaterialDiffuse, float aOpacity );
/** /**
* @brief OGL_LoadTexture - generate a new OpenGL texture * Generate a new OpenGL texture.
* @param aImage: a image to generate the texture from *
* @return the OpenGL texture index created * @param aImage a image to generate the texture from.
* @return the OpenGL texture index created.
*/ */
GLuint OGL_LoadTexture( const CIMAGE &aImage ); GLuint OGL_LoadTexture( const CIMAGE& aImage );
/** /**
* @brief OGL_GetScreenshot - got the pixel data of current OpenGL image * Get the pixel data of current OpenGL image.
* @param aDstImage: the output image. the image must be destroyed to free the data *
* @param aDstImage the output image. the image must be destroyed to free the data.
*/ */
void OGL_GetScreenshot( wxImage &aDstImage ); void OGL_GetScreenshot( wxImage& aDstImage );
void OGL_DrawBackground( const SFVEC3F& aTopColor, const SFVEC3F& aBotColor );
/** /**
* @brief OGL_DrawBackground * Reset to default state the texture settings.
* @param aTopColor
* @param aBotColor
*/
void OGL_DrawBackground( const SFVEC3F &aTopColor, const SFVEC3F &aBotColor );
/**
* @brief OGL_ResetTextureStateDefaults - resets to default state the texture settings
*/ */
void OGL_ResetTextureStateDefaults(); void OGL_ResetTextureStateDefaults();
#endif // OGL_UTILS_H_ #endif // OGL_UTILS_H_