/* * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2013-2015 CERN * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. * * @author Maciej Suminski * * 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 #include #include #include #include #include class BOARD_ITEM; class BOARD_CONNECTED_ITEM; class CN_CLUSTER; struct CN_PTR_CMP { bool operator()( const std::shared_ptr& aItem, const std::shared_ptr& bItem ) const { if( aItem->Pos().x == bItem->Pos().x ) return aItem->Pos().y < bItem->Pos().y; else return aItem->Pos().x < bItem->Pos().x; } }; /** * Describe ratsnest for a single net. */ class RN_NET { public: RN_NET(); /** * Mark ratsnest for given net as 'dirty', i.e. requiring recomputation. */ void MarkDirty() { m_dirty = true; } /** * Return state of the 'dirty' flag, indicating that ratsnest for a given net is invalid * and requires an update. * * @return True if ratsnest requires recomputation, false otherwise. */ bool IsDirty() const { return m_dirty; } /** * Recompute ratsnest for a net. */ void Update(); void Clear(); void AddCluster( std::shared_ptr aCluster ); unsigned int GetNodeCount() const { return m_nodes.size(); } const std::vector& GetEdges() const { return m_rnEdges; } std::vector& GetEdges() { return m_rnEdges; } bool NearestBicoloredPair( RN_NET* aOtherNet, VECTOR2I& aPos1, VECTOR2I& aPos2 ) const; protected: ///< Recompute ratsnest from scratch. void compute(); ///< Compute the minimum spanning tree using Kruskal's algorithm void kruskalMST( const std::vector &aEdges ); ///< 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. void optimizeRNEdges(); protected: ///< Vector of nodes std::multiset, CN_PTR_CMP> m_nodes; ///< Vector of edges that make pre-defined connections std::vector m_boardEdges; ///< Vector of edges that makes ratsnest for a given net. std::vector m_rnEdges; ///< Flag indicating necessity of recalculation of ratsnest for a net. bool m_dirty; class TRIANGULATOR_STATE; std::shared_ptr m_triangulator; }; #endif /* RATSNEST_DATA_H */