KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_preview_3d_model.h
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 The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef PANEL_PREVIEW_3D_MODEL_H
23#define PANEL_PREVIEW_3D_MODEL_H
24
26
27#include <vector>
28#include <widgets/unit_binder.h>
29#include <tool/tools_holder.h>
31#include <3d_viewer_id.h>
32#include <3d_model_align.h>
34#include <wx/event.h>
35#include <wx/timer.h>
36#include <array>
37#include <limits>
38#include <map>
39#include <math/vector3.h>
40
41// Define min and max parameter values
42#define MAX_SCALE 10000.0
43#define MAX_ROTATION 180.0
44#define MAX_OFFSET 1000.0
45
46#define SCALE_INCREMENT_FINE 0.02
47#define SCALE_INCREMENT 0.1
48
49#define ROTATION_INCREMENT 90 // in degrees
50#define ROTATION_INCREMENT_FINE 1 // in degrees
51
52#define OFFSET_INCREMENT_MM 0.5
53#define OFFSET_INCREMENT_MM_FINE 0.1
54
55#define OFFSET_INCREMENT_MIL 25.0
56#define OFFSET_INCREMENT_MIL_FINE 5.0
57
58wxDECLARE_EVENT( wxCUSTOM_PANEL_SHOWN_EVENT, wxCommandEvent );
59
60// Declared classes to create pointers
61class WX_INFOBAR;
62class S3D_CACHE;
64class EMBEDDED_FILES;
65class BOARD;
66class BOARD_ADAPTER;
67class FOOTPRINT;
69#if defined(__linux__) || defined(__FreeBSD__)
71#else
73#endif
74
75#define PANEL_PREVIEW_3D_MODEL_ID wxID_HIGHEST + 1244
76
78{
79public:
80 PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame, FOOTPRINT* aFootprint,
81 std::vector<FP_3DMODEL>* aParentModelList );
82
84
89 void OnMenuEvent( wxMenuEvent& aEvent );
90
91 wxWindow* GetToolCanvas() const override { return m_previewPane; }
92
95
100 void SetSelectedModel( int idx );
101
106 void UpdateDummyFootprint( bool aRelaodRequired = true );
107
108 void SetEmbeddedFilesDelegate( EMBEDDED_FILES* aDelegate );
109
115
117
118private:
120
121 void onAlign( wxCommandEvent& aEvent ) override;
122 void onAlignUpdateUI( wxUpdateUIEvent& aEvent ) override;
123 void onAlignKey( wxKeyEvent& aEvent );
124 void onAlignAnimation( wxTimerEvent& aEvent );
126 bool canAlign() const;
127 bool pickAlignment( const RAY& aRay );
128 void hoverAlignment( const std::optional<RAY>& aRay );
129 const S3DMODEL* alignmentModel();
131 void cancelAlignment();
133 void stopPicking();
135 void applyAlignment();
136
138 std::optional<size_t> alignmentRegionAt( const RAY& aRay );
139
141 std::vector<SFVEC3F> alignmentRegionTriangles( size_t aRegion ) const;
142
144 std::vector<SFVEC3F> alignmentPadTriangles( const PAD& aPad ) const;
145
147 glm::mat4 alignmentModelMatrix() const;
148
151
153 void startAlignmentAnimation( const VECTOR3D& aRotation, const VECTOR3D& aOffset );
155
159 void loadSettings();
160
164 void updateOrientation( wxCommandEvent& event ) override;
165
166 void onMouseWheelScale( wxMouseEvent& event ) override;
167 void onMouseWheelRot( wxMouseEvent& event ) override;
168 void onMouseWheelOffset( wxMouseEvent& event ) override;
169
170 void onIncrementRot( wxSpinEvent& event ) override
171 {
172 doIncrementRotation( event, 1.0 );
173 }
174 void onDecrementRot( wxSpinEvent& event ) override
175 {
176 doIncrementRotation( event, -1.0 );
177 }
178 void onIncrementScale( wxSpinEvent& event ) override
179 {
180 doIncrementScale( event, 1.0 );
181 }
182 void onDecrementScale( wxSpinEvent& event ) override
183 {
184 doIncrementScale( event, -1.0 );
185 }
186 void onIncrementOffset( wxSpinEvent& event ) override
187 {
188 doIncrementOffset( event, 1.0 );
189 }
190 void onDecrementOffset( wxSpinEvent& event ) override
191 {
192 doIncrementOffset( event, -1.0 );
193 }
194
195 void onOpacitySlider( wxCommandEvent& event ) override;
196
197 void doIncrementScale( wxSpinEvent& aEvent, double aSign );
198 void doIncrementRotation( wxSpinEvent& aEvent, double aSign );
199 void doIncrementOffset( wxSpinEvent& aEvent, double aSign );
200
201 void onUnitsChanged( wxCommandEvent& aEvent );
202 void onPanelShownEvent( wxCommandEvent& aEvent );
203
204 wxString formatScaleValue( double aValue );
205 wxString formatRotationValue( double aValue );
206 wxString formatOffsetValue( double aValue );
207
208 void evalRotationValue( TEXT_CTRL_EVAL* aRotationControl );
209
210 void View3DISO( wxCommandEvent& event ) override
211 {
212 m_currentCamera.ToggleProjection();
213 m_previewPane->Refresh();
214 }
215
216 // turn ON or OFF options to show the board body. If OFF, solder paste, soldermask
217 // and board body are hidden, to allows a good view of the 3D model and its pads.
218 // Useful for 3D model placement
219 void setBodyStyleView( wxCommandEvent& event ) override;
220
221 void View3DLeft( wxCommandEvent& event ) override
222 {
224 }
225
226 void View3DFront( wxCommandEvent& event ) override
227 {
229 }
230
231 void View3DTop( wxCommandEvent& event ) override
232 {
234 }
235
236 void View3DUpdate( wxCommandEvent& event ) override
237 {
239 m_previewPane->ReloadRequest();
240 m_previewPane->Refresh();
241 }
242
243 void View3DSettings( wxCommandEvent& event ) override;
244
245 void View3DRight( wxCommandEvent& event ) override
246 {
248 }
249
250 void View3DBack( wxCommandEvent& event ) override
251 {
253 }
254
255 void View3DBottom( wxCommandEvent& event ) override
256 {
258 }
259
260 void onModify();
261
263
264private:
272
275
276 std::vector<FP_3DMODEL>* m_parentModelList;
278
280 bool m_alignUpdating = false;
281 std::optional<std::bitset<LAYER_3D_END>> m_alignLayers;
282 std::optional<bool> m_alignBodyShown;
283 std::vector<MODEL_ALIGN::REGION> m_alignRegions;
284 std::vector<MODEL_ALIGN::ALIGN_SOLUTION> m_alignSolutions;
285 const S3DMODEL* m_alignGeometry = nullptr;
286 std::map<std::array<unsigned int, 2>, size_t> m_alignTriangleRegions;
287 size_t m_alignSeed = 0;
288 size_t m_alignSolution = 0;
289
290 std::vector<SFVEC3F> m_alignFaceTriangles;
291 std::optional<size_t> m_alignHoverRegion;
292 const PAD* m_alignHoverPad = nullptr;
293
295 int64_t m_alignAnimStart = 0;
300 bool m_alignAnimating = false;
301 size_t m_dummySelectedModel = std::numeric_limits<size_t>::max();
302
306
309
310#if defined(__linux__) || defined(__FreeBSD__)
311 std::unique_ptr<SPNAV_VIEWER_PLUGIN> m_spaceMouse;
312#else
313 std::unique_ptr<NL_FOOTPRINT_PROPERTIES_PLUGIN> m_spaceMouse;
314#endif
315};
316
317#endif // PANEL_PREVIEW_3D_MODEL_H
@ VIEW3D_BOTTOM
Definition 3d_enums.h:77
Helper class to handle information needed to display 3D board.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
A class used to derive camera objects from.
Definition camera.h:99
Implement a canvas based on a wxGLCanvas.
Provide an extensible class to resolve 3D model paths.
The class that implements the public interface to the SpaceMouse plug-in.
Definition pad.h:61
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)
void View3DTop(wxCommandEvent &event) override
wxString formatOffsetValue(double aValue)
void onAlign(wxCommandEvent &aEvent) override
void onMouseWheelRot(wxMouseEvent &event) override
void View3DSettings(wxCommandEvent &event) override
size_t m_dummySelectedModel
Selected model in the dummy footprint.
void onOpacitySlider(wxCommandEvent &event) override
void View3DFront(wxCommandEvent &event) override
void onDecrementRot(wxSpinEvent &event) override
void onIncrementScale(wxSpinEvent &event) override
void setBodyStyleView(wxCommandEvent &event) override
void hoverAlignment(const std::optional< RAY > &aRay)
void evalRotationValue(TEXT_CTRL_EVAL *aRotationControl)
void onMouseWheelScale(wxMouseEvent &event) override
EDA_3D_VIEWER_SETTINGS::RENDER_SETTINGS m_initialRender
The 3d viewer Render initial settings (must be saved and restored)
std::vector< SFVEC3F > m_alignFaceTriangles
Picked face, kept until the move finishes.
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.
glm::mat4 alignmentModelMatrix() const
Transform carrying the selected model's geometry into world units.
std::optional< bool > m_alignBodyShown
void View3DBack(wxCommandEvent &event) override
void onAlignKey(wxKeyEvent &aEvent)
void onAlignUpdateUI(wxUpdateUIEvent &aEvent) override
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)
wxWindow * GetToolCanvas() const override
Canvas access.
ALIGN_STATE m_alignState
Index into m_parentInfoList.
void startAlignmentAnimation(const VECTOR3D &aRotation, const VECTOR3D &aOffset)
Slide the preview from its current placement to the solved one.
void onIncrementOffset(wxSpinEvent &event) override
std::vector< SFVEC3F > alignmentRegionTriangles(size_t aRegion) const
Model-space triangle soup of one region, for the selection overlay.
PANEL_PREVIEW_3D_MODEL(wxWindow *aParent, PCB_BASE_FRAME *aFrame, FOOTPRINT *aFootprint, std::vector< FP_3DMODEL > *aParentModelList)
FOOTPRINT * GetDummyFootprint() const
Get the dummy footprint that is used for previewing the 3D model.
std::vector< MODEL_ALIGN::REGION > m_alignRegions
void onAlignAnimation(wxTimerEvent &aEvent)
void updateAlignmentOverlays()
Push the selection and roll-over overlays to the canvas.
std::optional< size_t > alignmentRegionAt(const RAY &aRay)
Region under the ray, as an index into m_alignRegions.
std::vector< SFVEC3F > alignmentPadTriangles(const PAD &aPad) const
World-space triangle soup covering a pad's copper shape.
void onDecrementOffset(wxSpinEvent &event) override
void SetEmbeddedFilesDelegate(EMBEDDED_FILES *aDelegate)
EXTRUDED_3D_BODY * m_extrudedBody
void SetExtrusionTransformMode(EXTRUDED_3D_BODY *aBody)
void doIncrementScale(wxSpinEvent &aEvent, double aSign)
bool pickAlignment(const RAY &aRay)
void View3DLeft(wxCommandEvent &event) override
void updateOrientation(wxCommandEvent &event) override
It will receive the events from editing the fields.
void View3DISO(wxCommandEvent &event) override
wxString formatRotationValue(double aValue)
void onMouseWheelOffset(wxMouseEvent &event) override
std::optional< size_t > m_alignHoverRegion
std::optional< std::bitset< LAYER_3D_END > > m_alignLayers
std::unique_ptr< NL_FOOTPRINT_PROPERTIES_PLUGIN > m_spaceMouse
void View3DBottom(wxCommandEvent &event) override
std::vector< MODEL_ALIGN::ALIGN_SOLUTION > m_alignSolutions
void onDecrementScale(wxSpinEvent &event) override
std::map< std::array< unsigned int, 2 >, size_t > m_alignTriangleRegions
void onIncrementRot(wxSpinEvent &event) override
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 ...
void View3DRight(wxCommandEvent &event) override
std::vector< FP_3DMODEL > * m_parentModelList
void View3DUpdate(wxCommandEvent &event) override
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
Cache for storing the 3D shapes.
Definition 3d_cache.h:53
wxTextCtrl wrapper to handle math expression evaluation.
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:76
EDA_UNITS
Definition eda_units.h:44
wxDECLARE_EVENT(wxCUSTOM_PANEL_SHOWN_EVENT, wxCommandEvent)
Definition ray.h:59
Store the a model based on meshes and materials.
Definition c3dmodel.h:111
Declaration for a track ball camera.
VECTOR3< double > VECTOR3D
Definition vector3.h:230