42 #include <wx/clipbrd.h> 43 #include <wx/dcmemory.h> 49 wxASSERT( aSheet && aHierarchy );
59 wxASSERT( destFile.IsAbsolute() );
63 msg.Printf(
_(
"The sheet changes cannot be made because the destination sheet already " 64 "has the sheet '%s' or one of its subsheets as a parent somewhere in the " 65 "schematic hierarchy." ),
66 destFile.GetFullPath() );
77 wxASSERT( aSheet && aSheet->
GetScreen() );
84 msg.Printf(
_(
"The schematic '%s' has not had its symbol library links remapped " 85 "to the symbol library table. The project this schematic belongs to " 86 "must first be remapped before it can be imported into the current " 106 const wxString& aFileName )
108 wxASSERT( aSheet && aHierarchy );
111 wxString topLevelSheetPath;
113 wxFileName currentSheetFileName;
114 bool libTableChanged =
false;
117 std::unique_ptr< SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( &
Schematic() );
121 const_cast<KIID&>( newSheet->m_Uuid ) =
KIID( 0 );
123 wxFileName fileName( aFileName );
125 if( !fileName.IsAbsolute() && !fileName.MakeAbsolute() )
127 wxFAIL_MSG(
wxString::Format( wxT(
"Cannot make file name '%s' path absolute." ), aFileName ) );
131 wxString fullFilename = fileName.GetFullPath();
137 newSheet.reset( pi->Load( fullFilename, &
Schematic() ) );
141 newSheet->SetFileName( fullFilename );
142 pi->Load( fullFilename, &
Schematic(), newSheet.get() );
145 if( !pi->GetError().IsEmpty() )
147 msg =
_(
"The entire schematic could not be loaded. Errors occurred attempting " 148 "to load hierarchical sheet schematics." );
150 wxMessageDialog msgDlg1(
this, msg,
_(
"Schematic Load Error" ),
151 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
152 wxCENTER | wxICON_QUESTION );
153 msgDlg1.SetOKLabel( wxMessageDialog::ButtonLabel(
_(
"Use partial schematic" ) ) );
154 msgDlg1.SetExtendedMessage( pi->GetError() );
156 if( msgDlg1.ShowModal() == wxID_CANCEL )
162 msg.Printf(
_(
"Error loading schematic '%s'." ), fullFilename );
165 msg.Printf(
_(
"Failed to load '%s'." ), fullFilename );
175 if( fileName.GetPathWithSep() !=
Prj().
GetProjectPath() && newSheet->CountSheets() )
178 if( tmp.MakeRelativeTo(
Prj().GetProjectPath() ) )
179 topLevelSheetPath = tmp.GetPathWithSep();
181 topLevelSheetPath = fileName.GetPathWithSep();
183 if( wxFileName::GetPathSeparator() ==
'\\' )
184 topLevelSheetPath.Replace( wxT(
"\\" ), wxT(
"/" ) );
200 wxArrayString newLibNames;
204 newScreens.GetLibNicknames( names );
206 wxMessageDialog::ButtonLabel okButtonLabel(
_(
"Continue Load" ) );
207 wxMessageDialog::ButtonLabel cancelButtonLabel(
_(
"Cancel Load" ) );
209 if( !prjScreens.HasSchematic( fullFilename ) )
217 for(
const wxString&
name : names )
219 if( !
Prj().SchSymbolLibTable()->HasLibrary(
name ) )
220 newLibNames.Add(
name );
223 if( !newLibNames.IsEmpty() )
225 msg =
_(
"There are library names in the selected schematic that are missing " 226 "from the current project library table. This may result in broken " 227 "symbol library references for the loaded schematic.\n\n" 228 "Do you wish to continue?" );
229 wxMessageDialog msgDlg3(
this, msg,
_(
"Continue Load Schematic" ),
230 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
231 wxCENTER | wxICON_QUESTION );
232 msgDlg3.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
234 if( msgDlg3.ShowModal() == wxID_CANCEL )
246 wxArrayString duplicateLibNames;
248 for(
const wxString&
name : names )
250 if( !
Prj().SchSymbolLibTable()->HasLibrary(
name ) )
251 newLibNames.Add(
name );
253 duplicateLibNames.Add(
name );
257 wxFileName symLibTableFn( fileName.GetPath(),
262 if( !newLibNames.IsEmpty() || !duplicateLibNames.IsEmpty() )
264 if( !symLibTableFn.Exists() || !symLibTableFn.IsFileReadable() )
266 msg =
_(
"The selected file was created as part of a different project. " 267 "Linking the file to this project may result in missing or " 268 "incorrect symbol library references.\n\n" 269 "Do you wish to continue?" );
270 wxMessageDialog msgDlg4(
this, msg,
_(
"Continue Load Schematic" ),
271 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
272 wxCENTER | wxICON_QUESTION );
273 msgDlg4.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
275 if( msgDlg4.ShowModal() == wxID_CANCEL )
282 table.
Load( symLibTableFn.GetFullPath() );
286 msg.Printf(
_(
"Error loading the symbol library table '%s'." ),
287 symLibTableFn.GetFullPath() );
297 if( !newLibNames.IsEmpty() )
299 bool missingLibNames = table.
IsEmpty();
301 if( !missingLibNames )
303 for(
const wxString& newLibName : newLibNames )
307 missingLibNames =
true;
313 if( missingLibNames )
315 msg =
_(
"There are symbol library names in the selected schematic that " 316 "are missing from the selected schematic project library table. " 317 "This may result in broken symbol library references.\n\n" 318 "Do you wish to continue?" );
319 wxMessageDialog msgDlg5(
this, msg,
_(
"Continue Load Schematic" ),
320 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
321 wxCENTER | wxICON_QUESTION );
322 msgDlg5.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
324 if( msgDlg5.ShowModal() == wxID_CANCEL )
332 if( !duplicateLibNames.IsEmpty() && !table.
IsEmpty() )
334 bool libNameConflict =
false;
336 for(
const wxString& duplicateLibName : duplicateLibNames )
341 if(
Prj().SchSymbolLibTable()->HasLibrary( duplicateLibName ) )
342 thisRow =
Prj().SchSymbolLibTable()->FindRow( duplicateLibName );
345 otherRow = table.
FindRow( duplicateLibName );
348 if( thisRow && !otherRow )
351 if( !thisRow || !otherRow )
354 wxFileName otherUriFileName;
355 wxString thisURI = thisRow->
GetFullURI(
true );
356 wxString otherURI = otherRow->
GetFullURI(
false);
358 if( otherURI.Contains(
"${KIPRJMOD}" ) || otherURI.Contains(
"$(KIPRJMOD)" ) )
362 otherUriFileName.SetPath( fileName.GetPath() );
363 otherUriFileName.SetFullName( otherURI.AfterLast(
'}' ) );
364 otherURI = otherUriFileName.GetFullPath();
367 if( thisURI != otherURI )
369 libNameConflict =
true;
374 if( libNameConflict )
376 msg =
_(
"A duplicate library name that references a different library exists " 377 "in the current library table. This conflict cannot be resolved and " 378 "may result in broken symbol library references.\n\n" 379 "Do you wish to continue?" );
380 wxMessageDialog msgDlg6(
this, msg,
_(
"Continue Load Schematic" ),
381 wxOK | wxCANCEL | wxCANCEL_DEFAULT |
382 wxCENTER | wxICON_QUESTION );
383 msgDlg6.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
385 if( msgDlg6.ShowModal() == wxID_CANCEL )
393 if( !newLibNames.IsEmpty() && !table.
IsEmpty() )
395 for(
const wxString& libName : newLibNames )
398 ||
Prj().SchSymbolLibTable()->HasLibrary( libName ) )
405 wxString uri = table.
GetFullURI( libName,
false );
408 if( uri.Contains(
"${KIPRJMOD}" ) || uri.Contains(
"$(KIPRJMOD)" ) )
412 newLib.SetPath( fileName.GetPath() );
413 newLib.SetFullName( uri.AfterLast(
'}' ) );
414 uri = newLib.GetFullPath();
425 wxCHECK( row,
false );
432 Prj().SchSymbolLibTable()->InsertRow( newRow );
433 libTableChanged =
true;
439 SCH_SCREEN* newScreen = newSheet->GetScreen();
440 wxCHECK_MSG( newScreen,
false, wxT(
"No screen defined for sheet." ) );
442 if( libTableChanged )
444 Prj().SchSymbolLibTable()->Save(
Prj().GetProjectPath() +
462 bool* aClearAnnotationNewItems )
464 if( aSheet ==
nullptr || aHierarchy ==
nullptr )
470 if( dlg.ShowModal() == wxID_CANCEL )
489 double scale = ppi / inch2Iu;
491 wxSize dcsize = DrawArea.GetSize();
493 int maxdim = std::max( dcsize.x, dcsize.y );
496 const int maxbitmapsize = 5600;
498 while(
int( maxdim *
scale ) > maxbitmapsize )
501 scale = ppi / inch2Iu;
515 wxBitmap
image( dcsize );
516 dc.SelectObject(
image );
533 if( wxTheClipboard->Open() )
536 wxBitmapDataObject* clipbrd_data =
new wxBitmapDataObject(
image );
537 wxTheClipboard->SetData( clipbrd_data );
538 wxTheClipboard->Flush();
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.
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.
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Helper to retrieve a layer color from the global color settings.
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...
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)
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.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
drawingsheet frame and titleblock
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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.
void SetContentModified(bool aModified=true)
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 symbol objects in the schematic for duplicate time stamps and replaces them as nec...
bool CanCauseCaseSensitivityIssue(const wxString &aSchematicFileName) const
Check aSchematicFileName for a potential file name case sensitivity issue.
void SetFileName(const wxString &aFileName)
Set the file name for this screen to 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 its child sheets have been remapped to the sym...
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.
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.