3D-Viewer: intercect modules and cooper items

show module and net information.
highlight shapes when selected.
This commit is contained in:
Mario Luzeiro 2020-09-04 01:00:56 +01:00 committed by Jon Evans
parent 456112de03
commit 6bc19dbfe9
12 changed files with 613 additions and 392 deletions

View File

@ -425,10 +425,13 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR
wxString msg;
if( aWarningReporter )
{
if( !createBoardPolygon( &msg ) )
aWarningReporter->Report( _( "Board outline is not closed: " ) + msg, RPT_SEVERITY_WARNING );
else
aWarningReporter->Report( wxEmptyString );
}
if( aStatusReporter )
aStatusReporter->Report( _( "Create layers" ) );

View File

@ -36,6 +36,7 @@
#include <eda_3d_viewer.h>
#include <3d_rendering/3d_render_raytracing/c3d_render_raytracing.h>
#include <3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h>
#include <3d_rendering/3d_render_raytracing/accelerators/cbvh_pbrt.h>
#include <3d_viewer_id.h>
#include <class_board.h>
#include <reporter.h>
@ -112,7 +113,9 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD*
m_camera( aCamera ),
m_3d_render( nullptr ),
m_opengl_supports_raytracing( false ),
m_render_raytracing_was_requested( false )
m_render_raytracing_was_requested( false ),
m_accelerator3DShapes( nullptr ),
m_currentIntersectedBoardItem( nullptr )
{
wxLogTrace( m_logTrace, "EDA_3D_CANVAS::EDA_3D_CANVAS" );
@ -176,6 +179,9 @@ EDA_3D_CANVAS::~EDA_3D_CANVAS()
{
wxLogTrace( m_logTrace, "EDA_3D_CANVAS::~EDA_3D_CANVAS" );
delete m_accelerator3DShapes;
m_accelerator3DShapes = NULL;
releaseOpenGL();
}
@ -462,8 +468,17 @@ void EDA_3D_CANVAS::DoRePaint()
{
m_3d_render->SetCurWindowSize( clientSize );
bool reloadRaytracingForIntersectionCalculations = false;
if( ( m_boardAdapter.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY ) &&
m_3d_render_ogl_legacy->IsReloadRequestPending() )
reloadRaytracingForIntersectionCalculations = true;
requested_redraw = m_3d_render->Redraw( m_mouse_was_moved || m_camera_is_moving,
&activityReporter, &warningReporter );
if( reloadRaytracingForIntersectionCalculations )
m_3d_render_raytracing->Reload( nullptr, nullptr, true );
}
if( m_render_pivot )
@ -659,6 +674,102 @@ void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent &event )
const wxPoint eventPosition = event.GetPosition();
m_camera.SetCurMousePosition( eventPosition );
if( !event.Dragging() )
{
STATUSBAR_REPORTER activityReporter(
m_parentStatusBar, static_cast<int>( EDA_3D_VIEWER_STATUSBAR::STATUS_TEXT ) );
RAY mouseRay = getRayAtCurrrentMousePosition();
BOARD_ITEM *intersectedBoardItem = m_3d_render_raytracing->IntersectBoardItem( mouseRay );
if( intersectedBoardItem )
{
if( intersectedBoardItem != m_currentIntersectedBoardItem )
{
m_3d_render_ogl_legacy->SetCurrentIntersectedBoardItem( intersectedBoardItem );
m_currentIntersectedBoardItem = intersectedBoardItem;
if( m_boardAdapter.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY )
Request_refresh();
}
switch( intersectedBoardItem->Type() )
{
case PCB_PAD_T:
{
D_PAD* item = dynamic_cast<D_PAD *>( intersectedBoardItem );
if( item )
{
if( item->IsOnCopperLayer() )
activityReporter.Report( wxString::Format( _( "Net %s\tNetClass %s\tPadName %s" ),
item->GetNet()->GetNetname(),
item->GetNet()->GetClassName(),
item->GetName() ) );
}
}
break;
case PCB_MODULE_T:
{
MODULE* module = dynamic_cast<MODULE *>( intersectedBoardItem );
if( module )
{
activityReporter.Report( module->GetReference() );
}
}
break;
case PCB_TRACE_T:
case PCB_VIA_T:
case PCB_ARC_T:
{
TRACK* item = dynamic_cast<TRACK *>( intersectedBoardItem );
if( item )
{
activityReporter.Report( wxString::Format( _( "Net %s\tNetClass %s" ),
item->GetNet()->GetNetname(),
item->GetNet()->GetClassName() ) );
}
}
break;
case PCB_ZONE_AREA_T:
{
ZONE_CONTAINER* item = dynamic_cast<ZONE_CONTAINER *>( intersectedBoardItem );
if( item )
{
if( item->IsOnCopperLayer() )
activityReporter.Report( wxString::Format( _( "Net %s\tNetClass %s" ),
item->GetNet()->GetNetname(),
item->GetNet()->GetClassName() ) );
}
}
break;
default:
break;
}
}
else
{
if( ( m_currentIntersectedBoardItem != nullptr ) &&
( m_boardAdapter.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY ) )
{
m_3d_render_ogl_legacy->SetCurrentIntersectedBoardItem( nullptr );
Request_refresh();
activityReporter.Report( "" );
}
m_currentIntersectedBoardItem = nullptr;
}
}
}
@ -666,6 +777,15 @@ void EDA_3D_CANVAS::OnLeftDown( wxMouseEvent &event )
{
SetFocus();
stop_editingTimeOut_Timer();
if( !event.Dragging() && ( m_3d_render_raytracing != nullptr ) )
{
RAY mouseRay = getRayAtCurrrentMousePosition();
BOARD_ITEM *intersectedBoardItem = m_3d_render_raytracing->IntersectBoardItem( mouseRay );
// !TODO: send a selection item to pcbnew, eg: via kiway?
}
}
@ -793,14 +913,7 @@ void EDA_3D_CANVAS::request_start_moving_camera( float aMovingSpeed, bool aRende
void EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position()
{
SFVEC3F rayOrigin;
SFVEC3F rayDir;
// Generate a ray origin and direction based on current mouser position and camera
m_camera.MakeRayAtCurrrentMousePosition( rayOrigin, rayDir );
RAY mouseRay;
mouseRay.Init( rayOrigin, rayDir );
RAY mouseRay = getRayAtCurrrentMousePosition();
float hit_t;
@ -994,3 +1107,18 @@ void EDA_3D_CANVAS::RenderEngineChanged()
Request_refresh();
}
RAY EDA_3D_CANVAS::getRayAtCurrrentMousePosition()
{
SFVEC3F rayOrigin;
SFVEC3F rayDir;
// Generate a ray origin and direction based on current mouser position and camera
m_camera.MakeRayAtCurrrentMousePosition( rayOrigin, rayDir );
RAY mouseRay;
mouseRay.Init( rayOrigin, rayDir );
return mouseRay;
}

View File

@ -27,6 +27,7 @@
#include "board_adapter.h"
#include "3d_rendering/3d_render_raytracing/accelerators/caccelerator.h"
#include "3d_rendering/c3d_render_base.h"
#include "3d_cache/3d_cache.h"
#include <gal/hidpi_gl_canvas.h>
@ -233,6 +234,8 @@ private:
*/
void releaseOpenGL();
RAY getRayAtCurrrentMousePosition();
private:
TOOL_DISPATCHER* m_eventDispatcher;
@ -267,6 +270,11 @@ private:
bool m_opengl_supports_raytracing;
bool m_render_raytracing_was_requested;
CCONTAINER m_3DShapes_container; // Holds 3D shapes from modules
CGENERICACCELERATOR *m_accelerator3DShapes; // used for mouse over searching
BOARD_ITEM* m_currentIntersectedBoardItem;
/**
* 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

View File

@ -75,6 +75,7 @@ C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY( BOARD_ADAPTER& aAdapter, CCAMERA&
m_ogl_circle_texture = 0;
m_ogl_disp_list_grid = 0;
m_last_grid_type = GRID3D_TYPE::NONE;
m_currentIntersectedBoardItem = nullptr;
m_3dmodel_map.clear();
}
@ -1241,15 +1242,34 @@ void C3D_RENDER_OGL_LEGACY::render_3D_models_selected( bool aRenderTopOrBot, boo
// Go for all modules
for( auto module : m_boardAdapter.GetBoard()->Modules() )
{
if( ( aRenderSelectedOnly && !module->IsSelected() ) ||
( !aRenderSelectedOnly && module->IsSelected() ) )
const bool isIntersected = ( module == m_currentIntersectedBoardItem );
if( !isIntersected &&
( ( aRenderSelectedOnly && !module->IsSelected() ) ||
( !aRenderSelectedOnly && module->IsSelected() ) ) )
continue;
if( isIntersected && aRenderSelectedOnly )
{
glEnable( GL_POLYGON_OFFSET_LINE );
glPolygonOffset( 8.0, 1.0 );
glPolygonMode( GL_FRONT, GL_LINE );
glLineWidth( 6 );
}
if( !module->Models().empty() )
if( m_boardAdapter.ShouldModuleBeDisplayed((MODULE_ATTR_T) module->GetAttributes() ) )
if( ( aRenderTopOrBot && !module->IsFlipped() )
|| ( !aRenderTopOrBot && module->IsFlipped() ) )
render_3D_module( module, aRenderTransparentOnly );
render_3D_module( module, aRenderTransparentOnly, isIntersected );
if( isIntersected && aRenderSelectedOnly )
{
// Restore
glDisable( GL_POLYGON_OFFSET_LINE );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
}
}
C_OGL_3DMODEL::EndDrawMulti();
@ -1264,7 +1284,8 @@ void C3D_RENDER_OGL_LEGACY::render_3D_models( bool aRenderTopOrBot,
void C3D_RENDER_OGL_LEGACY::render_3D_module( const MODULE* module,
bool aRenderTransparentOnly )
bool aRenderTransparentOnly,
bool aIsSelected )
{
if( !module->Models().empty() )
{
@ -1328,9 +1349,9 @@ void C3D_RENDER_OGL_LEGACY::render_3D_module( const MODULE* module,
glMultMatrixf( glm::value_ptr( mtx ) );
if( aRenderTransparentOnly )
modelPtr->Draw_transparent( sM.m_Opacity, module->IsSelected() );
modelPtr->Draw_transparent( sM.m_Opacity, module->IsSelected() || aIsSelected );
else
modelPtr->Draw_opaque( module->IsSelected() );
modelPtr->Draw_opaque( module->IsSelected() || aIsSelected );
if( m_boardAdapter.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) )
{

View File

@ -69,6 +69,8 @@ public:
int GetWaitForEditingTimeOut() override;
void SetCurrentIntersectedBoardItem( BOARD_ITEM* aCurrentIntersectedBoardItem ) { m_currentIntersectedBoardItem = aCurrentIntersectedBoardItem; }
private:
bool initializeOpenGL();
void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
@ -108,6 +110,8 @@ private:
MAP_3DMODEL m_3dmodel_map;
BOARD_ITEM* m_currentIntersectedBoardItem;
private:
CLAYERS_OGL_DISP_LISTS *generate_holes_display_list( const LIST_OBJECT2D &aListHolesObject2d,
const SHAPE_POLY_SET &aPoly,
@ -192,7 +196,7 @@ private:
void render_3D_models_selected( bool aRenderTopOrBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly );
void render_3D_module( const MODULE* module, bool aRenderTransparentOnly );
void render_3D_module( const MODULE* module, bool aRenderTransparentOnly, bool aIsSelected );
void setLight_Front( bool enabled );
void setLight_Top( bool enabled );

View File

@ -440,7 +440,9 @@ void C3D_RENDER_RAYTRACING::createItemsFromContainer( const CBVHCONTAINER2D *aCo
}
}
void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter )
void C3D_RENDER_RAYTRACING::Reload( REPORTER* aStatusReporter,
REPORTER* aWarningReporter,
bool aOnlyLoadCopperAndShapes )
{
m_reloadRequested = false;
@ -451,10 +453,13 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
unsigned stats_startReloadTime = GetRunningMicroSecs();
if( !aOnlyLoadCopperAndShapes )
{
m_boardAdapter.InitSettings( aStatusReporter, aWarningReporter );
SFVEC3F camera_pos = m_boardAdapter.GetBoardCenter3DU();
m_camera.SetBoardLookAtPos( camera_pos );
}
m_object_container.Clear();
m_containerWithObjectsToDelete.Clear();
@ -468,6 +473,8 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
m_outlineBoard2dObjects = new CCONTAINER2D;
if( !aOnlyLoadCopperAndShapes )
{
const int outlineCount = m_boardAdapter.GetBoardPoly().OutlineCount();
if( outlineCount > 0 )
@ -620,6 +627,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
}
}
}
}
// Add layers maps (except B_Mask and F_Mask)
@ -631,6 +639,9 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
{
PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
if( aOnlyLoadCopperAndShapes && !IsCopperLayer( layer_id ) )
continue;
// Mask kayers are not processed here because they are a special case
if( (layer_id == B_Mask) || (layer_id == F_Mask) )
continue;
@ -718,6 +729,8 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
createItemsFromContainer( m_boardAdapter.GetPlatedPads_Back(), B_Cu, &m_materials.m_Copper, layerColor_B_Cu, -m_boardAdapter.GetCopperThickness3DU() * 0.1f );
}
if( !aOnlyLoadCopperAndShapes )
{
// Add Mask layer
// Solder mask layers are "negative" layers so the elements that we have
// (in the container) should remove the board outline.
@ -864,6 +877,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
}
add_3D_vias_and_pads_to_container();
}
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_endConvertTime = GetRunningMicroSecs();
@ -871,13 +885,15 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
#endif
load_3D_models( false );
load_3D_models( m_object_container, aOnlyLoadCopperAndShapes );
#ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_endLoad3DmodelsTime = GetRunningMicroSecs();
#endif
if( !aOnlyLoadCopperAndShapes )
{
// Add floor
// /////////////////////////////////////////////////////////////////////////
if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_BACKFLOOR ) )
@ -999,7 +1015,7 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
m_boardAdapter.m_raytrace_lightColor[i] ) );
}
}
}
// Create an accelerator
// /////////////////////////////////////////////////////////////////////////
@ -1250,7 +1266,7 @@ void C3D_RENDER_RAYTRACING::add_3D_vias_and_pads_to_container()
}
void C3D_RENDER_RAYTRACING::load_3D_models( bool aSkipMaterialInformation )
void C3D_RENDER_RAYTRACING::load_3D_models( CCONTAINER &aDstContainer, bool aSkipMaterialInformation )
{
// Go for all modules
for( auto module : m_boardAdapter.GetBoard()->Modules() )
@ -1297,6 +1313,7 @@ void C3D_RENDER_RAYTRACING::load_3D_models( bool aSkipMaterialInformation )
modelunit_to_3d_units_factor,
modelunit_to_3d_units_factor ) );
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( module );
// Get the list of model files for this model
S3D_CACHE* cacheMgr = m_boardAdapter.Get3DCacheManager();
@ -1341,7 +1358,12 @@ void C3D_RENDER_RAYTRACING::load_3D_models( bool aSkipMaterialInformation )
sM->m_Scale.y,
sM->m_Scale.z ) );
add_3D_models( modelPtr, modelMatrix, (float)sM->m_Opacity, aSkipMaterialInformation );
add_3D_models( aDstContainer,
modelPtr,
modelMatrix,
(float)sM->m_Opacity,
aSkipMaterialInformation,
boardItem );
}
}
@ -1462,10 +1484,12 @@ MODEL_MATERIALS *C3D_RENDER_RAYTRACING::get_3D_model_material( const S3DMODEL *a
return materialVector;
}
void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
void C3D_RENDER_RAYTRACING::add_3D_models( CCONTAINER &aDstContainer,
const S3DMODEL *a3DModel,
const glm::mat4 &aModelMatrix,
float aModuleOpacity,
bool aSkipMaterialInformation )
bool aSkipMaterialInformation,
BOARD_ITEM *aBoardItem )
{
// Validate a3DModel pointers
@ -1562,7 +1586,9 @@ void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
CTRIANGLE *newTriangle = new CTRIANGLE( vt0, vt2, vt1,
nt0, nt2, nt1 );
m_object_container.Add( newTriangle );
newTriangle->SetBoardItem( aBoardItem );
aDstContainer.Add( newTriangle );
if( !aSkipMaterialInformation )
{

View File

@ -179,7 +179,7 @@ bool C3D_RENDER_RAYTRACING::Redraw(
//aIsMoving = true;
requestRedraw = true;
reload( aStatusReporter, aWarningReporter );
Reload( aStatusReporter, aWarningReporter, false );
}
@ -2079,3 +2079,18 @@ void C3D_RENDER_RAYTRACING::initialize_block_positions()
opengl_init_pbo();
}
BOARD_ITEM *C3D_RENDER_RAYTRACING::IntersectBoardItem( const RAY &aRay )
{
HITINFO hitInfo;
hitInfo.m_tHit = std::numeric_limits<float>::infinity();
if( m_accelerator )
if( m_accelerator->Intersect( aRay, hitInfo ) )
{
if( hitInfo.pHitObject )
return hitInfo.pHitObject->GetBoardItem();
}
return nullptr;
}

View File

@ -69,12 +69,15 @@ public:
int GetWaitForEditingTimeOut() override;
void Reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter, bool aOnlyLoadCopperAndShapes );
BOARD_ITEM *IntersectBoardItem( const RAY &aRay );
private:
bool initializeOpenGL();
void initializeNewWindowSize();
void opengl_init_pbo();
void opengl_delete_pbo();
void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
void createItemsFromContainer( const CBVHCONTAINER2D *aContainer2d,
PCB_LAYER_ID aLayer_id,
const CMATERIAL *aMaterialLayer,
@ -201,11 +204,13 @@ private:
void add_3D_vias_and_pads_to_container();
void insert3DViaHole( const VIA* aVia );
void insert3DPadHole( const D_PAD* aPad );
void load_3D_models( bool aSkipMaterialInformation );
void add_3D_models( const S3DMODEL *a3DModel,
void load_3D_models( CCONTAINER &aDstContainer, bool aSkipMaterialInformation );
void add_3D_models( CCONTAINER &aDstContainer,
const S3DMODEL *a3DModel,
const glm::mat4 &aModelMatrix,
float aModuleOpacity,
bool aSkipMaterialInformation );
bool aSkipMaterialInformation,
BOARD_ITEM *aBoardItem );
MODEL_MATERIALS *get_3D_model_material( const S3DMODEL *a3DModel );

View File

@ -42,6 +42,7 @@ COBJECT::COBJECT( OBJECT3D_TYPE aObjType )
COBJECT3D_STATS::Instance().AddOne( aObjType );
m_material = &s_defaultMaterial;
m_modelTransparency = 0.0f;
m_boardItem = nullptr;
}

View File

@ -34,6 +34,7 @@
#include "../hitinfo.h"
#include "../cmaterial.h"
#include <class_board_item.h>
enum class OBJECT3D_TYPE
{
@ -55,6 +56,8 @@ protected:
OBJECT3D_TYPE m_obj_type;
const CMATERIAL *m_material;
BOARD_ITEM *m_boardItem;
// m_modelTransparency combines the material and model opacity
// 0.0 full opaque, 1.0 full transparent.
float m_modelTransparency;
@ -63,6 +66,9 @@ public:
explicit COBJECT( OBJECT3D_TYPE aObjType );
const void SetBoardItem( BOARD_ITEM *aBoardItem ) { m_boardItem = aBoardItem; }
BOARD_ITEM *GetBoardItem() const { return m_boardItem; }
void SetMaterial( const CMATERIAL *aMaterial )
{
m_material = aMaterial;

View File

@ -380,8 +380,12 @@ void CCAMERA::MakeRay( const SFVEC2F &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &
void CCAMERA::MakeRayAtCurrrentMousePosition( SFVEC3F &aOutOrigin,
SFVEC3F &aOutDirection ) const
{
MakeRay( SFVEC2I( m_lastPosition.x,
m_windowSize.y - m_lastPosition.y ),
const SFVEC2I windowPos = SFVEC2I( m_lastPosition.x,
m_windowSize.y - m_lastPosition.y );
if( ( windowPos.x < m_windowSize.x ) &&
( windowPos.y < m_windowSize.y ) )
MakeRay( windowPos,
aOutOrigin, aOutDirection );
}

View File

@ -275,7 +275,7 @@ void EDA_3D_VIEWER::Redraw()
{
// Only update in OpenGL for an interactive interaction
if( m_boardAdapter.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY )
m_canvas->Refresh();
m_canvas->Request_refresh( true );
}
void EDA_3D_VIEWER::Exit3DFrame( wxCommandEvent &event )