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, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <3d_rendering/opengl/render_3d_opengl.h> // Must be included before any GL header
24
25#include <cmath>
26
31#include <tool/tool_manager.h>
35#include <base_units.h>
36#include <bitmaps.h>
37#include <board.h>
39#include <dpi_scaling_common.h>
40#include <footprint.h>
41#include <lset.h>
42#include <pgm_base.h>
43#include <project_pcb.h>
46#include <widgets/wx_infobar.h>
50
51#if defined(__linux__) || defined(__FreeBSD__)
53#else
55#endif
56
57static wxString evaluateTextCtrl( const wxString& aValue )
58{
59 // NUMERIC_EVALUATOR doesn't handle UTF-8 multi-byte characters properly,
60 // so skip evaluation if the string contains non-ASCII characters (e.g., degree symbols)
61 for( wxUniChar c : aValue )
62 {
63 if( !c.IsAscii() )
64 return aValue;
65 }
66
67 // Attempt to evaluate formula; if successful return result, otherwise return original
69
70 if( eval.Process( aValue ) )
71 return eval.Result();
72
73 return aValue;
74}
75
76
83static double normalizeRotation( double aRotation )
84{
85 double normalized = std::fmod( aRotation, 2.0 * MAX_ROTATION );
86
87 if( normalized <= -MAX_ROTATION )
88 normalized += 2.0 * MAX_ROTATION;
89 else if( normalized > MAX_ROTATION )
90 normalized -= 2.0 * MAX_ROTATION;
91
92 if( normalized == -0.0 )
93 normalized = 0.0;
94
95 return normalized;
96}
97
98
99static double rotationFromString( const wxString& aValue )
100{
102
103 return normalizeRotation( rotation );
104}
105
106
108 std::vector<FP_3DMODEL>* aParentModelList ) :
110 m_parentFrame( aFrame ),
111 m_previewPane( nullptr ),
112 m_infobar( nullptr ),
116{
117 m_userUnits = m_parentFrame->GetUserUnits();
118
119 m_dummyBoard = new BOARD();
120
121 m_dummyBoard->SetProject( &aFrame->Prj(), true );
122 m_dummyBoard->SetEmbeddedFilesDelegate( aFrame->GetBoard() );
123
124 // This board will only be used to hold a footprint for viewing
125 m_dummyBoard->SetBoardUse( BOARD_USE::FPHOLDER );
126
127 BOARD_DESIGN_SETTINGS parent_bds = aFrame->GetDesignSettings();
128 BOARD_DESIGN_SETTINGS& dummy_bds = m_dummyBoard->GetDesignSettings();
129 dummy_bds.SetBoardThickness( parent_bds.GetBoardThickness() );
131 BOARD_STACKUP& dummy_board_stackup = m_dummyBoard->GetDesignSettings().GetStackupDescriptor();
132 dummy_board_stackup.RemoveAll();
133 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
134
135 m_selected = -1;
136
137 m_previewLabel->SetFont( KIUI::GetStatusFont( this ) );
138
139 // Set the bitmap of 3D view buttons:
146 m_bpvISO->SetBitmap( KiBitmapBundle( BITMAPS::ortho ) );
150
151 // Set the min and max values of spin buttons (mandatory on Linux)
152 // They are not used, so they are set to min and max 32 bits int values
153 // (the min and max values supported by a wxSpinButton)
154 // It avoids blocking the up or down arrows when reaching this limit after
155 // a few clicks.
156 wxSpinButton* spinButtonList[] =
157 {
161 };
162
163 for( wxSpinButton* button : spinButtonList )
164 button->SetRange(INT_MIN, INT_MAX );
165
166 for( TEXT_CTRL_EVAL* rotCtrl : { xrot, yrot, zrot } )
167 {
168 rotCtrl->SetCustomEval(
169 [&]( TEXT_CTRL_EVAL* aCtrl )
170 {
171 double value = rotationFromString( evaluateTextCtrl( aCtrl->GetValue() ) );
172 aCtrl->SetValue( formatRotationValue( value ) );
173 } );
174 }
175
176 for( TEXT_CTRL_EVAL* scaleCtrl : { xscale, yscale, zscale } )
177 {
178 scaleCtrl->SetCustomEval(
179 [&]( TEXT_CTRL_EVAL* aCtrl )
180 {
182 evaluateTextCtrl( aCtrl->GetValue() ) );
183 aCtrl->SetValue( formatScaleValue( value ) );
184 } );
185 }
186
187 m_parentModelList = aParentModelList;
188
189 m_dummyFootprint = new FOOTPRINT( *aFootprint );
190 m_dummyFootprint->SetParentGroup( nullptr );
191
192 // Ensure the footprint is shown like in Fp editor: rot 0, not flipped
193 // to avoid mistakes when setting the3D shape position/rotation
194 if( m_dummyFootprint->IsFlipped() )
196
197 m_dummyFootprint->SetOrientation( ANGLE_0 );
198
200
201 // Create the 3D canvas
204 PROJECT_PCB::Get3DCacheManager( &aFrame->Prj() ) );
205
206 try
207 {
208#if defined(__linux__) || defined(__FreeBSD__)
209 m_spaceMouse = std::make_unique<SPNAV_VIEWER_PLUGIN>( m_previewPane );
210#else
211 m_spaceMouse = std::make_unique<NL_FOOTPRINT_PROPERTIES_PLUGIN>( m_previewPane );
212#endif
213 m_spaceMouse->SetFocus( true );
214 }
215 catch( const std::exception& e )
216 {
217 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), wxS( "%s" ), e.what() );
218 }
219 catch( ... )
220 {
221 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ),
222 wxT( "Unknown exception during SpaceMouse initialization" ) );
223 }
224
225 m_boardAdapter.SetBoard( m_dummyBoard );
226 m_boardAdapter.m_IsBoardView = false;
227
228 // Force display 3D models, regardless the 3D viewer options.
229 m_boardAdapter.m_IsPreviewer = true;
230
231 loadSettings();
232
233 // Don't show placeholder models in the footprint properties 3D preview
234 if( m_boardAdapter.m_Cfg )
235 m_boardAdapter.m_Cfg->m_Render.show_missing_models = false;
236
237 // Create the manager
239 m_toolManager->SetEnvironment( m_dummyBoard, nullptr, nullptr, nullptr, this );
240
243 m_previewPane->SetEventDispatcher( m_toolDispatcher );
244
245 // Register tools
246 m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
247 m_toolManager->InitTools();
248
249 // Run the viewer control tool, it is supposed to be always active
250 m_toolManager->InvokeTool( "3DViewer.Control" );
251
252 m_infobar = new WX_INFOBAR( this );
253 m_previewPane->SetInfoBar( m_infobar );
254
255 m_SizerPanelView->Add( m_infobar, 0, wxEXPAND, 0 );
256 m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 );
257
258 for( wxEventType eventType : { wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT } )
259 Connect( eventType, wxMenuEventHandler( PANEL_PREVIEW_3D_MODEL::OnMenuEvent ), nullptr, this );
260
261 aFrame->Connect( EDA_EVT_UNITS_CHANGED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL::onUnitsChanged ),
262 nullptr, this );
263
264 Bind( wxCUSTOM_PANEL_SHOWN_EVENT, &PANEL_PREVIEW_3D_MODEL::onPanelShownEvent, this );
265}
266
267
269{
270 // Shutdown all running tools
271 if( m_toolManager )
272 m_toolManager->ShutdownAllTools();
273
274 // Restore the 3D viewer Render settings, that can be modified by the panel tools
275 if( m_boardAdapter.m_Cfg )
276 m_boardAdapter.m_Cfg->m_Render = m_initialRender;
277
278 delete m_dummyBoard;
279 delete m_previewPane;
280}
281
282
283void PANEL_PREVIEW_3D_MODEL::OnMenuEvent( wxMenuEvent& aEvent )
284{
285 if( !m_toolDispatcher )
286 aEvent.Skip();
287 else
288 m_toolDispatcher->DispatchWxEvent( aEvent );
289}
290
291
293{
294 wxCHECK_RET( m_previewPane, wxT( "Cannot load settings to null canvas" ) );
295
296 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
297
298 // TODO(JE) use all control options
299 m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;
300
302 {
303 // Save the 3D viewer render settings, to restore it after closing the preview
304 m_initialRender = cfg->m_Render;
305
306 m_boardAdapter.m_Cfg = cfg;
307
308 m_previewPane->SetAnimationEnabled( cfg->m_Camera.animation_enabled );
309 m_previewPane->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier );
310 m_previewPane->SetProjectionMode( cfg->m_Camera.projection_mode );
311 }
312}
313
314
316{
317 return wxString::Format( wxT( "%.4f" ),
318 aValue );
319}
320
321
323{
324 // Sigh. Did we really need differentiated +/- 0.0?
325 if( aValue == -0.0 )
326 aValue = 0.0;
327
328 return wxString::Format( wxT( "%.2f%s" ),
329 aValue,
331}
332
333
335{
336 // Convert from internal units (mm) to user units
338 aValue /= 25.4;
339 else if( m_userUnits == EDA_UNITS::MILS )
340 aValue /= 25.4 / 1e3;
341
342 return wxString::Format( wxT( "%.6f%s" ),
343 aValue,
345}
346
347
349{
350 if( m_parentModelList && idx >= 0 && idx < (int) m_parentModelList->size() )
351 {
352 m_selected = idx;
353 const FP_3DMODEL& modelInfo = m_parentModelList->at( (unsigned) m_selected );
354
355 // Use ChangeValue() instead of SetValue(). It's not the user making the change, so we
356 // don't want to generate wxEVT_GRID_CELL_CHANGED events.
357 xscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.x ) );
358 yscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.y ) );
359 zscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.z ) );
360
361 // Rotation is stored in the file as positive-is-CW, but we use positive-is-CCW in the GUI
362 // to match the rest of KiCad
363 xrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.x ) );
364 yrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.y ) );
365 zrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.z ) );
366
367 xoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.x ) );
368 yoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.y ) );
369 zoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.z ) );
370
371 m_opacity->SetValue( modelInfo.m_Opacity * 100.0 );
372 }
373 else
374 {
375 m_selected = -1;
376
377 xscale->ChangeValue( wxEmptyString );
378 yscale->ChangeValue( wxEmptyString );
379 zscale->ChangeValue( wxEmptyString );
380
381 xrot->ChangeValue( wxEmptyString );
382 yrot->ChangeValue( wxEmptyString );
383 zrot->ChangeValue( wxEmptyString );
384
385 xoff->ChangeValue( wxEmptyString );
386 yoff->ChangeValue( wxEmptyString );
387 zoff->ChangeValue( wxEmptyString );
388
389 m_opacity->SetValue( 100 );
390 }
391}
392
393
395{
396 m_extrudedBody = aBody;
397
398 if( aBody )
399 {
400 xscale->ChangeValue( formatScaleValue( aBody->m_scale.x ) );
401 yscale->ChangeValue( formatScaleValue( aBody->m_scale.y ) );
402 zscale->ChangeValue( formatScaleValue( aBody->m_scale.z ) );
403
404 xrot->ChangeValue( formatRotationValue( -aBody->m_rotation.x ) );
405 yrot->ChangeValue( formatRotationValue( -aBody->m_rotation.y ) );
406 zrot->ChangeValue( formatRotationValue( -aBody->m_rotation.z ) );
407
408 xoff->ChangeValue( formatOffsetValue( aBody->m_offset.x ) );
409 yoff->ChangeValue( formatOffsetValue( aBody->m_offset.y ) );
410 zoff->ChangeValue( formatOffsetValue( aBody->m_offset.z ) );
411
412 m_opacity->SetValue( 100 );
413 m_opacity->Enable( false );
414 }
415 else
416 {
417 m_opacity->Enable( true );
418 }
419}
420
421
422void PANEL_PREVIEW_3D_MODEL::updateOrientation( wxCommandEvent &event )
423{
424 if( m_extrudedBody )
425 {
427 evaluateTextCtrl( xscale->GetValue() ) );
429 evaluateTextCtrl( yscale->GetValue() ) );
431 evaluateTextCtrl( zscale->GetValue() ) );
432
433 m_extrudedBody->m_rotation.x = -rotationFromString( evaluateTextCtrl( xrot->GetValue() ) );
434 m_extrudedBody->m_rotation.y = -rotationFromString( evaluateTextCtrl( yrot->GetValue() ) );
435 m_extrudedBody->m_rotation.z = -rotationFromString( evaluateTextCtrl( zrot->GetValue() ) );
436
438 evaluateTextCtrl( xoff->GetValue() ) )
439 / pcbIUScale.IU_PER_MM;
441 evaluateTextCtrl( yoff->GetValue() ) )
442 / pcbIUScale.IU_PER_MM;
444 evaluateTextCtrl( zoff->GetValue() ) )
445 / pcbIUScale.IU_PER_MM;
446
447 UpdateDummyFootprint( true );
448 onModify();
449 }
450 else if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
451 {
452 // Write settings back to the parent
453 FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
454
456 evaluateTextCtrl( xscale->GetValue() ) );
458 evaluateTextCtrl( yscale->GetValue() ) );
460 evaluateTextCtrl( zscale->GetValue() ) );
461
462 // Rotation is stored in the file as positive-is-CW, but we use positive-is-CCW in the GUI
463 // to match the rest of KiCad
464 modelInfo->m_Rotation.x = -rotationFromString( evaluateTextCtrl( xrot->GetValue() ) );
465 modelInfo->m_Rotation.y = -rotationFromString( evaluateTextCtrl( yrot->GetValue() ) );
466 modelInfo->m_Rotation.z = -rotationFromString( evaluateTextCtrl( zrot->GetValue() ) );
467
469 evaluateTextCtrl( xoff->GetValue() ) )
470 / pcbIUScale.IU_PER_MM;
472 evaluateTextCtrl( yoff->GetValue() ) )
473 / pcbIUScale.IU_PER_MM;
475 evaluateTextCtrl( zoff->GetValue() ) )
476 / pcbIUScale.IU_PER_MM;
477
478 // Update the dummy footprint for the preview
479 UpdateDummyFootprint( false );
480 onModify();
481 }
482}
483
484
485void PANEL_PREVIEW_3D_MODEL::onOpacitySlider( wxCommandEvent& event )
486{
487 if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
488 {
489 // Write settings back to the parent
490 FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
491
492 modelInfo->m_Opacity = m_opacity->GetValue() / 100.0;
493
494 // Update the dummy footprint for the preview
495 UpdateDummyFootprint( false );
496 onModify();
497 }
498}
499
500
501void PANEL_PREVIEW_3D_MODEL::setBodyStyleView( wxCommandEvent& event )
502{
503 // turn ON or OFF options to show the board body if OFF, solder paste, soldermask
504 // and board body are hidden, to allows a good view of the 3D model and its pads.
506
507 if( !cfg )
508 return;
509
511
512 m_previewPane->ReloadRequest();
513 m_previewPane->Refresh();
514}
515
516
517void PANEL_PREVIEW_3D_MODEL::View3DSettings( wxCommandEvent& event )
518{
519 BOARD_DESIGN_SETTINGS bds = m_dummyBoard->GetDesignSettings();
520 int thickness = bds.GetBoardThickness();
521
522 WX_UNIT_ENTRY_DIALOG dlg( m_parentFrame, _( "3D Preview Options" ), _( "Board thickness:" ), thickness );
523
524 if( dlg.ShowModal() != wxID_OK )
525 return;
526
527 bds.SetBoardThickness( dlg.GetValue() );
528
529 BOARD_STACKUP& boardStackup = m_dummyBoard->GetDesignSettings().GetStackupDescriptor();
530 boardStackup.RemoveAll();
531 boardStackup.BuildDefaultStackupList( &bds, 2 );
532
533 UpdateDummyFootprint( true );
534
535 m_previewPane->ReloadRequest();
536 m_previewPane->Refresh();
537}
538
539
540void PANEL_PREVIEW_3D_MODEL::doIncrementScale( wxSpinEvent& event, double aSign )
541{
542 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( event.GetEventObject() );
543
544 wxCHECK( spinCtrl, /* void */ );
545
546 wxTextCtrl * textCtrl = xscale;
547
548 if( spinCtrl == m_spinYscale )
549 textCtrl = yscale;
550 else if( spinCtrl == m_spinZscale )
551 textCtrl = zscale;
552
553 double step = SCALE_INCREMENT;
554
555 if( wxGetMouseState().ShiftDown( ) )
557
558 double value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::UNSCALED, textCtrl->GetValue() );
559
560 value += ( step * aSign );
561 value = std::max( 1/MAX_SCALE, value );
562 value = std::min( value, MAX_SCALE );
563
564 textCtrl->SetValue( formatScaleValue( value ) );
565}
566
567
568void PANEL_PREVIEW_3D_MODEL::doIncrementRotation( wxSpinEvent& aEvent, double aSign )
569{
570 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( aEvent.GetEventObject() );
571
572 wxCHECK( spinCtrl, /* void */ );
573
574 wxTextCtrl* textCtrl = xrot;
575
576 if( spinCtrl == m_spinYrot )
577 textCtrl = yrot;
578 else if( spinCtrl == m_spinZrot )
579 textCtrl = zrot;
580
581 double step = ROTATION_INCREMENT;
582
583 if( wxGetMouseState().ShiftDown( ) )
585
586 double value = rotationFromString( textCtrl->GetValue() );
587
588 value = normalizeRotation( value + step * aSign );
589
590 textCtrl->SetValue( formatRotationValue( value ) );
591}
592
593
594void PANEL_PREVIEW_3D_MODEL::doIncrementOffset( wxSpinEvent& event, double aSign )
595{
596 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( event.GetEventObject() );
597
598 wxCHECK( spinCtrl, /* void */ );
599
600 wxTextCtrl * textCtrl = xoff;
601
602 if( spinCtrl == m_spinYoffset )
603 textCtrl = yoff;
604 else if( spinCtrl == m_spinZoffset )
605 textCtrl = zoff;
606
607 double step_mm = OFFSET_INCREMENT_MM;
608
609 if( wxGetMouseState().ShiftDown( ) )
610 step_mm = OFFSET_INCREMENT_MM_FINE;
611
613 {
614 step_mm = 25.4*OFFSET_INCREMENT_MIL/1000;
615
616 if( wxGetMouseState().ShiftDown( ) )
617 step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000;;
618 }
619
620 double value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, textCtrl->GetValue() )
621 / pcbIUScale.IU_PER_MM;
622
623 value_mm += ( step_mm * aSign );
624 value_mm = std::max( -MAX_OFFSET, value_mm );
625 value_mm = std::min( value_mm, MAX_OFFSET );
626
627 textCtrl->SetValue( formatOffsetValue( value_mm ) );
628}
629
630
632{
633 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
634
635 wxCHECK( textCtrl, /* void */ );
636
637 double step = SCALE_INCREMENT;
638
639 if( event.ShiftDown( ) )
641
642 if( event.GetWheelRotation() >= 0 )
643 step = -step;
644
645 double value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::UNSCALED, textCtrl->GetValue() );
646
647 value += step;
648 value = std::max( 1/MAX_SCALE, value );
649 value = std::min( value, MAX_SCALE );
650
651 textCtrl->SetValue( formatScaleValue( value ) );
652}
653
654
656{
657 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
658
659 wxCHECK( textCtrl, /* void */ );
660
661 double step = ROTATION_INCREMENT;
662
663 if( event.ShiftDown( ) )
665
666 if( event.GetWheelRotation() >= 0 )
667 step = -step;
668
669 double value = rotationFromString( textCtrl->GetValue() );
670
671 value = normalizeRotation( value + step );
672
673 textCtrl->SetValue( formatRotationValue( value ) );
674}
675
676
678{
679 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
680
681 wxCHECK( textCtrl, /* void */ );
682
683 double step_mm = OFFSET_INCREMENT_MM;
684
685 if( event.ShiftDown( ) )
686 step_mm = OFFSET_INCREMENT_MM_FINE;
687
689 {
690 step_mm = 25.4*OFFSET_INCREMENT_MIL/1000.0;
691
692 if( event.ShiftDown( ) )
693 step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000.0;
694 }
695
696 if( event.GetWheelRotation() >= 0 )
697 step_mm = -step_mm;
698
699 double value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, textCtrl->GetValue() )
700 / pcbIUScale.IU_PER_MM;
701
702 value_mm += step_mm;
703 value_mm = std::max( -MAX_OFFSET, value_mm );
704 value_mm = std::min( value_mm, MAX_OFFSET );
705
706 textCtrl->SetValue( formatOffsetValue( value_mm ) );
707}
708
709
710void PANEL_PREVIEW_3D_MODEL::onUnitsChanged( wxCommandEvent& aEvent )
711{
713 / pcbIUScale.IU_PER_MM;
715 / pcbIUScale.IU_PER_MM;
717 / pcbIUScale.IU_PER_MM;
718
719 PCB_BASE_FRAME* frame = static_cast<PCB_BASE_FRAME*>( aEvent.GetClientData() );
720 m_userUnits = frame->GetUserUnits();
721
722 xoff->SetValue( formatOffsetValue( xoff_mm ) );
723 yoff->SetValue( formatOffsetValue( yoff_mm ) );
724 zoff->SetValue( formatOffsetValue( zoff_mm ) );
725
726 aEvent.Skip();
727}
728
729
730void PANEL_PREVIEW_3D_MODEL::onPanelShownEvent( wxCommandEvent& aEvent )
731{
732 if( m_spaceMouse )
733 {
734 m_spaceMouse->SetFocus( static_cast<bool>( aEvent.GetInt() ) );
735 }
736
737 aEvent.Skip();
738}
739
740
742{
743 m_dummyFootprint->Models().clear();
744
746 {
747 if( model.m_Show )
748 m_dummyFootprint->Models().push_back( model );
749 }
750
752
753 if( m_extrudedBody && !m_dummyFootprint->HasExtrudedBody() )
754 m_extrudedBody = nullptr;
755
756 if( aReloadRequired )
757 m_previewPane->ReloadRequest();
758
759 m_previewPane->Request_refresh();
760}
761
762
768
769
771{
772 m_dummyFootprint->ClearEmbeddedFiles();
773
775 {
776 for( const auto& [name, file] : m_localEmbeddedFiles->EmbeddedFileMap() )
777 {
778 m_dummyFootprint->AddFile(
779 new EMBEDDED_FILES::EMBEDDED_FILE( *file ) );
780 }
781 }
782}
783
784
786{
787 KIWAY_HOLDER* kiwayHolder = dynamic_cast<KIWAY_HOLDER*>( wxGetTopLevelParent( this ) );
788
789 if( kiwayHolder && kiwayHolder->GetType() == KIWAY_HOLDER::DIALOG )
790 static_cast<DIALOG_SHIM*>( kiwayHolder )->OnModify();
791}
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
constexpr EDA_IU_SCALE unityScale
Definition base_units.h:124
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
@ show_board_body
@ options_3drender
@ FPHOLDER
Definition board.h:364
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
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:65
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:114
VECTOR3D m_rotation
Definition footprint.h:113
VECTOR3D m_scale
Definition footprint.h:112
VECTOR3D m_Offset
3D model offset (mm)
Definition footprint.h:171
double m_Opacity
Definition footprint.h:172
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition footprint.h:170
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
Definition footprint.h:169
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:718
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition lset.cpp:725
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)
EMBEDDED_FILES * m_localEmbeddedFiles
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:528
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:25
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 normalizeRotation(double aRotation)
Normalize a rotation in degrees to the half-open range (-MAX_ROTATION, MAX_ROTATION].
static double rotationFromString(const wxString &aValue)
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