2019-03-11 21:32:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 CERN
|
2021-06-14 18:00:08 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-03-11 21:32:05 +00:00
|
|
|
* @author Jon Evans <jon@craftyjon.com>
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SCH_CONNECTION_H
|
|
|
|
#define _SCH_CONNECTION_H
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
#include <wx/regex.h>
|
|
|
|
|
|
|
|
#include <bus_alias.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
class CONNECTION_GRAPH;
|
2019-03-11 21:32:05 +00:00
|
|
|
class SCH_ITEM;
|
|
|
|
class SCH_SHEET_PATH;
|
|
|
|
|
|
|
|
|
2020-01-18 20:51:28 +00:00
|
|
|
enum class CONNECTION_TYPE
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
NONE, ///< No connection to this item
|
|
|
|
NET, ///< This item represents a net
|
|
|
|
BUS, ///< This item represents a bus vector
|
|
|
|
BUS_GROUP, ///< This item represents a bus group
|
2019-03-11 21:32:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Each graphical item can have a SCH_CONNECTION describing its logical
|
|
|
|
* connection (to a bus or net). These are generated when netlisting, or when
|
|
|
|
* editing operations that can change the netlist are performed.
|
|
|
|
*
|
|
|
|
* In hierarchical schematics, a single SCH_ITEM object can refer to multiple
|
|
|
|
* distinct parts of a design (in the case of a sub-sheet that is instanced
|
|
|
|
* more than once in a higher level sheet). Because of this, a single item may
|
|
|
|
* contain more than one SCH_CONNECTION -- each is specific to a sheet.
|
|
|
|
*
|
2021-03-29 10:46:05 +00:00
|
|
|
* Symbols contain connections for each of their pins (and for each sheet they
|
|
|
|
* exist on) but don't use their own connection object.
|
2019-03-11 21:32:05 +00:00
|
|
|
*/
|
|
|
|
class SCH_CONNECTION
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SCH_CONNECTION( SCH_ITEM* aParent = nullptr, SCH_SHEET_PATH aPath = SCH_SHEET_PATH() );
|
|
|
|
|
2020-05-19 02:58:28 +00:00
|
|
|
SCH_CONNECTION( CONNECTION_GRAPH* aGraph );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
~SCH_CONNECTION()
|
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Note: the equality operator for SCH_CONNECTION only tests the net
|
|
|
|
* properties, not the ownership / sheet location!
|
|
|
|
*/
|
|
|
|
bool operator==( const SCH_CONNECTION& aOther ) const;
|
|
|
|
|
|
|
|
bool operator!=( const SCH_CONNECTION& aOther ) const;
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
void SetGraph( CONNECTION_GRAPH* aGraph )
|
|
|
|
{
|
|
|
|
m_graph = aGraph;
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
/**
|
|
|
|
* Configures the connection given a label.
|
|
|
|
* For CONNECTION_NET, this just sets the name.
|
|
|
|
* For CONNECTION_BUS, this will deduce the correct BUS_TYPE and also
|
|
|
|
* generate a correct list of members.
|
|
|
|
*/
|
2020-05-10 17:38:44 +00:00
|
|
|
void ConfigureFromLabel( const wxString& aLabel );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears connectivity information
|
|
|
|
*/
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies connectivity information (but not parent) from another connection
|
|
|
|
*
|
|
|
|
* @param aOther is the connection to clone
|
|
|
|
*/
|
2021-03-05 04:37:33 +00:00
|
|
|
void Clone( const SCH_CONNECTION& aOther );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
SCH_ITEM* Parent() const { return m_parent; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
SCH_ITEM* Driver() const { return m_driver; }
|
2019-03-11 21:32:05 +00:00
|
|
|
void SetDriver( SCH_ITEM* aItem );
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
SCH_SHEET_PATH Sheet() const { return m_sheet; }
|
2019-03-11 21:32:05 +00:00
|
|
|
void SetSheet( SCH_SHEET_PATH aSheet );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the SCH_ITEM this connection is attached to can drive connections
|
2021-06-14 18:00:08 +00:00
|
|
|
* Drivers can be labels, sheet pins, or symbol pins.
|
2019-03-11 21:32:05 +00:00
|
|
|
*
|
|
|
|
* @return true if the attached items is a driver
|
|
|
|
*/
|
|
|
|
bool IsDriver() const;
|
|
|
|
|
|
|
|
bool IsBus() const
|
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
return ( m_type == CONNECTION_TYPE::BUS || m_type == CONNECTION_TYPE::BUS_GROUP );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNet() const
|
|
|
|
{
|
2020-01-18 20:51:28 +00:00
|
|
|
return ( m_type == CONNECTION_TYPE::NET );
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 19:43:07 +00:00
|
|
|
bool IsUnconnected() const { return ( m_type == CONNECTION_TYPE::NONE ); }
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
bool IsDirty() const { return m_dirty; }
|
|
|
|
void SetDirty() { m_dirty = true; }
|
|
|
|
void ClearDirty() { m_dirty = false; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
bool HasDriverChanged() const;
|
|
|
|
void ClearDriverChanged();
|
|
|
|
void* GetLastDriver() const { return m_lastDriver; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-08-24 17:00:19 +00:00
|
|
|
wxString Name( bool aIgnoreSheet = false ) const;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-01-04 03:11:00 +00:00
|
|
|
wxString LocalName() const { return m_local_name; }
|
|
|
|
|
2020-05-24 23:16:21 +00:00
|
|
|
wxString FullLocalName() const
|
|
|
|
{
|
2021-03-05 04:37:33 +00:00
|
|
|
return m_local_prefix + m_local_name + m_suffix;
|
2020-05-24 23:16:21 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 01:45:33 +00:00
|
|
|
void SetName( const wxString& aName )
|
|
|
|
{
|
|
|
|
m_name = aName;
|
2020-02-29 03:21:48 +00:00
|
|
|
recacheName();
|
2019-04-20 01:45:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
wxString Prefix() const { return m_prefix; }
|
2019-05-08 02:48:25 +00:00
|
|
|
void SetPrefix( const wxString& aPrefix );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
wxString BusPrefix() const { return m_bus_prefix; }
|
|
|
|
|
|
|
|
wxString Suffix() const { return m_suffix; }
|
2019-05-08 02:48:25 +00:00
|
|
|
void SetSuffix( const wxString& aSuffix );
|
2019-03-18 22:38:06 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
CONNECTION_TYPE Type() const { return m_type; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
void SetType( CONNECTION_TYPE aType )
|
|
|
|
{
|
|
|
|
m_type = aType;
|
2020-02-29 03:21:48 +00:00
|
|
|
recacheName();
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
int NetCode() const { return m_net_code; }
|
|
|
|
void SetNetCode( int aCode ) { m_net_code = aCode; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
int BusCode() const { return m_bus_code; }
|
|
|
|
void SetBusCode( int aCode ) { m_bus_code = aCode; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
int SubgraphCode() const { return m_subgraph_code; }
|
|
|
|
void SetSubgraphCode( int aCode ) { m_subgraph_code = aCode; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
long VectorStart() const { return m_vector_start; }
|
|
|
|
long VectorEnd() const { return m_vector_end; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
long VectorIndex() const { return m_vector_index; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
wxString VectorPrefix() const { return m_vector_prefix; }
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
std::vector< std::shared_ptr< SCH_CONNECTION > >& Members()
|
|
|
|
{
|
|
|
|
return m_members;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector< std::shared_ptr< SCH_CONNECTION > >& Members() const
|
|
|
|
{
|
|
|
|
return m_members;
|
|
|
|
}
|
|
|
|
|
2020-05-25 21:03:49 +00:00
|
|
|
const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const;
|
|
|
|
|
2020-05-13 15:26:53 +00:00
|
|
|
static wxString PrintBusForUI( const wxString& aString );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
/**
|
2020-05-25 21:35:26 +00:00
|
|
|
* Returns true if this connection is contained within aOther (but not the same as aOther)
|
|
|
|
* @return true if this connection is a member of aOther
|
2019-03-11 21:32:05 +00:00
|
|
|
*/
|
|
|
|
bool IsSubsetOf( SCH_CONNECTION* aOther ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this connection is a member of bus connection aOther
|
|
|
|
*
|
|
|
|
* Will always return false if aOther is not a bus connection
|
|
|
|
*/
|
|
|
|
bool IsMemberOfBus( SCH_CONNECTION* aOther ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds information about the connection object to aList
|
|
|
|
*/
|
|
|
|
void AppendInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if \a aLabel has a bus notation.
|
|
|
|
*
|
|
|
|
* @param aLabel A wxString object containing the label to test.
|
|
|
|
* @return true if text is a bus notation format otherwise false is returned.
|
|
|
|
*/
|
2019-03-23 18:21:25 +00:00
|
|
|
static bool IsBusLabel( const wxString& aLabel );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-05-06 22:26:56 +00:00
|
|
|
/**
|
|
|
|
* Test if \a aLabel looks like a bus notation.
|
|
|
|
* This check is much less expensive than IsBusLabel.
|
|
|
|
*
|
|
|
|
* @param aLabel A wxString object containing the label to test.
|
|
|
|
* @return true if text might be a bus label
|
|
|
|
*/
|
|
|
|
static bool MightBeBusLabel( const wxString& aLabel );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
private:
|
2020-02-29 03:21:48 +00:00
|
|
|
void recacheName();
|
2019-03-11 21:32:05 +00:00
|
|
|
|
|
|
|
bool m_dirty;
|
|
|
|
|
|
|
|
SCH_SHEET_PATH m_sheet; ///< The hierarchical sheet this connection is on
|
|
|
|
|
|
|
|
SCH_ITEM* m_parent; ///< The SCH_ITEM this connection is owned by
|
|
|
|
|
2020-10-17 18:59:08 +00:00
|
|
|
void* m_lastDriver; ///< WEAK POINTER (there is no guarantee it is still allocated)
|
|
|
|
///< Equality comparisons are OK, but that's pretty much it
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
SCH_ITEM* m_driver; ///< The SCH_ITEM that drives this connection's net
|
|
|
|
|
|
|
|
CONNECTION_TYPE m_type; ///< @see enum CONNECTION_TYPE
|
|
|
|
|
2020-01-04 03:11:00 +00:00
|
|
|
wxString m_name; ///< Name of the connection.
|
|
|
|
|
2020-02-29 03:21:48 +00:00
|
|
|
wxString m_cached_name; ///< Full name, including prefix and suffix
|
|
|
|
|
|
|
|
wxString m_cached_name_with_path; ///< Full name including sheet path (if not global)
|
|
|
|
|
2020-01-04 03:11:00 +00:00
|
|
|
/**
|
|
|
|
* For bus members, we want to keep track of the "local" name of a member, that is,
|
|
|
|
* the name it takes on from its parent bus name. This is because we always want to use
|
|
|
|
* the local name for bus unfolding, matching within buses, etc. The actual resolved name
|
|
|
|
* of this bus member might change, for example if it's connected elsewhere to some other
|
|
|
|
* item with higher priority.
|
|
|
|
*/
|
|
|
|
wxString m_local_name;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-07-21 00:41:56 +00:00
|
|
|
/// Prefix if connection is member of a labeled bus group (or "" if not)
|
2019-03-11 21:32:05 +00:00
|
|
|
wxString m_prefix;
|
2020-07-21 00:41:56 +00:00
|
|
|
|
2021-03-05 04:37:33 +00:00
|
|
|
/// Local prefix for group bus members (used with m_local_name)
|
|
|
|
wxString m_local_prefix;
|
|
|
|
|
2020-07-21 00:41:56 +00:00
|
|
|
/// Optional prefix of a bux group (always empty for nets and vector buses)
|
|
|
|
wxString m_bus_prefix;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-03-18 22:38:06 +00:00
|
|
|
wxString m_suffix; ///< Name suffix (used only for disambiguation)
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
int m_net_code; // TODO(JE) remove if unused
|
|
|
|
|
|
|
|
int m_bus_code; // TODO(JE) remove if unused
|
|
|
|
|
|
|
|
int m_subgraph_code; ///< Groups directly-connected items
|
|
|
|
|
|
|
|
long m_vector_index; ///< Index of bus vector member nets
|
|
|
|
|
|
|
|
long m_vector_start; ///< Highest member of a vector bus
|
|
|
|
|
|
|
|
long m_vector_end; ///< Lowest member of a vector bus
|
|
|
|
|
|
|
|
///< Prefix name of the vector, if m_type == CONNECTION_BUS (or "" if not)
|
|
|
|
wxString m_vector_prefix;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For bus connections, store a list of member connections
|
|
|
|
*
|
|
|
|
* NOTE: All connections that Clone() others share the list of member
|
|
|
|
* pointers. This seems fine at the moment.
|
|
|
|
*/
|
|
|
|
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members;
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
/**
|
|
|
|
* Pointer to the connection graph for the schematic this connection exists on.
|
|
|
|
* Needed for bus alias lookups.
|
|
|
|
*/
|
|
|
|
CONNECTION_GRAPH* m_graph;
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|