2018-10-13 18:37:28 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2022-01-13 23:30:52 +00:00
|
|
|
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-10-13 18:37:28 +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.
|
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* This program is distributed in the hope that it will be useful
|
2018-10-13 18:37:28 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "graphics_importer_pcbnew.h"
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
|
|
|
#include <pcb_text.h>
|
|
|
|
#include <fp_text.h>
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <memory>
|
2018-10-13 18:37:28 +00:00
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
GRAPHICS_IMPORTER_PCBNEW::GRAPHICS_IMPORTER_PCBNEW()
|
|
|
|
{
|
|
|
|
m_layer = Dwgs_User;
|
2022-09-16 11:33:56 +00:00
|
|
|
m_millimeterToIu = pcbIUScale.mmToIU( 1.0 );
|
2018-11-05 16:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxPoint GRAPHICS_IMPORTER_PCBNEW::MapCoordinate( const VECTOR2D& aCoordinate )
|
|
|
|
{
|
|
|
|
VECTOR2D coord = ( aCoordinate + GetImportOffsetMM() ) * ImportScalingFactor();
|
2021-12-01 00:10:24 +00:00
|
|
|
return wxPoint( KiROUND( coord.x ), KiROUND( coord.y ) );
|
2018-11-05 16:04:05 +00:00
|
|
|
}
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
|
|
|
|
int GRAPHICS_IMPORTER_PCBNEW::MapLineWidth( double aLineWidth )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2018-11-05 16:04:05 +00:00
|
|
|
if( aLineWidth <= 0.0 )
|
|
|
|
return int( GetLineWidthMM() * ImportScalingFactor() );
|
|
|
|
|
|
|
|
// aLineWidth is in mm:
|
|
|
|
return int( aLineWidth * ImportScalingFactor() );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
void GRAPHICS_IMPORTER_PCBNEW::AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd,
|
|
|
|
double aWidth )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> line( createDrawing() );
|
2021-07-21 18:31:25 +00:00
|
|
|
line->SetShape( SHAPE_T::SEGMENT );
|
2018-10-13 18:37:28 +00:00
|
|
|
line->SetLayer( GetLayer() );
|
2021-07-17 19:56:18 +00:00
|
|
|
line->SetStroke( STROKE_PARAMS( MapLineWidth( aWidth ), PLOT_DASH_TYPE::SOLID ) );
|
2018-11-05 16:04:05 +00:00
|
|
|
line->SetStart( MapCoordinate( aOrigin ) );
|
|
|
|
line->SetEnd( MapCoordinate( aEnd ) );
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( line->Type() == PCB_FP_SHAPE_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_SHAPE*>( line.get() )->SetLocalCoord();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
addItem( std::move( line ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
void GRAPHICS_IMPORTER_PCBNEW::AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth,
|
|
|
|
bool aFilled )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> circle( createDrawing() );
|
2021-07-21 18:31:25 +00:00
|
|
|
circle->SetShape( SHAPE_T::CIRCLE );
|
2020-11-20 01:07:08 +00:00
|
|
|
circle->SetFilled( aFilled );
|
2018-10-13 18:37:28 +00:00
|
|
|
circle->SetLayer( GetLayer() );
|
2021-07-17 19:56:18 +00:00
|
|
|
circle->SetStroke( STROKE_PARAMS( MapLineWidth( aWidth ), PLOT_DASH_TYPE::SOLID ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
circle->SetStart( MapCoordinate( aCenter ));
|
|
|
|
circle->SetEnd( MapCoordinate( VECTOR2D( aCenter.x + aRadius, aCenter.y ) ) );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( circle->Type() == PCB_FP_SHAPE_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_SHAPE*>( circle.get() )->SetLocalCoord();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
addItem( std::move( circle ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-22 18:59:43 +00:00
|
|
|
void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart,
|
2022-01-20 23:08:48 +00:00
|
|
|
const EDA_ANGLE& aAngle, double aWidth )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> arc( createDrawing() );
|
2021-07-21 18:31:25 +00:00
|
|
|
arc->SetShape( SHAPE_T::ARC );
|
2018-10-13 18:37:28 +00:00
|
|
|
arc->SetLayer( GetLayer() );
|
2021-12-07 18:51:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We need to perform the rotation/conversion here while still using floating point values
|
|
|
|
* to avoid rounding errors when operating in integer space in pcbnew
|
|
|
|
*/
|
2022-01-20 23:08:48 +00:00
|
|
|
VECTOR2D end = aStart;
|
|
|
|
VECTOR2D mid = aStart;
|
2021-12-07 18:51:58 +00:00
|
|
|
|
2022-01-20 23:08:48 +00:00
|
|
|
RotatePoint( end, aCenter, -aAngle );
|
|
|
|
RotatePoint( mid, aCenter, -aAngle / 2.0 );
|
2021-12-07 18:51:58 +00:00
|
|
|
|
|
|
|
arc->SetArcGeometry( MapCoordinate( aStart ), MapCoordinate( mid ), MapCoordinate( end ) );
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( MapLineWidth( aWidth ), PLOT_DASH_TYPE::SOLID ) );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( arc->Type() == PCB_FP_SHAPE_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_SHAPE*>( arc.get() )->SetLocalCoord();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
addItem( std::move( arc ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
void GRAPHICS_IMPORTER_PCBNEW::AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> convertedPoints;
|
2022-08-17 03:38:08 +00:00
|
|
|
convertedPoints.reserve( aVertices.size() );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
|
|
|
for( const VECTOR2D& precisePoint : aVertices )
|
|
|
|
convertedPoints.emplace_back( MapCoordinate( precisePoint ) );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> polygon( createDrawing() );
|
2021-07-21 18:31:25 +00:00
|
|
|
polygon->SetShape( SHAPE_T::POLY );
|
2020-11-14 01:16:02 +00:00
|
|
|
polygon->SetFilled( GetLayer() != Edge_Cuts );
|
2018-10-13 18:37:28 +00:00
|
|
|
polygon->SetLayer( GetLayer() );
|
2018-11-05 16:04:05 +00:00
|
|
|
polygon->SetPolyPoints( convertedPoints );
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( polygon->Type() == PCB_FP_SHAPE_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_SHAPE*>( polygon.get() )->SetLocalCoord();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
polygon->SetStroke( STROKE_PARAMS( MapLineWidth( aWidth ), PLOT_DASH_TYPE::SOLID ) );
|
2018-10-13 18:37:28 +00:00
|
|
|
addItem( std::move( polygon ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GRAPHICS_IMPORTER_PCBNEW::AddText( const VECTOR2D& aOrigin, const wxString& aText,
|
2021-07-17 19:56:18 +00:00
|
|
|
double aHeight, double aWidth, double aThickness,
|
2021-12-28 22:13:54 +00:00
|
|
|
double aOrientation, GR_TEXT_H_ALIGN_T aHJustify,
|
|
|
|
GR_TEXT_V_ALIGN_T aVJustify )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-05-08 07:39:47 +00:00
|
|
|
std::unique_ptr<BOARD_ITEM> boardItem;
|
2018-10-13 18:37:28 +00:00
|
|
|
EDA_TEXT* textItem;
|
|
|
|
tie( boardItem, textItem ) = createText();
|
|
|
|
boardItem->SetLayer( GetLayer() );
|
2020-04-14 12:25:00 +00:00
|
|
|
textItem->SetTextThickness( MapLineWidth( aThickness ) );
|
2018-11-05 16:04:05 +00:00
|
|
|
textItem->SetTextPos( MapCoordinate( aOrigin ) );
|
2022-01-13 23:30:52 +00:00
|
|
|
textItem->SetTextAngle( EDA_ANGLE( aOrientation, DEGREES_T ) ); // Pcbnew uses the decidegree
|
2018-11-05 16:04:05 +00:00
|
|
|
textItem->SetTextWidth( aWidth * ImportScalingFactor() );
|
|
|
|
textItem->SetTextHeight( aHeight * ImportScalingFactor() );
|
2018-10-13 18:37:28 +00:00
|
|
|
textItem->SetVertJustify( aVJustify );
|
|
|
|
textItem->SetHorizJustify( aHJustify );
|
|
|
|
textItem->SetText( aText );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( boardItem->Type() == PCB_FP_TEXT_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_TEXT*>( boardItem.get() )->SetLocalCoord();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
addItem( std::move( boardItem ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-01 09:47:41 +00:00
|
|
|
void GRAPHICS_IMPORTER_PCBNEW::AddSpline( const VECTOR2D& aStart, const VECTOR2D& BezierControl1,
|
2021-07-17 19:56:18 +00:00
|
|
|
const VECTOR2D& BezierControl2, const VECTOR2D& aEnd,
|
|
|
|
double aWidth )
|
2018-11-01 09:47:41 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> spline( createDrawing() );
|
2021-07-21 18:31:25 +00:00
|
|
|
spline->SetShape( SHAPE_T::BEZIER );
|
2018-11-01 09:47:41 +00:00
|
|
|
spline->SetLayer( GetLayer() );
|
2021-07-17 19:56:18 +00:00
|
|
|
spline->SetStroke( STROKE_PARAMS( MapLineWidth( aWidth ), PLOT_DASH_TYPE::SOLID ) );
|
2018-11-05 16:04:05 +00:00
|
|
|
spline->SetStart( MapCoordinate( aStart ) );
|
2021-07-18 12:31:56 +00:00
|
|
|
spline->SetBezierC1( MapCoordinate( BezierControl1 ));
|
|
|
|
spline->SetBezierC2( MapCoordinate( BezierControl2 ));
|
2018-11-05 16:04:05 +00:00
|
|
|
spline->SetEnd( MapCoordinate( aEnd ) );
|
2018-11-01 09:47:41 +00:00
|
|
|
spline->RebuildBezierToSegmentsPointsList( aWidth );
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( spline->Type() == PCB_FP_SHAPE_T )
|
2020-10-04 23:34:59 +00:00
|
|
|
static_cast<FP_SHAPE*>( spline.get() )->SetLocalCoord();
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2018-11-01 09:47:41 +00:00
|
|
|
addItem( std::move( spline ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> GRAPHICS_IMPORTER_BOARD::createDrawing()
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
return std::make_unique<PCB_SHAPE>( m_board );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-08 07:39:47 +00:00
|
|
|
std::pair<std::unique_ptr<BOARD_ITEM>, EDA_TEXT*> GRAPHICS_IMPORTER_BOARD::createText()
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT* text = new PCB_TEXT( m_board );
|
2020-05-08 07:39:47 +00:00
|
|
|
return make_pair( std::unique_ptr<BOARD_ITEM>( text ), static_cast<EDA_TEXT*>( text ) );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> GRAPHICS_IMPORTER_FOOTPRINT::createDrawing()
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
return std::make_unique<FP_SHAPE>( m_footprint );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
std::pair<std::unique_ptr<BOARD_ITEM>, EDA_TEXT*> GRAPHICS_IMPORTER_FOOTPRINT::createText()
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
FP_TEXT* text = new FP_TEXT( m_footprint );
|
2020-05-08 07:39:47 +00:00
|
|
|
return make_pair( std::unique_ptr<BOARD_ITEM>( text ), static_cast<EDA_TEXT*>( text ) );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|