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
|
2018-01-13 01:58:44 +00:00
|
|
|
* Copyright (C) 2015-2018 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
|
|
|
|
*/
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
|
|
|
* @file panel_prev_model.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <3d_canvas/eda_3d_canvas.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
#include <common_ogl/cogl_att_list.h>
|
|
|
|
#include <cstdlib>
|
2017-02-07 10:05:08 +00:00
|
|
|
#include <limits.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2015-12-09 05:43:30 +00:00
|
|
|
#include <wx/valnum.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <wx/tglbtn.h>
|
2016-01-25 04:55:36 +00:00
|
|
|
|
|
|
|
#include "project.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
#include "panel_prev_model.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <class_board.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2017-02-19 07:30:34 +00:00
|
|
|
PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, S3D_CACHE* aCacheManager,
|
2018-01-13 01:58:44 +00:00
|
|
|
MODULE* aModuleCopy,
|
|
|
|
COLORS_DESIGN_SETTINGS *aColors,
|
|
|
|
std::vector<MODULE_3D_SETTINGS> *aParentInfoList ) :
|
|
|
|
PANEL_PREV_3D_BASE( aParent, wxID_ANY )
|
|
|
|
{
|
|
|
|
initPanel();
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
// Initialize the color settings to draw the board and the footprint
|
|
|
|
if( aColors )
|
|
|
|
m_dummyBoard->SetColorsSettings( aColors );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static COLORS_DESIGN_SETTINGS defaultColors( FRAME_PCB_DISPLAY3D );
|
|
|
|
m_dummyBoard->SetColorsSettings( &defaultColors );
|
|
|
|
}
|
2017-08-05 14:37:51 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
if( NULL != aCacheManager )
|
|
|
|
m_resolver = aCacheManager->GetResolver();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
m_parentInfoList = aParentInfoList;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
m_dummyBoard->Add( (MODULE*)aModuleCopy );
|
|
|
|
m_copyModule = aModuleCopy;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
// Set 3d viewer configuration for preview
|
|
|
|
m_settings3Dviewer = new CINFO3D_VISU();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
// Create the 3D canvas
|
|
|
|
m_previewPane = new EDA_3D_CANVAS( this,
|
|
|
|
COGL_ATT_LIST::GetAttributesList( true ),
|
|
|
|
m_dummyBoard,
|
|
|
|
*m_settings3Dviewer,
|
|
|
|
aCacheManager );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
m_previewPane->Connect( wxEVT_ENTER_WINDOW,
|
|
|
|
wxMouseEventHandler( PANEL_PREV_3D::onEnterPreviewCanvas ),
|
|
|
|
NULL, this );
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2017-02-19 07:30:34 +00:00
|
|
|
PANEL_PREV_3D::~PANEL_PREV_3D()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2017-02-06 14:20:46 +00:00
|
|
|
m_previewPane->Disconnect( wxEVT_ENTER_WINDOW,
|
2018-01-13 01:58:44 +00:00
|
|
|
wxMouseEventHandler( PANEL_PREV_3D::onEnterPreviewCanvas ),
|
|
|
|
NULL, this );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2017-02-06 14:20:46 +00:00
|
|
|
delete m_settings3Dviewer;
|
2016-07-19 17:35:25 +00:00
|
|
|
delete m_dummyBoard;
|
|
|
|
delete m_previewPane;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-19 07:30:34 +00:00
|
|
|
void PANEL_PREV_3D::initPanel()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2017-02-06 14:20:46 +00:00
|
|
|
m_resolver = NULL;
|
|
|
|
currentModelFile.clear();
|
|
|
|
m_dummyBoard = new BOARD();
|
|
|
|
m_currentSelectedIdx = -1;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2017-02-07 09:26:03 +00:00
|
|
|
// Set the bitmap of 3D view buttons:
|
2017-02-06 14:20:46 +00:00
|
|
|
m_bpvTop->SetBitmap( KiBitmap( axis3d_top_xpm ) );
|
|
|
|
m_bpvFront->SetBitmap( KiBitmap( axis3d_front_xpm ) );
|
|
|
|
m_bpvBack->SetBitmap( KiBitmap( axis3d_back_xpm ) );
|
|
|
|
m_bpvLeft->SetBitmap( KiBitmap( axis3d_left_xpm ) );
|
|
|
|
m_bpvRight->SetBitmap( KiBitmap( axis3d_right_xpm ) );
|
|
|
|
m_bpvBottom->SetBitmap( KiBitmap( axis3d_bottom_xpm ) );
|
|
|
|
m_bpvISO->SetBitmap( KiBitmap( ortho_xpm ) );
|
|
|
|
m_bpUpdate->SetBitmap( KiBitmap( reload_xpm ) );
|
2017-02-07 09:26:03 +00:00
|
|
|
|
|
|
|
// Set the min and max values of spin buttons (mandatory on Linux)
|
2017-02-07 10:05:08 +00:00
|
|
|
// 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.
|
2017-02-07 09:26:03 +00:00
|
|
|
wxSpinButton* spinButtonList[] =
|
|
|
|
{
|
|
|
|
m_spinXscale, m_spinYscale, m_spinZscale,
|
|
|
|
m_spinXrot, m_spinYrot, m_spinZrot,
|
|
|
|
m_spinXoffset,m_spinYoffset, m_spinZoffset
|
|
|
|
};
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 9; ii++ )
|
2017-11-08 09:56:57 +00:00
|
|
|
{
|
2017-02-07 10:05:08 +00:00
|
|
|
spinButtonList[ii]->SetRange( INT_MIN, INT_MAX );
|
2017-11-08 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString units;
|
|
|
|
|
|
|
|
switch( g_UserUnit )
|
|
|
|
{
|
|
|
|
case INCHES:
|
|
|
|
units = _( "inches" );
|
|
|
|
break;
|
|
|
|
case MILLIMETRES:
|
|
|
|
units = _( "mm" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !units.IsEmpty() )
|
|
|
|
{
|
|
|
|
units = wxString::Format( _( "Offset (%s)" ), units );
|
2018-01-11 16:59:18 +00:00
|
|
|
m_staticTextOffset->SetLabel( units );
|
2017-11-08 09:56:57 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-06 14:20:46 +00:00
|
|
|
/**
|
2017-02-06 20:28:35 +00:00
|
|
|
* @brief checkRotation
|
|
|
|
* Ensure -MAX_ROTATION <= rotation <= MAX_ROTATION
|
|
|
|
* aRotation will be normalized between -MAX_ROTATION and MAX_ROTATION
|
|
|
|
* @param aRotation: in out parameter
|
2017-02-06 14:20:46 +00:00
|
|
|
*/
|
2017-02-06 20:28:35 +00:00
|
|
|
static void checkRotation( double& aRotation )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2017-02-06 20:28:35 +00:00
|
|
|
if( aRotation > MAX_ROTATION )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2017-02-06 20:28:35 +00:00
|
|
|
int n = aRotation / MAX_ROTATION;
|
|
|
|
aRotation -= MAX_ROTATION * n;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2017-02-06 20:28:35 +00:00
|
|
|
else if( aRotation < -MAX_ROTATION )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2017-02-06 20:28:35 +00:00
|
|
|
int n = -aRotation / MAX_ROTATION;
|
|
|
|
aRotation += MAX_ROTATION * n;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2017-02-06 19:49:29 +00:00
|
|
|
static bool validateFloatTextCtrl( wxTextCtrl* aTextCtrl )
|
2018-01-13 01:58:44 +00:00
|
|
|
{
|
2017-02-06 19:49:29 +00:00
|
|
|
if( aTextCtrl == NULL )
|
|
|
|
return false;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2017-02-06 19:49:29 +00:00
|
|
|
if( aTextCtrl->GetLineLength(0) == 0 ) // This will skip the got and event with empty field
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aTextCtrl->GetLineLength(0) == 1 )
|
|
|
|
{
|
|
|
|
if( (aTextCtrl->GetLineText(0).compare( "." ) == 0) ||
|
|
|
|
(aTextCtrl->GetLineText(0).compare( "," ) == 0) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
|
2017-02-06 19:49:29 +00:00
|
|
|
static void incrementTextCtrl( wxTextCtrl* aTextCtrl, double aInc, double aMinval, double aMaxval )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2017-02-06 19:49:29 +00:00
|
|
|
if( !validateFloatTextCtrl( aTextCtrl ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
double curr_value = 0;
|
|
|
|
|
|
|
|
aTextCtrl->GetValue().ToDouble( &curr_value );
|
|
|
|
curr_value += aInc;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
if( curr_value > aMaxval )
|
|
|
|
curr_value = aMaxval;
|
|
|
|
|
|
|
|
if( curr_value < aMinval )
|
|
|
|
curr_value = aMinval;
|
2017-02-06 19:49:29 +00:00
|
|
|
|
|
|
|
aTextCtrl->SetValue( wxString::Format( "%.4f", curr_value ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
void PANEL_PREV_3D::SetModelDataIdx( int idx, bool aReloadPreviewModule )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
wxASSERT( m_parentInfoList != NULL );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_parentInfoList && (idx >= 0) )
|
2016-01-23 21:37:28 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
wxASSERT( (unsigned int)idx < (*m_parentInfoList).size() );
|
2016-01-23 21:37:28 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( (unsigned int)idx < (*m_parentInfoList).size() )
|
|
|
|
{
|
|
|
|
m_currentSelectedIdx = -1; // In case that we receive events on the
|
|
|
|
// next updates, it will set first an
|
|
|
|
// invalid selection
|
|
|
|
|
2017-10-27 14:25:20 +00:00
|
|
|
const MODULE_3D_SETTINGS *aModel = (const MODULE_3D_SETTINGS *)&((*m_parentInfoList)[idx]);
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
xscale->SetValue( wxString::Format( "%.4f", aModel->m_Scale.x ) );
|
|
|
|
yscale->SetValue( wxString::Format( "%.4f", aModel->m_Scale.y ) );
|
|
|
|
zscale->SetValue( wxString::Format( "%.4f", aModel->m_Scale.z ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
xrot->SetValue( wxString::Format( "%.2f", aModel->m_Rotation.x ) );
|
|
|
|
yrot->SetValue( wxString::Format( "%.2f", aModel->m_Rotation.y ) );
|
|
|
|
zrot->SetValue( wxString::Format( "%.2f", aModel->m_Rotation.z ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2017-11-08 09:56:57 +00:00
|
|
|
// Convert from internal units (mm) to user units
|
|
|
|
|
|
|
|
double scaler = 1;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
switch( g_UserUnit )
|
|
|
|
{
|
|
|
|
case MILLIMETRES:
|
2017-11-08 09:56:57 +00:00
|
|
|
scaler = 1.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
case INCHES:
|
2017-11-08 09:56:57 +00:00
|
|
|
scaler = 25.4f;
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-11-08 09:56:57 +00:00
|
|
|
wxASSERT( 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 09:56:57 +00:00
|
|
|
xoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.x / scaler ) );
|
|
|
|
yoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.y / scaler ) );
|
|
|
|
zoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.z / scaler ) );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
UpdateModelName( aModel->m_Filename );
|
|
|
|
|
|
|
|
if( aReloadPreviewModule && m_previewPane )
|
|
|
|
{
|
|
|
|
updateListOnModelCopy();
|
|
|
|
|
|
|
|
m_previewPane->ReloadRequest();
|
|
|
|
m_previewPane->Request_refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentSelectedIdx = idx;
|
|
|
|
}
|
2016-01-23 21:37:28 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_previewPane )
|
2017-11-08 09:56:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
m_previewPane->SetFocus();
|
2017-11-08 09:56:57 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
void PANEL_PREV_3D::ResetModelData( bool aReloadPreviewModule )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
m_currentSelectedIdx = -1;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
xscale->SetValue( wxString::FromDouble( 1.0 ) );
|
|
|
|
yscale->SetValue( wxString::FromDouble( 1.0 ) );
|
|
|
|
zscale->SetValue( wxString::FromDouble( 1.0 ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
xrot->SetValue( wxString::FromDouble( 0.0 ) );
|
|
|
|
yrot->SetValue( wxString::FromDouble( 0.0 ) );
|
|
|
|
zrot->SetValue( wxString::FromDouble( 0.0 ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
xoff->SetValue( wxString::FromDouble( 0.0 ) );
|
|
|
|
yoff->SetValue( wxString::FromDouble( 0.0 ) );
|
|
|
|
zoff->SetValue( wxString::FromDouble( 0.0 ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// This will update the model on the preview board with the current list of 3d shapes
|
|
|
|
if( aReloadPreviewModule )
|
|
|
|
{
|
|
|
|
updateListOnModelCopy();
|
|
|
|
|
|
|
|
if( m_previewPane )
|
|
|
|
{
|
|
|
|
m_previewPane->ReloadRequest();
|
|
|
|
m_previewPane->Request_refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_previewPane )
|
|
|
|
m_previewPane->SetFocus();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PREV_3D::UpdateModelName( wxString const& aModelName )
|
|
|
|
{
|
|
|
|
bool newModel = false;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_modelInfo.m_Filename = aModelName;
|
2016-01-25 04:55:36 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
// if the model name is a directory simply clear the current model
|
|
|
|
if( aModelName.empty() || wxFileName::DirExists( aModelName ) )
|
|
|
|
{
|
|
|
|
currentModelFile.clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
m_modelInfo.m_Filename.clear();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString newModelFile;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( m_resolver )
|
|
|
|
newModelFile = m_resolver->ResolvePath( aModelName );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-02-23 06:46:22 +00:00
|
|
|
if( !newModelFile.empty() && newModelFile.Cmp( currentModelFile ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
newModel = true;
|
|
|
|
|
|
|
|
currentModelFile = newModelFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( currentModelFile.empty() || newModel )
|
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
updateListOnModelCopy();
|
|
|
|
|
|
|
|
if( m_previewPane )
|
2015-12-09 05:43:30 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
m_previewPane->ReloadRequest();
|
|
|
|
m_previewPane->Refresh();
|
2015-12-09 05:43:30 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
if( currentModelFile.empty() )
|
|
|
|
return;
|
|
|
|
}
|
2016-01-25 04:55:36 +00:00
|
|
|
else
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_previewPane )
|
|
|
|
m_previewPane->Refresh();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_previewPane )
|
|
|
|
m_previewPane->SetFocus();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
wxTextCtrl *textCtrl = (wxTextCtrl *)event.GetEventObject();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( textCtrl == NULL )
|
|
|
|
return;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( textCtrl->GetLineLength(0) == 0 ) // This will skip the got and event with empty field
|
|
|
|
return;
|
2015-12-08 23:38:25 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( textCtrl->GetLineLength(0) == 1 )
|
|
|
|
if( (textCtrl->GetLineText(0).compare( "." ) == 0) ||
|
|
|
|
(textCtrl->GetLineText(0).compare( "," ) == 0) )
|
|
|
|
return;
|
2015-12-08 23:38:25 +00:00
|
|
|
|
2015-12-09 05:43:30 +00:00
|
|
|
SGPOINT scale;
|
|
|
|
SGPOINT rotation;
|
|
|
|
SGPOINT offset;
|
|
|
|
|
|
|
|
getOrientationVars( scale, rotation, offset );
|
|
|
|
|
2017-10-27 14:25:20 +00:00
|
|
|
m_modelInfo.m_Scale.x = scale.x;
|
|
|
|
m_modelInfo.m_Scale.y = scale.y;
|
|
|
|
m_modelInfo.m_Scale.z = scale.z;
|
|
|
|
m_modelInfo.m_Offset.x = offset.x;
|
|
|
|
m_modelInfo.m_Offset.y = offset.y;
|
|
|
|
m_modelInfo.m_Offset.z = offset.z;
|
|
|
|
m_modelInfo.m_Rotation.x = rotation.x;
|
|
|
|
m_modelInfo.m_Rotation.y = rotation.y;
|
|
|
|
m_modelInfo.m_Rotation.z = rotation.z;
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_currentSelectedIdx >= 0 )
|
|
|
|
{
|
|
|
|
// This will update the parent list with the new data
|
|
|
|
(*m_parentInfoList)[m_currentSelectedIdx] = m_modelInfo;
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// It will update the copy model in the preview board
|
|
|
|
updateListOnModelCopy();
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Since the OpenGL render does not need to be reloaded to update the
|
|
|
|
// shapes position, we just request to redraw again the canvas
|
|
|
|
if( m_previewPane )
|
|
|
|
m_previewPane->Refresh();
|
2015-12-09 05:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-06 19:49:29 +00:00
|
|
|
void PANEL_PREV_3D::onIncrementRot( wxSpinEvent& event )
|
|
|
|
{
|
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
|
|
|
|
|
|
|
|
wxTextCtrl * textCtrl = xrot;
|
|
|
|
|
|
|
|
if( spinCtrl == m_spinYrot )
|
|
|
|
textCtrl = yrot;
|
|
|
|
else if( spinCtrl == m_spinZrot )
|
|
|
|
textCtrl = zrot;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, ROTATION_INCREMENT, -MAX_ROTATION, MAX_ROTATION );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PREV_3D::onDecrementRot( wxSpinEvent& event )
|
|
|
|
{
|
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
|
|
|
|
|
|
|
|
wxTextCtrl * textCtrl = xrot;
|
|
|
|
|
|
|
|
if( spinCtrl == m_spinYrot )
|
|
|
|
textCtrl = yrot;
|
|
|
|
else if( spinCtrl == m_spinZrot )
|
|
|
|
textCtrl = zrot;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, -ROTATION_INCREMENT, -MAX_ROTATION, MAX_ROTATION );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PREV_3D::onIncrementScale( wxSpinEvent& event )
|
|
|
|
{
|
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
|
|
|
|
|
|
|
|
wxTextCtrl * textCtrl = xscale;
|
|
|
|
|
|
|
|
if( spinCtrl == m_spinYscale )
|
|
|
|
textCtrl = yscale;
|
|
|
|
else if( spinCtrl == m_spinZscale )
|
|
|
|
textCtrl = zscale;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, SCALE_INCREMENT, 1/MAX_SCALE, MAX_SCALE );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PREV_3D::onDecrementScale( wxSpinEvent& event )
|
|
|
|
{
|
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
|
|
|
|
|
|
|
|
wxTextCtrl * textCtrl = xscale;
|
|
|
|
|
|
|
|
if( spinCtrl == m_spinYscale )
|
|
|
|
textCtrl = yscale;
|
|
|
|
else if( spinCtrl == m_spinZscale )
|
|
|
|
textCtrl = zscale;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, -SCALE_INCREMENT, 1/MAX_SCALE, MAX_SCALE );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PREV_3D::onIncrementOffset( wxSpinEvent& event )
|
|
|
|
{
|
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
|
|
|
|
|
|
|
|
wxTextCtrl * textCtrl = xoff;
|
|
|
|
|
|
|
|
if( spinCtrl == m_spinYoffset )
|
|
|
|
textCtrl = yoff;
|
|
|
|
else if( spinCtrl == m_spinZoffset )
|
|
|
|
textCtrl = zoff;
|
|
|
|
|
|
|
|
double step = OFFSET_INCREMENT_MM;
|
|
|
|
|
|
|
|
if( g_UserUnit == INCHES )
|
|
|
|
step = OFFSET_INCREMENT_MIL/1000.0;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, step, -MAX_OFFSET, MAX_OFFSET );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PREV_3D::onDecrementOffset( wxSpinEvent& event )
|
|
|
|
{
|
|
|
|
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();
|
|
|
|
|
|
|
|
wxTextCtrl * textCtrl = xoff;
|
|
|
|
|
|
|
|
if( spinCtrl == m_spinYoffset )
|
|
|
|
textCtrl = yoff;
|
|
|
|
else if( spinCtrl == m_spinZoffset )
|
|
|
|
textCtrl = zoff;
|
|
|
|
|
|
|
|
double step = OFFSET_INCREMENT_MM;
|
|
|
|
|
|
|
|
if( g_UserUnit == INCHES )
|
|
|
|
step = OFFSET_INCREMENT_MIL/1000.0;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, -step, -MAX_OFFSET, MAX_OFFSET );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PREV_3D::onMouseWheelScale( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, step, 1/MAX_SCALE, MAX_SCALE );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PREV_3D::onMouseWheelRot( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject();
|
|
|
|
|
2017-03-02 18:58:14 +00:00
|
|
|
wxKeyboardState kbdState;
|
|
|
|
|
2017-02-06 19:49:29 +00:00
|
|
|
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;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, step, -MAX_ROTATION, MAX_ROTATION );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2017-02-06 19:49:29 +00:00
|
|
|
void PANEL_PREV_3D::onMouseWheelOffset( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject();
|
|
|
|
|
|
|
|
double step = OFFSET_INCREMENT_MM;
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2017-03-02 18:58:14 +00:00
|
|
|
if( event.ShiftDown( ) )
|
|
|
|
step = OFFSET_INCREMENT_MM_FINE;
|
2017-02-06 19:49:29 +00:00
|
|
|
|
|
|
|
if( g_UserUnit == INCHES )
|
2017-03-02 18:58:14 +00:00
|
|
|
{
|
2017-02-06 19:49:29 +00:00
|
|
|
step = OFFSET_INCREMENT_MIL/1000.0;
|
2017-03-02 18:58:14 +00:00
|
|
|
if( event.ShiftDown( ) )
|
|
|
|
step = OFFSET_INCREMENT_MIL_FINE/1000.0;
|
|
|
|
}
|
2017-02-06 19:49:29 +00:00
|
|
|
|
|
|
|
if( event.GetWheelRotation() >= 0 )
|
|
|
|
step = -step;
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
incrementTextCtrl( textCtrl, step, -MAX_OFFSET, MAX_OFFSET );
|
2017-02-06 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
void PANEL_PREV_3D::getOrientationVars( SGPOINT& aScale, SGPOINT& aRotation, SGPOINT& aOffset )
|
2015-12-09 05:43:30 +00:00
|
|
|
{
|
|
|
|
if( NULL == xscale || NULL == yscale || NULL == zscale
|
|
|
|
|| NULL == xrot || NULL == yrot || NULL == zrot
|
|
|
|
|| NULL == xoff || NULL == yoff || NULL == zoff )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
xscale->GetValue().ToDouble( &aScale.x );
|
|
|
|
yscale->GetValue().ToDouble( &aScale.y );
|
|
|
|
zscale->GetValue().ToDouble( &aScale.z );
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
xrot->GetValue().ToDouble( &aRotation.x );
|
|
|
|
yrot->GetValue().ToDouble( &aRotation.y );
|
|
|
|
zrot->GetValue().ToDouble( &aRotation.z );
|
2016-01-12 06:09:04 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
checkRotation( aRotation.x );
|
|
|
|
checkRotation( aRotation.y );
|
|
|
|
checkRotation( aRotation.z );
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
xoff->GetValue().ToDouble( &aOffset.x );
|
|
|
|
yoff->GetValue().ToDouble( &aOffset.y );
|
|
|
|
zoff->GetValue().ToDouble( &aOffset.z );
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2017-11-08 09:56:57 +00:00
|
|
|
// Convert from user units to internal units (mm)
|
|
|
|
|
|
|
|
double scaler = 1.0f;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
switch( g_UserUnit )
|
|
|
|
{
|
|
|
|
case MILLIMETRES:
|
2017-11-08 09:56:57 +00:00
|
|
|
scaler = 1.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
case INCHES:
|
2017-11-08 09:56:57 +00:00
|
|
|
scaler = 25.4f;
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-11-08 09:56:57 +00:00
|
|
|
wxASSERT( 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-09 05:43:30 +00:00
|
|
|
|
2017-11-08 09:56:57 +00:00
|
|
|
aOffset.x *= scaler;
|
|
|
|
aOffset.y *= scaler;
|
|
|
|
aOffset.z *= scaler;
|
|
|
|
|
2015-12-09 05:43:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
|
2016-09-30 05:51:18 +00:00
|
|
|
bool PANEL_PREV_3D::ValidateWithMessage( wxString& aErrorMessage )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2016-08-05 19:30:23 +00:00
|
|
|
bool invalidScale = false;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
for( unsigned int idx = 0; idx < m_parentInfoList->size(); ++idx )
|
|
|
|
{
|
2016-08-05 19:30:23 +00:00
|
|
|
wxString msg;
|
|
|
|
bool addError = false;
|
2017-10-27 14:25:20 +00:00
|
|
|
MODULE_3D_SETTINGS& s3dshape = (*m_parentInfoList)[idx];
|
2016-08-05 19:30:23 +00:00
|
|
|
|
2017-10-27 14:25:20 +00:00
|
|
|
SGPOINT scale;
|
|
|
|
scale.x = s3dshape.m_Scale.x;
|
|
|
|
scale.y = s3dshape.m_Scale.y;
|
|
|
|
scale.z = s3dshape.m_Scale.z;
|
2016-08-05 19:30:23 +00:00
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
if( 1/MAX_SCALE > scale.x || MAX_SCALE < scale.x )
|
2016-08-05 19:30:23 +00:00
|
|
|
{
|
|
|
|
invalidScale = true;
|
|
|
|
addError = true;
|
|
|
|
msg += _( "Invalid X scale" );
|
|
|
|
}
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
if( 1/MAX_SCALE > scale.y || MAX_SCALE < scale.y )
|
2016-08-05 19:30:23 +00:00
|
|
|
{
|
|
|
|
invalidScale = true;
|
|
|
|
addError = true;
|
|
|
|
|
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
msg += "\n";
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
msg += _( "Invalid Y scale" );
|
|
|
|
}
|
|
|
|
|
2017-02-06 20:28:35 +00:00
|
|
|
if( 1/MAX_SCALE > scale.z || MAX_SCALE < scale.z )
|
2016-08-05 19:30:23 +00:00
|
|
|
{
|
|
|
|
invalidScale = true;
|
|
|
|
addError = true;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
msg += "\n";
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
msg += _( "Invalid Z scale" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( addError )
|
|
|
|
{
|
|
|
|
msg.Prepend( s3dshape.m_Filename + "\n" );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
if( !aErrorMessage.IsEmpty() )
|
|
|
|
aErrorMessage += "\n\n";
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
aErrorMessage += msg;
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
if( !aErrorMessage.IsEmpty() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2016-08-05 19:30:23 +00:00
|
|
|
aErrorMessage += "\n\n";
|
|
|
|
aErrorMessage += wxString::Format( "Min value = %.4f and max value = %.4f",
|
2017-02-06 20:28:35 +00:00
|
|
|
1/MAX_SCALE, MAX_SCALE );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
return invalidScale == false;
|
|
|
|
}
|
|
|
|
|
2018-01-13 01:58:44 +00:00
|
|
|
|
2016-08-05 19:30:23 +00:00
|
|
|
void PANEL_PREV_3D::updateListOnModelCopy()
|
|
|
|
{
|
2017-10-27 14:25:20 +00:00
|
|
|
auto draw3D = &m_copyModule->Models();
|
2016-07-19 17:35:25 +00:00
|
|
|
draw3D->clear();
|
|
|
|
draw3D->insert( draw3D->end(), m_parentInfoList->begin(), m_parentInfoList->end() );
|
|
|
|
}
|