31 #include <wx/clipbrd.h> 46 wxASSERT( aSheet && aHierarchy );
56 wxASSERT( destFile.IsAbsolute() );
60 msg.Printf(
_(
"The sheet changes cannot be made because the destination sheet already " 61 "has the sheet \"%s\" or one of it's subsheets as a parent somewhere in " 62 "the schematic hierarchy." ),
63 destFile.GetFullPath() );
74 wxASSERT( aSheet && aSheet->
GetScreen() );
81 msg.Printf(
_(
"The schematic \"%s\" has not had it's symbol library links remapped " 82 "to the symbol library table. The project this schematic belongs to " 83 "must first be remapped before it can be imported into the current " 102 const wxString& aFileName )
104 wxASSERT( aSheet && aHierarchy );
107 wxString topLevelSheetPath;
109 wxFileName currentSheetFileName;
110 bool libTableChanged =
false;
114 std::unique_ptr< SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( &
Schematic() );
118 const_cast<KIID&>( newSheet->m_Uuid ) =
KIID( 0 );
120 wxFileName fileName( aFileName );
122 if( !fileName.IsAbsolute() && !fileName.MakeAbsolute() )
124 wxFAIL_MSG(
wxString::Format(
"Cannot make file name \"%s\" path absolute.", aFileName ) );
128 wxString fullFilename = fileName.GetFullPath();
134 newSheet.reset( pi->Load( fullFilename, &
Schematic() ) );
138 newSheet->SetFileName( fullFilename );
139 pi->Load( fullFilename, &
Schematic(), newSheet.get() );
142 if( !pi->GetError().IsEmpty() )
144 msg =
_(
"The entire schematic could not be loaded. Errors occurred attempting " 145 "to load hierarchical sheet schematics." );
147 wxMessageDialog msgDlg1(
this, msg,
_(
"Schematic Load Error" ),
148 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
149 wxCENTER | wxICON_QUESTION );
150 msgDlg1.SetOKLabel( wxMessageDialog::ButtonLabel(
_(
"Use partial schematic" ) ) );
151 msgDlg1.SetExtendedMessage( pi->GetError() );
153 if( msgDlg1.ShowModal() == wxID_CANCEL )
159 msg.Printf(
_(
"Error occurred loading schematic file \"%s\"." ), fullFilename );
162 msg.Printf(
_(
"Failed to load schematic \"%s\"" ), fullFilename );
172 if( fileName.GetPathWithSep() !=
Prj().
GetProjectPath() && newSheet->CountSheets() )
175 if( tmp.MakeRelativeTo(
Prj().GetProjectPath() ) )
176 topLevelSheetPath = tmp.GetPathWithSep();
178 topLevelSheetPath = fileName.GetPathWithSep();
180 if( wxFileName::GetPathSeparator() ==
'\\' )
181 topLevelSheetPath.Replace(
"\\",
"/" );
197 wxArrayString newLibNames;
201 newScreens.GetLibNicknames( names );
203 wxMessageDialog::ButtonLabel okButtonLabel(
_(
"Continue Load" ) );
204 wxMessageDialog::ButtonLabel cancelButtonLabel(
_(
"Cancel Load" ) );
207 && !prjScreens.HasSchematic( fullFilename ) )
213 for(
const auto&
name : names )
215 if( !
Prj().SchSymbolLibTable()->HasLibrary(
name ) )
216 newLibNames.Add(
name );
219 if( !newLibNames.IsEmpty() )
221 msg =
_(
"There are library names in the loaded schematic that are missing " 222 "from the project library table. This may result in broken symbol " 223 "library links for the loaded schematic. Do you wish to continue?" );
224 wxMessageDialog msgDlg3(
this, msg,
_(
"Continue Load Schematic" ),
225 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
226 wxCENTER | wxICON_QUESTION );
227 msgDlg3.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
229 if( msgDlg3.ShowModal() == wxID_CANCEL )
241 wxArrayString duplicateLibNames;
243 for(
const auto&
name : names )
245 if( !
Prj().SchSymbolLibTable()->HasLibrary(
name ) )
246 newLibNames.Add(
name );
248 duplicateLibNames.Add(
name );
252 wxFileName symLibTableFn( fileName.GetPath(),
257 if( !newLibNames.IsEmpty() || !duplicateLibNames.IsEmpty() )
259 if( !symLibTableFn.Exists() || !symLibTableFn.IsFileReadable() )
261 msg.Printf(
_(
"The project library table \"%s\" does not exist or cannot " 262 "be read. This may result in broken symbol links for the " 263 "schematic. Do you wish to continue?" ),
264 fileName.GetFullPath() );
265 wxMessageDialog msgDlg4(
this, msg,
_(
"Continue Load Schematic" ),
266 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
267 wxCENTER | wxICON_QUESTION );
268 msgDlg4.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
270 if( msgDlg4.ShowModal() == wxID_CANCEL )
277 table.
Load( symLibTableFn.GetFullPath() );
281 msg.Printf(
_(
"An error occurred loading the symbol library table \"%s\"." ),
282 symLibTableFn.GetFullPath() );
292 if( !newLibNames.IsEmpty() )
294 bool missingLibNames = table.
IsEmpty();
296 if( !missingLibNames )
298 for(
const auto& newLibName : newLibNames )
302 missingLibNames =
true;
308 if( missingLibNames )
310 msg =
_(
"There are library names in the loaded schematic that are missing " 311 "from the loaded schematic project library table. This may result " 312 "in broken symbol library links for the schematic. " 313 "Do you wish to continue?" );
314 wxMessageDialog msgDlg5(
this, msg,
_(
"Continue Load Schematic" ),
315 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
316 wxCENTER | wxICON_QUESTION );
317 msgDlg5.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
319 if( msgDlg5.ShowModal() == wxID_CANCEL )
327 if( !duplicateLibNames.IsEmpty() && !table.
IsEmpty() )
329 bool libNameConflict =
false;
331 for(
const auto& duplicateLibName : duplicateLibNames )
336 if(
Prj().SchSymbolLibTable()->HasLibrary( duplicateLibName ) )
337 thisRow =
Prj().SchSymbolLibTable()->FindRow( duplicateLibName );
340 otherRow = table.
FindRow( duplicateLibName );
343 if( thisRow && !otherRow )
346 if( !thisRow || !otherRow )
349 wxFileName otherUriFileName;
350 wxString thisURI = thisRow->
GetFullURI(
true );
351 wxString otherURI = otherRow->
GetFullURI(
false);
353 if( otherURI.Contains(
"${KIPRJMOD}" ) || otherURI.Contains(
"$(KIPRJMOD)" ) )
357 otherUriFileName.SetPath( fileName.GetPath() );
358 otherUriFileName.SetFullName( otherURI.AfterLast(
'}' ) );
359 otherURI = otherUriFileName.GetFullPath();
362 if( thisURI != otherURI )
364 libNameConflict =
true;
369 if( libNameConflict )
371 msg =
_(
"A duplicate library name that references a different library exists " 372 "in the current library table. This conflict cannot be resolved and " 373 "may result in broken symbol library links for the schematic. " 374 "Do you wish to continue?" );
375 wxMessageDialog msgDlg6(
this, msg,
_(
"Continue Load Schematic" ),
376 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
377 wxCENTER | wxICON_QUESTION );
378 msgDlg6.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
380 if( msgDlg6.ShowModal() == wxID_CANCEL )
388 if( !newLibNames.IsEmpty() && !table.
IsEmpty() )
390 for(
const wxString& libName : newLibNames )
393 ||
Prj().SchSymbolLibTable()->HasLibrary( libName ) )
400 wxString uri = table.
GetFullURI( libName,
false );
403 if( uri.Contains(
"${KIPRJMOD}" ) || uri.Contains(
"$(KIPRJMOD)" ) )
407 newLib.SetPath( fileName.GetPath() );
408 newLib.SetFullName( uri.AfterLast(
'}' ) );
409 uri = newLib.GetFullPath();
420 wxCHECK( row,
false );
427 Prj().SchSymbolLibTable()->InsertRow( newRow );
428 libTableChanged =
true;
433 SCH_SCREEN* newScreen = newSheet->GetScreen();
434 wxCHECK_MSG( newScreen,
false,
"No screen defined for sheet." );
440 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
442 if( wxFileName( sheet->
GetFileName() ).IsRelative( wxPATH_UNIX ) )
446 if( libTableChanged )
448 Prj().SchSymbolLibTable()->Save(
Prj().GetProjectPath() +
466 bool* aClearAnnotationNewItems )
468 if( aSheet ==
NULL || aHierarchy ==
NULL )
474 if( dlg.ShowModal() == wxID_CANCEL )
493 double scale = ppi / inch2Iu;
495 wxSize dcsize = DrawArea.GetSize();
497 int maxdim = std::max( dcsize.x, dcsize.y );
500 const int maxbitmapsize = 5600;
502 while(
int( maxdim *
scale ) > maxbitmapsize )
505 scale = ppi / inch2Iu;
519 wxBitmap image( dcsize );
520 dc.SelectObject( image );
534 if( wxTheClipboard->Open() )
537 wxBitmapDataObject* clipbrd_data =
new wxBitmapDataObject( image );
538 wxTheClipboard->SetData( clipbrd_data );
539 wxTheClipboard->Close();
544 dc.SelectObject( wxNullBitmap );
557 wxFileName fn = aSchematicFileName;
559 wxCHECK( fn.IsAbsolute(), false );
564 msg.Printf(
_(
"The file name \"%s\" can cause issues with an existing file name\n" 565 "already defined in the schematic on systems that support case\n" 566 "insensitive file names. This will cause issues if you copy this\n" 567 "project to an operating system that supports case insensitive file\n" 568 "names.\n\nDo you wish to continue?" ),
571 wxRichMessageDialog dlg(
this, msg,
_(
"Warning" ),
572 wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION );
573 dlg.ShowCheckBox(
_(
"Do not show this message again." ) );
574 dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Create New Sheet" ) ),
575 wxMessageDialog::ButtonLabel(
_(
"Discard New Sheet" ) ) );
577 if( dlg.ShowModal() == wxID_NO )
581 !dlg.IsCheckBoxChecked();
bool CheckSheetForRecursion(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy)
Verify that aSheet will not cause a recursion error in aHierarchy.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
EE_TYPE OfType(KICAD_T aType) const
static const wxString & GetSymbolLibTableFileName()
void GRResetPenAndBrush(wxDC *DC)
const wxString & GetFileName() const
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
virtual void PrintPage(const RENDER_SETTINGS *aSettings) override
Plot or print the current sheet to the clipboard.
This file is part of the common library.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
void DrawCurrentSheetToClipboard()
Use the wxWidgets print code to draw an image of the current sheet onto the clipboard.
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const
virtual const wxString GetProjectPath() const
Return the full path of the project.
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
const wxString & GetDescr() const
Return the description of the library referenced by this row.
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
EESCHEMA_SETTINGS * eeconfig() const
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static SCH_FILE_T GuessPluginTypeFromSchPath(const wxString &aSchematicPath)
Return a plugin type given a schematic using the file extension of aSchematicPath.
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device)
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName)
Test every SCH_SHEET_PATH in this SCH_SHEET_LIST to verify if adding the sheets stored in aSrcSheetHi...
void SetFileName(wxString aFilename)
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
bool AllowCaseSensitiveFileNameClashes(const wxString &aSchematicFileName)
Check aSchematicFileName for a potential file name case sensitivity clashes.
virtual const wxString What() const
A composite of Problem() and Where()
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
wxString GetFullURI(const wxString &aLibNickname, bool aExpandEnvVars=true) const
Return the full URI of the library mapped to aLibNickname.
Handles how to draw a screen (a board, a schematic ...)
const wxString GetType() const override
Return the type of symbol library table represented by this row.
SCHEMATIC & Schematic() const
Definition of file extensions used in Kicad.
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString GetFileName() const
Return the filename corresponding to this sheet.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
SCH_SCREEN * LastScreen()
void Append(SCH_ITEM *aItem)
bool show_sheet_filename_case_sensitivity_dialog
wxPoint m_DrawOrg
offsets for drawing the circuit on the screen
bool EditSheetProperties(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, bool *aClearAnnotationNewItems)
Edit an existing sheet or add a new sheet to the schematic.
int ReplaceDuplicateTimeStamps()
Test all sheet and component objects in the schematic for duplicate time stamps and replaces them as ...
bool CanCauseCaseSensitivityIssue(const wxString &aSchematicFileName) const
Check aSchematicFileName for a potential file name case sensitivity issue.
void SetFileName(const wxString &aFileName)
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
bool checkForNoFullyDefinedLibIds(SCH_SHEET *aSheet)
Verify that the symbol library links aSheet and all of it's child sheets have been remapped to the sy...
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Base class for any item which can be embedded within the SCHEMATIC container class,...
void SetPrintDC(wxDC *aDC)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.