2018-11-13 13:30:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-11-28 20:46:30 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-11-13 13:30:56 +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, 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 CONVERT_TOOL_H_
|
|
|
|
#define CONVERT_TOOL_H_
|
|
|
|
|
2020-10-02 22:42:32 +00:00
|
|
|
#include <geometry/shape_poly_set.h>
|
2018-11-13 13:30:56 +00:00
|
|
|
#include <tool/tool_interactive.h>
|
2022-11-28 20:46:30 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
class CONDITIONAL_MENU;
|
2020-12-16 13:31:32 +00:00
|
|
|
class PCB_SELECTION_TOOL;
|
2018-11-13 13:30:56 +00:00
|
|
|
class PCB_BASE_FRAME;
|
|
|
|
|
|
|
|
|
|
|
|
class CONVERT_TOOL : public TOOL_INTERACTIVE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CONVERT_TOOL();
|
|
|
|
virtual ~CONVERT_TOOL();
|
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
|
|
|
void Reset( RESET_REASON aReason ) override {}
|
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
|
|
|
bool Init() override;
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Convert selected lines to a polygon, if possible.
|
2018-11-13 13:30:56 +00:00
|
|
|
*/
|
2021-08-09 00:28:47 +00:00
|
|
|
int CreatePolys( const TOOL_EVENT& aEvent );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Convert selected polygon-like object to graphic lines, if possible.
|
2018-11-13 13:30:56 +00:00
|
|
|
*/
|
2021-08-09 00:28:47 +00:00
|
|
|
int CreateLines( const TOOL_EVENT& aEvent );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Convert selected segment (graphic or track) to an arc of the same type
|
2018-11-13 13:30:56 +00:00
|
|
|
*/
|
|
|
|
int SegmentToArc( const TOOL_EVENT& aEvent );
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< @copydoc TOOL_INTERACTIVE::setTransitions()
|
2018-11-13 13:30:56 +00:00
|
|
|
void setTransitions() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Retrieve the start and end points for a generic item.
|
|
|
|
*
|
|
|
|
* @param aItem is an item that has a start and end point.
|
2022-08-25 22:50:47 +00:00
|
|
|
* @return a segment from start to end, or std::nullopt if invalid.
|
2018-11-13 13:30:56 +00:00
|
|
|
*/
|
2022-11-28 20:46:30 +00:00
|
|
|
static std::optional<SEG> getStartEndPoints( EDA_ITEM* aItem );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-27 16:15:36 +00:00
|
|
|
* Try to make polygons from chained segments in the selected items.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
2018-11-13 13:30:56 +00:00
|
|
|
* Polygons are formed from chains of lines/arcs. Each set containing two or more lines/arcs
|
2021-01-27 22:15:38 +00:00
|
|
|
* that are connected will be added to the return SHAPE_POLY_SET as an outline. No attempt
|
|
|
|
* is made to guess at holes.
|
|
|
|
*
|
|
|
|
* @param aItems is a list of items to process.
|
|
|
|
* @return a #SHAPE_POLY_SET containing any polygons that were created.
|
2018-11-13 13:30:56 +00:00
|
|
|
*/
|
2022-11-28 20:46:30 +00:00
|
|
|
SHAPE_POLY_SET makePolysFromChainedSegs( const std::deque<EDA_ITEM*>& aItems,
|
|
|
|
CONVERT_STRATEGY aStrategy );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-27 16:15:36 +00:00
|
|
|
* Make polygons from graphic shapes and zones.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
2022-07-27 16:15:36 +00:00
|
|
|
* @param aItems is a list of items to process.
|
2021-01-27 22:15:38 +00:00
|
|
|
* @return a #SHAPE_POLY_SET containing any polygons that were created.
|
2021-01-06 17:20:54 +00:00
|
|
|
*/
|
2022-12-01 13:22:29 +00:00
|
|
|
SHAPE_POLY_SET makePolysFromOpenGraphics( const std::deque<EDA_ITEM*>& aItems, int aGap );
|
2022-11-27 18:29:41 +00:00
|
|
|
SHAPE_POLY_SET makePolysFromClosedGraphics( const std::deque<EDA_ITEM*>& aItems,
|
2022-11-28 20:46:30 +00:00
|
|
|
CONVERT_STRATEGY aStrategy );
|
2021-08-09 00:28:47 +00:00
|
|
|
|
2022-11-30 14:27:40 +00:00
|
|
|
private:
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* m_selectionTool;
|
|
|
|
CONDITIONAL_MENU* m_menu;
|
|
|
|
PCB_BASE_FRAME* m_frame;
|
2022-12-01 13:27:59 +00:00
|
|
|
CONVERT_SETTINGS m_userSettings;
|
2018-11-13 13:30:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|