2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-07-19 17:35:25 +00:00
|
|
|
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2015-12-08 07:31:57 +00:00
|
|
|
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
2017-02-06 14:20:46 +00:00
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2022-03-13 23:13:40 +00:00
|
|
|
* Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
#include "panel_preview_3d_model.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <3d_canvas/eda_3d_canvas.h>
|
2020-03-24 01:01:23 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/tool_dispatcher.h>
|
2021-06-19 17:28:45 +00:00
|
|
|
#include <tools/eda_3d_actions.h>
|
|
|
|
#include <tools/eda_3d_controller.h>
|
2019-04-08 09:49:18 +00:00
|
|
|
#include <base_units.h>
|
|
|
|
#include <bitmaps.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-01-03 22:23:00 +00:00
|
|
|
#include <common_ogl/ogl_attr_list.h>
|
2020-06-19 16:02:46 +00:00
|
|
|
#include <gal/dpi_scaling.h>
|
2018-09-25 19:23:54 +00:00
|
|
|
#include <pgm_base.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/common_settings.h>
|
2021-07-04 12:19:40 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2022-12-28 22:03:03 +00:00
|
|
|
#include <widgets/wx_infobar.h>
|
2021-07-04 12:19:40 +00:00
|
|
|
#include <eda_3d_viewer_settings.h>
|
2021-10-10 14:41:25 +00:00
|
|
|
#include <board_design_settings.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame,
|
|
|
|
FOOTPRINT* aFootprint,
|
|
|
|
std::vector<FP_3DMODEL>* aParentModelList ) :
|
|
|
|
PANEL_PREVIEW_3D_MODEL_BASE( aParent, wxID_ANY ),
|
2020-03-26 14:05:20 +00:00
|
|
|
m_previewPane( nullptr ),
|
2020-10-06 09:55:26 +00:00
|
|
|
m_infobar( nullptr ),
|
2020-03-26 14:05:20 +00:00
|
|
|
m_boardAdapter(),
|
|
|
|
m_currentCamera( m_trackBallCamera ),
|
2022-10-02 19:00:42 +00:00
|
|
|
m_trackBallCamera( 2 * RANGE_SCALE_3D ),
|
2022-12-03 19:31:41 +00:00
|
|
|
m_boardThickness( aFrame, nullptr, m_boardThicknessCtrl, m_boardThicknessUnits )
|
2018-01-13 01:58:44 +00:00
|
|
|
{
|
2018-03-28 17:14:04 +00:00
|
|
|
m_userUnits = aFrame->GetUserUnits();
|
2018-02-02 15:56:09 +00:00
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
m_dummyBoard = new BOARD();
|
2022-09-26 03:04:13 +00:00
|
|
|
m_dummyBoard->SetProject( &aFrame->Prj(), true );
|
2020-02-27 17:46:49 +00:00
|
|
|
|
|
|
|
// This board will only be used to hold a footprint for viewing
|
|
|
|
m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
|
|
|
|
|
2022-09-26 20:35:59 +00:00
|
|
|
BOARD_DESIGN_SETTINGS parent_bds = aFrame->GetDesignSettings();
|
|
|
|
BOARD_DESIGN_SETTINGS dummy_bds = m_dummyBoard->GetDesignSettings();
|
|
|
|
dummy_bds.SetBoardThickness( parent_bds.GetBoardThickness() );
|
|
|
|
BOARD_STACKUP& dummy_board_stackup = m_dummyBoard->GetDesignSettings().GetStackupDescriptor();
|
|
|
|
dummy_board_stackup.RemoveAll();
|
|
|
|
dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
m_selected = -1;
|
|
|
|
|
|
|
|
// Set the bitmap of 3D view buttons:
|
2021-03-08 02:59:07 +00:00
|
|
|
m_bpvTop->SetBitmap( KiBitmap( BITMAPS::axis3d_top ) );
|
|
|
|
m_bpvFront->SetBitmap( KiBitmap( BITMAPS::axis3d_front ) );
|
|
|
|
m_bpvBack->SetBitmap( KiBitmap( BITMAPS::axis3d_back ) );
|
|
|
|
m_bpvLeft->SetBitmap( KiBitmap( BITMAPS::axis3d_left ) );
|
|
|
|
m_bpvRight->SetBitmap( KiBitmap( BITMAPS::axis3d_right ) );
|
|
|
|
m_bpvBottom->SetBitmap( KiBitmap( BITMAPS::axis3d_bottom ) );
|
|
|
|
m_bpvISO->SetBitmap( KiBitmap( BITMAPS::ortho ) );
|
|
|
|
m_bpUpdate->SetBitmap( KiBitmap( BITMAPS::reload ) );
|
2020-03-24 01:01:23 +00:00
|
|
|
|
|
|
|
// Set the min and max values of spin buttons (mandatory on Linux)
|
|
|
|
// They are not used, so they are set to min and max 32 bits int values
|
|
|
|
// (the min and max values supported by a wxSpinButton)
|
|
|
|
// It avoids blocking the up or down arrows when reaching this limit after
|
|
|
|
// a few clicks.
|
|
|
|
wxSpinButton* spinButtonList[] =
|
|
|
|
{
|
|
|
|
m_spinXscale, m_spinYscale, m_spinZscale,
|
|
|
|
m_spinXrot, m_spinYrot, m_spinZrot,
|
2022-10-02 19:00:42 +00:00
|
|
|
m_spinXoffset,m_spinYoffset, m_spinZoffset
|
2020-03-24 01:01:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for( wxSpinButton* button : spinButtonList )
|
|
|
|
button->SetRange(INT_MIN, INT_MAX );
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2018-07-20 20:56:12 +00:00
|
|
|
m_parentModelList = aParentModelList;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
m_dummyFootprint = new FOOTPRINT( *aFootprint );
|
2020-11-13 00:43:45 +00:00
|
|
|
m_dummyBoard->Add( m_dummyFootprint );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
// Create the 3D canvas
|
2020-12-11 12:09:37 +00:00
|
|
|
m_previewPane = new EDA_3D_CANVAS( this,
|
2021-01-02 21:05:29 +00:00
|
|
|
OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
|
2021-07-18 15:44:54 +00:00
|
|
|
m_boardAdapter, m_currentCamera,
|
2018-03-28 17:14:04 +00:00
|
|
|
aFrame->Prj().Get3DCacheManager() );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-07-18 15:44:54 +00:00
|
|
|
m_boardAdapter.SetBoard( m_dummyBoard );
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_IsBoardView = false;
|
2022-01-06 11:04:28 +00:00
|
|
|
m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
|
|
|
|
|
2021-07-04 12:19:40 +00:00
|
|
|
loadSettings();
|
2019-04-08 09:49:18 +00:00
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
// Create the manager
|
|
|
|
m_toolManager = new TOOL_MANAGER;
|
2020-06-12 10:58:56 +00:00
|
|
|
m_toolManager->SetEnvironment( m_dummyBoard, nullptr, nullptr, nullptr, this );
|
2020-03-24 01:01:23 +00:00
|
|
|
|
|
|
|
m_actions = new EDA_3D_ACTIONS();
|
2021-03-27 20:02:34 +00:00
|
|
|
m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
|
2020-03-24 01:01:23 +00:00
|
|
|
m_previewPane->SetEventDispatcher( m_toolDispatcher );
|
|
|
|
|
|
|
|
// Register tools
|
|
|
|
m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
|
|
|
|
m_toolManager->InitTools();
|
|
|
|
|
|
|
|
// Run the viewer control tool, it is supposed to be always active
|
|
|
|
m_toolManager->InvokeTool( "3DViewer.Control" );
|
|
|
|
|
2020-12-11 12:09:37 +00:00
|
|
|
m_infobar = new WX_INFOBAR( this );
|
|
|
|
m_previewPane->SetInfoBar( m_infobar );
|
2020-10-06 09:55:26 +00:00
|
|
|
|
2020-12-15 11:39:32 +00:00
|
|
|
m_SizerPanelView->Add( m_infobar, 0, wxEXPAND, 0 );
|
|
|
|
m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 );
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
for( wxEventType eventType : { wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT } )
|
2022-03-13 23:13:40 +00:00
|
|
|
{
|
2021-07-14 19:47:32 +00:00
|
|
|
Connect( eventType, wxMenuEventHandler( PANEL_PREVIEW_3D_MODEL::OnMenuEvent ), nullptr,
|
|
|
|
this );
|
2022-03-13 23:13:40 +00:00
|
|
|
}
|
2020-06-07 14:46:44 +00:00
|
|
|
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
// Call layout once to get the proper button sizes after the bitmaps have been set
|
|
|
|
Layout();
|
|
|
|
|
|
|
|
// The rounded-button style used has a small border on the left/right sides.
|
|
|
|
// This is automatically fixed in wx for buttons with a bitmap < 20, but not
|
|
|
|
// when the bitmap is set to be 26x26.
|
2020-12-16 18:19:28 +00:00
|
|
|
wxSize borderFix = wxSize( 4, 4 );
|
2020-06-07 14:46:44 +00:00
|
|
|
|
|
|
|
m_bpvTop->SetMinSize( m_bpvTop->GetSize() + borderFix );
|
|
|
|
m_bpvFront->SetMinSize( m_bpvFront->GetSize() + borderFix );
|
|
|
|
m_bpvBack->SetMinSize( m_bpvBack->GetSize() + borderFix );
|
|
|
|
m_bpvLeft->SetMinSize( m_bpvLeft->GetSize() + borderFix );
|
|
|
|
m_bpvRight->SetMinSize( m_bpvRight->GetSize() + borderFix );
|
|
|
|
m_bpvBottom->SetMinSize( m_bpvBottom->GetSize() + borderFix );
|
|
|
|
m_bpvISO->SetMinSize( m_bpvISO->GetSize() + borderFix );
|
|
|
|
m_bpUpdate->SetMinSize( m_bpUpdate->GetSize() + borderFix );
|
|
|
|
#endif
|
2018-01-13 01:58:44 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
PANEL_PREVIEW_3D_MODEL::~PANEL_PREVIEW_3D_MODEL()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
delete m_dummyBoard;
|
|
|
|
delete m_previewPane;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::OnMenuEvent( wxMenuEvent& aEvent )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
if( !m_toolDispatcher )
|
|
|
|
aEvent.Skip();
|
|
|
|
else
|
|
|
|
m_toolDispatcher->DispatchWxEvent( aEvent );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-04 12:19:40 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::loadSettings()
|
2019-04-08 09:49:18 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxCHECK_RET( m_previewPane, wxT( "Cannot load settings to null canvas" ) );
|
2019-04-08 09:49:18 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
|
2019-04-08 09:49:18 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
const DPI_SCALING dpi{ settings, this };
|
|
|
|
m_previewPane->SetScaleFactor( dpi.GetScaleFactor() );
|
2019-04-08 09:49:18 +00:00
|
|
|
|
2020-05-17 00:19:48 +00:00
|
|
|
// TODO(JE) use all control options
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;
|
2021-07-04 12:19:40 +00:00
|
|
|
|
|
|
|
COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
|
|
|
|
|
|
|
|
if( colors )
|
|
|
|
{
|
|
|
|
auto set =
|
|
|
|
[] ( const COLOR4D& aColor, SFVEC4F& aTarget )
|
|
|
|
{
|
|
|
|
aTarget.r = aColor.r;
|
|
|
|
aTarget.g = aColor.g;
|
|
|
|
aTarget.b = aColor.b;
|
|
|
|
aTarget.a = aColor.a;
|
|
|
|
};
|
|
|
|
|
|
|
|
set( colors->GetColor( LAYER_3D_BACKGROUND_BOTTOM ), m_boardAdapter.m_BgColorBot );
|
|
|
|
set( colors->GetColor( LAYER_3D_BACKGROUND_TOP ), m_boardAdapter.m_BgColorTop );
|
|
|
|
set( colors->GetColor( LAYER_3D_BOARD ), m_boardAdapter.m_BoardBodyColor );
|
|
|
|
set( colors->GetColor( LAYER_3D_COPPER ), m_boardAdapter.m_CopperColor );
|
|
|
|
set( colors->GetColor( LAYER_3D_SILKSCREEN_BOTTOM ), m_boardAdapter.m_SilkScreenColorBot );
|
|
|
|
set( colors->GetColor( LAYER_3D_SILKSCREEN_TOP ), m_boardAdapter.m_SilkScreenColorTop );
|
2021-07-27 21:24:18 +00:00
|
|
|
set( colors->GetColor( LAYER_3D_SOLDERMASK_BOTTOM ), m_boardAdapter.m_SolderMaskColorBot );
|
|
|
|
set( colors->GetColor( LAYER_3D_SOLDERMASK_TOP ), m_boardAdapter.m_SolderMaskColorTop );
|
2021-07-04 12:19:40 +00:00
|
|
|
set( colors->GetColor( LAYER_3D_SOLDERPASTE ), m_boardAdapter.m_SolderPasteColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
|
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_Cfg = cfg;
|
2021-07-04 12:19:40 +00:00
|
|
|
|
|
|
|
m_previewPane->SetAnimationEnabled( cfg->m_Camera.animation_enabled );
|
|
|
|
m_previewPane->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier );
|
|
|
|
m_previewPane->SetProjectionMode( cfg->m_Camera.projection_mode );
|
|
|
|
}
|
2019-04-08 09:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-06 14:20:46 +00:00
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Ensure -MAX_ROTATION <= rotation <= MAX_ROTATION.
|
|
|
|
*
|
|
|
|
* @param \a aRotation will be normalized between -MAX_ROTATION and MAX_ROTATION.
|
2017-02-06 14:20:46 +00:00
|
|
|
*/
|
2018-03-28 17:14:04 +00:00
|
|
|
static double rotationFromString( const wxString& aValue )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2022-09-19 09:25:20 +00:00
|
|
|
double rotation = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::DEGREES, aValue );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
if( rotation > MAX_ROTATION )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
int n = KiROUND( rotation / MAX_ROTATION );
|
2018-03-28 17:14:04 +00:00
|
|
|
rotation -= MAX_ROTATION * n;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
else if( rotation < -MAX_ROTATION )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-03-24 01:01:23 +00:00
|
|
|
int n = KiROUND( -rotation / MAX_ROTATION );
|
2018-03-28 17:14:04 +00:00
|
|
|
rotation += MAX_ROTATION * n;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
return rotation;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
wxString PANEL_PREVIEW_3D_MODEL::formatScaleValue( double aValue )
|
2018-01-13 01:58:44 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
return wxString::Format( wxT( "%.4f" ),
|
|
|
|
aValue );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
wxString PANEL_PREVIEW_3D_MODEL::formatRotationValue( double aValue )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
return wxString::Format( wxT( "%.2f%s" ),
|
|
|
|
aValue,
|
2022-09-19 09:25:20 +00:00
|
|
|
EDA_UNIT_UTILS::GetText( EDA_UNITS::DEGREES ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
wxString PANEL_PREVIEW_3D_MODEL::formatOffsetValue( double aValue )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2018-03-28 17:14:04 +00:00
|
|
|
// Convert from internal units (mm) to user units
|
2019-12-20 14:11:39 +00:00
|
|
|
if( m_userUnits == EDA_UNITS::INCHES )
|
2021-12-28 09:36:37 +00:00
|
|
|
aValue /= 25.4;
|
|
|
|
else if( m_userUnits == EDA_UNITS::MILS )
|
|
|
|
aValue /= 25.4 / 1e3;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
return wxString::Format( wxT( "%.6f%s" ),
|
|
|
|
aValue,
|
2022-09-19 09:25:20 +00:00
|
|
|
EDA_UNIT_UTILS::GetText( m_userUnits ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::SetSelectedModel( int idx )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2018-07-20 20:56:12 +00:00
|
|
|
if( m_parentModelList && idx >= 0 && idx < (int) m_parentModelList->size() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2018-07-20 20:56:12 +00:00
|
|
|
m_selected = idx;
|
2020-11-13 00:43:45 +00:00
|
|
|
const FP_3DMODEL& modelInfo = m_parentModelList->at( (unsigned) m_selected );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// Use ChangeValue() instead of SetValue(). It's not the user making the change, so we
|
|
|
|
// don't want to generate wxEVT_GRID_CELL_CHANGED events.
|
|
|
|
xscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.x ) );
|
|
|
|
yscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.y ) );
|
|
|
|
zscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.z ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
xrot->ChangeValue( formatRotationValue( modelInfo.m_Rotation.x ) );
|
|
|
|
yrot->ChangeValue( formatRotationValue( modelInfo.m_Rotation.y ) );
|
|
|
|
zrot->ChangeValue( formatRotationValue( modelInfo.m_Rotation.z ) );
|
2016-01-25 04:55:36 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
xoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.x ) );
|
|
|
|
yoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.y ) );
|
|
|
|
zoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.z ) );
|
2020-04-19 17:23:40 +00:00
|
|
|
|
|
|
|
m_opacity->SetValue( modelInfo.m_Opacity * 100.0 );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-20 20:56:12 +00:00
|
|
|
m_selected = -1;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
xscale->ChangeValue( wxEmptyString );
|
|
|
|
yscale->ChangeValue( wxEmptyString );
|
|
|
|
zscale->ChangeValue( wxEmptyString );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
xrot->ChangeValue( wxEmptyString );
|
|
|
|
yrot->ChangeValue( wxEmptyString );
|
|
|
|
zrot->ChangeValue( wxEmptyString );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
xoff->ChangeValue( wxEmptyString );
|
|
|
|
yoff->ChangeValue( wxEmptyString );
|
|
|
|
zoff->ChangeValue( wxEmptyString );
|
2020-04-19 17:23:40 +00:00
|
|
|
|
|
|
|
m_opacity->SetValue( 100 );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
2022-10-02 19:00:42 +00:00
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS dummy_bds = m_dummyBoard->GetDesignSettings();
|
|
|
|
m_boardThickness.ChangeValue( dummy_bds.GetBoardThickness() );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::updateOrientation( wxCommandEvent &event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2018-07-20 20:56:12 +00:00
|
|
|
if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
|
|
|
|
{
|
|
|
|
// Write settings back to the parent
|
2020-11-13 00:43:45 +00:00
|
|
|
FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
|
2015-12-08 23:38:25 +00:00
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
modelInfo->m_Scale.x = EDA_UNIT_UTILS::UI::DoubleValueFromString(
|
|
|
|
pcbIUScale, EDA_UNITS::UNSCALED, xscale->GetValue() );
|
|
|
|
modelInfo->m_Scale.y = EDA_UNIT_UTILS::UI::DoubleValueFromString(
|
|
|
|
pcbIUScale, EDA_UNITS::UNSCALED, yscale->GetValue() );
|
|
|
|
modelInfo->m_Scale.z = EDA_UNIT_UTILS::UI::DoubleValueFromString(
|
|
|
|
pcbIUScale, EDA_UNITS::UNSCALED, zscale->GetValue() );
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2018-07-20 20:56:12 +00:00
|
|
|
modelInfo->m_Rotation.x = rotationFromString( xrot->GetValue() );
|
|
|
|
modelInfo->m_Rotation.y = rotationFromString( yrot->GetValue() );
|
|
|
|
modelInfo->m_Rotation.z = rotationFromString( zrot->GetValue() );
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
modelInfo->m_Offset.x = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits,
|
|
|
|
xoff->GetValue() )
|
|
|
|
/ pcbIUScale.IU_PER_MM;
|
|
|
|
modelInfo->m_Offset.y = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits,
|
|
|
|
yoff->GetValue() )
|
|
|
|
/ pcbIUScale.IU_PER_MM;
|
|
|
|
modelInfo->m_Offset.z = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits,
|
|
|
|
zoff->GetValue() )
|
|
|
|
/ pcbIUScale.IU_PER_MM;
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Update the dummy footprint for the preview
|
2020-10-14 23:37:26 +00:00
|
|
|
UpdateDummyFootprint( false );
|
2015-12-09 05:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::onOpacitySlider( wxCommandEvent& event )
|
2020-04-19 17:23:40 +00:00
|
|
|
{
|
|
|
|
if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
|
|
|
|
{
|
|
|
|
// Write settings back to the parent
|
2020-11-13 00:43:45 +00:00
|
|
|
FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
|
2020-04-19 17:23:40 +00:00
|
|
|
|
|
|
|
modelInfo->m_Opacity = m_opacity->GetValue() / 100.0;
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Update the dummy footprint for the preview
|
2020-10-14 23:37:26 +00:00
|
|
|
UpdateDummyFootprint( false );
|
2020-04-19 17:23:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-02 19:00:42 +00:00
|
|
|
|
2021-10-10 14:41:25 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::updateBoardThickness( wxCommandEvent& event )
|
|
|
|
{
|
2022-09-26 20:35:59 +00:00
|
|
|
BOARD_DESIGN_SETTINGS dummy_bds = m_dummyBoard->GetDesignSettings();
|
2022-10-02 19:00:42 +00:00
|
|
|
dummy_bds.SetBoardThickness( m_boardThickness.GetValue() );
|
2021-10-10 14:41:25 +00:00
|
|
|
|
2022-09-26 20:35:59 +00:00
|
|
|
BOARD_STACKUP& dummy_board_stackup = m_dummyBoard->GetDesignSettings().GetStackupDescriptor();
|
|
|
|
dummy_board_stackup.RemoveAll();
|
|
|
|
dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
|
|
|
|
|
|
|
|
UpdateDummyFootprint( true );
|
2021-10-10 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-19 17:23:40 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::doIncrementScale( wxSpinEvent& event, double aSign )
|
2017-02-06 19:49:29 +00:00
|
|
|
{
|
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
|
|
|
|
|
|
|
|
wxTextCtrl * textCtrl = xscale;
|
|
|
|
|
|
|
|
if( spinCtrl == m_spinYscale )
|
|
|
|
textCtrl = yscale;
|
|
|
|
else if( spinCtrl == m_spinZscale )
|
|
|
|
textCtrl = zscale;
|
|
|
|
|
2022-10-02 19:00:42 +00:00
|
|
|
double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::UNSCALED,
|
|
|
|
textCtrl->GetValue() );
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
curr_value += ( SCALE_INCREMENT * aSign );
|
|
|
|
curr_value = std::max( 1/MAX_SCALE, curr_value );
|
|
|
|
curr_value = std::min( curr_value, MAX_SCALE );
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
textCtrl->SetValue( formatScaleValue( curr_value ) );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::doIncrementRotation( wxSpinEvent& aEvent, double aSign )
|
2017-02-06 19:49:29 +00:00
|
|
|
{
|
2018-03-28 17:14:04 +00:00
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) aEvent.GetEventObject();
|
|
|
|
wxTextCtrl* textCtrl = xrot;
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
if( spinCtrl == m_spinYrot )
|
|
|
|
textCtrl = yrot;
|
|
|
|
else if( spinCtrl == m_spinZrot )
|
|
|
|
textCtrl = zrot;
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::DEGREES,
|
2022-09-16 04:38:10 +00:00
|
|
|
textCtrl->GetValue() );
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
curr_value += ( ROTATION_INCREMENT * aSign );
|
|
|
|
curr_value = std::max( -MAX_ROTATION, curr_value );
|
|
|
|
curr_value = std::min( curr_value, MAX_ROTATION );
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
textCtrl->SetValue( formatRotationValue( curr_value ) );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::doIncrementOffset( wxSpinEvent& event, double aSign )
|
2017-02-06 19:49:29 +00:00
|
|
|
{
|
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
|
|
|
|
|
|
|
|
wxTextCtrl * textCtrl = xoff;
|
|
|
|
|
|
|
|
if( spinCtrl == m_spinYoffset )
|
|
|
|
textCtrl = yoff;
|
|
|
|
else if( spinCtrl == m_spinZoffset )
|
|
|
|
textCtrl = zoff;
|
|
|
|
|
2021-12-28 09:36:37 +00:00
|
|
|
double step_mm = OFFSET_INCREMENT_MM;
|
2022-09-16 04:38:10 +00:00
|
|
|
double curr_value_mm =
|
|
|
|
EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, textCtrl->GetValue() )
|
|
|
|
/ pcbIUScale.IU_PER_MM;
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2021-12-28 09:36:37 +00:00
|
|
|
if( m_userUnits == EDA_UNITS::MILS || m_userUnits == EDA_UNITS::INCHES )
|
|
|
|
{
|
|
|
|
step_mm = 25.4*OFFSET_INCREMENT_MIL/1000;
|
|
|
|
}
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-12-28 09:36:37 +00:00
|
|
|
curr_value_mm += ( step_mm * aSign );
|
|
|
|
curr_value_mm = std::max( -MAX_OFFSET, curr_value_mm );
|
|
|
|
curr_value_mm = std::min( curr_value_mm, MAX_OFFSET );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
2021-12-28 09:36:37 +00:00
|
|
|
textCtrl->SetValue( formatOffsetValue( curr_value_mm ) );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::onMouseWheelScale( wxMouseEvent& event )
|
2017-02-06 19:49:29 +00:00
|
|
|
{
|
|
|
|
wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject();
|
|
|
|
|
|
|
|
double step = SCALE_INCREMENT;
|
|
|
|
|
2017-03-02 18:58:14 +00:00
|
|
|
if( event.ShiftDown( ) )
|
|
|
|
step = SCALE_INCREMENT_FINE;
|
|
|
|
|
2017-02-06 19:49:29 +00:00
|
|
|
if( event.GetWheelRotation() >= 0 )
|
|
|
|
step = -step;
|
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::UNSCALED,
|
|
|
|
textCtrl->GetValue() );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
curr_value += step;
|
|
|
|
curr_value = std::max( 1/MAX_SCALE, curr_value );
|
|
|
|
curr_value = std::min( curr_value, MAX_SCALE );
|
|
|
|
|
|
|
|
textCtrl->SetValue( formatScaleValue( curr_value ) );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::onMouseWheelRot( wxMouseEvent& event )
|
2017-02-06 19:49:29 +00:00
|
|
|
{
|
|
|
|
wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject();
|
|
|
|
|
|
|
|
double step = ROTATION_INCREMENT_WHEEL;
|
|
|
|
|
2017-03-02 18:58:14 +00:00
|
|
|
if( event.ShiftDown( ) )
|
|
|
|
step = ROTATION_INCREMENT_WHEEL_FINE;
|
|
|
|
|
2017-02-06 19:49:29 +00:00
|
|
|
if( event.GetWheelRotation() >= 0 )
|
|
|
|
step = -step;
|
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::DEGREES,
|
2022-09-16 04:38:10 +00:00
|
|
|
textCtrl->GetValue() );
|
2018-03-28 17:14:04 +00:00
|
|
|
|
|
|
|
curr_value += step;
|
|
|
|
curr_value = std::max( -MAX_ROTATION, curr_value );
|
|
|
|
curr_value = std::min( curr_value, MAX_ROTATION );
|
|
|
|
|
|
|
|
textCtrl->SetValue( formatRotationValue( curr_value ) );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::onMouseWheelOffset( wxMouseEvent& event )
|
2017-02-06 19:49:29 +00:00
|
|
|
{
|
|
|
|
wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject();
|
|
|
|
|
2021-12-28 09:36:37 +00:00
|
|
|
double step_mm = OFFSET_INCREMENT_MM;
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2017-03-02 18:58:14 +00:00
|
|
|
if( event.ShiftDown( ) )
|
2021-12-28 09:36:37 +00:00
|
|
|
step_mm = OFFSET_INCREMENT_MM_FINE;
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2021-12-28 09:36:37 +00:00
|
|
|
if( m_userUnits == EDA_UNITS::MILS || m_userUnits == EDA_UNITS::INCHES )
|
2017-03-02 18:58:14 +00:00
|
|
|
{
|
2021-12-28 09:36:37 +00:00
|
|
|
step_mm = 25.4*OFFSET_INCREMENT_MIL/1000.0;
|
2020-03-24 01:01:23 +00:00
|
|
|
|
2017-03-02 18:58:14 +00:00
|
|
|
if( event.ShiftDown( ) )
|
2021-12-28 09:36:37 +00:00
|
|
|
step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000.0;
|
2017-03-02 18:58:14 +00:00
|
|
|
}
|
2017-02-06 19:49:29 +00:00
|
|
|
|
|
|
|
if( event.GetWheelRotation() >= 0 )
|
2021-12-28 09:36:37 +00:00
|
|
|
step_mm = -step_mm;
|
2017-02-06 19:49:29 +00:00
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
double curr_value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits,
|
|
|
|
textCtrl->GetValue() )
|
|
|
|
/ pcbIUScale.IU_PER_MM;
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2021-12-28 09:36:37 +00:00
|
|
|
curr_value_mm += step_mm;
|
|
|
|
curr_value_mm = std::max( -MAX_OFFSET, curr_value_mm );
|
|
|
|
curr_value_mm = std::min( curr_value_mm, MAX_OFFSET );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2021-12-28 09:36:37 +00:00
|
|
|
textCtrl->SetValue( formatOffsetValue( curr_value_mm ) );
|
2015-12-09 05:43:30 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void PANEL_PREVIEW_3D_MODEL::UpdateDummyFootprint( bool aReloadRequired )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-13 00:43:45 +00:00
|
|
|
m_dummyFootprint->Models().clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-02-17 14:06:19 +00:00
|
|
|
for( FP_3DMODEL& model : *m_parentModelList )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-04-10 21:48:48 +00:00
|
|
|
if( model.m_Show )
|
2020-11-13 00:43:45 +00:00
|
|
|
m_dummyFootprint->Models().push_back( model );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
if( aReloadRequired )
|
|
|
|
m_previewPane->ReloadRequest();
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
m_previewPane->Request_refresh();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|