2020-01-29 16:33:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Alexander Shuklin <Jasuramme@gmail.com>
|
2023-06-09 16:24:49 +00:00
|
|
|
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-01-29 16:33:57 +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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef BACKANNOTATE_H
|
|
|
|
#define BACKANNOTATE_H
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <sch_reference_list.h>
|
|
|
|
#include <template_fieldnames.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class REPORTER;
|
|
|
|
class SCH_SHEET_LIST;
|
|
|
|
class SCH_EDIT_FRAME;
|
2023-06-09 21:41:33 +00:00
|
|
|
class SCH_COMMIT;
|
2020-01-29 16:33:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Back annotation algorithm class used to receive, check, and apply a \ref NETLIST from
|
|
|
|
* Pcbnew.
|
|
|
|
*
|
2020-06-08 18:36:25 +00:00
|
|
|
* The following checks are made:
|
2021-01-26 15:23:37 +00:00
|
|
|
* - Schematic symbol exists, but linked Pcbnew footprint missing.
|
|
|
|
* - Pcbnew footprint exists but no schematic symbol connected to.
|
|
|
|
* - Pcbnew footprint is standalone.
|
2020-01-29 16:33:57 +00:00
|
|
|
* - Schematic sheet is reused one or more times and user trying to change footprint or value
|
2021-01-26 15:23:37 +00:00
|
|
|
* only for few of them.
|
|
|
|
* - Schematic symbols share same path.
|
|
|
|
* - More than one Pcbnew footprint linked to same path.
|
2020-01-29 16:33:57 +00:00
|
|
|
*/
|
|
|
|
class BACK_ANNOTATE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2021-03-24 13:25:32 +00:00
|
|
|
* Container for Pcbnew footprint data.
|
2020-01-29 16:33:57 +00:00
|
|
|
*/
|
2020-11-13 02:57:11 +00:00
|
|
|
struct PCB_FP_DATA
|
2020-01-29 16:33:57 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
PCB_FP_DATA( const wxString& aRef, const wxString& aFootprint, const wxString& aValue,
|
2023-05-01 12:53:36 +00:00
|
|
|
bool aDNP, bool aExcludeFromBOM,
|
2023-07-31 14:38:02 +00:00
|
|
|
const std::map<wxString, wxString>& aPinMap,
|
|
|
|
const std::map<wxString, wxString>& aFieldsMap ) :
|
2020-06-08 18:36:25 +00:00
|
|
|
m_ref( aRef ),
|
|
|
|
m_footprint( aFootprint ),
|
|
|
|
m_value( aValue ),
|
2023-05-01 12:53:36 +00:00
|
|
|
m_DNP( aDNP ),
|
|
|
|
m_excludeFromBOM( aExcludeFromBOM ),
|
2023-07-31 14:38:02 +00:00
|
|
|
m_pinMap( aPinMap ),
|
|
|
|
m_fieldsMap( aFieldsMap )
|
2023-05-01 12:53:36 +00:00
|
|
|
{}
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
wxString m_ref;
|
|
|
|
wxString m_footprint;
|
|
|
|
wxString m_value;
|
|
|
|
bool m_DNP;
|
|
|
|
bool m_excludeFromBOM;
|
2020-06-08 18:36:25 +00:00
|
|
|
std::map<wxString, wxString> m_pinMap;
|
2023-07-31 14:38:02 +00:00
|
|
|
std::map<wxString, wxString> m_fieldsMap;
|
2020-01-29 16:33:57 +00:00
|
|
|
};
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Map to hold NETLIST footprints data
|
2020-11-13 15:15:52 +00:00
|
|
|
using PCB_FOOTPRINTS_MAP = std::map<wxString, std::shared_ptr<PCB_FP_DATA>>;
|
2020-01-29 16:33:57 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
using CHANGELIST_ITEM = std::pair<SCH_REFERENCE, std::shared_ptr<PCB_FP_DATA>>;
|
2020-01-29 16:33:57 +00:00
|
|
|
|
2020-07-16 17:31:36 +00:00
|
|
|
BACK_ANNOTATE( SCH_EDIT_FRAME* aFrame, REPORTER& aReporter, bool aRelinkFootprints,
|
|
|
|
bool aProcessFootprints, bool aProcessValues, bool aProcessReferences,
|
2023-07-31 14:38:02 +00:00
|
|
|
bool aProcessNetNames, bool aProcessAttributes, bool aProcessOtherFields,
|
|
|
|
bool aDryRun );
|
2020-01-29 16:33:57 +00:00
|
|
|
~BACK_ANNOTATE();
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Get netlist from the Pcbnew.
|
|
|
|
*
|
2021-03-24 13:25:32 +00:00
|
|
|
* @param aNetlist is the netlist for the board editor.
|
|
|
|
* @return true if success.
|
2020-01-29 16:33:57 +00:00
|
|
|
*/
|
|
|
|
bool FetchNetlistFromPCB( std::string& aNetlist );
|
|
|
|
|
2020-07-16 17:31:36 +00:00
|
|
|
void PushNewLinksToPCB();
|
|
|
|
|
2020-01-29 16:33:57 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Run back annotation algorithm. If any errors, back annotation doesn't run.
|
|
|
|
*
|
2021-03-24 13:25:32 +00:00
|
|
|
* @param aNetlist is the netlist to use for back annotation.
|
|
|
|
* @return true if back annotation completed success.
|
2020-01-29 16:33:57 +00:00
|
|
|
*/
|
|
|
|
bool BackAnnotateSymbols( const std::string& aNetlist );
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Parse netlist sent over KiWay express mail interface and fill \ref m_pcbModules.
|
|
|
|
*
|
2021-03-24 13:25:32 +00:00
|
|
|
* @param aPayload is the netlist from Pcbnew.
|
|
|
|
* @return number of errors during parsing.
|
2020-01-29 16:33:57 +00:00
|
|
|
*/
|
2020-06-08 18:36:25 +00:00
|
|
|
void getPcbModulesFromString( const std::string& aPayload );
|
2020-01-29 16:33:57 +00:00
|
|
|
|
2021-03-24 13:25:32 +00:00
|
|
|
///< Create changelist.
|
2020-06-08 18:36:25 +00:00
|
|
|
void getChangeList();
|
2020-01-29 16:33:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Check if some symbols are not represented in PCB footprints and vice versa.
|
2021-03-24 13:25:32 +00:00
|
|
|
*
|
|
|
|
* \ref m_refs must be sorted by path.
|
2020-01-29 16:33:57 +00:00
|
|
|
*/
|
2020-06-08 18:36:25 +00:00
|
|
|
void checkForUnusedSymbols();
|
2020-01-29 16:33:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-24 13:25:32 +00:00
|
|
|
* Apply changelist to the schematic.
|
2021-01-26 15:23:37 +00:00
|
|
|
*/
|
2020-01-29 16:33:57 +00:00
|
|
|
void applyChangelist();
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
void processNetNameChange( SCH_COMMIT* aCommit, const wxString& aRef, SCH_PIN* aPin,
|
2020-11-25 22:16:06 +00:00
|
|
|
const SCH_CONNECTION* aConnection, const wxString& aOldName,
|
2020-06-08 18:36:25 +00:00
|
|
|
const wxString& aNewName );
|
2021-01-26 15:23:37 +00:00
|
|
|
|
|
|
|
REPORTER& m_reporter;
|
|
|
|
|
|
|
|
bool m_matchByReference;
|
|
|
|
bool m_processFootprints;
|
|
|
|
bool m_processValues;
|
|
|
|
bool m_processReferences;
|
|
|
|
bool m_processNetNames;
|
2023-05-01 12:53:36 +00:00
|
|
|
bool m_processAttributes;
|
2023-07-31 14:38:02 +00:00
|
|
|
bool m_processOtherFields;
|
2021-01-26 15:23:37 +00:00
|
|
|
bool m_dryRun;
|
|
|
|
|
|
|
|
PCB_FOOTPRINTS_MAP m_pcbFootprints;
|
|
|
|
SCH_REFERENCE_LIST m_refs;
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP m_multiUnitsRefs;
|
|
|
|
std::deque<CHANGELIST_ITEM> m_changelist;
|
|
|
|
SCH_EDIT_FRAME* m_frame;
|
|
|
|
|
|
|
|
int m_changesCount; // Number of user-level changes
|
2020-01-29 16:33:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|