2020-05-13 02:00:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-08-17 15:31:49 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-05-13 02:00:37 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KICAD_SCHEMATIC_H
|
|
|
|
#define KICAD_SCHEMATIC_H
|
|
|
|
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2020-05-20 03:34:55 +00:00
|
|
|
#include <schematic_settings.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BUS_ALIAS;
|
|
|
|
class CONNECTION_GRAPH;
|
|
|
|
class EDA_BASE_FRAME;
|
|
|
|
class ERC_SETTINGS;
|
2020-05-21 02:27:48 +00:00
|
|
|
class PROJECT;
|
2020-05-13 02:00:37 +00:00
|
|
|
class SCH_SCREEN;
|
|
|
|
class SCH_SHEET;
|
2020-10-18 20:30:37 +00:00
|
|
|
class SCH_SHEET_LIST;
|
2022-11-03 04:12:53 +00:00
|
|
|
class SCH_GLOBALLABEL;
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2021-01-25 21:19:07 +00:00
|
|
|
class SCHEMATIC_IFACE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SCHEMATIC_IFACE() {};
|
|
|
|
virtual ~SCHEMATIC_IFACE() {};
|
|
|
|
|
|
|
|
virtual CONNECTION_GRAPH* ConnectionGraph() const = 0;
|
|
|
|
virtual SCH_SHEET_LIST GetSheets() const = 0;
|
|
|
|
virtual void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) = 0;
|
|
|
|
virtual SCH_SHEET_PATH& CurrentSheet() const = 0;
|
|
|
|
virtual wxString GetFileName() const = 0;
|
|
|
|
virtual PROJECT& Prj() const = 0;
|
|
|
|
};
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
/**
|
2021-03-25 21:13:01 +00:00
|
|
|
* Holds all the data relating to one schematic.
|
|
|
|
*
|
2020-05-13 02:00:37 +00:00
|
|
|
* A schematic may consist of one or more sheets (and one root sheet)
|
2021-03-25 21:13:01 +00:00
|
|
|
* Right now, Eeschema can have only one schematic open at a time, but this could change.
|
2020-05-13 02:00:37 +00:00
|
|
|
* Please keep this possibility in mind when adding to this object.
|
|
|
|
*/
|
2021-01-25 21:19:07 +00:00
|
|
|
class SCHEMATIC : public SCHEMATIC_IFACE, public EDA_ITEM
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-21 02:27:48 +00:00
|
|
|
SCHEMATIC( PROJECT* aPrj );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2021-01-25 21:19:07 +00:00
|
|
|
virtual ~SCHEMATIC();
|
2020-05-13 02:00:37 +00:00
|
|
|
|
|
|
|
virtual wxString GetClass() const override
|
|
|
|
{
|
|
|
|
return wxT( "SCHEMATIC" );
|
|
|
|
}
|
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
/// Initialize this schematic to a blank one, unloading anything existing.
|
2020-05-13 02:00:37 +00:00
|
|
|
void Reset();
|
|
|
|
|
2020-05-21 02:27:48 +00:00
|
|
|
/// Return a reference to the project this schematic is part of
|
2022-09-20 14:25:03 +00:00
|
|
|
PROJECT& Prj() const override { return *m_project; }
|
2020-06-08 02:19:46 +00:00
|
|
|
void SetProject( PROJECT* aPrj );
|
2020-05-21 02:27:48 +00:00
|
|
|
|
2022-09-20 14:25:03 +00:00
|
|
|
const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
/**
|
|
|
|
* Builds and returns an updated schematic hierarchy
|
|
|
|
* TODO: can this be cached?
|
|
|
|
* @return a SCH_SHEET_LIST containing the schematic hierarchy
|
|
|
|
*/
|
2021-01-25 21:19:07 +00:00
|
|
|
SCH_SHEET_LIST GetSheets() const override
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
|
|
|
return SCH_SHEET_LIST( m_rootSheet );
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_SHEET& Root() const
|
|
|
|
{
|
|
|
|
return *m_rootSheet;
|
|
|
|
}
|
|
|
|
|
2020-05-23 19:11:02 +00:00
|
|
|
/**
|
2021-03-25 21:13:01 +00:00
|
|
|
* Initialize the schematic with a new root sheet.
|
|
|
|
*
|
2020-05-23 19:11:02 +00:00
|
|
|
* This is typically done by calling a file loader that returns the new root sheet
|
|
|
|
* As a side-effect, takes care of some post-load initialization.
|
2021-03-25 21:13:01 +00:00
|
|
|
*
|
2020-05-23 19:11:02 +00:00
|
|
|
* @param aRootSheet is the new root sheet for this schematic.
|
|
|
|
*/
|
|
|
|
void SetRoot( SCH_SHEET* aRootSheet );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
|
|
|
/// A simple test if the schematic is loaded, not a complete one
|
|
|
|
bool IsValid() const
|
|
|
|
{
|
|
|
|
return m_rootSheet != nullptr;
|
|
|
|
}
|
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
/// Helper to retrieve the screen of the root sheet
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREEN* RootScreen() const;
|
|
|
|
|
2021-07-06 12:27:36 +00:00
|
|
|
bool ResolveTextVar( wxString* token, int aDepth ) const;
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
/// Helper to retrieve the filename from the root sheet screen
|
2021-01-25 21:19:07 +00:00
|
|
|
wxString GetFileName() const override;
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2021-01-25 21:19:07 +00:00
|
|
|
SCH_SHEET_PATH& CurrentSheet() const override
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
|
|
|
return *m_currentSheet;
|
|
|
|
}
|
|
|
|
|
2021-01-25 21:19:07 +00:00
|
|
|
void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) override
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
|
|
|
*m_currentSheet = aPath;
|
|
|
|
}
|
|
|
|
|
2021-01-25 21:19:07 +00:00
|
|
|
CONNECTION_GRAPH* ConnectionGraph() const override
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
|
|
|
return m_connectionGraph;
|
|
|
|
}
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
SCHEMATIC_SETTINGS& Settings() const;
|
|
|
|
|
|
|
|
ERC_SETTINGS& ErcSettings() const;
|
2020-05-20 03:34:55 +00:00
|
|
|
|
2020-11-18 22:55:38 +00:00
|
|
|
std::vector<SCH_MARKER*> ResolveERCExclusions();
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
/**
|
2021-03-25 21:13:01 +00:00
|
|
|
* Return a pointer to a bus alias object for the given label, or null if one
|
2020-07-06 10:51:04 +00:00
|
|
|
* doesn't exist.
|
2020-05-13 02:00:37 +00:00
|
|
|
*/
|
|
|
|
std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
|
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
/**
|
2022-09-03 18:29:02 +00:00
|
|
|
* Return the set of netname candidates for netclass assignment. The list will include both
|
2020-07-06 10:51:04 +00:00
|
|
|
* composite names (buses) and atomic net names. Names are fetched from available labels,
|
|
|
|
* power pins, etc.
|
|
|
|
*/
|
2022-09-03 18:29:02 +00:00
|
|
|
std::set<wxString> GetNetClassAssignmentCandidates();
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2020-07-29 17:02:39 +00:00
|
|
|
/**
|
|
|
|
* Resolves text vars that refer to other items.
|
|
|
|
* Note that the actual resolve is delegated to the symbol/sheet in question. This routine
|
|
|
|
* just does the look-up and delegation.
|
|
|
|
*/
|
|
|
|
bool ResolveCrossReference( wxString* token, int aDepth ) const;
|
|
|
|
|
2022-07-23 03:02:05 +00:00
|
|
|
std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
|
2020-11-17 16:02:47 +00:00
|
|
|
|
2022-08-04 20:58:15 +00:00
|
|
|
std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
|
|
|
|
std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
|
|
|
|
|
2020-07-29 17:02:39 +00:00
|
|
|
wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
|
|
|
|
wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
/**
|
2021-03-25 21:13:01 +00:00
|
|
|
* Return the full schematic flattened hierarchical sheet list.
|
2020-10-18 20:30:37 +00:00
|
|
|
*/
|
|
|
|
SCH_SHEET_LIST& GetFullHierarchy() const;
|
|
|
|
|
2022-08-17 15:31:49 +00:00
|
|
|
/**
|
|
|
|
* Update the symbol value and footprint instance data for legacy designs.
|
|
|
|
*
|
|
|
|
* Prior to schematic file format version 20200828 and legacy file format version, only
|
|
|
|
* symbol reference field and unit were saved in the instance data. The value and footprint
|
|
|
|
* fields must be carried forward from the original symbol to prevent data loss.
|
|
|
|
*/
|
|
|
|
void SetLegacySymbolInstanceData();
|
2020-07-29 17:02:39 +00:00
|
|
|
|
2022-10-26 21:59:33 +00:00
|
|
|
/**
|
|
|
|
* @return a filename that can be used in plot and print functions for the current screen
|
|
|
|
* and sheet path. This filename is unique and must be used instead of the screen filename
|
|
|
|
* when one must create files for each sheet in the hierarchy.
|
|
|
|
* Name is <root sheet filename>-<sheet path> and has no extension.
|
|
|
|
* However if filename is too long name is <sheet filename>-<sheet number>
|
|
|
|
*/
|
|
|
|
wxString GetUniqueFilenameForCurrentSheet();
|
|
|
|
|
2022-11-03 03:38:02 +00:00
|
|
|
/**
|
|
|
|
* Set the m_ScreenNumber and m_NumberOfScreens members for screens.
|
|
|
|
*
|
|
|
|
* @note This must be called after deleting or adding a sheet and when entering a sheet.
|
|
|
|
*/
|
|
|
|
void SetSheetNumberAndCount();
|
|
|
|
|
2022-11-03 04:12:53 +00:00
|
|
|
/**
|
|
|
|
* Update the schematic's page reference map for all global labels, and refresh the labels
|
|
|
|
* so that they are redrawn with up-to-date references.
|
|
|
|
*/
|
|
|
|
void RecomputeIntersheetRefs( bool autoplaceUninitialized,
|
|
|
|
const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void Show( int nestLevel, std::ostream& os ) const override {}
|
|
|
|
#endif
|
2021-03-25 21:13:01 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SCH_EDIT_FRAME;
|
|
|
|
|
|
|
|
PROJECT* m_project;
|
|
|
|
|
|
|
|
/// The top-level sheet in this schematic hierarchy (or potentially the only one)
|
|
|
|
SCH_SHEET* m_rootSheet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The sheet path of the sheet currently being edited or displayed.
|
|
|
|
* Note that this was moved here from SCH_EDIT_FRAME because currently many places in the code
|
|
|
|
* want to know the current sheet. Potentially this can be moved back to the UI code once
|
|
|
|
* the only places that want to know it are UI-related
|
|
|
|
*/
|
|
|
|
SCH_SHEET_PATH* m_currentSheet;
|
|
|
|
|
|
|
|
/// Holds and calculates connectivity information of this schematic
|
|
|
|
CONNECTION_GRAPH* m_connectionGraph;
|
|
|
|
|
|
|
|
/**
|
2022-07-23 03:02:05 +00:00
|
|
|
* Holds a map of labels to the page sequence (virtual page number) that they appear on. It is
|
|
|
|
* used for updating global label intersheet references.
|
2021-03-25 21:13:01 +00:00
|
|
|
*/
|
2022-07-23 03:02:05 +00:00
|
|
|
std::map<wxString, std::set<int>> m_labelToPageRefsMap;
|
2022-09-20 14:25:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Properties for text variable substitution (and perhaps other uses in future).
|
|
|
|
*/
|
|
|
|
std::map<wxString, wxString> m_properties;
|
2020-05-13 02:00:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|