KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_preview_3d_model.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2015 Cirilo Bernardo <[email protected]>
6 * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <3d_rendering/opengl/render_3d_opengl.h> // Must be included before any GL header
28
33#include <tool/tool_manager.h>
37#include <base_units.h>
38#include <bitmaps.h>
39#include <board.h>
41#include <dpi_scaling_common.h>
42#include <footprint.h>
43#include <lset.h>
44#include <pgm_base.h>
45#include <project_pcb.h>
48#include <widgets/wx_infobar.h>
52
53#if defined(__linux__) || defined(__FreeBSD__)
55#else
57#endif
58
59static wxString evaluateTextCtrl( const wxString& aValue )
60{
61 // NUMERIC_EVALUATOR doesn't handle UTF-8 multi-byte characters properly,
62 // so skip evaluation if the string contains non-ASCII characters (e.g., degree symbols)
63 for( wxUniChar c : aValue )
64 {
65 if( !c.IsAscii() )
66 return aValue;
67 }
68
69 // Attempt to evaluate formula; if successful return result, otherwise return original
71
72 if( eval.Process( aValue ) )
73 return eval.Result();
74
75 return aValue;
76}
77
78
84static double rotationFromString( const wxString& aValue )
85{
87
88 if( rotation > MAX_ROTATION )
89 {
90 int n = KiROUND( rotation / MAX_ROTATION );
91 rotation -= MAX_ROTATION * n;
92 }
93 else if( rotation < -MAX_ROTATION )
94 {
95 int n = KiROUND( -rotation / MAX_ROTATION );
96 rotation += MAX_ROTATION * n;
97 }
98
99 return rotation;
100}
101
102
104 std::vector<FP_3DMODEL>* aParentModelList ) :
106 m_parentFrame( aFrame ),
107 m_previewPane( nullptr ),
108 m_infobar( nullptr ),
112{
113 m_userUnits = m_parentFrame->GetUserUnits();
114
115 m_dummyBoard = new BOARD();
116
117 m_dummyBoard->SetProject( &aFrame->Prj(), true );
118 m_dummyBoard->SetEmbeddedFilesDelegate( aFrame->GetBoard() );
119
120 // This board will only be used to hold a footprint for viewing
121 m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
122
123 BOARD_DESIGN_SETTINGS parent_bds = aFrame->GetDesignSettings();
124 BOARD_DESIGN_SETTINGS& dummy_bds = m_dummyBoard->GetDesignSettings();
125 dummy_bds.SetBoardThickness( parent_bds.GetBoardThickness() );
127 BOARD_STACKUP& dummy_board_stackup = m_dummyBoard->GetDesignSettings().GetStackupDescriptor();
128 dummy_board_stackup.RemoveAll();
129 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
130
131 m_selected = -1;
132
133 m_previewLabel->SetFont( KIUI::GetStatusFont( this ) );
134
135 // Set the bitmap of 3D view buttons:
142 m_bpvISO->SetBitmap( KiBitmapBundle( BITMAPS::ortho ) );
146
147 // Set the min and max values of spin buttons (mandatory on Linux)
148 // They are not used, so they are set to min and max 32 bits int values
149 // (the min and max values supported by a wxSpinButton)
150 // It avoids blocking the up or down arrows when reaching this limit after
151 // a few clicks.
152 wxSpinButton* spinButtonList[] =
153 {
157 };
158
159 for( wxSpinButton* button : spinButtonList )
160 button->SetRange(INT_MIN, INT_MAX );
161
162 for( TEXT_CTRL_EVAL* rotCtrl : { xrot, yrot, zrot } )
163 {
164 rotCtrl->SetCustomEval(
165 [&]( TEXT_CTRL_EVAL* aCtrl )
166 {
167 double value = rotationFromString( evaluateTextCtrl( aCtrl->GetValue() ) );
168 aCtrl->SetValue( formatRotationValue( value ) );
169 } );
170 }
171
172 for( TEXT_CTRL_EVAL* scaleCtrl : { xscale, yscale, zscale } )
173 {
174 scaleCtrl->SetCustomEval(
175 [&]( TEXT_CTRL_EVAL* aCtrl )
176 {
178 evaluateTextCtrl( aCtrl->GetValue() ) );
179 aCtrl->SetValue( formatScaleValue( value ) );
180 } );
181 }
182
183 m_parentModelList = aParentModelList;
184
185 m_dummyFootprint = new FOOTPRINT( *aFootprint );
186 m_dummyFootprint->SetParentGroup( nullptr );
187
188 // Ensure the footprint is shown like in Fp editor: rot 0, not flipped
189 // to avoid mistakes when setting the3D shape position/rotation
190 if( m_dummyFootprint->IsFlipped() )
192
193 m_dummyFootprint->SetOrientation( ANGLE_0 );
194
196
197 // Create the 3D canvas
200 PROJECT_PCB::Get3DCacheManager( &aFrame->Prj() ) );
201
202 try
203 {
204#if defined(__linux__) || defined(__FreeBSD__)
205 m_spaceMouse = std::make_unique<SPNAV_VIEWER_PLUGIN>( m_previewPane );
206#else
207 m_spaceMouse = std::make_unique<NL_FOOTPRINT_PROPERTIES_PLUGIN>( m_previewPane );
208#endif
209 m_spaceMouse->SetFocus( true );
210 }
211 catch( const std::system_error& e )
212 {
213 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
214 }
215
216 m_boardAdapter.SetBoard( m_dummyBoard );
217 m_boardAdapter.m_IsBoardView = false;
218
219 // Force display 3D models, regardless the 3D viewer options.
220 m_boardAdapter.m_IsPreviewer = true;
221
222 loadSettings();
223
224 // Don't show placeholder models in the footprint properties 3D preview
225 if( m_boardAdapter.m_Cfg )
226 m_boardAdapter.m_Cfg->m_Render.show_missing_models = false;
227
228 // Create the manager
230 m_toolManager->SetEnvironment( m_dummyBoard, nullptr, nullptr, nullptr, this );
231
234 m_previewPane->SetEventDispatcher( m_toolDispatcher );
235
236 // Register tools
237 m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
238 m_toolManager->InitTools();
239
240 // Run the viewer control tool, it is supposed to be always active
241 m_toolManager->InvokeTool( "3DViewer.Control" );
242
243 m_infobar = new WX_INFOBAR( this );
244 m_previewPane->SetInfoBar( m_infobar );
245
246 m_SizerPanelView->Add( m_infobar, 0, wxEXPAND, 0 );
247 m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 );
248
249 for( wxEventType eventType : { wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT } )
250 Connect( eventType, wxMenuEventHandler( PANEL_PREVIEW_3D_MODEL::OnMenuEvent ), nullptr, this );
251
252 aFrame->Connect( EDA_EVT_UNITS_CHANGED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL::onUnitsChanged ),
253 nullptr, this );
254
255 Bind( wxCUSTOM_PANEL_SHOWN_EVENT, &PANEL_PREVIEW_3D_MODEL::onPanelShownEvent, this );
256}
257
258
260{
261 // Shutdown all running tools
262 if( m_toolManager )
263 m_toolManager->ShutdownAllTools();
264
265 // Restore the 3D viewer Render settings, that can be modified by the panel tools
266 if( m_boardAdapter.m_Cfg )
267 m_boardAdapter.m_Cfg->m_Render = m_initialRender;
268
269 delete m_dummyBoard;
270 delete m_previewPane;
271}
272
273
274void PANEL_PREVIEW_3D_MODEL::OnMenuEvent( wxMenuEvent& aEvent )
275{
276 if( !m_toolDispatcher )
277 aEvent.Skip();
278 else
279 m_toolDispatcher->DispatchWxEvent( aEvent );
280}
281
282
284{
285 wxCHECK_RET( m_previewPane, wxT( "Cannot load settings to null canvas" ) );
286
287 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
288
289 // TODO(JE) use all control options
290 m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;
291
293 {
294 // Save the 3D viewer render settings, to restore it after closing the preview
295 m_initialRender = cfg->m_Render;
296
297 m_boardAdapter.m_Cfg = cfg;
298
299 m_previewPane->SetAnimationEnabled( cfg->m_Camera.animation_enabled );
300 m_previewPane->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier );
301 m_previewPane->SetProjectionMode( cfg->m_Camera.projection_mode );
302 }
303}
304
305
307{
308 return wxString::Format( wxT( "%.4f" ),
309 aValue );
310}
311
312
314{
315 // Sigh. Did we really need differentiated +/- 0.0?
316 if( aValue == -0.0 )
317 aValue = 0.0;
318
319 return wxString::Format( wxT( "%.2f%s" ),
320 aValue,
322}
323
324
326{
327 // Convert from internal units (mm) to user units
329 aValue /= 25.4;
330 else if( m_userUnits == EDA_UNITS::MILS )
331 aValue /= 25.4 / 1e3;
332
333 return wxString::Format( wxT( "%.6f%s" ),
334 aValue,
336}
337
338
340{
341 if( m_parentModelList && idx >= 0 && idx < (int) m_parentModelList->size() )
342 {
343 m_selected = idx;
344 const FP_3DMODEL& modelInfo = m_parentModelList->at( (unsigned) m_selected );
345
346 // Use ChangeValue() instead of SetValue(). It's not the user making the change, so we
347 // don't want to generate wxEVT_GRID_CELL_CHANGED events.
348 xscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.x ) );
349 yscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.y ) );
350 zscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.z ) );
351
352 // Rotation is stored in the file as positive-is-CW, but we use positive-is-CCW in the GUI
353 // to match the rest of KiCad
354 xrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.x ) );
355 yrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.y ) );
356 zrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.z ) );
357
358 xoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.x ) );
359 yoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.y ) );
360 zoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.z ) );
361
362 m_opacity->SetValue( modelInfo.m_Opacity * 100.0 );
363 }
364 else
365 {
366 m_selected = -1;
367
368 xscale->ChangeValue( wxEmptyString );
369 yscale->ChangeValue( wxEmptyString );
370 zscale->ChangeValue( wxEmptyString );
371
372 xrot->ChangeValue( wxEmptyString );
373 yrot->ChangeValue( wxEmptyString );
374 zrot->ChangeValue( wxEmptyString );
375
376 xoff->ChangeValue( wxEmptyString );
377 yoff->ChangeValue( wxEmptyString );
378 zoff->ChangeValue( wxEmptyString );
379
380 m_opacity->SetValue( 100 );
381 }
382}
383
384
386{
387 m_extrudedBody = aBody;
388
389 if( aBody )
390 {
391 xscale->ChangeValue( formatScaleValue( aBody->m_scale.x ) );
392 yscale->ChangeValue( formatScaleValue( aBody->m_scale.y ) );
393 zscale->ChangeValue( formatScaleValue( aBody->m_scale.z ) );
394
395 xrot->ChangeValue( formatRotationValue( -aBody->m_rotation.x ) );
396 yrot->ChangeValue( formatRotationValue( -aBody->m_rotation.y ) );
397 zrot->ChangeValue( formatRotationValue( -aBody->m_rotation.z ) );
398
399 xoff->ChangeValue( formatOffsetValue( aBody->m_offset.x ) );
400 yoff->ChangeValue( formatOffsetValue( aBody->m_offset.y ) );
401 zoff->ChangeValue( formatOffsetValue( aBody->m_offset.z ) );
402
403 m_opacity->SetValue( 100 );
404 m_opacity->Enable( false );
405 }
406 else
407 {
408 m_opacity->Enable( true );
409 }
410}
411
412
413void PANEL_PREVIEW_3D_MODEL::updateOrientation( wxCommandEvent &event )
414{
415 if( m_extrudedBody )
416 {
418 evaluateTextCtrl( xscale->GetValue() ) );
420 evaluateTextCtrl( yscale->GetValue() ) );
422 evaluateTextCtrl( zscale->GetValue() ) );
423
424 m_extrudedBody->m_rotation.x = -rotationFromString( evaluateTextCtrl( xrot->GetValue() ) );
425 m_extrudedBody->m_rotation.y = -rotationFromString( evaluateTextCtrl( yrot->GetValue() ) );
426 m_extrudedBody->m_rotation.z = -rotationFromString( evaluateTextCtrl( zrot->GetValue() ) );
427
429 evaluateTextCtrl( xoff->GetValue() ) )
430 / pcbIUScale.IU_PER_MM;
432 evaluateTextCtrl( yoff->GetValue() ) )
433 / pcbIUScale.IU_PER_MM;
435 evaluateTextCtrl( zoff->GetValue() ) )
436 / pcbIUScale.IU_PER_MM;
437
438 UpdateDummyFootprint( true );
439 onModify();
440 }
441 else if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
442 {
443 // Write settings back to the parent
444 FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
445
447 evaluateTextCtrl( xscale->GetValue() ) );
449 evaluateTextCtrl( yscale->GetValue() ) );
451 evaluateTextCtrl( zscale->GetValue() ) );
452
453 // Rotation is stored in the file as positive-is-CW, but we use positive-is-CCW in the GUI
454 // to match the rest of KiCad
455 modelInfo->m_Rotation.x = -rotationFromString( evaluateTextCtrl( xrot->GetValue() ) );
456 modelInfo->m_Rotation.y = -rotationFromString( evaluateTextCtrl( yrot->GetValue() ) );
457 modelInfo->m_Rotation.z = -rotationFromString( evaluateTextCtrl( zrot->GetValue() ) );
458
460 evaluateTextCtrl( xoff->GetValue() ) )
461 / pcbIUScale.IU_PER_MM;
463 evaluateTextCtrl( yoff->GetValue() ) )
464 / pcbIUScale.IU_PER_MM;
466 evaluateTextCtrl( zoff->GetValue() ) )
467 / pcbIUScale.IU_PER_MM;
468
469 // Update the dummy footprint for the preview
470 UpdateDummyFootprint( false );
471 onModify();
472 }
473}
474
475
476void PANEL_PREVIEW_3D_MODEL::onOpacitySlider( wxCommandEvent& event )
477{
478 if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
479 {
480 // Write settings back to the parent
481 FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
482
483 modelInfo->m_Opacity = m_opacity->GetValue() / 100.0;
484
485 // Update the dummy footprint for the preview
486 UpdateDummyFootprint( false );
487 onModify();
488 }
489}
490
491
492void PANEL_PREVIEW_3D_MODEL::setBodyStyleView( wxCommandEvent& event )
493{
494 // turn ON or OFF options to show the board body if OFF, solder paste, soldermask
495 // and board body are hidden, to allows a good view of the 3D model and its pads.
497
498 if( !cfg )
499 return;
500
502
503 m_previewPane->ReloadRequest();
504 m_previewPane->Refresh();
505}
506
507
508void PANEL_PREVIEW_3D_MODEL::View3DSettings( wxCommandEvent& event )
509{
510 BOARD_DESIGN_SETTINGS bds = m_dummyBoard->GetDesignSettings();
511 int thickness = bds.GetBoardThickness();
512
513 WX_UNIT_ENTRY_DIALOG dlg( m_parentFrame, _( "3D Preview Options" ), _( "Board thickness:" ), thickness );
514
515 if( dlg.ShowModal() != wxID_OK )
516 return;
517
518 bds.SetBoardThickness( dlg.GetValue() );
519
520 BOARD_STACKUP& boardStackup = m_dummyBoard->GetDesignSettings().GetStackupDescriptor();
521 boardStackup.RemoveAll();
522 boardStackup.BuildDefaultStackupList( &bds, 2 );
523
524 UpdateDummyFootprint( true );
525
526 m_previewPane->ReloadRequest();
527 m_previewPane->Refresh();
528}
529
530
531void PANEL_PREVIEW_3D_MODEL::doIncrementScale( wxSpinEvent& event, double aSign )
532{
533 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( event.GetEventObject() );
534
535 wxCHECK( spinCtrl, /* void */ );
536
537 wxTextCtrl * textCtrl = xscale;
538
539 if( spinCtrl == m_spinYscale )
540 textCtrl = yscale;
541 else if( spinCtrl == m_spinZscale )
542 textCtrl = zscale;
543
544 double step = SCALE_INCREMENT;
545
546 if( wxGetMouseState().ShiftDown( ) )
548
549 double value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::UNSCALED, textCtrl->GetValue() );
550
551 value += ( step * aSign );
552 value = std::max( 1/MAX_SCALE, value );
553 value = std::min( value, MAX_SCALE );
554
555 textCtrl->SetValue( formatScaleValue( value ) );
556}
557
558
559void PANEL_PREVIEW_3D_MODEL::doIncrementRotation( wxSpinEvent& aEvent, double aSign )
560{
561 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( aEvent.GetEventObject() );
562
563 wxCHECK( spinCtrl, /* void */ );
564
565 wxTextCtrl* textCtrl = xrot;
566
567 if( spinCtrl == m_spinYrot )
568 textCtrl = yrot;
569 else if( spinCtrl == m_spinZrot )
570 textCtrl = zrot;
571
572 double step = ROTATION_INCREMENT;
573
574 if( wxGetMouseState().ShiftDown( ) )
576
577 double value = rotationFromString( textCtrl->GetValue() );
578
579 value += ( step * aSign );
580
581 textCtrl->SetValue( formatRotationValue( value ) );
582}
583
584
585void PANEL_PREVIEW_3D_MODEL::doIncrementOffset( wxSpinEvent& event, double aSign )
586{
587 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( event.GetEventObject() );
588
589 wxCHECK( spinCtrl, /* void */ );
590
591 wxTextCtrl * textCtrl = xoff;
592
593 if( spinCtrl == m_spinYoffset )
594 textCtrl = yoff;
595 else if( spinCtrl == m_spinZoffset )
596 textCtrl = zoff;
597
598 double step_mm = OFFSET_INCREMENT_MM;
599
600 if( wxGetMouseState().ShiftDown( ) )
601 step_mm = OFFSET_INCREMENT_MM_FINE;
602
604 {
605 step_mm = 25.4*OFFSET_INCREMENT_MIL/1000;
606
607 if( wxGetMouseState().ShiftDown( ) )
608 step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000;;
609 }
610
611 double value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, textCtrl->GetValue() )
612 / pcbIUScale.IU_PER_MM;
613
614 value_mm += ( step_mm * aSign );
615 value_mm = std::max( -MAX_OFFSET, value_mm );
616 value_mm = std::min( value_mm, MAX_OFFSET );
617
618 textCtrl->SetValue( formatOffsetValue( value_mm ) );
619}
620
621
623{
624 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
625
626 wxCHECK( textCtrl, /* void */ );
627
628 double step = SCALE_INCREMENT;
629
630 if( event.ShiftDown( ) )
632
633 if( event.GetWheelRotation() >= 0 )
634 step = -step;
635
636 double value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::UNSCALED, textCtrl->GetValue() );
637
638 value += step;
639 value = std::max( 1/MAX_SCALE, value );
640 value = std::min( value, MAX_SCALE );
641
642 textCtrl->SetValue( formatScaleValue( value ) );
643}
644
645
647{
648 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
649
650 wxCHECK( textCtrl, /* void */ );
651
652 double step = ROTATION_INCREMENT;
653
654 if( event.ShiftDown( ) )
656
657 if( event.GetWheelRotation() >= 0 )
658 step = -step;
659
660 double value = rotationFromString( textCtrl->GetValue() );
661
662 value += step;
663
664 textCtrl->SetValue( formatRotationValue( value ) );
665}
666
667
669{
670 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
671
672 wxCHECK( textCtrl, /* void */ );
673
674 double step_mm = OFFSET_INCREMENT_MM;
675
676 if( event.ShiftDown( ) )
677 step_mm = OFFSET_INCREMENT_MM_FINE;
678
680 {
681 step_mm = 25.4*OFFSET_INCREMENT_MIL/1000.0;
682
683 if( event.ShiftDown( ) )
684 step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000.0;
685 }
686
687 if( event.GetWheelRotation() >= 0 )
688 step_mm = -step_mm;
689
690 double value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, textCtrl->GetValue() )
691 / pcbIUScale.IU_PER_MM;
692
693 value_mm += step_mm;
694 value_mm = std::max( -MAX_OFFSET, value_mm );
695 value_mm = std::min( value_mm, MAX_OFFSET );
696
697 textCtrl->SetValue( formatOffsetValue( value_mm ) );
698}
699
700
701void PANEL_PREVIEW_3D_MODEL::onUnitsChanged( wxCommandEvent& aEvent )
702{
704 / pcbIUScale.IU_PER_MM;
706 / pcbIUScale.IU_PER_MM;
708 / pcbIUScale.IU_PER_MM;
709
710 PCB_BASE_FRAME* frame = static_cast<PCB_BASE_FRAME*>( aEvent.GetClientData() );
711 m_userUnits = frame->GetUserUnits();
712
713 xoff->SetValue( formatOffsetValue( xoff_mm ) );
714 yoff->SetValue( formatOffsetValue( yoff_mm ) );
715 zoff->SetValue( formatOffsetValue( zoff_mm ) );
716
717 aEvent.Skip();
718}
719
720
721void PANEL_PREVIEW_3D_MODEL::onPanelShownEvent( wxCommandEvent& aEvent )
722{
723 if( m_spaceMouse )
724 {
725 m_spaceMouse->SetFocus( static_cast<bool>( aEvent.GetInt() ) );
726 }
727
728 aEvent.Skip();
729}
730
731
733{
734 m_dummyFootprint->Models().clear();
735
737 {
738 if( model.m_Show )
739 m_dummyFootprint->Models().push_back( model );
740 }
741
742 if( m_extrudedBody && !m_dummyFootprint->HasExtrudedBody() )
743 m_extrudedBody = nullptr;
744
745 if( aReloadRequired )
746 m_previewPane->ReloadRequest();
747
748 m_previewPane->Request_refresh();
749}
750
751
753{
754 m_dummyBoard->SetEmbeddedFilesDelegate( aDelegate );
755}
756
757
759{
760 KIWAY_HOLDER* kiwayHolder = dynamic_cast<KIWAY_HOLDER*>( wxGetTopLevelParent( this ) );
761
762 if( kiwayHolder && kiwayHolder->GetType() == KIWAY_HOLDER::DIALOG )
763 static_cast<DIALOG_SHIM*>( kiwayHolder )->OnModify();
764}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:125
constexpr EDA_IU_SCALE unityScale
Definition base_units.h:128
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
@ show_board_body
@ options_3drender
@ FPHOLDER
Definition board.h:315
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
Container for design settings for a BOARD object.
void SetEnabledLayers(const LSET &aMask)
Change the bit-mask of enabled layers to aMask.
int GetBoardThickness() const
The full thickness of the board including copper and masks.
void SetBoardThickness(int aThickness)
Manage layers needed to make a physical board.
void RemoveAll()
Delete all items in list and clear the list.
void BuildDefaultStackupList(const BOARD_DESIGN_SETTINGS *aSettings, int aActiveCopperLayersCount=0)
Create a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:68
int ShowModal() override
EDA_3D_ACTIONS.
Implement a canvas based on a wxGLCanvas.
Handle view actions for various 3D canvases.
VECTOR3D m_offset
Definition footprint.h:116
VECTOR3D m_rotation
Definition footprint.h:115
VECTOR3D m_scale
Definition footprint.h:114
VECTOR3D m_Offset
3D model offset (mm)
Definition footprint.h:173
double m_Opacity
Definition footprint.h:174
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition footprint.h:172
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
Definition footprint.h:171
A mix in class which holds the location of a wxWindow's KIWAY.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
HOLDER_TYPE GetType() const
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition lset.cpp:722
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition lset.cpp:729
wxString Result() const
bool Process(const wxString &aString)
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
PANEL_PREVIEW_3D_MODEL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxString formatOffsetValue(double aValue)
void onMouseWheelRot(wxMouseEvent &event) override
void View3DSettings(wxCommandEvent &event) override
void onOpacitySlider(wxCommandEvent &event) override
void setBodyStyleView(wxCommandEvent &event) override
void onMouseWheelScale(wxMouseEvent &event) override
EDA_3D_VIEWER_SETTINGS::RENDER_SETTINGS m_initialRender
The 3d viewer Render initial settings (must be saved and restored)
void UpdateDummyFootprint(bool aRelaodRequired=true)
Copy shapes from the current shape list which are flagged for preview to the copy of footprint that i...
wxString formatScaleValue(double aValue)
void doIncrementRotation(wxSpinEvent &aEvent, double aSign)
void loadSettings()
Load 3D relevant settings from the user configuration.
void OnMenuEvent(wxMenuEvent &aEvent)
The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu events aren't ...
void onUnitsChanged(wxCommandEvent &aEvent)
void doIncrementOffset(wxSpinEvent &aEvent, double aSign)
PANEL_PREVIEW_3D_MODEL(wxWindow *aParent, PCB_BASE_FRAME *aFrame, FOOTPRINT *aFootprint, std::vector< FP_3DMODEL > *aParentModelList)
void SetEmbeddedFilesDelegate(EMBEDDED_FILES *aDelegate)
EXTRUDED_3D_BODY * m_extrudedBody
void SetExtrusionTransformMode(EXTRUDED_3D_BODY *aBody)
void doIncrementScale(wxSpinEvent &aEvent, double aSign)
void updateOrientation(wxCommandEvent &event) override
It will receive the events from editing the fields.
wxString formatRotationValue(double aValue)
void onMouseWheelOffset(wxMouseEvent &event) override
std::unique_ptr< NL_FOOTPRINT_PROPERTIES_PLUGIN > m_spaceMouse
void onPanelShownEvent(wxCommandEvent &aEvent)
void SetSelectedModel(int idx)
Set the currently selected index in the model list so that the scale/rotation/offset controls can be ...
std::vector< FP_3DMODEL > * m_parentModelList
EDA_UNITS m_userUnits
Index into m_parentInfoList.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Return the BOARD_DESIGN_SETTINGS for the open project.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:541
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
wxTextCtrl wrapper to handle math expression evaluation.
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer and display it in the wxTextCtrl.
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
ACTIONS * m_actions
Master controller class:
EDA_UNITS GetUserUnits() const
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
An extension of WX_TEXT_ENTRY_DIALOG that uses UNIT_BINDER to request a dimension (e....
int GetValue()
Return the value in internal units.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:29
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
KICOMMON_API wxString GetText(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
declaration of the nl_footprint_properties_plugin class
Declaration of the cogl_att_list class.
static double rotationFromString(const wxString &aValue)
Ensure -MAX_ROTATION <= rotation <= MAX_ROTATION.
static wxString evaluateTextCtrl(const wxString &aValue)
#define MAX_SCALE
#define MAX_ROTATION
#define MAX_OFFSET
#define OFFSET_INCREMENT_MM_FINE
#define OFFSET_INCREMENT_MIL
#define SCALE_INCREMENT
#define ROTATION_INCREMENT_FINE
#define OFFSET_INCREMENT_MM
#define ROTATION_INCREMENT
#define OFFSET_INCREMENT_MIL_FINE
#define SCALE_INCREMENT_FINE
#define PANEL_PREVIEW_3D_MODEL_ID
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
T * GetAppSettings(const char *aFilename)
KIBIS_MODEL * model