50#include <wx/filename.h>
63#if defined(__linux__) || defined(__FreeBSD__)
78 for( wxUniChar c : aValue )
125 std::vector<FP_3DMODEL>* aParentModelList ) :
174 wxSpinButton* spinButtonList[] =
181 for( wxSpinButton* button : spinButtonList )
182 button->SetRange(INT_MIN, INT_MAX );
186 rotCtrl->SetCustomEval(
196 scaleCtrl->SetCustomEval(
226#if defined(__linux__) || defined(__FreeBSD__)
233 catch(
const std::exception& e )
235 wxLogTrace( wxT(
"KI_TRACE_NAVLIB" ), wxS(
"%s" ), e.what() );
239 wxLogTrace( wxT(
"KI_TRACE_NAVLIB" ),
240 wxT(
"Unknown exception during SpaceMouse initialization" ) );
278 for( wxEventType eventType : { wxEVT_MENU_OPEN, wxEVT_MENU_CLOSE, wxEVT_MENU_HIGHLIGHT } )
324 wxCHECK_RET(
m_previewPane, wxT(
"Cannot load settings to null canvas" ) );
338 m_previewPane->SetAnimationEnabled( cfg->m_Camera.animation_enabled );
339 m_previewPane->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier );
340 m_previewPane->SetProjectionMode( cfg->m_Camera.projection_mode );
347 return wxString::Format( wxT(
"%.4f" ),
358 return wxString::Format( wxT(
"%.2f%s" ),
370 aValue /= 25.4 / 1e3;
372 return wxString::Format( wxT(
"%.6f%s" ),
387 const std::string extension = wxFileName(
model.m_Filename ).GetExt().utf8_string();
392 && std::isfinite(
model.m_Scale.x ) &&
model.m_Scale.x != 0.0
393 && std::isfinite(
model.m_Scale.y ) &&
model.m_Scale.y != 0.0
394 && std::isfinite(
model.m_Scale.z ) &&
model.m_Scale.z != 0.0;
427 { m_dummyFootprint->GetEmbeddedFiles(), m_dummyBoard->GetEmbeddedFiles() } );
511 if( aEvent.GetKeyCode() == WXK_ESCAPE
563 body->m_show =
false;
572 layers.reset( layer );
581 m_alignmentInfoBar->ShowMessage(
_(
"Click the model face that sits on the board. Press Esc to cancel." ),
582 wxICON_INFORMATION );
614 m_alignmentInfoBar->ShowMessage(
_(
"Click the footprint pad for that contact. Press Esc to cancel." ),
615 wxICON_INFORMATION );
633 std::vector<MODEL_ALIGN::PAD> pads;
634 size_t clickedIndex = 0;
640 clickedIndex = pads.size();
646 item.
number =
pad->GetNumber().utf8_string();
654 pads.push_back( std::move( item ) );
660 glm::dvec3( -rotation.x, -rotation.y, -rotation.z ) );
704 wxCommandEvent event;
715 m_alignmentInfoBar->ShowMessage( wxString::Format(
_(
"Solution %d of %d, press Align to cycle." ),
718 wxICON_INFORMATION );
743 std::vector<SFVEC3F> triangles;
745 triangles.reserve( region.
triangles.size() * 3 );
747 for(
const std::array<unsigned int, 3>& triangle : region.
triangles )
749 for(
unsigned int index : triangle )
752 triangles.emplace_back( vertex.x, vertex.y, vertex.z );
766 std::vector<SFVEC3F> triangles;
781 for(
const VECTOR2I& point : { a, b, c } )
782 triangles.emplace_back( point.x * units, -point.y * units, z );
792 std::vector<EDA_3D_CANVAS::OVERLAY> overlays;
808 overlays.push_back( std::move(
overlay ) );
817 overlays.push_back( std::move(
overlay ) );
826 overlays.push_back( std::move(
overlay ) );
839 std::optional<EDA_3D_CANVAS::MODEL_HIT> hit =
851 return region->second;
857 std::optional<size_t> region;
890 || ( aRotation ==
model.m_Rotation && aOffset ==
model.m_Offset ) )
925 const float eased = (float) ( t * t * ( 3.0 - 2.0 * t ) );
994 xscale->ChangeValue( wxEmptyString );
995 yscale->ChangeValue( wxEmptyString );
996 zscale->ChangeValue( wxEmptyString );
998 xrot->ChangeValue( wxEmptyString );
999 yrot->ChangeValue( wxEmptyString );
1000 zrot->ChangeValue( wxEmptyString );
1002 xoff->ChangeValue( wxEmptyString );
1003 yoff->ChangeValue( wxEmptyString );
1004 zoff->ChangeValue( wxEmptyString );
1099 if( previousScale == modelInfo->
m_Scale && previousRotation == modelInfo->
m_Rotation
1100 && previousOffset == modelInfo->
m_Offset )
1171 wxSpinButton* spinCtrl =
dynamic_cast<wxSpinButton*
>(
event.GetEventObject() );
1173 wxCHECK( spinCtrl, );
1175 wxTextCtrl * textCtrl =
xscale;
1184 if( wxGetMouseState().ShiftDown( ) )
1189 value += ( step * aSign );
1199 wxSpinButton* spinCtrl =
dynamic_cast<wxSpinButton*
>( aEvent.GetEventObject() );
1201 wxCHECK( spinCtrl, );
1203 wxTextCtrl* textCtrl =
xrot;
1212 if( wxGetMouseState().ShiftDown( ) )
1225 wxSpinButton* spinCtrl =
dynamic_cast<wxSpinButton*
>(
event.GetEventObject() );
1227 wxCHECK( spinCtrl, );
1229 wxTextCtrl * textCtrl =
xoff;
1238 if( wxGetMouseState().ShiftDown( ) )
1245 if( wxGetMouseState().ShiftDown( ) )
1252 value_mm += ( step_mm * aSign );
1253 value_mm = std::max( -
MAX_OFFSET, value_mm );
1262 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
1264 wxCHECK( textCtrl, );
1268 if( event.ShiftDown( ) )
1271 if( event.GetWheelRotation() >= 0 )
1286 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
1288 wxCHECK( textCtrl, );
1292 if( event.ShiftDown( ) )
1295 if( event.GetWheelRotation() >= 0 )
1308 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
1310 wxCHECK( textCtrl, );
1314 if( event.ShiftDown( ) )
1321 if( event.ShiftDown( ) )
1325 if( event.GetWheelRotation() >= 0 )
1331 value_mm += step_mm;
1332 value_mm = std::max( -
MAX_OFFSET, value_mm );
1361 if( !aEvent.GetInt() )
1366 m_spaceMouse->SetFocus(
static_cast<bool>( aEvent.GetInt() ) );
1407 if( aReloadRequired )
1443 static_cast<DIALOG_SHIM*
>( kiwayHolder )->OnModify();
SFVEC3F InterpolateModelRotation(const SFVEC3F &aStart, const SFVEC3F &aEnd, float aT)
Interpolate between two model orientations along the shortest arc.
glm::mat4 CalcModelMatrix(const SFVEC3F &aOffset, const SFVEC3F &aRotation, const SFVEC3F &aScale)
Build the model-to-footprint transform used by rendering and picking.
Defines math related functions.
static std::optional< VECTOR2D > normalized(const VECTOR2D &aVec)
constexpr EDA_IU_SCALE pcbIUScale
constexpr EDA_IU_SCALE unityScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
#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...
Implement a canvas based on a wxGLCanvas.
Handle view actions for various 3D canvases.
VECTOR3D m_Offset
3D model offset (mm)
VECTOR3D m_Rotation
3D model rotation (degrees)
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
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
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
bool Process(const wxString &aString)
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
PAD_ATTRIB GetAttribute() const
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon(PCB_LAYER_ID aLayer, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
wxSpinButton * m_spinYrot
wxSpinButton * m_spinZrot
STD_BITMAP_BUTTON * m_bpvFront
wxSpinButton * m_spinXscale
wxSpinButton * m_spinYscale
wxSpinButton * m_spinXrot
wxBoxSizer * m_SizerPanelView
wxSpinButton * m_spinZoffset
wxStaticText * m_previewLabel
STD_BITMAP_BUTTON * m_bpvLeft
wxSpinButton * m_spinXoffset
wxSpinButton * m_spinYoffset
STD_BITMAP_BUTTON * m_bpSettings
STD_BITMAP_BUTTON * m_bpvRight
STD_BITMAP_BUTTON * m_bpvBodyStyle
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)
STD_BITMAP_BUTTON * m_bpvBack
wxSpinButton * m_spinZscale
STD_BITMAP_BUTTON * m_bpUpdate
STD_BITMAP_BUTTON * m_bpvTop
STD_BITMAP_BUTTON * m_bpvISO
STD_BITMAP_BUTTON * m_bpvBottom
void dismissAlignmentInfoBar()
VECTOR3D m_alignAnimFromOffset
const S3DMODEL * m_alignGeometry
void tickAlignmentAnimation()
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 setBodyStyleView(wxCommandEvent &event) override
void hoverAlignment(const std::optional< RAY > &aRay)
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...
~PANEL_PREVIEW_3D_MODEL()
void syncLocalEmbeddedFiles()
wxString formatScaleValue(double aValue)
void doIncrementRotation(wxSpinEvent &aEvent, double aSign)
void refreshAlignmentView()
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 onAlignKey(wxKeyEvent &aEvent)
void onAlignUpdateUI(wxUpdateUIEvent &aEvent) override
VECTOR3D m_alignAnimRotation
void OnMenuEvent(wxMenuEvent &aEvent)
The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu events aren't ...
WX_INFOBAR * m_alignmentInfoBar
void onUnitsChanged(wxCommandEvent &aEvent)
void doIncrementOffset(wxSpinEvent &aEvent, double aSign)
BOARD_ADAPTER m_boardAdapter
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.
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)
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.
const PAD * m_alignHoverPad
VECTOR3D m_alignAnimFromRotation
PCB_BASE_FRAME * m_parentFrame
void SetEmbeddedFilesDelegate(EMBEDDED_FILES *aDelegate)
EDA_3D_CANVAS * m_previewPane
EXTRUDED_3D_BODY * m_extrudedBody
void SetExtrusionTransformMode(EXTRUDED_3D_BODY *aBody)
void doIncrementScale(wxSpinEvent &aEvent, double aSign)
bool pickAlignment(const RAY &aRay)
void updateOrientation(wxCommandEvent &event) override
It will receive the events from editing the fields.
const S3DMODEL * alignmentModel()
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 restoreAlignmentView()
FOOTPRINT * m_dummyFootprint
TRACK_BALL m_trackBallCamera
std::vector< MODEL_ALIGN::ALIGN_SOLUTION > m_alignSolutions
std::map< std::array< unsigned int, 2 >, size_t > m_alignTriangleRegions
void onPanelShownEvent(wxCommandEvent &aEvent)
void stopAlignmentAnimation()
EMBEDDED_FILES * m_localEmbeddedFiles
VECTOR3D m_alignAnimOffset
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
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Return the BOARD_DESIGN_SETTINGS for the open project.
virtual COMMON_SETTINGS * GetCommonSettings() const
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
RAII class that sets an value at construction and resets it to the original value at destruction.
size_t GetTriangleCount() const
void GetTriangle(int index, VECTOR2I &a, VECTOR2I &b, VECTOR2I &c) const
Represent a set of closed polygons.
virtual void CacheTriangulation(bool aSimplify=false, const TASK_SUBMITTER &aSubmitter={})
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
const TRIANGULATED_POLYGON * TriangulatedPolygon(int aIndex) const
unsigned int TriangulatedPolyCount() const
Return the number of triangulated polygons.
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.
EDA_UNITS GetUserUnits() const
A modified version of the wxInfoBar class that allows us to:
An extension of WX_TEXT_ENTRY_DIALOG that uses UNIT_BINDER to request a dimension (e....
int GetValue()
Return the value in internal units.
static constexpr EDA_ANGLE ANGLE_0
static const std::string StepFileAbrvExtension
static const std::string StepFileExtension
static const std::string StepZFileAbrvExtension
@ LAYER_3D_SOLDERMASK_TOP
@ LAYER_3D_SOLDERMASK_BOTTOM
@ LAYER_3D_PLATED_BARRELS
PCB_LAYER_ID
A quick note on layer IDs:
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
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)
std::vector< REGION > BuildRegions(const S3DMODEL &aModel, const glm::dvec3 &aScale)
std::vector< PAD > BuildPadGroup(const std::vector< PAD > &aPads, size_t aClickedPad)
Return the clicked pad first, followed by its congruent, deduplicated peers.
std::vector< ALIGN_SOLUTION > SolveAlignment(const std::vector< REGION > &aRegions, size_t aSeed, const std::vector< PAD > &aPadGroup, const std::vector< PAD > &aAllPads, const glm::dvec3 &aCurrentRotation)
The first element of aPadGroup must be the clicked pad; all coordinates are millimetres,...
Declaration of the cogl_att_list class.
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
static double normalizeRotation(double aRotation)
Normalize a rotation in degrees to the half-open range (-MAX_ROTATION, MAX_ROTATION].
static constexpr int ALIGN_ANIMATION_INTERVAL_MS
static constexpr double ALIGN_ANIMATION_SECONDS
Duration and frame interval of the slide from the old placement to the aligned one.
static double rotationFromString(const wxString &aValue)
static wxString evaluateTextCtrl(const wxString &aValue)
#define OFFSET_INCREMENT_MM_FINE
#define OFFSET_INCREMENT_MIL
#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.
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
T * GetAppSettings(const char *aFilename)
A translucent triangle soup drawn over the scene.
bool preview_show_board_body
glm::dvec3 rotation
GUI degrees of Rz * Ry * Rx; negate when storing in FP_3DMODEL.
glm::dvec3 offset
Footprint-local millimetres, Y up.
glm::dvec2 position
Footprint-local millimetres, Y up.
double rotation
Degrees in the Y-up frame.
std::vector< std::array< unsigned int, 3 > > triangles
std::vector< glm::dvec3 > vertices
Scaled model coordinates, millimetres.
Store the a model based on meshes and materials.
VECTOR2< int32_t > VECTOR2I
VECTOR3< double > VECTOR3D
bool compareFileExtensions(const std::string &aExtension, const std::vector< std::string > &aReference, bool aCaseSensitive)
Compare the given extension against the reference extensions to see if it matches any of the referenc...
Definition of file extensions used in Kicad.