98 wxGridCellAttr* attr =
new wxGridCellAttr;
103 attr =
new wxGridCellAttr;
108 wxT(
"*.*" ),
true,
m_frame->Prj().GetProjectPath(),
109 [
this](
const wxString& aFile ) -> wxString
111 EMBEDDED_FILES::EMBEDDED_FILE* result = m_filesPanel->AddEmbeddedFile( aFile );
115 wxString msg = wxString::Format( _(
"Error adding 3D model" ) );
116 wxMessageBox( msg, _(
"Error" ), wxICON_ERROR | wxOK, this );
127 attr =
new wxGridCellAttr;
128 attr->SetRenderer(
new wxGridCellBoolRenderer() );
130 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
131 m_modelsGrid->SetColAttr(
COL_SHOWN, attr );
132 m_modelsGrid->SetWindowStyleFlag( m_modelsGrid->GetWindowStyle() & ~wxHSCROLL );
138 m_previewPane->SetEmbeddedFilesDelegate( m_filesPanel->GetLocalFiles() );
140 m_LowerSizer3D->Add( m_previewPane, 1, wxEXPAND, 5 );
183 wxString default_path;
187 default_path.Replace( wxT(
"/" ), wxT(
"\\" ) );
193 wxString origPath, alias, shortPath;
199 origPath = model.m_Filename;
201 if(
res &&
res->SplitAlias( origPath, alias, shortPath ) )
202 origPath = alias + wxT(
":" ) + shortPath;
226 aModelIdx = std::max( 0, aModelIdx );
227 aModelIdx = std::min( aModelIdx,
m_modelsGrid->GetNumberRows() - 1 );
252 bool hasAlias =
false;
257 if( !filename.empty() )
259 filename.Replace( wxT(
"\n" ), wxT(
"" ) );
260 filename.Replace( wxT(
"\r" ), wxT(
"" ) );
261 filename.Replace( wxT(
"\t" ), wxT(
"" ) );
263 res->ValidateFileName( filename, hasAlias );
267 filename.insert( 0, wxT(
":" ) );
271 filename.Replace( wxT(
"\\" ), wxT(
"/" ) );
288 m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT(
"1" ) );
304 wxArrayInt selectedRows =
m_modelsGrid->GetSelectedRows();
305 wxGridCellCoordsArray selectedCells =
m_modelsGrid->GetSelectedCells();
306 wxGridCellCoordsArray blockTopLeft =
m_modelsGrid->GetSelectionBlockTopLeft();
307 wxGridCellCoordsArray blockBottomRight =
m_modelsGrid->GetSelectionBlockBottomRight();
309 for(
unsigned ii = 0; ii < selectedCells.GetCount(); ++ii )
310 selectedRows.Add( selectedCells[ii].GetRow() );
312 if( !blockTopLeft.IsEmpty() && !blockBottomRight.IsEmpty() )
314 for(
int row = blockTopLeft[0].GetRow(); row <= blockBottomRight[0].GetRow(); ++row )
315 selectedRows.Add( row );
318 if( selectedRows.empty() &&
m_modelsGrid->GetGridCursorRow() >= 0 )
321 if( selectedRows.empty() )
327 std::sort( selectedRows.begin(), selectedRows.end() );
329 int nextSelection = selectedRows.front();
338 for(
int ii = selectedRows.size() - 1; ii >= 0; --ii )
340 int row = selectedRows[ii];
357 nextSelection = std::min( nextSelection,
m_modelsGrid->GetNumberRows() - 1 );
387 if( initialpath.IsEmpty() )
390 || initialpath.IsEmpty() )
401 if( tmp > 0 && tmp <= INT_MAX )
410 if( retval != wxID_OK || model.
m_Filename.empty() )
423 wxString libraryName =
m_footprint->GetFPID().GetLibNickname();
424 wxString footprintBasePath = wxEmptyString;
426 std::optional<LIBRARY_TABLE_ROW*> fpRow =
431 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
432 embeddedFilesStack.push_back(
m_filesPanel->GetLocalFiles() );
433 embeddedFilesStack.push_back(
m_frame->GetBoard()->GetEmbeddedFiles() );
435 wxString fullPath =
res->ResolvePath( model.
m_Filename, footprintBasePath, std::move( embeddedFilesStack ) );
436 wxFileName fname( fullPath );
443 wxString msg = wxString::Format(
_(
"Error adding 3D model" ) );
444 wxMessageBox( msg,
_(
"Error" ), wxICON_ERROR | wxOK,
this );
452 sidx = wxString::Format( wxT(
"%i" ),
filter );
459 if(
res &&
res->SplitAlias( filename, alias, shortPath ) )
460 filename = alias + wxT(
":" ) + shortPath;
464 model.
m_Filename.Replace( wxT(
"\\" ), wxT(
"/" ) );
486 [&]() -> std::pair<int, int>
520 icon = wxICON_WARNING;
521 errStr =
_(
"No filename entered" );
526 errStr =
_(
"Illegal filename" );
531 errStr =
_(
"File not found" );
536 errStr =
_(
"Unable to open file" );
541 errStr =
_(
"Unknown error" );
552 if( aFilename.empty() )
555 bool hasAlias =
false;
564 wxString libraryName =
m_footprint->GetFPID().GetLibNickname();
565 wxString footprintBasePath = wxEmptyString;
567 std::optional<LIBRARY_TABLE_ROW*> fpRow =
572 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
573 embeddedFilesStack.push_back(
m_filesPanel->GetLocalFiles() );
574 embeddedFilesStack.push_back(
m_frame->GetBoard()->GetEmbeddedFiles() );
576 wxString fullPath = resolv->
ResolvePath( aFilename, footprintBasePath, std::move( embeddedFilesStack ) );
578 if( fullPath.IsEmpty() )
581 if( !wxFileName::IsFileReadable( fullPath ) )
626 wxCommandEvent event( wxCUSTOM_PANEL_SHOWN_EVENT );
628 event.SetInt(
static_cast<int>( predicate ) );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
bool IsEmbedded3DModel() const
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Provide an extensible class to resolve 3D model paths.
bool ValidateFileName(const wxString &aFileName, bool &hasAlias) const
Return true if the given path is a valid aliased relative path.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Determine the full path of the given file name.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
wxString m_Filename
The 3D shape filename in 3D library.
bool m_Show
Include model in rendering.
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
void SetTooltipEnable(int aCol, bool aEnable=true)
Enable the tooltip for a column.
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) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
wxSplitterWindow * m_splitter1
PANEL_FP_PROPERTIES_3D_MODEL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(778, 286), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
STD_BITMAP_BUTTON * m_button3DShapeRemove
void OnUpdateUI(wxUpdateUIEvent &event) override
void Cfg3DPath(wxCommandEvent &event) override
void OnRemove3DModel(wxCommandEvent &event) override
virtual void onShowEvent(wxShowEvent &aEvent)
void On3DModelCellChanged(wxGridEvent &aEvent) override
virtual void onDialogActivateEvent(wxActivateEvent &aEvent)
~PANEL_FP_PROPERTIES_3D_MODEL() override
PCB_BASE_EDIT_FRAME * m_frame
void ReloadModelsFromFootprint()
DIALOG_SHIM * m_parentDialog
bool TransferDataToWindow() override
PANEL_PREVIEW_3D_MODEL * m_previewPane
PANEL_FP_PROPERTIES_3D_MODEL(PCB_BASE_EDIT_FRAME *aFrame, FOOTPRINT *aFootprint, DIALOG_SHIM *aDialogParent, PANEL_EMBEDDED_FILES *aFilesPanel, wxWindow *aParent)
void postCustomPanelShownEventWithPredicate(bool predicate)
void updateValidateStatus(int aRow)
bool TransferDataFromWindow() override
MODEL_VALIDATE_ERRORS validateModelExists(const wxString &aFilename)
void OnAdd3DModel(wxCommandEvent &event) override
void OnAdd3DRow(wxCommandEvent &event) override
PANEL_EMBEDDED_FILES * m_filesPanel
std::vector< FP_3DMODEL > m_shapes3D_list
void On3DModelSelected(wxGridEvent &) override
void select3DModel(int aModelIdx)
wxString m_LastFootprint3dDir
Common, abstract interface for edit frames.
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
static FILENAME_RESOLVER * Get3DFilenameResolver(PROJECT *aProject)
Accessor for 3D path resolver.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
Cache for storing the 3D shapes.
void FlushCache(bool closePlugins=true)
Free all data in the cache and by default closes all plugins.
FILENAME_RESOLVER * GetResolver() noexcept
Declaration of the eda_3d_viewer class.
Functions related to environment variables, including help functions.
KICOMMON_API wxString GetVersionedEnvVarName(const wxString &aBaseName)
Construct a versioned environment variable based on this KiCad major version.
wxDEFINE_EVENT(wxCUSTOM_PANEL_SHOWN_EVENT, wxCommandEvent)
PGM_BASE & Pgm()
The global program "get" accessor.
T * GetAppSettings(const char *aFilename)
wxString result
Test unit parsing edge cases and error handling.