2013-11-25 15:50:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2015-03-09 12:41:34 +00:00
|
|
|
* Copyright (C) 2013-2015 CERN
|
2022-09-29 16:07:42 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
2013-11-25 15:50:03 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file ratsnest_data.h
|
|
|
|
* @brief Class that computes missing connections on a PCB.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RATSNEST_DATA_H
|
|
|
|
#define RATSNEST_DATA_H
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
#include <core/typeinfo.h>
|
2013-11-25 15:50:03 +00:00
|
|
|
#include <math/box2.h>
|
|
|
|
|
2020-06-23 02:18:46 +00:00
|
|
|
#include <set>
|
2020-06-21 15:56:24 +00:00
|
|
|
#include <vector>
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_algo.h>
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
class BOARD_ITEM;
|
|
|
|
class BOARD_CONNECTED_ITEM;
|
2017-03-22 13:43:10 +00:00
|
|
|
class CN_CLUSTER;
|
2015-06-05 15:49:00 +00:00
|
|
|
|
2020-06-23 02:18:46 +00:00
|
|
|
struct CN_PTR_CMP
|
|
|
|
{
|
2022-02-13 11:54:41 +00:00
|
|
|
bool operator()( const std::shared_ptr<CN_ANCHOR>& aItem,
|
|
|
|
const std::shared_ptr<CN_ANCHOR>& bItem ) const
|
2020-06-23 02:18:46 +00:00
|
|
|
{
|
|
|
|
if( aItem->Pos().x == bItem->Pos().x )
|
|
|
|
return aItem->Pos().y < bItem->Pos().y;
|
|
|
|
else
|
|
|
|
return aItem->Pos().x < bItem->Pos().x;
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Describe ratsnest for a single net.
|
2013-11-25 15:50:03 +00:00
|
|
|
*/
|
|
|
|
class RN_NET
|
|
|
|
{
|
|
|
|
public:
|
2017-03-22 13:43:10 +00:00
|
|
|
RN_NET();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return state of the 'dirty' flag, indicating that ratsnest for a given net is invalid
|
2013-11-25 15:50:03 +00:00
|
|
|
* and requires an update.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
2013-11-25 15:50:03 +00:00
|
|
|
* @return True if ratsnest requires recomputation, false otherwise.
|
|
|
|
*/
|
2021-11-30 14:19:39 +00:00
|
|
|
bool IsDirty() const { return m_dirty; }
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Recompute ratsnest for a net.
|
2013-11-25 15:50:03 +00:00
|
|
|
*/
|
2022-11-21 18:50:01 +00:00
|
|
|
void UpdateNet();
|
2023-04-16 14:35:58 +00:00
|
|
|
|
2023-11-01 13:53:30 +00:00
|
|
|
void RemoveInvalidRefs();
|
|
|
|
|
2023-04-16 14:35:58 +00:00
|
|
|
/**
|
|
|
|
* Find optimal ends of RNEdges. The MST will have found the closest anchors, but when
|
|
|
|
* zones are involved we might have points closer than the anchors.
|
|
|
|
*
|
|
|
|
* Normally called after UpdateNet(), but from a separate multi-threaded loop for safety.
|
|
|
|
*/
|
|
|
|
void OptimizeRNEdges();
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
void Clear();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
void AddCluster( std::shared_ptr<CN_CLUSTER> aCluster );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
unsigned int GetNodeCount() const { return m_nodes.size(); }
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2021-11-30 14:19:39 +00:00
|
|
|
const std::vector<CN_EDGE>& GetEdges() const { return m_rnEdges; }
|
2021-12-01 14:42:44 +00:00
|
|
|
std::vector<CN_EDGE>& GetEdges() { return m_rnEdges; }
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2022-10-05 00:00:08 +00:00
|
|
|
bool NearestBicoloredPair( RN_NET* aOtherNet, VECTOR2I& aPos1, VECTOR2I& aPos2 ) const;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
protected:
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Recompute ratsnest from scratch.
|
2022-09-29 16:07:42 +00:00
|
|
|
void compute();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Compute the minimum spanning tree using Kruskal's algorithm
|
2022-09-29 16:07:42 +00:00
|
|
|
void kruskalMST( const std::vector<CN_EDGE> &aEdges );
|
2020-06-18 02:25:46 +00:00
|
|
|
|
2022-09-30 19:04:54 +00:00
|
|
|
protected:
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Vector of nodes
|
2022-02-13 11:54:41 +00:00
|
|
|
std::multiset<std::shared_ptr<CN_ANCHOR>, CN_PTR_CMP> m_nodes;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Vector of edges that make pre-defined connections
|
2017-03-22 13:43:10 +00:00
|
|
|
std::vector<CN_EDGE> m_boardEdges;
|
2014-01-31 17:05:11 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Vector of edges that makes ratsnest for a given net.
|
2017-03-22 13:43:10 +00:00
|
|
|
std::vector<CN_EDGE> m_rnEdges;
|
2015-06-05 15:49:00 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Flag indicating necessity of recalculation of ratsnest for a net.
|
2013-11-25 15:50:03 +00:00
|
|
|
bool m_dirty;
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
class TRIANGULATOR_STATE;
|
2015-07-03 18:58:12 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
std::shared_ptr<TRIANGULATOR_STATE> m_triangulator;
|
2013-11-25 15:50:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* RATSNEST_DATA_H */
|