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::system_error& e )
216 {
217 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
218 }
219
220 m_boardAdapter.SetBoard( m_dummyBoard );
221 m_boardAdapter.m_IsBoardView = false;
222
223 // Force display 3D models, regardless the 3D viewer options.
224 m_boardAdapter.m_IsPreviewer = true;
225
226 loadSettings();
227
228 // Don't show placeholder models in the footprint properties 3D preview
229 if( m_boardAdapter.m_Cfg )
230 m_boardAdapter.m_Cfg->m_Render.show_missing_models = false;
231
232 // Create the manager
234 m_toolManager->SetEnvironment( m_dummyBoard, nullptr, nullptr, nullptr, this );
235
238 m_previewPane->SetEventDispatcher( m_toolDispatcher );
239
240 // Register tools
241 m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
242 m_toolManager->InitTools();
243
244 // Run the viewer control tool, it is supposed to be always active
245 m_toolManager->InvokeTool( "3DViewer.Control" );
246
247 m_infobar = new WX_INFOBAR( this );
248 m_previewPane->SetInfoBar( m_infobar );
249
250 m_SizerPanelView->Add( m_infobar, 0, wxEXPAND, 0 );
251 m_SizerPanelView->Add( m_previewPane, 1, wxEXPAND, 5 );
252
253 for( wxEventType eventType : { wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT } )
254 Connect( eventType, wxMenuEventHandler( PANEL_PREVIEW_3D_MODEL::OnMenuEvent ), nullptr, this );
255
256 aFrame->Connect( EDA_EVT_UNITS_CHANGED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL::onUnitsChanged ),
257 nullptr, this );
258
259 Bind( wxCUSTOM_PANEL_SHOWN_EVENT, &PANEL_PREVIEW_3D_MODEL::onPanelShownEvent, this );
260}
261
262
264{
265 // Shutdown all running tools
266 if( m_toolManager )
267 m_toolManager->ShutdownAllTools();
268
269 // Restore the 3D viewer Render settings, that can be modified by the panel tools
270 if( m_boardAdapter.m_Cfg )
271 m_boardAdapter.m_Cfg->m_Render = m_initialRender;
272
273 delete m_dummyBoard;
274 delete m_previewPane;
275}
276
277
278void PANEL_PREVIEW_3D_MODEL::OnMenuEvent( wxMenuEvent& aEvent )
279{
280 if( !m_toolDispatcher )
281 aEvent.Skip();
282 else
283 m_toolDispatcher->DispatchWxEvent( aEvent );
284}
285
286
288{
289 wxCHECK_RET( m_previewPane, wxT( "Cannot load settings to null canvas" ) );
290
291 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
292
293 // TODO(JE) use all control options
294 m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;
295
297 {
298 // Save the 3D viewer render settings, to restore it after closing the preview
299 m_initialRender = cfg->m_Render;
300
301 m_boardAdapter.m_Cfg = cfg;
302
303 m_previewPane->SetAnimationEnabled( cfg->m_Camera.animation_enabled );
304 m_previewPane->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier );
305 m_previewPane->SetProjectionMode( cfg->m_Camera.projection_mode );
306 }
307}
308
309
311{
312 return wxString::Format( wxT( "%.4f" ),
313 aValue );
314}
315
316
318{
319 // Sigh. Did we really need differentiated +/- 0.0?
320 if( aValue == -0.0 )
321 aValue = 0.0;
322
323 return wxString::Format( wxT( "%.2f%s" ),
324 aValue,
326}
327
328
330{
331 // Convert from internal units (mm) to user units
333 aValue /= 25.4;
334 else if( m_userUnits == EDA_UNITS::MILS )
335 aValue /= 25.4 / 1e3;
336
337 return wxString::Format( wxT( "%.6f%s" ),
338 aValue,
340}
341
342
344{
345 if( m_parentModelList && idx >= 0 && idx < (int) m_parentModelList->size() )
346 {
347 m_selected = idx;
348 const FP_3DMODEL& modelInfo = m_parentModelList->at( (unsigned) m_selected );
349
350 // Use ChangeValue() instead of SetValue(). It's not the user making the change, so we
351 // don't want to generate wxEVT_GRID_CELL_CHANGED events.
352 xscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.x ) );
353 yscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.y ) );
354 zscale->ChangeValue( formatScaleValue( modelInfo.m_Scale.z ) );
355
356 // Rotation is stored in the file as positive-is-CW, but we use positive-is-CCW in the GUI
357 // to match the rest of KiCad
358 xrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.x ) );
359 yrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.y ) );
360 zrot->ChangeValue( formatRotationValue( -modelInfo.m_Rotation.z ) );
361
362 xoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.x ) );
363 yoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.y ) );
364 zoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.z ) );
365
366 m_opacity->SetValue( modelInfo.m_Opacity * 100.0 );
367 }
368 else
369 {
370 m_selected = -1;
371
372 xscale->ChangeValue( wxEmptyString );
373 yscale->ChangeValue( wxEmptyString );
374 zscale->ChangeValue( wxEmptyString );
375
376 xrot->ChangeValue( wxEmptyString );
377 yrot->ChangeValue( wxEmptyString );
378 zrot->ChangeValue( wxEmptyString );
379
380 xoff->ChangeValue( wxEmptyString );
381 yoff->ChangeValue( wxEmptyString );
382 zoff->ChangeValue( wxEmptyString );
383
384 m_opacity->SetValue( 100 );
385 }
386}
387
388
390{
391 m_extrudedBody = aBody;
392
393 if( aBody )
394 {
395 xscale->ChangeValue( formatScaleValue( aBody->m_scale.x ) );
396 yscale->ChangeValue( formatScaleValue( aBody->m_scale.y ) );
397 zscale->ChangeValue( formatScaleValue( aBody->m_scale.z ) );
398
399 xrot->ChangeValue( formatRotationValue( -aBody->m_rotation.x ) );
400 yrot->ChangeValue( formatRotationValue( -aBody->m_rotation.y ) );
401 zrot->ChangeValue( formatRotationValue( -aBody->m_rotation.z ) );
402
403 xoff->ChangeValue( formatOffsetValue( aBody->m_offset.x ) );
404 yoff->ChangeValue( formatOffsetValue( aBody->m_offset.y ) );
405 zoff->ChangeValue( formatOffsetValue( aBody->m_offset.z ) );
406
407 m_opacity->SetValue( 100 );
408 m_opacity->Enable( false );
409 }
410 else
411 {
412 m_opacity->Enable( true );
413 }
414}
415
416
417void PANEL_PREVIEW_3D_MODEL::updateOrientation( wxCommandEvent &event )
418{
419 if( m_extrudedBody )
420 {
422 evaluateTextCtrl( xscale->GetValue() ) );
424 evaluateTextCtrl( yscale->GetValue() ) );
426 evaluateTextCtrl( zscale->GetValue() ) );
427
428 m_extrudedBody->m_rotation.x = -rotationFromString( evaluateTextCtrl( xrot->GetValue() ) );
429 m_extrudedBody->m_rotation.y = -rotationFromString( evaluateTextCtrl( yrot->GetValue() ) );
430 m_extrudedBody->m_rotation.z = -rotationFromString( evaluateTextCtrl( zrot->GetValue() ) );
431
433 evaluateTextCtrl( xoff->GetValue() ) )
434 / pcbIUScale.IU_PER_MM;
436 evaluateTextCtrl( yoff->GetValue() ) )
437 / pcbIUScale.IU_PER_MM;
439 evaluateTextCtrl( zoff->GetValue() ) )
440 / pcbIUScale.IU_PER_MM;
441
442 UpdateDummyFootprint( true );
443 onModify();
444 }
445 else if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
446 {
447 // Write settings back to the parent
448 FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
449
451 evaluateTextCtrl( xscale->GetValue() ) );
453 evaluateTextCtrl( yscale->GetValue() ) );
455 evaluateTextCtrl( zscale->GetValue() ) );
456
457 // Rotation is stored in the file as positive-is-CW, but we use positive-is-CCW in the GUI
458 // to match the rest of KiCad
459 modelInfo->m_Rotation.x = -rotationFromString( evaluateTextCtrl( xrot->GetValue() ) );
460 modelInfo->m_Rotation.y = -rotationFromString( evaluateTextCtrl( yrot->GetValue() ) );
461 modelInfo->m_Rotation.z = -rotationFromString( evaluateTextCtrl( zrot->GetValue() ) );
462
464 evaluateTextCtrl( xoff->GetValue() ) )
465 / pcbIUScale.IU_PER_MM;
467 evaluateTextCtrl( yoff->GetValue() ) )
468 / pcbIUScale.IU_PER_MM;
470 evaluateTextCtrl( zoff->GetValue() ) )
471 / pcbIUScale.IU_PER_MM;
472
473 // Update the dummy footprint for the preview
474 UpdateDummyFootprint( false );
475 onModify();
476 }
477}
478
479
480void PANEL_PREVIEW_3D_MODEL::onOpacitySlider( wxCommandEvent& event )
481{
482 if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
483 {
484 // Write settings back to the parent
485 FP_3DMODEL* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
486
487 modelInfo->m_Opacity = m_opacity->GetValue() / 100.0;
488
489 // Update the dummy footprint for the preview
490 UpdateDummyFootprint( false );
491 onModify();
492 }
493}
494
495
496void PANEL_PREVIEW_3D_MODEL::setBodyStyleView( wxCommandEvent& event )
497{
498 // turn ON or OFF options to show the board body if OFF, solder paste, soldermask
499 // and board body are hidden, to allows a good view of the 3D model and its pads.
501
502 if( !cfg )
503 return;
504
506
507 m_previewPane->ReloadRequest();
508 m_previewPane->Refresh();
509}
510
511
512void PANEL_PREVIEW_3D_MODEL::View3DSettings( wxCommandEvent& event )
513{
514 BOARD_DESIGN_SETTINGS bds = m_dummyBoard->GetDesignSettings();
515 int thickness = bds.GetBoardThickness();
516
517 WX_UNIT_ENTRY_DIALOG dlg( m_parentFrame, _( "3D Preview Options" ), _( "Board thickness:" ), thickness );
518
519 if( dlg.ShowModal() != wxID_OK )
520 return;
521
522 bds.SetBoardThickness( dlg.GetValue() );
523
524 BOARD_STACKUP& boardStackup = m_dummyBoard->GetDesignSettings().GetStackupDescriptor();
525 boardStackup.RemoveAll();
526 boardStackup.BuildDefaultStackupList( &bds, 2 );
527
528 UpdateDummyFootprint( true );
529
530 m_previewPane->ReloadRequest();
531 m_previewPane->Refresh();
532}
533
534
535void PANEL_PREVIEW_3D_MODEL::doIncrementScale( wxSpinEvent& event, double aSign )
536{
537 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( event.GetEventObject() );
538
539 wxCHECK( spinCtrl, /* void */ );
540
541 wxTextCtrl * textCtrl = xscale;
542
543 if( spinCtrl == m_spinYscale )
544 textCtrl = yscale;
545 else if( spinCtrl == m_spinZscale )
546 textCtrl = zscale;
547
548 double step = SCALE_INCREMENT;
549
550 if( wxGetMouseState().ShiftDown( ) )
552
553 double value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::UNSCALED, textCtrl->GetValue() );
554
555 value += ( step * aSign );
556 value = std::max( 1/MAX_SCALE, value );
557 value = std::min( value, MAX_SCALE );
558
559 textCtrl->SetValue( formatScaleValue( value ) );
560}
561
562
563void PANEL_PREVIEW_3D_MODEL::doIncrementRotation( wxSpinEvent& aEvent, double aSign )
564{
565 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( aEvent.GetEventObject() );
566
567 wxCHECK( spinCtrl, /* void */ );
568
569 wxTextCtrl* textCtrl = xrot;
570
571 if( spinCtrl == m_spinYrot )
572 textCtrl = yrot;
573 else if( spinCtrl == m_spinZrot )
574 textCtrl = zrot;
575
576 double step = ROTATION_INCREMENT;
577
578 if( wxGetMouseState().ShiftDown( ) )
580
581 double value = rotationFromString( textCtrl->GetValue() );
582
583 value = normalizeRotation( value + step * aSign );
584
585 textCtrl->SetValue( formatRotationValue( value ) );
586}
587
588
589void PANEL_PREVIEW_3D_MODEL::doIncrementOffset( wxSpinEvent& event, double aSign )
590{
591 wxSpinButton* spinCtrl = dynamic_cast<wxSpinButton*>( event.GetEventObject() );
592
593 wxCHECK( spinCtrl, /* void */ );
594
595 wxTextCtrl * textCtrl = xoff;
596
597 if( spinCtrl == m_spinYoffset )
598 textCtrl = yoff;
599 else if( spinCtrl == m_spinZoffset )
600 textCtrl = zoff;
601
602 double step_mm = OFFSET_INCREMENT_MM;
603
604 if( wxGetMouseState().ShiftDown( ) )
605 step_mm = OFFSET_INCREMENT_MM_FINE;
606
608 {
609 step_mm = 25.4*OFFSET_INCREMENT_MIL/1000;
610
611 if( wxGetMouseState().ShiftDown( ) )
612 step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000;;
613 }
614
615 double value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, textCtrl->GetValue() )
616 / pcbIUScale.IU_PER_MM;
617
618 value_mm += ( step_mm * aSign );
619 value_mm = std::max( -MAX_OFFSET, value_mm );
620 value_mm = std::min( value_mm, MAX_OFFSET );
621
622 textCtrl->SetValue( formatOffsetValue( value_mm ) );
623}
624
625
627{
628 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
629
630 wxCHECK( textCtrl, /* void */ );
631
632 double step = SCALE_INCREMENT;
633
634 if( event.ShiftDown( ) )
636
637 if( event.GetWheelRotation() >= 0 )
638 step = -step;
639
640 double value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::UNSCALED, textCtrl->GetValue() );
641
642 value += step;
643 value = std::max( 1/MAX_SCALE, value );
644 value = std::min( value, MAX_SCALE );
645
646 textCtrl->SetValue( formatScaleValue( value ) );
647}
648
649
651{
652 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
653
654 wxCHECK( textCtrl, /* void */ );
655
656 double step = ROTATION_INCREMENT;
657
658 if( event.ShiftDown( ) )
660
661 if( event.GetWheelRotation() >= 0 )
662 step = -step;
663
664 double value = rotationFromString( textCtrl->GetValue() );
665
666 value = normalizeRotation( value + step );
667
668 textCtrl->SetValue( formatRotationValue( value ) );
669}
670
671
673{
674 wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
675
676 wxCHECK( textCtrl, /* void */ );
677
678 double step_mm = OFFSET_INCREMENT_MM;
679
680 if( event.ShiftDown( ) )
681 step_mm = OFFSET_INCREMENT_MM_FINE;
682
684 {
685 step_mm = 25.4*OFFSET_INCREMENT_MIL/1000.0;
686
687 if( event.ShiftDown( ) )
688 step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000.0;
689 }
690
691 if( event.GetWheelRotation() >= 0 )
692 step_mm = -step_mm;
693
694 double value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, textCtrl->GetValue() )
695 / pcbIUScale.IU_PER_MM;
696
697 value_mm += step_mm;
698 value_mm = std::max( -MAX_OFFSET, value_mm );
699 value_mm = std::min( value_mm, MAX_OFFSET );
700
701 textCtrl->SetValue( formatOffsetValue( value_mm ) );
702}
703
704
705void PANEL_PREVIEW_3D_MODEL::onUnitsChanged( wxCommandEvent& aEvent )
706{
708 / pcbIUScale.IU_PER_MM;
710 / pcbIUScale.IU_PER_MM;
712 / pcbIUScale.IU_PER_MM;
713
714 PCB_BASE_FRAME* frame = static_cast<PCB_BASE_FRAME*>( aEvent.GetClientData() );
715 m_userUnits = frame->GetUserUnits();
716
717 xoff->SetValue( formatOffsetValue( xoff_mm ) );
718 yoff->SetValue( formatOffsetValue( yoff_mm ) );
719 zoff->SetValue( formatOffsetValue( zoff_mm ) );
720
721 aEvent.Skip();
722}
723
724
725void PANEL_PREVIEW_3D_MODEL::onPanelShownEvent( wxCommandEvent& aEvent )
726{
727 if( m_spaceMouse )
728 {
729 m_spaceMouse->SetFocus( static_cast<bool>( aEvent.GetInt() ) );
730 }
731
732 aEvent.Skip();
733}
734
735
737{
738 m_dummyFootprint->Models().clear();
739
741 {
742 if( model.m_Show )
743 m_dummyFootprint->Models().push_back( model );
744 }
745
747
748 if( m_extrudedBody && !m_dummyFootprint->HasExtrudedBody() )
749 m_extrudedBody = nullptr;
750
751 if( aReloadRequired )
752 m_previewPane->ReloadRequest();
753
754 m_previewPane->Request_refresh();
755}
756
757
763
764
766{
767 m_dummyFootprint->ClearEmbeddedFiles();
768
770 {
771 for( const auto& [name, file] : m_localEmbeddedFiles->EmbeddedFileMap() )
772 {
773 m_dummyFootprint->AddFile(
774 new EMBEDDED_FILES::EMBEDDED_FILE( *file ) );
775 }
776 }
777}
778
779
781{
782 KIWAY_HOLDER* kiwayHolder = dynamic_cast<KIWAY_HOLDER*>( wxGetTopLevelParent( this ) );
783
784 if( kiwayHolder && kiwayHolder->GetType() == KIWAY_HOLDER::DIALOG )
785 static_cast<DIALOG_SHIM*>( kiwayHolder )->OnModify();
786}
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:312
#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:112
VECTOR3D m_rotation
Definition footprint.h:111
VECTOR3D m_scale
Definition footprint.h:110
VECTOR3D m_Offset
3D model offset (mm)
Definition footprint.h:169
double m_Opacity
Definition footprint.h:170
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition footprint.h:168
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
Definition footprint.h:167
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:537
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