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 );
185 wxString default_path;
189 default_path.Replace( wxT(
"/" ), wxT(
"\\" ) );
195 wxString origPath, alias, shortPath;
201 origPath =
model.m_Filename;
203 if(
res &&
res->SplitAlias( origPath, alias, shortPath ) )
204 origPath = alias + wxT(
":" ) + shortPath;
228 aModelIdx = std::max( 0, aModelIdx );
229 aModelIdx = std::min( aModelIdx,
m_modelsGrid->GetNumberRows() - 1 );
252 if( !aFilename->empty() )
254 bool hasAlias =
false;
257 aFilename->Replace( wxT(
"\n" ), wxT(
"" ) );
258 aFilename->Replace( wxT(
"\r" ), wxT(
"" ) );
259 aFilename->Replace( wxT(
"\t" ), wxT(
"" ) );
261 res->ValidateFileName( *aFilename, hasAlias );
265 aFilename->insert( 0, wxT(
":" ) );
269 aFilename->Replace( wxT(
"\\" ), wxT(
"/" ) );
288 if( !filename.empty() )
306 m_shapes3D_list[ aEvent.GetRow() ].m_Show = ( showValue == wxT(
"1" ) );
322 wxArrayInt selectedRows =
m_modelsGrid->GetSelectedRows();
323 wxGridCellCoordsArray selectedCells =
m_modelsGrid->GetSelectedCells();
324 wxGridCellCoordsArray blockTopLeft =
m_modelsGrid->GetSelectionBlockTopLeft();
325 wxGridCellCoordsArray blockBottomRight =
m_modelsGrid->GetSelectionBlockBottomRight();
327 for(
unsigned ii = 0; ii < selectedCells.GetCount(); ++ii )
328 selectedRows.Add( selectedCells[ii].GetRow() );
330 if( !blockTopLeft.IsEmpty() && !blockBottomRight.IsEmpty() )
332 for(
int row = blockTopLeft[0].GetRow(); row <= blockBottomRight[0].GetRow(); ++row )
333 selectedRows.Add( row );
336 if( selectedRows.empty() &&
m_modelsGrid->GetGridCursorRow() >= 0 )
339 if( selectedRows.empty() )
345 std::sort( selectedRows.begin(), selectedRows.end() );
347 int nextSelection = selectedRows.front();
356 for(
int ii = selectedRows.size() - 1; ii >= 0; --ii )
358 int row = selectedRows[ii];
375 nextSelection = std::min( nextSelection,
m_modelsGrid->GetNumberRows() - 1 );
405 if( initialpath.IsEmpty() )
408 || initialpath.IsEmpty() )
419 if( tmp > 0 && tmp <= INT_MAX )
428 if( retval != wxID_OK ||
model.m_Filename.empty() )
441 wxString libraryName =
m_footprint->GetFPID().GetLibNickname();
442 wxString footprintBasePath = wxEmptyString;
444 std::optional<LIBRARY_TABLE_ROW*> fpRow =
449 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
450 embeddedFilesStack.push_back(
m_filesPanel->GetLocalFiles() );
451 embeddedFilesStack.push_back(
m_frame->GetBoard()->GetEmbeddedFiles() );
453 wxString fullPath =
res->ResolvePath(
model.m_Filename, footprintBasePath, std::move( embeddedFilesStack ) );
454 wxFileName fname( fullPath );
461 wxString msg = wxString::Format(
_(
"Error adding 3D model" ) );
462 wxMessageBox( msg,
_(
"Error" ), wxICON_ERROR | wxOK,
this );
470 sidx = wxString::Format( wxT(
"%i" ),
filter );
475 wxString filename =
model.m_Filename;
477 if(
res &&
res->SplitAlias( filename, alias, shortPath ) )
478 filename = alias + wxT(
":" ) + shortPath;
482 model.m_Filename.Replace( wxT(
"\\" ), wxT(
"/" ) );
504 [&]() -> std::pair<int, int>
533 if( cellEditor->IsCreated() && cellEditor->GetWindow()->IsShown() )
534 filename = cellEditor->GetValue();
536 cellEditor->DecRef();
547 icon = wxICON_WARNING;
548 errStr =
_(
"No filename entered" );
553 errStr =
_(
"Illegal filename" );
558 errStr =
_(
"File not found" );
563 errStr =
_(
"Unable to open file" );
568 errStr =
_(
"Unknown error" );
579 if( aFilename.empty() )
582 bool hasAlias =
false;
591 wxString libraryName =
m_footprint->GetFPID().GetLibNickname();
592 wxString footprintBasePath = wxEmptyString;
594 std::optional<LIBRARY_TABLE_ROW*> fpRow =
599 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
600 embeddedFilesStack.push_back(
m_filesPanel->GetLocalFiles() );
601 embeddedFilesStack.push_back(
m_frame->GetBoard()->GetEmbeddedFiles() );
603 wxString fullPath = resolv->
ResolvePath( aFilename, footprintBasePath, std::move( embeddedFilesStack ) );
605 if( fullPath.IsEmpty() )
608 if( !wxFileName::IsFileReadable( fullPath ) )
653 wxCommandEvent event( wxCUSTOM_PANEL_SHOWN_EVENT );
655 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.
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 on3DModelCellChanging(wxGridEvent &aEvent)
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
void cleanupFilename(wxString *aFilename)
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.