diff --git a/3d-viewer/3d_canvas/board_adapter.cpp b/3d-viewer/3d_canvas/board_adapter.cpp index 48b91353f1..cd93a30012 100644 --- a/3d-viewer/3d_canvas/board_adapter.cpp +++ b/3d-viewer/3d_canvas/board_adapter.cpp @@ -67,6 +67,9 @@ const wxChar *BOARD_ADAPTER::m_logTrace = wxT( "KI_TRACE_EDA_CINFO3D_VISU" ); BOARD_ADAPTER::BOARD_ADAPTER() : + m_Cfg( nullptr ), + m_IsBoardView( true ), + m_MousewheelPanning( true ), m_board( nullptr ), m_3dModelManager( nullptr ), m_colors( nullptr ), @@ -75,16 +78,9 @@ BOARD_ADAPTER::BOARD_ADAPTER() : { wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::BOARD_ADAPTER" ) ); - m_gridType = GRID3D_TYPE::NONE; - m_antiAliasingMode = ANTIALIASING_MODE::AA_8X; - m_drawFlags.resize( FL_LAST, false ); - if( PgmOrNull() ) m_colors = Pgm().GetSettingsManager().GetColorSettings(); - m_renderEngine = RENDER_ENGINE::OPENGL; - m_materialMode = MATERIAL_MODE::NORMAL; - m_boardPos = wxPoint(); m_boardSize = wxSize(); m_boardCenter = SFVEC3F( 0.0f ); @@ -109,27 +105,6 @@ BOARD_ADAPTER::BOARD_ADAPTER() : m_averageHoleDiameter = 0.0f; m_averageTrackWidth = 0.0f; - SetFlag( FL_USE_REALISTIC_MODE, true ); - SetFlag( FL_FP_ATTRIBUTES_NORMAL, true ); - SetFlag( FL_SHOW_BOARD_BODY, true ); - SetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS, false ); - SetFlag( FL_FP_ATTRIBUTES_NORMAL, true ); - SetFlag( FL_FP_ATTRIBUTES_NORMAL_INSERT, true ); - SetFlag( FL_FP_ATTRIBUTES_VIRTUAL, true ); - SetFlag( FL_ZONE, true ); - SetFlag( FL_SILKSCREEN, true ); - SetFlag( FL_SOLDERMASK, true ); - SetFlag( FL_SUBTRACT_MASK_FROM_SILK, false ); - - SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, true ); - SetFlag( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE, false ); - SetFlag( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE, false ); - SetFlag( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE, false ); - SetFlag( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE, false ); - - SetFlag( FL_USE_SELECTION, true ); - SetFlag( FL_HIGHLIGHT_ROLLOVER_ITEM, true ); - m_BgColorBot = SFVEC4F( 0.4, 0.4, 0.5, 1.0 ); m_BgColorTop = SFVEC4F( 0.8, 0.8, 0.9, 1.0 ); m_BoardBodyColor = SFVEC4F( 0.4, 0.4, 0.5, 0.9 ); @@ -146,18 +121,6 @@ BOARD_ADAPTER::BOARD_ADAPTER() : m_frontPlatedPadPolys = nullptr; m_backPlatedPadPolys = nullptr; - // Avoid raytracing options not initialized: - m_RtShadowSampleCount = 0; - m_RtReflectionSampleCount = 0; - m_RtRefractionSampleCount = 0; - - m_RtSpreadShadows = 0.0; - m_RtSpreadReflections = 0.0; - m_RtSpreadRefractions = 0.0; - - m_RtRecursiveReflectionCount = 0; - m_RtRecursiveRefractionCount = 0; - if( !g_ColorsLoaded ) { #define ADD_COLOR( list, r, g, b, a, name ) \ @@ -242,50 +205,37 @@ bool BOARD_ADAPTER::Is3dLayerEnabled( PCB_LAYER_ID aLayer ) const { case B_Adhes: case F_Adhes: - return GetFlag( FL_ADHESIVE ); + return m_Cfg->m_Render.show_adhesive; case B_Paste: case F_Paste: - return GetFlag( FL_SOLDERPASTE ); + return m_Cfg->m_Render.show_solderpaste; case B_SilkS: case F_SilkS: - return GetFlag( FL_SILKSCREEN ); + return m_Cfg->m_Render.show_silkscreen; case B_Mask: case F_Mask: - return GetFlag( FL_SOLDERMASK ); + return m_Cfg->m_Render.show_soldermask; case Dwgs_User: case Cmts_User: - if( GetFlag( FL_USE_REALISTIC_MODE ) ) - return false; - - return GetFlag( FL_COMMENTS ); + return !m_Cfg->m_Render.realistic && m_Cfg->m_Render.show_comments; case Eco1_User: case Eco2_User: - if( GetFlag( FL_USE_REALISTIC_MODE ) ) - return false; - - return GetFlag( FL_ECO ); + return !m_Cfg->m_Render.realistic && m_Cfg->m_Render.show_eco; case Edge_Cuts: - if( GetFlag( FL_SHOW_BOARD_BODY ) || GetFlag( FL_USE_REALISTIC_MODE ) ) - return false; - - return true; + return !m_Cfg->m_Render.realistic && !m_Cfg->m_Render.show_board_body; case Margin: - if( GetFlag( FL_USE_REALISTIC_MODE ) ) - return false; - - return true; + return !m_Cfg->m_Render.realistic; case B_Cu: case F_Cu: - return m_board ? m_board->IsLayerVisible( aLayer ) || GetFlag( FL_USE_REALISTIC_MODE ) - : true; + return !m_board || m_board->IsLayerVisible( aLayer ) || m_Cfg->m_Render.realistic; default: // the layer is an internal copper layer, used the visibility @@ -294,30 +244,14 @@ bool BOARD_ADAPTER::Is3dLayerEnabled( PCB_LAYER_ID aLayer ) const } -bool BOARD_ADAPTER::GetFlag( DISPLAY3D_FLG aFlag ) const -{ - wxASSERT( aFlag < FL_LAST ); - - return m_drawFlags[aFlag]; -} - - -void BOARD_ADAPTER::SetFlag( DISPLAY3D_FLG aFlag, bool aState ) -{ - wxASSERT( aFlag < FL_LAST ); - - m_drawFlags[aFlag] = aState; -} - - bool BOARD_ADAPTER::IsFootprintShown( FOOTPRINT_ATTR_T aFPAttributes ) const { if( aFPAttributes & FP_SMD ) - return GetFlag( FL_FP_ATTRIBUTES_NORMAL_INSERT ); + return m_Cfg->m_Render.show_footprints_insert; else if( aFPAttributes & FP_THROUGH_HOLE ) - return GetFlag( FL_FP_ATTRIBUTES_NORMAL ); + return m_Cfg->m_Render.show_footprints_normal; else - return GetFlag( FL_FP_ATTRIBUTES_VIRTUAL ); + return m_Cfg->m_Render.show_footprints_virtual; } @@ -361,30 +295,24 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR wxString msg; - const bool succeedToGetBoardPolygon = createBoardPolygon( &msg ); + const bool haveOutline = createBoardPolygon( &msg ); if( aWarningReporter ) { - if( !succeedToGetBoardPolygon ) + if( !haveOutline ) aWarningReporter->Report( msg, RPT_SEVERITY_WARNING ); else aWarningReporter->Report( wxEmptyString ); } - // Calculates the board bounding box (board outlines + items) - // to ensure any item, even outside the board outlines can be seen - bool boardEdgesOnly = true; - - if( ( m_board && m_board->IsFootprintHolder() ) || !GetFlag( FL_USE_REALISTIC_MODE ) - || !succeedToGetBoardPolygon ) - { - boardEdgesOnly = false; - } - EDA_RECT bbbox; if( m_board ) - bbbox = m_board->ComputeBoundingBox( boardEdgesOnly ); + { + bbbox = m_board->ComputeBoundingBox( !m_board->IsFootprintHolder() + && m_Cfg->m_Render.realistic + && haveOutline ); + } // Gives a non null size to avoid issues in zoom / scale calculations if( ( bbbox.GetWidth() == 0 ) && ( bbbox.GetHeight() == 0 ) ) @@ -720,14 +648,14 @@ float BOARD_ADAPTER::GetFootprintZPos( bool aIsFlipped ) const { if( aIsFlipped ) { - if( GetFlag( FL_SOLDERPASTE ) ) + if( m_Cfg->m_Render.show_solderpaste ) return m_layerZcoordBottom[B_SilkS]; else return m_layerZcoordBottom[B_Paste]; } else { - if( GetFlag( FL_SOLDERPASTE ) ) + if( m_Cfg->m_Render.show_solderpaste ) return m_layerZcoordTop[F_SilkS]; else return m_layerZcoordTop[F_Paste]; @@ -755,3 +683,16 @@ SFVEC4F BOARD_ADAPTER::GetColor( const COLOR4D& aColor ) const { return SFVEC4F( aColor.r, aColor.g, aColor.b, aColor.a ); } + + +SFVEC2F BOARD_ADAPTER::GetSphericalCoord( int i ) const +{ + SFVEC2F sphericalCoord = + SFVEC2F( ( m_Cfg->m_Render.raytrace_lightElevation[i] + 90.0f ) / 180.0f, + m_Cfg->m_Render.raytrace_lightAzimuth[i] / 180.0f ); + + sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f ); + sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f ); + + return sphericalCoord; +} diff --git a/3d-viewer/3d_canvas/board_adapter.h b/3d-viewer/3d_canvas/board_adapter.h index a29a8e4c29..68095ec10c 100644 --- a/3d-viewer/3d_canvas/board_adapter.h +++ b/3d-viewer/3d_canvas/board_adapter.h @@ -34,6 +34,7 @@ #include "../3d_enums.h" #include "../3d_cache/3d_cache.h" #include "../common_ogl/ogl_attr_list.h" +#include "../3d_viewer/eda_3d_viewer_settings.h" #include #include @@ -51,10 +52,10 @@ class COLOR_SETTINGS; /// A type that stores a container of 2d objects for each layer id -typedef std::map< PCB_LAYER_ID, BVH_CONTAINER_2D *> MAP_CONTAINER_2D_BASE; +typedef std::map MAP_CONTAINER_2D_BASE; /// A type that stores polysets for each layer id -typedef std::map< PCB_LAYER_ID, SHAPE_POLY_SET *> MAP_POLY; +typedef std::map MAP_POLY; /// This defines the range that all coord will have to be rendered. /// It will use this value to convert to a normalized value between @@ -90,22 +91,6 @@ public: return m_3dModelManager; } - /** - * Get a configuration status of a flag. - * - * @param aFlag the flag to get the status. - * @return true if flag is set, false if not. - */ - bool GetFlag( DISPLAY3D_FLG aFlag ) const ; - - /** - * Set the status of a flag. - * - * @param aFlag the flag to set the status - * @param aState status to set. - */ - void SetFlag( DISPLAY3D_FLG aFlag, bool aState ); - /** * Check if a layer is enabled. * @@ -247,72 +232,6 @@ public: */ float GetFootprintZPos( bool aIsFlipped ) const ; - /** - * Get the current grid. - * - * @return space type of the grid. - */ - GRID3D_TYPE GetGridType() const noexcept - { - return m_gridType; - } - - /** - * Set the current grid. - * - * @param aGridType the type space of the grid. - */ - void SetGridType( GRID3D_TYPE aGridType ) noexcept - { - m_gridType = aGridType; - } - - /** - * Get the current antialiasing mode value. - * - * @return antialiasing mode value - */ - ANTIALIASING_MODE GetAntiAliasingMode() const { return m_antiAliasingMode; } - - /** - * Set the current antialiasing mode value. - * - * @param aAAmode antialiasing mode value. - */ - void SetAntiAliasingMode( ANTIALIASING_MODE aAAmode ) { m_antiAliasingMode = aAAmode; } - - /** - * @param aRenderEngine the render engine mode selected. - */ - void SetRenderEngine( RENDER_ENGINE aRenderEngine ) noexcept - { - m_renderEngine = aRenderEngine; - } - - /** - * @return render engine on use. - */ - RENDER_ENGINE GetRenderEngine() const noexcept - { - return m_renderEngine; - } - - /** - * @param aMaterialMode the render material mode. - */ - void SetMaterialMode( MATERIAL_MODE aMaterialMode ) noexcept - { - m_materialMode = aMaterialMode; - } - - /** - * @return material rendering mode. - */ - MATERIAL_MODE GetMaterialMode() const noexcept - { - return m_materialMode; - } - /** * Get the current polygon of the epoxy board. * @@ -345,6 +264,8 @@ public: */ SFVEC4F GetColor( const COLOR4D& aColor ) const; + SFVEC2F GetSphericalCoord( int i ) const; + /** * Get the top z position. * @@ -464,8 +385,6 @@ public: /** * Get number of vias in this board. - * - * @return number of vias. */ unsigned int GetViaCount() const noexcept { @@ -474,8 +393,6 @@ public: /** * Get number of holes in this board. - * - * @return number of holes. */ unsigned int GetHoleCount() const noexcept { @@ -624,6 +541,10 @@ public: static KIGFX::COLOR4D g_DefaultBoardBody; public: + EDA_3D_VIEWER_SETTINGS* m_Cfg; + bool m_IsBoardView; + bool m_MousewheelPanning; + SFVEC4F m_BgColorBot; ///< background bottom color SFVEC4F m_BgColorTop; ///< background top color SFVEC4F m_BoardBodyColor; ///< in realistic mode: FR4 board color @@ -634,142 +555,71 @@ public: SFVEC4F m_SilkScreenColorTop; ///< in realistic mode: SilkScreen color ( top ) SFVEC4F m_CopperColor; ///< in realistic mode: copper color - SFVEC3F m_OpenGlSelectionColor; - - // Raytracing light colors - SFVEC3F m_RtCameraLightColor; - SFVEC3F m_RtLightColorTop; - SFVEC3F m_RtLightColorBottom; - - std::vector m_RtLightColor; - std::vector m_RtLightSphericalCoords; - - // Raytracing options - int m_RtShadowSampleCount; - int m_RtReflectionSampleCount; - int m_RtRefractionSampleCount; - int m_RtRecursiveReflectionCount; - int m_RtRecursiveRefractionCount; - - float m_RtSpreadShadows; - float m_RtSpreadReflections; - float m_RtSpreadRefractions; - private: - BOARD* m_board; - S3D_CACHE* m_3dModelManager; - COLOR_SETTINGS* m_colors; + BOARD* m_board; + S3D_CACHE* m_3dModelManager; + COLOR_SETTINGS* m_colors; - std::vector< bool > m_drawFlags; - GRID3D_TYPE m_gridType; - RENDER_ENGINE m_renderEngine; - MATERIAL_MODE m_materialMode; - ANTIALIASING_MODE m_antiAliasingMode; + wxPoint m_boardPos; ///< Board center position in board internal units. + wxSize m_boardSize; ///< Board size in board internal units. + SFVEC3F m_boardCenter; ///< 3D center position of the board in 3D units. + BBOX_3D m_boardBoundingBox; ///< 3D bounding box of the board in 3D units. - - wxPoint m_boardPos; ///< Board center position in board internal units. - wxSize m_boardSize; ///< Board size in board internal units. - SFVEC3F m_boardCenter; ///< 3D center position of the board in 3D units. - BBOX_3D m_boardBoundingBox; ///< 3D bounding box of the board in 3D units. - - - ///< Polygon contours for each layer. + ///< Amalgamated polygon contours for various types of items MAP_POLY m_layers_poly; SHAPE_POLY_SET* m_frontPlatedPadPolys; SHAPE_POLY_SET* m_backPlatedPadPolys; - ///< Polygon contours for hole outer diameters for each layer. - MAP_POLY m_layerHoleOdPolys; + MAP_POLY m_layerHoleOdPolys; ///< Hole outer diameters (per layer) + MAP_POLY m_layerHoleIdPolys; ///< Hole inner diameters (per layer) - ///< Polygon contours for hole inner diameters for each layer. - MAP_POLY m_layerHoleIdPolys; + SHAPE_POLY_SET m_nonPlatedThroughHoleOdPolys; ///< NPTH outer diameters + SHAPE_POLY_SET m_throughHoleOdPolys; ///< PTH outer diameters + SHAPE_POLY_SET m_throughHoleViaOdPolys; ///< Via hole outer diameters + SHAPE_POLY_SET m_throughHoleAnnularRingPolys; ///< Via annular ring outer diameters - ///< Polygon contours for non plated through hole outer diameters. - SHAPE_POLY_SET m_nonPlatedThroughHoleOdPolys; - - ///< Polygon contours for through hole outer diameters. - SHAPE_POLY_SET m_throughHoleOdPolys; - - ///< Polygon contours for through holes via outer diameters. - SHAPE_POLY_SET m_throughHoleViaOdPolys; - - ///< Polygon contours for through hole via annular rings. - SHAPE_POLY_SET m_throughHoleAnnularRingPolys; - - SHAPE_POLY_SET m_board_poly; ///< Board outline polygon. - - MAP_CONTAINER_2D_BASE m_layerMap; ///< 2D elements for each layer. + SHAPE_POLY_SET m_board_poly; ///< Board outline polygon. + MAP_CONTAINER_2D_BASE m_layerMap; ///< 2D elements for each layer. + MAP_CONTAINER_2D_BASE m_layerHoleMap; ///< Holes for each layer. BVH_CONTAINER_2D* m_platedPadsFront; BVH_CONTAINER_2D* m_platedPadsBack; - ///< The holes per each layer. - MAP_CONTAINER_2D_BASE m_layerHoleMap; + BVH_CONTAINER_2D m_throughHoleOds; ///< List of PTH outer diameters + BVH_CONTAINER_2D m_throughHoleIds; ///< List of PTH inner diameters + BVH_CONTAINER_2D m_throughHoleAnnularRings; ///< List of via annular rings + BVH_CONTAINER_2D m_throughHoleViaOds; ///< List of via hole outer diameters + BVH_CONTAINER_2D m_throughHoleViaIds; ///< List of via hole inner diameters - ///< List of through holes with the radius of the hole inflated with the copper thickness. - BVH_CONTAINER_2D m_throughHoleOds; + unsigned int m_copperLayersCount; - ///< List of plated through hole annular rings. - BVH_CONTAINER_2D m_throughHoleAnnularRings; + double m_biuTo3Dunits; ///< Scale factor to convert board internal units to + ///< 3D units normalized between -1.0 and 1.0. - ///< List of through hole inner diameters. - BVH_CONTAINER_2D m_throughHoleIds; + std::array m_layerZcoordTop; ///< Top (End) Z position of each + ///< layer in 3D units. - ///< List of through hole vias with the radius of the hole inflated with the copper thickness. - BVH_CONTAINER_2D m_throughHoleViaOds; + std::array m_layerZcoordBottom; ///< Bottom (Start) Z position of + ///< each layer in 3D units. - ///< List of through hole via inner diameters. - BVH_CONTAINER_2D m_throughHoleViaIds; + float m_copperThickness3DU; + float m_epoxyThickness3DU; + float m_nonCopperLayerThickness3DU; + float m_solderPasteLayerThickness3DU; - ///< Number of copper layers actually used by the board. - unsigned int m_copperLayersCount; - - ///< Scale factor to convert board internal units to 3D units normalized between -1.0 and 1.0. - double m_biuTo3Dunits; - - ///< Top (End) Z position of each layer in 3D units. - std::array m_layerZcoordTop; - - ///< Bottom (Start) Z position of each layer in 3D units. - std::array m_layerZcoordBottom; - - ///< Copper thickness in 3D units. - float m_copperThickness3DU; - - ///< Epoxy thickness in 3D units. - float m_epoxyThickness3DU; - - ///< Non copper layers thickness in 3D units. - float m_nonCopperLayerThickness3DU; - - ///< solder paste layers thickness in 3D units. - float m_solderPasteLayerThickness3DU; - - ///< Number of tracks in the board. - unsigned int m_trackCount; - - ///< Track average width. - float m_averageTrackWidth; - - ///< Number of through hole vias in the board. - unsigned int m_viaCount; - - ///< Computed average diameter of the via holes in 3D units. - float m_averageViaHoleDiameter; - - ///< Number of holes in the board. - unsigned int m_holeCount; - - ///< Computed average diameter of the holes in 3D units. - float m_averageHoleDiameter; + unsigned int m_trackCount; + float m_averageTrackWidth; + unsigned int m_viaCount; + float m_averageViaHoleDiameter; + unsigned int m_holeCount; + float m_averageHoleDiameter; /** - * Trace mask used to enable or disable the trace output of this class. - * The debug output can be turned on by setting the WXTRACE environment variable to - * "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for - * more information. + * Trace mask used to enable or disable debug output for this class. Output can be turned + * on by setting the WXTRACE environment variable to "KI_TRACE_EDA_CINFO3D_VISU". See the + * wxWidgets documentation on wxLogTrace for more information. */ static const wxChar* m_logTrace; diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp index a8c3ea3b1e..3cfeb7d7a3 100644 --- a/3d-viewer/3d_canvas/create_layer_items.cpp +++ b/3d-viewer/3d_canvas/create_layer_items.cpp @@ -32,11 +32,7 @@ */ #include "board_adapter.h" -#include "../3d_rendering/raytracing/shapes2D/ring_2d.h" #include "../3d_rendering/raytracing/shapes2D/filled_circle_2d.h" -#include "../3d_rendering/raytracing/shapes3D/cylinder_3d.h" - -#include #include #include #include @@ -205,14 +201,15 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) BVH_CONTAINER_2D *layerContainer = new BVH_CONTAINER_2D; m_layerMap[curr_layer_id] = layerContainer; - if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) && m_renderEngine == RENDER_ENGINE::OPENGL ) + if( m_Cfg->m_Render.opengl_copper_thickness + && m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { SHAPE_POLY_SET* layerPoly = new SHAPE_POLY_SET; m_layers_poly[curr_layer_id] = layerPoly; } } - if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_Cfg->m_Render.renderPlatedPadsAsPlated && m_Cfg->m_Render.realistic ) { m_frontPlatedPadPolys = new SHAPE_POLY_SET; m_backPlatedPadPolys = new SHAPE_POLY_SET; @@ -316,16 +313,15 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) hole_inner_radius + thickness, *track ) ); - if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && - GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_Cfg->m_Render.clip_silk_on_via_annulus && m_Cfg->m_Render.realistic ) { m_throughHoleAnnularRings.Add( new FILLED_CIRCLE_2D( via_center, - ring_radius, - *track ) ); + ring_radius, + *track ) ); } m_throughHoleIds.Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius, - *track ) ); + *track ) ); } } } @@ -406,11 +402,11 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) TransformCircleToPolygon( m_throughHoleViaOdPolys, via->GetStart(), hole_outer_radius, ARC_HIGH_DEF, ERROR_INSIDE ); - if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_Cfg->m_Render.clip_silk_on_via_annulus && m_Cfg->m_Render.realistic ) { - TransformCircleToPolygon( m_throughHoleAnnularRingPolys, - via->GetStart(), hole_outer_ring_radius, - ARC_HIGH_DEF, ERROR_INSIDE ); + TransformCircleToPolygon( m_throughHoleAnnularRingPolys, via->GetStart(), + hole_outer_ring_radius, ARC_HIGH_DEF, + ERROR_INSIDE ); } } } @@ -418,7 +414,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) } // Creates vertical outline contours of the tracks and add it to the poly of the layer - if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) && m_renderEngine == RENDER_ENGINE::OPENGL ) + if( m_Cfg->m_Render.opengl_copper_thickness && m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { for( PCB_LAYER_ID curr_layer_id : layer_id ) { @@ -469,10 +465,8 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) m_throughHoleOds.Add( createPadWithDrill( pad, inflate ) ); - if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && GetFlag( FL_USE_REALISTIC_MODE ) ) - { + if( m_Cfg->m_Render.clip_silk_on_via_annulus && m_Cfg->m_Render.realistic ) m_throughHoleAnnularRings.Add( createPadWithDrill( pad, inflate ) ); - } m_throughHoleIds.Add( createPadWithDrill( pad, 0 ) ); } @@ -496,7 +490,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) if( pad->GetAttribute () != PAD_ATTRIB::NPTH ) { - if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_Cfg->m_Render.clip_silk_on_via_annulus && m_Cfg->m_Render.realistic ) { pad->TransformHoleWithClearanceToPolygon( m_throughHoleAnnularRingPolys, inflate, ARC_HIGH_DEF, ERROR_INSIDE ); @@ -508,7 +502,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) else { // If not plated, no copper. - if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_Cfg->m_Render.clip_silk_on_via_annulus && m_Cfg->m_Render.realistic ) { pad->TransformHoleWithClearanceToPolygon( m_throughHoleAnnularRingPolys, 0, ARC_HIGH_DEF, ERROR_INSIDE ); @@ -520,8 +514,8 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) } } - const bool renderPlatedPadsAsPlated = GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && - GetFlag( FL_USE_REALISTIC_MODE ); + const bool renderPlatedPadsAsPlated = m_Cfg->m_Render.renderPlatedPadsAsPlated + && m_Cfg->m_Render.realistic; // Add footprints PADs objects to containers for( PCB_LAYER_ID curr_layer_id : layer_id ) @@ -533,10 +527,10 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) // ADD PADS for( FOOTPRINT* footprint : m_board->Footprints() ) { - // Note: NPTH pads are not drawn on copper layers when the pad - // has same shape as its hole - addPadsWithClearance( footprint, layerContainer, curr_layer_id, 0, - true, renderPlatedPadsAsPlated, false ); + // Note: NPTH pads are not drawn on copper layers when the pad has the same shape + // as its hole + addPadsWithClearance( footprint, layerContainer, curr_layer_id, 0, true, + renderPlatedPadsAsPlated, false ); // Micro-wave footprints may have items on copper layers addFootprintShapesWithClearance( footprint, layerContainer, curr_layer_id, 0 ); @@ -558,7 +552,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) } // Add footprints PADs poly contours (vertical outlines) - if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) && m_renderEngine == RENDER_ENGINE::OPENGL ) + if( m_Cfg->m_Render.opengl_copper_thickness && m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { for( PCB_LAYER_ID curr_layer_id : layer_id ) { @@ -639,7 +633,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) } // Add graphic item on copper layers to poly contours (vertical outlines) - if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) && m_renderEngine == RENDER_ENGINE::OPENGL ) + if( m_Cfg->m_Render.opengl_copper_thickness && m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { for( PCB_LAYER_ID cur_layer_id : layer_id ) { @@ -678,7 +672,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) } } - if( GetFlag( FL_ZONE ) ) + if( m_Cfg->m_Render.show_zones ) { if( aStatusReporter ) aStatusReporter->Report( _( "Create zones" ) ); @@ -725,9 +719,9 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) addSolidAreasShapes( zone, layerContainer->second, layer ); } - if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) - && m_renderEngine == RENDER_ENGINE::OPENGL - && layerPolyContainer != m_layers_poly.end() ) + if( m_Cfg->m_Render.opengl_copper_thickness + && m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL + && layerPolyContainer != m_layers_poly.end() ) { auto mut_it = layer_lock.find( layer ); @@ -752,9 +746,9 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) if( aStatusReporter ) aStatusReporter->Report( _( "Simplifying copper layers polygons" ) ); - if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) && m_renderEngine == RENDER_ENGINE::OPENGL ) + if( m_Cfg->m_Render.opengl_copper_thickness && m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { - if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && GetFlag( FL_USE_REALISTIC_MODE ) ) + if( renderPlatedPadsAsPlated ) { if( m_frontPlatedPadPolys && ( m_layers_poly.find( F_Cu ) != m_layers_poly.end() ) ) { @@ -782,7 +776,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) std::vector< PCB_LAYER_ID > &selected_layer_id = layer_id; std::vector< PCB_LAYER_ID > layer_id_without_F_and_B; - if( GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && GetFlag( FL_USE_REALISTIC_MODE ) ) + if( renderPlatedPadsAsPlated ) { layer_id_without_F_and_B.clear(); layer_id_without_F_and_B.reserve( layer_id.size() ); @@ -799,9 +793,10 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) if( selected_layer_id.size() > 0 ) { if( aStatusReporter ) - aStatusReporter->Report( wxString::Format( - _( "Simplifying %d copper layers" ), - (int)selected_layer_id.size() ) ); + { + aStatusReporter->Report( wxString::Format( _( "Simplifying %d copper layers" ), + (int) selected_layer_id.size() ) ); + } std::atomic nextItem( 0 ); std::atomic threadsFinished( 0 ); @@ -1025,7 +1020,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) // Draw non copper zones - if( GetFlag( FL_ZONE ) ) + if( m_Cfg->m_Render.show_zones ) { for( ZONE* zone : m_board->Zones() ) { diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index fc7a48c71d..0227439c71 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -432,11 +432,11 @@ void EDA_3D_CANVAS::DoRePaint() { m_3d_render = m_3d_render_opengl; m_render_raytracing_was_requested = false; - m_boardAdapter.SetRenderEngine( RENDER_ENGINE::OPENGL ); + m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL; } // Check if a raytacing was requested and need to switch to raytracing mode - if( m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { const bool was_camera_changed = m_camera.ParametersChanged(); @@ -485,7 +485,7 @@ void EDA_3D_CANVAS::DoRePaint() bool reloadRaytracingForCalculations = false; - if( m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL + if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL && m_3d_render_opengl->IsReloadRequestPending() ) { reloadRaytracingForCalculations = true; @@ -593,11 +593,10 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event ) float delta_move = m_delta_move_step_factor * m_camera.GetZoom(); - if( m_boardAdapter.GetFlag( FL_MOUSEWHEEL_PANNING ) ) + if( m_boardAdapter.m_MousewheelPanning ) delta_move *= 0.01f * event.GetWheelRotation(); - else - if( event.GetWheelRotation() < 0 ) - delta_move = -delta_move; + else if( event.GetWheelRotation() < 0 ) + delta_move = -delta_move; // mousewheel_panning enabled: // wheel -> pan; @@ -608,7 +607,7 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event ) // wheel + ctrl -> horizontal scrolling; // wheel -> zooming. - if( m_boardAdapter.GetFlag( FL_MOUSEWHEEL_PANNING ) && !event.ControlDown() ) + if( m_boardAdapter.m_MousewheelPanning && !event.ControlDown() ) { if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL || event.ShiftDown() ) m_camera.Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) ); @@ -617,12 +616,12 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event ) mouseActivity = true; } - else if( event.ShiftDown() && !m_boardAdapter.GetFlag( FL_MOUSEWHEEL_PANNING ) ) + else if( event.ShiftDown() && !m_boardAdapter.m_MousewheelPanning ) { m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) ); mouseActivity = true; } - else if( event.ControlDown() && !m_boardAdapter.GetFlag( FL_MOUSEWHEEL_PANNING ) ) + else if( event.ControlDown() && !m_boardAdapter.m_MousewheelPanning ) { m_camera.Pan( SFVEC3F( delta_move, 0.0f, 0.0f ) ); mouseActivity = true; @@ -699,7 +698,7 @@ void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event ) m_camera.SetCurMousePosition( nativePosition ); - if( !event.Dragging() && m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( !event.Dragging() && m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { STATUSBAR_REPORTER reporter( m_parentStatusBar, static_cast( EDA_3D_VIEWER_STATUSBAR::HOVERED_ITEM ) ); @@ -777,7 +776,8 @@ void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event ) } else { - if( m_currentRollOverItem && m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( m_currentRollOverItem + && m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { m_3d_render_opengl->SetCurrentRollOverItem( nullptr ); Request_refresh(); @@ -1111,7 +1111,10 @@ bool EDA_3D_CANVAS::SetView3D( int aKeycode ) void EDA_3D_CANVAS::RenderEngineChanged() { - switch( m_boardAdapter.GetRenderEngine() ) + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + EDA_3D_VIEWER_SETTINGS* cfg = mgr.GetAppSettings(); + + switch( cfg->m_Render.engine ) { case RENDER_ENGINE::OPENGL: m_3d_render = m_3d_render_opengl; break; case RENDER_ENGINE::RAYTRACING: m_3d_render = m_3d_render_raytracing; break; diff --git a/3d-viewer/3d_enums.h b/3d-viewer/3d_enums.h index b535c72f53..f142e0675a 100644 --- a/3d-viewer/3d_enums.h +++ b/3d-viewer/3d_enums.h @@ -30,52 +30,6 @@ #ifndef _3D_ENUMS_H_ #define _3D_ENUMS_H_ -/// Flags used in rendering options -enum DISPLAY3D_FLG -{ - FL_AXIS = 0, - FL_ZONE, - FL_ADHESIVE, - FL_SILKSCREEN, - FL_SOLDERMASK, - FL_SOLDERPASTE, - FL_COMMENTS, - FL_ECO, - - FL_FP_ATTRIBUTES_NORMAL, - FL_FP_ATTRIBUTES_NORMAL_INSERT, - FL_FP_ATTRIBUTES_VIRTUAL, - - FL_USE_SELECTION, - FL_HIGHLIGHT_ROLLOVER_ITEM, - - FL_SHOW_BOARD_BODY, - FL_MOUSEWHEEL_PANNING, - FL_USE_REALISTIC_MODE, - FL_SUBTRACT_MASK_FROM_SILK, - FL_CLIP_SILK_ON_VIA_ANNULUS, - FL_RENDER_PLATED_PADS_AS_PLATED, - - // OpenGL options - FL_RENDER_OPENGL_SHOW_MODEL_BBOX, - FL_RENDER_OPENGL_COPPER_THICKNESS, - FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE, - FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE, - FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE, - FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE, - - // Raytracing options - FL_RENDER_RAYTRACING_SHADOWS, - FL_RENDER_RAYTRACING_BACKFLOOR, - FL_RENDER_RAYTRACING_REFRACTIONS, - FL_RENDER_RAYTRACING_REFLECTIONS, - FL_RENDER_RAYTRACING_POST_PROCESSING, - FL_RENDER_RAYTRACING_ANTI_ALIASING, - FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, - FL_LAST -}; - - /// Rotation direction for the 3d canvas enum class ROTATION_DIR { @@ -96,7 +50,7 @@ enum class CAMERA_TYPE /// Grid types -enum class GRID3D_TYPE +enum GRID3D_TYPE { NONE, GRID_1MM, @@ -107,7 +61,7 @@ enum class GRID3D_TYPE /// Render engine mode -enum class RENDER_ENGINE +enum RENDER_ENGINE { OPENGL, RAYTRACING, @@ -115,7 +69,7 @@ enum class RENDER_ENGINE /// Render 3d model shape materials mode -enum class MATERIAL_MODE +enum MATERIAL_MODE { NORMAL, ///< Use all material properties from model file DIFFUSE_ONLY, ///< Use only diffuse material properties diff --git a/3d-viewer/3d_rendering/opengl/create_scene.cpp b/3d-viewer/3d_rendering/opengl/create_scene.cpp index b73e669547..45a04301f1 100644 --- a/3d-viewer/3d_rendering/opengl/create_scene.cpp +++ b/3d-viewer/3d_rendering/opengl/create_scene.cpp @@ -451,7 +451,7 @@ void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningRepo // Create Board m_board = createBoard( m_boardAdapter.GetBoardPoly(), &m_boardAdapter.GetThroughHoleIds() ); - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) { m_antiBoardPolys.RemoveAllContours(); m_antiBoardPolys.NewOutline(); @@ -483,7 +483,7 @@ void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningRepo SHAPE_POLY_SET outerPolyTHT = m_boardAdapter.GetThroughHoleOdPolys(); - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) outerPolyTHT.BooleanIntersection( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); @@ -495,8 +495,8 @@ void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningRepo m_boardAdapter.GetThroughHoleViaOds().GetList(), m_boardAdapter.GetThroughHoleViaOdPolys(), 1.0f, 0.0f, false ); - if( m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && - m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus && + m_boardAdapter.m_Cfg->m_Render.realistic ) { m_outerThroughHoleRings = generateHoles( m_boardAdapter.GetThroughHoleAnnularRings().GetList(), @@ -557,8 +557,10 @@ void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningRepo continue; if( aStatusReporter ) - aStatusReporter->Report( wxString::Format( - _( "Load OpenGL layer %d" ), (int)layer_id ) ); + { + aStatusReporter->Report( wxString::Format( _( "Load OpenGL layer %d" ), + (int) layer_id ) ); + } const BVH_CONTAINER_2D* container2d = ii.second; @@ -571,12 +573,12 @@ void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningRepo { polyListSubtracted = *map_poly.at( layer_id );; - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) { polyListSubtracted.BooleanIntersection( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_FAST ); - if( ( layer_id != B_Mask ) && ( layer_id != F_Mask ) ) + if( layer_id != B_Mask && layer_id != F_Mask ) { polyListSubtracted.BooleanSubtract( m_boardAdapter.GetThroughHoleOdPolys(), SHAPE_POLY_SET::PM_FAST ); @@ -585,7 +587,7 @@ void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningRepo SHAPE_POLY_SET::PM_FAST ); } - if( m_boardAdapter.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) ) + if( m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk ) { if( layer_id == B_SilkS && map_poly.find( B_Mask ) != map_poly.end() ) { @@ -611,8 +613,8 @@ void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningRepo } - if( m_boardAdapter.GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && - m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated + && m_boardAdapter.m_Cfg->m_Render.realistic ) { if( m_boardAdapter.GetFrontPlatedPadPolys() ) { @@ -652,8 +654,7 @@ void RENDER_3D_OPENGL::reload( REPORTER* aStatusReporter, REPORTER* aWarningRepo if( aStatusReporter ) { // Calculation time in seconds - const double calculation_time = (double)( GetRunningMicroSecs() - - stats_startReloadTime) / 1e6; + double calculation_time = (double)( GetRunningMicroSecs() - stats_startReloadTime) / 1e6; aStatusReporter->Report( wxString::Format( _( "Reload time %.3f s" ), calculation_time ) ); } @@ -674,10 +675,10 @@ void RENDER_3D_OPENGL::addTopAndBottomTriangles( TRIANGLE_DISPLAY_LIST* aDst, co } -void RENDER_3D_OPENGL::getLayerZPos( PCB_LAYER_ID aLayerID, float& aOutZtop, float& aOutZbot ) const +void RENDER_3D_OPENGL::getLayerZPos( PCB_LAYER_ID aLayer, float& aOutZtop, float& aOutZbot ) const { - aOutZbot = m_boardAdapter.GetLayerBottomZPos( aLayerID ); - aOutZtop = m_boardAdapter.GetLayerTopZPos( aLayerID ); + aOutZbot = m_boardAdapter.GetLayerBottomZPos( aLayer ); + aOutZtop = m_boardAdapter.GetLayerTopZPos( aLayer ); if( aOutZtop < aOutZbot ) { @@ -732,13 +733,11 @@ void RENDER_3D_OPENGL::generateViasAndPads() if( m_boardAdapter.GetViaCount() > 0 ) { - const unsigned int reserve_nr_triangles_estimation = - m_boardAdapter.GetCircleSegmentCount( - m_boardAdapter.GetAverageViaHoleDiameter() ) * 8 * - m_boardAdapter.GetViaCount(); + float averageDiameter = m_boardAdapter.GetAverageViaHoleDiameter(); + unsigned int averageSegCount = m_boardAdapter.GetCircleSegmentCount( averageDiameter ); + unsigned int trianglesEstimate = averageSegCount * 8 * m_boardAdapter.GetViaCount(); - TRIANGLE_DISPLAY_LIST* layerTriangleVIA = - new TRIANGLE_DISPLAY_LIST( reserve_nr_triangles_estimation ); + TRIANGLE_DISPLAY_LIST* layerTriangleVIA = new TRIANGLE_DISPLAY_LIST( trianglesEstimate ); // Insert plated vertical holes inside the board @@ -811,29 +810,27 @@ void RENDER_3D_OPENGL::generateViasAndPads() // Subtract the holes tht_outer_holes_poly.BooleanSubtract( tht_inner_holes_poly, SHAPE_POLY_SET::PM_FAST ); - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) tht_outer_holes_poly.BooleanSubtract( m_antiBoardPolys, SHAPE_POLY_SET::PM_FAST ); CONTAINER_2D holesContainer; ConvertPolygonToTriangles( tht_outer_holes_poly, holesContainer, - m_boardAdapter.BiuTo3dUnits(), - (const BOARD_ITEM &)*m_boardAdapter.GetBoard() ); + m_boardAdapter.BiuTo3dUnits(), *m_boardAdapter.GetBoard() ); - const LIST_OBJECT2D& listHolesObject2d = holesContainer.GetList(); + const LIST_OBJECT2D& holes2D = holesContainer.GetList(); - if( listHolesObject2d.size() > 0 ) + if( holes2D.size() > 0 ) { float layer_z_top, layer_z_bot, dummy; getLayerZPos( F_Cu, layer_z_top, dummy ); getLayerZPos( B_Cu, dummy, layer_z_bot ); - TRIANGLE_DISPLAY_LIST* layerTriangles = - new TRIANGLE_DISPLAY_LIST( listHolesObject2d.size() ); + TRIANGLE_DISPLAY_LIST* layerTriangles = new TRIANGLE_DISPLAY_LIST( holes2D.size() ); // Convert the list of objects(triangles) to triangle layer structure - for( const OBJECT_2D* itemOnLayer : listHolesObject2d ) + for( const OBJECT_2D* itemOnLayer : holes2D ) { const OBJECT_2D* object2d_A = itemOnLayer; @@ -889,9 +886,9 @@ void RENDER_3D_OPENGL::load3dModels( REPORTER* aStatusReporter ) if( !m_boardAdapter.GetBoard() ) return; - if( !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_NORMAL ) - && !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_NORMAL_INSERT ) - && !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_VIRTUAL ) ) + if( !m_boardAdapter.m_Cfg->m_Render.show_footprints_normal + && !m_boardAdapter.m_Cfg->m_Render.show_footprints_insert + && !m_boardAdapter.m_Cfg->m_Render.show_footprints_virtual ) { return; } @@ -899,35 +896,34 @@ void RENDER_3D_OPENGL::load3dModels( REPORTER* aStatusReporter ) // Go for all footprints for( const FOOTPRINT* footprint : m_boardAdapter.GetBoard()->Footprints() ) { - for( const FP_3DMODEL& model : footprint->Models() ) + for( const FP_3DMODEL& fp_model : footprint->Models() ) { - if( model.m_Show && !model.m_Filename.empty() ) + if( fp_model.m_Show && !fp_model.m_Filename.empty() ) { if( aStatusReporter ) { - // Display the short filename of the 3D model loaded: + // Display the short filename of the 3D fp_model loaded: // (the full name is usually too long to be displayed) - wxFileName fn( model.m_Filename ); + wxFileName fn( fp_model.m_Filename ); aStatusReporter->Report( wxString::Format( _( "Loading %s..." ), fn.GetFullName() ) ); } - // Check if the model is not present in our cache map + // Check if the fp_model is not present in our cache map // (Not already loaded in memory) - if( m_3dModelMap.find( model.m_Filename ) == m_3dModelMap.end() ) + if( m_3dModelMap.find( fp_model.m_Filename ) == m_3dModelMap.end() ) { // It is not present, try get it from cache const S3DMODEL* modelPtr = - m_boardAdapter.Get3dCacheManager()->GetModel( model.m_Filename ); + m_boardAdapter.Get3dCacheManager()->GetModel( fp_model.m_Filename ); // only add it if the return is not NULL if( modelPtr ) { - MATERIAL_MODE materialMode = m_boardAdapter.GetMaterialMode(); - MODEL_3D* ogl_model = new MODEL_3D( *modelPtr, materialMode ); + int materialMode = m_boardAdapter.m_Cfg->m_Render.material_mode; + MODEL_3D* model = new MODEL_3D( *modelPtr, (MATERIAL_MODE) materialMode ); - if( ogl_model ) - m_3dModelMap[ model.m_Filename ] = ogl_model; + m_3dModelMap[ fp_model.m_Filename ] = model; } } } diff --git a/3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp b/3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp index 3e81a7ee7c..3bc36468c3 100644 --- a/3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp +++ b/3d-viewer/3d_rendering/opengl/render_3d_opengl.cpp @@ -169,7 +169,7 @@ void RENDER_3D_OPENGL::setupMaterials() { m_materials = {}; - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) { // http://devernay.free.fr/cours/opengl/materials.html @@ -328,7 +328,7 @@ void RENDER_3D_OPENGL::setLayerMaterial( PCB_LAYER_ID aLayerID ) // Convert Opacity to Transparency m_materials.m_SolderMask.m_Transparency = 1.0f - layerColor.a; - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) { m_materials.m_SolderMask.m_Ambient = m_materials.m_SolderMask.m_Diffuse * 0.3f; @@ -395,7 +395,7 @@ SFVEC4F RENDER_3D_OPENGL::getLayerColor( PCB_LAYER_ID aLayerID ) { SFVEC4F layerColor = m_boardAdapter.GetLayerColor( aLayerID ); - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) { switch( aLayerID ) { @@ -563,16 +563,16 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, reload( aStatusReporter, aWarningReporter ); // generate a new 3D grid as the size of the board may had changed - m_lastGridType = m_boardAdapter.GetGridType(); + m_lastGridType = static_cast( m_boardAdapter.m_Cfg->m_Render.grid_type ); generate3dGrid( m_lastGridType ); } else { // Check if grid was changed - if( m_boardAdapter.GetGridType() != m_lastGridType ) + if( m_boardAdapter.m_Cfg->m_Render.grid_type != m_lastGridType ) { // and generate a new one - m_lastGridType = m_boardAdapter.GetGridType(); + m_lastGridType = static_cast( m_boardAdapter.m_Cfg->m_Render.grid_type ); generate3dGrid( m_lastGridType ); } } @@ -586,7 +586,7 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, glEnable( GL_NORMALIZE ); // This allow OpenGL to normalize the normals after transformations glViewport( 0, 0, m_windowSize.x, m_windowSize.y ); - if( m_boardAdapter.GetFlag( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE ) && aIsMoving ) + if( aIsMoving && m_boardAdapter.m_Cfg->m_Render.opengl_AA_disableOnMove ) glDisable( GL_MULTISAMPLE ); else glEnable( GL_MULTISAMPLE ); @@ -627,13 +627,9 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, float zpos; if( cameraPos.z > 0.0f ) - { zpos = glm::max( cameraPos.z, 0.5f ) + cameraPos.z * cameraPos.z; - } else - { zpos = glm::min( cameraPos.z,-0.5f ) - cameraPos.z * cameraPos.z; - } // This is a point light. const GLfloat headlight_pos[] = { cameraPos.x, cameraPos.y, zpos, 1.0f }; @@ -641,16 +637,13 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, glLightfv( GL_LIGHT0, GL_POSITION, headlight_pos ); } - const bool drawMiddleSegments = !( aIsMoving && - m_boardAdapter.GetFlag( FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE ) ); + bool skipThickness = aIsMoving && m_boardAdapter.m_Cfg->m_Render.opengl_thickness_disableOnMove; + bool skipRenderHoles = aIsMoving && m_boardAdapter.m_Cfg->m_Render.opengl_holes_disableOnMove; + bool skipRenderVias = aIsMoving && m_boardAdapter.m_Cfg->m_Render.opengl_vias_disableOnMove; - const bool skipRenderHoles = aIsMoving && - m_boardAdapter.GetFlag( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE ); + bool drawMiddleSegments = !skipThickness; - const bool skipRenderVias = aIsMoving && - m_boardAdapter.GetFlag( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE ); - - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) { // Draw vias and pad holes with copper material setLayerMaterial( B_Cu ); @@ -680,8 +673,8 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, // So avoid creating them is they are not very visible const double opacity_min = 0.8; - if( m_boardAdapter.GetFlag( FL_SHOW_BOARD_BODY ) && - ( m_boardAdapter.m_BoardBodyColor.a > opacity_min ) ) + if( m_boardAdapter.m_Cfg->m_Render.show_board_body + && m_boardAdapter.m_BoardBodyColor.a > opacity_min ) { if( ( layer_id > F_Cu ) && ( layer_id < B_Cu ) ) continue; @@ -693,21 +686,26 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, if( ( layer_id >= F_Cu ) && ( layer_id <= B_Cu ) ) { - if( !m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) || - !( m_boardAdapter.GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && - m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) ) - setLayerMaterial( layer_id ); - else + if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated + && m_boardAdapter.m_Cfg->m_Render.realistic ) + { setCopperMaterial(); + } + else + { + setLayerMaterial( layer_id ); + } if( skipRenderHoles ) { pLayerDispList->DrawAllCameraCulled( m_camera.GetPos().z, drawMiddleSegments ); // Draw copper plated pads - if( ( ( layer_id == F_Cu ) || ( layer_id == B_Cu ) ) && - ( m_platedPadsFront || m_platedPadsBack ) ) + if( ( layer_id == F_Cu || layer_id == B_Cu ) + && ( m_platedPadsFront || m_platedPadsBack ) ) + { setPlatedCopperAndDepthOffset( layer_id ); + } if( layer_id == F_Cu && m_platedPadsFront ) { @@ -814,33 +812,32 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, setLayerMaterial( layer_id ); OPENGL_RENDER_LIST* throughHolesOuter = - m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) - && m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) - && ( layer_id == B_SilkS || layer_id == F_SilkS ) - ? m_outerThroughHoleRings - : m_outerThroughHoles; + m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus + && m_boardAdapter.m_Cfg->m_Render.realistic + && ( layer_id == B_SilkS || layer_id == F_SilkS ) ? m_outerThroughHoleRings + : m_outerThroughHoles; if( throughHolesOuter ) { - throughHolesOuter->ApplyScalePosition( - pLayerDispList->GetZBot(), - pLayerDispList->GetZTop() - pLayerDispList->GetZBot() ); + throughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(), + pLayerDispList->GetZTop() + - pLayerDispList->GetZBot() ); } OPENGL_RENDER_LIST* anti_board = m_antiBoard; if( anti_board ) { - anti_board->ApplyScalePosition( - pLayerDispList->GetZBot(), - pLayerDispList->GetZTop() - pLayerDispList->GetZBot() ); + anti_board->ApplyScalePosition( pLayerDispList->GetZBot(), + pLayerDispList->GetZTop() + - pLayerDispList->GetZBot() ); } if( !skipRenderHoles - && m_boardAdapter.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) - && m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) - && ( ( layer_id == B_SilkS && m_layers.find( B_Mask ) != m_layers.end() ) - || ( layer_id == F_SilkS && m_layers.find( F_Mask ) != m_layers.end() ) ) ) + && m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk + && m_boardAdapter.m_Cfg->m_Render.realistic + && ( ( layer_id == B_SilkS && m_layers.find( B_Mask ) != m_layers.end() ) + || ( layer_id == F_SilkS && m_layers.find( F_Mask ) != m_layers.end() ) ) ) { const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS) ? B_Mask : F_Mask; @@ -880,13 +877,11 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, render3dModels( true, false ); // Display board body - if( m_boardAdapter.GetFlag( FL_SHOW_BOARD_BODY ) ) - { + if( m_boardAdapter.m_Cfg->m_Render.show_board_body ) renderBoardBody( skipRenderHoles ); - } // Display transparent mask layers - if( m_boardAdapter.GetFlag( FL_SOLDERMASK ) ) + if( m_boardAdapter.m_Cfg->m_Render.show_soldermask ) { // add a depth buffer offset, it will help to hide some artifacts // on silkscreen where the SolderMask is removed @@ -949,7 +944,7 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, glDepthMask( GL_TRUE ); // Render Grid - if( m_boardAdapter.GetGridType() != GRID3D_TYPE::NONE ) + if( m_boardAdapter.m_Cfg->m_Render.grid_type != GRID3D_TYPE::NONE ) { glDisable( GL_LIGHTING ); @@ -960,7 +955,7 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter, } // Render 3D arrows - if( m_boardAdapter.GetFlag( FL_AXIS ) ) + if( m_boardAdapter.m_Cfg->m_Render.show_axis ) render3dArrows(); // Return back to the original viewport (this is important if we want @@ -1186,12 +1181,12 @@ void RENDER_3D_OPENGL::render3dModelsSelected( bool aRenderTopOrBot, bool aRende { bool highlight = false; - if( m_boardAdapter.GetFlag( FL_USE_SELECTION ) ) + if( m_boardAdapter.m_IsBoardView ) { if( fp->IsSelected() ) highlight = true; - if( m_boardAdapter.GetFlag( FL_HIGHLIGHT_ROLLOVER_ITEM ) && fp == m_currentRollOverItem ) + if( m_boardAdapter.m_Cfg->m_Render.opengl_highlight_on_rollover ) highlight = true; if( aRenderSelectedOnly != highlight ) @@ -1214,7 +1209,7 @@ void RENDER_3D_OPENGL::render3dModelsSelected( bool aRenderTopOrBot, bool aRende void RENDER_3D_OPENGL::render3dModels( bool aRenderTopOrBot, bool aRenderTransparentOnly ) { - if( m_boardAdapter.GetFlag( FL_USE_SELECTION ) ) + if( m_boardAdapter.m_IsBoardView ) render3dModelsSelected( aRenderTopOrBot, aRenderTransparentOnly, true ); render3dModelsSelected( aRenderTopOrBot, aRenderTransparentOnly, false ); @@ -1227,6 +1222,8 @@ void RENDER_3D_OPENGL::renderFootprint( const FOOTPRINT* aFootprint, bool aRende if( !aFootprint->Models().empty() ) { const double zpos = m_boardAdapter.GetFootprintZPos( aFootprint->IsFlipped() ); + SFVEC3F selColor = m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.opengl_selection_color ); + glPushMatrix(); @@ -1287,15 +1284,14 @@ void RENDER_3D_OPENGL::renderFootprint( const FOOTPRINT* aFootprint, bool aRende { modelPtr->DrawTransparent( sM.m_Opacity, aFootprint->IsSelected() || aIsSelected, - m_boardAdapter.m_OpenGlSelectionColor ); + selColor ); } else { - modelPtr->DrawOpaque( aFootprint->IsSelected() || aIsSelected, - m_boardAdapter.m_OpenGlSelectionColor ); + modelPtr->DrawOpaque( aFootprint->IsSelected() || aIsSelected, selColor ); } - if( m_boardAdapter.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) ) + if( m_boardAdapter.m_Cfg->m_Render.opengl_show_model_bbox ) { glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); diff --git a/3d-viewer/3d_rendering/raytracing/create_scene.cpp b/3d-viewer/3d_rendering/raytracing/create_scene.cpp index e26ef4a9cd..128b3ce4e2 100644 --- a/3d-viewer/3d_rendering/raytracing/create_scene.cpp +++ b/3d-viewer/3d_rendering/raytracing/create_scene.cpp @@ -70,30 +70,23 @@ static float TransparencyControl( float aGrayColorValue, float aTransparency ) void RENDER_3D_RAYTRACE::setupMaterials() { - MATERIAL::SetDefaultRefractionRayCount( m_boardAdapter.m_RtRefractionSampleCount ); - MATERIAL::SetDefaultReflectionRayCount( m_boardAdapter.m_RtReflectionSampleCount ); + MATERIAL::SetDefaultRefractionRayCount( m_boardAdapter.m_Cfg->m_Render.raytrace_nrsamples_refractions ); + MATERIAL::SetDefaultReflectionRayCount( m_boardAdapter.m_Cfg->m_Render.raytrace_nrsamples_reflections ); - MATERIAL::SetDefaultRefractionRecursionCount( m_boardAdapter.m_RtRecursiveRefractionCount ); - MATERIAL::SetDefaultReflectionRecursionCount( m_boardAdapter.m_RtRecursiveReflectionCount ); + MATERIAL::SetDefaultRefractionRecursionCount( m_boardAdapter.m_Cfg->m_Render.raytrace_recursivelevel_refractions ); + MATERIAL::SetDefaultReflectionRecursionCount( m_boardAdapter.m_Cfg->m_Render.raytrace_recursivelevel_reflections ); double mmTo3Dunits = IU_PER_MM * m_boardAdapter.BiuTo3dUnits(); - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures ) { m_boardMaterial = BOARD_NORMAL( 0.40f * mmTo3Dunits ); - m_copperMaterial = COPPER_NORMAL( 4.0f * mmTo3Dunits, &m_boardMaterial ); - m_platedCopperMaterial = PLATED_COPPER_NORMAL( 0.5f * mmTo3Dunits ); - m_solderMaskMaterial = SOLDER_MASK_NORMAL( &m_boardMaterial ); - m_plasticMaterial = PLASTIC_NORMAL( 0.05f * mmTo3Dunits ); - m_shinyPlasticMaterial = PLASTIC_SHINE_NORMAL( 0.1f * mmTo3Dunits ); - m_brushedMetalMaterial = BRUSHED_METAL_NORMAL( 0.05f * mmTo3Dunits ); - m_silkScreenMaterial = SILK_SCREEN_NORMAL( 0.25f * mmTo3Dunits ); } @@ -107,14 +100,14 @@ void RENDER_3D_RAYTRACE::setupMaterials() ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_CopperColor * 0.3f ), SFVEC3F( 0.0f ), copperSpecularLinear, 0.4f * 128.0f, 0.0f, 0.0f ); - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures ) m_materials.m_Copper.SetGenerator( &m_platedCopperMaterial ); m_materials.m_NonPlatedCopper = BLINN_PHONG_MATERIAL( ConvertSRGBToLinear( SFVEC3F( 0.191f, 0.073f, 0.022f ) ), SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.256f, 0.137f, 0.086f ), 0.15f * 128.0f, 0.0f, 0.0f ); - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures ) m_materials.m_NonPlatedCopper.SetGenerator( &m_copperMaterial ); m_materials.m_Paste = BLINN_PHONG_MATERIAL( @@ -132,7 +125,7 @@ void RENDER_3D_RAYTRACE::setupMaterials() (SFVEC3F) m_boardAdapter.m_SilkScreenColorTop ) ), SFVEC3F( 0.0f ), SFVEC3F( 0.10f ) ), 0.078125f * 128.0f, 0.0f, 0.0f ); - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures ) m_materials.m_SilkS.SetGenerator( &m_silkScreenMaterial ); // Assume that SolderMaskTop == SolderMaskBot @@ -153,7 +146,7 @@ void RENDER_3D_RAYTRACE::setupMaterials() m_materials.m_SolderMask.SetCastShadows( true ); m_materials.m_SolderMask.SetRefractionRayCount( 1 ); - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures ) m_materials.m_SolderMask.SetGenerator( &m_solderMaskMaterial ); m_materials.m_EpoxyBoard = @@ -166,7 +159,7 @@ void RENDER_3D_RAYTRACE::setupMaterials() m_materials.m_EpoxyBoard.SetAbsorvance( 10.0f ); - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures ) m_materials.m_EpoxyBoard.SetGenerator( &m_boardMaterial ); SFVEC3F bgTop = ConvertSRGBToLinear( (SFVEC3F) m_boardAdapter.m_BgColorTop ); @@ -278,11 +271,11 @@ void RENDER_3D_RAYTRACE::createItemsFromContainer( const BVH_CONTAINER_2D* aCont // layer and the flag is set, then clip the silk at the outer edge of the annular ring, // rather than the at the outer edge of the copper plating. const BVH_CONTAINER_2D& throughHoleOuter = - ( m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) - && m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) - && ( ( aLayer_id == B_SilkS ) || ( aLayer_id == F_SilkS ) ) ) ? - m_boardAdapter.GetThroughHoleAnnularRings() : - m_boardAdapter.GetThroughHoleOds(); + m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus + && m_boardAdapter.m_Cfg->m_Render.realistic + && ( aLayer_id == B_SilkS || aLayer_id == F_SilkS ) ? + m_boardAdapter.GetThroughHoleAnnularRings() : + m_boardAdapter.GetThroughHoleOds(); if( !throughHoleOuter.GetList().empty() ) { @@ -308,8 +301,8 @@ void RENDER_3D_RAYTRACE::createItemsFromContainer( const BVH_CONTAINER_2D* aCont const MAP_CONTAINER_2D_BASE& mapLayers = m_boardAdapter.GetLayerMap(); - if( m_boardAdapter.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) - && m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) + if( m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk + && m_boardAdapter.m_Cfg->m_Render.realistic && ( ( aLayer_id == B_SilkS && mapLayers.find( B_Mask ) != mapLayers.end() ) || ( aLayer_id == F_SilkS && mapLayers.find( F_Mask ) != mapLayers.end() ) ) ) { @@ -439,7 +432,7 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe *m_boardAdapter.GetBoard(), ii ); } - if( m_boardAdapter.GetFlag( FL_SHOW_BOARD_BODY ) ) + if( m_boardAdapter.m_Cfg->m_Render.show_board_body ) { const LIST_OBJECT2D& listObjects = m_outlineBoard2dObjects->GetList(); @@ -592,7 +585,7 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe case F_Paste: materialLayer = &m_materials.m_Paste; - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) layerColor = m_boardAdapter.m_SolderPasteColor; else layerColor = m_boardAdapter.GetLayerColor( layer_id ); @@ -602,7 +595,7 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe case B_SilkS: materialLayer = &m_materials.m_SilkS; - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) layerColor = m_boardAdapter.m_SilkScreenColorBot; else layerColor = m_boardAdapter.GetLayerColor( layer_id ); @@ -612,7 +605,7 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe case F_SilkS: materialLayer = &m_materials.m_SilkS; - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) layerColor = m_boardAdapter.m_SilkScreenColorTop; else layerColor = m_boardAdapter.GetLayerColor( layer_id ); @@ -636,9 +629,9 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe break; default: - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) { - if( m_boardAdapter.GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) ) + if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated ) layerColor = SFVEC3F( 184.0f / 255.0f, 115.0f / 255.0f, 50.0f / 255.0f ); else layerColor = m_boardAdapter.m_CopperColor; @@ -656,8 +649,8 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe } // for each layer on map // Create plated copper - if( m_boardAdapter.GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) - && m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated + && m_boardAdapter.m_Cfg->m_Render.realistic ) { createItemsFromContainer( m_boardAdapter.GetPlatedPadsFront(), F_Cu, &m_materials.m_Copper, m_boardAdapter.m_CopperColor, @@ -674,7 +667,8 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe // Solder mask layers are "negative" layers so the elements that we have in the container // should remove the board outline. We will check for all objects in the outline if it // intersects any object in the layer container and also any hole. - if( m_boardAdapter.GetFlag( FL_SOLDERMASK ) && !m_outlineBoard2dObjects->GetList().empty() ) + if( m_boardAdapter.m_Cfg->m_Render.show_soldermask + && !m_outlineBoard2dObjects->GetList().empty() ) { const MATERIAL* materialLayer = &m_materials.m_SolderMask; @@ -693,7 +687,7 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe SFVEC3F layerColor; - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) { if( layer_id == B_Mask ) layerColor = m_boardAdapter.m_SolderMaskColorBot; @@ -798,7 +792,7 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe if( !aOnlyLoadCopperAndShapes ) { // Add floor - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_BACKFLOOR ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_backfloor ) { BBOX_3D boardBBox = m_boardAdapter.GetBBox(); @@ -878,41 +872,47 @@ void RENDER_3D_RAYTRACE::Reload( REPORTER* aStatusReporter, REPORTER* aWarningRe && ( aSource.b < ( 1.0f / 255.0f ) ) ); }; - m_cameraLight = new DIRECTIONAL_LIGHT( SFVEC3F( 0.0f, 0.0f, 0.0f ), - m_boardAdapter.m_RtCameraLightColor ); + SFVEC3F cameraLightColor = + m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorCamera ); + SFVEC3F topLightColor = + m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorTop ); + SFVEC3F bottomLightColor = + m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColorBottom ); + + m_cameraLight = new DIRECTIONAL_LIGHT( SFVEC3F( 0.0f, 0.0f, 0.0f ), cameraLightColor ); m_cameraLight->SetCastShadows( false ); - if( !IsColorZero( m_boardAdapter.m_RtCameraLightColor ) ) + if( !IsColorZero( cameraLightColor ) ) m_lights.push_back( m_cameraLight ); const SFVEC3F& boardCenter = m_boardAdapter.GetBBox().GetCenter(); - if( !IsColorZero( m_boardAdapter.m_RtLightColorTop ) ) + if( !IsColorZero( topLightColor ) ) { m_lights.push_back( new POINT_LIGHT( SFVEC3F( boardCenter.x, boardCenter.y, +RANGE_SCALE_3D * 2.0f ), - m_boardAdapter.m_RtLightColorTop ) ); + topLightColor ) ); } - if( !IsColorZero( m_boardAdapter.m_RtLightColorBottom ) ) + if( !IsColorZero( bottomLightColor ) ) { m_lights.push_back( new POINT_LIGHT( SFVEC3F( boardCenter.x, boardCenter.y, -RANGE_SCALE_3D * 2.0f ), - m_boardAdapter.m_RtLightColorBottom ) ); + bottomLightColor ) ); } - wxASSERT( m_boardAdapter.m_RtLightColor.size() - == m_boardAdapter.m_RtLightSphericalCoords.size() ); - - for( size_t i = 0; i < m_boardAdapter.m_RtLightColor.size(); ++i ) + for( size_t i = 0; i < m_boardAdapter.m_Cfg->m_Render.raytrace_lightColor.size(); ++i ) { - if( !IsColorZero( m_boardAdapter.m_RtLightColor[i] ) ) + SFVEC3F lightColor = + m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.raytrace_lightColor[i] ); + + if( !IsColorZero( lightColor ) ) { - const SFVEC2F sc = m_boardAdapter.m_RtLightSphericalCoords[i]; + const SFVEC2F sc = m_boardAdapter.GetSphericalCoord( i ); m_lights.push_back( new DIRECTIONAL_LIGHT( SphericalToCartesian( glm::pi() * sc.x, glm::pi() * sc.y ), - m_boardAdapter.m_RtLightColor[i] ) ); + lightColor ) ); } } } @@ -970,7 +970,7 @@ void RENDER_3D_RAYTRACE::insertHole( const PCB_VIA* aVia ) objPtr->SetMaterial( &m_materials.m_Copper ); - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.m_CopperColor ) ); else if( aVia->GetViaType() == VIATYPE::MICROVIA ) objPtr->SetColor( ConvertSRGBToLinear( m_boardAdapter.GetItemColor( LAYER_VIA_MICROVIA ) ) ); @@ -989,7 +989,7 @@ void RENDER_3D_RAYTRACE::insertHole( const PAD* aPad ) SFVEC3F objColor; - if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) + if( m_boardAdapter.m_Cfg->m_Render.realistic ) objColor = m_boardAdapter.m_CopperColor; else objColor = m_boardAdapter.GetItemColor( LAYER_PADS_TH ); @@ -1195,9 +1195,9 @@ void RENDER_3D_RAYTRACE::load3DModels( CONTAINER_3D& aDstContainer, bool aSkipMa if( !m_boardAdapter.GetBoard() ) return; - if( !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_NORMAL ) - && !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_NORMAL_INSERT ) - && !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_VIRTUAL ) ) + if( !m_boardAdapter.m_Cfg->m_Render.show_footprints_normal + && !m_boardAdapter.m_Cfg->m_Render.show_footprints_insert + && !m_boardAdapter.m_Cfg->m_Render.show_footprints_virtual ) { return; } @@ -1312,7 +1312,7 @@ MODEL_MATERIALS* RENDER_3D_RAYTRACE::getModelMaterial( const S3DMODEL* a3DModel for( unsigned int imat = 0; imat < a3DModel->m_MaterialsSize; ++imat ) { - if( m_boardAdapter.GetMaterialMode() == MATERIAL_MODE::NORMAL ) + if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::NORMAL ) { const SMATERIAL& material = a3DModel->m_Materials[imat]; @@ -1334,7 +1334,7 @@ MODEL_MATERIALS* RENDER_3D_RAYTRACE::getModelMaterial( const S3DMODEL* a3DModel ConvertSRGBToLinear( material.m_Specular ), material.m_Shininess * 180.0f, material.m_Transparency, reflectionFactor ); - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_procedural_textures ) { // Guess material type and apply a normal perturbator if( ( RGBtoGray( material.m_Diffuse ) < 0.3f ) @@ -1502,7 +1502,7 @@ void RENDER_3D_RAYTRACE::addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* const SFVEC3F diffuseColor = a3DModel->m_Materials[mesh.m_MaterialIdx].m_Diffuse; - if( m_boardAdapter.GetMaterialMode() == MATERIAL_MODE::CAD_MODE ) + if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::CAD_MODE ) newTriangle->SetColor( ConvertSRGBToLinear( MaterialDiffuseToColorCAD( diffuseColor ) ) ); else @@ -1510,7 +1510,8 @@ void RENDER_3D_RAYTRACE::addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* } else { - if( m_boardAdapter.GetMaterialMode() == MATERIAL_MODE::CAD_MODE ) + if( m_boardAdapter.m_Cfg->m_Render.material_mode == MATERIAL_MODE::CAD_MODE ) + { newTriangle->SetColor( ConvertSRGBToLinear( MaterialDiffuseToColorCAD( mesh.m_Color[idx0] ) ), @@ -1518,11 +1519,14 @@ void RENDER_3D_RAYTRACE::addModels( CONTAINER_3D& aDstContainer, const S3DMODEL* mesh.m_Color[idx1] ) ), ConvertSRGBToLinear( MaterialDiffuseToColorCAD( mesh.m_Color[idx2] ) ) ); + } else + { newTriangle->SetColor( ConvertSRGBToLinear( mesh.m_Color[idx0] ), ConvertSRGBToLinear( mesh.m_Color[idx1] ), ConvertSRGBToLinear( mesh.m_Color[idx2] ) ); + } } } } diff --git a/3d-viewer/3d_rendering/raytracing/render_3d_raytrace.cpp b/3d-viewer/3d_rendering/raytracing/render_3d_raytrace.cpp index b3a8143675..b139e84b40 100644 --- a/3d-viewer/3d_rendering/raytracing/render_3d_raytrace.cpp +++ b/3d-viewer/3d_rendering/raytracing/render_3d_raytrace.cpp @@ -293,7 +293,7 @@ void RENDER_3D_RAYTRACE::render( GLubyte* ptrPBO, REPORTER* aStatusReporter ) if( m_cameraLight ) m_cameraLight->SetDirection( -m_camera.GetDir() ); - if( m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { // Set all pixels of PBO transparent (Alpha to 0) // This way it will draw the full buffer but only shows the updated ( @@ -399,7 +399,7 @@ void RENDER_3D_RAYTRACE::renderTracing( GLubyte* ptrPBO, REPORTER* aStatusReport // or mark it as finished if( m_blockRenderProgressCount >= m_blockPositions.size() ) { - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_post_processing ) m_renderState = RT_RENDER_STATE_POST_PROCESS_SHADE; else m_renderState = RT_RENDER_STATE_FINISH; @@ -504,7 +504,7 @@ void RENDER_3D_RAYTRACE::renderAntiAliasPackets( const SFVEC3F* aBgColorY, const HITINFO_PACKET* aHitPck_AA_X1Y1, const RAY* aRayPck, SFVEC3F* aOutHitColor ) { - const bool is_testShadow = m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_SHADOWS ); + const bool is_testShadow = m_boardAdapter.m_Cfg->m_Render.raytrace_shadows; for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y ) { @@ -652,7 +652,7 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock if( !m_accelerator->Intersect( blockPacket, hitPacket_X0Y0 ) ) { // If block is empty then set shades and continue - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_post_processing ) { for( unsigned int y = 0; y < RAYPACKET_DIM; ++y ) { @@ -670,10 +670,9 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock } // This will set the output color to be displayed - // If post processing is enabled, it will not reflect the final result - // (as the final color will be computed on post processing) - // but it is used for report progress - const bool isFinalColor = !m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ); + // If post processing is enabled, it will not reflect the final result (as the final + // color will be computed on post processing) but it is used for report progress + const bool isFinalColor = !m_boardAdapter.m_Cfg->m_Render.raytrace_post_processing; for( unsigned int y = 0; y < RAYPACKET_DIM; ++y ) { @@ -698,9 +697,9 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock // Shade original (0, 0) hits ("paint" the intersected objects) renderRayPackets( bgColor, blockPacket.m_ray, hitPacket_X0Y0, - m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_SHADOWS ), hitColor_X0Y0 ); + m_boardAdapter.m_Cfg->m_Render.raytrace_shadows, hitColor_X0Y0 ); - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_anti_aliasing ) { SFVEC3F hitColor_AA_X1Y1[RAYPACKET_RAYS_PER_PACKET]; @@ -719,16 +718,13 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock const SFVEC3F& outColor = bgColor[y]; for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i ) - { hitColor_AA_X1Y1[i] = outColor; - } } } else { renderRayPackets( bgColor, blockPacket_AA_X1Y1.m_ray, hitPacket_AA_X1Y1, - m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_SHADOWS ), - hitColor_AA_X1Y1 ); + m_boardAdapter.m_Cfg->m_Render.raytrace_shadows, hitColor_AA_X1Y1 ); } SFVEC3F hitColor_AA_X1Y0[RAYPACKET_RAYS_PER_PACKET]; @@ -737,8 +733,7 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock for( unsigned int i = 0; i < RAYPACKET_RAYS_PER_PACKET; ++i ) { - const SFVEC3F color_average = ( hitColor_X0Y0[i] + - hitColor_AA_X1Y1[i] ) * SFVEC3F( 0.5f ); + SFVEC3F color_average = ( hitColor_X0Y0[i] + hitColor_AA_X1Y1[i] ) * SFVEC3F( 0.5f ); hitColor_AA_X1Y0[i] = color_average; hitColor_AA_X0Y1[i] = color_average; @@ -784,7 +779,7 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock const uint32_t ptrInc = ( m_realBufferSize.x - RAYPACKET_DIM ) * 4; - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_post_processing ) { SFVEC2I bPos; bPos.y = blockPos.y; @@ -798,6 +793,7 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock const SFVEC3F& hColor = hitColor_X0Y0[i]; if( hitPacket_X0Y0[i].m_hitresult == true ) + { m_postShaderSsao.SetPixelData( bPos.x, bPos.y, hitPacket_X0Y0[i].m_HitInfo.m_HitNormal, hColor, @@ -805,9 +801,12 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock hitPacket_X0Y0[i].m_HitInfo.m_tHit ), hitPacket_X0Y0[i].m_HitInfo.m_tHit, hitPacket_X0Y0[i].m_HitInfo.m_ShadowFactor ); + } else + { m_postShaderSsao.SetPixelData( bPos.x, bPos.y, SFVEC3F( 0.0f ), hColor, SFVEC3F( 0.0f ), 0, 1.0f ); + } renderFinalColor( ptr, hColor, false ); @@ -837,13 +836,12 @@ void RENDER_3D_RAYTRACE::renderBlockTracing( GLubyte* ptrPBO, signed int iBlock void RENDER_3D_RAYTRACE::postProcessShading( GLubyte* /* ptrPBO */, REPORTER* aStatusReporter ) { - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_post_processing ) { if( aStatusReporter ) aStatusReporter->Report( _( "Rendering: Post processing shader" ) ); - m_postShaderSsao.SetShadowsEnabled( - m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_SHADOWS ) ); + m_postShaderSsao.SetShadowsEnabled( m_boardAdapter.m_Cfg->m_Render.raytrace_shadows ); std::atomic nextBlock( 0 ); std::atomic threadsFinished( 0 ); @@ -890,7 +888,7 @@ void RENDER_3D_RAYTRACE::postProcessShading( GLubyte* /* ptrPBO */, REPORTER* aS void RENDER_3D_RAYTRACE::postProcessBlurFinish( GLubyte* ptrPBO, REPORTER* /* aStatusReporter */ ) { - if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) ) + if( m_boardAdapter.m_Cfg->m_Render.raytrace_post_processing ) { // Now blurs the shader result and compute the final color std::atomic nextBlock( 0 ); @@ -1560,8 +1558,7 @@ SFVEC3F RENDER_3D_RAYTRACE::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, const SFVEC3F diffuseColorObj = aHitInfo.pHitObject->GetDiffuseColor( aHitInfo ); #if USE_EXPERIMENTAL_SOFT_SHADOWS - const bool is_aa_enabled = m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) && - (!m_isPreview); + bool is_aa_enabled = m_boardAdapter.m_Cfg->m_Render.raytrace_anti_aliasing && !m_isPreview; #endif float shadow_att_factor_sum = 0.0f; @@ -1607,9 +1604,8 @@ SFVEC3F RENDER_3D_RAYTRACE::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, } else // Experimental softshadow calculation { - const unsigned int shadow_number_of_samples = - m_boardAdapter.m_RtShadowSampleCount; + m_boardAdapter.m_Cfg->m_Render.raytrace_nrsamples_shadows; const float shadow_inc_factor = 1.0f / (float) ( shadow_number_of_samples ); for( unsigned int i = 0; i < shadow_number_of_samples; ++i ) @@ -1625,7 +1621,7 @@ SFVEC3F RENDER_3D_RAYTRACE::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, const SFVEC3F unifVector = UniformRandomHemisphereDirection(); const SFVEC3F disturbed_vector_to_light = glm::normalize( vectorToLight + unifVector * - m_boardAdapter.m_RtSpreadShadows ); + m_boardAdapter.m_Cfg->m_Render.raytrace_spread_shadows ); rayToLight.Init( hitPoint, disturbed_vector_to_light ); } @@ -1670,7 +1666,7 @@ SFVEC3F RENDER_3D_RAYTRACE::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, { // Reflections if( ( objMaterial->GetReflection() > 0.0f ) - && m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_REFLECTIONS ) + && m_boardAdapter.m_Cfg->m_Render.raytrace_reflections && ( aRecursiveLevel < objMaterial->GetReflectionRecursionCount() ) ) { const unsigned int reflection_number_of_samples = @@ -1695,7 +1691,7 @@ SFVEC3F RENDER_3D_RAYTRACE::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, const SFVEC3F random_reflectVector = glm::normalize( reflectVector + UniformRandomHemisphereDirection() * - m_boardAdapter.m_RtSpreadReflections ); + m_boardAdapter.m_Cfg->m_Render.raytrace_spread_reflections ); reflectedRay.Init( hitPoint, random_reflectVector ); } @@ -1721,7 +1717,7 @@ SFVEC3F RENDER_3D_RAYTRACE::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, // Refraction const float objTransparency = aHitInfo.pHitObject->GetModelTransparency(); - if( ( objTransparency > 0.0f ) && m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_REFRACTIONS ) + if( ( objTransparency > 0.0f ) && m_boardAdapter.m_Cfg->m_Render.raytrace_refractions && ( aRecursiveLevel < objMaterial->GetRefractionRecursionCount() ) ) { const float airIndex = 1.000293f; @@ -1760,7 +1756,7 @@ SFVEC3F RENDER_3D_RAYTRACE::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, const SFVEC3F randomizeRefractedVector = glm::normalize( refractedVector + UniformRandomHemisphereDirection() * - m_boardAdapter.m_RtSpreadRefractions ); + m_boardAdapter.m_Cfg->m_Render.raytrace_spread_refractions ); refractedRay.Init( startPoint, randomizeRefractedVector ); } diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp index 8bfb453d48..86d1bea672 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp @@ -101,20 +101,19 @@ EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY *aKiway, PCB_BASE_FRAME *aParent wxStatusBar *status_bar = CreateStatusBar( arrayDim( status_dims ) ); SetStatusWidths( arrayDim( status_dims ), status_dims ); - m_canvas = new EDA_3D_CANVAS( this, - OGL_ATT_LIST::GetAttributesList( m_boardAdapter.GetAntiAliasingMode() ), - m_boardAdapter, m_currentCamera, - Prj().Get3DCacheManager() ); + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + EDA_3D_VIEWER_SETTINGS* cfg = mgr.GetAppSettings(); + ANTIALIASING_MODE aaMode = static_cast( cfg->m_Render.opengl_AA_mode ); - auto config = Pgm().GetSettingsManager().GetAppSettings(); - LoadSettings( config ); + m_canvas = new EDA_3D_CANVAS( this, OGL_ATT_LIST::GetAttributesList( aaMode ), + m_boardAdapter, m_currentCamera, Prj().Get3DCacheManager() ); - // Some settings need the canvas + LoadSettings( cfg ); loadCommonSettings(); // Create the manager m_toolManager = new TOOL_MANAGER; - m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr, config, this ); + m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr, cfg, this ); m_actions = new EDA_3D_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager ); @@ -128,7 +127,7 @@ EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY *aKiway, PCB_BASE_FRAME *aParent setupUIConditions(); if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool() ) - ctrlTool->SetRotationIncrement( config->m_Camera.rotation_increment ); + ctrlTool->SetRotationIncrement( cfg->m_Camera.rotation_increment ); // Run the viewer control tool, it is supposed to be always active m_toolManager->InvokeTool( "3DViewer.Control" ); @@ -182,39 +181,59 @@ void EDA_3D_VIEWER_FRAME::setupUIConditions() EDA_3D_CONDITIONS cond( &m_boardAdapter ); // Helper to define check conditions -#define FlagCheck( x ) ACTION_CONDITIONS().Check( cond.Flag( x ) ) #define GridSizeCheck( x ) ACTION_CONDITIONS().Check( cond.GridSize( x ) ) - auto raytracingCondition = + auto raytracing = [this]( const SELECTION& aSel ) { - return m_boardAdapter.GetRenderEngine() != RENDER_ENGINE::OPENGL; + return m_boardAdapter.m_Cfg->m_Render.engine != RENDER_ENGINE::OPENGL; + }; + auto showTH = + [this]( const SELECTION& aSel ) + { + return m_boardAdapter.m_Cfg->m_Render.show_footprints_normal; + }; + auto showSMD = + [this]( const SELECTION& aSel ) + { + return m_boardAdapter.m_Cfg->m_Render.show_footprints_insert; + }; + auto showVirtual = + [this]( const SELECTION& aSel ) + { + return m_boardAdapter.m_Cfg->m_Render.show_footprints_virtual; + }; + auto showBBoxes = + [this]( const SELECTION& aSel ) + { + return m_boardAdapter.m_Cfg->m_Render.opengl_show_model_bbox; + }; + auto showAxes = + [this]( const SELECTION& aSel ) + { + return m_boardAdapter.m_Cfg->m_Render.show_axis; + }; + auto ortho = + [this]( const SELECTION& ) + { + return m_currentCamera.GetProjection() == PROJECTION_TYPE::ORTHO; }; - RegisterUIUpdateHandler( ID_RENDER_CURRENT_VIEW, - ACTION_CONDITIONS().Check( raytracingCondition ) ); + RegisterUIUpdateHandler( ID_RENDER_CURRENT_VIEW, ACTION_CONDITIONS().Check( raytracing ) ); - mgr->SetConditions( EDA_3D_ACTIONS::showTHT, FlagCheck( FL_FP_ATTRIBUTES_NORMAL ) ); - mgr->SetConditions( EDA_3D_ACTIONS::showSMD, FlagCheck( FL_FP_ATTRIBUTES_NORMAL_INSERT ) ); - mgr->SetConditions( EDA_3D_ACTIONS::showVirtual, FlagCheck( FL_FP_ATTRIBUTES_VIRTUAL ) ); + mgr->SetConditions( EDA_3D_ACTIONS::showTHT, ACTION_CONDITIONS().Check( showTH ) ); + mgr->SetConditions( EDA_3D_ACTIONS::showSMD, ACTION_CONDITIONS().Check( showSMD ) ); + mgr->SetConditions( EDA_3D_ACTIONS::showVirtual, ACTION_CONDITIONS().Check( showVirtual ) ); - mgr->SetConditions( EDA_3D_ACTIONS::showBBoxes, FlagCheck( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) ); - mgr->SetConditions( EDA_3D_ACTIONS::showAxis, FlagCheck( FL_AXIS ) ); + mgr->SetConditions( EDA_3D_ACTIONS::showBBoxes, ACTION_CONDITIONS().Check( showBBoxes ) ); + mgr->SetConditions( EDA_3D_ACTIONS::showAxis, ACTION_CONDITIONS().Check( showAxes ) ); mgr->SetConditions( EDA_3D_ACTIONS::noGrid, GridSizeCheck( GRID3D_TYPE::NONE ) ); mgr->SetConditions( EDA_3D_ACTIONS::show10mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_10MM ) ); mgr->SetConditions( EDA_3D_ACTIONS::show5mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_5MM ) ); mgr->SetConditions( EDA_3D_ACTIONS::show2_5mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_2P5MM ) ); mgr->SetConditions( EDA_3D_ACTIONS::show1mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_1MM ) ); - - - auto orthoCondition = - [this]( const SELECTION& ) - { - return m_currentCamera.GetProjection() == PROJECTION_TYPE::ORTHO; - }; - - mgr->SetConditions( EDA_3D_ACTIONS::toggleOrtho, ACTION_CONDITIONS().Check( orthoCondition ) ); + mgr->SetConditions( EDA_3D_ACTIONS::toggleOrtho, ACTION_CONDITIONS().Check( ortho ) ); #undef FlagCheck #undef GridSizeCheck @@ -243,14 +262,14 @@ void EDA_3D_VIEWER_FRAME::NewDisplay( bool aForceImmediateRedraw ) void EDA_3D_VIEWER_FRAME::Redraw() { // Only update in OpenGL for an interactive interaction - if( m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) m_canvas->Request_refresh( true ); } void EDA_3D_VIEWER_FRAME::refreshRender() { - if( m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) m_canvas->Request_refresh(); else NewDisplay( true ); @@ -327,18 +346,18 @@ void EDA_3D_VIEWER_FRAME::Process_Special_Functions( wxCommandEvent &event ) void EDA_3D_VIEWER_FRAME::OnRenderEngineSelection( wxCommandEvent &event ) { - const RENDER_ENGINE old_engine = m_boardAdapter.GetRenderEngine(); + int old_engine = m_boardAdapter.m_Cfg->m_Render.engine; if( old_engine == RENDER_ENGINE::OPENGL ) - m_boardAdapter.SetRenderEngine( RENDER_ENGINE::RAYTRACING ); + m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::RAYTRACING; else - m_boardAdapter.SetRenderEngine( RENDER_ENGINE::OPENGL ); + m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL; wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::OnRenderEngineSelection type %s ", - ( m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::RAYTRACING ) ? "raytracing" : - "realtime" ); + m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::RAYTRACING ? "raytracing" + : "realtime" ); - if( old_engine != m_boardAdapter.GetRenderEngine() ) + if( old_engine != m_boardAdapter.m_Cfg->m_Render.engine ) RenderEngineChanged(); } @@ -348,7 +367,7 @@ void EDA_3D_VIEWER_FRAME::OnDisableRayTracing( wxCommandEvent& aEvent ) wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::%s disabling ray tracing.", __WXFUNCTION__ ); m_disable_ray_tracing = true; - m_boardAdapter.SetRenderEngine( RENDER_ENGINE::OPENGL ); + m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL; } @@ -392,88 +411,7 @@ void EDA_3D_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE *aCfg ) if( cfg ) { - m_boardAdapter.m_RtCameraLightColor = - m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorCamera ); - m_boardAdapter.m_RtLightColorTop = - m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorTop ); - m_boardAdapter.m_RtLightColorBottom = - m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColorBottom ); - - m_boardAdapter.m_RtLightColor.resize( cfg->m_Render.raytrace_lightColor.size() ); - m_boardAdapter.m_RtLightSphericalCoords.resize( cfg->m_Render.raytrace_lightColor.size() ); - - for( size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i ) - { - m_boardAdapter.m_RtLightColor[i] = - m_boardAdapter.GetColor( cfg->m_Render.raytrace_lightColor[i] ); - - SFVEC2F sphericalCoord = - 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.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f ); - - m_boardAdapter.m_RtLightSphericalCoords[i] = sphericalCoord; - } - -#define TRANSFER_SETTING( flag, field ) m_boardAdapter.SetFlag( flag, cfg->m_Render.field ) - - TRANSFER_SETTING( FL_USE_REALISTIC_MODE, realistic ); - TRANSFER_SETTING( FL_SUBTRACT_MASK_FROM_SILK, subtract_mask_from_silk ); - - // OpenGL options - 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_HIGHLIGHT_ROLLOVER_ITEM, opengl_highlight_on_rollover ); - 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_VIAS_DISABLE_ON_MOVE, opengl_vias_disableOnMove ); - TRANSFER_SETTING( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE, opengl_holes_disableOnMove ); - - // Raytracing options - TRANSFER_SETTING( FL_RENDER_RAYTRACING_SHADOWS, raytrace_shadows ); - TRANSFER_SETTING( FL_RENDER_RAYTRACING_BACKFLOOR, raytrace_backfloor ); - TRANSFER_SETTING( FL_RENDER_RAYTRACING_REFRACTIONS, raytrace_refractions ); - TRANSFER_SETTING( FL_RENDER_RAYTRACING_REFLECTIONS, raytrace_reflections ); - TRANSFER_SETTING( FL_RENDER_RAYTRACING_POST_PROCESSING, raytrace_post_processing ); - TRANSFER_SETTING( FL_RENDER_RAYTRACING_ANTI_ALIASING, raytrace_anti_aliasing ); - TRANSFER_SETTING( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, raytrace_procedural_textures ); - - TRANSFER_SETTING( FL_AXIS, show_axis ); - TRANSFER_SETTING( FL_FP_ATTRIBUTES_NORMAL, show_footprints_normal ); - TRANSFER_SETTING( FL_FP_ATTRIBUTES_NORMAL_INSERT, show_footprints_insert ); - TRANSFER_SETTING( FL_FP_ATTRIBUTES_VIRTUAL, show_footprints_virtual ); - TRANSFER_SETTING( FL_ZONE, show_zones ); - TRANSFER_SETTING( FL_ADHESIVE, show_adhesive ); - TRANSFER_SETTING( FL_SILKSCREEN, show_silkscreen ); - TRANSFER_SETTING( FL_SOLDERMASK, show_soldermask ); - TRANSFER_SETTING( FL_SOLDERPASTE, show_solderpaste ); - TRANSFER_SETTING( FL_COMMENTS, show_comments ); - TRANSFER_SETTING( FL_ECO, show_eco ); - TRANSFER_SETTING( FL_SHOW_BOARD_BODY, show_board_body ); - TRANSFER_SETTING( FL_CLIP_SILK_ON_VIA_ANNULUS, clip_silk_on_via_annulus ); - TRANSFER_SETTING( FL_RENDER_PLATED_PADS_AS_PLATED, renderPlatedPadsAsPlated ); - - m_boardAdapter.SetGridType( static_cast( cfg->m_Render.grid_type ) ); - m_boardAdapter.SetAntiAliasingMode( - static_cast( cfg->m_Render.opengl_AA_mode ) ); - - m_boardAdapter.m_OpenGlSelectionColor = - m_boardAdapter.GetColor( cfg->m_Render.opengl_selection_color ); - - m_boardAdapter.m_RtShadowSampleCount = cfg->m_Render.raytrace_nrsamples_shadows; - m_boardAdapter.m_RtReflectionSampleCount = cfg->m_Render.raytrace_nrsamples_reflections; - m_boardAdapter.m_RtRefractionSampleCount = cfg->m_Render.raytrace_nrsamples_refractions; - - m_boardAdapter.m_RtSpreadShadows = cfg->m_Render.raytrace_spread_shadows; - m_boardAdapter.m_RtSpreadReflections = cfg->m_Render.raytrace_spread_reflections; - m_boardAdapter.m_RtSpreadRefractions = cfg->m_Render.raytrace_spread_refractions; - - m_boardAdapter.m_RtRecursiveRefractionCount = - cfg->m_Render.raytrace_recursivelevel_refractions; - m_boardAdapter.m_RtRecursiveReflectionCount = - cfg->m_Render.raytrace_recursivelevel_reflections; + m_boardAdapter.m_Cfg = cfg; // 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 @@ -484,11 +422,9 @@ void EDA_3D_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE *aCfg ) "EDA_3D_VIEWER_FRAME::LoadSettings render setting Ray Trace" : "EDA_3D_VIEWER_FRAME::LoadSettings render setting OpenGL" ); #else - m_boardAdapter.SetRenderEngine( RENDER_ENGINE::OPENGL ); + m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL; #endif - m_boardAdapter.SetMaterialMode( static_cast( cfg->m_Render.material_mode ) ); - m_canvas->SetAnimationEnabled( cfg->m_Camera.animation_enabled ); m_canvas->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier ); m_canvas->SetProjectionMode( cfg->m_Camera.projection_mode ); @@ -506,95 +442,18 @@ void EDA_3D_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE *aCfg ) wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::SaveSettings" ); - wxLogTrace( m_logTrace, m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::RAYTRACING ? + wxLogTrace( m_logTrace, m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::RAYTRACING ? "EDA_3D_VIEWER_FRAME::SaveSettings render setting Ray Trace" : "EDA_3D_VIEWER_FRAME::SaveSettings render setting OpenGL" ); if( cfg ) { - auto save_color = - [] ( const SFVEC3F& aSource, COLOR4D& aTarget ) - { - aTarget = COLOR4D( aSource.r, aSource.g, aSource.b, 1.0 ); - }; - - save_color( m_boardAdapter.m_RtCameraLightColor, cfg->m_Render.raytrace_lightColorCamera ); - save_color( m_boardAdapter.m_RtLightColorTop, cfg->m_Render.raytrace_lightColorTop ); - save_color( m_boardAdapter.m_RtLightColorBottom, cfg->m_Render.raytrace_lightColorBottom ); - - for( size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i ) - { - save_color( m_boardAdapter.m_RtLightColor[i], cfg->m_Render.raytrace_lightColor[i] ); - - cfg->m_Render.raytrace_lightElevation[i] = - (int)( m_boardAdapter.m_RtLightSphericalCoords[i].x * 180.0f - 90.0f ); - cfg->m_Render.raytrace_lightAzimuth[i] = - (int)( m_boardAdapter.m_RtLightSphericalCoords[i].y * 180.0f ); - } - - cfg->m_Render.raytrace_nrsamples_shadows = m_boardAdapter.m_RtShadowSampleCount; - cfg->m_Render.raytrace_nrsamples_reflections = m_boardAdapter.m_RtReflectionSampleCount; - cfg->m_Render.raytrace_nrsamples_refractions = m_boardAdapter.m_RtRefractionSampleCount; - - cfg->m_Render.raytrace_spread_shadows = m_boardAdapter.m_RtSpreadShadows; - cfg->m_Render.raytrace_spread_reflections = m_boardAdapter.m_RtSpreadReflections; - cfg->m_Render.raytrace_spread_refractions = m_boardAdapter.m_RtSpreadRefractions; - - cfg->m_Render.raytrace_recursivelevel_refractions = - m_boardAdapter.m_RtRecursiveRefractionCount; - cfg->m_Render.raytrace_recursivelevel_reflections = - m_boardAdapter.m_RtRecursiveReflectionCount; - -#define TRANSFER_SETTING( field, flag ) cfg->m_Render.field = m_boardAdapter.GetFlag( flag ) - - cfg->m_Render.engine = static_cast( m_boardAdapter.GetRenderEngine() ); - cfg->m_Render.grid_type = static_cast( m_boardAdapter.GetGridType() ); - cfg->m_Render.material_mode = static_cast( m_boardAdapter.GetMaterialMode() ); - cfg->m_Render.opengl_AA_mode = static_cast( m_boardAdapter.GetAntiAliasingMode() ); - - save_color( m_boardAdapter.m_OpenGlSelectionColor, cfg->m_Render.opengl_selection_color ); - cfg->m_Camera.animation_enabled = m_canvas->GetAnimationEnabled(); cfg->m_Camera.moving_speed_multiplier = m_canvas->GetMovingSpeedMultiplier(); cfg->m_Camera.projection_mode = m_canvas->GetProjectionMode(); if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool() ) cfg->m_Camera.rotation_increment = ctrlTool->GetRotationIncrement(); - - 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_show_model_bbox, FL_RENDER_OPENGL_SHOW_MODEL_BBOX ); - TRANSFER_SETTING( opengl_highlight_on_rollover, FL_HIGHLIGHT_ROLLOVER_ITEM ); - 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_holes_disableOnMove, FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE ); - - TRANSFER_SETTING( raytrace_anti_aliasing, FL_RENDER_RAYTRACING_ANTI_ALIASING ); - TRANSFER_SETTING( raytrace_backfloor, FL_RENDER_RAYTRACING_BACKFLOOR ); - TRANSFER_SETTING( raytrace_post_processing, FL_RENDER_RAYTRACING_POST_PROCESSING ); - TRANSFER_SETTING( raytrace_procedural_textures, FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ); - TRANSFER_SETTING( raytrace_reflections, FL_RENDER_RAYTRACING_REFLECTIONS ); - TRANSFER_SETTING( raytrace_refractions, FL_RENDER_RAYTRACING_REFRACTIONS ); - TRANSFER_SETTING( raytrace_shadows, FL_RENDER_RAYTRACING_SHADOWS ); - - TRANSFER_SETTING( realistic, FL_USE_REALISTIC_MODE ); - TRANSFER_SETTING( show_adhesive, FL_ADHESIVE ); - TRANSFER_SETTING( show_axis, FL_AXIS ); - TRANSFER_SETTING( show_board_body, FL_SHOW_BOARD_BODY ); - TRANSFER_SETTING( clip_silk_on_via_annulus, FL_CLIP_SILK_ON_VIA_ANNULUS ); - TRANSFER_SETTING( renderPlatedPadsAsPlated, FL_RENDER_PLATED_PADS_AS_PLATED ); - TRANSFER_SETTING( show_comments, FL_COMMENTS ); - TRANSFER_SETTING( show_eco, FL_ECO ); - TRANSFER_SETTING( show_footprints_insert, FL_FP_ATTRIBUTES_NORMAL_INSERT ); - TRANSFER_SETTING( show_footprints_normal, FL_FP_ATTRIBUTES_NORMAL ); - TRANSFER_SETTING( show_footprints_virtual, FL_FP_ATTRIBUTES_VIRTUAL ); - TRANSFER_SETTING( show_silkscreen, FL_SILKSCREEN ); - TRANSFER_SETTING( show_soldermask, FL_SOLDERMASK ); - TRANSFER_SETTING( show_solderpaste, FL_SOLDERPASTE ); - TRANSFER_SETTING( show_zones, FL_ZONE ); - TRANSFER_SETTING( subtract_mask_from_silk, FL_SUBTRACT_MASK_FROM_SILK ); - -#undef TRANSFER_SETTING } } @@ -727,5 +586,5 @@ void EDA_3D_VIEWER_FRAME::loadCommonSettings() const DPI_SCALING dpi{ settings, this }; m_canvas->SetScaleFactor( dpi.GetScaleFactor() ); // TODO(JE) use all control options - m_boardAdapter.SetFlag( FL_MOUSEWHEEL_PANNING, settings->m_Input.scroll_modifier_zoom != 0 ); + m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0; } diff --git a/3d-viewer/3d_viewer/tools/eda_3d_actions.cpp b/3d-viewer/3d_viewer/tools/eda_3d_actions.cpp index 436550306c..299c528d16 100644 --- a/3d-viewer/3d_viewer/tools/eda_3d_actions.cpp +++ b/3d-viewer/3d_viewer/tools/eda_3d_actions.cpp @@ -211,72 +211,63 @@ TOOL_ACTION EDA_3D_ACTIONS::showTHT( "3DViewer.Control.attributesTHT", AS_ACTIVE, 'T', "", _( "Toggle Through Hole 3D models" ), _( "Toggle 3D models for 'Through hole' type components" ), - BITMAPS::show_tht, AF_NONE, (void*) FL_FP_ATTRIBUTES_NORMAL ); + BITMAPS::show_tht, AF_NONE ); TOOL_ACTION EDA_3D_ACTIONS::showSMD( "3DViewer.Control.attributesSMD", AS_ACTIVE, 'S', "", _( "Toggle SMD 3D models" ), _( "Toggle 3D models for 'Surface mount' type components" ), - BITMAPS::show_smt, AF_NONE, (void*) FL_FP_ATTRIBUTES_NORMAL_INSERT ); + BITMAPS::show_smt, AF_NONE ); TOOL_ACTION EDA_3D_ACTIONS::showVirtual( "3DViewer.Control.attributesOther", AS_ACTIVE, 'V', "", _( "Toggle Other 3D models" ), _( "Toggle 3D models for 'Other' type components" ), - BITMAPS::show_other, AF_NONE, (void*) FL_FP_ATTRIBUTES_VIRTUAL ); + BITMAPS::show_other, AF_NONE ); TOOL_ACTION EDA_3D_ACTIONS::showBBoxes( "3DViewer.Control.showBoundingBoxes", AS_GLOBAL, 0, "", _( "Show Model Bounding Boxes" ), _( "Show Model Bounding Boxes" ), - BITMAPS::ortho, AF_NONE, (void*) FL_RENDER_OPENGL_SHOW_MODEL_BBOX ); + BITMAPS::ortho, AF_NONE ); TOOL_ACTION EDA_3D_ACTIONS::toggleRealisticMode( "3DViewer.Control.toggleRealisticMode", AS_GLOBAL, 0, "", - _( "Toggle realistic mode" ), _( "Toggle realistic mode" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_USE_REALISTIC_MODE ); + _( "Toggle realistic mode" ), _( "Toggle realistic mode" ) ); TOOL_ACTION EDA_3D_ACTIONS::toggleBoardBody( "3DViewer.Control.toggleBoardBody", AS_GLOBAL, 0, "", - _( "Toggle board body display" ), _( "Toggle board body display" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_SHOW_BOARD_BODY ); + _( "Toggle board body display" ), _( "Toggle board body display" ) ); TOOL_ACTION EDA_3D_ACTIONS::showAxis( "3DViewer.Control.showAxis", AS_GLOBAL, 0, "", _( "Show 3D Axis" ), _( "Show 3D Axis" ), - BITMAPS::axis3d_front, AF_NONE, (void*) FL_AXIS ); + BITMAPS::axis3d_front, AF_NONE ); TOOL_ACTION EDA_3D_ACTIONS::toggleZones( "3DViewer.Control.toggleZones", AS_GLOBAL, 0, "", - _( "Toggle zone display" ), _( "Toggle zone display" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_ZONE ); + _( "Toggle zone display" ), _( "Toggle zone display" ) ); TOOL_ACTION EDA_3D_ACTIONS::toggleAdhesive( "3DViewer.Control.toggleAdhesive", AS_GLOBAL, 0, "", - _( "Toggle adhesive display" ), _( "Toggle display of adhesive layers" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_ADHESIVE ); + _( "Toggle adhesive display" ), _( "Toggle display of adhesive layers" ) ); TOOL_ACTION EDA_3D_ACTIONS::toggleSilk( "3DViewer.Control.toggleSilk", AS_GLOBAL, 0, "", - _( "Toggle silkscreen display" ), _( "Toggle display of silkscreen layers" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_SILKSCREEN ); + _( "Toggle silkscreen display" ), _( "Toggle display of silkscreen layers" ) ); TOOL_ACTION EDA_3D_ACTIONS::toggleSolderMask( "3DViewer.Control.toggleSolderMask", AS_GLOBAL, 0, "", - _( "Toggle solder mask display" ), _( "Toggle display of solder mask layers" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_SOLDERMASK ); + _( "Toggle solder mask display" ), _( "Toggle display of solder mask layers" ) ); TOOL_ACTION EDA_3D_ACTIONS::toggleSolderPaste( "3DViewer.Control.toggleSolderPaste", AS_GLOBAL, 0, "", - _( "Toggle solder paste display" ), _( "Toggle display of solder paste layers" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_SOLDERPASTE ); + _( "Toggle solder paste display" ), _( "Toggle display of solder paste layers" ) ); TOOL_ACTION EDA_3D_ACTIONS::toggleComments( "3DViewer.Control.toggleComments", AS_GLOBAL, 0, "", - _( "Toggle comments display" ), _( "Toggle display of comments and drawings layers" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_COMMENTS ); + _( "Toggle comments display" ), _( "Toggle display of comments and drawings layers" ) ); TOOL_ACTION EDA_3D_ACTIONS::toggleECO( "3DViewer.Control.toggleECO", AS_GLOBAL, 0, "", - _( "Toggle ECO display" ), _( "Toggle display of ECO layers" ), - BITMAPS::INVALID_BITMAP, AF_NONE, (void*) FL_ECO ); + _( "Toggle ECO display" ), _( "Toggle display of ECO layers" ) ); diff --git a/3d-viewer/3d_viewer/tools/eda_3d_conditions.cpp b/3d-viewer/3d_viewer/tools/eda_3d_conditions.cpp index 91b0ebe06f..9dd7d22a12 100644 --- a/3d-viewer/3d_viewer/tools/eda_3d_conditions.cpp +++ b/3d-viewer/3d_viewer/tools/eda_3d_conditions.cpp @@ -30,43 +30,15 @@ using namespace std::placeholders; -SELECTION_CONDITION EDA_3D_CONDITIONS::MaterialMode( MATERIAL_MODE aMaterial ) -{ - return std::bind( &EDA_3D_CONDITIONS::materialModeFunction, _1, m_adapter, aMaterial ); -} - - -SELECTION_CONDITION EDA_3D_CONDITIONS::Flag( DISPLAY3D_FLG aFlag ) -{ - return std::bind( &EDA_3D_CONDITIONS::flagFunction, _1, m_adapter, aFlag ); -} - - SELECTION_CONDITION EDA_3D_CONDITIONS::GridSize( GRID3D_TYPE aGridSize ) { return std::bind( &EDA_3D_CONDITIONS::gridSizeFunction, _1, m_adapter, aGridSize ); } -bool EDA_3D_CONDITIONS::materialModeFunction( const SELECTION& aSelection, - BOARD_ADAPTER* aAdapter, - MATERIAL_MODE aMaterial ) -{ - return aAdapter->GetMaterialMode() == aMaterial; -} - - -bool EDA_3D_CONDITIONS::flagFunction( const SELECTION& aSelection, - BOARD_ADAPTER* aAdapter, - DISPLAY3D_FLG aFlag ) -{ - return aAdapter->GetFlag( aFlag ); -} - - bool EDA_3D_CONDITIONS::gridSizeFunction( const SELECTION& aSelection, BOARD_ADAPTER* aAdapter, GRID3D_TYPE aGridSize ) { - return aAdapter->GetGridType() == aGridSize; + return aAdapter->m_Cfg->m_Render.grid_type == aGridSize; } diff --git a/3d-viewer/3d_viewer/tools/eda_3d_conditions.h b/3d-viewer/3d_viewer/tools/eda_3d_conditions.h index 4152f6661c..79a019c548 100644 --- a/3d-viewer/3d_viewer/tools/eda_3d_conditions.h +++ b/3d-viewer/3d_viewer/tools/eda_3d_conditions.h @@ -44,24 +44,6 @@ public: m_adapter( aAdapter ) {} - /** - * Creates a functor that tests if a specific material mode is active. - * - * @param aAdapter is the board adapter the setting is in - * @param aMaterial is the material mode to test for. - * @return Functor testing if a material mode is active. - */ - SELECTION_CONDITION MaterialMode( MATERIAL_MODE aMaterial ); - - /** - * Creates a functor that tests if the board adapter has a flag set currently. - * - * @param aAdapter is the board adapter the setting is in - * @param aFlag is the flag to test for. - * @return Functor testing if the flag is set. - */ - SELECTION_CONDITION Flag( DISPLAY3D_FLG aFlag ); - /** * Creates a functor that tests the current grid size. * @@ -72,14 +54,6 @@ public: SELECTION_CONDITION GridSize( GRID3D_TYPE aGridSize ); private: - ///< Helper function used by MaterialMode() - static bool materialModeFunction( const SELECTION& aSelection, BOARD_ADAPTER* aAdapter, - MATERIAL_MODE aMaterial ); - - ///< Helper function used by Flag() - static bool flagFunction( const SELECTION& aSelection, BOARD_ADAPTER* aAdapter, - DISPLAY3D_FLG aFlag ); - ///< Helper function used by GridDize() static bool gridSizeFunction( const SELECTION& aSelection, BOARD_ADAPTER* aAdapter, GRID3D_TYPE aGridSize ); diff --git a/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp b/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp index d71d9f92c0..fe107b3070 100644 --- a/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp +++ b/3d-viewer/3d_viewer/tools/eda_3d_controller.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -152,17 +152,17 @@ int EDA_3D_CONTROLLER::RotateView( const TOOL_EVENT& aEvent ) switch( aEvent.Parameter() ) { - case ROTATION_DIR::X_CW: m_camera->RotateX( -rotIncrement ); break; + case ROTATION_DIR::X_CW: m_camera->RotateX( -rotIncrement ); break; case ROTATION_DIR::X_CCW: m_camera->RotateX( rotIncrement ); break; /// Y rotations are backward b/c the RHR has Y pointing into the screen - case ROTATION_DIR::Y_CW: m_camera->RotateY( rotIncrement ); break; - case ROTATION_DIR::Y_CCW: m_camera->RotateY( -rotIncrement ); break; - case ROTATION_DIR::Z_CW: m_camera->RotateZ( -rotIncrement ); break; + case ROTATION_DIR::Y_CW: m_camera->RotateY( rotIncrement ); break; + case ROTATION_DIR::Y_CCW: m_camera->RotateY( -rotIncrement ); break; + case ROTATION_DIR::Z_CW: m_camera->RotateZ( -rotIncrement ); break; case ROTATION_DIR::Z_CCW: m_camera->RotateZ( rotIncrement ); break; - default: wxFAIL; break; + default: wxFAIL; break; } - if( m_boardAdapter->GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( m_boardAdapter->m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) m_canvas->Request_refresh(); else m_canvas->RenderRaytracingRequest(); @@ -173,9 +173,7 @@ int EDA_3D_CONTROLLER::RotateView( const TOOL_EVENT& aEvent ) int EDA_3D_CONTROLLER::SetMaterial( const TOOL_EVENT& aEvent ) { - MATERIAL_MODE mode = aEvent.Parameter(); - - m_boardAdapter->SetMaterialMode( mode ); + m_boardAdapter->m_Cfg->m_Render.material_mode = aEvent.Parameter(); if( auto* viewer = dynamic_cast( m_toolMgr->GetToolHolder() ) ) viewer->NewDisplay( true ); @@ -190,7 +188,7 @@ int EDA_3D_CONTROLLER::ToggleOrtho( const TOOL_EVENT& aEvent ) { m_camera->ToggleProjection(); - if( m_boardAdapter->GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( m_boardAdapter->m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) m_canvas->Request_refresh(); else m_canvas->RenderRaytracingRequest(); @@ -198,56 +196,91 @@ int EDA_3D_CONTROLLER::ToggleOrtho( const TOOL_EVENT& aEvent ) return 0; } - int EDA_3D_CONTROLLER::ToggleVisibility( const TOOL_EVENT& aEvent ) { - DISPLAY3D_FLG flag = aEvent.Parameter(); + bool reload = false; - m_boardAdapter->SetFlag( flag, !m_boardAdapter->GetFlag( flag ) ); +#define FLIP( x ) x = !x - switch( flag ) + if( aEvent.IsAction( &EDA_3D_ACTIONS::showTHT ) ) { - // These commands do not request a 3D scene rebuild (and do not exist in raytracing): - case FL_RENDER_OPENGL_SHOW_MODEL_BBOX: - case FL_AXIS: - m_canvas->Request_refresh(); - break; + FLIP( m_boardAdapter->m_Cfg->m_Render.show_footprints_normal ); + reload = true; + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::showSMD ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_footprints_insert ); + reload = true; + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::showVirtual ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_footprints_virtual ); + reload = true; + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::showBBoxes ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.opengl_show_model_bbox ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleRealisticMode ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.realistic ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleBoardBody ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_board_body ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::showAxis ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_axis ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleZones ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_zones ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleAdhesive ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_adhesive ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleSilk ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_silkscreen ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleSolderMask ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_soldermask ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleSolderPaste ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_solderpaste ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleComments ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_comments ); + } + else if( aEvent.IsAction( &EDA_3D_ACTIONS::toggleECO ) ) + { + FLIP( m_boardAdapter->m_Cfg->m_Render.show_eco ); + } - // These commands do not request a 3D scene rebuild and exist in raytracing: - case FL_RENDER_RAYTRACING_SHADOWS: - case FL_RENDER_RAYTRACING_REFRACTIONS: - case FL_RENDER_RAYTRACING_REFLECTIONS: - case FL_RENDER_RAYTRACING_ANTI_ALIASING: - if( m_boardAdapter->GetRenderEngine() == RENDER_ENGINE::OPENGL ) - m_canvas->Request_refresh(); - else - m_canvas->RenderRaytracingRequest(); - - break; - - case FL_FP_ATTRIBUTES_NORMAL: - case FL_FP_ATTRIBUTES_NORMAL_INSERT: - case FL_FP_ATTRIBUTES_VIRTUAL: - // Loading 3D shapes can be needed if not yet loaded - if( m_boardAdapter->GetRenderEngine() == RENDER_ENGINE::OPENGL ) + if( reload ) + { + if( m_boardAdapter->m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL ) { - RENDER_3D_OPENGL* render = static_cast( m_canvas->GetCurrentRender() ); - render->Load3dModelsIfNeeded(); + auto* renderer = static_cast( m_canvas->GetCurrentRender() ); + renderer->Load3dModelsIfNeeded(); m_canvas->Request_refresh(); } else + { m_canvas->RenderRaytracingRequest(); - - break; - - default: + } + } + else { if( auto viewer = dynamic_cast( m_toolMgr->GetToolHolder() ) ) viewer->NewDisplay( true ); else m_canvas->Request_refresh(); - break; - } } return 0; @@ -256,8 +289,7 @@ int EDA_3D_CONTROLLER::ToggleVisibility( const TOOL_EVENT& aEvent ) int EDA_3D_CONTROLLER::On3DGridSelection( const TOOL_EVENT& aEvent ) { - GRID3D_TYPE grid = aEvent.Parameter(); - m_boardAdapter->SetGridType( grid ); + m_boardAdapter->m_Cfg->m_Render.grid_type = aEvent.Parameter(); if( m_canvas ) m_canvas->Request_refresh(); diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index dcf87f846c..836267bca6 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -97,11 +97,9 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM aFrame->Prj().Get3DCacheManager() ); m_boardAdapter.SetBoard( m_dummyBoard ); + m_boardAdapter.m_IsBoardView = false; loadSettings(); - m_boardAdapter.SetFlag( FL_USE_SELECTION, false ); - m_boardAdapter.SetFlag( FL_HIGHLIGHT_ROLLOVER_ITEM, false ); - // Create the manager m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( m_dummyBoard, nullptr, nullptr, nullptr, this ); @@ -174,7 +172,7 @@ void PANEL_PREVIEW_3D_MODEL::loadSettings() m_previewPane->SetScaleFactor( dpi.GetScaleFactor() ); // TODO(JE) use all control options - m_boardAdapter.SetFlag( FL_MOUSEWHEEL_PANNING, settings->m_Input.scroll_modifier_zoom != 0 ); + m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0; COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings(); @@ -204,9 +202,7 @@ void PANEL_PREVIEW_3D_MODEL::loadSettings() if( cfg ) { - m_boardAdapter.SetRenderEngine( RENDER_ENGINE::OPENGL ); - m_boardAdapter.SetFlag( FL_USE_REALISTIC_MODE, cfg->m_Render.realistic ); - m_boardAdapter.SetMaterialMode( static_cast( cfg->m_Render.material_mode ) ); + m_boardAdapter.m_Cfg = cfg; m_previewPane->SetAnimationEnabled( cfg->m_Camera.animation_enabled ); m_previewPane->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier ); diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 29675eb7a0..d33eea82b2 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -40,7 +39,6 @@ #include #include #include -#include #include #include #include