diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index 39c7883dd5..e0cfab4a34 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2016 Mario Luzeiro - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -34,16 +34,14 @@ #include "../3d_rendering/raytracing/shapes2D/filled_circle_2d.h" #include "../3d_rendering/raytracing/shapes2D/round_segment_2d.h" #include "../3d_rendering/raytracing/shapes2D/triangle_2d.h" -#include "fp_textbox.h" #include #include #include #include -#include +#include #include #include // for PCB_RENDER_SETTINGS #include -#include #include #include #include @@ -194,9 +192,9 @@ void BOARD_ADAPTER::addFootprintShapes( const FOOTPRINT* aFootprint, CONTAINER_2 { switch( item->Type() ) { - case PCB_FP_TEXT_T: + case PCB_TEXT_T: { - FP_TEXT* text = static_cast( item ); + PCB_TEXT* text = static_cast( item ); if( text->GetLayer() == aLayerId && text->IsVisible() ) addText( text, aContainer, text ); @@ -204,9 +202,9 @@ void BOARD_ADAPTER::addFootprintShapes( const FOOTPRINT* aFootprint, CONTAINER_2 break; } - case PCB_FP_TEXTBOX_T: + case PCB_TEXTBOX_T: { - FP_TEXTBOX* textbox = static_cast( item ); + PCB_TEXTBOX* textbox = static_cast( item ); if( textbox->GetLayer() == aLayerId ) { @@ -217,11 +215,11 @@ void BOARD_ADAPTER::addFootprintShapes( const FOOTPRINT* aFootprint, CONTAINER_2 break; } - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_LEADER_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_LEADER_T: { PCB_DIMENSION_BASE* dimension = static_cast( item ); @@ -231,9 +229,9 @@ void BOARD_ADAPTER::addFootprintShapes( const FOOTPRINT* aFootprint, CONTAINER_2 break; } - case PCB_FP_SHAPE_T: + case PCB_SHAPE_T: { - FP_SHAPE* shape = static_cast( item ); + PCB_SHAPE* shape = static_cast( item ); if( shape->GetLayer() == aLayerId ) addShape( shape, aContainer, aFootprint ); diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp index 062941f6c4..9c4472ad4b 100644 --- a/3d-viewer/3d_canvas/create_layer_items.cpp +++ b/3d-viewer/3d_canvas/create_layer_items.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/3d-viewer/3d_canvas/create_layer_poly.cpp b/3d-viewer/3d_canvas/create_layer_poly.cpp index 3858dd8749..f6c6ba56b1 100644 --- a/3d-viewer/3d_canvas/create_layer_poly.cpp +++ b/3d-viewer/3d_canvas/create_layer_poly.cpp @@ -31,7 +31,7 @@ #include "board_adapter.h" #include #include -#include +#include #include @@ -71,19 +71,10 @@ void BOARD_ADAPTER::transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB for( BOARD_ITEM* item : aFootprint->GraphicalItems() ) { - if( item->Type() == PCB_FP_SHAPE_T ) + if( item->Type() == PCB_SHAPE_T || BaseType( item->Type() ) == PCB_DIMENSION_T ) { - FP_SHAPE* shape = static_cast( item ); - - if( shape->GetLayer() == aLayer ) - shape->TransformShapeToPolygon( aBuffer, aLayer, 0, maxError, ERROR_INSIDE ); - } - else if( BaseType( item->Type() ) == PCB_DIMENSION_T ) - { - PCB_DIMENSION_BASE* dimension = static_cast( item ); - - if( dimension->GetLayer() == aLayer ) - dimension->TransformShapeToPolygon( aBuffer, aLayer, 0, maxError, ERROR_INSIDE ); + if( item->GetLayer() == aLayer ) + item->TransformShapeToPolygon( aBuffer, aLayer, 0, maxError, ERROR_INSIDE ); } } } diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index afe84910a1..386eb24868 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -540,7 +540,6 @@ set( PCB_COMMON_SRCS ${CMAKE_SOURCE_DIR}/pcbnew/board_item.cpp ${CMAKE_SOURCE_DIR}/pcbnew/pcb_dimension.cpp ${CMAKE_SOURCE_DIR}/pcbnew/pcb_shape.cpp - ${CMAKE_SOURCE_DIR}/pcbnew/fp_shape.cpp ${CMAKE_SOURCE_DIR}/pcbnew/pcb_group.cpp ${CMAKE_SOURCE_DIR}/pcbnew/pcb_marker.cpp ${CMAKE_SOURCE_DIR}/pcbnew/footprint.cpp @@ -552,8 +551,6 @@ set( PCB_COMMON_SRCS ${CMAKE_SOURCE_DIR}/pcbnew/pcb_text.cpp ${CMAKE_SOURCE_DIR}/pcbnew/pcb_textbox.cpp ${CMAKE_SOURCE_DIR}/pcbnew/board_stackup_manager/board_stackup.cpp - ${CMAKE_SOURCE_DIR}/pcbnew/fp_text.cpp - ${CMAKE_SOURCE_DIR}/pcbnew/fp_textbox.cpp ${CMAKE_SOURCE_DIR}/pcbnew/pcb_track.cpp ${CMAKE_SOURCE_DIR}/pcbnew/zone.cpp ${CMAKE_SOURCE_DIR}/pcbnew/collectors.cpp diff --git a/common/eda_item.cpp b/common/eda_item.cpp index 272e33fdc9..64c84621cb 100644 --- a/common/eda_item.cpp +++ b/common/eda_item.cpp @@ -328,15 +328,6 @@ static struct EDA_ITEM_DESC .Map( PCB_BITMAP_T, _HKI( "Bitmap" ) ) .Map( PCB_TEXT_T, _HKI( "Text" ) ) .Map( PCB_TEXTBOX_T, _HKI( "Text Box" ) ) - .Map( PCB_FP_TEXT_T, _HKI( "Text" ) ) - .Map( PCB_FP_TEXTBOX_T, _HKI( "Text Box" ) ) - .Map( PCB_FP_SHAPE_T, _HKI( "Graphic" ) ) - .Map( PCB_FP_DIM_ALIGNED_T, _HKI( "Dimension" ) ) - .Map( PCB_FP_DIM_ORTHOGONAL_T, _HKI( "Dimension" ) ) - .Map( PCB_FP_DIM_CENTER_T, _HKI( "Dimension" ) ) - .Map( PCB_FP_DIM_RADIAL_T, _HKI( "Dimension" ) ) - .Map( PCB_FP_DIM_LEADER_T, _HKI( "Leader" ) ) - .Map( PCB_FP_ZONE_T, _HKI( "Zone" ) ) .Map( PCB_TRACE_T, _HKI( "Track" ) ) .Map( PCB_ARC_T, _HKI( "Track" ) ) .Map( PCB_VIA_T, _HKI( "Via" ) ) diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index 3fb784642d..7a357603df 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -184,7 +184,7 @@ void EDA_SHAPE::move( const VECTOR2I& aMoveVector ) break; case SHAPE_T::POLY: - m_poly.Move( VECTOR2I( aMoveVector ) ); + m_poly.Move( aMoveVector ); break; case SHAPE_T::BEZIER: @@ -712,14 +712,7 @@ const BOX2I EDA_SHAPE::getBoundingBox() const break; for( auto iter = m_poly.CIterate(); iter; iter++ ) - { - VECTOR2I pt( iter->x, iter->y ); - - RotatePoint( pt, getParentOrientation() ); - pt += getParentPosition(); - - bbox.Merge( pt ); - } + bbox.Merge( *iter ); break; @@ -949,18 +942,10 @@ bool EDA_SHAPE::hitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) co // Account for the width of the line arect.Inflate( GetWidth() / 2 ); - // Polygons in footprints use coordinates relative to the footprint. - // Therefore, instead of using m_poly, we make a copy which is translated - // to the actual location in the board. - VECTOR2I offset = getParentPosition(); - for( int ii = 0; ii < m_poly.OutlineCount(); ++ii ) { - SHAPE_LINE_CHAIN poly = m_poly.Outline( ii ); - poly.Rotate( getParentOrientation() ); - poly.Move( offset ); - - int count = poly.GetPointCount(); + const SHAPE_LINE_CHAIN& poly = m_poly.Outline( ii ); + int count = poly.GetPointCount(); for( int jj = 0; jj < count; jj++ ) { @@ -1038,32 +1023,11 @@ std::vector EDA_SHAPE::GetRectCorners() const VECTOR2I topLeft = GetStart(); VECTOR2I botRight = GetEnd(); - // Un-rotate rect topLeft and botRight - if( !getParentOrientation().IsCardinal() ) - { - topLeft -= getParentPosition(); - RotatePoint( topLeft, -getParentOrientation() ); - - botRight -= getParentPosition(); - RotatePoint( botRight, -getParentOrientation() ); - } - - // Set up the un-rotated 4 corners pts.emplace_back( topLeft ); pts.emplace_back( botRight.x, topLeft.y ); pts.emplace_back( botRight ); pts.emplace_back( topLeft.x, botRight.y ); - // Now re-rotate the 4 corners to get a diamond - if( !getParentOrientation().IsCardinal() ) - { - for( VECTOR2I& pt : pts ) - { - RotatePoint( pt, getParentOrientation() ); - pt += getParentPosition(); - } - } - return pts; } @@ -1198,9 +1162,6 @@ std::vector EDA_SHAPE::makeEffectiveShapes( bool aEdgeOnly, bool aLineCh if( aLineChainOnly ) l.SetClosed( false ); - l.Rotate( getParentOrientation() ); - l.Move( getParentPosition() ); - if( IsFilled() && !aEdgeOnly ) effectiveShapes.emplace_back( new SHAPE_SIMPLE( l ) ); @@ -1604,38 +1565,30 @@ void EDA_SHAPE::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, int aClearance if( !IsPolyShapeValid() ) break; - // The polygon is expected to be a simple polygon; not self intersecting, no hole. - EDA_ANGLE orientation = getParentOrientation(); - VECTOR2I offset = getParentPosition(); - - // Build the polygon with the actual position and orientation: - std::vector poly; - DupPolyPointsList( poly ); - - for( VECTOR2I& point : poly ) - { - RotatePoint( point, orientation ); - point += offset; - } - if( IsFilled() ) { aBuffer.NewOutline(); - for( const VECTOR2I& point : poly ) - aBuffer.Append( point.x, point.y ); + for( int ii = 0; ii < m_poly.OutlineCount(); ++ii ) + { + const SHAPE_LINE_CHAIN& poly = m_poly.Outline( ii ); + + for( int jj = 0; jj < (int) poly.GetPointCount(); ++jj ) + aBuffer.Append( poly.GetPoint( jj ) ); + } } if( width > 0 || !IsFilled() ) { - VECTOR2I pt1( poly[poly.size() - 1] ); - - for( const VECTOR2I& pt2 : poly ) + for( int ii = 0; ii < m_poly.OutlineCount(); ++ii ) { - if( pt2 != pt1 ) - TransformOvalToPolygon( aBuffer, pt1, pt2, width, aError, aErrorLoc ); + const SHAPE_LINE_CHAIN& poly = m_poly.Outline( ii ); - pt1 = pt2; + for( int jj = 0; jj < (int) poly.SegmentCount(); ++jj ) + { + const SEG& seg = poly.GetSegment( jj ); + TransformOvalToPolygon( aBuffer, seg.A, seg.B, width, aError, aErrorLoc ); + } } } diff --git a/common/hash_eda.cpp b/common/hash_eda.cpp index 196731a3f1..ef5447d284 100644 --- a/common/hash_eda.cpp +++ b/common/hash_eda.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 CERN - * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -26,9 +26,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -101,14 +101,14 @@ size_t hash_fp_item( const EDA_ITEM* aItem, int aFlags ) } break; - case PCB_FP_TEXT_T: + case PCB_TEXT_T: { - const FP_TEXT* text = static_cast( aItem ); + const PCB_TEXT* text = static_cast( aItem ); - if( !( aFlags & HASH_REF ) && text->GetType() == FP_TEXT::TEXT_is_REFERENCE ) + if( !( aFlags & HASH_REF ) && text->GetType() == PCB_TEXT::TEXT_is_REFERENCE ) break; - if( !( aFlags & HASH_VALUE ) && text->GetType() == FP_TEXT::TEXT_is_VALUE ) + if( !( aFlags & HASH_VALUE ) && text->GetType() == PCB_TEXT::TEXT_is_VALUE ) break; ret = hash_board_item( text, aFlags ); @@ -123,10 +123,10 @@ size_t hash_fp_item( const EDA_ITEM* aItem, int aFlags ) if( aFlags & HASH_POS ) { - if( aFlags & REL_COORD ) - hash_combine( ret, text->GetPos0().x, text->GetPos0().y ); - else - hash_combine( ret, text->GetPosition().x, text->GetPosition().y ); + VECTOR2I pos = ( aFlags & REL_COORD ) ? text->GetFPRelativePosition() + : text->GetPosition(); + + hash_combine( ret, pos.x, pos.y ); } if( aFlags & HASH_ROT ) @@ -134,9 +134,9 @@ size_t hash_fp_item( const EDA_ITEM* aItem, int aFlags ) } break; - case PCB_FP_SHAPE_T: + case PCB_SHAPE_T: { - const FP_SHAPE* shape = static_cast( aItem ); + const PCB_SHAPE* shape = static_cast( aItem ); ret = hash_board_item( shape, aFlags ); hash_combine( ret, shape->GetShape() ); hash_combine( ret, shape->GetWidth() ); @@ -147,39 +147,40 @@ size_t hash_fp_item( const EDA_ITEM* aItem, int aFlags ) if( aFlags & HASH_POS ) { - if( aFlags & REL_COORD ) - { - hash_combine( ret, shape->GetStart0().x ); - hash_combine( ret, shape->GetStart0().y ); - hash_combine( ret, shape->GetEnd0().x ); - hash_combine( ret, shape->GetEnd0().y ); + VECTOR2I start = shape->GetStart(); + VECTOR2I end = shape->GetEnd(); + VECTOR2I center = shape->GetCenter(); - if( shape->GetShape() == SHAPE_T::ARC ) - { - hash_combine( ret, shape->GetCenter0().x ); - hash_combine( ret, shape->GetCenter0().y ); - } + FOOTPRINT* parentFP = shape->GetParentFootprint(); + + if( parentFP && ( aFlags & REL_COORD ) ) + { + start -= parentFP->GetPosition(); + end -= parentFP->GetPosition(); + center -= parentFP->GetPosition(); + + RotatePoint( start, -parentFP->GetOrientation() ); + RotatePoint( end, -parentFP->GetOrientation() ); + RotatePoint( center, -parentFP->GetOrientation() ); } - else - { - hash_combine( ret, shape->GetStart().x ); - hash_combine( ret, shape->GetStart().y ); - hash_combine( ret, shape->GetEnd().x ); - hash_combine( ret, shape->GetEnd().y ); - if( shape->GetShape() == SHAPE_T::ARC ) - { - hash_combine( ret, shape->GetCenter().x ); - hash_combine( ret, shape->GetCenter().y ); - } + hash_combine( ret, start.x ); + hash_combine( ret, start.y ); + hash_combine( ret, end.x ); + hash_combine( ret, end.y ); + + if( shape->GetShape() == SHAPE_T::ARC ) + { + hash_combine( ret, center.x ); + hash_combine( ret, center.y ); } } } break; - case PCB_FP_TEXTBOX_T: + case PCB_TEXTBOX_T: { - const FP_TEXTBOX* textbox = static_cast( aItem ); + const PCB_TEXTBOX* textbox = static_cast( aItem ); ret = hash_board_item( textbox, aFlags ); hash_combine( ret, textbox->GetText().ToStdString() ); @@ -199,20 +200,24 @@ size_t hash_fp_item( const EDA_ITEM* aItem, int aFlags ) if( aFlags & HASH_POS ) { - if( aFlags & REL_COORD ) + VECTOR2I start = textbox->GetStart(); + VECTOR2I end = textbox->GetEnd(); + + FOOTPRINT* parentFP = textbox->GetParentFootprint(); + + if( parentFP && ( aFlags & REL_COORD ) ) { - hash_combine( ret, textbox->GetStart0().x ); - hash_combine( ret, textbox->GetStart0().y ); - hash_combine( ret, textbox->GetEnd0().x ); - hash_combine( ret, textbox->GetEnd0().y ); - } - else - { - hash_combine( ret, textbox->GetStart().x ); - hash_combine( ret, textbox->GetStart().y ); - hash_combine( ret, textbox->GetEnd().x ); - hash_combine( ret, textbox->GetEnd().y ); + start -= parentFP->GetPosition(); + end -= parentFP->GetPosition(); + + RotatePoint( start, -parentFP->GetOrientation() ); + RotatePoint( end, -parentFP->GetOrientation() ); } + + hash_combine( ret, start.x ); + hash_combine( ret, start.y ); + hash_combine( ret, end.x ); + hash_combine( ret, end.y ); } } break; diff --git a/eeschema/lib_shape.h b/eeschema/lib_shape.h index a218f1e49b..372b6d0818 100644 --- a/eeschema/lib_shape.h +++ b/eeschema/lib_shape.h @@ -128,9 +128,6 @@ private: void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData, const TRANSFORM& aTransform, bool aDimmed ) override; - - EDA_ANGLE getParentOrientation() const override { return ANGLE_0; } - VECTOR2I getParentPosition() const override { return VECTOR2I(); } }; diff --git a/eeschema/sch_shape.h b/eeschema/sch_shape.h index 23ab6e3456..6de173413c 100644 --- a/eeschema/sch_shape.h +++ b/eeschema/sch_shape.h @@ -114,9 +114,6 @@ public: private: void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override; void PrintBackground( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override; - - EDA_ANGLE getParentOrientation() const override { return ANGLE_0; } - VECTOR2I getParentPosition() const override { return VECTOR2I(); } }; diff --git a/include/board_item.h b/include/board_item.h index 7778f8163c..cf32667b34 100644 --- a/include/board_item.h +++ b/include/board_item.h @@ -39,6 +39,7 @@ class SHAPE_SEGMENT; class PCB_BASE_FRAME; class SHAPE; class PCB_GROUP; +class FOOTPRINT; /** @@ -174,7 +175,10 @@ public: BOARD_ITEM_CONTAINER* GetParent() const { return (BOARD_ITEM_CONTAINER*) m_parent; } - BOARD_ITEM_CONTAINER* GetParentFootprint() const; + FOOTPRINT* GetParentFootprint() const; + + VECTOR2I GetFPRelativePosition() const; + void SetFPRelativePosition( const VECTOR2I& aPos ); /** * Check if this item has line stoke properties. diff --git a/include/core/typeinfo.h b/include/core/typeinfo.h index 01d647597b..ef275b73ea 100644 --- a/include/core/typeinfo.h +++ b/include/core/typeinfo.h @@ -89,15 +89,6 @@ enum KICAD_T PCB_BITMAP_T, ///< class PCB_BITMAP, bitmap on a layer PCB_TEXT_T, ///< class PCB_TEXT, text on a layer PCB_TEXTBOX_T, ///< class PCB_TEXTBOX, wrapped text on a layer - PCB_FP_TEXT_T, ///< class FP_TEXT, text in a footprint - PCB_FP_TEXTBOX_T, ///< class FP_TEXTBOX, wrapped text in a footprint - PCB_FP_SHAPE_T, ///< class FP_SHAPE, a footprint edge - PCB_FP_DIM_ALIGNED_T, ///< class PCB_DIM_ALIGNED, a linear dimension (graphic item) - PCB_FP_DIM_LEADER_T, ///< class PCB_DIM_LEADER, a leader dimension (graphic item) - PCB_FP_DIM_CENTER_T, ///< class PCB_DIM_CENTER, a center point marking (graphic item) - PCB_FP_DIM_RADIAL_T, ///< class PCB_DIM_RADIAL, a radius or diameter dimension - PCB_FP_DIM_ORTHOGONAL_T, ///< class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y - PCB_FP_ZONE_T, ///< class ZONE, managed by a footprint PCB_TRACE_T, ///< class PCB_TRACK, a track segment (segment on a copper layer) PCB_VIA_T, ///< class PCB_VIA, a via (like a track segment on a copper layer) PCB_ARC_T, ///< class PCB_ARC, an arc track segment on a copper layer @@ -121,13 +112,12 @@ enum KICAD_T PCB_LOCATE_UVIA_T, PCB_LOCATE_BBVIA_T, PCB_LOCATE_TEXT_T, - PCB_LOCATE_GRAPHIC_T, PCB_LOCATE_HOLE_T, PCB_LOCATE_PTH_T, PCB_LOCATE_NPTH_T, PCB_LOCATE_BOARD_EDGE_T, - // Same for locating shapes types from PCB_SHAPE_T and PCB_FP_SHAPE_T items + // Same for locating shapes types from PCB_SHAPE_T items PCB_SHAPE_LOCATE_SEGMENT_T, PCB_SHAPE_LOCATE_RECT_T, PCB_SHAPE_LOCATE_CIRCLE_T, @@ -291,11 +281,6 @@ constexpr KICAD_T BaseType( const KICAD_T aType ) case PCB_DIM_RADIAL_T: case PCB_DIM_ORTHOGONAL_T: case PCB_DIM_LEADER_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_LEADER_T: return PCB_DIMENSION_T; default: @@ -336,7 +321,6 @@ constexpr bool IsInstantiableType( const KICAD_T aType ) case PCB_LOCATE_UVIA_T: case PCB_LOCATE_BBVIA_T: case PCB_LOCATE_TEXT_T: - case PCB_LOCATE_GRAPHIC_T: case PCB_LOCATE_HOLE_T: case PCB_LOCATE_PTH_T: case PCB_LOCATE_NPTH_T: @@ -432,15 +416,6 @@ constexpr bool IsPcbnewType( const KICAD_T aType ) case PCB_BITMAP_T: case PCB_TEXT_T: case PCB_TEXTBOX_T: - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_ZONE_T: case PCB_TRACE_T: case PCB_VIA_T: case PCB_ARC_T: @@ -461,7 +436,6 @@ constexpr bool IsPcbnewType( const KICAD_T aType ) case PCB_LOCATE_UVIA_T: case PCB_LOCATE_BBVIA_T: case PCB_LOCATE_TEXT_T: - case PCB_LOCATE_GRAPHIC_T: case PCB_LOCATE_HOLE_T: case PCB_LOCATE_PTH_T: case PCB_LOCATE_NPTH_T: diff --git a/include/eda_shape.h b/include/eda_shape.h index 7d59a62a8a..53be08fd40 100644 --- a/include/eda_shape.h +++ b/include/eda_shape.h @@ -324,10 +324,6 @@ protected: void flip( const VECTOR2I& aCentre, bool aFlipLeftRight ); void scale( double aScale ); - // To be implemented by concrete classes - virtual EDA_ANGLE getParentOrientation() const = 0; - virtual VECTOR2I getParentPosition() const = 0; - const BOX2I getBoundingBox() const; void computeArcBBox( BOX2I& aBBox ) const; diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index 01421dce74..5eb51021c0 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -87,7 +87,7 @@ void ARRAY_CREATOR::Invoke() if( item->Type() == PCB_PAD_T && !m_isFootprintEditor ) { // If it is not the footprint editor, then duplicate the parent footprint instead - item = static_cast( item )->GetParent(); + item = item->GetParentFootprint(); } BOARD_ITEM* this_item = nullptr; diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 964a7fc408..0ea6e13a0e 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -1002,12 +1002,7 @@ void BOARD::UpdateUserUnits( BOARD_ITEM* aItem, KIGFX::VIEW* aView ) PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_DIM_CENTER_T, - PCB_DIM_RADIAL_T, - PCB_FP_DIM_ALIGNED_T, - PCB_FP_DIM_LEADER_T, - PCB_FP_DIM_ORTHOGONAL_T, - PCB_FP_DIM_CENTER_T, - PCB_FP_DIM_RADIAL_T } ); + PCB_DIM_RADIAL_T } ); } @@ -1321,7 +1316,7 @@ BOX2I BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const { for( const BOARD_ITEM* edge : footprint->GraphicalItems() ) { - if( edge->GetLayer() == Edge_Cuts && edge->Type() == PCB_FP_SHAPE_T ) + if( edge->GetLayer() == Edge_Cuts && edge->Type() == PCB_SHAPE_T ) bbox.Merge( edge->GetBoundingBox() ); } } @@ -1419,15 +1414,16 @@ INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, case PCB_FOOTPRINT_T: case PCB_PAD_T: - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_ZONE_T: + case PCB_SHAPE_T: + case PCB_BITMAP_T: + case PCB_TEXT_T: + case PCB_TEXTBOX_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_DIM_LEADER_T: + case PCB_TARGET_T: if( !footprintsScanned ) { if( IterateForward( m_footprints, inspector, testData, scanTypes ) @@ -1439,18 +1435,6 @@ INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, footprintsScanned = true; } - break; - - case PCB_SHAPE_T: - case PCB_BITMAP_T: - case PCB_TEXT_T: - case PCB_TEXTBOX_T: - case PCB_DIM_ALIGNED_T: - case PCB_DIM_CENTER_T: - case PCB_DIM_RADIAL_T: - case PCB_DIM_ORTHOGONAL_T: - case PCB_DIM_LEADER_T: - case PCB_TARGET_T: if( !drawingsScanned ) { if( IterateForward( m_drawings, inspector, testData, scanTypes ) @@ -1490,6 +1474,17 @@ INSPECT_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, break; case PCB_ZONE_T: + if( !footprintsScanned ) + { + if( IterateForward( m_footprints, inspector, testData, scanTypes ) + == INSPECT_RESULT::QUIT ) + { + return INSPECT_RESULT::QUIT; + } + + footprintsScanned = true; + } + for( ZONE* zone : m_zones) { if( zone->Visit( inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT ) @@ -1976,7 +1971,7 @@ std::list BOARD::GetZoneList( bool aIncludeZonesInFootprints ) const { for( FOOTPRINT* footprint : m_footprints ) { - for( FP_ZONE* zone : footprint->Zones() ) + for( ZONE* zone : footprint->Zones() ) zones.push_back( zone ); } } diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 2f0310dba6..3ed53dfa1f 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -23,6 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -144,7 +145,7 @@ void BOARD_COMMIT::dirtyIntersectingZones( BOARD_ITEM* item, int aChangeType ) ZONE_FILLER_TOOL* zoneFillerTool = m_toolMgr->GetTool(); - if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) + if( item->Type() == PCB_ZONE_T ) zoneFillerTool->DirtyZone( static_cast( item ) ); if( item->Type() == PCB_FOOTPRINT_T ) @@ -318,21 +319,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) if( !( changeFlags & CHT_DONE ) ) board->Footprints().front()->Add( boardItem ); } - else if( boardItem->Type() == PCB_PAD_T - || boardItem->Type() == PCB_FP_TEXT_T - || boardItem->Type() == PCB_FP_TEXTBOX_T - || boardItem->Type() == PCB_FP_SHAPE_T - || boardItem->Type() == PCB_FP_DIM_ALIGNED_T - || boardItem->Type() == PCB_FP_DIM_LEADER_T - || boardItem->Type() == PCB_FP_DIM_CENTER_T - || boardItem->Type() == PCB_FP_DIM_RADIAL_T - || boardItem->Type() == PCB_FP_DIM_ORTHOGONAL_T - || boardItem->Type() == PCB_FP_ZONE_T ) - { - wxASSERT( boardItem->GetParent() && - boardItem->GetParent()->Type() == PCB_FOOTPRINT_T ); - } - else + else if( !boardItem->GetParentFootprint() ) { if( !( aCommitFlags & SKIP_UNDO ) ) undoList.PushItem( ITEM_PICKER( nullptr, boardItem, UNDO_REDO::NEWITEM ) ); @@ -355,6 +342,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) case CHT_REMOVE: { + FOOTPRINT* parentFP = boardItem->GetParentFootprint(); PCB_GROUP* parentGroup = boardItem->GetParentGroup(); if( !m_isFootprintEditor && !( aCommitFlags & SKIP_UNDO ) ) @@ -376,47 +364,16 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) switch( boardItem->Type() ) { - // Footprint items + case PCB_TEXT_T: + // don't allow deletion of Reference or Value + if( static_cast( boardItem )->GetType() != PCB_TEXT::TEXT_is_DIVERS ) + break; + + KI_FALLTHROUGH; + case PCB_PAD_T: - case PCB_FP_SHAPE_T: - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_ZONE_T: - // This level can only handle footprint children in the footprint editor as - // only in that case has the entire footprint (and all its children) already - // been saved for undo. - wxASSERT( m_isFootprintEditor ); - - if( boardItem->Type() == PCB_FP_TEXT_T ) - { - FP_TEXT* text = static_cast( boardItem ); - - // don't allow deletion of Reference or Value - if( text->GetType() != FP_TEXT::TEXT_is_DIVERS ) - break; - } - - if( view ) - view->Remove( boardItem ); - - if( !( changeFlags & CHT_DONE ) ) - { - FOOTPRINT* footprint = static_cast( boardItem->GetParent() ); - wxASSERT( footprint && footprint->Type() == PCB_FOOTPRINT_T ); - footprint->Delete( boardItem ); - } - - break; - - // Board items case PCB_SHAPE_T: // a shape (normally not on copper layers) case PCB_BITMAP_T: // a bitmap on a user layer - case PCB_TEXT_T: // a text on a layer case PCB_TEXTBOX_T: // a wrapped text on a layer case PCB_TRACE_T: // a track segment (segment on a copper layer) case PCB_ARC_T: // an arced track segment (segment on a copper layer) @@ -434,8 +391,15 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) if( !( changeFlags & CHT_DONE ) ) { - board->Remove( boardItem, REMOVE_MODE::BULK ); - bulkRemovedItems.push_back( boardItem ); + if( parentFP ) + { + parentFP->Delete( boardItem ); + } + else + { + board->Remove( boardItem, REMOVE_MODE::BULK ); + bulkRemovedItems.push_back( boardItem ); + } } break; @@ -467,8 +431,10 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) if( !( changeFlags & CHT_DONE ) ) { - if( m_isFootprintEditor ) - board->GetFirstFootprint()->Remove( boardItem ); + if( parentFP ) + { + parentFP->Remove( boardItem ); + } else { board->Remove( boardItem, REMOVE_MODE::BULK ); @@ -638,26 +604,10 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) EDA_ITEM* BOARD_COMMIT::parentObject( EDA_ITEM* aItem ) const { - switch( aItem->Type() ) + if( BOARD_ITEM* boardItem = dynamic_cast( aItem ) ) { - case PCB_PAD_T: - case PCB_FP_SHAPE_T: - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_ZONE_T: - return aItem->GetParent(); - - case PCB_ZONE_T: - wxASSERT( !dynamic_cast( aItem->GetParent() ) ); - return aItem; - - default: - break; + if( FOOTPRINT* parentFP = boardItem->GetParentFootprint() ) + return parentFP; } return aItem; diff --git a/pcbnew/board_item.cpp b/pcbnew/board_item.cpp index a28aa9f0c5..8e53d22146 100644 --- a/pcbnew/board_item.cpp +++ b/pcbnew/board_item.cpp @@ -32,6 +32,7 @@ #include #include #include +#include BOARD_ITEM::~BOARD_ITEM() @@ -236,14 +237,45 @@ std::shared_ptr BOARD_ITEM::GetEffectiveHoleShape() const } -BOARD_ITEM_CONTAINER* BOARD_ITEM::GetParentFootprint() const +FOOTPRINT* BOARD_ITEM::GetParentFootprint() const { BOARD_ITEM_CONTAINER* ancestor = GetParent(); while( ancestor && ancestor->Type() == PCB_GROUP_T ) ancestor = ancestor->GetParent(); - return ( ancestor && ancestor->Type() == PCB_FOOTPRINT_T ) ? ancestor : nullptr; + if( ancestor && ancestor->Type() == PCB_FOOTPRINT_T ) + return static_cast( ancestor ); + + return nullptr; +} + + +VECTOR2I BOARD_ITEM::GetFPRelativePosition() const +{ + VECTOR2I pos = GetPosition(); + + if( FOOTPRINT* parentFP = GetParentFootprint() ) + { + pos -= parentFP->GetPosition(); + RotatePoint( pos, -parentFP->GetOrientation() ); + } + + return pos; +} + + +void BOARD_ITEM::SetFPRelativePosition( const VECTOR2I& aPos ) +{ + VECTOR2I pos( aPos ); + + if( FOOTPRINT* parentFP = GetParentFootprint() ) + { + RotatePoint( pos, parentFP->GetOrientation() ); + pos += parentFP->GetPosition(); + } + + SetPosition( pos ); } diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp index df172ca075..0ecf0ed7e5 100644 --- a/pcbnew/collectors.cpp +++ b/pcbnew/collectors.cpp @@ -26,7 +26,6 @@ #include // class BOARD_ITEM #include -#include #include #include #include @@ -54,8 +53,6 @@ const std::vector GENERAL_COLLECTOR::AllBoardItems = { PCB_TRACE_T, // in m_tracks PCB_ARC_T, // in m_tracks PCB_PAD_T, // in footprints - PCB_FP_TEXT_T, // in footprints - PCB_FP_TEXTBOX_T, // in footprints PCB_FOOTPRINT_T, // in m_footprints PCB_GROUP_T, // in m_groups PCB_ZONE_T // in m_zones @@ -98,16 +95,16 @@ const std::vector GENERAL_COLLECTOR::PadsOrTracks = { const std::vector GENERAL_COLLECTOR::FootprintItems = { PCB_MARKER_T, - PCB_FP_TEXT_T, - PCB_FP_TEXTBOX_T, - PCB_FP_SHAPE_T, - PCB_FP_DIM_ALIGNED_T, - PCB_FP_DIM_ORTHOGONAL_T, - PCB_FP_DIM_CENTER_T, - PCB_FP_DIM_RADIAL_T, - PCB_FP_DIM_LEADER_T, + PCB_TEXT_T, + PCB_TEXTBOX_T, + PCB_SHAPE_T, + PCB_DIM_ALIGNED_T, + PCB_DIM_ORTHOGONAL_T, + PCB_DIM_CENTER_T, + PCB_DIM_RADIAL_T, + PCB_DIM_LEADER_T, PCB_PAD_T, - PCB_FP_ZONE_T, + PCB_ZONE_T, PCB_GROUP_T, PCB_BITMAP_T }; @@ -129,23 +126,12 @@ const std::vector GENERAL_COLLECTOR::LockableItems = { }; -const std::vector GENERAL_COLLECTOR::Zones = { - PCB_ZONE_T, - PCB_FP_ZONE_T -}; - - const std::vector GENERAL_COLLECTOR::Dimensions = { PCB_DIM_ALIGNED_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_DIM_CENTER_T, - PCB_DIM_RADIAL_T, - PCB_FP_DIM_ALIGNED_T, - PCB_FP_DIM_LEADER_T, - PCB_FP_DIM_ORTHOGONAL_T, - PCB_FP_DIM_CENTER_T, - PCB_FP_DIM_RADIAL_T + PCB_DIM_RADIAL_T }; @@ -159,8 +145,8 @@ const std::vector GENERAL_COLLECTOR::DraggableItems = { INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) { - BOARD_ITEM* item = (BOARD_ITEM*) testItem; - FOOTPRINT* footprint = nullptr; + BOARD_ITEM* item = static_cast( testItem ); + FOOTPRINT* footprint = item->GetParentFootprint(); PCB_GROUP* group = nullptr; PAD* pad = nullptr; bool pad_through = false; @@ -208,19 +194,6 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) breakhere++; break; - case PCB_FP_TEXT_T: - { - FP_TEXT* fpText = (FP_TEXT*) item; - - if( fpText->GetText() == wxT( "10uH" ) ) - breakhere++; - } - break; - - case PCB_FP_TEXTBOX_T: - breakhere++; - break; - case PCB_FOOTPRINT_T: { FOOTPRINT* footprint = (FOOTPRINT*) item; @@ -259,10 +232,6 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) // by leaving footprint==NULL, but having pad != null pad_through = true; } - else // smd, so use pads test after footprint test - { - footprint = static_cast( item->GetParent() ); - } break; @@ -277,31 +246,14 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) break; - case PCB_FP_ZONE_T: - footprint = static_cast( item->GetParent() ); - - // Fallthrough to get the zone as well - KI_FALLTHROUGH; - case PCB_ZONE_T: zone = static_cast( item ); break; - case PCB_TEXT_T: case PCB_TEXTBOX_T: case PCB_SHAPE_T: break; - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_LEADER_T: - footprint = static_cast( item->GetParent() ); - - // Fallthrough to get the zone as well - KI_FALLTHROUGH; - case PCB_DIM_ALIGNED_T: case PCB_DIM_CENTER_T: case PCB_DIM_RADIAL_T: @@ -313,63 +265,51 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) case PCB_TARGET_T: break; - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - { - PCB_LAYER_ID layer = item->GetLayer(); - - if( m_Guide->IgnoreHiddenFPText() && item->Type() == PCB_FP_TEXT_T ) + case PCB_TEXT_T: + if( item->GetParentFootprint() ) { - FP_TEXT *text = static_cast( item ); + PCB_TEXT* text = static_cast( item ); + PCB_LAYER_ID layer = item->GetLayer(); - if( !text->IsVisible() ) + if( m_Guide->IgnoreHiddenFPText() ) + { + if( !text->IsVisible() ) + return INSPECT_RESULT::CONTINUE; + } + + if( m_Guide->IgnoreFPTextOnBack() && IsBackLayer( layer ) ) return INSPECT_RESULT::CONTINUE; + + if( m_Guide->IgnoreFPTextOnFront() && IsFrontLayer( layer ) ) + return INSPECT_RESULT::CONTINUE; + + /* + * The three text types have different criteria: reference and value have their own + * ignore flags; user text instead follows their layer visibility. Checking this here + * is simpler than later (when layer visibility is checked for other entities) + */ + switch( text->GetType() ) + { + case PCB_TEXT::TEXT_is_REFERENCE: + if( m_Guide->IgnoreFPReferences() ) + return INSPECT_RESULT::CONTINUE; + + break; + + case PCB_TEXT::TEXT_is_VALUE: + if( m_Guide->IgnoreFPValues() ) + return INSPECT_RESULT::CONTINUE; + + break; + + case PCB_TEXT::TEXT_is_DIVERS: + if( !m_Guide->IsLayerVisible( layer ) ) + return INSPECT_RESULT::CONTINUE; + + break; + } } - if( m_Guide->IgnoreFPTextOnBack() && IsBackLayer( layer ) ) - return INSPECT_RESULT::CONTINUE; - - if( m_Guide->IgnoreFPTextOnFront() && IsFrontLayer( layer ) ) - return INSPECT_RESULT::CONTINUE; - - /* - * The three text types have different criteria: reference and value have their own - * ignore flags; user text instead follows their layer visibility. Checking this here - * is simpler than later (when layer visibility is checked for other entities) - */ - - FP_TEXT::TEXT_TYPE textType = FP_TEXT::TEXT_is_DIVERS; - - if( item->Type() == PCB_FP_TEXT_T ) - textType = static_cast( item )->GetType(); - - switch( textType ) - { - case FP_TEXT::TEXT_is_REFERENCE: - if( m_Guide->IgnoreFPReferences() ) - return INSPECT_RESULT::CONTINUE; - - break; - - case FP_TEXT::TEXT_is_VALUE: - if( m_Guide->IgnoreFPValues() ) - return INSPECT_RESULT::CONTINUE; - - break; - - case FP_TEXT::TEXT_is_DIVERS: - if( !m_Guide->IsLayerVisible( layer ) ) - return INSPECT_RESULT::CONTINUE; - - break; - } - - // Extract the footprint since it could be hidden - footprint = static_cast( item->GetParent() ); - break; - } - - case PCB_FP_SHAPE_T: break; case PCB_FOOTPRINT_T: @@ -390,7 +330,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) // common tests: - if( footprint ) // true from case PCB_PAD_T, PCB_FP_TEXT_T, or PCB_FOOTPRINT_T + if( footprint ) { if( m_Guide->IgnoreFootprintsOnBack() && ( footprint->GetLayer() == B_Cu ) ) return INSPECT_RESULT::CONTINUE; diff --git a/pcbnew/collectors.h b/pcbnew/collectors.h index b1d6eaeb96..058f677687 100644 --- a/pcbnew/collectors.h +++ b/pcbnew/collectors.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -230,7 +230,7 @@ public: /** * A scan list for all primary board items, omitting items which are subordinate to - * a FOOTPRINT, such as PAD and FP_TEXT. + * a FOOTPRINT, such as PAD and PCB_TEXT. */ static const std::vector BoardLevelItems; diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index 528ce9d916..06f4cc24b4 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -143,7 +143,7 @@ bool CN_CONNECTIVITY_ALGO::Add( BOARD_ITEM* aItem ) case PCB_PAD_T: { - if( FOOTPRINT* fp = dynamic_cast( aItem->GetParentFootprint() ) ) + if( FOOTPRINT* fp = aItem->GetParentFootprint() ) { if( fp->GetAttributes() & FP_JUST_ADDED ) return false; diff --git a/pcbnew/convert_shape_list_to_polygon.cpp b/pcbnew/convert_shape_list_to_polygon.cpp index ad973f0d76..033b7b1489 100644 --- a/pcbnew/convert_shape_list_to_polygon.cpp +++ b/pcbnew/convert_shape_list_to_polygon.cpp @@ -622,8 +622,8 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, int aE SHAPE_POLY_SET fpHoles; - // Get all the PCB and FP shapes into 'items', then keep only those on layer == Edge_Cuts. - items.Collect( aBoard, { PCB_SHAPE_T, PCB_FP_SHAPE_T } ); + // Get all the shapes into 'items', then keep only those on layer == Edge_Cuts. + items.Collect( aBoard, { PCB_SHAPE_T } ); for( int ii = 0; ii < items.GetCount(); ++ii ) items[ii]->ClearFlags( SKIP_STRUCT ); @@ -631,7 +631,7 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, int aE for( FOOTPRINT* fp : aBoard->Footprints() ) { PCB_TYPE_COLLECTOR fpItems; - fpItems.Collect( fp, { PCB_SHAPE_T, PCB_FP_SHAPE_T } ); + fpItems.Collect( fp, { PCB_SHAPE_T } ); std::vector fpSegList; @@ -881,7 +881,7 @@ bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, in bool success = false; // Get all the SHAPEs into 'items', then keep only those on layer == Edge_Cuts. - items.Collect( aBoard, { PCB_SHAPE_T, PCB_FP_SHAPE_T } ); + items.Collect( aBoard, { PCB_SHAPE_T } ); // Make a working copy of aSegList, because the list is modified during calculations std::vector segList; diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index c0fef90fd1..0b2b305454 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -257,39 +257,38 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) std::string FormatProbeItem( BOARD_ITEM* aItem ) { - FOOTPRINT* footprint; - if( !aItem ) return "$CLEAR: \"HIGHLIGHTED\""; // message to clear highlight state switch( aItem->Type() ) { case PCB_FOOTPRINT_T: - footprint = (FOOTPRINT*) aItem; + { + FOOTPRINT* footprint = static_cast( aItem ); return StrPrintf( "$PART: \"%s\"", TO_UTF8( footprint->GetReference() ) ); + } case PCB_PAD_T: { - footprint = static_cast( aItem->GetParent() ); - wxString pad = static_cast( aItem )->GetNumber(); + PAD* pad = static_cast( aItem ); + FOOTPRINT* footprint = pad->GetParentFootprint(); return StrPrintf( "$PART: \"%s\" $PAD: \"%s\"", TO_UTF8( footprint->GetReference() ), - TO_UTF8( pad ) ); + TO_UTF8( pad->GetNumber() ) ); } - case PCB_FP_TEXT_T: + case PCB_TEXT_T: { - footprint = static_cast( aItem->GetParent() ); - - FP_TEXT* text = static_cast( aItem ); + PCB_TEXT* text = static_cast( aItem ); + FOOTPRINT* footprint = text->GetParentFootprint(); const char* text_key; /* This can't be a switch since the break need to pull out * from the outer switch! */ - if( text->GetType() == FP_TEXT::TEXT_is_REFERENCE ) + if( text->GetType() == PCB_TEXT::TEXT_is_REFERENCE ) text_key = "$REF:"; - else if( text->GetType() == FP_TEXT::TEXT_is_VALUE ) + else if( text->GetType() == PCB_TEXT::TEXT_is_VALUE ) text_key = "$VAL:"; else break; @@ -335,9 +334,8 @@ void collectItemsForSyncParts( ItemContainer& aItems, std::set& parts case PCB_PAD_T: { - PAD* pad = static_cast( item ); - FOOTPRINT* footprint = static_cast( pad->GetParentFootprint() ); - wxString ref = footprint->GetReference(); + PAD* pad = static_cast( item ); + wxString ref = pad->GetParentFootprint()->GetReference(); parts.emplace( wxT( "P" ) + EscapeString( ref, CTX_IPC ) + wxT( "/" ) + EscapeString( pad->GetNumber(), CTX_IPC ) ); diff --git a/pcbnew/dialogs/dialog_dimension_properties.cpp b/pcbnew/dialogs/dialog_dimension_properties.cpp index 0cdff851f8..5370a3ed38 100644 --- a/pcbnew/dialogs/dialog_dimension_properties.cpp +++ b/pcbnew/dialogs/dialog_dimension_properties.cpp @@ -56,7 +56,6 @@ DIALOG_DIMENSION_PROPERTIES::DIALOG_DIMENSION_PROPERTIES( PCB_BASE_EDIT_FRAME* a switch( m_dimension->Type() ) { case PCB_DIM_LEADER_T: - case PCB_FP_DIM_LEADER_T: // Hide the main format controls and keep the leader controls shown m_sizerFormat->GetStaticBox()->Hide(); m_sizerCenter->GetStaticBox()->Hide(); @@ -70,7 +69,6 @@ DIALOG_DIMENSION_PROPERTIES::DIALOG_DIMENSION_PROPERTIES( PCB_BASE_EDIT_FRAME* a break; case PCB_DIM_CENTER_T: - case PCB_FP_DIM_CENTER_T: m_sizerLeader->GetStaticBox()->Hide(); m_sizerFormat->GetStaticBox()->Hide(); m_sizerText->GetStaticBox()->Hide(); @@ -275,7 +273,7 @@ bool DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow() m_txtValueActual->SetValue( m_dimension->GetValueText() ); } - if( m_dimension->Type() == PCB_DIM_LEADER_T || m_dimension->Type() == PCB_FP_DIM_LEADER_T ) + if( m_dimension->Type() == PCB_DIM_LEADER_T ) { PCB_DIM_LEADER* leader = static_cast( m_dimension ); m_cbTextFrame->SetSelection( static_cast( leader->GetTextBorder() ) ); @@ -428,7 +426,7 @@ void DIALOG_DIMENSION_PROPERTIES::updateDimensionFromDialog( PCB_DIMENSION_BASE* aTarget->SetArrowLength( m_arrowLength.GetValue() ); aTarget->SetExtensionOffset( m_extensionOffset.GetValue() ); - if( aTarget->Type() == PCB_DIM_LEADER_T || m_dimension->Type() == PCB_FP_DIM_LEADER_T ) + if( aTarget->Type() == PCB_DIM_LEADER_T ) { PCB_DIM_LEADER* leader = static_cast( aTarget ); leader->SetTextBorder( static_cast( m_cbTextFrame->GetSelection())); diff --git a/pcbnew/dialogs/dialog_find.cpp b/pcbnew/dialogs/dialog_find.cpp index b719bb34ac..998d6607f0 100644 --- a/pcbnew/dialogs/dialog_find.cpp +++ b/pcbnew/dialogs/dialog_find.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -267,12 +266,12 @@ void DIALOG_FIND::search( bool aDirection ) { for( BOARD_ITEM* item : fp->GraphicalItems() ) { - FP_TEXT* textItem = dynamic_cast( item ); - - if( textItem && textItem->Matches( m_frame->GetFindReplaceData(), - nullptr ) ) + if( item->Type() == PCB_TEXT_T ) { - m_hitList.push_back( fp ); + PCB_TEXT* text = static_cast( item ); + + if( text && text->Matches( m_frame->GetFindReplaceData(), nullptr ) ) + m_hitList.push_back( fp ); } } } @@ -282,22 +281,21 @@ void DIALOG_FIND::search( bool aDirection ) { for( BOARD_ITEM* item : board->Drawings() ) { - PCB_TEXT* textItem = dynamic_cast( item ); - - if( textItem && textItem->Matches( m_frame->GetFindReplaceData(), nullptr ) ) + if( item->Type() == PCB_TEXT_T ) { - m_hitList.push_back( textItem ); + PCB_TEXT* text = static_cast( item ); + + if( text && text->Matches( m_frame->GetFindReplaceData(), nullptr ) ) + m_hitList.push_back( text ); } } for( BOARD_ITEM* item : board->Zones() ) { - ZONE* zoneItem = dynamic_cast( item ); + ZONE* zone = static_cast( item ); - if( zoneItem && zoneItem->Matches( m_frame->GetFindReplaceData(), nullptr ) ) - { - m_hitList.push_back( zoneItem ); - } + if( zone->Matches( m_frame->GetFindReplaceData(), nullptr ) ) + m_hitList.push_back( zone ); } } } @@ -316,9 +314,7 @@ void DIALOG_FIND::search( bool aDirection ) for( NETINFO_ITEM* net : board->GetNetInfo() ) { if( net && net->Matches( m_frame->GetFindReplaceData(), nullptr ) ) - { m_hitList.push_back( net ); - } } } diff --git a/pcbnew/dialogs/dialog_footprint_properties.cpp b/pcbnew/dialogs/dialog_footprint_properties.cpp index 6ac799838f..eaf4bccc47 100644 --- a/pcbnew/dialogs/dialog_footprint_properties.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2016 Mario Luzeiro * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Dick Hollenbeck, dick@softplc.com - * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -250,9 +250,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow() for( BOARD_ITEM* item : m_footprint->GraphicalItems() ) { - FP_TEXT* textItem = dyn_cast( item ); - - if( textItem ) + if( PCB_TEXT* textItem = dynamic_cast( item ) ) m_texts->push_back( *textItem ); } @@ -349,7 +347,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES::Validate() // Validate texts. for( size_t i = 0; i < m_texts->size(); ++i ) { - FP_TEXT& text = m_texts->at( i ); + PCB_TEXT& text = m_texts->at( i ); if( i >= 2 ) { @@ -478,9 +476,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow() for( BOARD_ITEM* item : m_footprint->GraphicalItems() ) { - FP_TEXT* textItem = dyn_cast( item ); - - if( textItem ) + if( PCB_TEXT* textItem = dynamic_cast( item ) ) { // copy grid table entries till we run out, then delete any remaining texts if( i < m_texts->size() ) @@ -493,7 +489,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow() // if there are still grid table entries, create new texts for them while( i < m_texts->size() ) { - auto newText = new FP_TEXT( m_texts->at( i++ ) ); + PCB_TEXT* newText = new PCB_TEXT( m_texts->at( i++ ) ); m_footprint->Add( newText, ADD_MODE::APPEND ); view->Add( newText ); } @@ -583,7 +579,7 @@ void DIALOG_FOOTPRINT_PROPERTIES::OnAddField( wxCommandEvent& ) return; const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); - FP_TEXT textItem( m_footprint ); + PCB_TEXT textItem( m_footprint, PCB_TEXT::TEXT_is_DIVERS ); // Set active layer if legal; otherwise copy layer from previous text item if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) ) diff --git a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp index 8963973595..fa6b4fcf50 100644 --- a/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp @@ -274,9 +274,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow() for( BOARD_ITEM* item : m_footprint->GraphicalItems() ) { - FP_TEXT* textItem = dyn_cast( item ); - - if( textItem ) + if( PCB_TEXT* textItem = dynamic_cast( item) ) m_texts->push_back( *textItem ); } @@ -406,7 +404,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Validate() // Check for empty texts. for( size_t i = 2; i < m_texts->size(); ++i ) { - FP_TEXT& text = m_texts->at( i ); + PCB_TEXT& text = m_texts->at( i ); if( text.GetText().IsEmpty() ) { @@ -506,11 +504,11 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow() m_footprint->Value() = m_texts->at( 1 ); size_t i = 2; - std::vector items_to_remove; + std::vector items_to_remove; for( BOARD_ITEM* item : m_footprint->GraphicalItems() ) { - FP_TEXT* textItem = dynamic_cast( item ); + PCB_TEXT* textItem = dynamic_cast( item ); if( textItem ) { @@ -526,7 +524,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow() // Remove text items: PCB_SELECTION_TOOL* selTool = m_frame->GetToolManager()->GetTool(); - for( FP_TEXT* item: items_to_remove ) + for( PCB_TEXT* item: items_to_remove ) { selTool->RemoveItemFromSel( item ); view->Remove( item ); @@ -536,7 +534,7 @@ bool DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow() // if there are still grid table entries, create new texts for them while( i < m_texts->size() ) { - FP_TEXT* newText = new FP_TEXT( m_texts->at( i++ ) ); + PCB_TEXT* newText = new PCB_TEXT( m_texts->at( i++ ) ); m_footprint->Add( newText, ADD_MODE::APPEND ); view->Add( newText ); } @@ -632,7 +630,7 @@ void DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAddField( wxCommandEvent& event ) return; const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); - FP_TEXT textItem( m_footprint ); + PCB_TEXT textItem( m_footprint ); // Set active layer if legal; otherwise copy layer from previous text item if( LSET::AllTechMask().test( m_frame->GetActiveLayer() ) ) diff --git a/pcbnew/dialogs/dialog_global_edit_text_and_graphics.cpp b/pcbnew/dialogs/dialog_global_edit_text_and_graphics.cpp index 76a77abdf7..9dba3e0149 100644 --- a/pcbnew/dialogs/dialog_global_edit_text_and_graphics.cpp +++ b/pcbnew/dialogs/dialog_global_edit_text_and_graphics.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,7 +41,6 @@ #include #include #include -#include "font/kicad_font_name.h" // Columns of layer classes grid enum @@ -338,60 +337,58 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem( BOARD_COMMIT& aCommit, B { aCommit.Modify( aItem ); - EDA_TEXT* edaText = dynamic_cast( aItem ); - FP_TEXT* fpText = dynamic_cast( aItem ); + PCB_TEXT* text = dynamic_cast( aItem ); PCB_SHAPE* shape = dynamic_cast( aItem ); PCB_DIMENSION_BASE* dimension = dynamic_cast( aItem ); + FOOTPRINT* parentFP = aItem->GetParentFootprint(); if( m_setToSpecifiedValues->GetValue() ) { if( m_LayerCtrl->GetLayerSelection() != UNDEFINED_LAYER ) aItem->SetLayer( ToLAYER_ID( m_LayerCtrl->GetLayerSelection() ) ); - if( edaText ) + if( text ) { if( !m_textWidth.IsIndeterminate() ) - edaText->SetTextSize( VECTOR2I( m_textWidth.GetValue(), edaText->GetTextSize().y ) ); + text->SetTextSize( VECTOR2I( m_textWidth.GetValue(), text->GetTextSize().y ) ); if( !m_textHeight.IsIndeterminate() ) - edaText->SetTextSize( VECTOR2I( edaText->GetTextSize().x, m_textHeight.GetValue() ) ); + text->SetTextSize( VECTOR2I( text->GetTextSize().x, m_textHeight.GetValue() ) ); if( !m_thickness.IsIndeterminate() ) - edaText->SetTextThickness( m_thickness.GetValue() ); + text->SetTextThickness( m_thickness.GetValue() ); if( m_bold->Get3StateValue() != wxCHK_UNDETERMINED ) - edaText->SetBold( m_bold->GetValue() ); + text->SetBold( m_bold->GetValue() ); if( m_italic->Get3StateValue() != wxCHK_UNDETERMINED ) - edaText->SetItalic( m_italic->GetValue() ); + text->SetItalic( m_italic->GetValue() ); // Must come after setting bold & italic if( m_fontCtrl->GetStringSelection() != INDETERMINATE_ACTION ) { - edaText->SetFont( m_fontCtrl->GetFontSelection( edaText->IsBold(), - edaText->IsItalic() ) ); + text->SetFont( m_fontCtrl->GetFontSelection( text->IsBold(), text->IsItalic() ) ); } else if(( m_italic->Get3StateValue() != wxCHK_UNDETERMINED || m_bold->Get3StateValue() != wxCHK_UNDETERMINED ) ) { - wxString fontName = edaText->GetFontName(); + wxString fontName = text->GetFontName(); - if( !edaText->GetFontName().IsEmpty() ) + if( !text->GetFontName().IsEmpty() ) { - edaText->SetFont( KIFONT::FONT::GetFont( edaText->GetFontName(), - edaText->IsBold(), - edaText->IsItalic() ) ); + text->SetFont( KIFONT::FONT::GetFont( text->GetFontName(), text->IsBold(), + text->IsItalic() ) ); } } - if( m_visible->Get3StateValue() != wxCHK_UNDETERMINED ) - edaText->SetVisible( m_visible->GetValue() ); - } + if( parentFP ) + { + if( m_visible->Get3StateValue() != wxCHK_UNDETERMINED ) + text->SetVisible( m_visible->GetValue() ); - if( fpText ) - { - if( m_keepUpright->Get3StateValue() != wxCHK_UNDETERMINED ) - fpText->SetKeepUpright( m_keepUpright->GetValue() ); + if( m_keepUpright->Get3StateValue() != wxCHK_UNDETERMINED ) + text->SetKeepUpright( m_keepUpright->GetValue() ); + } } if( !m_lineWidth.IsIndeterminate() ) @@ -411,15 +408,15 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem( BOARD_COMMIT& aCommit, B { PCB_LAYER_ID layer = aItem->GetLayer(); - if( edaText ) + if( text ) { - edaText->SetTextSize( m_brdSettings->GetTextSize( layer ) ); - edaText->SetTextThickness( m_brdSettings->GetTextThickness( layer ) ); - edaText->SetItalic( m_brdSettings->GetTextItalic( layer ) ); - } + text->SetTextSize( m_brdSettings->GetTextSize( layer ) ); + text->SetTextThickness( m_brdSettings->GetTextThickness( layer ) ); + text->SetItalic( m_brdSettings->GetTextItalic( layer ) ); - if( fpText ) - fpText->SetKeepUpright( m_brdSettings->GetTextUpright( layer ) ); + if( parentFP ) + text->SetKeepUpright( m_brdSettings->GetTextUpright( layer ) ); + } if( shape ) { @@ -477,9 +474,7 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem( BOARD_COMMIT& aCommit, BOA { if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() ) { - FOOTPRINT* fp = dynamic_cast( aItem->GetParent() ); - - if( fp ) + if( FOOTPRINT* fp = aItem->GetParentFootprint() ) { if( !WildCompareString( m_referenceFilter->GetValue(), fp->GetReference(), false ) ) return; @@ -488,9 +483,7 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem( BOARD_COMMIT& aCommit, BOA if( m_footprintFilterOpt->GetValue() && !m_footprintFilter->GetValue().IsEmpty() ) { - FOOTPRINT* fp = dynamic_cast( aItem->GetParent() ); - - if( fp ) + if( FOOTPRINT* fp = aItem->GetParentFootprint() ) { if( !WildCompareString( m_footprintFilter->GetValue(), fp->GetFPID().Format(), false ) ) return; @@ -526,7 +519,7 @@ bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow() { KICAD_T itemType = boardItem->Type(); - if( itemType == PCB_FP_TEXT_T || itemType == PCB_FP_TEXTBOX_T ) + if( itemType == PCB_TEXT_T || itemType == PCB_TEXTBOX_T ) { if( m_otherFields->GetValue() ) visitItem( commit, boardItem ); @@ -536,7 +529,7 @@ bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow() if( m_footprintDimensions->GetValue() ) visitItem( commit, boardItem ); } - else if( itemType == PCB_FP_SHAPE_T ) + else if( itemType == PCB_SHAPE_T ) { if( m_footprintGraphics->GetValue() ) visitItem( commit, boardItem ); diff --git a/pcbnew/dialogs/dialog_graphic_item_properties.cpp b/pcbnew/dialogs/dialog_graphic_item_properties.cpp index 3d698e7d98..c94e90239f 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties.cpp @@ -35,9 +35,7 @@ #include #include #include -#include #include -#include #include #include @@ -47,7 +45,7 @@ class DIALOG_GRAPHIC_ITEM_PROPERTIES : public DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE { public: - DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BOARD_ITEM* aItem ); + DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, PCB_SHAPE* aShape ); ~DIALOG_GRAPHIC_ITEM_PROPERTIES() {}; private: @@ -70,7 +68,6 @@ private: private: PCB_BASE_EDIT_FRAME* m_parent; PCB_SHAPE* m_item; - FP_SHAPE* m_fp_item; UNIT_BINDER m_startX, m_startY; UNIT_BINDER m_endX, m_endY; @@ -83,8 +80,10 @@ private: }; DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, - BOARD_ITEM* aItem ): + PCB_SHAPE* aShape ): DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE( aParent ), + m_parent( aParent ), + m_item( aShape ), m_startX( aParent, m_startXLabel, m_startXCtrl, m_startXUnits ), m_startY( aParent, m_startYLabel, m_startYCtrl, m_startYUnits ), m_endX( aParent, m_endXLabel, m_endXCtrl, m_endXUnits ), @@ -97,10 +96,6 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FR m_bezierCtrl2Y( aParent, m_BezierPointC2YLabel, m_BezierC2Y_Ctrl, m_BezierPointC2YUnit ), m_flipStartEnd( false ) { - m_parent = aParent; - m_item = dynamic_cast( aItem ); - m_fp_item = dynamic_cast( aItem ); - // Configure display origin transforms m_startX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD ); m_startY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD ); @@ -117,13 +112,13 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FR m_locked->Show( dynamic_cast( aParent ) != nullptr ); // Configure the layers list selector - if( m_fp_item ) + if( m_parent->GetFrameType() == FRAME_FOOTPRINT_EDITOR ) { LSET forbiddenLayers = LSET::ForbiddenFootprintLayers(); // If someone went to the trouble of setting the layer in a text editor, then there's // very little sense in nagging them about it. - forbiddenLayers.set( m_fp_item->GetLayer(), false ); + forbiddenLayers.set( m_item->GetLayer(), false ); m_LayerSelectionCtrl->SetNotAllowedLayerSet( forbiddenLayers ); } @@ -143,18 +138,18 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FR } -void PCB_BASE_EDIT_FRAME::ShowGraphicItemPropertiesDialog( BOARD_ITEM* aItem ) +void PCB_BASE_EDIT_FRAME::ShowGraphicItemPropertiesDialog( PCB_SHAPE* aShape ) { - wxCHECK_RET( aItem != NULL, wxT( "ShowGraphicItemPropertiesDialog() error: NULL item" ) ); + wxCHECK_RET( aShape != NULL, wxT( "ShowGraphicItemPropertiesDialog() error: NULL item" ) ); - DIALOG_GRAPHIC_ITEM_PROPERTIES dlg( this, aItem ); + DIALOG_GRAPHIC_ITEM_PROPERTIES dlg( this, aShape ); if( dlg.ShowQuasiModal() == wxID_OK ) { - if( aItem->IsOnLayer( GetActiveLayer(), true ) ) + if( aShape->IsOnLayer( GetActiveLayer(), true ) ) { DRAWING_TOOL* drawingTool = m_toolManager->GetTool(); - drawingTool->SetStroke( aItem->GetStroke(), GetActiveLayer() ); + drawingTool->SetStroke( aShape->GetStroke(), GetActiveLayer() ); } } } @@ -363,22 +358,6 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow() m_item->SetCenter( c ); } - if( m_fp_item ) - { - // We are editing a footprint; init the item coordinates relative to the footprint anchor. - m_fp_item->SetStart0( m_fp_item->GetStart() ); - m_fp_item->SetEnd0( m_fp_item->GetEnd() ); - - if( m_fp_item->GetShape() == SHAPE_T::ARC ) - m_fp_item->SetCenter0( m_fp_item->GetCenter() ); - - if( m_fp_item->GetShape() == SHAPE_T::BEZIER ) - { - m_fp_item->SetBezierC1_0( m_fp_item->GetBezierC1() ); - m_fp_item->SetBezierC2_0( m_fp_item->GetBezierC2() ); - } - } - bool wasLocked = m_item->IsLocked(); m_item->SetFilled( m_filledCtrl->GetValue() ); diff --git a/pcbnew/dialogs/dialog_text_properties.cpp b/pcbnew/dialogs/dialog_text_properties.cpp index b9b1d6c6c6..2cd67e8856 100644 --- a/pcbnew/dialogs/dialog_text_properties.cpp +++ b/pcbnew/dialogs/dialog_text_properties.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004-2018 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 2010-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2010-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -41,13 +40,10 @@ #include -DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BOARD_ITEM* aItem ) : +DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, PCB_TEXT* aText ) : DIALOG_TEXT_PROPERTIES_BASE( aParent ), m_frame( aParent ), - m_item( aItem ), - m_edaText( nullptr ), - m_fpText( nullptr ), - m_pcbText( nullptr ), + m_item( aText ), m_textWidth( aParent, m_SizeXLabel, m_SizeXCtrl, m_SizeXUnits ), m_textHeight( aParent, m_SizeYLabel, m_SizeYCtrl, m_SizeYUnits ), m_thickness( aParent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnits ), @@ -74,23 +70,20 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO m_MultiLineText->SetScrollWidth( 1 ); m_MultiLineText->SetScrollWidthTracking( true ); - if( m_item->Type() == PCB_FP_TEXT_T ) + if( m_item->GetParentFootprint() ) { - m_fpText = (FP_TEXT*) m_item; - m_edaText = static_cast( m_fpText ); - - switch( m_fpText->GetType() ) + switch( m_item->GetType() ) { - case FP_TEXT::TEXT_is_REFERENCE: title = _( "Footprint Reference Properties" ); break; - case FP_TEXT::TEXT_is_VALUE: title = _( "Footprint Value Properties" ); break; - case FP_TEXT::TEXT_is_DIVERS: title = _( "Footprint Text Properties" ); break; + case PCB_TEXT::TEXT_is_REFERENCE: title = _( "Footprint Reference Properties" ); break; + case PCB_TEXT::TEXT_is_VALUE: title = _( "Footprint Value Properties" ); break; + case PCB_TEXT::TEXT_is_DIVERS: title = _( "Footprint Text Properties" ); break; } - switch( m_fpText->GetType() ) + switch( m_item->GetType() ) { - case FP_TEXT::TEXT_is_REFERENCE: m_TextLabel->SetLabel( _( "Reference:" ) ); break; - case FP_TEXT::TEXT_is_VALUE: m_TextLabel->SetLabel( _( "Value:" ) ); break; - case FP_TEXT::TEXT_is_DIVERS: m_TextLabel->SetLabel( _( "Text:" ) ); break; + case PCB_TEXT::TEXT_is_REFERENCE: m_TextLabel->SetLabel( _( "Reference:" ) ); break; + case PCB_TEXT::TEXT_is_VALUE: m_TextLabel->SetLabel( _( "Value:" ) ); break; + case PCB_TEXT::TEXT_is_DIVERS: m_TextLabel->SetLabel( _( "Text:" ) ); break; } SetInitialFocus( m_SingleLineText ); @@ -103,9 +96,6 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO { title = _( "Text Properties" ); - m_pcbText = (PCB_TEXT*) aItem; - m_edaText = static_cast( m_pcbText ); - SetInitialFocus( m_MultiLineText ); m_SingleLineSizer->Show( false ); @@ -190,7 +180,7 @@ DIALOG_TEXT_PROPERTIES::~DIALOG_TEXT_PROPERTIES() } -void PCB_BASE_EDIT_FRAME::ShowTextPropertiesDialog( BOARD_ITEM* aText ) +void PCB_BASE_EDIT_FRAME::ShowTextPropertiesDialog( PCB_TEXT* aText ) { DIALOG_TEXT_PROPERTIES dlg( this, aText ); dlg.ShowQuasiModal(); @@ -206,11 +196,11 @@ void DIALOG_TEXT_PROPERTIES::OnSetFocusText( wxFocusEvent& event ) // Note that we can't do this on OSX as it tends to provoke Apple's // "[NSAlert runModal] may not be invoked inside of transaction begin/commit pair" // bug. See: https://bugs.launchpad.net/kicad/+bug/1837225 - if( m_fpText->GetType() == FP_TEXT::TEXT_is_REFERENCE ) + if( m_item->GetType() == PCB_TEXT::TEXT_is_REFERENCE ) m_SingleLineText->Update(); #endif - if( m_fpText->GetType() == FP_TEXT::TEXT_is_REFERENCE ) + if( m_item->GetType() == PCB_TEXT::TEXT_is_REFERENCE ) KIUI::SelectReferenceNumber( static_cast( m_SingleLineText ) ); else m_SingleLineText->SetSelection( -1, -1 ); @@ -221,41 +211,35 @@ void DIALOG_TEXT_PROPERTIES::OnSetFocusText( wxFocusEvent& event ) bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow() { + BOARD* board = m_frame->GetBoard(); + FOOTPRINT* parentFP = m_item->GetParentFootprint(); + if( m_SingleLineText->IsShown() ) { - m_SingleLineText->SetValue( m_edaText->GetText() ); + m_SingleLineText->SetValue( m_item->GetText() ); - if( m_fpText && m_fpText->GetType() == FP_TEXT::TEXT_is_REFERENCE ) + if( m_item->GetType() == PCB_TEXT::TEXT_is_REFERENCE ) KIUI::SelectReferenceNumber( static_cast( m_SingleLineText ) ); else m_SingleLineText->SetSelection( -1, -1 ); } else if( m_MultiLineText->IsShown() ) { - BOARD* board = m_frame->GetBoard(); - wxString converted = board->ConvertKIIDsToCrossReferences( - UnescapeString( m_edaText->GetText() ) ); + wxString msg = board->ConvertKIIDsToCrossReferences( UnescapeString( m_item->GetText() ) ); - m_MultiLineText->SetValue( converted ); + m_MultiLineText->SetValue( msg ); m_MultiLineText->SetSelection( -1, -1 ); m_MultiLineText->EmptyUndoBuffer(); } - if( m_item->Type() == PCB_FP_TEXT_T && m_fpText ) + if( parentFP ) { - FOOTPRINT* footprint = dynamic_cast( m_fpText->GetParent() ); - wxString msg; - - if( footprint ) - { - msg.Printf( _( "Footprint %s (%s), %s, rotated %.1f deg"), - footprint->GetReference(), - footprint->GetValue(), - footprint->IsFlipped() ? _( "back side (mirrored)" ) : _( "front side" ), - footprint->GetOrientation().AsDegrees() ); - } - - m_statusLine->SetLabel( msg ); + m_statusLine->SetLabel( wxString::Format( _( "Footprint %s (%s), %s, rotated %.1f deg"), + parentFP->GetReference(), + parentFP->GetValue(), + parentFP->IsFlipped() ? _( "back side (mirrored)" ) + : _( "front side" ), + parentFP->GetOrientation().AsDegrees() ) ); } else { @@ -267,39 +251,39 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow() m_LayerSelectionCtrl->SetLayerSelection( m_item->GetLayer() ); m_cbKnockout->SetValue( m_item->IsKnockout() ); - m_fontCtrl->SetFontSelection( m_edaText->GetFont() ); + m_fontCtrl->SetFontSelection( m_item->GetFont() ); - m_textWidth.SetValue( m_edaText->GetTextSize().x ); - m_textHeight.SetValue( m_edaText->GetTextSize().y ); - m_thickness.SetValue( m_edaText->GetTextThickness() ); - m_posX.SetValue( m_edaText->GetTextPos().x ); - m_posY.SetValue( m_edaText->GetTextPos().y ); + m_textWidth.SetValue( m_item->GetTextSize().x ); + m_textHeight.SetValue( m_item->GetTextSize().y ); + m_thickness.SetValue( m_item->GetTextThickness() ); + m_posX.SetValue( m_item->GetFPRelativePosition().x ); + m_posY.SetValue( m_item->GetFPRelativePosition().y ); - m_Visible->SetValue( m_edaText->IsVisible() ); + m_Visible->SetValue( m_item->IsVisible() ); - if( m_fpText ) - m_KeepUpright->SetValue( m_fpText->IsKeepUpright() ); + if( parentFP ) + m_KeepUpright->SetValue( m_item->IsKeepUpright() ); - m_bold->Check( m_edaText->IsBold() ); - m_italic->Check( m_edaText->IsItalic() ); + m_bold->Check( m_item->IsBold() ); + m_italic->Check( m_item->IsItalic() ); - switch ( m_edaText->GetHorizJustify() ) + switch ( m_item->GetHorizJustify() ) { case GR_TEXT_H_ALIGN_LEFT: m_alignLeft->Check( true ); break; case GR_TEXT_H_ALIGN_CENTER: m_alignCenter->Check( true ); break; case GR_TEXT_H_ALIGN_RIGHT: m_alignRight->Check( true ); break; } - switch ( m_edaText->GetVertJustify() ) + switch ( m_item->GetVertJustify() ) { case GR_TEXT_V_ALIGN_BOTTOM: m_valignBottom->Check( true ); break; case GR_TEXT_V_ALIGN_CENTER: m_valignCenter->Check( true ); break; case GR_TEXT_V_ALIGN_TOP: m_valignTop->Check( true ); break; } - m_mirrored->Check( m_edaText->IsMirrored() ); + m_mirrored->Check( m_item->IsMirrored() ); - EDA_ANGLE orientation = m_edaText->GetTextAngle(); + EDA_ANGLE orientation = m_item->GetTextAngle(); m_orientation.SetAngleValue( orientation.Normalize180() ); return DIALOG_TEXT_PROPERTIES_BASE::TransferDataToWindow(); @@ -395,7 +379,7 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow() if( m_SingleLineText->IsShown() ) { if( !m_SingleLineText->GetValue().IsEmpty() ) - m_edaText->SetText( m_SingleLineText->GetValue() ); + m_item->SetText( m_SingleLineText->GetValue() ); } else if( m_MultiLineText->IsShown() ) { @@ -413,7 +397,7 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow() // drawing routines so strip the \r char. txt.Replace( wxT( "\r" ), wxT( "" ) ); #endif - m_edaText->SetText( EscapeString( txt, CTX_QUOTED_STR ) ); + m_item->SetText( EscapeString( txt, CTX_QUOTED_STR ) ); } } @@ -424,52 +408,49 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow() if( m_fontCtrl->HaveFontSelection() ) { - m_edaText->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), - m_italic->IsChecked() ) ); + m_item->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), + m_italic->IsChecked() ) ); } - m_edaText->SetTextSize( VECTOR2I( m_textWidth.GetValue(), m_textHeight.GetValue() ) ); - m_edaText->SetTextThickness( m_thickness.GetValue() ); - m_edaText->SetTextPos( VECTOR2I( m_posX.GetValue(), m_posY.GetValue() ) ); - - if( m_fpText ) - m_fpText->SetLocalCoord(); + m_item->SetTextSize( VECTOR2I( m_textWidth.GetValue(), m_textHeight.GetValue() ) ); + m_item->SetTextThickness( m_thickness.GetValue() ); + m_item->SetFPRelativePosition( VECTOR2I( m_posX.GetValue(), m_posY.GetValue() ) ); // Test for acceptable values for thickness and size and clamp if fails - int maxPenWidth = Clamp_Text_PenSize( m_edaText->GetTextThickness(), m_edaText->GetTextSize() ); + int maxPenWidth = Clamp_Text_PenSize( m_item->GetTextThickness(), m_item->GetTextSize() ); - if( m_edaText->GetTextThickness() > maxPenWidth ) + if( m_item->GetTextThickness() > maxPenWidth ) { DisplayError( this, _( "The text thickness is too large for the text size.\n" "It will be clamped." ) ); - m_edaText->SetTextThickness( maxPenWidth ); + m_item->SetTextThickness( maxPenWidth ); } - m_edaText->SetTextAngle( m_orientation.GetAngleValue().Normalize() ); + m_item->SetTextAngle( m_orientation.GetAngleValue().Normalize() ); - m_edaText->SetVisible( m_Visible->GetValue() ); + m_item->SetVisible( m_Visible->GetValue() ); - if( m_fpText ) - m_fpText->SetKeepUpright( m_KeepUpright->GetValue() ); + if( m_KeepUpright->IsShown() ) + m_item->SetKeepUpright( m_KeepUpright->GetValue() ); - m_edaText->SetBold( m_bold->IsChecked() ); - m_edaText->SetItalic( m_italic->IsChecked() ); + m_item->SetBold( m_bold->IsChecked() ); + m_item->SetItalic( m_italic->IsChecked() ); if( m_alignLeft->IsChecked() ) - m_edaText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + m_item->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); else if( m_alignCenter->IsChecked() ) - m_edaText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER ); + m_item->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER ); else - m_edaText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + m_item->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); if( m_valignBottom->IsChecked() ) - m_edaText->SetVertJustify ( GR_TEXT_V_ALIGN_BOTTOM ); + m_item->SetVertJustify ( GR_TEXT_V_ALIGN_BOTTOM ); else if( m_valignCenter->IsChecked() ) - m_edaText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER ); + m_item->SetVertJustify( GR_TEXT_V_ALIGN_CENTER ); else - m_edaText->SetVertJustify( GR_TEXT_V_ALIGN_TOP ); + m_item->SetVertJustify( GR_TEXT_V_ALIGN_TOP ); - m_edaText->SetMirrored( m_mirrored->IsChecked() ); + m_item->SetMirrored( m_mirrored->IsChecked() ); if( pushCommit ) commit.Push( _( "Change text properties" ) ); diff --git a/pcbnew/dialogs/dialog_text_properties.h b/pcbnew/dialogs/dialog_text_properties.h index ea042335a9..482d47a524 100644 --- a/pcbnew/dialogs/dialog_text_properties.h +++ b/pcbnew/dialogs/dialog_text_properties.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,7 +33,6 @@ class PCB_BASE_EDIT_FRAME; class BOARD_ITEM; class EDA_TEXT; -class FP_TEXT; class PCB_TEXT; class SCINTILLA_TRICKS; @@ -41,7 +40,7 @@ class SCINTILLA_TRICKS; class DIALOG_TEXT_PROPERTIES : public DIALOG_TEXT_PROPERTIES_BASE { public: - DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BOARD_ITEM* aItem ); + DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, PCB_TEXT* aText ); ~DIALOG_TEXT_PROPERTIES(); /** @@ -64,10 +63,7 @@ private: private: PCB_BASE_EDIT_FRAME* m_frame; - BOARD_ITEM* m_item; // FP_TEXT or PCB_TEXT - EDA_TEXT* m_edaText; // always non-null - FP_TEXT* m_fpText; // only non-null for FP_TEXTs - PCB_TEXT* m_pcbText; // only non-null for PCB_TEXTs + PCB_TEXT* m_item; UNIT_BINDER m_textWidth; UNIT_BINDER m_textHeight; diff --git a/pcbnew/dialogs/dialog_textbox_properties.cpp b/pcbnew/dialogs/dialog_textbox_properties.cpp index 1a14b4529e..b25d22d73e 100644 --- a/pcbnew/dialogs/dialog_textbox_properties.cpp +++ b/pcbnew/dialogs/dialog_textbox_properties.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -41,13 +40,10 @@ #include "macros.h" DIALOG_TEXTBOX_PROPERTIES::DIALOG_TEXTBOX_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, - BOARD_ITEM* aItem ) : + PCB_TEXTBOX* aTextBox ) : DIALOG_TEXTBOX_PROPERTIES_BASE( aParent ), m_frame( aParent ), - m_item( aItem ), - m_edaText( nullptr ), - m_fpTextBox( nullptr ), - m_pcbTextBox( nullptr ), + m_textBox( aTextBox ), m_textWidth( aParent, m_SizeXLabel, m_SizeXCtrl, m_SizeXUnits ), m_textHeight( aParent, m_SizeYLabel, m_SizeYCtrl, m_SizeYUnits ), m_thickness( aParent, m_ThicknessLabel, m_ThicknessCtrl, m_ThicknessUnits ), @@ -67,23 +63,11 @@ DIALOG_TEXTBOX_PROPERTIES::DIALOG_TEXTBOX_PROPERTIES( PCB_BASE_EDIT_FRAME* aPare m_MultiLineText->SetScrollWidth( 1 ); m_MultiLineText->SetScrollWidthTracking( true ); - if( m_item->Type() == PCB_FP_TEXTBOX_T ) + if( m_textBox->GetParentFootprint() ) { - m_fpTextBox = static_cast( m_item ); - m_edaText = m_fpTextBox; - // Do not allow locking items in the footprint editor m_cbLocked->Show( false ); } - else if( m_item->Type() == PCB_TEXTBOX_T ) - { - m_pcbTextBox = static_cast( m_item ); - m_edaText = m_pcbTextBox; - } - else - { - UNIMPLEMENTED_FOR( m_item->GetClass() ); - } SetInitialFocus( m_MultiLineText ); @@ -112,7 +96,7 @@ DIALOG_TEXTBOX_PROPERTIES::DIALOG_TEXTBOX_PROPERTIES( PCB_BASE_EDIT_FRAME* aPare // Configure the layers list selector. Note that footprints are built outside the current // board and so we may need to show all layers if the text is on an unactivated layer. - if( !m_frame->GetBoard()->IsLayerEnabled( m_item->GetLayer() ) ) + if( !m_frame->GetBoard()->IsLayerEnabled( m_textBox->GetLayer() ) ) m_LayerSelectionCtrl->ShowNonActivatedLayers( true ); m_LayerSelectionCtrl->SetLayersHotkeys( false ); @@ -154,9 +138,9 @@ DIALOG_TEXTBOX_PROPERTIES::~DIALOG_TEXTBOX_PROPERTIES() } -int PCB_BASE_EDIT_FRAME::ShowTextBoxPropertiesDialog( BOARD_ITEM* aText ) +int PCB_BASE_EDIT_FRAME::ShowTextBoxPropertiesDialog( PCB_TEXTBOX* aTextBox ) { - DIALOG_TEXTBOX_PROPERTIES dlg( this, aText ); + DIALOG_TEXTBOX_PROPERTIES dlg( this, aTextBox ); return dlg.ShowQuasiModal(); } @@ -165,44 +149,38 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataToWindow() { BOARD* board = m_frame->GetBoard(); wxString converted = board->ConvertKIIDsToCrossReferences( - UnescapeString( m_edaText->GetText() ) ); + UnescapeString( m_textBox->GetText() ) ); m_MultiLineText->SetValue( converted ); m_MultiLineText->SetSelection( -1, -1 ); m_MultiLineText->EmptyUndoBuffer(); - m_cbLocked->SetValue( m_item->IsLocked() ); + m_cbLocked->SetValue( m_textBox->IsLocked() ); - m_LayerSelectionCtrl->SetLayerSelection( m_item->GetLayer() ); + m_LayerSelectionCtrl->SetLayerSelection( m_textBox->GetLayer() ); - m_fontCtrl->SetFontSelection( m_edaText->GetFont() ); + m_fontCtrl->SetFontSelection( m_textBox->GetFont() ); - m_textWidth.SetValue( m_edaText->GetTextSize().x ); - m_textHeight.SetValue( m_edaText->GetTextSize().y ); - m_thickness.SetValue( m_edaText->GetTextThickness() ); + m_textWidth.SetValue( m_textBox->GetTextSize().x ); + m_textHeight.SetValue( m_textBox->GetTextSize().y ); + m_thickness.SetValue( m_textBox->GetTextThickness() ); - m_bold->Check( m_edaText->IsBold() ); - m_italic->Check( m_edaText->IsItalic() ); + m_bold->Check( m_textBox->IsBold() ); + m_italic->Check( m_textBox->IsItalic() ); - switch ( m_edaText->GetHorizJustify() ) + switch ( m_textBox->GetHorizJustify() ) { case GR_TEXT_H_ALIGN_LEFT: m_alignLeft->Check( true ); break; case GR_TEXT_H_ALIGN_CENTER: m_alignCenter->Check( true ); break; case GR_TEXT_H_ALIGN_RIGHT: m_alignRight->Check( true ); break; } - m_mirrored->Check( m_edaText->IsMirrored() ); + m_mirrored->Check( m_textBox->IsMirrored() ); - EDA_ANGLE orientation = m_edaText->GetTextAngle(); + EDA_ANGLE orientation = m_textBox->GetTextAngle(); m_orientation.SetAngleValue( orientation.Normalize180() ); - STROKE_PARAMS stroke; - - if( m_fpTextBox ) - stroke = m_fpTextBox->GetStroke(); - else if( m_pcbTextBox ) - stroke = m_pcbTextBox->GetStroke(); - + STROKE_PARAMS stroke = m_textBox->GetStroke(); m_borderCheckbox->SetValue( stroke.GetWidth() >= 0 ); if( stroke.GetWidth() >= 0 ) @@ -282,8 +260,8 @@ void DIALOG_TEXTBOX_PROPERTIES::onBorderChecked( wxCommandEvent& event ) if( border && m_borderWidth.GetValue() <= 0 ) { - BOARD_DESIGN_SETTINGS& bds = m_item->GetBoard()->GetDesignSettings(); - m_borderWidth.SetValue( bds.GetLineThickness( m_item->GetLayer() ) ); + BOARD_DESIGN_SETTINGS& bds = m_textBox->GetBoard()->GetDesignSettings(); + m_borderWidth.SetValue( bds.GetLineThickness( m_textBox->GetLayer() ) ); } m_borderWidth.Enable( border ); @@ -304,16 +282,16 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow() } BOARD_COMMIT commit( m_frame ); - commit.Modify( m_item ); + commit.Modify( m_textBox ); // If no other command in progress, prepare undo command // (for a command in progress, will be made later, at the completion of command) - bool pushCommit = ( m_item->GetEditFlags() == 0 ); + bool pushCommit = ( m_textBox->GetEditFlags() == 0 ); // Set IN_EDIT flag to force undo/redo/abort proper operation and avoid new calls to // SaveCopyInUndoList for the same text if is moved, and then rotated, edited, etc.... if( !pushCommit ) - m_item->SetFlags( IN_EDIT ); + m_textBox->SetFlags( IN_EDIT ); BOARD* board = m_frame->GetBoard(); wxString txt = board->ConvertCrossReferencesToKIIDs( m_MultiLineText->GetValue() ); @@ -328,54 +306,43 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow() txt.Replace( "\r", "" ); #endif - m_edaText->SetText( EscapeString( txt, CTX_QUOTED_STR ) ); - - m_item->SetLocked( m_cbLocked->GetValue() ); - - m_item->SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) ); + m_textBox->SetText( EscapeString( txt, CTX_QUOTED_STR ) ); + m_textBox->SetLocked( m_cbLocked->GetValue() ); + m_textBox->SetLayer( ToLAYER_ID( m_LayerSelectionCtrl->GetLayerSelection() ) ); if( m_fontCtrl->HaveFontSelection() ) { - m_edaText->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), + m_textBox->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) ); } - m_edaText->SetTextSize( VECTOR2I( m_textWidth.GetValue(), m_textHeight.GetValue() ) ); - m_edaText->SetTextThickness( m_thickness.GetValue() ); - - if( m_fpTextBox ) - m_fpTextBox->SetLocalCoord(); + m_textBox->SetTextSize( VECTOR2I( m_textWidth.GetValue(), m_textHeight.GetValue() ) ); + m_textBox->SetTextThickness( m_thickness.GetValue() ); // Test for acceptable values for thickness and size and clamp if fails - int maxPenWidth = Clamp_Text_PenSize( m_edaText->GetTextThickness(), m_edaText->GetTextSize() ); + int maxPenWidth = Clamp_Text_PenSize( m_textBox->GetTextThickness(), m_textBox->GetTextSize() ); - if( m_edaText->GetTextThickness() > maxPenWidth ) + if( m_textBox->GetTextThickness() > maxPenWidth ) { DisplayError( this, _( "The text thickness is too large for the text size.\n" "It will be clamped." ) ); - m_edaText->SetTextThickness( maxPenWidth ); + m_textBox->SetTextThickness( maxPenWidth ); } - m_edaText->SetTextAngle( m_orientation.GetAngleValue().Normalize() ); - - m_edaText->SetBold( m_bold->IsChecked() ); - m_edaText->SetItalic( m_italic->IsChecked() ); + m_textBox->SetTextAngle( m_orientation.GetAngleValue().Normalize() ); + m_textBox->SetBold( m_bold->IsChecked() ); + m_textBox->SetItalic( m_italic->IsChecked() ); if( m_alignLeft->IsChecked() ) - m_edaText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + m_textBox->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); else if( m_alignCenter->IsChecked() ) - m_edaText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER ); + m_textBox->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER ); else - m_edaText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + m_textBox->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); - m_edaText->SetMirrored( m_mirrored->IsChecked() ); + m_textBox->SetMirrored( m_mirrored->IsChecked() ); - STROKE_PARAMS stroke; - - if( m_fpTextBox ) - stroke = m_fpTextBox->GetStroke(); - else if( m_pcbTextBox ) - stroke = m_pcbTextBox->GetStroke(); + STROKE_PARAMS stroke = m_textBox->GetStroke(); if( m_borderCheckbox->GetValue() ) { @@ -395,13 +362,10 @@ bool DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow() else stroke.SetPlotStyle( it->first ); - if( m_fpTextBox ) - m_fpTextBox->SetStroke( stroke ); - else if( m_pcbTextBox ) - m_pcbTextBox->SetStroke( stroke ); + m_textBox->SetStroke( stroke ); - m_edaText->ClearBoundingBoxCache(); - m_edaText->ClearRenderCache(); + m_textBox->ClearBoundingBoxCache(); + m_textBox->ClearRenderCache(); if( pushCommit ) commit.Push( _( "Change text box properties" ) ); diff --git a/pcbnew/dialogs/dialog_textbox_properties.h b/pcbnew/dialogs/dialog_textbox_properties.h index 9caed703c8..b60dc6c330 100644 --- a/pcbnew/dialogs/dialog_textbox_properties.h +++ b/pcbnew/dialogs/dialog_textbox_properties.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,9 +31,6 @@ class PCB_BASE_EDIT_FRAME; -class BOARD_ITEM; -class EDA_TEXT; -class FP_TEXTBOX; class PCB_TEXTBOX; class SCINTILLA_TRICKS; @@ -41,7 +38,7 @@ class SCINTILLA_TRICKS; class DIALOG_TEXTBOX_PROPERTIES : public DIALOG_TEXTBOX_PROPERTIES_BASE { public: - DIALOG_TEXTBOX_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BOARD_ITEM* aItem ); + DIALOG_TEXTBOX_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, PCB_TEXTBOX* aTextBox ); ~DIALOG_TEXTBOX_PROPERTIES(); private: @@ -57,10 +54,7 @@ private: private: PCB_BASE_EDIT_FRAME* m_frame; - BOARD_ITEM* m_item; // FP_TEXTBOX or PCB_TEXTBOX - EDA_TEXT* m_edaText; // always non-null - FP_TEXTBOX* m_fpTextBox; // only non-null for FP_TEXTBOXes - PCB_TEXTBOX* m_pcbTextBox; // only non-null for PCB_TEXTBOXes + PCB_TEXTBOX* m_textBox; UNIT_BINDER m_textWidth; UNIT_BINDER m_textHeight; diff --git a/pcbnew/dialogs/panel_setup_formatting.cpp b/pcbnew/dialogs/panel_setup_formatting.cpp index 537a1775f4..e7dd0921d4 100644 --- a/pcbnew/dialogs/panel_setup_formatting.cpp +++ b/pcbnew/dialogs/panel_setup_formatting.cpp @@ -72,24 +72,11 @@ bool PANEL_SETUP_FORMATTING::TransferDataFromWindow() view->GetPainter()->GetSettings()->SetDashLengthRatio( settings.GetDashedLineDashRatio() ); view->GetPainter()->GetSettings()->SetGapLengthRatio( settings.GetDashedLineGapRatio() ); - view->UpdateAllItemsConditionally( KIGFX::REPAINT, [] ( KIGFX::VIEW_ITEM* aItem ) -> bool + view->UpdateAllItemsConditionally( KIGFX::REPAINT, + [] ( KIGFX::VIEW_ITEM* aItem ) -> bool { - - const EDA_ITEM* item = dynamic_cast( aItem ); - - if( !item ) - return false; - - switch( item->Type() ) - { - case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: - return true; - - default: - return false; - } - + const EDA_ITEM* item = dynamic_cast( aItem ); + return item && item->Type() == PCB_SHAPE_T; } ); m_frame->GetCanvas()->Refresh(); diff --git a/pcbnew/drc/drc_cache_generator.cpp b/pcbnew/drc/drc_cache_generator.cpp index c0f903dd03..39b1337256 100644 --- a/pcbnew/drc/drc_cache_generator.cpp +++ b/pcbnew/drc/drc_cache_generator.cpp @@ -136,8 +136,8 @@ bool DRC_CACHE_GENERATOR::Run() static const std::vector itemTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, - PCB_SHAPE_T, PCB_FP_SHAPE_T, - PCB_TEXT_T, PCB_FP_TEXT_T, PCB_TEXTBOX_T, PCB_FP_TEXTBOX_T, + PCB_SHAPE_T, + PCB_TEXT_T, PCB_TEXTBOX_T, PCB_DIMENSION_T }; diff --git a/pcbnew/drc/drc_engine.cpp b/pcbnew/drc/drc_engine.cpp index df310c1fa8..1d3ac08666 100644 --- a/pcbnew/drc/drc_engine.cpp +++ b/pcbnew/drc/drc_engine.cpp @@ -98,10 +98,7 @@ DRC_ENGINE::~DRC_ENGINE() static bool isKeepoutZone( const BOARD_ITEM* aItem, bool aCheckFlags ) { - if( !aItem ) - return false; - - if( aItem->Type() != PCB_ZONE_T && aItem->Type() != PCB_FP_ZONE_T ) + if( !aItem || aItem->Type() != PCB_ZONE_T ) return false; const ZONE* zone = static_cast( aItem ); @@ -693,16 +690,16 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRules( DRC_CONSTRAINT_T aConstraintType, const BO { if( a && a->Type() == PCB_PAD_T ) pad = static_cast( a ); - else if( a && ( a->Type() == PCB_ZONE_T || a->Type() == PCB_FP_ZONE_T ) ) + else if( a && a->Type() == PCB_ZONE_T ) zone = static_cast( a ); if( b && b->Type() == PCB_PAD_T ) pad = static_cast( b ); - else if( b && ( b->Type() == PCB_ZONE_T || b->Type() == PCB_FP_ZONE_T ) ) + else if( b && b->Type() == PCB_ZONE_T ) zone = static_cast( b ); if( pad ) - parentFootprint = static_cast( pad->GetParentFootprint() ); + parentFootprint = pad->GetParentFootprint(); } DRC_CONSTRAINT constraint; @@ -1112,24 +1109,17 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRules( DRC_CONSTRAINT_T aConstraintType, const BO case PCB_PAD_T: mask = DRC_DISALLOW_PADS; break; case PCB_FOOTPRINT_T: mask = DRC_DISALLOW_FOOTPRINTS; break; case PCB_SHAPE_T: mask = DRC_DISALLOW_GRAPHICS; break; - case PCB_FP_SHAPE_T: mask = DRC_DISALLOW_GRAPHICS; break; case PCB_TEXT_T: mask = DRC_DISALLOW_TEXTS; break; case PCB_TEXTBOX_T: mask = DRC_DISALLOW_TEXTS; break; - case PCB_FP_TEXT_T: mask = DRC_DISALLOW_TEXTS; break; - case PCB_FP_TEXTBOX_T: mask = DRC_DISALLOW_TEXTS; break; - case PCB_ZONE_T: - case PCB_FP_ZONE_T: - { - const ZONE* test_zone = static_cast( a ); + case PCB_ZONE_T: // Treat teardrop areas as tracks for DRC purposes - if( test_zone->IsTeardropArea() ) + if( static_cast( a )->IsTeardropArea() ) mask = DRC_DISALLOW_TRACKS; else mask = DRC_DISALLOW_ZONES; break; - } case PCB_LOCATE_HOLE_T: mask = DRC_DISALLOW_HOLES; break; default: mask = 0; break; @@ -1775,7 +1765,7 @@ bool DRC_ENGINE::IsNetADiffPair( BOARD* aBoard, NETINFO_ITEM* aNet, int& aNetP, bool DRC_ENGINE::IsNetTieExclusion( int aTrackNetCode, PCB_LAYER_ID aTrackLayer, const VECTOR2I& aCollisionPos, BOARD_ITEM* aCollidingItem ) { - FOOTPRINT* parentFootprint = static_cast( aCollidingItem->GetParentFootprint() ); + FOOTPRINT* parentFootprint = aCollidingItem->GetParentFootprint(); if( parentFootprint && parentFootprint->IsNetTie() ) { diff --git a/pcbnew/drc/drc_rtree.h b/pcbnew/drc/drc_rtree.h index 9568b34ced..ac1c00ec59 100644 --- a/pcbnew/drc/drc_rtree.h +++ b/pcbnew/drc/drc_rtree.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include @@ -115,7 +115,7 @@ public: { wxCHECK( aTargetLayer != UNDEFINED_LAYER, /* void */ ); - if( aItem->Type() == PCB_FP_TEXT_T && !static_cast( aItem )->IsVisible() ) + if( aItem->Type() == PCB_TEXT_T && !static_cast( aItem )->IsVisible() ) return; std::vector subshapes; diff --git a/pcbnew/drc/drc_test_provider.cpp b/pcbnew/drc/drc_test_provider.cpp index e231111d9b..e416a3e979 100644 --- a/pcbnew/drc/drc_test_provider.cpp +++ b/pcbnew/drc/drc_test_provider.cpp @@ -60,7 +60,7 @@ void DRC_TEST_PROVIDER::Init() { s_allBasicItems.push_back( (KICAD_T) i ); - if( i != PCB_ZONE_T && i != PCB_FP_ZONE_T ) + if( i != PCB_ZONE_T ) s_allBasicItemsButZones.push_back( (KICAD_T) i ); } } @@ -247,7 +247,7 @@ int DRC_TEST_PROVIDER::forEachGeometryItem( const std::vector& aTypes, for( FOOTPRINT* footprint : brd->Footprints() ) { - if( typeMask[ PCB_FP_TEXT_T ] ) + if( typeMask[ PCB_TEXT_T ] ) { if( ( footprint->Reference().GetLayerSet() & aLayers ).any() ) { @@ -292,21 +292,21 @@ int DRC_TEST_PROVIDER::forEachGeometryItem( const std::vector& aTypes, n++; } - else if( typeMask[ PCB_FP_TEXT_T ] && dwg->Type() == PCB_FP_TEXT_T ) + else if( typeMask[ PCB_TEXT_T ] && dwg->Type() == PCB_TEXT_T ) { if( !aFunc( dwg ) ) return n; n++; } - else if( typeMask[ PCB_FP_TEXTBOX_T ] && dwg->Type() == PCB_FP_TEXTBOX_T ) + else if( typeMask[ PCB_TEXTBOX_T ] && dwg->Type() == PCB_TEXTBOX_T ) { if( !aFunc( dwg ) ) return n; n++; } - else if( typeMask[ PCB_FP_SHAPE_T ] && dwg->Type() == PCB_FP_SHAPE_T ) + else if( typeMask[ PCB_SHAPE_T ] && dwg->Type() == PCB_SHAPE_T ) { if( !aFunc( dwg ) ) return n; @@ -316,7 +316,7 @@ int DRC_TEST_PROVIDER::forEachGeometryItem( const std::vector& aTypes, } } - if( typeMask[ PCB_FP_ZONE_T ] ) + if( typeMask[ PCB_ZONE_T ] ) { for( ZONE* zone : footprint->Zones() ) { @@ -345,13 +345,6 @@ int DRC_TEST_PROVIDER::forEachGeometryItem( const std::vector& aTypes, bool DRC_TEST_PROVIDER::isInvisibleText( const BOARD_ITEM* aItem ) const { - - if( const FP_TEXT* text = dyn_cast( aItem ) ) - { - if( !text->IsVisible() ) - return true; - } - if( const PCB_TEXT* text = dyn_cast( aItem ) ) { if( !text->IsVisible() ) diff --git a/pcbnew/drc/drc_test_provider_copper_clearance.cpp b/pcbnew/drc/drc_test_provider_copper_clearance.cpp index 13ff0593b3..5028a93be6 100644 --- a/pcbnew/drc/drc_test_provider_copper_clearance.cpp +++ b/pcbnew/drc/drc_test_provider_copper_clearance.cpp @@ -551,7 +551,7 @@ bool DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem( PAD* pad, SHAPE* pa // Disable some tests for net-tie objects in a footprint if( other->GetParent() == pad->GetParent() ) { - FOOTPRINT* fp = static_cast( pad->GetParent() ); + FOOTPRINT* fp = pad->GetParentFootprint(); std::map padToNetTieGroupMap = fp->MapPadNumbersToNetTieGroups(); int padGroupIdx = padToNetTieGroupMap[ pad->GetNumber() ]; @@ -566,7 +566,7 @@ bool DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem( PAD* pad, SHAPE* pa testHoles = false; } - if( other->Type() == PCB_FP_SHAPE_T && padGroupIdx >= 0 ) + if( other->Type() == PCB_SHAPE_T && padGroupIdx >= 0 ) testClearance = false; } diff --git a/pcbnew/drc/drc_test_provider_edge_clearance.cpp b/pcbnew/drc/drc_test_provider_edge_clearance.cpp index 7e631dfe5c..d3834ae70c 100644 --- a/pcbnew/drc/drc_test_provider_edge_clearance.cpp +++ b/pcbnew/drc/drc_test_provider_edge_clearance.cpp @@ -175,7 +175,7 @@ bool DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run() std::vector> edges; DRC_RTREE edgesTree; - forEachGeometryItem( { PCB_SHAPE_T, PCB_FP_SHAPE_T }, LSET( 2, Edge_Cuts, Margin ), + forEachGeometryItem( { PCB_SHAPE_T }, LSET( 2, Edge_Cuts, Margin ), [&]( BOARD_ITEM *item ) -> bool { PCB_SHAPE* shape = static_cast( item ); diff --git a/pcbnew/drc/drc_test_provider_library_parity.cpp b/pcbnew/drc/drc_test_provider_library_parity.cpp index 5bb03d379b..ceaa61fb8d 100644 --- a/pcbnew/drc/drc_test_provider_library_parity.cpp +++ b/pcbnew/drc/drc_test_provider_library_parity.cpp @@ -26,8 +26,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -266,7 +265,7 @@ bool padHasOverrides( const PAD* a, const PAD* b ) } -bool shapeNeedsUpdate( const FP_SHAPE* a, const FP_SHAPE* b ) +bool shapeNeedsUpdate( const PCB_SHAPE* a, const PCB_SHAPE* b ) { REPORTER* aReporter = nullptr; bool diff = false; @@ -278,26 +277,26 @@ bool shapeNeedsUpdate( const FP_SHAPE* a, const FP_SHAPE* b ) case SHAPE_T::SEGMENT: case SHAPE_T::RECT: case SHAPE_T::CIRCLE: - TEST( a->GetStart0(), b->GetStart0(), "" ); - TEST( a->GetEnd0(), b->GetEnd0(), "" ); + TEST( a->GetStart(), b->GetStart(), "" ); + TEST( a->GetEnd(), b->GetEnd(), "" ); break; case SHAPE_T::ARC: - TEST( a->GetStart0(), b->GetStart0(), "" ); - TEST( a->GetEnd0(), b->GetEnd0(), "" ); + TEST( a->GetStart(), b->GetStart(), "" ); + TEST( a->GetEnd(), b->GetEnd(), "" ); // Arc center is calculated and so may have round-off errors when parents are // differentially rotated. - if( ( a->GetCenter0() - b->GetCenter0() ).EuclideanNorm() > pcbIUScale.mmToIU( 0.0001 ) ) + if( ( a->GetCenter() - b->GetCenter() ).EuclideanNorm() > pcbIUScale.mmToIU( 0.0001 ) ) return true; break; case SHAPE_T::BEZIER: - TEST( a->GetStart0(), b->GetStart0(), "" ); - TEST( a->GetEnd0(), b->GetEnd0(), "" ); - TEST( a->GetBezierC1_0(), b->GetBezierC1_0(), "" ); - TEST( a->GetBezierC2_0(), b->GetBezierC2_0(), "" ); + TEST( a->GetStart(), b->GetStart(), "" ); + TEST( a->GetEnd(), b->GetEnd(), "" ); + TEST( a->GetBezierC1(), b->GetBezierC1(), "" ); + TEST( a->GetBezierC2(), b->GetBezierC2(), "" ); break; case SHAPE_T::POLY: @@ -321,7 +320,7 @@ bool shapeNeedsUpdate( const FP_SHAPE* a, const FP_SHAPE* b ) } -bool textNeedsUpdate( const FP_TEXT* a, const FP_TEXT* b ) +bool textNeedsUpdate( const PCB_TEXT* a, const PCB_TEXT* b ) { REPORTER* aReporter = nullptr; bool diff = false; @@ -342,13 +341,13 @@ bool textNeedsUpdate( const FP_TEXT* a, const FP_TEXT* b ) TEST( a->GetVertJustify(), b->GetVertJustify(), "" ); TEST( a->GetTextSize(), b->GetTextSize(), "" ); - TEST( a->GetPos0(), b->GetPos0(), "" ); + TEST( a->GetFPRelativePosition(), b->GetFPRelativePosition(), "" ); return diff; } -bool zoneNeedsUpdate( const FP_ZONE* a, const FP_ZONE* b, REPORTER* aReporter ) +bool zoneNeedsUpdate( const ZONE* a, const ZONE* b, REPORTER* aReporter ) { bool diff = false; @@ -539,14 +538,14 @@ bool FOOTPRINT::FootprintNeedsUpdate( const FOOTPRINT* aLibFootprint, REPORTER* std::inserter( aShapes, aShapes.begin() ), []( BOARD_ITEM* item ) { - return item->Type() == PCB_FP_SHAPE_T; + return item->Type() == PCB_SHAPE_T; } ); std::set bShapes; std::copy_if( aLibFootprint->GraphicalItems().begin(), aLibFootprint->GraphicalItems().end(), std::inserter( bShapes, bShapes.begin() ), []( BOARD_ITEM* item ) { - return item->Type() == PCB_FP_SHAPE_T; + return item->Type() == PCB_SHAPE_T; } ); if( aShapes.size() != bShapes.size() ) @@ -558,9 +557,9 @@ bool FOOTPRINT::FootprintNeedsUpdate( const FOOTPRINT* aLibFootprint, REPORTER* { for( auto aIt = aShapes.begin(), bIt = bShapes.begin(); aIt != aShapes.end(); aIt++, bIt++ ) { - if( ( *aIt )->Type() == PCB_FP_SHAPE_T ) + if( ( *aIt )->Type() == PCB_SHAPE_T ) { - if( shapeNeedsUpdate( static_cast( *aIt ), static_cast( *bIt ) ) ) + if( shapeNeedsUpdate( static_cast( *aIt ), static_cast( *bIt ) ) ) { diff = true; REPORT( wxString::Format( _( "%s differs." ), ITEM_DESC( *aIt ) ) ); @@ -617,8 +616,8 @@ bool FOOTPRINT::FootprintNeedsUpdate( const FOOTPRINT* aLibFootprint, REPORTER* libCopy->SetOrientation( GetOrientation() ); libCopy->Move( GetPosition() ); - std::set aZones( Zones().begin(), Zones().end() ); - std::set bZones( libCopy->Zones().begin(), libCopy->Zones().end() ); + std::set aZones( Zones().begin(), Zones().end() ); + std::set bZones( libCopy->Zones().begin(), libCopy->Zones().end() ); if( aZones.size() != bZones.size() ) { diff --git a/pcbnew/drc/drc_test_provider_misc.cpp b/pcbnew/drc/drc_test_provider_misc.cpp index 30e7d1d3db..e0fc4c5592 100644 --- a/pcbnew/drc/drc_test_provider_misc.cpp +++ b/pcbnew/drc/drc_test_provider_misc.cpp @@ -178,7 +178,7 @@ void DRC_TEST_PROVIDER_MISC::testDisabledLayers() else if( disabledLayers.test( bottom ) ) badLayer = bottom; } - else if( item->Type() == PCB_FP_ZONE_T ) + else if( item->Type() == PCB_ZONE_T ) { // Footprint zones just get a top/bottom/inner setting, so they're on // whatever inner layers there are. @@ -260,7 +260,8 @@ void DRC_TEST_PROVIDER_MISC::testTextVars() int items = 0; static const std::vector itemTypes = { - PCB_TEXT_T, PCB_FP_TEXT_T, PCB_TEXTBOX_T, PCB_FP_TEXTBOX_T, + PCB_TEXT_T, + PCB_TEXTBOX_T, PCB_DIMENSION_T }; diff --git a/pcbnew/drc/drc_test_provider_physical_clearance.cpp b/pcbnew/drc/drc_test_provider_physical_clearance.cpp index 2f94611ade..42f8384009 100644 --- a/pcbnew/drc/drc_test_provider_physical_clearance.cpp +++ b/pcbnew/drc/drc_test_provider_physical_clearance.cpp @@ -112,8 +112,8 @@ bool DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run() PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_FOOTPRINT_T, PCB_PAD_T, - PCB_SHAPE_T, PCB_FP_SHAPE_T, - PCB_TEXT_T, PCB_FP_TEXT_T, PCB_TEXTBOX_T, PCB_FP_TEXTBOX_T, + PCB_SHAPE_T, + PCB_TEXT_T, PCB_TEXTBOX_T, PCB_DIMENSION_T }; @@ -259,7 +259,7 @@ bool DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run() // Generate a count for progress reporting. // - forEachGeometryItem( { PCB_ZONE_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_FP_SHAPE_T }, + forEachGeometryItem( { PCB_ZONE_T, PCB_SHAPE_T }, LSET::AllCuMask(), [&]( BOARD_ITEM* item ) -> bool { @@ -277,7 +277,7 @@ bool DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run() // Run clearance checks -within- polygonal items. // - forEachGeometryItem( { PCB_ZONE_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_FP_SHAPE_T }, + forEachGeometryItem( { PCB_ZONE_T, PCB_SHAPE_T }, LSET::AllCuMask(), [&]( BOARD_ITEM* item ) -> bool { @@ -512,8 +512,11 @@ void DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testShapeLineChain( const SHAPE_LINE_ std::shared_ptr drce = DRC_ITEM::Create( DRCE_CLEARANCE ); VECTOR2I pt = collision.first; - if( aParentItem->GetParentFootprint() ) - pt += aParentItem->GetParentFootprint()->GetPosition(); + if( FOOTPRINT* parentFP = aParentItem->GetParentFootprint() ) + { + RotatePoint( pt, parentFP->GetOrientation() ); + pt += parentFP->GetPosition(); + } wxString msg = formatMsg( _( "Internal clearance violation (%s clearance %s; actual %s)" ), aConstraint.GetName(), @@ -644,7 +647,6 @@ int DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstItem( BOARD_ITEM* aItem if( aItem->Type() == PCB_VIA_T ) { - wxCHECK_MSG( aItem->GetLayerSet().Contains( aLayer ), violations, wxT( "Bug! Vias should only be checked for layers on which they exist" ) ); diff --git a/pcbnew/drc/drc_test_provider_silk_clearance.cpp b/pcbnew/drc/drc_test_provider_silk_clearance.cpp index 5a64cc98f7..d9868e58a0 100644 --- a/pcbnew/drc/drc_test_provider_silk_clearance.cpp +++ b/pcbnew/drc/drc_test_provider_silk_clearance.cpp @@ -220,12 +220,8 @@ bool DRC_TEST_PROVIDER_SILK_CLEARANCE::Run() VECTOR2I pos; // Graphics are often compound shapes so ignore collisions between shapes in a - // single footprint or on the board. - if( refItem->Type() == PCB_SHAPE_T && testItem->Type() == PCB_SHAPE_T ) - { - return true; - } - else if( refItem->Type() == PCB_FP_SHAPE_T && testItem->Type() == PCB_FP_SHAPE_T + // single footprint or on the board (both parent footprints will be nullptr). + if( refItem->Type() == PCB_SHAPE_T && testItem->Type() == PCB_SHAPE_T && refItem->GetParentFootprint() == testItem->GetParentFootprint() ) { return true; diff --git a/pcbnew/drc/drc_test_provider_solder_mask.cpp b/pcbnew/drc/drc_test_provider_solder_mask.cpp index 295a4aaf8a..186f129c12 100644 --- a/pcbnew/drc/drc_test_provider_solder_mask.cpp +++ b/pcbnew/drc/drc_test_provider_solder_mask.cpp @@ -114,7 +114,7 @@ void DRC_TEST_PROVIDER_SOLDER_MASK::addItemToRTrees( BOARD_ITEM* aItem ) { ZONE* solderMask = m_board->m_SolderMask; - if( aItem->Type() == PCB_ZONE_T || aItem->Type() == PCB_FP_ZONE_T ) + if( aItem->Type() == PCB_ZONE_T ) { ZONE* zone = static_cast( aItem ); @@ -174,21 +174,6 @@ void DRC_TEST_PROVIDER_SOLDER_MASK::addItemToRTrees( BOARD_ITEM* aItem ) } } } - else if( aItem->Type() == PCB_FP_TEXT_T ) - { - for( PCB_LAYER_ID layer : { F_Mask, B_Mask } ) - { - if( aItem->IsOnLayer( layer ) ) - { - const FP_TEXT* text = static_cast( aItem ); - - text->TransformTextToPolySet( *solderMask->GetFill( layer ), layer, - m_webWidth / 2, m_maxError, ERROR_OUTSIDE ); - - m_itemTree->Insert( aItem, layer, m_largestClearance ); - } - } - } else { for( PCB_LAYER_ID layer : { F_Mask, B_Mask } ) @@ -379,7 +364,7 @@ bool DRC_TEST_PROVIDER_SOLDER_MASK::checkMaskAperture( BOARD_ITEM* aMaskItem, BO if( aTestLayer == B_Mask && !aTestItem->IsOnLayer( B_Cu ) ) return false; - FOOTPRINT* fp = static_cast( aMaskItem->GetParentFootprint() ); + FOOTPRINT* fp = aMaskItem->GetParentFootprint(); if( fp && ( fp->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES ) > 0 ) { @@ -421,7 +406,7 @@ bool DRC_TEST_PROVIDER_SOLDER_MASK::checkMaskAperture( BOARD_ITEM* aMaskItem, BO bool DRC_TEST_PROVIDER_SOLDER_MASK::checkItemMask( BOARD_ITEM* aMaskItem, int aTestNet ) { - FOOTPRINT* fp = static_cast( aMaskItem->GetParentFootprint() ); + FOOTPRINT* fp = aMaskItem->GetParentFootprint(); wxCHECK( fp, false ); @@ -463,7 +448,7 @@ void DRC_TEST_PROVIDER_SOLDER_MASK::testItemAgainstItems( BOARD_ITEM* aItem, con // Filter: [&]( BOARD_ITEM* other ) -> bool { - FOOTPRINT* itemFP = static_cast( aItem->GetParentFootprint() ); + FOOTPRINT* itemFP = aItem->GetParentFootprint(); PAD* otherPad = dynamic_cast( other ); int otherNet = -1; diff --git a/pcbnew/drc/drc_test_provider_text_dims.cpp b/pcbnew/drc/drc_test_provider_text_dims.cpp index 50c1fcd8a7..607788886f 100644 --- a/pcbnew/drc/drc_test_provider_text_dims.cpp +++ b/pcbnew/drc/drc_test_provider_text_dims.cpp @@ -24,8 +24,6 @@ #include #include #include -#include -#include #include #include #include @@ -255,8 +253,7 @@ bool DRC_TEST_PROVIDER_TEXT_DIMS::Run() return true; }; - static const std::vector itemTypes = { PCB_TEXT_T, PCB_FP_TEXT_T, - PCB_TEXTBOX_T, PCB_FP_TEXTBOX_T }; + static const std::vector itemTypes = { PCB_TEXT_T, PCB_TEXTBOX_T }; forEachGeometryItem( itemTypes, LSET::AllLayersMask(), [&]( BOARD_ITEM* item ) -> bool @@ -276,11 +273,9 @@ bool DRC_TEST_PROVIDER_TEXT_DIMS::Run() switch( item->Type() ) { - case PCB_TEXT_T: text = static_cast( item ); break; - case PCB_TEXTBOX_T: text = static_cast( item ); break; - case PCB_FP_TEXT_T: text = static_cast( item ); break; - case PCB_FP_TEXTBOX_T: text = static_cast( item ); break; - default: UNIMPLEMENTED_FOR( item->GetClass() ); break; + case PCB_TEXT_T: text = static_cast( item ); break; + case PCB_TEXTBOX_T: text = static_cast( item ); break; + default: UNIMPLEMENTED_FOR( item->GetClass() ); break; } if( !text || !text->IsVisible() ) diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 9ac0874c2f..189f0a2365 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #include #include @@ -124,13 +126,11 @@ void PCB_EDIT_FRAME::OnEditItemRequest( BOARD_ITEM* aItem ) break; case PCB_TEXT_T: - case PCB_FP_TEXT_T: - ShowTextPropertiesDialog( aItem ); + ShowTextPropertiesDialog( static_cast( aItem ) ); break; case PCB_TEXTBOX_T: - case PCB_FP_TEXTBOX_T: - ShowTextBoxPropertiesDialog( aItem ); + ShowTextBoxPropertiesDialog( static_cast( aItem ) ); break; case PCB_PAD_T: @@ -157,7 +157,7 @@ void PCB_EDIT_FRAME::OnEditItemRequest( BOARD_ITEM* aItem ) } case PCB_SHAPE_T: - ShowGraphicItemPropertiesDialog( aItem ); + ShowGraphicItemPropertiesDialog( static_cast( aItem ) ); break; case PCB_ZONE_T: diff --git a/pcbnew/exporters/export_gencad.cpp b/pcbnew/exporters/export_gencad.cpp index dcde63d337..92c99e786d 100644 --- a/pcbnew/exporters/export_gencad.cpp +++ b/pcbnew/exporters/export_gencad.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2016 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2012 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -49,7 +49,6 @@ #include // LAST_PATH_TYPE #include -#include static bool CreateHeaderInfoData( FILE* aFile, PCB_EDIT_FRAME* frame ); static void CreateArtworksSection( FILE* aFile ); @@ -891,24 +890,25 @@ static void CreateComponentsSection( FILE* aFile, BOARD* aPcb ) mirror, flip ); // Text on silk layer: RefDes and value (are they actually useful?) - for( FP_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } ) + for( PCB_TEXT* textItem : { &footprint->Reference(), &footprint->Value() } ) { std::string layer = GenCADLayerName( cu_count, footprint->GetFlag() ? B_SilkS : F_SilkS ); fprintf( aFile, "TEXT %g %g %g %g %s %s \"%s\"", - textItem->GetPos0().x / SCALE_FACTOR, - -textItem->GetPos0().y / SCALE_FACTOR, + textItem->GetFPRelativePosition().x / SCALE_FACTOR, + -textItem->GetFPRelativePosition().y / SCALE_FACTOR, textItem->GetTextWidth() / SCALE_FACTOR, textItem->GetTextAngle().AsDegrees(), mirror, layer.c_str(), TO_UTF8( escapeString( textItem->GetText() ) ) ); - // Please note, the width is approx + BOX2I textBox = textItem->GetTextBox(); + fprintf( aFile, " 0 0 %g %g\n", - ( textItem->GetTextWidth() * textItem->GetLength() ) / SCALE_FACTOR, - textItem->GetTextHeight() / SCALE_FACTOR ); + textBox.GetWidth() / SCALE_FACTOR, + textBox.GetHeight() / SCALE_FACTOR ); } // The SHEET is a 'generic description' for referencing the component @@ -1197,8 +1197,6 @@ static void CreateTracksInfoData( FILE* aFile, BOARD* aPcb ) */ static void FootprintWriteShape( FILE* aFile, FOOTPRINT* aFootprint, const wxString& aShapeName ) { - FP_SHAPE* shape; - /* creates header: */ fprintf( aFile, "\nSHAPE \"%s\"\n", TO_UTF8( escapeString( aShapeName ) ) ); @@ -1211,99 +1209,85 @@ static void FootprintWriteShape( FILE* aFile, FOOTPRINT* aFootprint, const wxStr // CAM350 read it right but only closed shapes // ProntoPlace double-flip it (at least the pads are correct) // GerberTool usually get it right... - for( BOARD_ITEM* PtStruct : aFootprint->GraphicalItems() ) + for( BOARD_ITEM* item : aFootprint->GraphicalItems() ) { - switch( PtStruct->Type() ) + if( item->Type() == PCB_SHAPE_T + && ( item->GetLayer() == F_SilkS || item->GetLayer() == B_SilkS ) ) { - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: + PCB_SHAPE* shape = static_cast( item ); + VECTOR2I start = shape->GetStart() - aFootprint->GetPosition(); + VECTOR2I end = shape->GetEnd() - aFootprint->GetPosition(); + VECTOR2I center = shape->GetCenter() - aFootprint->GetPosition(); - // If we wanted to export text, this is not the correct section - break; + RotatePoint( start, -aFootprint->GetOrientation() ); + RotatePoint( end, -aFootprint->GetOrientation() ); + RotatePoint( center, -aFootprint->GetOrientation() ); - case PCB_FP_SHAPE_T: - shape = (FP_SHAPE*) PtStruct; - - if( shape->GetLayer() == F_SilkS || shape->GetLayer() == B_SilkS ) + switch( shape->GetShape() ) { - switch( shape->GetShape() ) - { - case SHAPE_T::SEGMENT: - fprintf( aFile, "LINE %g %g %g %g\n", - shape->GetStart0().x / SCALE_FACTOR, - -shape->GetStart0().y / SCALE_FACTOR, - shape->GetEnd0().x / SCALE_FACTOR, - -shape->GetEnd0().y / SCALE_FACTOR ); - break; + case SHAPE_T::SEGMENT: + fprintf( aFile, "LINE %g %g %g %g\n", + start.x / SCALE_FACTOR, + -start.y / SCALE_FACTOR, + end.x / SCALE_FACTOR, + -end.y / SCALE_FACTOR ); + break; - case SHAPE_T::RECT: - { - fprintf( aFile, "LINE %g %g %g %g\n", - shape->GetStart0().x / SCALE_FACTOR, - -shape->GetStart0().y / SCALE_FACTOR, - shape->GetEnd0().x / SCALE_FACTOR, - -shape->GetStart0().y / SCALE_FACTOR ); - fprintf( aFile, "LINE %g %g %g %g\n", - shape->GetEnd0().x / SCALE_FACTOR, - -shape->GetStart0().y / SCALE_FACTOR, - shape->GetEnd0().x / SCALE_FACTOR, - -shape->GetEnd0().y / SCALE_FACTOR ); - fprintf( aFile, "LINE %g %g %g %g\n", - shape->GetEnd0().x / SCALE_FACTOR, - -shape->GetEnd0().y / SCALE_FACTOR, - shape->GetStart0().x / SCALE_FACTOR, - -shape->GetEnd0().y / SCALE_FACTOR ); - fprintf( aFile, "LINE %g %g %g %g\n", - shape->GetStart0().x / SCALE_FACTOR, - -shape->GetEnd0().y / SCALE_FACTOR, - shape->GetStart0().x / SCALE_FACTOR, - -shape->GetStart0().y / SCALE_FACTOR ); - } - break; + case SHAPE_T::RECT: + fprintf( aFile, "LINE %g %g %g %g\n", + start.x / SCALE_FACTOR, + -start.y / SCALE_FACTOR, + end.x / SCALE_FACTOR, + -end.y / SCALE_FACTOR ); + fprintf( aFile, "LINE %g %g %g %g\n", + end.x / SCALE_FACTOR, + -start.y / SCALE_FACTOR, + end.x / SCALE_FACTOR, + -end.y / SCALE_FACTOR ); + fprintf( aFile, "LINE %g %g %g %g\n", + end.x / SCALE_FACTOR, + -end.y / SCALE_FACTOR, + start.x / SCALE_FACTOR, + -end.y / SCALE_FACTOR ); + fprintf( aFile, "LINE %g %g %g %g\n", + start.x / SCALE_FACTOR, + -end.y / SCALE_FACTOR, + start.x / SCALE_FACTOR, + -start.y / SCALE_FACTOR ); + break; - case SHAPE_T::CIRCLE: - { - int radius = KiROUND( GetLineLength( shape->GetEnd0(), shape->GetStart0() ) ); + case SHAPE_T::CIRCLE: + { + int radius = KiROUND( GetLineLength( end, start ) ); - fprintf( aFile, "CIRCLE %g %g %g\n", - shape->GetStart0().x / SCALE_FACTOR, - -shape->GetStart0().y / SCALE_FACTOR, - radius / SCALE_FACTOR ); - break; - } - - case SHAPE_T::ARC: - { - VECTOR2I start = shape->GetStart0(); - VECTOR2I end = shape->GetEnd0(); - - if( shape->GetArcAngle() > ANGLE_0 ) - std::swap( start, end ); - - fprintf( aFile, "ARC %g %g %g %g %g %g\n", - start.x / SCALE_FACTOR, - -start.y / SCALE_FACTOR, - end.x / SCALE_FACTOR, - -end.y / SCALE_FACTOR, - shape->GetCenter0().x / SCALE_FACTOR, - -shape->GetCenter0().y / SCALE_FACTOR ); - } - break; - - case SHAPE_T::POLY: - // Not exported (TODO) - break; - - default: - wxFAIL_MSG( wxString::Format( wxT( "Type Edge Module %d invalid." ), - PtStruct->Type() ) ); - break; - } + fprintf( aFile, "CIRCLE %g %g %g\n", + start.x / SCALE_FACTOR, + -start.y / SCALE_FACTOR, + radius / SCALE_FACTOR ); + break; } - break; - default: - break; + case SHAPE_T::ARC: + if( shape->GetArcAngle() > ANGLE_0 ) + std::swap( start, end ); + + fprintf( aFile, "ARC %g %g %g %g %g %g\n", + start.x / SCALE_FACTOR, + -start.y / SCALE_FACTOR, + end.x / SCALE_FACTOR, + -end.y / SCALE_FACTOR, + center.x / SCALE_FACTOR, + -center.y / SCALE_FACTOR ); + break; + + case SHAPE_T::POLY: + // Not exported (TODO) + break; + + default: + wxFAIL_MSG( wxString::Format( wxT( "Shape type %d invalid." ), item->Type() ) ); + break; + } } } } diff --git a/pcbnew/exporters/export_idf.cpp b/pcbnew/exporters/export_idf.cpp index b138fef437..8b1619824b 100644 --- a/pcbnew/exporters/export_idf.cpp +++ b/pcbnew/exporters/export_idf.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 Cirilo Bernardo - * Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,9 +31,9 @@ #include #include #include -#include #include #include +#include #include #include #include "project.h" @@ -59,12 +59,9 @@ static FILENAME_RESOLVER* resolver; static void idf_export_outline( BOARD* aPcb, IDF3_BOARD& aIDFBoard ) { double scale = aIDFBoard.GetUserScale(); - - PCB_SHAPE* graphic; // KiCad graphical item IDF_POINT sp, ep; // start and end points from KiCad item - std::list< IDF_SEGMENT* > lines; // IDF intermediate form of KiCad graphical item - IDF_OUTLINE* outline = nullptr; // graphical items forming an outline or cutout + IDF_OUTLINE* outline = nullptr; // graphical items forming an outline or cutout // NOTE: IMPLEMENTATION // If/when component cutouts are allowed, we must implement them separately. Cutouts @@ -80,7 +77,7 @@ static void idf_export_outline( BOARD* aPcb, IDF3_BOARD& aIDFBoard ) if( item->Type() != PCB_SHAPE_T || item->GetLayer() != Edge_Cuts ) continue; - graphic = (PCB_SHAPE*) item; + PCB_SHAPE* graphic = static_cast( item ); switch( graphic->GetShape() ) { @@ -311,7 +308,7 @@ static void idf_export_footprint( BOARD* aPcb, FOOTPRINT* aFootprint, IDF3_BOARD // TODO: If footprint cutouts are supported we must add code here // for( EDA_ITEM* item = aFootprint->GraphicalItems(); item != NULL; item = item->Next() ) // { - // if( item->Type() != PCB_FP_SHAPE_T || item->GetLayer() != Edge_Cuts ) + // if( item->Type() != PCB_SHAPE_T || item->GetLayer() != Edge_Cuts ) // continue; // code to export cutouts // } diff --git a/pcbnew/exporters/exporter_vrml.cpp b/pcbnew/exporters/exporter_vrml.cpp index 8f68e4a28f..0d9bb42a83 100644 --- a/pcbnew/exporters/exporter_vrml.cpp +++ b/pcbnew/exporters/exporter_vrml.cpp @@ -34,7 +34,6 @@ #include "board.h" #include "board_design_settings.h" #include -#include "fp_shape.h" #include "footprint.h" #include "pad.h" #include "pcb_text.h" diff --git a/pcbnew/exporters/gerber_placefile_writer.cpp b/pcbnew/exporters/gerber_placefile_writer.cpp index 6acf56bf04..a328969a5b 100644 --- a/pcbnew/exporters/gerber_placefile_writer.cpp +++ b/pcbnew/exporters/gerber_placefile_writer.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 Jean_Pierre Charras - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * 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 @@ -41,7 +41,6 @@ #include #include #include -#include PLACEFILE_GERBER_WRITER::PLACEFILE_GERBER_WRITER( BOARD* aPcb ) @@ -304,8 +303,8 @@ int PLACEFILE_GERBER_WRITER::CreatePlaceFile( wxString& aFullFilename, PCB_LAYER { for( BOARD_ITEM* item : footprint->GraphicalItems() ) { - if( item->Type() == PCB_FP_SHAPE_T && item->GetLayer() == Edge_Cuts ) - brd_plotter.PlotFootprintShape( static_cast( item ) ); + if( item->Type() == PCB_SHAPE_T && item->GetLayer() == Edge_Cuts ) + brd_plotter.PlotPcbShape( static_cast( item ) ); } } } diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 109b4e3dc0..9a425866c9 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -41,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -50,9 +50,9 @@ #include #include #include -#include "fp_textbox.h" #include "convert_basic_shapes_to_polygon.h" + FOOTPRINT::FOOTPRINT( BOARD* parent ) : BOARD_ITEM_CONTAINER((BOARD_ITEM*) parent, PCB_FOOTPRINT_T ), m_boundingBoxCacheTimeStamp( 0 ), @@ -77,8 +77,8 @@ FOOTPRINT::FOOTPRINT( BOARD* parent ) : m_fileFormatVersionAtLoad = 0; // These are special and mandatory text fields - m_reference = new FP_TEXT( this, FP_TEXT::TEXT_is_REFERENCE ); - m_value = new FP_TEXT( this, FP_TEXT::TEXT_is_VALUE ); + m_reference = new PCB_TEXT( this, PCB_TEXT::TEXT_is_REFERENCE ); + m_value = new PCB_TEXT( this, PCB_TEXT::TEXT_is_VALUE ); m_3D_Drawings.clear(); } @@ -116,11 +116,11 @@ FOOTPRINT::FOOTPRINT( const FOOTPRINT& aFootprint ) : std::map ptrMap; // Copy reference and value. - m_reference = new FP_TEXT( *aFootprint.m_reference ); + m_reference = new PCB_TEXT( *aFootprint.m_reference ); m_reference->SetParent( this ); ptrMap[ aFootprint.m_reference ] = m_reference; - m_value = new FP_TEXT( *aFootprint.m_value ); + m_value = new PCB_TEXT( *aFootprint.m_value ); m_value->SetParent( this ); ptrMap[ aFootprint.m_value ] = m_value; @@ -133,9 +133,9 @@ FOOTPRINT::FOOTPRINT( const FOOTPRINT& aFootprint ) : } // Copy zones - for( FP_ZONE* zone : aFootprint.Zones() ) + for( ZONE* zone : aFootprint.Zones() ) { - FP_ZONE* newZone = static_cast( zone->Clone() ); + ZONE* newZone = static_cast( zone->Clone() ); ptrMap[ zone ] = newZone; Add( newZone, ADD_MODE::APPEND ); // Append to ensure indexes are identical @@ -200,7 +200,7 @@ FOOTPRINT::FOOTPRINT( FOOTPRINT&& aFootprint ) : FOOTPRINT::~FOOTPRINT() { // Untangle group parents before doing any deleting - for( PCB_GROUP* group : m_fp_groups ) + for( PCB_GROUP* group : m_groups ) { for( BOARD_ITEM* item : group->GetItems() ) item->SetParentGroup( nullptr ); @@ -216,15 +216,15 @@ FOOTPRINT::~FOOTPRINT() m_pads.clear(); - for( FP_ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) delete zone; - m_fp_zones.clear(); + m_zones.clear(); - for( PCB_GROUP* group : m_fp_groups ) + for( PCB_GROUP* group : m_groups ) delete group; - m_fp_groups.clear(); + m_groups.clear(); for( BOARD_ITEM* d : m_drawings ) delete d; @@ -252,11 +252,11 @@ bool FOOTPRINT::FixUuids() // Note: one cannot fix null UUIDs inside the group, but it should not happen // because null uuids can be found in old footprints, therefore without group - for( PCB_GROUP* group : m_fp_groups ) + for( PCB_GROUP* group : m_groups ) item_list.push_back( group ); // Probably notneeded, because old fp do not have zones. But just in case. - for( FP_ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) item_list.push_back( zone ); bool changed = false; @@ -319,9 +319,9 @@ FOOTPRINT& FOOTPRINT::operator=( FOOTPRINT&& aOther ) aOther.Pads().clear(); // Move the zones - m_fp_zones.clear(); + m_zones.clear(); - for( FP_ZONE* item : aOther.Zones() ) + for( ZONE* item : aOther.Zones() ) { Add( item ); @@ -343,7 +343,7 @@ FOOTPRINT& FOOTPRINT::operator=( FOOTPRINT&& aOther ) aOther.GraphicalItems().clear(); // Move the groups - m_fp_groups.clear(); + m_groups.clear(); for( PCB_GROUP* group : aOther.Groups() ) Add( group ); @@ -419,11 +419,11 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther ) } // Copy zones - m_fp_zones.clear(); + m_zones.clear(); - for( FP_ZONE* zone : aOther.Zones() ) + for( ZONE* zone : aOther.Zones() ) { - FP_ZONE* newZone = static_cast( zone->Clone() ); + ZONE* newZone = static_cast( zone->Clone() ); ptrMap[ zone ] = newZone; Add( newZone ); @@ -445,7 +445,7 @@ FOOTPRINT& FOOTPRINT::operator=( const FOOTPRINT& aOther ) } // Copy groups - m_fp_groups.clear(); + m_groups.clear(); for( PCB_GROUP* group : aOther.Groups() ) { @@ -569,18 +569,18 @@ void FOOTPRINT::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode, bool aSkipConnectiv { switch( aBoardItem->Type() ) { - case PCB_FP_TEXT_T: + case PCB_TEXT_T: // Only user text can be added this way. - wxASSERT( static_cast( aBoardItem )->GetType() == FP_TEXT::TEXT_is_DIVERS ); + wxASSERT( static_cast( aBoardItem )->GetType() == PCB_TEXT::TEXT_is_DIVERS ); KI_FALLTHROUGH; - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_SHAPE_T: - case PCB_FP_TEXTBOX_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_LEADER_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_SHAPE_T: + case PCB_TEXTBOX_T: case PCB_BITMAP_T: if( aMode == ADD_MODE::APPEND ) m_drawings.push_back( aBoardItem ); @@ -595,18 +595,18 @@ void FOOTPRINT::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode, bool aSkipConnectiv m_pads.push_front( static_cast( aBoardItem ) ); break; - case PCB_FP_ZONE_T: + case PCB_ZONE_T: if( aMode == ADD_MODE::APPEND ) - m_fp_zones.push_back( static_cast( aBoardItem ) ); + m_zones.push_back( static_cast( aBoardItem ) ); else - m_fp_zones.insert( m_fp_zones.begin(), static_cast( aBoardItem ) ); + m_zones.insert( m_zones.begin(), static_cast( aBoardItem ) ); break; case PCB_GROUP_T: if( aMode == ADD_MODE::APPEND ) - m_fp_groups.push_back( static_cast( aBoardItem ) ); + m_groups.push_back( static_cast( aBoardItem ) ); else - m_fp_groups.insert( m_fp_groups.begin(), static_cast( aBoardItem ) ); + m_groups.insert( m_groups.begin(), static_cast( aBoardItem ) ); break; default: @@ -629,19 +629,19 @@ void FOOTPRINT::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aMode ) { switch( aBoardItem->Type() ) { - case PCB_FP_TEXT_T: + case PCB_TEXT_T: // Only user text can be removed this way. - wxCHECK_RET( static_cast( aBoardItem )->GetType() == FP_TEXT::TEXT_is_DIVERS, + wxCHECK_RET( static_cast( aBoardItem )->GetType() == PCB_TEXT::TEXT_is_DIVERS, wxT( "Please report this bug: Invalid remove operation on required text" ) ); KI_FALLTHROUGH; - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_SHAPE_T: - case PCB_FP_TEXTBOX_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_LEADER_T: + case PCB_SHAPE_T: + case PCB_TEXTBOX_T: case PCB_BITMAP_T: for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it ) { @@ -666,12 +666,12 @@ void FOOTPRINT::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aMode ) break; - case PCB_FP_ZONE_T: - for( auto it = m_fp_zones.begin(); it != m_fp_zones.end(); ++it ) + case PCB_ZONE_T: + for( auto it = m_zones.begin(); it != m_zones.end(); ++it ) { - if( *it == static_cast( aBoardItem ) ) + if( *it == static_cast( aBoardItem ) ) { - m_fp_zones.erase( it ); + m_zones.erase( it ); break; } } @@ -679,11 +679,11 @@ void FOOTPRINT::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aMode ) break; case PCB_GROUP_T: - for( auto it = m_fp_groups.begin(); it != m_fp_groups.end(); ++it ) + for( auto it = m_groups.begin(); it != m_groups.end(); ++it ) { if( *it == static_cast( aBoardItem ) ) { - m_fp_groups.erase( it ); + m_groups.erase( it ); break; } } @@ -847,14 +847,11 @@ const BOX2I FOOTPRINT::GetBoundingBox( bool aIncludeText, bool aIncludeInvisible continue; // Handle text separately - if( item->Type() == PCB_FP_TEXT_T ) + if( item->Type() == PCB_TEXT_T ) continue; // Treat dimension objects as text - if( !aIncludeText - && ( item->Type() == PCB_FP_DIM_ALIGNED_T || item->Type() == PCB_FP_DIM_CENTER_T - || item->Type() == PCB_FP_DIM_LEADER_T || item->Type() == PCB_FP_DIM_ORTHOGONAL_T - || item->Type() == PCB_FP_DIM_RADIAL_T ) ) + if( !aIncludeText && BaseType( item->Type() ) == PCB_DIMENSION_T ) continue; bbox.Merge( item->GetBoundingBox() ); @@ -863,10 +860,10 @@ const BOX2I FOOTPRINT::GetBoundingBox( bool aIncludeText, bool aIncludeInvisible for( PAD* pad : m_pads ) bbox.Merge( pad->GetBoundingBox() ); - for( FP_ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) bbox.Merge( zone->GetBoundingBox() ); - bool noDrawItems = ( m_drawings.empty() && m_pads.empty() && m_fp_zones.empty() ); + bool noDrawItems = ( m_drawings.empty() && m_pads.empty() && m_zones.empty() ); // Groups do not contribute to the rect, only their members if( aIncludeText || noDrawItems ) @@ -876,9 +873,9 @@ const BOX2I FOOTPRINT::GetBoundingBox( bool aIncludeText, bool aIncludeInvisible if( !isFPEdit && m_privateLayers.test( item->GetLayer() ) ) continue; - // Only FP_TEXT items are independently selectable; FP_TEXTBOX items go in with + // Only PCB_TEXT items are independently selectable; PCB_TEXTBOX items go in with // other graphic items above. - if( item->Type() == PCB_FP_TEXT_T ) + if( item->Type() == PCB_TEXT_T ) bbox.Merge( item->GetBoundingBox() ); } @@ -960,7 +957,7 @@ SHAPE_POLY_SET FOOTPRINT::GetBoundingHull() const if( !isFPEdit && m_privateLayers.test( item->GetLayer() ) ) continue; - if( item->Type() != PCB_FP_TEXT_T && item->Type() != PCB_BITMAP_T ) + if( item->Type() != PCB_TEXT_T && item->Type() != PCB_BITMAP_T ) { item->TransformShapeToPolygon( rawPolys, UNDEFINED_LAYER, 0, ARC_LOW_DEF, ERROR_OUTSIDE ); @@ -976,7 +973,7 @@ SHAPE_POLY_SET FOOTPRINT::GetBoundingHull() const pad->TransformHoleToPolygon( rawPolys, 0, ARC_LOW_DEF, ERROR_OUTSIDE ); } - for( FP_ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) { for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) { @@ -1104,7 +1101,7 @@ bool FOOTPRINT::IsOnLayer( PCB_LAYER_ID aLayer, bool aIncludeCourtyards ) const return m_layer == aLayer; // No pads? Check if this entire footprint exists on the given layer - for( FP_ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) { if( !zone->IsOnLayer( aLayer ) ) return false; @@ -1149,7 +1146,7 @@ bool FOOTPRINT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) co return false; // The empty footprint dummy rectangle intersects the selection area. - if( m_pads.empty() && m_fp_zones.empty() && m_drawings.empty() ) + if( m_pads.empty() && m_zones.empty() && m_drawings.empty() ) return GetBoundingBox( true, false ).Intersects( arect ); // Determine if any elements in the FOOTPRINT intersect the rect @@ -1159,7 +1156,7 @@ bool FOOTPRINT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) co return true; } - for( FP_ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) { if( zone->HitTest( arect, false, 0 ) ) return true; @@ -1170,11 +1167,8 @@ bool FOOTPRINT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) co // Text items are selectable on their own, and are therefore excluded from this // test. TextBox items are NOT selectable on their own, and so MUST be included // here. Bitmaps aren't selectable since they aren't displayed. - if( item->Type() != PCB_FP_TEXT_T && item->Type() != PCB_FP_TEXT_T - && item->HitTest( arect, false, 0 ) ) - { + if( item->Type() != PCB_TEXT_T && item->HitTest( arect, false, 0 ) ) return true; - } } // Groups are not hit-tested; only their members @@ -1310,8 +1304,8 @@ INSPECT_RESULT FOOTPRINT::Visit( INSPECTOR inspector, void* testData, break; - case PCB_FP_ZONE_T: - if( IterateForward( m_fp_zones, inspector, testData, { scanType } ) + case PCB_ZONE_T: + if( IterateForward( m_zones, inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT ) { return INSPECT_RESULT::QUIT; @@ -1319,23 +1313,23 @@ INSPECT_RESULT FOOTPRINT::Visit( INSPECTOR inspector, void* testData, break; - case PCB_FP_TEXT_T: + case PCB_TEXT_T: if( inspector( m_reference, testData ) == INSPECT_RESULT::QUIT ) return INSPECT_RESULT::QUIT; if( inspector( m_value, testData ) == INSPECT_RESULT::QUIT ) return INSPECT_RESULT::QUIT; - // Intentionally fall through since m_Drawings can hold PCB_FP_TEXT_T also + // Intentionally fall through since m_Drawings can hold PCB_TEXT_T also KI_FALLTHROUGH; - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_SHAPE_T: - case PCB_FP_TEXTBOX_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_LEADER_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_SHAPE_T: + case PCB_TEXTBOX_T: if( !drawingsScanned ) { if( IterateForward( m_drawings, inspector, testData, aScanTypes ) @@ -1350,7 +1344,7 @@ INSPECT_RESULT FOOTPRINT::Visit( INSPECTOR inspector, void* testData, break; case PCB_GROUP_T: - if( IterateForward( m_fp_groups, inspector, testData, { scanType } ) + if( IterateForward( m_groups, inspector, testData, { scanType } ) == INSPECT_RESULT::QUIT ) { return INSPECT_RESULT::QUIT; @@ -1397,10 +1391,10 @@ void FOOTPRINT::RunOnChildren( const std::function& aFuncti for( PAD* pad : m_pads ) aFunction( static_cast( pad ) ); - for( FP_ZONE* zone : m_fp_zones ) - aFunction( static_cast( zone ) ); + for( ZONE* zone : m_zones ) + aFunction( static_cast( zone ) ); - for( PCB_GROUP* group : m_fp_groups ) + for( PCB_GROUP* group : m_groups ) aFunction( static_cast( group ) ); for( BOARD_ITEM* drawing : m_drawings ) @@ -1573,8 +1567,8 @@ void FOOTPRINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) for( BOARD_ITEM* item : m_drawings ) { - if( item->Type() == PCB_FP_TEXT_T ) - static_cast( item )->KeepUpright( orientation, newOrientation ); + if( item->Type() == PCB_TEXT_T ) + static_cast( item )->KeepUpright( orientation, newOrientation ); } m_boundingBoxCacheTimeStamp = 0; @@ -1624,7 +1618,7 @@ void FOOTPRINT::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) pad->Flip( m_pos, false ); // Mirror zones to other side of board. - for( ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) zone->Flip( m_pos, false ); // Mirror reference and value. @@ -1633,39 +1627,7 @@ void FOOTPRINT::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) // Reverse mirror footprint graphics and texts. for( BOARD_ITEM* item : m_drawings ) - { - switch( item->Type() ) - { - case PCB_FP_SHAPE_T: - static_cast( item )->Flip( m_pos, false ); - break; - - case PCB_FP_TEXT_T: - static_cast( item )->Flip( m_pos, false ); - break; - - case PCB_FP_TEXTBOX_T: - static_cast( item )->Flip( m_pos, false ); - break; - - case PCB_BITMAP_T: - static_cast( item )->Flip( m_pos, false ); - break; - - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_LEADER_T: - static_cast( item )->Flip( m_pos, false ); - break; - - default: - wxMessageBox( wxString::Format( wxT( "FOOTPRINT::Flip() error: Unknown Draw Type %d" ), - (int)item->Type() ) ); - break; - } - } + item->Flip( m_pos, false ); // Now rotate 180 deg if required if( aFlipLeftRight ) @@ -1694,49 +1656,11 @@ void FOOTPRINT::SetPosition( const VECTOR2I& aPos ) for( PAD* pad : m_pads ) pad->SetPosition( pad->GetPosition() + delta ); - for( ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) zone->Move( delta ); for( BOARD_ITEM* item : m_drawings ) - { - switch( item->Type() ) - { - case PCB_FP_SHAPE_T: - { - FP_SHAPE* shape = static_cast( item ); - shape->SetDrawCoord(); - break; - } - - case PCB_FP_TEXTBOX_T: - { - FP_TEXTBOX* textb = static_cast( item ); - textb->SetDrawCoord(); - textb->ClearRenderCache(); - break; - } - - case PCB_FP_TEXT_T: - { - FP_TEXT* text = static_cast( item ); - text->EDA_TEXT::Offset( delta ); - break; - } - - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_LEADER_T: - case PCB_BITMAP_T: - item->Move( delta ); - break; - - default: - wxMessageBox( wxT( "Draw type undefined." ) ); - break; - } - } + item->Move( delta ); m_cachedBoundingBox.Move( delta ); m_cachedVisibleBBox.Move( delta ); @@ -1763,10 +1687,8 @@ void FOOTPRINT::MoveAnchorPosition( const VECTOR2I& aMoveVector ) RotatePoint( moveVector, -GetOrientation() ); // Update of the reference and value. - m_reference->SetPos0( m_reference->GetPos0() + moveVector ); - m_reference->SetDrawCoord(); - m_value->SetPos0( m_value->GetPos0() + moveVector ); - m_value->SetDrawCoord(); + m_reference->Move( moveVector ); + m_value->Move( moveVector ); // Update the pad local coordinates. for( PAD* pad : m_pads ) @@ -1777,35 +1699,11 @@ void FOOTPRINT::MoveAnchorPosition( const VECTOR2I& aMoveVector ) // Update the draw element coordinates. for( BOARD_ITEM* item : GraphicalItems() ) - { - switch( item->Type() ) - { - case PCB_FP_SHAPE_T: - case PCB_FP_TEXTBOX_T: - { - FP_SHAPE* shape = static_cast( item ); - shape->Move( moveVector ); - break; - } - - case PCB_FP_TEXT_T: - { - FP_TEXT* text = static_cast( item ); - text->SetPos0( text->GetPos0() + moveVector ); - text->SetDrawCoord(); - break; - } - - default: - break; - } - } + item->Move( moveVector ); // Update the keepout zones for( ZONE* zone : Zones() ) - { zone->Move( moveVector ); - } // Update the 3D models for( FP_3DMODEL& model : Models() ) @@ -1834,37 +1732,15 @@ void FOOTPRINT::SetOrientation( const EDA_ANGLE& aNewAngle ) pad->SetDrawCoord(); } - for( ZONE* zone : m_fp_zones ) + for( ZONE* zone : m_zones ) zone->Rotate( GetPosition(), angleChange ); - for( BOARD_ITEM* item : m_drawings ) - { - if( PCB_DIMENSION_BASE* dimension = dynamic_cast( item ) ) - dimension->Rotate( GetPosition(), angleChange ); - } - // Update of the reference and value. - m_reference->SetDrawCoord(); - m_value->SetDrawCoord(); + m_reference->Rotate( GetPosition(), angleChange ); + m_value->Rotate( GetPosition(), angleChange ); - // Displace contours and text of the footprint. for( BOARD_ITEM* item : m_drawings ) - { - switch( item->Type() ) - { - case PCB_FP_SHAPE_T: - case PCB_FP_TEXTBOX_T: - static_cast( item )->SetDrawCoord(); - break; - - case PCB_FP_TEXT_T: - static_cast( item )->SetDrawCoord(); - break; - - default: - break; - } - } + item->Rotate( GetPosition(), angleChange ); m_boundingBoxCacheTimeStamp = 0; m_visibleBBoxCacheTimeStamp = 0; @@ -1891,7 +1767,6 @@ BOARD_ITEM* FOOTPRINT::Duplicate() const BOARD_ITEM* FOOTPRINT::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToFootprint ) { BOARD_ITEM* new_item = nullptr; - FP_ZONE* new_zone = nullptr; switch( aItem->Type() ) { @@ -1907,45 +1782,44 @@ BOARD_ITEM* FOOTPRINT::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToFootpr break; } - case PCB_FP_ZONE_T: + case PCB_ZONE_T: { - new_zone = new FP_ZONE( *static_cast( aItem ) ); + ZONE* new_zone = new ZONE( *static_cast( aItem ) ); const_cast( new_zone->m_Uuid ) = KIID(); if( aAddToFootprint ) - m_fp_zones.push_back( new_zone ); + m_zones.push_back( new_zone ); new_item = new_zone; break; } - case PCB_FP_TEXT_T: + case PCB_TEXT_T: { - FP_TEXT* new_text = new FP_TEXT( *static_cast( aItem ) ); + PCB_TEXT* new_text = new PCB_TEXT( *static_cast( aItem ) ); const_cast( new_text->m_Uuid ) = KIID(); - if( new_text->GetType() == FP_TEXT::TEXT_is_REFERENCE ) + if( new_text->GetType() == PCB_TEXT::TEXT_is_REFERENCE ) { new_text->SetText( wxT( "${REFERENCE}" ) ); - new_text->SetType( FP_TEXT::TEXT_is_DIVERS ); + new_text->SetType( PCB_TEXT::TEXT_is_DIVERS ); } - else if( new_text->GetType() == FP_TEXT::TEXT_is_VALUE ) + else if( new_text->GetType() == PCB_TEXT::TEXT_is_VALUE ) { new_text->SetText( wxT( "${VALUE}" ) ); - new_text->SetType( FP_TEXT::TEXT_is_DIVERS ); + new_text->SetType( PCB_TEXT::TEXT_is_DIVERS ); } if( aAddToFootprint ) Add( new_text ); new_item = new_text; - break; } - case PCB_FP_SHAPE_T: + case PCB_SHAPE_T: { - FP_SHAPE* new_shape = new FP_SHAPE( *static_cast( aItem ) ); + PCB_SHAPE* new_shape = new PCB_SHAPE( *static_cast( aItem ) ); const_cast( new_shape->m_Uuid ) = KIID(); if( aAddToFootprint ) @@ -1955,9 +1829,9 @@ BOARD_ITEM* FOOTPRINT::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToFootpr break; } - case PCB_FP_TEXTBOX_T: + case PCB_TEXTBOX_T: { - FP_TEXTBOX* new_textbox = new FP_TEXTBOX( *static_cast( aItem ) ); + PCB_TEXTBOX* new_textbox = new PCB_TEXTBOX( *static_cast( aItem ) ); const_cast( new_textbox->m_Uuid ) = KIID(); if( aAddToFootprint ) @@ -1967,11 +1841,11 @@ BOARD_ITEM* FOOTPRINT::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToFootpr break; } - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_LEADER_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_ORTHOGONAL_T: { PCB_DIMENSION_BASE* dimension = static_cast( aItem->Duplicate() ); @@ -2075,15 +1949,15 @@ double FOOTPRINT::GetCoverageArea( const BOARD_ITEM* aItem, const GENERAL_COLLEC poly = footprint->GetBoundingHull(); } - else if( aItem->Type() == PCB_FP_TEXT_T ) + else if( aItem->Type() == PCB_TEXT_T ) { - const FP_TEXT* text = static_cast( aItem ); + const PCB_TEXT* text = static_cast( aItem ); text->TransformTextToPolySet( poly, UNDEFINED_LAYER, textMargin, ARC_LOW_DEF, ERROR_OUTSIDE ); } - else if( aItem->Type() == PCB_FP_TEXTBOX_T ) + else if( aItem->Type() == PCB_TEXTBOX_T ) { - const FP_TEXTBOX* tb = static_cast( aItem ); + const PCB_TEXTBOX* tb = static_cast( aItem ); tb->TransformTextToPolySet( poly, UNDEFINED_LAYER, textMargin, ARC_LOW_DEF, ERROR_OUTSIDE ); } @@ -2151,24 +2025,17 @@ double FOOTPRINT::CoverageRatio( const GENERAL_COLLECTOR& aCollector ) const switch( item->Type() ) { - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - if( item->GetParent() != this ) - { - item->TransformShapeToPolygon( coveredRegion, UNDEFINED_LAYER, 0, ARC_LOW_DEF, - ERROR_OUTSIDE ); - } - break; - case PCB_TEXT_T: case PCB_TEXTBOX_T: case PCB_SHAPE_T: case PCB_TRACE_T: case PCB_ARC_T: case PCB_VIA_T: - item->TransformShapeToPolygon( coveredRegion, UNDEFINED_LAYER, 0, ARC_LOW_DEF, - ERROR_OUTSIDE ); + if( item->GetParent() != this ) + { + item->TransformShapeToPolygon( coveredRegion, UNDEFINED_LAYER, 0, ARC_LOW_DEF, + ERROR_OUTSIDE ); + } break; case PCB_FOOTPRINT_T: @@ -2225,7 +2092,7 @@ std::shared_ptr FOOTPRINT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHI for( BOARD_ITEM* item : GraphicalItems() ) { - if( item->Type() == PCB_FP_SHAPE_T ) + if( item->Type() == PCB_SHAPE_T ) shape->AddShape( item->GetEffectiveShape( aLayer, aFlash )->Clone() ); } } @@ -2255,17 +2122,17 @@ void FOOTPRINT::BuildCourtyardCaches( OUTLINE_ERROR_HANDLER* aErrorHandler ) m_courtyard_cache_timestamp = GetBoard()->GetTimeStamp(); // Build the courtyard area from graphic items on the courtyard. - // Only PCB_FP_SHAPE_T have meaning, graphic texts are ignored. + // Only PCB_SHAPE_T have meaning, graphic texts are ignored. // Collect items: std::vector list_front; std::vector list_back; for( BOARD_ITEM* item : GraphicalItems() ) { - if( item->GetLayer() == B_CrtYd && item->Type() == PCB_FP_SHAPE_T ) + if( item->GetLayer() == B_CrtYd && item->Type() == PCB_SHAPE_T ) list_back.push_back( static_cast( item ) ); - if( item->GetLayer() == F_CrtYd && item->Type() == PCB_FP_SHAPE_T ) + if( item->GetLayer() == F_CrtYd && item->Type() == PCB_SHAPE_T ) list_front.push_back( static_cast( item ) ); } @@ -2550,7 +2417,7 @@ void FOOTPRINT::CheckNetTies( const std::functionGetIsRuleArea() && zone->IsOnCopperLayer() ) copperItems.push_back( zone ); @@ -2690,24 +2557,24 @@ bool FOOTPRINT::cmp_drawings::operator()( const BOARD_ITEM* itemA, const BOARD_I TEST( itemA->Type(), itemB->Type() ); TEST( itemA->GetLayer(), itemB->GetLayer() ); - if( itemA->Type() == PCB_FP_SHAPE_T ) + if( itemA->Type() == PCB_SHAPE_T ) { - const FP_SHAPE* dwgA = static_cast( itemA ); - const FP_SHAPE* dwgB = static_cast( itemB ); + const PCB_SHAPE* dwgA = static_cast( itemA ); + const PCB_SHAPE* dwgB = static_cast( itemB ); TEST( dwgA->GetShape(), dwgB->GetShape() ); - TEST_PT( dwgA->GetStart0(), dwgB->GetStart0() ); - TEST_PT( dwgA->GetEnd0(), dwgB->GetEnd0() ); + TEST_PT( dwgA->GetStart(), dwgB->GetStart() ); + TEST_PT( dwgA->GetEnd(), dwgB->GetEnd() ); if( dwgA->GetShape() == SHAPE_T::ARC ) { - TEST_PT( dwgA->GetCenter0(), dwgB->GetCenter0() ); + TEST_PT( dwgA->GetCenter(), dwgB->GetCenter() ); } else if( dwgA->GetShape() == SHAPE_T::BEZIER ) { - TEST_PT( dwgA->GetBezierC1_0(), dwgB->GetBezierC1_0() ); - TEST_PT( dwgA->GetBezierC2_0(), dwgB->GetBezierC2_0() ); + TEST_PT( dwgA->GetBezierC1(), dwgB->GetBezierC1() ); + TEST_PT( dwgA->GetBezierC2(), dwgB->GetBezierC2() ); } else if( dwgA->GetShape() == SHAPE_T::POLY ) { @@ -2742,7 +2609,7 @@ bool FOOTPRINT::cmp_pads::operator()( const PAD* aFirst, const PAD* aSecond ) co } -bool FOOTPRINT::cmp_zones::operator()( const FP_ZONE* aFirst, const FP_ZONE* aSecond ) const +bool FOOTPRINT::cmp_zones::operator()( const ZONE* aFirst, const ZONE* aSecond ) const { TEST( aFirst->GetAssignedPriority(), aSecond->GetAssignedPriority() ); TEST( aFirst->GetLayerSet().Seq(), aSecond->GetLayerSet().Seq() ); @@ -2839,32 +2706,32 @@ void FOOTPRINT::TransformFPShapesToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_I bool aIncludeText, bool aIncludeShapes, bool aIncludePrivateItems ) const { - std::vector texts; // List of FP_TEXT to convert + std::vector texts; // List of PCB_TEXTs to convert for( BOARD_ITEM* item : GraphicalItems() ) { if( GetPrivateLayers().test( item->GetLayer() ) && !aIncludePrivateItems ) continue; - if( item->Type() == PCB_FP_TEXT_T && aIncludeText ) + if( item->Type() == PCB_TEXT_T && aIncludeText ) { - FP_TEXT* text = static_cast( item ); + PCB_TEXT* text = static_cast( item ); if( aLayer != UNDEFINED_LAYER && text->GetLayer() == aLayer && text->IsVisible() ) texts.push_back( text ); } - if( item->Type() == PCB_FP_TEXTBOX_T && aIncludeText ) + if( item->Type() == PCB_TEXTBOX_T && aIncludeText ) { - FP_TEXTBOX* textbox = static_cast( item ); + PCB_TEXTBOX* textbox = static_cast( item ); if( aLayer != UNDEFINED_LAYER && textbox->GetLayer() == aLayer && textbox->IsVisible() ) textbox->TransformShapeToPolygon( aBuffer, aLayer, 0, aError, aErrorLoc ); } - if( item->Type() == PCB_FP_SHAPE_T && aIncludeShapes ) + if( item->Type() == PCB_SHAPE_T && aIncludeShapes ) { - const FP_SHAPE* outline = static_cast( item ); + const PCB_SHAPE* outline = static_cast( item ); if( aLayer != UNDEFINED_LAYER && outline->GetLayer() == aLayer ) outline->TransformShapeToPolygon( aBuffer, aLayer, 0, aError, aErrorLoc ); @@ -2880,7 +2747,7 @@ void FOOTPRINT::TransformFPShapesToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_I texts.push_back( &Value() ); } - for( const FP_TEXT* text : texts ) + for( const PCB_TEXT* text : texts ) text->TransformTextToPolySet( aBuffer, aLayer, aClearance, aError, aErrorLoc ); } diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index 8a7f103a24..c468433231 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include @@ -168,17 +168,17 @@ public: const BOX2I GetBoundingBox() const override; const BOX2I GetBoundingBox( bool aIncludeText, bool aIncludeInvisibleText ) const; - PADS& Pads() { return m_pads; } - const PADS& Pads() const { return m_pads; } + PADS& Pads() { return m_pads; } + const PADS& Pads() const { return m_pads; } DRAWINGS& GraphicalItems() { return m_drawings; } const DRAWINGS& GraphicalItems() const { return m_drawings; } - FP_ZONES& Zones() { return m_fp_zones; } - const FP_ZONES& Zones() const { return m_fp_zones; } + ZONES& Zones() { return m_zones; } + const ZONES& Zones() const { return m_zones; } - FP_GROUPS& Groups() { return m_fp_groups; } - const FP_GROUPS& Groups() const { return m_fp_groups; } + GROUPS& Groups() { return m_groups; } + const GROUPS& Groups() const { return m_groups; } bool HasThroughHolePads() const; @@ -565,12 +565,12 @@ public: } /// read/write accessors: - FP_TEXT& Value() { return *m_value; } - FP_TEXT& Reference() { return *m_reference; } + PCB_TEXT& Value() { return *m_value; } + PCB_TEXT& Reference() { return *m_reference; } /// The const versions to keep the compiler happy. - FP_TEXT& Value() const { return *m_value; } - FP_TEXT& Reference() const { return *m_reference; } + PCB_TEXT& Value() const { return *m_value; } + PCB_TEXT& Reference() const { return *m_reference; } const std::map& GetProperties() const { return m_properties; } void SetProperties( const std::map& aProps ) { m_properties = aProps; } @@ -819,7 +819,7 @@ public: struct cmp_zones { - bool operator()( const FP_ZONE* aFirst, const FP_ZONE* aSecond ) const; + bool operator()( const ZONE* aFirst, const ZONE* aSecond ) const; }; protected: @@ -828,13 +828,13 @@ protected: private: DRAWINGS m_drawings; // BOARD_ITEMs for drawings on the board, owned by pointer. PADS m_pads; // PAD items, owned by pointer - FP_ZONES m_fp_zones; // FP_ZONE items, owned by pointer - FP_GROUPS m_fp_groups; // PCB_GROUP items, owned by pointer + ZONES m_zones; // PCB_ZONE items, owned by pointer + GROUPS m_groups; // PCB_GROUP items, owned by pointer EDA_ANGLE m_orient; // Orientation VECTOR2I m_pos; // Position of footprint on the board in internal units. - FP_TEXT* m_reference; // Component reference designator value (U34, R18..) - FP_TEXT* m_value; // Component value (74LS00, 22K..) + PCB_TEXT* m_reference; // Component reference designator value (U34, R18..) + PCB_TEXT* m_value; // Component value (74LS00, 22K..) LIB_ID m_fpid; // The #LIB_ID of the FOOTPRINT. int m_attributes; // Flag bits (see FOOTPRINT_ATTR_T) int m_fpStatus; // For autoplace: flags (LOCKED, FIELDS_AUTOPLACED) diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index a8b5ba9912..02fd8110e0 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -688,7 +688,7 @@ const BOX2I FOOTPRINT_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) { for( const BOARD_ITEM* item : footprint->GraphicalItems() ) { - if( item->Type() == PCB_FP_TEXT_T ) + if( item->Type() == PCB_TEXT_T ) continue; hasGraphicalItem = true; diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index 7c9e0e4757..280dbdf9d9 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -70,19 +72,19 @@ void FOOTPRINT_EDIT_FRAME::LoadFootprintFromLibrary( LIB_ID aFPID ) // if either m_Reference or m_Value are gone, reinstall them - // otherwise you cannot see what you are doing on board - FP_TEXT* ref = &footprint->Reference(); - FP_TEXT* val = &footprint->Value(); + PCB_TEXT* ref = &footprint->Reference(); + PCB_TEXT* val = &footprint->Value(); if( val && ref ) { - ref->SetType( FP_TEXT::TEXT_is_REFERENCE ); // just in case ... + ref->SetType( PCB_TEXT::TEXT_is_REFERENCE ); // just in case ... - if( ref->GetLength() == 0 ) + if( ref->GetText().IsEmpty() ) ref->SetText( wxT( "Ref**" ) ); - val->SetType( FP_TEXT::TEXT_is_VALUE ); // just in case ... + val->SetType( PCB_TEXT::TEXT_is_VALUE ); // just in case ... - if( val->GetLength() == 0 ) + if( val->GetText().IsEmpty() ) val->SetText( wxT( "Val**" ) ); } @@ -201,30 +203,30 @@ void FOOTPRINT_EDIT_FRAME::OnEditItemRequest( BOARD_ITEM* aItem ) GetCanvas()->Refresh(); break; - case PCB_FP_TEXT_T: - ShowTextPropertiesDialog( aItem ); + case PCB_TEXT_T: + ShowTextPropertiesDialog( static_cast( aItem ) ); break; - case PCB_FP_TEXTBOX_T: - ShowTextBoxPropertiesDialog( aItem ); + case PCB_TEXTBOX_T: + ShowTextBoxPropertiesDialog( static_cast( aItem ) ); break; - case PCB_FP_SHAPE_T : - ShowGraphicItemPropertiesDialog( aItem ); + case PCB_SHAPE_T : + ShowGraphicItemPropertiesDialog( static_cast( aItem ) ); break; - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_LEADER_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_DIM_LEADER_T: { DIALOG_DIMENSION_PROPERTIES dlg( this, static_cast( aItem ) ); dlg.ShowQuasiModal(); break; } - case PCB_FP_ZONE_T: + case PCB_ZONE_T: { ZONE* zone = static_cast( aItem ); bool success = false; diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 9e9e78d518..937fb92d9e 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -36,8 +36,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -49,7 +51,6 @@ #include #include #include "footprint_viewer_frame.h" -#include "tools/pad_tool.h" #include #include @@ -1312,7 +1313,7 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( const wxString& aFootprintName, b for( size_t i = 2; i < settings.m_DefaultFPTextItems.size(); ++i ) { - FP_TEXT* textItem = new FP_TEXT( footprint ); + PCB_TEXT* textItem = new PCB_TEXT( footprint, PCB_TEXT::TEXT_is_DIVERS ); textItem->SetText( settings.m_DefaultFPTextItems[i].m_Text ); textItem->SetVisible( settings.m_DefaultFPTextItems[i].m_Visible ); txt_layer = (PCB_LAYER_ID) settings.m_DefaultFPTextItems[i].m_Layer; @@ -1332,9 +1333,9 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( const wxString& aFootprintName, b footprint->RunOnChildren( [&] ( BOARD_ITEM* aChild ) { - if( aChild->Type() == PCB_FP_TEXT_T ) + if( aChild->Type() == PCB_TEXT_T ) { - FP_TEXT* textItem = static_cast( aChild ); + PCB_TEXT* textItem = static_cast( aChild ); PCB_LAYER_ID layer = textItem->GetLayer(); textItem->SetTextThickness( settings.GetTextThickness( layer ) ); diff --git a/pcbnew/footprint_preview_panel.cpp b/pcbnew/footprint_preview_panel.cpp index 12d6333e8c..53b16d16e3 100644 --- a/pcbnew/footprint_preview_panel.cpp +++ b/pcbnew/footprint_preview_panel.cpp @@ -111,10 +111,11 @@ void FOOTPRINT_PREVIEW_PANEL::renderFootprint( std::shared_ptr aFootp return INSPECT_RESULT::CONTINUE; }; - aFootprint->Visit( inspector, nullptr, { PCB_FP_DIM_LEADER_T, - PCB_FP_DIM_ORTHOGONAL_T, - PCB_FP_DIM_CENTER_T, - PCB_FP_DIM_RADIAL_T } ); + aFootprint->Visit( inspector, nullptr, { PCB_DIM_LEADER_T, + PCB_DIM_ALIGNED_T, + PCB_DIM_ORTHOGONAL_T, + PCB_DIM_CENTER_T, + PCB_DIM_RADIAL_T } ); // Ensure we are not using the high contrast mode to display the selected footprint KIGFX::PAINTER* painter = GetView()->GetPainter(); diff --git a/pcbnew/fp_shape.cpp b/pcbnew/fp_shape.cpp deleted file mode 100644 index 15cbd32e0d..0000000000 --- a/pcbnew/fp_shape.cpp +++ /dev/null @@ -1,434 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2015 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr - * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2012 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. - * - * 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 - */ - -#include -#include -#include -#include -#include // for KiROUND -#include -#include -#include -#include -#include -#include - - -FP_SHAPE::FP_SHAPE( FOOTPRINT* parent, SHAPE_T aShape, KICAD_T aItemType ) : - PCB_SHAPE( parent, aItemType, aShape ) -{ - m_layer = F_SilkS; -} - - -FP_SHAPE::~FP_SHAPE() -{ -} - - -void FP_SHAPE::SetLocalCoord() -{ - FOOTPRINT* fp = static_cast( m_parent ); - - if( fp == NULL ) - { - m_start0 = m_start; - m_end0 = m_end; - m_arcCenter0 = m_arcCenter; - m_bezierC1_0 = m_bezierC1; - m_bezierC2_0 = m_bezierC2; - return; - } - - m_start0 = m_start - fp->GetPosition(); - m_end0 = m_end - fp->GetPosition(); - m_arcCenter0 = m_arcCenter - fp->GetPosition(); - m_bezierC1_0 = m_bezierC1 - fp->GetPosition(); - m_bezierC2_0 = m_bezierC2 - fp->GetPosition(); - - RotatePoint( &m_start0.x, &m_start0.y, - fp->GetOrientation() ); - RotatePoint( &m_end0.x, &m_end0.y, - fp->GetOrientation() ); - RotatePoint( &m_arcCenter0.x, &m_arcCenter0.y, - fp->GetOrientation() ); - RotatePoint( &m_bezierC1_0.x, &m_bezierC1_0.y, - fp->GetOrientation() ); - RotatePoint( &m_bezierC2_0.x, &m_bezierC2_0.y, - fp->GetOrientation() ); -} - - -void FP_SHAPE::SetDrawCoord() -{ - FOOTPRINT* fp = static_cast( m_parent ); - - m_start = m_start0; - m_end = m_end0; - m_arcCenter = m_arcCenter0; - m_bezierC1 = m_bezierC1_0; - m_bezierC2 = m_bezierC2_0; - - if( fp ) - { - RotatePoint( &m_start.x, &m_start.y, fp->GetOrientation() ); - RotatePoint( &m_end.x, &m_end.y, fp->GetOrientation() ); - RotatePoint( &m_arcCenter.x, &m_arcCenter.y, fp->GetOrientation() ); - RotatePoint( &m_bezierC1.x, &m_bezierC1.y, fp->GetOrientation() ); - RotatePoint( &m_bezierC2.x, &m_bezierC2.y, fp->GetOrientation() ); - - m_start += fp->GetPosition(); - m_end += fp->GetPosition(); - m_arcCenter += fp->GetPosition(); - m_bezierC1 += fp->GetPosition(); - m_bezierC2 += fp->GetPosition(); - } - - RebuildBezierToSegmentsPointsList( GetWidth() ); -} - - -void FP_SHAPE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) -{ - if( aFrame->GetName() == PCB_EDIT_FRAME_NAME ) - { - FOOTPRINT* fp = static_cast( m_parent ); - - if( fp ) - aList.emplace_back( _( "Footprint" ), fp->GetReference() ); - } - - // append the features shared with the base class - PCB_SHAPE::GetMsgPanelInfo( aFrame, aList ); -} - - -wxString FP_SHAPE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const -{ - return wxString::Format( _( "%s on %s" ), - ShowShape(), - GetLayerName() ); -} - - -BITMAPS FP_SHAPE::GetMenuImage() const -{ - return BITMAPS::show_mod_edge; -} - - -EDA_ITEM* FP_SHAPE::Clone() const -{ - return new FP_SHAPE( *this ); -} - - -VECTOR2I FP_SHAPE::GetCenter0() const -{ - switch( m_shape ) - { - case SHAPE_T::ARC: - return m_arcCenter0; - - case SHAPE_T::CIRCLE: - return m_start0; - - default: - UNIMPLEMENTED_FOR( SHAPE_T_asString() ); - return VECTOR2I(); - } -} - - -void FP_SHAPE::SetCenter0( const VECTOR2I& aCenter ) -{ - switch( m_shape ) - { - case SHAPE_T::ARC: - m_arcCenter0 = aCenter; - break; - - case SHAPE_T::CIRCLE: - m_start0 = aCenter; - break; - - default: - UNIMPLEMENTED_FOR( SHAPE_T_asString() ); - } -} - - -VECTOR2I FP_SHAPE::GetArcMid0() const -{ - // If none of the input data have changed since we loaded the arc, - // keep the original mid point data to minimize churn - if( m_arcMidData_0.start == m_start && m_arcMidData_0.end == m_end - && m_arcMidData_0.center == m_arcCenter ) - return m_arcMidData_0.mid; - - VECTOR2I mid0 = m_start0; - RotatePoint( mid0, m_arcCenter0, -GetArcAngle() / 2.0 ); - return mid0; -} - - -void FP_SHAPE::SetArcAngleAndEnd0( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle ) -{ - EDA_ANGLE angle( aAngle ); - - m_end0 = m_start0; - RotatePoint( m_end0, m_arcCenter0, -angle.Normalize720() ); - - if( aCheckNegativeAngle && aAngle < ANGLE_0 ) - std::swap( m_start0, m_end0 ); -} - - -void FP_SHAPE::SetArcGeometry0( const VECTOR2I& aStart0, const VECTOR2I& aMid0, - const VECTOR2I& aEnd0 ) -{ - m_start0 = aStart0; - m_end0 = aEnd0; - m_arcCenter0 = CalcArcCenter( aStart0, aMid0, aEnd0 ); - - m_arcMidData_0.center = m_arcCenter0; - m_arcMidData_0.end = m_end0; - m_arcMidData_0.mid = aMid0; - m_arcMidData_0.start = m_start0; -} - - -void FP_SHAPE::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) -{ - VECTOR2I pt( 0, 0 ); - - switch( GetShape() ) - { - case SHAPE_T::ARC: - case SHAPE_T::SEGMENT: - case SHAPE_T::RECT: - case SHAPE_T::CIRCLE: - case SHAPE_T::BEZIER: - // If Start0 and Start are equal (ie: Footprint Editor), then flip both sets around the - // centre point. - if( m_start == m_start0 ) - pt = aCentre; - - if( aFlipLeftRight ) - { - MIRROR( m_start.x, aCentre.x ); - MIRROR( m_end.x, aCentre.x ); - MIRROR( m_arcCenter.x, aCentre.x ); - MIRROR( m_bezierC1.x, aCentre.x ); - MIRROR( m_bezierC2.x, aCentre.x ); - MIRROR( m_start0.x, pt.x ); - MIRROR( m_end0.x, pt.x ); - MIRROR( m_arcCenter0.x, pt.x ); - MIRROR( m_bezierC1_0.x, pt.x ); - MIRROR( m_bezierC2_0.x, pt.x ); - } - else - { - MIRROR( m_start.y, aCentre.y ); - MIRROR( m_end.y, aCentre.y ); - MIRROR( m_arcCenter.y, aCentre.y ); - MIRROR( m_bezierC1.y, aCentre.y ); - MIRROR( m_bezierC2.y, aCentre.y ); - MIRROR( m_start0.y, pt.y ); - MIRROR( m_end0.y, pt.y ); - MIRROR( m_arcCenter0.y, pt.y ); - MIRROR( m_bezierC1_0.y, pt.y ); - MIRROR( m_bezierC2_0.y, pt.y ); - } - - if( GetShape() == SHAPE_T::BEZIER ) - RebuildBezierToSegmentsPointsList( GetWidth() ); - - if( GetShape() == SHAPE_T::ARC ) - { - std::swap( m_start, m_end ); - std::swap( m_start0, m_end0 ); - } - - break; - - case SHAPE_T::POLY: - // polygon corners coordinates are relative to the footprint position, orientation 0 - m_poly.Mirror( aFlipLeftRight, !aFlipLeftRight ); - break; - - default: - UNIMPLEMENTED_FOR( SHAPE_T_asString() ); - } - - SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) ); -} - - -bool FP_SHAPE::IsParentFlipped() const -{ - if( GetParent() && GetParent()->GetLayer() == B_Cu ) - return true; - return false; -} - - -void FP_SHAPE::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ) -{ - switch( GetShape() ) - { - case SHAPE_T::ARC: - case SHAPE_T::SEGMENT: - case SHAPE_T::RECT: - case SHAPE_T::CIRCLE: - case SHAPE_T::BEZIER: - if( aMirrorAroundXAxis ) - { - MIRROR( m_start0.y, aCentre.y ); - MIRROR( m_end0.y, aCentre.y ); - MIRROR( m_arcCenter0.y, aCentre.y ); - MIRROR( m_bezierC1_0.y, aCentre.y ); - MIRROR( m_bezierC2_0.y, aCentre.y ); - } - else - { - MIRROR( m_start0.x, aCentre.x ); - MIRROR( m_end0.x, aCentre.x ); - MIRROR( m_arcCenter0.x, aCentre.x ); - MIRROR( m_bezierC1_0.x, aCentre.x ); - MIRROR( m_bezierC2_0.x, aCentre.x ); - } - - if( GetShape() == SHAPE_T::ARC ) - { - std::swap( m_start, m_end ); - std::swap( m_start0, m_end0 ); - } - - if( GetShape() == SHAPE_T::BEZIER ) - RebuildBezierToSegmentsPointsList( GetWidth() ); - - break; - - case SHAPE_T::POLY: - m_poly.Mirror( !aMirrorAroundXAxis, aMirrorAroundXAxis, aCentre ); - break; - - default: - UNIMPLEMENTED_FOR( SHAPE_T_asString() ); - } - - SetDrawCoord(); -} - - -void FP_SHAPE::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) -{ - // We should rotate the relative coordinates, but to avoid duplicate code do the base class - // rotation of draw coordinates, which is acceptable because in the footprint editor - // m_Pos0 = m_Pos - PCB_SHAPE::Rotate( aRotCentre, aAngle ); - - // and now update the relative coordinates, which are the reference in most transforms. - SetLocalCoord(); -} - - -void FP_SHAPE::Move( const VECTOR2I& aMoveVector ) -{ - // Move an edge of the footprint. - // This is a footprint shape modification. - - switch( GetShape() ) - { - case SHAPE_T::ARC: - case SHAPE_T::SEGMENT: - case SHAPE_T::RECT: - case SHAPE_T::CIRCLE: - case SHAPE_T::BEZIER: - m_start0 += aMoveVector; - m_end0 += aMoveVector; - m_arcCenter0 += aMoveVector; - m_bezierC1_0 += aMoveVector; - m_bezierC2_0 += aMoveVector; - break; - - case SHAPE_T::POLY: - // polygon corners coordinates are always relative to the - // footprint position, orientation 0 - m_poly.Move( VECTOR2I( aMoveVector ) ); - - break; - - default: - UNIMPLEMENTED_FOR( SHAPE_T_asString() ); - } - - SetDrawCoord(); -} - - -double FP_SHAPE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const -{ - constexpr double HIDE = std::numeric_limits::max(); - - if( !aView ) - return 0; - - // Handle Render tab switches - if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) ) - return HIDE; - - if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) ) - return HIDE; - - // Other layers are shown without any conditions - return 0.0; -} - - -wxString FP_SHAPE::GetParentAsString() const -{ - if( FOOTPRINT* fp = dynamic_cast( m_parent ) ) - return fp->GetReference(); - - return m_parent->m_Uuid.AsString(); -} - - -static struct FP_SHAPE_DESC -{ - FP_SHAPE_DESC() - { - PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); - REGISTER_TYPE( FP_SHAPE ); - propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.InheritsAfter( TYPE_HASH( FP_SHAPE ), TYPE_HASH( BOARD_ITEM ) ); - propMgr.InheritsAfter( TYPE_HASH( FP_SHAPE ), TYPE_HASH( EDA_SHAPE ) ); - propMgr.InheritsAfter( TYPE_HASH( FP_SHAPE ), TYPE_HASH( PCB_SHAPE ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Parent" ), - NO_SETTER( FP_SHAPE, wxString ), &FP_SHAPE::GetParentAsString ) ) - .SetIsHiddenFromLibraryEditors(); - } -} _FP_SHAPE_DESC; diff --git a/pcbnew/fp_shape.h b/pcbnew/fp_shape.h deleted file mode 100644 index 171e543663..0000000000 --- a/pcbnew/fp_shape.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2013 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. - * - * 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 FP_SHAPE_H -#define FP_SHAPE_H - - -#include - - -class LINE_READER; -class MSG_PANEL_ITEM; - - -class FP_SHAPE : public PCB_SHAPE -{ -public: - FP_SHAPE( FOOTPRINT* aParent, SHAPE_T aShape = SHAPE_T::SEGMENT, - KICAD_T aItemType = PCB_FP_SHAPE_T ); - - // Do not create a copy constructor & operator=. - // The ones generated by the compiler are adequate. - - ~FP_SHAPE(); - - static inline bool ClassOf( const EDA_ITEM* aItem ) - { - return aItem && PCB_FP_SHAPE_T == aItem->Type(); - } - - bool IsType( const std::vector& aScanTypes ) const override - { - if( PCB_SHAPE::IsType( aScanTypes ) ) - return true; - - // No special processing above and beyond PCB_SHAPE at present.... - - return false; - } - - /** - * Sets the angle for arcs, and normalizes it within the range 0 - 360 degrees. - * @param aAngle is tenths of degrees, but will soon be degrees. - */ - void SetArcAngleAndEnd0( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle = false ); - - void SetArcGeometry0( const VECTOR2I& aStart, const VECTOR2I& aMid, const VECTOR2I& aEnd ); - - void Move( const VECTOR2I& aMoveVector ) override; - - /** - * Mirror horizontally or vertically. Do not change the layer. - */ - void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ) override; - - void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override; - - /** - * Flip entity relative to aCentre. - * The item is mirrored, and layer changed to the paired corresponding layer if it is on a - * paired layer. - * This function should be called only from FOOTPRINT::Flip because it is not usual to flip - * an item alone, without flipping the parent footprint (consider Mirror() instead). - */ - void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override; - - bool IsParentFlipped() const; - - void SetStart0( const VECTOR2I& aPoint ) { m_start0 = aPoint; } - const VECTOR2I& GetStart0() const { return m_start0; } - - void SetEnd0( const VECTOR2I& aPoint ) { m_end0 = aPoint; } - const VECTOR2I& GetEnd0() const { return m_end0; } - - void SetBezierC1_0( const VECTOR2I& aPoint ) { m_bezierC1_0 = aPoint; } - const VECTOR2I& GetBezierC1_0() const { return m_bezierC1_0; } - - void SetBezierC2_0( const VECTOR2I& aPoint ) { m_bezierC2_0 = aPoint; } - const VECTOR2I& GetBezierC2_0() const { return m_bezierC2_0; } - - VECTOR2I GetCenter0() const; - void SetCenter0( const VECTOR2I& aPt ); - - VECTOR2I GetArcMid0() const; - - /** - * Set relative coordinates from draw coordinates. - * Call in only when the geometry or the footprint is modified and therefore the relative - * coordinates have to be updated from the draw coordinates. - */ - virtual void SetLocalCoord(); - - /** - * Set draw coordinates (absolute values ) from relative coordinates. - * Must be called when a relative coordinate has changed in order to see the changes on screen - */ - virtual void SetDrawCoord(); - - void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; - - wxString GetClass() const override - { - return wxT( "MGRAPHIC" ); - } - - wxString GetParentAsString() const; - - wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override; - - BITMAPS GetMenuImage() const override; - - EDA_ITEM* Clone() const override; - - double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; - -#if defined(DEBUG) - void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } -#endif - -protected: - VECTOR2I m_start0; ///< Start point or circle center, relative to footprint origin, orient 0. - VECTOR2I m_end0; ///< End point or circle edge, relative to footprint origin, orient 0. - VECTOR2I m_arcCenter0; ///< Center of arc, relative to footprint origin, orient 0. - VECTOR2I m_bezierC1_0; ///< Bezier Control Point 1, relative to footprint origin, orient 0. - VECTOR2I m_bezierC2_0; ///< Bezier Control Point 2, relative to footprint origin, orient 0. - - ARC_MID m_arcMidData_0; ///< Originating Arc data, orient 0 -}; - -#endif // FP_SHAPE_H diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp deleted file mode 100644 index 851dc4754d..0000000000 --- a/pcbnew/fp_text.cpp +++ /dev/null @@ -1,534 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. - * - * 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 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -FP_TEXT::FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type ) : - BOARD_ITEM( aParentFootprint, PCB_FP_TEXT_T ), - EDA_TEXT( pcbIUScale ) -{ - FOOTPRINT* parentFootprint = static_cast( m_parent ); - - m_Type = text_type; - SetKeepUpright( true ); - - // Set text thickness to a default value - SetTextThickness( pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ) ); - SetLayer( F_SilkS ); - - // Set position and give a default layer if a valid parent footprint exists - if( parentFootprint && parentFootprint->Type() == PCB_FOOTPRINT_T ) - { - SetTextPos( parentFootprint->GetPosition() ); - - if( IsBackLayer( parentFootprint->GetLayer() ) ) - { - SetLayer( B_SilkS ); - SetMirrored( true ); - } - } - - SetDrawCoord(); -} - - -FP_TEXT::~FP_TEXT() -{ -} - - -bool FP_TEXT::TextHitTest( const VECTOR2I& aPoint, int aAccuracy ) const -{ - BOX2I rect = GetTextBox(); - VECTOR2I location = aPoint; - - rect.Inflate( aAccuracy ); - - RotatePoint( location, GetTextPos(), -GetDrawRotation() ); - - return rect.Contains( location ); -} - - -bool FP_TEXT::TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const -{ - BOX2I rect = aRect; - - rect.Inflate( aAccuracy ); - - if( aContains ) - return rect.Contains( GetBoundingBox() ); - else - return rect.Intersects( GetTextBox(), GetDrawRotation() ); -} - - -void FP_TEXT::KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation ) -{ - if( !IsKeepUpright() ) - return; - - EDA_ANGLE newAngle = GetTextAngle() + aNewOrientation; - newAngle.Normalize(); - - bool needsFlipped = newAngle >= ANGLE_180; - - if( needsFlipped ) - { - SetHorizJustify( static_cast( -GetHorizJustify() ) ); - SetTextAngle( GetTextAngle() + ANGLE_180 ); - SetDrawCoord(); - } -} - - -void FP_TEXT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) -{ - // Used in footprint editing - // Note also in footprint editor, m_Pos0 = m_Pos - - VECTOR2I pt = GetTextPos(); - RotatePoint( pt, aRotCentre, aAngle ); - SetTextPos( pt ); - - EDA_ANGLE new_angle = GetTextAngle() + aAngle; - new_angle.Normalize180(); - SetTextAngle( new_angle ); - - SetLocalCoord(); -} - - -void FP_TEXT::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) -{ - // flipping the footprint is relative to the X axis - if( aFlipLeftRight ) - { - SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) ); - SetTextAngle( -GetTextAngle() ); - } - else - { - SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) ); - SetTextAngle( ANGLE_180 - GetTextAngle() ); - } - - SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) ); - - if( ( GetLayerSet() & LSET::SideSpecificMask() ).any() ) - SetMirrored( !IsMirrored() ); - - SetLocalCoord(); -} - -bool FP_TEXT::IsParentFlipped() const -{ - if( GetParent() && GetParent()->GetLayer() == B_Cu ) - return true; - return false; -} - - -void FP_TEXT::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ) -{ - // the position and justification are mirrored, but not the text itself - - if( aMirrorAroundXAxis ) - { - if( GetTextAngle() == ANGLE_VERTICAL ) - SetHorizJustify( (GR_TEXT_H_ALIGN_T) -GetHorizJustify() ); - - SetTextY( ::MIRRORVAL( GetTextPos().y, aCentre.y ) ); - } - else - { - if( GetTextAngle() == ANGLE_HORIZONTAL ) - SetHorizJustify( (GR_TEXT_H_ALIGN_T) -GetHorizJustify() ); - - SetTextX( ::MIRRORVAL( GetTextPos().x, aCentre.x ) ); - } - - SetLocalCoord(); -} - - -void FP_TEXT::Move( const VECTOR2I& aMoveVector ) -{ - Offset( aMoveVector ); - SetLocalCoord(); -} - - -int FP_TEXT::GetLength() const -{ - return GetText().Len(); -} - - -void FP_TEXT::SetDrawCoord() -{ - const FOOTPRINT* parentFootprint = static_cast( m_parent ); - - SetTextPos( m_Pos0 ); - - if( parentFootprint ) - { - VECTOR2I pt = GetTextPos(); - RotatePoint( pt, parentFootprint->GetOrientation() ); - SetTextPos( pt ); - - Offset( parentFootprint->GetPosition() ); - } -} - - -void FP_TEXT::SetLocalCoord() -{ - const FOOTPRINT* parentFootprint = static_cast( m_parent ); - - if( parentFootprint ) - { - m_Pos0 = GetTextPos() - parentFootprint->GetPosition(); - RotatePoint( &m_Pos0.x, &m_Pos0.y, - parentFootprint->GetOrientation() ); - } - else - { - m_Pos0 = GetTextPos(); - } -} - -const BOX2I FP_TEXT::GetBoundingBox() const -{ - EDA_ANGLE angle = GetDrawRotation(); - BOX2I bbox = GetTextBox(); - - if( !angle.IsZero() ) - bbox = bbox.GetBoundingBoxRotated( GetTextPos(), angle ); - - return bbox; -} - - -EDA_ANGLE FP_TEXT::GetDrawRotation() const -{ - FOOTPRINT* parentFootprint = static_cast( m_parent ); - EDA_ANGLE rotation = GetTextAngle(); - - if( parentFootprint ) - rotation += parentFootprint->GetOrientation(); - - if( IsKeepUpright() ) - { - // Keep angle between ]-90 .. 90 deg]. Otherwise the text is not easy to read - while( rotation > ANGLE_90 ) - rotation -= ANGLE_180; - - while( rotation <= -ANGLE_90 ) - rotation += ANGLE_180; - } - else - { - rotation.Normalize(); - } - - return rotation; -} - - -void FP_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) -{ - wxString msg; - - static const wxString text_type_msg[3] = - { - _( "Reference" ), _( "Value" ), _( "Text" ) - }; - - if( aFrame->GetName() == PCB_EDIT_FRAME_NAME ) - { - FOOTPRINT* fp = static_cast( m_parent ); - - if( fp ) - aList.emplace_back( _( "Footprint" ), fp->GetReference() ); - } - - // Don't use GetShownText() here; we want to show the user the variable references - aList.emplace_back( _( "Text" ), UnescapeString( GetText() ) ); - - wxASSERT( m_Type >= TEXT_is_REFERENCE && m_Type <= TEXT_is_DIVERS ); - aList.emplace_back( _( "Type" ), text_type_msg[m_Type] ); - - if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() ) - aList.emplace_back( _( "Status" ), _( "Locked" ) ); - - aList.emplace_back( _( "Display" ), IsVisible() ? _( "Yes" ) : _( "No" ) ); - - // Display text layer - aList.emplace_back( _( "Layer" ), GetLayerName() ); - - aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) ); - - msg.Printf( wxT( "%g" ), GetTextAngle().AsDegrees() ); - aList.emplace_back( _( "Angle" ), msg ); - - aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); - aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); - aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); - aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) ); -} - - -wxString FP_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const -{ - switch( m_Type ) - { - case TEXT_is_REFERENCE: - return wxString::Format( _( "Reference '%s'" ), - static_cast( GetParent() )->GetReference() ); - - case TEXT_is_VALUE: - return wxString::Format( _( "Value '%s' of %s" ), - GetShownText(), - static_cast( GetParent() )->GetReference() ); - - default: - return wxString::Format( _( "Footprint Text '%s' of %s" ), - KIUI::EllipsizeMenuText( GetShownText() ), - static_cast( GetParent() )->GetReference() ); - } -} - - -BITMAPS FP_TEXT::GetMenuImage() const -{ - return BITMAPS::text; -} - - -EDA_ITEM* FP_TEXT::Clone() const -{ - return new FP_TEXT( *this ); -} - - -const BOX2I FP_TEXT::ViewBBox() const -{ - EDA_ANGLE angle = GetDrawRotation(); - BOX2I text_area = GetTextBox(); - - if( !angle.IsZero() ) - text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle ); - - return BOX2I( text_area.GetPosition(), text_area.GetSize() ); -} - - -void FP_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const -{ - if( IsVisible() ) - aLayers[0] = GetLayer(); - else - aLayers[0] = LAYER_MOD_TEXT_INVISIBLE; - - aCount = 1; -} - - -double FP_TEXT::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const -{ - constexpr double HIDE = (double)std::numeric_limits::max(); - - if( !aView ) - return 0.0; - - // Hidden text gets put on the LAYER_MOD_TEXT_INVISIBLE for rendering, but - // should only render if its native layer is visible. - if( !aView->IsLayerVisible( GetLayer() ) ) - return HIDE; - - // Handle Render tab switches - if( m_Type == TEXT_is_VALUE || GetText() == wxT( "${VALUE}" ) ) - { - if( !aView->IsLayerVisible( LAYER_MOD_VALUES ) ) - { - return HIDE; - } - } - - if( m_Type == TEXT_is_REFERENCE || GetText() == wxT( "${REFERENCE}" ) ) - { - if( !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) ) - { - return HIDE; - } - } - - if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) ) - return HIDE; - - if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) ) - return HIDE; - - if( !aView->IsLayerVisible( LAYER_MOD_TEXT ) ) - return HIDE; - - // Other layers are shown without any conditions - return 0.0; -} - - -wxString FP_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const -{ - const FOOTPRINT* parentFootprint = static_cast( GetParent() ); - - std::function footprintResolver = - [&]( wxString* token ) -> bool - { - return parentFootprint && parentFootprint->ResolveTextVar( token, aDepth ); - }; - - wxString text = EDA_TEXT::GetShownText(); - - if( HasTextVars() ) - { - if( aDepth < 10 ) - text = ExpandTextVars( text, &footprintResolver ); - } - - return text; -} - - -std::shared_ptr FP_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const -{ - if( IsKnockout() ) - { - SHAPE_POLY_SET knockouts; - - TransformTextToPolySet( knockouts, aLayer, 0, GetBoard()->GetDesignSettings().m_MaxError, - ERROR_INSIDE ); - - SHAPE_POLY_SET finalPoly; - int strokeWidth = GetEffectiveTextPenWidth(); - VECTOR2I fontSize = GetTextSize(); - int margin = strokeWidth * 1.5 + GetKnockoutTextMargin( fontSize, strokeWidth ); - - TransformBoundingBoxToPolygon( &finalPoly, margin ); - finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST ); - finalPoly.Fracture( SHAPE_POLY_SET::PM_FAST ); - - return std::make_shared( finalPoly ); - } - - return GetEffectiveTextShape(); -} - - -void FP_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, - int aError, ERROR_LOC aErrorLoc ) const -{ - KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = getDrawFont(); - int penWidth = GetEffectiveTextPenWidth(); - - // The polygonal shape of a text can have many basic shapes, so combining these shapes can - // be very useful to create a final shape with a lot less vertices to speedup calculations. - // Simplify shapes is not usually always efficient, but in this case it is. - SHAPE_POLY_SET buffer; - - CALLBACK_GAL callback_gal( empty_opts, - // Stroke callback - [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 ) - { - TransformOvalToPolygon( buffer, aPt1, aPt2, penWidth + ( 2 * aClearance ), aError, - ERROR_INSIDE ); - }, - // Triangulation callback - [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 ) - { - buffer.NewOutline(); - - for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } ) - buffer.Append( point.x, point.y ); - } ); - - TEXT_ATTRIBUTES attrs = GetAttributes(); - attrs.m_Angle = GetDrawRotation(); - - font->Draw( &callback_gal, GetShownText(), GetTextPos(), attrs ); - - buffer.Simplify( SHAPE_POLY_SET::PM_FAST ); - aBuffer.Append( buffer ); -} - - -void FP_TEXT::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, - int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth ) const -{ - SHAPE_POLY_SET buffer; - - EDA_TEXT::TransformBoundingBoxToPolygon( &buffer, aClearance ); - aBuffer.Append( buffer ); -} - - -wxString FP_TEXT::GetParentAsString() const -{ - if( FOOTPRINT* fp = dynamic_cast( m_parent ) ) - return fp->GetReference(); - - return m_parent->m_Uuid.AsString(); -} - - -static struct FP_TEXT_DESC -{ - FP_TEXT_DESC() - { - PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); - REGISTER_TYPE( FP_TEXT ); - propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.InheritsAfter( TYPE_HASH( FP_TEXT ), TYPE_HASH( BOARD_ITEM ) ); - propMgr.InheritsAfter( TYPE_HASH( FP_TEXT ), TYPE_HASH( EDA_TEXT ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Parent" ), - NO_SETTER( FP_TEXT, wxString ), &FP_TEXT::GetParentAsString ) ) - .SetIsHiddenFromLibraryEditors(); - } -} _FP_TEXT_DESC; diff --git a/pcbnew/fp_text.h b/pcbnew/fp_text.h deleted file mode 100644 index b459777e9e..0000000000 --- a/pcbnew/fp_text.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. - * - * 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 FP_TEXT_H -#define FP_TEXT_H - -#include -#include - -class LINE_READER; -class FOOTPRINT; -class MSG_PANEL_ITEM; -class PCB_BASE_FRAME; -class SHAPE; - - -class FP_TEXT : public BOARD_ITEM, public EDA_TEXT -{ -public: - /** - * Footprint text type: there must be only one (and only one) for each of the reference - * value texts in one footprint; others could be added for the user (DIVERS is French for - * 'others'). Reference and value always live on silkscreen (on the footprint side); other - * texts are planned to go on whatever layer the user wants. - */ - enum TEXT_TYPE - { - TEXT_is_REFERENCE = 0, - TEXT_is_VALUE = 1, - TEXT_is_DIVERS = 2 - }; - - FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type = TEXT_is_DIVERS ); - - // Do not create a copy constructor & operator=. - // The ones generated by the compiler are adequate. - - ~FP_TEXT(); - - static inline bool ClassOf( const EDA_ITEM* aItem ) - { - return aItem && aItem->Type() == PCB_FP_TEXT_T; - } - - bool IsType( const std::vector& aScanTypes ) const override - { - if( BOARD_ITEM::IsType( aScanTypes ) ) - return true; - - for( KICAD_T scanType : aScanTypes ) - { - if( scanType == PCB_LOCATE_TEXT_T ) - return true; - } - - return false; - } - - wxString GetParentAsString() const; - - bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override - { - return BOARD_ITEM::Matches( GetShownText(), aSearchData ); - } - - virtual VECTOR2I GetPosition() const override - { - return EDA_TEXT::GetTextPos(); - } - - virtual void SetPosition( const VECTOR2I& aPos ) override - { - EDA_TEXT::SetTextPos( aPos ); - SetLocalCoord(); - } - - /** - * Called when rotating the parent footprint. - */ - void KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation ); - - void Rotate( const VECTOR2I& aOffset, const EDA_ANGLE& aAngle ) override; - - /// Flip entity during footprint flip - void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override; - - bool IsParentFlipped() const; - - /** - * Mirror text position. Do not mirror the text itself, or change its layer. - */ - void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ); - - void Move( const VECTOR2I& aMoveVector ) override; - - /// @deprecated it seems (but the type is used to 'protect' reference and value from deletion, - /// and for identification) - void SetType( TEXT_TYPE aType ) { m_Type = aType; } - TEXT_TYPE GetType() const { return m_Type; } - - // The Pos0 accessors are for footprint-relative coordinates. - void SetPos0( const VECTOR2I& aPos ) { m_Pos0 = aPos; SetDrawCoord(); } - const VECTOR2I& GetPos0() const { return m_Pos0; } - - int GetLength() const; // text length - - /** - * @return the text rotation for drawings and plotting the footprint rotation is taken - * in account. - */ - virtual EDA_ANGLE GetDrawRotation() const override; - - // Virtual function - const BOX2I GetBoundingBox() const override; - - ///< Set absolute coordinates. - void SetDrawCoord(); - - ///< Set relative coordinates. - void SetLocalCoord(); - - void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; - - bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const override; - bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const override; - - bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override - { - return TextHitTest( aPosition, aAccuracy ); - } - - bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override - { - return TextHitTest( aRect, aContained, aAccuracy ); - } - - void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, - int aError, ERROR_LOC aErrorLoc, - bool aIgnoreLineWidth ) const override; - - void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, - int aError, ERROR_LOC aErrorLoc ) const; - - // @copydoc BOARD_ITEM::GetEffectiveShape - std::shared_ptr GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER, - FLASHING aFlash = FLASHING::DEFAULT ) const override; - - wxString GetClass() const override - { - return wxT( "FP_TEXT" ); - } - - wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override; - - BITMAPS GetMenuImage() const override; - - EDA_ITEM* Clone() const override; - - virtual wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override; - - virtual const BOX2I ViewBBox() const override; - - virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; - - double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; - -#if defined(DEBUG) - virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } -#endif - -private: - TEXT_TYPE m_Type; ///< 0=ref, 1=val, etc. - - VECTOR2I m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0. - ///< text coordinate ref point is the text center -}; - -#endif // FP_TEXT_H diff --git a/pcbnew/fp_text_grid_table.cpp b/pcbnew/fp_text_grid_table.cpp index ba9c64a448..dce4154370 100644 --- a/pcbnew/fp_text_grid_table.cpp +++ b/pcbnew/fp_text_grid_table.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "grid_layer_box_helpers.h" enum @@ -193,8 +194,8 @@ wxGridCellAttr* FP_TEXT_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr: wxString FP_TEXT_GRID_TABLE::GetValue( int aRow, int aCol ) { - wxGrid* grid = GetView(); - const FP_TEXT& text = this->at( (size_t) aRow ); + wxGrid* grid = GetView(); + const PCB_TEXT& text = this->at( (size_t) aRow ); if( grid->GetGridCursorRow() == aRow && grid->GetGridCursorCol() == aCol && grid->IsCellEditControlShown() ) @@ -223,13 +224,16 @@ wxString FP_TEXT_GRID_TABLE::GetValue( int aRow, int aCol ) return text.GetLayerName(); case FPT_ORIENTATION: - return m_frame->StringFromValue( text.GetTextAngle(), true ); + { + EDA_ANGLE angle = text.GetTextAngle() - text.GetParentFootprint()->GetOrientation(); + return m_frame->StringFromValue( angle, true ); + } case FPT_XOFFSET: - return m_frame->StringFromValue( text.GetPos0().x, true ); + return m_frame->StringFromValue( text.GetFPRelativePosition().x, true ); case FPT_YOFFSET: - return m_frame->StringFromValue( text.GetPos0().y, true ); + return m_frame->StringFromValue( text.GetFPRelativePosition().y, true ); default: // we can't assert here because wxWidgets sometimes calls this without checking @@ -241,7 +245,7 @@ wxString FP_TEXT_GRID_TABLE::GetValue( int aRow, int aCol ) bool FP_TEXT_GRID_TABLE::GetValueAsBool( int aRow, int aCol ) { - FP_TEXT& text = this->at( (size_t) aRow ); + PCB_TEXT& text = this->at( (size_t) aRow ); switch( aCol ) { @@ -258,7 +262,7 @@ bool FP_TEXT_GRID_TABLE::GetValueAsBool( int aRow, int aCol ) long FP_TEXT_GRID_TABLE::GetValueAsLong( int aRow, int aCol ) { - FP_TEXT& text = this->at( (size_t) aRow ); + PCB_TEXT& text = this->at( (size_t) aRow ); switch( aCol ) { @@ -273,9 +277,9 @@ long FP_TEXT_GRID_TABLE::GetValueAsLong( int aRow, int aCol ) void FP_TEXT_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) { - FP_TEXT& text = this->at( (size_t) aRow ); - VECTOR2I pos; - wxString value = aValue; + PCB_TEXT& text = this->at( (size_t) aRow ); + VECTOR2I pos; + wxString value = aValue; switch( aCol ) { @@ -317,21 +321,20 @@ void FP_TEXT_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) break; case FPT_ORIENTATION: - text.SetTextAngle( m_frame->AngleValueFromString( value ) ); - text.SetDrawCoord(); + text.SetTextAngle( m_frame->AngleValueFromString( value ) + + text.GetParentFootprint()->GetOrientation() ); break; case FPT_XOFFSET: case FPT_YOFFSET: - pos = text.GetPos0(); + pos = text.GetFPRelativePosition(); if( aCol == FPT_XOFFSET ) pos.x = m_frame->ValueFromString( value ); else pos.y = m_frame->ValueFromString( value ); - text.SetPos0( pos ); - text.SetDrawCoord(); + text.SetFPRelativePosition( pos ); break; default: @@ -345,7 +348,7 @@ void FP_TEXT_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) void FP_TEXT_GRID_TABLE::SetValueAsBool( int aRow, int aCol, bool aValue ) { - FP_TEXT& text = this->at( (size_t) aRow ); + PCB_TEXT& text = this->at( (size_t) aRow ); switch( aCol ) { @@ -369,7 +372,7 @@ void FP_TEXT_GRID_TABLE::SetValueAsBool( int aRow, int aCol, bool aValue ) void FP_TEXT_GRID_TABLE::SetValueAsLong( int aRow, int aCol, long aValue ) { - FP_TEXT& text = this->at( (size_t) aRow ); + PCB_TEXT& text = this->at( (size_t) aRow ); switch( aCol ) { diff --git a/pcbnew/fp_text_grid_table.h b/pcbnew/fp_text_grid_table.h index 55d32cdcb9..3164fcc9fb 100644 --- a/pcbnew/fp_text_grid_table.h +++ b/pcbnew/fp_text_grid_table.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,10 +26,9 @@ #include #include -#include +#include -class FOOTPRINT; class PCB_BASE_FRAME; enum FP_TEXT_COL_ORDER @@ -50,7 +49,7 @@ enum FP_TEXT_COL_ORDER }; -class FP_TEXT_GRID_TABLE : public wxGridTableBase, public std::vector +class FP_TEXT_GRID_TABLE : public wxGridTableBase, public std::vector { public: FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame ); diff --git a/pcbnew/fp_textbox.cpp b/pcbnew/fp_textbox.cpp deleted file mode 100644 index eaed0b5c42..0000000000 --- a/pcbnew/fp_textbox.cpp +++ /dev/null @@ -1,614 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors. - * - * 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 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -FP_TEXTBOX::FP_TEXTBOX( FOOTPRINT* aParentFootprint ) : - FP_SHAPE( aParentFootprint, SHAPE_T::RECT, PCB_FP_TEXTBOX_T ), - EDA_TEXT( pcbIUScale ) -{ - SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); - SetVertJustify( GR_TEXT_V_ALIGN_TOP ); - SetMultilineAllowed( true ); - - SetDrawCoord(); -} - - -FP_TEXTBOX::~FP_TEXTBOX() -{ -} - - -int FP_TEXTBOX::GetTextMargin() const -{ - return KiROUND( GetStroke().GetWidth() / 2.0 ) + KiROUND( GetTextSize().y * 0.75 ); -} - - -VECTOR2I FP_TEXTBOX::GetTopLeft() const -{ - EDA_ANGLE rotation = GetDrawRotation(); - - if( rotation == ANGLE_90 ) - return VECTOR2I( GetStartX(), GetEndY() ); - else if( rotation == ANGLE_180 ) - return GetEnd(); - else if( rotation == ANGLE_270 ) - return VECTOR2I( GetEndX(), GetStartY() ); - else - return GetStart(); -} - - -VECTOR2I FP_TEXTBOX::GetBotRight() const -{ - EDA_ANGLE rotation = GetDrawRotation(); - - if( rotation == ANGLE_90 ) - return VECTOR2I( GetEndX(), GetStartY() ); - else if( rotation == ANGLE_180 ) - return GetStart(); - else if( rotation == ANGLE_270 ) - return VECTOR2I( GetStartX(), GetEndY() ); - else - return GetEnd(); -} - - -void FP_TEXTBOX::SetTop( int aVal ) -{ - EDA_ANGLE rotation = GetDrawRotation(); - - if( rotation == ANGLE_90 || rotation == ANGLE_180 ) - SetEndY( aVal ); - else - SetStartY( aVal ); -} - - -void FP_TEXTBOX::SetBottom( int aVal ) -{ - EDA_ANGLE rotation = GetDrawRotation(); - - if( rotation == ANGLE_90 || rotation == ANGLE_180 ) - SetStartY( aVal ); - else - SetEndY( aVal ); -} - - -void FP_TEXTBOX::SetLeft( int aVal ) -{ - EDA_ANGLE rotation = GetDrawRotation(); - - if( rotation == ANGLE_180 || rotation == ANGLE_270 ) - SetEndX( aVal ); - else - SetStartX( aVal ); -} - - -void FP_TEXTBOX::SetRight( int aVal ) -{ - EDA_ANGLE rotation = GetDrawRotation(); - - if( rotation == ANGLE_180 || rotation == ANGLE_270 ) - SetStartX( aVal ); - else - SetEndX( aVal ); -} - - -void FP_TEXTBOX::SetTextAngle( const EDA_ANGLE& aAngle ) -{ - EDA_ANGLE delta = aAngle.Normalized() - GetTextAngle(); - Rotate( GetPosition(), delta ); -} - - -std::vector FP_TEXTBOX::GetCorners() const -{ - std::vector pts = FP_SHAPE::GetCorners(); - - // SHAPE_T::POLY doesn't use the DrawCoord/LocalCoord architecture and instead stores fully - // resolved points (ie: relative to the board, not parent footprint). - if( GetShape() == SHAPE_T::POLY ) - { - if( FOOTPRINT* parentFootprint = PCB_SHAPE::GetParentFootprint() ) - { - for( VECTOR2I& pt : pts ) - RotatePoint( pt, parentFootprint->GetPosition(), parentFootprint->GetOrientation() ); - } - } - - return pts; -} - - -EDA_ANGLE FP_TEXTBOX::GetDrawRotation() const -{ - EDA_ANGLE rotation = GetTextAngle(); - - if( FOOTPRINT* parentFootprint = PCB_SHAPE::GetParentFootprint() ) - rotation += parentFootprint->GetOrientation(); - - rotation.Normalize(); - - return rotation; -} - - -std::vector FP_TEXTBOX::GetNormalizedCorners() const -{ - std::vector corners = GetCorners(); - EDA_ANGLE textAngle( GetDrawRotation() ); - - if( FOOTPRINT* parentFootprint = PCB_SHAPE::GetParentFootprint() ) - { - if( parentFootprint->IsFlipped() ) - std::swap( corners[1], corners[3] ); - } - - textAngle.Normalize(); - - if( textAngle < ANGLE_90 ) - { - if( corners[1].y > corners[0].y ) - std::swap( corners[1], corners[3] ); - } - else if( textAngle < ANGLE_180 ) - { - if( corners[1].x > corners[0].x ) - std::swap( corners[1], corners[3] ); - } - else if( textAngle < ANGLE_270 ) - { - if( corners[1].y < corners[0].y ) - std::swap( corners[1], corners[3] ); - } - else - { - if( corners[1].x < corners[0].x ) - std::swap( corners[1], corners[3] ); - } - - return corners; -} - - -VECTOR2I FP_TEXTBOX::GetDrawPos() const -{ - std::vector corners = GetNormalizedCorners(); - GR_TEXT_H_ALIGN_T effectiveAlignment = GetHorizJustify(); - VECTOR2I textAnchor; - VECTOR2I vMargin; - VECTOR2I hMargin; - bool isFlipped = false; - - if( FOOTPRINT* parentFootprint = PCB_SHAPE::GetParentFootprint() ) - isFlipped = parentFootprint->IsFlipped(); - - if( IsMirrored() != isFlipped ) - { - std::swap( corners[0], corners[1] ); - std::swap( corners[2], corners[3] ); - - switch( GetHorizJustify() ) - { - case GR_TEXT_H_ALIGN_LEFT: effectiveAlignment = GR_TEXT_H_ALIGN_RIGHT; break; - case GR_TEXT_H_ALIGN_CENTER: effectiveAlignment = GR_TEXT_H_ALIGN_CENTER; break; - case GR_TEXT_H_ALIGN_RIGHT: effectiveAlignment = GR_TEXT_H_ALIGN_LEFT; break; - } - } - - switch( effectiveAlignment ) - { - case GR_TEXT_H_ALIGN_LEFT: - textAnchor = corners[0]; - vMargin = ( corners[2] - corners[1] ).Resize( GetTextMargin() ); - hMargin = ( corners[1] - corners[0] ).Resize( GetTextMargin() ); - break; - case GR_TEXT_H_ALIGN_CENTER: - textAnchor = ( corners[0] + corners[1] ) / 2; - vMargin = ( corners[2] - corners[1] ).Resize( GetTextMargin() ); - break; - case GR_TEXT_H_ALIGN_RIGHT: - textAnchor = corners[1]; - vMargin = ( corners[2] - corners[1] ).Resize( GetTextMargin() ); - hMargin = ( corners[0] - corners[1] ).Resize( GetTextMargin() ); - break; - } - - return textAnchor + hMargin + vMargin; -} - - -bool FP_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const -{ - BOX2I rect = GetBoundingBox(); - - rect.Inflate( aAccuracy ); - - return rect.Contains( aPosition ); -} - - -bool FP_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const -{ - BOX2I rect = aRect; - - rect.Inflate( aAccuracy ); - - if( aContained ) - return rect.Contains( GetBoundingBox() ); - - return rect.Intersects( GetBoundingBox() ); -} - - -void FP_TEXTBOX::Move( const VECTOR2I& aMoveVector ) -{ - FP_SHAPE::Move( aMoveVector ); - EDA_TEXT::Offset( aMoveVector ); -} - - -void FP_TEXTBOX::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) -{ - FP_SHAPE::Rotate( aRotCentre, aAngle ); - EDA_TEXT::SetTextAngle( ( GetTextAngle() + aAngle ).Normalized() ); -} - - -void FP_TEXTBOX::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) -{ - FP_SHAPE::Flip( aCentre, aFlipLeftRight ); - - // flipping the footprint is relative to the X axis - if( aFlipLeftRight ) - { - SetTextX( MIRRORVAL( GetTextPos().x, aCentre.x ) ); - EDA_TEXT::SetTextAngle( -GetTextAngle() ); - } - else - { - SetTextY( MIRRORVAL( GetTextPos().y, aCentre.y ) ); - EDA_TEXT::SetTextAngle( ANGLE_180 - GetTextAngle() ); - } - - if( ( GetLayerSet() & LSET::SideSpecificMask() ).any() ) - SetMirrored( !IsMirrored() ); - - SetLocalCoord(); -} - - -void FP_TEXTBOX::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ) -{ - // the position is mirrored, but not the text (or its justification) - FP_SHAPE::Mirror( aCentre, aMirrorAroundXAxis ); - - BOX2I rect( m_start0, m_end0 - m_start0 ); - rect.Normalize(); - m_start0 = VECTOR2I( rect.GetLeft(), rect.GetTop() ); - m_end0 = VECTOR2I( rect.GetRight(), rect.GetBottom() ); - - SetDrawCoord(); -} - - -void FP_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) -{ - // Don't use GetShownText() here; we want to show the user the variable references - aList.emplace_back( _( "Text Box" ), UnescapeString( GetText() ) ); - - if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() ) - aList.emplace_back( _( "Status" ), _( "Locked" ) ); - - aList.emplace_back( _( "Layer" ), GetLayerName() ); - aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) ); - aList.emplace_back( _( "Angle" ), wxString::Format( "%g", GetTextAngle().AsDegrees() ) ); - - aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) ); - aList.emplace_back( _( "Thickness" ), aFrame->MessageTextFromValue( GetTextThickness() ) ); - aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) ); - aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) ); - - wxString msg = aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ); - aList.emplace_back( _( "Box Width" ), msg ); - - msg = aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ); - aList.emplace_back( _( "Box Height" ), msg ); - - m_stroke.GetMsgPanelInfo( aFrame, aList ); -} - - -wxString FP_TEXTBOX::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const -{ - return wxString::Format( _( "Footprint Text Box of %s" ), - static_cast( GetParent() )->GetReference() ); -} - - -BITMAPS FP_TEXTBOX::GetMenuImage() const -{ - return BITMAPS::add_textbox; -} - - -EDA_ITEM* FP_TEXTBOX::Clone() const -{ - return new FP_TEXTBOX( *this ); -} - - -void FP_TEXTBOX::ViewGetLayers( int aLayers[], int& aCount ) const -{ - if( IsVisible() ) - aLayers[0] = GetLayer(); - else - aLayers[0] = LAYER_MOD_TEXT_INVISIBLE; - - aCount = 1; -} - - -double FP_TEXTBOX::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const -{ - constexpr double HIDE = (double)std::numeric_limits::max(); - - if( !aView ) - return 0.0; - - // Hidden text gets put on the LAYER_MOD_TEXT_INVISIBLE for rendering, but - // should only render if its native layer is visible. - if( !aView->IsLayerVisible( GetLayer() ) ) - return HIDE; - - RENDER_SETTINGS* renderSettings = aView->GetPainter()->GetSettings(); - COLOR4D backgroundColor = renderSettings->GetLayerColor( LAYER_PCB_BACKGROUND ); - - // Handle Render tab switches - if( renderSettings->GetLayerColor( LAYER_MOD_TEXT ) == backgroundColor ) - return HIDE; - - if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) ) - return HIDE; - - if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) ) - return HIDE; - - if( !aView->IsLayerVisible( LAYER_MOD_TEXT ) ) - return HIDE; - - // Other layers are shown without any conditions - return 0.0; -} - - -wxString FP_TEXTBOX::GetShownText( int aDepth, bool aAllowExtraText ) const -{ - const FOOTPRINT* parentFootprint = static_cast( GetParent() ); - - std::function footprintResolver = - [&]( wxString* token ) -> bool - { - return parentFootprint && parentFootprint->ResolveTextVar( token, aDepth ); - }; - - wxString text = EDA_TEXT::GetShownText(); - - if( HasTextVars() ) - { - if( aDepth < 10 ) - text = ExpandTextVars( text, &footprintResolver ); - } - - KIFONT::FONT* font = getDrawFont(); - std::vector corners = GetNormalizedCorners(); - int colWidth = ( corners[1] - corners[0] ).EuclideanNorm(); - - colWidth -= GetTextMargin() * 2; - font->LinebreakText( text, colWidth, GetTextSize(), GetTextThickness(), IsBold(), IsItalic() ); - - return text; -} - - -std::shared_ptr FP_TEXTBOX::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const -{ - std::shared_ptr shape = GetEffectiveTextShape(); - - if( PCB_SHAPE::GetStroke().GetWidth() >= 0 ) - shape->AddShape( PCB_SHAPE::GetEffectiveShape( aLayer, aFlash ) ); - - return shape; -} - - -void FP_TEXTBOX::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, - int aClearance, int aError, ERROR_LOC aErrorLoc ) const -{ - KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - KIFONT::FONT* font = getDrawFont(); - int penWidth = GetEffectiveTextPenWidth(); - - // Note: this function is mainly used in 3D viewer. - // the polygonal shape of a text can have many basic shapes, - // so combining these shapes can be very useful to create a final shape - // swith a lot less vertices to speedup calculations using this final shape - // Simplify shapes is not usually always efficient, but in this case it is. - SHAPE_POLY_SET buffer; - - CALLBACK_GAL callback_gal( empty_opts, - // Stroke callback - [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 ) - { - TransformOvalToPolygon( buffer, aPt1, aPt2, penWidth + ( 2 * aClearance ), aError, - ERROR_INSIDE ); - }, - // Triangulation callback - [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 ) - { - buffer.NewOutline(); - - for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } ) - buffer.Append( point.x, point.y ); - } ); - - TEXT_ATTRIBUTES attrs = GetAttributes(); - attrs.m_Angle = GetDrawRotation(); - - font->Draw( &callback_gal, GetShownText(), GetDrawPos(), attrs ); - - buffer.Simplify( SHAPE_POLY_SET::PM_FAST ); - aBuffer.Append( buffer ); -} - - -void FP_TEXTBOX::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, - int aClearance, int aError, ERROR_LOC aErrorLoc, - bool aIgnoreLineWidth ) const -{ - // Don't use FP_SHAPE::TransformShapeToPolygon. We want to treat the textbox as filled even - // if there's no background colour. - - int width = GetWidth() + ( 2 * aClearance ); - - switch( m_shape ) - { - case SHAPE_T::RECT: - { - std::vector pts = GetRectCorners(); - - aBuffer.NewOutline(); - - for( const VECTOR2I& pt : pts ) - aBuffer.Append( pt ); - - if( width > 0 ) - { - // Add in segments - TransformOvalToPolygon( aBuffer, pts[0], pts[1], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[1], pts[2], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[2], pts[3], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[3], pts[0], width, aError, aErrorLoc ); - } - - break; - } - - case SHAPE_T::POLY: - { - if( !IsPolyShapeValid() ) - break; - - // The polygon is expected to be a simple polygon; not self intersecting, no hole. - EDA_ANGLE orientation = getParentOrientation(); - VECTOR2I offset = getParentPosition(); - - // Build the polygon with the actual position and orientation: - std::vector poly; - DupPolyPointsList( poly ); - - for( VECTOR2I& point : poly ) - { - RotatePoint( point, orientation ); - point += offset; - } - - aBuffer.NewOutline(); - - for( const VECTOR2I& point : poly ) - aBuffer.Append( point.x, point.y ); - - if( width > 0 ) - { - VECTOR2I pt1( poly[poly.size() - 1] ); - - for( const VECTOR2I& pt2 : poly ) - { - if( pt2 != pt1 ) - TransformOvalToPolygon( aBuffer, pt1, pt2, width, aError, aErrorLoc ); - - pt1 = pt2; - } - } - - break; - } - - default: - UNIMPLEMENTED_FOR( SHAPE_T_asString() ); - break; - } -} - - -wxString FP_TEXTBOX::GetParentAsString() const -{ - if( FOOTPRINT* fp = dynamic_cast( m_parent ) ) - return fp->GetReference(); - - return m_parent->m_Uuid.AsString(); -} - - -static struct FP_TEXTBOX_DESC -{ - FP_TEXTBOX_DESC() - { - PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); - REGISTER_TYPE( FP_TEXTBOX ); - propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.InheritsAfter( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( FP_SHAPE ) ); - propMgr.InheritsAfter( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_TEXT ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Parent" ), - NO_SETTER( FP_TEXTBOX, wxString ), &FP_TEXTBOX::GetParentAsString ) ) - .SetIsHiddenFromLibraryEditors(); - - propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) ); - propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) ); - propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) ); - propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) ); - propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) ); - propMgr.Mask( TYPE_HASH( FP_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) ); - } -} _FP_TEXTBOX_DESC; diff --git a/pcbnew/fp_textbox.h b/pcbnew/fp_textbox.h deleted file mode 100644 index 8356155289..0000000000 --- a/pcbnew/fp_textbox.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. - * - * 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 FP_TEXTBOX_H -#define FP_TEXTBOX_H - -#include -#include - -class LINE_READER; -class FOOTPRINT; -class MSG_PANEL_ITEM; -class PCB_BASE_FRAME; -class SHAPE; - - -class FP_TEXTBOX : public FP_SHAPE, public EDA_TEXT -{ -public: - FP_TEXTBOX( FOOTPRINT* aParentFootprint ); - - // Do not create a copy constructor & operator=. - // The ones generated by the compiler are adequate. - - ~FP_TEXTBOX(); - - static inline bool ClassOf( const EDA_ITEM* aItem ) - { - return aItem && aItem->Type() == PCB_FP_TEXT_T; - } - - bool IsType( const std::vector& aScanTypes ) const override - { - if( BOARD_ITEM::IsType( aScanTypes ) ) - return true; - - for( KICAD_T scanType : aScanTypes ) - { - if( scanType == PCB_LOCATE_TEXT_T ) - return true; - } - - return false; - } - - VECTOR2I GetTopLeft() const override; - VECTOR2I GetBotRight() const override; - - void SetTop( int aVal ) override; - void SetLeft( int aVal ) override; - void SetRight( int aVal ) override; - void SetBottom( int aVal ) override; - - void SetTextAngle( const EDA_ANGLE& aAngle ) override; - - wxString GetParentAsString() const; - - bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override - { - return BOARD_ITEM::Matches( GetShownText(), aSearchData ); - } - - int GetTextMargin() const; - - virtual EDA_ANGLE GetDrawRotation() const override; - - VECTOR2I GetDrawPos() const override; - - std::vector GetCorners() const override; - std::vector GetNormalizedCorners() const; - - void Move( const VECTOR2I& aMoveVector ) override; - - void Rotate( const VECTOR2I& aOffset, const EDA_ANGLE& aAngle ) override; - - void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override; - - /** - * Mirror the textbox's position, but not the text (or its justification). - */ - void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ) override; - - void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; - - bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override; - bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override; - - void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, - int aError, ERROR_LOC aErrorLoc, - bool aIgnoreLineWidth = false ) const override; - - void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, - int aError, ERROR_LOC aErrorLoc ) const; - - // @copydoc BOARD_ITEM::GetEffectiveShape - std::shared_ptr GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER, - FLASHING aFlash = FLASHING::DEFAULT ) const override; - - wxString GetClass() const override - { - return wxT( "FP_TEXTBOX" ); - } - - wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override; - - BITMAPS GetMenuImage() const override; - - EDA_ITEM* Clone() const override; - - virtual wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override; - - virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; - - double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; - -#if defined(DEBUG) - virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } -#endif - -private: - VECTOR2I m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0. - ///< text coordinate ref point is the text center -}; - -#endif // FP_TEXTBOX_H diff --git a/pcbnew/graphics_cleaner.cpp b/pcbnew/graphics_cleaner.cpp index a8e95cfdab..ffba7580d1 100644 --- a/pcbnew/graphics_cleaner.cpp +++ b/pcbnew/graphics_cleaner.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -320,13 +319,7 @@ void GRAPHICS_CLEANER::mergeRects() if( !m_dryRun ) { - PCB_SHAPE* rect; - FP_SHAPE* fp_rect = nullptr; - - if( m_parentFootprint ) - rect = fp_rect = new FP_SHAPE( m_parentFootprint ); - else - rect = new PCB_SHAPE(); + PCB_SHAPE* rect = new PCB_SHAPE( m_parentFootprint ); rect->SetShape( SHAPE_T::RECT ); rect->SetFilled( false ); @@ -335,9 +328,6 @@ void GRAPHICS_CLEANER::mergeRects() rect->SetLayer( top->shape->GetLayer() ); rect->SetStroke( top->shape->GetStroke() ); - if( fp_rect ) - fp_rect->SetLocalCoord(); - m_commit.Add( rect ); m_commit.Remove( left->shape ); m_commit.Remove( top->shape ); @@ -366,13 +356,13 @@ void GRAPHICS_CLEANER::mergePads() if( padToNetTieGroupMap[ pad->GetNumber() ] >= 0 ) continue; - std::vector shapes = padTool->RecombinePad( pad, m_dryRun, m_commit ); + std::vector shapes = padTool->RecombinePad( pad, m_dryRun, m_commit ); if( !shapes.empty() ) { std::shared_ptr item = std::make_shared( CLEANUP_MERGE_PAD ); - for( FP_SHAPE* shape : shapes ) + for( PCB_SHAPE* shape : shapes ) item->AddItem( shape ); item->AddItem( pad ); diff --git a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp index c1075888f2..945ef87d50 100644 --- a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp +++ b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2016 CERN * @author Maciej Suminski - * Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,9 +26,9 @@ #include "graphics_importer_pcbnew.h" #include -#include +#include +#include #include -#include #include #include @@ -71,10 +71,6 @@ void GRAPHICS_IMPORTER_PCBNEW::AddLine( const VECTOR2D& aOrigin, const VECTOR2D& if( line->GetStart() == line->GetEnd() ) return; - - if( line->Type() == PCB_FP_SHAPE_T ) - static_cast( line.get() )->SetLocalCoord(); - addItem( std::move( line ) ); } @@ -90,9 +86,6 @@ void GRAPHICS_IMPORTER_PCBNEW::AddCircle( const VECTOR2D& aCenter, double aRadiu circle->SetStart( MapCoordinate( aCenter )); circle->SetEnd( MapCoordinate( VECTOR2D( aCenter.x + aRadius, aCenter.y ) ) ); - if( circle->Type() == PCB_FP_SHAPE_T ) - static_cast( circle.get() )->SetLocalCoord(); - addItem( std::move( circle ) ); } @@ -118,14 +111,11 @@ void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D& arc->SetStroke( STROKE_PARAMS( MapLineWidth( aWidth ), PLOT_DASH_TYPE::SOLID ) ); - if( arc->Type() == PCB_FP_SHAPE_T ) - static_cast( arc.get() )->SetLocalCoord(); - addItem( std::move( arc ) ); } -void GRAPHICS_IMPORTER_PCBNEW::AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) +void GRAPHICS_IMPORTER_PCBNEW::AddPolygon( const std::vector& aVertices, double aWidth ) { std::vector convertedPoints; convertedPoints.reserve( aVertices.size() ); @@ -139,8 +129,11 @@ void GRAPHICS_IMPORTER_PCBNEW::AddPolygon( const std::vector< VECTOR2D >& aVerti polygon->SetLayer( GetLayer() ); polygon->SetPolyPoints( convertedPoints ); - if( polygon->Type() == PCB_FP_SHAPE_T ) - static_cast( polygon.get() )->SetLocalCoord(); + if( FOOTPRINT* parentFP = polygon->GetParentFootprint() ) + { + polygon->Rotate( { 0, 0 }, parentFP->GetOrientation() ); + polygon->Move( parentFP->GetPosition() ); + } polygon->SetStroke( STROKE_PARAMS( MapLineWidth( aWidth ), PLOT_DASH_TYPE::SOLID ) ); addItem( std::move( polygon ) ); @@ -152,23 +145,18 @@ void GRAPHICS_IMPORTER_PCBNEW::AddText( const VECTOR2D& aOrigin, const wxString& double aOrientation, GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify ) { - std::unique_ptr boardItem; - EDA_TEXT* textItem; - tie( boardItem, textItem ) = createText(); - boardItem->SetLayer( GetLayer() ); + std::unique_ptr textItem = createText(); + textItem->SetLayer( GetLayer() ); textItem->SetTextThickness( MapLineWidth( aThickness ) ); textItem->SetTextPos( MapCoordinate( aOrigin ) ); - textItem->SetTextAngle( EDA_ANGLE( aOrientation, DEGREES_T ) ); // Pcbnew uses the decidegree + textItem->SetTextAngle( EDA_ANGLE( aOrientation, DEGREES_T ) ); textItem->SetTextWidth( aWidth * ImportScalingFactor() ); textItem->SetTextHeight( aHeight * ImportScalingFactor() ); textItem->SetVertJustify( aVJustify ); textItem->SetHorizJustify( aHJustify ); textItem->SetText( aText ); - if( boardItem->Type() == PCB_FP_TEXT_T ) - static_cast( boardItem.get() )->SetLocalCoord(); - - addItem( std::move( boardItem ) ); + addItem( std::move( textItem ) ); } @@ -199,10 +187,6 @@ void GRAPHICS_IMPORTER_PCBNEW::AddSpline( const VECTOR2D& aStart, const VECTOR2D return; } - - if( spline->Type() == PCB_FP_SHAPE_T ) - static_cast( spline.get() )->SetLocalCoord(); - addItem( std::move( spline ) ); } @@ -213,21 +197,19 @@ std::unique_ptr GRAPHICS_IMPORTER_BOARD::createDrawing() } -std::pair, EDA_TEXT*> GRAPHICS_IMPORTER_BOARD::createText() +std::unique_ptr GRAPHICS_IMPORTER_BOARD::createText() { - PCB_TEXT* text = new PCB_TEXT( m_board ); - return make_pair( std::unique_ptr( text ), static_cast( text ) ); + return std::make_unique( m_board ); } std::unique_ptr GRAPHICS_IMPORTER_FOOTPRINT::createDrawing() { - return std::make_unique( m_footprint ); + return std::make_unique( m_footprint ); } -std::pair, EDA_TEXT*> GRAPHICS_IMPORTER_FOOTPRINT::createText() +std::unique_ptr GRAPHICS_IMPORTER_FOOTPRINT::createText() { - FP_TEXT* text = new FP_TEXT( m_footprint ); - return make_pair( std::unique_ptr( text ), static_cast( text ) ); + return std::make_unique( m_footprint, PCB_TEXT::TEXT_is_DIVERS ); } diff --git a/pcbnew/import_gfx/graphics_importer_pcbnew.h b/pcbnew/import_gfx/graphics_importer_pcbnew.h index 1a027070a6..c312c3f9aa 100644 --- a/pcbnew/import_gfx/graphics_importer_pcbnew.h +++ b/pcbnew/import_gfx/graphics_importer_pcbnew.h @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2016 CERN - * Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors. * * @author Maciej Suminski * @@ -31,11 +31,10 @@ #include -class BOARD_ITEM; class BOARD; class FOOTPRINT; class PCB_SHAPE; -class EDA_TEXT; +class PCB_TEXT; class GRAPHICS_IMPORTER_PCBNEW : public GRAPHICS_IMPORTER { @@ -97,9 +96,8 @@ protected: ///< Create an object representing a graphical shape. virtual std::unique_ptr createDrawing() = 0; - ///< Create an object representing a text. Both pointers point to different parts of the - ///< same object, the EDA_TEXT pointer is simply for convenience. - virtual std::pair, EDA_TEXT*> createText() = 0; + ///< Create an object representing a text. + virtual std::unique_ptr createText() = 0; ///< Target layer for the imported shapes. PCB_LAYER_ID m_layer; @@ -116,7 +114,7 @@ public: protected: std::unique_ptr createDrawing() override; - std::pair, EDA_TEXT*> createText() override; + std::unique_ptr createText() override; BOARD* m_board; }; @@ -132,7 +130,7 @@ public: protected: std::unique_ptr createDrawing() override; - std::pair, EDA_TEXT*> createText() override; + std::unique_ptr createText() override; FOOTPRINT* m_footprint; }; diff --git a/pcbnew/kicad_clipboard.cpp b/pcbnew/kicad_clipboard.cpp index 2f762bf07a..7ec951b466 100644 --- a/pcbnew/kicad_clipboard.cpp +++ b/pcbnew/kicad_clipboard.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 KiCad Developers, see AUTHORS.TXT for contributors. - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * @author Kristoffer Ödmark * * This program is free software; you can redistribute it and/or @@ -33,8 +33,6 @@ #include #include #include -#include -#include #include #include #include @@ -113,9 +111,9 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri const PCB_GROUP* group = dynamic_cast( item ); BOARD_ITEM* clone; - if( const FP_TEXT* text = dyn_cast( item ) ) + if( const PCB_TEXT* text = dyn_cast( item ) ) { - if( text->GetType() != FP_TEXT::TEXT_is_DIVERS ) + if( text->GetType() != PCB_TEXT::TEXT_is_DIVERS ) continue; } @@ -133,7 +131,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri partialFootprint.Add( clone ); // A list of not added items, when adding items to the footprint - // some FP_TEXT (reference and value) cannot be added to the footprint + // some PCB_TEXT (reference and value) cannot be added to the footprint std::vector skipped_items; if( group ) @@ -142,12 +140,12 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri [&]( BOARD_ITEM* descendant ) { // One cannot add a text reference or value to a given footprint: - // only one is allowed. So add only FP_TEXT::TEXT_is_DIVERS + // only one is allowed. So add only PCB_TEXT::TEXT_is_DIVERS bool can_add = true; - if( const FP_TEXT* text = dyn_cast( descendant ) ) + if( const PCB_TEXT* text = dyn_cast( descendant ) ) { - if( text->GetType() != FP_TEXT::TEXT_is_DIVERS ) + if( text->GetType() != PCB_TEXT::TEXT_is_DIVERS ) can_add = false; } @@ -197,41 +195,16 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri BOARD_ITEM* item = static_cast( i ); BOARD_ITEM* copy = nullptr; - if( item->Type() == PCB_FP_SHAPE_T ) + if( item->Type() == PCB_TEXT_T ) { - // Convert to PCB_SHAPE_T - copy = (BOARD_ITEM*) reinterpret_cast( item )->Clone(); - copy->SetLayer( item->GetLayer() ); - } - else if( item->Type() == PCB_FP_TEXT_T ) - { - // Convert to PCB_TEXT_T - FOOTPRINT* footprint = static_cast( item->GetParent() ); - FP_TEXT* fp_text = static_cast( item ); - PCB_TEXT* pcb_text = new PCB_TEXT( m_board ); + copy = static_cast( item->Clone() ); - if( fp_text->GetText() == wxT( "${VALUE}" ) ) - pcb_text->SetText( footprint->GetValue() ); - else if( fp_text->GetText() == wxT( "${REFERENCE}" ) ) - pcb_text->SetText( footprint->GetReference() ); - else - pcb_text->CopyText( *fp_text ); + PCB_TEXT* textItem = static_cast( copy ); - pcb_text->SetAttributes( *fp_text ); - pcb_text->SetLayer( fp_text->GetLayer() ); - copy = pcb_text; - } - else if( item->Type() == PCB_FP_TEXTBOX_T ) - { - // Convert to PCB_TEXTBOX_T - FP_TEXTBOX* fp_textbox = static_cast( item ); - PCB_TEXTBOX* pcb_textbox = new PCB_TEXTBOX( m_board ); - - pcb_textbox->CopyText( *fp_textbox ); - - pcb_textbox->SetAttributes( *fp_textbox ); - pcb_textbox->SetLayer( fp_textbox->GetLayer() ); - copy = pcb_textbox; + if( textItem->GetText() == wxT( "${VALUE}" ) ) + textItem->SetText( item->GetParentFootprint()->GetValue() ); + else if( textItem->GetText() == wxT( "${REFERENCE}" ) ) + textItem->SetText( item->GetParentFootprint()->GetReference() ); } else if( item->Type() == PCB_PAD_T ) { @@ -244,13 +217,6 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri footprint->Add( pad ); copy = footprint; } - else if( item->Type() == PCB_FP_ZONE_T ) - { - // Convert to PCB_ZONE_T - ZONE* zone = new ZONE( m_board ); - zone->InitDataFromSrcInCopyCtor( *static_cast( item ) ); - copy = zone; - } else if( item->Type() == PCB_GROUP_T ) { copy = static_cast( item )->DeepClone(); diff --git a/pcbnew/microwave/microwave_inductor.cpp b/pcbnew/microwave/microwave_inductor.cpp index fd7b68a046..5e266d4967 100644 --- a/pcbnew/microwave/microwave_inductor.cpp +++ b/pcbnew/microwave/microwave_inductor.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -417,13 +417,11 @@ FOOTPRINT* MICROWAVE_TOOL::createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN& // Generate segments for( unsigned jj = 1; jj < buffer.size(); jj++ ) { - FP_SHAPE* seg = new FP_SHAPE( footprint, SHAPE_T::SEGMENT ); + PCB_SHAPE* seg = new PCB_SHAPE( footprint, SHAPE_T::SEGMENT ); seg->SetStart( buffer[jj - 1] ); seg->SetEnd( buffer[jj] ); seg->SetStroke( STROKE_PARAMS( aInductorPattern.m_Width, PLOT_DASH_TYPE::SOLID ) ); seg->SetLayer( footprint->GetLayer() ); - seg->SetStart0( seg->GetStart() - footprint->GetPosition() ); - seg->SetEnd0( seg->GetEnd() - footprint->GetPosition() ); footprint->Add( seg ); } diff --git a/pcbnew/microwave/microwave_polygon.cpp b/pcbnew/microwave/microwave_polygon.cpp index fe31ad7462..0ba3b2c3e8 100644 --- a/pcbnew/microwave/microwave_polygon.cpp +++ b/pcbnew/microwave/microwave_polygon.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -289,7 +289,7 @@ FOOTPRINT* MICROWAVE_TOOL::createPolygonShape() FOOTPRINT* footprint; wxString cmp_name; int pad_count = 2; - FP_SHAPE* shape; + PCB_SHAPE* shape; PCB_EDIT_FRAME& editFrame = *getEditFrame(); @@ -341,7 +341,7 @@ FOOTPRINT* MICROWAVE_TOOL::createPolygonShape() pad2->SetX( pad2->GetPos0().x ); // Add a polygonal edge (corners will be added later) on copper layer - shape = new FP_SHAPE( footprint, SHAPE_T::POLY ); + shape = new PCB_SHAPE( footprint, SHAPE_T::POLY ); shape->SetFilled( true ); shape->SetLayer( F_Cu ); @@ -386,6 +386,8 @@ FOOTPRINT* MICROWAVE_TOOL::createPolygonShape() } shape->SetPolyPoints( polyPoints ); + shape->Rotate( { 0, 0 }, footprint->GetOrientation() ); + shape->Move( footprint->GetPosition() ); // Set the polygon outline thickness to 0, only the polygonal shape is filled // without extra thickness. diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index bc0c74a1b4..00b948a28a 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -164,7 +164,7 @@ bool PAD::IsLocked() const bool PAD::SharesNetTieGroup( const PAD* aOther ) const { - FOOTPRINT* parentFp = static_cast( GetParentFootprint() ); + FOOTPRINT* parentFp = GetParentFootprint(); if( parentFp && parentFp->IsNetTie() && aOther->GetParentFootprint() == parentFp ) { diff --git a/pcbnew/pad.h b/pcbnew/pad.h index 33fcd9fa18..9e67ecb483 100644 --- a/pcbnew/pad.h +++ b/pcbnew/pad.h @@ -49,7 +49,6 @@ enum CUST_PAD_SHAPE_IN_ZONE class LINE_READER; class EDA_3D_CANVAS; class FOOTPRINT; -class FP_SHAPE; namespace KIGFX { diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 92b63cd80c..2e30f90825 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 CERN - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors. * * @author Maciej Suminski * @@ -33,6 +33,9 @@ class APPEARANCE_CONTROLS; class BOARD_ITEM_CONTAINER; class PANEL_SELECTION_FILTER; class PROPERTIES_PANEL; +class PCB_TEXTBOX; +class PCB_TEXT; +class PCB_SHAPE; /** * Common, abstract interface for edit frames. @@ -174,9 +177,9 @@ public: //void SetRotationAngle( EDA_ANGLE aRotationAngle ); void ShowBitmapPropertiesDialog( BOARD_ITEM* aBitmap ); - void ShowTextPropertiesDialog( BOARD_ITEM* aText ); - int ShowTextBoxPropertiesDialog( BOARD_ITEM* aText ); - void ShowGraphicItemPropertiesDialog( BOARD_ITEM* aItem ); + void ShowTextPropertiesDialog( PCB_TEXT* aText ); + int ShowTextBoxPropertiesDialog( PCB_TEXTBOX* aTextBox ); + void ShowGraphicItemPropertiesDialog( PCB_SHAPE* aShape ); ///< @copydoc EDA_DRAW_FRAME::UseGalCanvas() void ActivateGalCanvas() override; diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 225416f37e..2d0c21d723 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -447,10 +447,6 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector aItems, PCB_LAYER_ID case PCB_SHAPE_T: case PCB_TEXT_T: case PCB_TEXTBOX_T: - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - case PCB_FP_ZONE_T: case PCB_TRACE_T: case PCB_ARC_T: case PCB_DIM_ALIGNED_T: @@ -458,11 +454,6 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector aItems, PCB_LAYER_ID case PCB_DIM_CENTER_T: case PCB_DIM_RADIAL_T: case PCB_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: item->TransformShapeToPolygon( itemPoly, aLayer, 0, pcbIUScale.mmToIU( 0.1 ), ERROR_INSIDE ); break; diff --git a/pcbnew/pcb_dimension.cpp b/pcbnew/pcb_dimension.cpp index 83a453544e..c4ab618920 100644 --- a/pcbnew/pcb_dimension.cpp +++ b/pcbnew/pcb_dimension.cpp @@ -335,7 +335,7 @@ void PCB_DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, ORIGIN_TRANSFORMS originTransforms = aFrame->GetOriginTransforms(); - if( Type() == PCB_DIM_CENTER_T || Type() == PCB_FP_DIM_CENTER_T ) + if( Type() == PCB_DIM_CENTER_T ) { VECTOR2I startCoord = originTransforms.ToDisplayAbs( GetStart() ); wxString start = wxString::Format( wxT( "@(%s, %s)" ), @@ -735,8 +735,8 @@ void PCB_DIM_ALIGNED::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector( m_arrowLength * s_arrowAngle.Sin() ); @@ -948,8 +948,8 @@ void PCB_DIM_ORTHOGONAL::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aA } -PCB_DIM_LEADER::PCB_DIM_LEADER( BOARD_ITEM* aParent, bool aInFP ) : - PCB_DIMENSION_BASE( aParent, aInFP ? PCB_FP_DIM_LEADER_T : PCB_DIM_LEADER_T ), +PCB_DIM_LEADER::PCB_DIM_LEADER( BOARD_ITEM* aParent ) : + PCB_DIMENSION_BASE( aParent, PCB_DIM_LEADER_T ), m_textBorder( DIM_TEXT_BORDER::NONE ) { m_unitsFormat = DIM_UNITS_FORMAT::NO_SUFFIX; @@ -1097,8 +1097,8 @@ void PCB_DIM_LEADER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aScanTypes ) const override - { - if( BOARD_ITEM::IsType( aScanTypes ) ) - return true; - - for( KICAD_T scanType : aScanTypes ) - { - if( scanType == PCB_LOCATE_GRAPHIC_T ) - return true; - } - - return false; - } - /** * The dimension's origin is the first feature point for the dimension. Every dimension has * one or more feature points, so every dimension has at least an origin. @@ -383,7 +369,7 @@ protected: class PCB_DIM_ALIGNED : public PCB_DIMENSION_BASE { public: - PCB_DIM_ALIGNED( BOARD_ITEM* aParent, KICAD_T aType ); + PCB_DIM_ALIGNED( BOARD_ITEM* aParent, KICAD_T aType = PCB_DIM_ALIGNED_T ); // Do not create a copy constructor & operator=. // The ones generated by the compiler are adequate. @@ -392,8 +378,7 @@ public: static inline bool ClassOf( const EDA_ITEM* aItem ) { - return aItem && ( aItem->Type() == PCB_DIM_ALIGNED_T - || aItem->Type() == PCB_FP_DIM_ALIGNED_T ); + return aItem && aItem->Type() == PCB_DIM_ALIGNED_T; } EDA_ITEM* Clone() const override; @@ -485,14 +470,13 @@ public: VERTICAL // Aligned with y-axis }; - PCB_DIM_ORTHOGONAL( BOARD_ITEM* aParent, bool aInFP = false ); + PCB_DIM_ORTHOGONAL( BOARD_ITEM* aParent ); ~PCB_DIM_ORTHOGONAL() = default; static inline bool ClassOf( const EDA_ITEM* aItem ) { - return aItem && ( aItem->Type() == PCB_DIM_ORTHOGONAL_T - || aItem->Type() == PCB_FP_DIM_ORTHOGONAL_T ); + return aItem && aItem->Type() == PCB_DIM_ORTHOGONAL_T; } EDA_ITEM* Clone() const override; @@ -550,12 +534,11 @@ private: class PCB_DIM_RADIAL : public PCB_DIMENSION_BASE { public: - PCB_DIM_RADIAL( BOARD_ITEM* aParent, bool aInFP = false ); + PCB_DIM_RADIAL( BOARD_ITEM* aParent ); static inline bool ClassOf( const EDA_ITEM* aItem ) { - return aItem && ( aItem->Type() == PCB_DIM_RADIAL_T - || aItem->Type() == PCB_FP_DIM_RADIAL_T ); + return aItem && aItem->Type() == PCB_DIM_RADIAL_T; } EDA_ITEM* Clone() const override; @@ -607,12 +590,11 @@ private: class PCB_DIM_LEADER : public PCB_DIMENSION_BASE { public: - PCB_DIM_LEADER( BOARD_ITEM* aParent, bool aInFP = false ); + PCB_DIM_LEADER( BOARD_ITEM* aParent ); static inline bool ClassOf( const EDA_ITEM* aItem ) { - return aItem && ( aItem->Type() == PCB_DIM_LEADER_T - || aItem->Type() == PCB_FP_DIM_LEADER_T ); + return aItem && aItem->Type() == PCB_DIM_LEADER_T; } EDA_ITEM* Clone() const override; @@ -655,12 +637,11 @@ private: class PCB_DIM_CENTER : public PCB_DIMENSION_BASE { public: - PCB_DIM_CENTER( BOARD_ITEM* aParent, bool aInFP = false ); + PCB_DIM_CENTER( BOARD_ITEM* aParent ); static inline bool ClassOf( const EDA_ITEM* aItem ) { - return aItem && ( aItem->Type() == PCB_DIM_CENTER_T - || aItem->Type() == PCB_FP_DIM_CENTER_T ); + return aItem && aItem->Type() == PCB_DIM_CENTER_T; } EDA_ITEM* Clone() const override; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 7c587ec4cd..52de4b57a9 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -889,10 +889,10 @@ void PCB_EDIT_FRAME::setupUIConditions() SELECTION_CONDITION singleZoneCond = SELECTION_CONDITIONS::Count( 1 ) - && SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T, PCB_FP_ZONE_T } ); + && SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T } ); SELECTION_CONDITION zoneMergeCond = SELECTION_CONDITIONS::MoreThan( 1 ) - && SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T, PCB_FP_ZONE_T } ); + && SELECTION_CONDITIONS::OnlyTypes( { PCB_ZONE_T } ); mgr->SetConditions( PCB_ACTIONS::zoneDuplicate, ENABLE( singleZoneCond ) ); mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) ); @@ -1699,10 +1699,6 @@ void PCB_EDIT_FRAME::ShowFindDialog() findString = static_cast( front )->GetValue(); break; - case PCB_FP_TEXT_T: - findString = static_cast( front )->GetShownText(); - break; - case PCB_TEXT_T: findString = static_cast( front )->GetShownText(); @@ -2047,7 +2043,7 @@ int PCB_EDIT_FRAME::ShowExchangeFootprintsDialog( FOOTPRINT* aFootprint, bool aU namespace { -void processTextItem( const FP_TEXT& aSrc, FP_TEXT& aDest, +void processTextItem( const PCB_TEXT& aSrc, PCB_TEXT& aDest, bool resetText, bool resetTextLayers, bool resetTextEffects, bool* aUpdated ) { @@ -2074,7 +2070,7 @@ void processTextItem( const FP_TEXT& aSrc, FP_TEXT& aDest, *aUpdated |= aSrc.GetTextSize() != aDest.GetTextSize(); *aUpdated |= aSrc.GetTextThickness() != aDest.GetTextThickness(); *aUpdated |= aSrc.GetTextAngle() != aDest.GetTextAngle(); - *aUpdated |= aSrc.GetPos0() != aDest.GetPos0(); + *aUpdated |= aSrc.GetFPRelativePosition() != aDest.GetFPRelativePosition(); } else { @@ -2082,20 +2078,20 @@ void processTextItem( const FP_TEXT& aSrc, FP_TEXT& aDest, bool visible = aDest.IsVisible(); aDest.SetAttributes( aSrc ); aDest.SetVisible( visible ); - aDest.SetPos0( aSrc.GetPos0() ); + aDest.SetFPRelativePosition( aSrc.GetFPRelativePosition() ); } aDest.SetLocked( aSrc.IsLocked() ); } -FP_TEXT* getMatchingTextItem( FP_TEXT* aRefItem, FOOTPRINT* aFootprint ) +PCB_TEXT* getMatchingTextItem( PCB_TEXT* aRefItem, FOOTPRINT* aFootprint ) { - std::vector candidates; + std::vector candidates; for( BOARD_ITEM* item : aFootprint->GraphicalItems() ) { - FP_TEXT* candidate = dyn_cast( item ); + PCB_TEXT* candidate = dyn_cast( item ); if( candidate && candidate->GetText() == aRefItem->GetText() ) candidates.push_back( candidate ); @@ -2108,9 +2104,9 @@ FP_TEXT* getMatchingTextItem( FP_TEXT* aRefItem, FOOTPRINT* aFootprint ) return candidates[0]; // Try refining the match by layer - std::vector candidatesOnSameLayer; + std::vector candidatesOnSameLayer; - for( FP_TEXT* candidate : candidates ) + for( PCB_TEXT* candidate : candidates ) { if( candidate->GetLayer() == aRefItem->GetLayer() ) candidatesOnSameLayer.push_back( candidate ); @@ -2120,11 +2116,11 @@ FP_TEXT* getMatchingTextItem( FP_TEXT* aRefItem, FOOTPRINT* aFootprint ) return candidatesOnSameLayer[0]; // Last ditch effort: refine by position - std::vector candidatesAtSamePos; + std::vector candidatesAtSamePos; - for( FP_TEXT* candidate : candidatesOnSameLayer.size() ? candidatesOnSameLayer : candidates ) + for( PCB_TEXT* candidate : candidatesOnSameLayer.size() ? candidatesOnSameLayer : candidates ) { - if( candidate->GetPos0() == aRefItem->GetPos0() ) + if( candidate->GetFPRelativePosition() == aRefItem->GetFPRelativePosition() ) candidatesAtSamePos.push_back( candidate ); } @@ -2236,11 +2232,11 @@ void PCB_EDIT_FRAME::ExchangeFootprint( FOOTPRINT* aExisting, FOOTPRINT* aNew, for( BOARD_ITEM* item : aExisting->GraphicalItems() ) { - FP_TEXT* srcItem = dyn_cast( item ); + PCB_TEXT* srcItem = dyn_cast( item ); if( srcItem ) { - FP_TEXT* destItem = getMatchingTextItem( srcItem, aNew ); + PCB_TEXT* destItem = getMatchingTextItem( srcItem, aNew ); if( destItem ) { @@ -2249,7 +2245,7 @@ void PCB_EDIT_FRAME::ExchangeFootprint( FOOTPRINT* aExisting, FOOTPRINT* aNew, } else if( !deleteExtraTexts ) { - aNew->Add( new FP_TEXT( *srcItem ) ); + aNew->Add( new PCB_TEXT( *srcItem ) ); } } } diff --git a/pcbnew/pcb_expr_functions.cpp b/pcbnew/pcb_expr_functions.cpp index 16240420d1..58c95308a5 100644 --- a/pcbnew/pcb_expr_functions.cpp +++ b/pcbnew/pcb_expr_functions.cpp @@ -482,7 +482,7 @@ bool collidesWithArea( BOARD_ITEM* aItem, PCB_EXPR_CONTEXT* aCtx, ZONE* aArea ) return false; } - if( aItem->Type() == PCB_ZONE_T || aItem->Type() == PCB_FP_ZONE_T ) + if( aItem->Type() == PCB_ZONE_T ) { ZONE* zone = static_cast( aItem ); diff --git a/pcbnew/pcb_group.cpp b/pcbnew/pcb_group.cpp index 06e2ce89ec..9d00aba827 100644 --- a/pcbnew/pcb_group.cpp +++ b/pcbnew/pcb_group.cpp @@ -50,15 +50,6 @@ bool PCB_GROUP::IsGroupableType( KICAD_T aType ) case PCB_BITMAP_T: case PCB_TEXT_T: case PCB_TEXTBOX_T: - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_LEADER_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_ZONE_T: case PCB_GROUP_T: case PCB_TRACE_T: case PCB_VIA_T: diff --git a/pcbnew/pcb_item_containers.h b/pcbnew/pcb_item_containers.h index 0c7bf7f05e..62d218225c 100644 --- a/pcbnew/pcb_item_containers.h +++ b/pcbnew/pcb_item_containers.h @@ -48,11 +48,8 @@ DECL_DEQ_FOR_SWIG( DRAWINGS, BOARD_ITEM* ) // Footprint-level items -class FP_ZONE; class PAD; DECL_DEQ_FOR_SWIG( PADS, PAD* ) -DECL_VEC_FOR_SWIG( FP_ZONES, FP_ZONE* ) -DECL_VEC_FOR_SWIG( FP_GROUPS, PCB_GROUP* ) #endif // PCB_ITEM_CONTAINERS_H_ diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 63778d752d..4b73c03840 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -223,7 +222,7 @@ COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) cons } // Zones should pull from the copper layer - if( item && ( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) ) + if( item && item->Type() == PCB_ZONE_T ) { if( IsZoneFillLayer( aLayer ) ) aLayer = aLayer - LAYER_ZONE_START; @@ -429,7 +428,7 @@ COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) cons color.a *= m_viaOpacity; else if( item->Type() == PCB_PAD_T ) color.a *= m_padOpacity; - else if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) + else if( item->Type() == PCB_ZONE_T ) color.a *= m_zoneOpacity; else if( item->Type() == PCB_BITMAP_T ) color.a *= m_imageOpacity; @@ -505,11 +504,13 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) if( item->GetParentFootprint() && !board->IsFootprintHolder() ) { - FOOTPRINT* parentFP = static_cast( item->GetParentFootprint() ); + FOOTPRINT* parentFP = item->GetParentFootprint(); // Never draw footprint bitmaps on board if( item->Type() == PCB_BITMAP_T ) + { return false; + } else if( item->GetLayerSet().count() > 1 ) { // For multi-layer objects, exclude only those layers that are private @@ -553,7 +554,6 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) break; case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: draw( static_cast( item ), aLayer ); break; @@ -569,14 +569,6 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) draw( static_cast( item ), aLayer ); break; - case PCB_FP_TEXT_T: - draw( static_cast( item ), aLayer ); - break; - - case PCB_FP_TEXTBOX_T: - draw( static_cast( item ), aLayer ); - break; - case PCB_FOOTPRINT_T: draw( static_cast( item ), aLayer ); break; @@ -586,7 +578,6 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) break; case PCB_ZONE_T: - case PCB_FP_ZONE_T: draw( static_cast( item ), aLayer ); break; @@ -595,11 +586,6 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) case PCB_DIM_RADIAL_T: case PCB_DIM_ORTHOGONAL_T: case PCB_DIM_LEADER_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_LEADER_T: draw( static_cast( item ), aLayer ); break; @@ -1116,14 +1102,14 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) if( aPad->GetFlags() & ENTERED ) { - FOOTPRINT* fp = static_cast( aPad->GetParentFootprint() ); + FOOTPRINT* fp = aPad->GetParentFootprint(); // Find the number box for( const BOARD_ITEM* aItem : fp->GraphicalItems() ) { - if( aItem->Type() == PCB_FP_SHAPE_T ) + if( aItem->Type() == PCB_SHAPE_T ) { - const FP_SHAPE* shape = static_cast( aItem ); + const PCB_SHAPE* shape = static_cast( aItem ); if( shape->IsAnnotationProxy() ) { @@ -1768,18 +1754,10 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer ) case SHAPE_T::POLY: { SHAPE_POLY_SET& shape = const_cast( aShape )->GetPolyShape(); - const FOOTPRINT* parentFootprint = aShape->GetParentFootprint(); if( shape.OutlineCount() == 0 ) break; - if( parentFootprint ) - { - m_gal->Save(); - m_gal->Translate( parentFootprint->GetPosition() ); - m_gal->Rotate( -parentFootprint->GetOrientation().AsRadians() ); - } - if( outline_mode ) { for( int ii = 0; ii < shape.OutlineCount(); ++ii ) @@ -1809,9 +1787,6 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer ) } } - if( parentFootprint ) - m_gal->Restore(); - break; } @@ -1976,6 +1951,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) m_gal->SetStrokeColor( color ); m_gal->SetFillColor( color ); + attrs.m_Angle = aText->GetDrawRotation(); if( aText->IsKnockout() ) { @@ -2131,159 +2107,6 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) } -void PCB_PAINTER::draw( const FP_TEXT* aText, int aLayer ) -{ - wxString resolvedText( aText->GetShownText() ); - - if( resolvedText.Length() == 0 ) - return; - - const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer ); - bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; - TEXT_ATTRIBUTES attrs = aText->GetAttributes(); - - KIFONT::FONT* font = aText->GetFont(); - - if( !font ) - { - font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aText->IsBold(), - aText->IsItalic() ); - } - - m_gal->SetStrokeColor( color ); - m_gal->SetFillColor( color ); - attrs.m_Angle = aText->GetDrawRotation(); - - if( aText->IsKnockout() ) - { - KIGFX::GAL_DISPLAY_OPTIONS empty_opts; - SHAPE_POLY_SET knockouts; - - CALLBACK_GAL callback_gal( empty_opts, - // Polygon callback - [&]( const SHAPE_LINE_CHAIN& aPoly ) - { - knockouts.AddOutline( aPoly ); - } ); - - attrs.m_StrokeWidth = getLineThickness( aText->GetEffectiveTextPenWidth() ); - - callback_gal.SetIsFill( font->IsOutline() ); - callback_gal.SetIsStroke( font->IsStroke() ); - callback_gal.SetLineWidth( attrs.m_StrokeWidth ); - font->Draw( &callback_gal, resolvedText, aText->GetDrawPos(), attrs ); - - SHAPE_POLY_SET finalPoly; - int margin = attrs.m_StrokeWidth * 1.5 - + GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth ); - - aText->TransformBoundingBoxToPolygon( &finalPoly, margin ); - finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST ); - finalPoly.Fracture( SHAPE_POLY_SET::PM_FAST ); - - m_gal->SetIsStroke( false ); - m_gal->SetIsFill( true ); - m_gal->DrawPolygon( finalPoly ); - } - else - { - if( outline_mode ) - attrs.m_StrokeWidth = m_pcbSettings.m_outlineWidth; - else - attrs.m_StrokeWidth = getLineThickness( aText->GetEffectiveTextPenWidth() ); - - if( m_gal->IsFlippedX() && !( aText->GetLayerSet() & LSET::SideSpecificMask() ).any() ) - { - attrs.m_Mirrored = !attrs.m_Mirrored; - attrs.m_Halign = static_cast( -attrs.m_Halign ); - } - - std::vector>* cache = nullptr; - - if( font->IsOutline() ) - cache = aText->GetRenderCache( font, resolvedText ); - - if( cache ) - m_gal->DrawGlyphs( *cache ); - else - strokeText( resolvedText, aText->GetTextPos(), attrs ); - } - - // Draw the umbilical line - if( aText->IsSelected() ) - { - m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth ); - m_gal->SetStrokeColor( m_pcbSettings.GetColor( nullptr, LAYER_ANCHOR ) ); - m_gal->DrawLine( aText->GetTextPos(), aText->GetParent()->GetPosition() ); - } -} - - -void PCB_PAINTER::draw( const FP_TEXTBOX* aTextBox, int aLayer ) -{ - const COLOR4D& color = m_pcbSettings.GetColor( aTextBox, aTextBox->GetLayer() ); - int thickness = getLineThickness( aTextBox->GetWidth() ); - PLOT_DASH_TYPE lineStyle = aTextBox->GetStroke().GetPlotStyle(); - - m_gal->SetFillColor( color ); - m_gal->SetStrokeColor( color ); - m_gal->SetIsFill( true ); - m_gal->SetIsStroke( false ); - - if( thickness > 0 ) - { - if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE ) - { - std::vector pts = aTextBox->GetCorners(); - - for( size_t ii = 0; ii < pts.size(); ++ii ) - m_gal->DrawSegment( pts[ ii ], pts[ (ii + 1) % pts.size() ], thickness ); - } - else - { - std::vector shapes = aTextBox->MakeEffectiveShapes( true ); - - for( SHAPE* shape : shapes ) - { - STROKE_PARAMS::Stroke( shape, lineStyle, thickness, &m_pcbSettings, - [&]( const VECTOR2I& a, const VECTOR2I& b ) - { - m_gal->DrawSegment( a, b, thickness ); - } ); - } - - for( SHAPE* shape : shapes ) - delete shape; - } - } - - wxString resolvedText( aTextBox->GetShownText() ); - - if( resolvedText.Length() == 0 ) - return; - - TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes(); - attrs.m_Angle = aTextBox->GetDrawRotation(); - attrs.m_StrokeWidth = getLineThickness( aTextBox->GetEffectiveTextPenWidth() ); - - if( m_gal->IsFlippedX() && !( aTextBox->GetLayerSet() & LSET::SideSpecificMask() ).any() ) - { - attrs.m_Mirrored = !attrs.m_Mirrored; - attrs.m_Halign = static_cast( -attrs.m_Halign ); - } - - std::vector>* cache = nullptr; - - if( aTextBox->GetFont() && aTextBox->GetFont()->IsOutline() ) - cache = aTextBox->GetRenderCache( aTextBox->GetFont(), resolvedText ); - - if( cache ) - m_gal->DrawGlyphs( *cache ); - else - strokeText( resolvedText, aTextBox->GetDrawPos(), attrs ); -} - - void PCB_PAINTER::draw( const FOOTPRINT* aFootprint, int aLayer ) { if( aLayer == LAYER_ANCHOR ) diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index cf9bb31a32..7461c93311 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -52,8 +52,6 @@ class ZONE; class PCB_BITMAP; class PCB_TEXT; class PCB_TEXTBOX; -class FP_TEXT; -class FP_TEXTBOX; class PCB_DIMENSION_BASE; class PCB_TARGET; class PCB_MARKER; @@ -180,8 +178,6 @@ protected: void draw( const PCB_BITMAP* aBitmap, int aLayer ); void draw( const PCB_TEXT* aText, int aLayer ); void draw( const PCB_TEXTBOX* aText, int aLayer ); - void draw( const FP_TEXT* aText, int aLayer ); - void draw( const FP_TEXTBOX* aText, int aLayer ); void draw( const FOOTPRINT* aFootprint, int aLayer ); void draw( const PCB_GROUP* aGroup, int aLayer ); void draw( const ZONE* aZone, int aLayer ); diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp index 6cd10b2658..c3a1956ed3 100644 --- a/pcbnew/pcb_shape.cpp +++ b/pcbnew/pcb_shape.cpp @@ -63,9 +63,7 @@ bool PCB_SHAPE::IsType( const std::vector& aScanTypes ) const for( KICAD_T scanType : aScanTypes ) { - if( scanType == PCB_LOCATE_GRAPHIC_T ) - return true; - else if( scanType == PCB_LOCATE_BOARD_EDGE_T ) + if( scanType == PCB_LOCATE_BOARD_EDGE_T ) sametype = m_layer == Edge_Cuts; else if( scanType == PCB_SHAPE_LOCATE_ARC_T ) sametype = m_shape == SHAPE_T::ARC; @@ -140,12 +138,10 @@ std::vector PCB_SHAPE::GetCorners() const } else if( GetShape() == SHAPE_T::POLY ) { - VECTOR2I offset = getParentPosition(); - for( int ii = 0; ii < GetPolyShape().OutlineCount(); ++ii ) { for( const VECTOR2I& pt : GetPolyShape().Outline( ii ).CPoints() ) - pts.emplace_back( pt + offset ); + pts.emplace_back( pt ); } } else @@ -249,30 +245,6 @@ void PCB_SHAPE::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ) } -FOOTPRINT* PCB_SHAPE::GetParentFootprint() const -{ - return dynamic_cast( BOARD_ITEM::GetParentFootprint() ); -} - - -EDA_ANGLE PCB_SHAPE::getParentOrientation() const -{ - if( GetParentFootprint() ) - return GetParentFootprint()->GetOrientation(); - else - return ANGLE_0; -} - - -VECTOR2I PCB_SHAPE::getParentPosition() const -{ - if( GetParentFootprint() ) - return GetParentFootprint()->GetPosition(); - else - return VECTOR2I( 0, 0 ); -} - - double PCB_SHAPE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { constexpr double HIDE = std::numeric_limits::max(); @@ -295,12 +267,27 @@ double PCB_SHAPE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const } } + if( FOOTPRINT* parent = GetParentFootprint() ) + { + if( parent->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_MOD_FR ) ) + return HIDE; + + if( parent->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_MOD_BK ) ) + return HIDE; + } + return SHOW; } void PCB_SHAPE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) { + if( aFrame->GetName() == PCB_EDIT_FRAME_NAME ) + { + if( FOOTPRINT* parent = GetParentFootprint() ) + aList.emplace_back( _( "Footprint" ), parent->GetReference() ); + } + aList.emplace_back( _( "Type" ), _( "Drawing" ) ); if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() ) @@ -320,7 +307,10 @@ wxString PCB_SHAPE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const BITMAPS PCB_SHAPE::GetMenuImage() const { - return BITMAPS::add_dashed_line; + if( GetParentFootprint() ) + return BITMAPS::show_mod_edge; + else + return BITMAPS::add_dashed_line; } diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h index 0273dbb474..fc80e6c2a3 100644 --- a/pcbnew/pcb_shape.h +++ b/pcbnew/pcb_shape.h @@ -83,13 +83,6 @@ public: */ const VECTOR2I GetFocusPosition() const override; - /** - * Return the parent footprint or NULL if PCB_SHAPE does not belong to a footprint. - * - * @return the parent footprint or NULL. - */ - FOOTPRINT* GetParentFootprint() const; - /** * Make a set of SHAPE objects representing the PCB_SHAPE. Caller owns the objects. */ @@ -158,9 +151,6 @@ protected: { bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const; }; - - EDA_ANGLE getParentOrientation() const override; - VECTOR2I getParentPosition() const override; }; #endif // PCB_SHAPE_H diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index d7eb8e3942..dee077afa3 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -40,13 +40,38 @@ PCB_TEXT::PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype ) : - BOARD_ITEM( parent, idtype ), - EDA_TEXT( pcbIUScale ) + BOARD_ITEM( parent, idtype ), + EDA_TEXT( pcbIUScale ), + m_type( TEXT_is_DIVERS ) { SetMultilineAllowed( true ); } +PCB_TEXT::PCB_TEXT( FOOTPRINT* aParent, TEXT_TYPE text_type ) : + BOARD_ITEM( aParent, PCB_TEXT_T ), + EDA_TEXT( pcbIUScale ), + m_type( text_type ) +{ + SetKeepUpright( true ); + + // Set text thickness to a default value + SetTextThickness( pcbIUScale.mmToIU( DEFAULT_TEXT_WIDTH ) ); + SetLayer( F_SilkS ); + + if( aParent ) + { + SetTextPos( aParent->GetPosition() ); + + if( IsBackLayer( aParent->GetLayer() ) ) + { + SetLayer( B_SilkS ); + SetMirrored( true ); + } + } +} + + PCB_TEXT::~PCB_TEXT() { } @@ -54,11 +79,15 @@ PCB_TEXT::~PCB_TEXT() wxString PCB_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const { - BOARD* board = dynamic_cast( GetParent() ); + const FOOTPRINT* parentFootprint = GetParentFootprint(); + const BOARD* board = GetBoard(); - std::function pcbTextResolver = + std::function resolver = [&]( wxString* token ) -> bool { + if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) ) + return true; + if( token->IsSameAs( wxT( "LAYER" ) ) ) { *token = GetLayerName(); @@ -66,35 +95,85 @@ wxString PCB_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const } if( board->ResolveTextVar( token, aDepth + 1 ) ) - { return true; - } return false; }; wxString text = EDA_TEXT::GetShownText(); - if( board && HasTextVars() && aDepth < 10 ) - text = ExpandTextVars( text, &pcbTextResolver ); + if( HasTextVars() ) + { + if( aDepth < 10 ) + text = ExpandTextVars( text, &resolver ); + } return text; } +EDA_ANGLE PCB_TEXT::GetDrawRotation() const +{ + EDA_ANGLE rotation = GetTextAngle(); + + if( GetParentFootprint() && IsKeepUpright() ) + { + // Keep angle between ]-90..90] deg. Otherwise the text is not easy to read + while( rotation > ANGLE_90 ) + rotation -= ANGLE_180; + + while( rotation <= -ANGLE_90 ) + rotation += ANGLE_180; + } + else + { + rotation.Normalize(); + } + + return rotation; +} + + +const BOX2I PCB_TEXT::ViewBBox() const +{ + EDA_ANGLE angle = GetDrawRotation(); + BOX2I text_area = GetTextBox(); + + if( !angle.IsZero() ) + text_area = text_area.GetBoundingBoxRotated( GetTextPos(), angle ); + + return BOX2I( text_area.GetPosition(), text_area.GetSize() ); +} + + +void PCB_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const +{ + if( GetParentFootprint() == nullptr || IsVisible() ) + aLayers[0] = GetLayer(); + else + aLayers[0] = LAYER_MOD_TEXT_INVISIBLE; + + aCount = 1; +} + + double PCB_TEXT::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { constexpr double HIDE = std::numeric_limits::max(); + if( !aView ) + return 0.0; + KIGFX::PCB_PAINTER* painter = static_cast( aView->GetPainter() ); KIGFX::PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings(); + // Hidden text gets put on the LAYER_MOD_TEXT_INVISIBLE for rendering, but + // should only render if its native layer is visible. + if( !aView->IsLayerVisible( GetLayer() ) ) + return HIDE; + if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) { - // Hide shadow if the main layer is not shown - if( !aView->IsLayerVisible( m_layer ) ) - return HIDE; - // Hide shadow on dimmed tracks if( renderSettings->GetHighContrast() ) { @@ -103,18 +182,64 @@ double PCB_TEXT::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const } } + if( FOOTPRINT* parentFP = GetParentFootprint() ) + { + // Handle Render tab switches + if( m_type == TEXT_is_VALUE || GetText() == wxT( "${VALUE}" ) ) + { + if( !aView->IsLayerVisible( LAYER_MOD_VALUES ) ) + return HIDE; + } + + if( m_type == TEXT_is_REFERENCE || GetText() == wxT( "${REFERENCE}" ) ) + { + if( !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) ) + return HIDE; + } + + if( parentFP->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_MOD_FR ) ) + return HIDE; + + if( parentFP->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_MOD_BK ) ) + return HIDE; + + if( !aView->IsLayerVisible( LAYER_MOD_TEXT ) ) + return HIDE; + } + return 0.0; } void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) { + FOOTPRINT* parentFP = GetParentFootprint(); + + if( parentFP && aFrame->GetName() == PCB_EDIT_FRAME_NAME ) + aList.emplace_back( _( "Footprint" ), parentFP->GetReference() ); + // Don't use GetShownText() here; we want to show the user the variable references - aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) ); + if( parentFP ) + aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) ); + else + aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) ); + + if( parentFP ) + { + switch( m_type ) + { + case TEXT_is_REFERENCE: aList.emplace_back( _( "Type" ), _( "Reference" ) ); break; + case TEXT_is_VALUE: aList.emplace_back( _( "Type" ), _( "Value" ) ); break; + case TEXT_is_DIVERS: aList.emplace_back( _( "Type" ), _( "Text" ) ); break; + } + } if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() ) aList.emplace_back( _( "Status" ), _( "Locked" ) ); + if( parentFP ) + aList.emplace_back( _( "Display" ), IsVisible() ? _( "Yes" ) : _( "No" ) ); + aList.emplace_back( _( "Layer" ), GetLayerName() ); aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) ); @@ -137,14 +262,33 @@ int PCB_TEXT::getKnockoutMargin() const } +void PCB_TEXT::KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation ) +{ + if( !IsKeepUpright() ) + return; + + EDA_ANGLE newAngle = GetTextAngle() + aNewOrientation; + newAngle.Normalize(); + + bool needsFlipped = newAngle >= ANGLE_180; + + if( needsFlipped ) + { + SetHorizJustify( static_cast( -GetHorizJustify() ) ); + SetTextAngle( GetTextAngle() + ANGLE_180 ); + } +} + + const BOX2I PCB_TEXT::GetBoundingBox() const { - BOX2I rect = GetTextBox(); + EDA_ANGLE angle = GetDrawRotation(); + BOX2I rect = GetTextBox(); if( IsKnockout() ) rect.Inflate( getKnockoutMargin() ); - if( !GetTextAngle().IsZero() ) + if( !angle.IsZero() ) rect = rect.GetBoundingBoxRotated( GetTextPos(), GetTextAngle() ); return rect; @@ -236,9 +380,31 @@ void PCB_TEXT::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) wxString PCB_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const { - return wxString::Format( _( "PCB Text '%s' on %s"), - KIUI::EllipsizeMenuText( GetShownText() ), - GetLayerName() ); + if( FOOTPRINT* parentFP = GetParentFootprint() ) + { + switch( m_type ) + { + case TEXT_is_REFERENCE: + return wxString::Format( _( "Reference '%s'" ), + parentFP->GetReference() ); + + case TEXT_is_VALUE: + return wxString::Format( _( "Value '%s' of %s" ), + GetShownText(), + parentFP->GetReference() ); + + case TEXT_is_DIVERS: + return wxString::Format( _( "Footprint Text '%s' of %s" ), + KIUI::EllipsizeMenuText( GetShownText() ), + parentFP->GetReference() ); + } + } + else + { + return wxString::Format( _( "PCB Text '%s' on %s"), + KIUI::EllipsizeMenuText( GetShownText() ), + GetLayerName() ); + } } diff --git a/pcbnew/pcb_text.h b/pcbnew/pcb_text.h index 718ac736b5..663befff77 100644 --- a/pcbnew/pcb_text.h +++ b/pcbnew/pcb_text.h @@ -31,6 +31,7 @@ class LINE_READER; class MSG_PANEL_ITEM; +class FOOTPRINT; class PCB_TEXT : public BOARD_ITEM, public EDA_TEXT @@ -38,6 +39,21 @@ class PCB_TEXT : public BOARD_ITEM, public EDA_TEXT public: PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype = PCB_TEXT_T ); + /** + * Footprint text type: there must be only one (and only one) for each of the reference + * value texts in one footprint; others could be added for the user (DIVERS is French for + * 'others'). Reference and value always live on silkscreen (on the footprint side); other + * texts are planned to go on whatever layer the user wants. + */ + enum TEXT_TYPE + { + TEXT_is_REFERENCE = 0, + TEXT_is_VALUE = 1, + TEXT_is_DIVERS = 2 + }; + + PCB_TEXT( FOOTPRINT* aParent, TEXT_TYPE text_type ); + // Do not create a copy constructor & operator=. // The ones generated by the compiler are adequate. @@ -62,11 +78,15 @@ public: return false; } + /** + * Called when rotating the parent footprint. + */ + void KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation ); + wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override; - /// PCB_TEXTs are always visible: - void SetVisible( bool aVisible ) override { /* do nothing */} - bool IsVisible() const override { return true; } + void SetType( TEXT_TYPE aType ) { m_type = aType; } + TEXT_TYPE GetType() const { return m_type; } bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override { @@ -138,6 +158,16 @@ public: BITMAPS GetMenuImage() const override; + /** + * @return the text rotation for drawings and plotting the footprint rotation is taken + * in account. + */ + EDA_ANGLE GetDrawRotation() const override; + + const BOX2I ViewBBox() const override; + + void ViewGetLayers( int aLayers[], int& aCount ) const override; + ///< @copydoc VIEW_ITEM::ViewGetLOD double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; @@ -154,6 +184,9 @@ protected: virtual void swapData( BOARD_ITEM* aImage ) override; int getKnockoutMargin() const; + +private: + TEXT_TYPE m_type; }; #endif // #define PCB_TEXT_H diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index ad369e8dfe..71c75bd7b7 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -485,22 +485,43 @@ void PCB_TEXTBOX::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID // Don't use PCB_SHAPE::TransformShapeToPolygon. We want to treat the textbox as filled even // if there's no background colour. - std::vector pts = GetRectCorners(); - - aBuffer.NewOutline(); - - for( const VECTOR2I& pt : pts ) - aBuffer.Append( pt ); - int width = GetWidth() + ( 2 * aClearance ); - if( width > 0 ) + if( GetShape() == SHAPE_T::RECT ) { - // Add in segments - TransformOvalToPolygon( aBuffer, pts[0], pts[1], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[1], pts[2], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[2], pts[3], width, aError, aErrorLoc ); - TransformOvalToPolygon( aBuffer, pts[3], pts[0], width, aError, aErrorLoc ); + std::vector pts = GetRectCorners(); + + aBuffer.NewOutline(); + + for( const VECTOR2I& pt : pts ) + aBuffer.Append( pt ); + + if( width > 0 ) + { + // Add in segments + TransformOvalToPolygon( aBuffer, pts[0], pts[1], width, aError, aErrorLoc ); + TransformOvalToPolygon( aBuffer, pts[1], pts[2], width, aError, aErrorLoc ); + TransformOvalToPolygon( aBuffer, pts[2], pts[3], width, aError, aErrorLoc ); + TransformOvalToPolygon( aBuffer, pts[3], pts[0], width, aError, aErrorLoc ); + } + } + else if( GetShape() == SHAPE_T::POLY ) // Non-cardinally-rotated rect + { + aBuffer.NewOutline(); + + const SHAPE_LINE_CHAIN& poly = m_poly.Outline( 0 ); + + for( int ii = 0; ii < poly.PointCount(); ++ii ) + aBuffer.Append( poly.GetPoint( ii ) ); + + if( width > 0 ) + { + for( int ii = 0; ii < poly.SegmentCount(); ++ii ) + { + const SEG& seg = poly.GetSegment( ii ); + TransformOvalToPolygon( aBuffer, seg.A, seg.B, width, aError, aErrorLoc ); + } + } } } diff --git a/pcbnew/pcbplot.h b/pcbnew/pcbplot.h index 61e67b69ab..82c2ef7981 100644 --- a/pcbnew/pcbplot.h +++ b/pcbnew/pcbplot.h @@ -37,9 +37,7 @@ class PAD; class PCB_SHAPE; class PCB_DIMENSION_BASE; class FOOTPRINT; -class FP_SHAPE; class PCB_TARGET; -class FP_TEXT; class ZONE; class BOARD; class BOARD_ITEM; @@ -80,8 +78,7 @@ public: // Basic functions to plot a board item void SetLayerSet( LSET aLayerMask ) { m_layerMask = aLayerMask; } void PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ); - void PlotFootprintShape( const FP_SHAPE* aShape ); - void PlotFootprintTextItem( const FP_TEXT* aText, const COLOR4D& aColor ); + void PlotFootprintTextItem( const PCB_TEXT* aText, const COLOR4D& aColor ); /* * Reference, Value, and other fields are plotted only if the corresponding option is enabled. diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 98aca8848d..1b8b240be0 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -825,7 +824,7 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask, SHAPE_POLY_SET initialPolys; auto plotFPTextItem = - [&]( const FP_TEXT& aText ) + [&]( const PCB_TEXT& aText ) { if( !aText.IsVisible() && !itemplotter.GetPlotInvisibleText() ) return; @@ -865,9 +864,9 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask, { if( item->IsOnLayer( layer ) ) { - if( item->Type() == PCB_FP_TEXT_T ) + if( item->Type() == PCB_TEXT_T ) { - plotFPTextItem( static_cast( *item ) ); + plotFPTextItem( static_cast( *item ) ); } else { @@ -882,7 +881,8 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask, } else if( item->IsOnLayer( Edge_Cuts ) ) { - itemplotter.PlotFootprintShape( static_cast( item ) ); + if( item->Type() == PCB_SHAPE_T ) + itemplotter.PlotPcbShape( static_cast( item ) ); } } } diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 2e5f817777..5ef162e404 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -53,10 +53,7 @@ #include // for BOARD_ITEM, S_CIRCLE #include #include -#include #include -#include -#include #include #include #include @@ -296,8 +293,8 @@ void BRDITEMS_PLOTTER::PlotPad( const PAD* aPad, const COLOR4D& aColor, OUTLINE_ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint ) { - const FP_TEXT* textItem = &aFootprint->Reference(); - int textLayer = textItem->GetLayer(); + const PCB_TEXT* textItem = &aFootprint->Reference(); + int textLayer = textItem->GetLayer(); // Reference and value are specific items, not in graphic items list if( GetPlotReference() && m_layerMask[textLayer] @@ -317,7 +314,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItems( const FOOTPRINT* aFootprint ) for( const BOARD_ITEM* item : aFootprint->GraphicalItems() ) { - textItem = dyn_cast( item ); + textItem = dyn_cast( item ); if( !textItem ) continue; @@ -392,7 +389,7 @@ void BRDITEMS_PLOTTER::PlotBoardGraphicItems() } -void BRDITEMS_PLOTTER::PlotFootprintTextItem( const FP_TEXT* aText, const COLOR4D& aColor ) +void BRDITEMS_PLOTTER::PlotFootprintTextItem( const PCB_TEXT* aText, const COLOR4D& aColor ) { COLOR4D color = aColor; @@ -431,7 +428,7 @@ void BRDITEMS_PLOTTER::PlotFootprintTextItem( const FP_TEXT* aText, const COLOR4 gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_NONCONDUCTOR ); gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_CMP ); - const FOOTPRINT* parent = static_cast ( aText->GetParent() ); + const FOOTPRINT* parent = aText->GetParentFootprint(); gbr_metadata.SetCmpReference( parent->GetReference() ); m_plotter->SetCurrentLineWidth( thickness ); @@ -586,34 +583,34 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ) switch( item->Type() ) { - case PCB_FP_SHAPE_T: + case PCB_SHAPE_T: { - const FP_SHAPE* shape = static_cast( item ); + const PCB_SHAPE* shape = static_cast( item ); if( m_layerMask[ shape->GetLayer() ] ) - PlotFootprintShape( shape ); + PlotPcbShape( shape ); break; } - case PCB_FP_TEXTBOX_T: + case PCB_TEXTBOX_T: { - const FP_TEXTBOX* textbox = static_cast( item ); + const PCB_TEXTBOX* textbox = static_cast( item ); if( m_layerMask[ textbox->GetLayer() ] ) { PlotPcbText( textbox, textbox->GetLayer(), textbox->IsKnockout() ); - PlotFootprintShape( textbox ); + PlotPcbShape( textbox ); } break; } - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_LEADER_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_DIM_LEADER_T: { const PCB_DIMENSION_BASE* dimension = static_cast( item ); @@ -623,7 +620,7 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ) break; } - case PCB_FP_TEXT_T: + case PCB_TEXT_T: // Plotted in PlotFootprintTextItem() break; @@ -634,195 +631,6 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ) } -void BRDITEMS_PLOTTER::PlotFootprintShape( const FP_SHAPE* aShape ) -{ - m_plotter->SetColor( getColor( aShape->GetLayer() ) ); - - bool sketch = GetPlotMode() == SKETCH; - int thickness = aShape->GetWidth(); - - GBR_METADATA gbr_metadata; - gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_CMP ); - const FOOTPRINT* parent = static_cast ( aShape->GetParent() ); - gbr_metadata.SetCmpReference( parent->GetReference() ); - - bool isOnCopperLayer = ( m_layerMask & LSET::AllCuMask() ).any(); - - if( aShape->GetLayer() == Edge_Cuts ) // happens also when plotting copper layers - { - gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_EDGECUT ); - } - else if( isOnCopperLayer ) // only for items not on Edge_Cuts. - { - gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_ETCHEDCMP ); - gbr_metadata.SetCopper( true ); - } - - int radius; // Circle/arc radius. - PLOT_DASH_TYPE lineStyle = aShape->GetStroke().GetPlotStyle(); - - if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE ) - { - switch( aShape->GetShape() ) - { - case SHAPE_T::SEGMENT: - m_plotter->ThickSegment( aShape->GetStart(), aShape->GetEnd(), thickness, GetPlotMode(), - &gbr_metadata ); - break; - - case SHAPE_T::RECT: - { - std::vector pts = aShape->GetRectCorners(); - - if( sketch || thickness > 0 ) - { - m_plotter->ThickSegment( pts[0], pts[1], thickness, GetPlotMode(), &gbr_metadata ); - m_plotter->ThickSegment( pts[1], pts[2], thickness, GetPlotMode(), &gbr_metadata ); - m_plotter->ThickSegment( pts[2], pts[3], thickness, GetPlotMode(), &gbr_metadata ); - m_plotter->ThickSegment( pts[3], pts[0], thickness, GetPlotMode(), &gbr_metadata ); - } - - if( !sketch && aShape->IsFilled() ) - { - SHAPE_LINE_CHAIN poly; - - for( const VECTOR2I& pt : pts ) - poly.Append( pt ); - - m_plotter->PlotPoly( poly, FILL_T::FILLED_SHAPE, -1, &gbr_metadata ); - } - } - break; - - case SHAPE_T::CIRCLE: - radius = KiROUND( GetLineLength( aShape->GetStart(), aShape->GetEnd() ) ); - - if( aShape->IsFilled() ) - { - m_plotter->FilledCircle( aShape->GetStart(), radius * 2 + thickness, GetPlotMode(), - &gbr_metadata ); - } - else - { - m_plotter->ThickCircle( aShape->GetStart(), radius * 2, thickness, GetPlotMode(), - &gbr_metadata ); - } - - break; - - case SHAPE_T::ARC: - { - radius = KiROUND( GetLineLength( aShape->GetCenter(), aShape->GetStart() ) ); - - // when startAngle == endAngle ThickArc() doesn't know whether it's 0 deg and 360 deg - // but it is a circle - if( std::abs( aShape->GetArcAngle().AsDegrees() ) == 360.0 ) - { - m_plotter->ThickCircle( aShape->GetCenter(), radius * 2, thickness, GetPlotMode(), - &gbr_metadata ); - } - else - { - m_plotter->ThickArc( *aShape, GetPlotMode(), &gbr_metadata ); - } - } - break; - - case SHAPE_T::POLY: - if( aShape->IsPolyShapeValid() ) - { - std::vector cornerList; - aShape->DupPolyPointsList( cornerList ); - - // We must compute board coordinates from m_PolyList which are relative to the parent - // position at orientation 0 - const FOOTPRINT *parentFootprint = aShape->GetParentFootprint(); - - if( parentFootprint ) - { - for( unsigned ii = 0; ii < cornerList.size(); ++ii ) - { - RotatePoint( cornerList[ii], parentFootprint->GetOrientation() ); - cornerList[ii] += parentFootprint->GetPosition(); - } - } - - if( sketch ) - { - for( size_t i = 1; i < cornerList.size(); i++ ) - { - m_plotter->ThickSegment( cornerList[i - 1], cornerList[i], thickness, - GetPlotMode(), &gbr_metadata ); - } - - m_plotter->ThickSegment( cornerList.back(), cornerList.front(), thickness, - GetPlotMode(), &gbr_metadata ); - - } - else - { - // This must be simplified and fractured to prevent overlapping polygons - // from generating invalid Gerber files - - SHAPE_LINE_CHAIN line( cornerList ); - SHAPE_POLY_SET tmpPoly; - - line.SetClosed( true ); - tmpPoly.AddOutline( line ); - tmpPoly.Fracture( SHAPE_POLY_SET::PM_FAST ); - - for( int jj = 0; jj < tmpPoly.OutlineCount(); ++jj ) - { - SHAPE_LINE_CHAIN& poly = tmpPoly.Outline( jj ); - FILL_T fill_mode = aShape->IsFilled() ? FILL_T::FILLED_SHAPE - : FILL_T::NO_FILL; - // Plot the current filled area - // (as region for Gerber plotter to manage attributes) - if( m_plotter->GetPlotterType() == PLOT_FORMAT::GERBER ) - { - static_cast( m_plotter )-> - PlotPolyAsRegion( poly, fill_mode, - thickness, &gbr_metadata ); - } - else - m_plotter->PlotPoly( poly, fill_mode, - thickness, &gbr_metadata ); - } - } - } - - break; - - case SHAPE_T::BEZIER: - m_plotter->BezierCurve( aShape->GetStart(), aShape->GetBezierC1(), - aShape->GetBezierC2(), aShape->GetEnd(), 0, thickness ); - break; - - default: - wxASSERT_MSG( false, wxT( "Unhandled FP_SHAPE shape" ) ); - break; - } - } - else - { - std::vector shapes = aShape->MakeEffectiveShapes( true ); - - for( SHAPE* shape : shapes ) - { - STROKE_PARAMS::Stroke( shape, lineStyle, thickness, m_plotter->RenderSettings(), - [&]( const VECTOR2I& a, const VECTOR2I& b ) - { - m_plotter->ThickSegment( a, b, thickness, GetPlotMode(), - &gbr_metadata ); - } ); - } - - for( SHAPE* shape : shapes ) - delete shape; - } -} - - #include void BRDITEMS_PLOTTER::PlotPcbText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout ) { @@ -990,16 +798,31 @@ void BRDITEMS_PLOTTER::PlotPcbShape( const PCB_SHAPE* aShape ) m_plotter->SetColor( getColor( aShape->GetLayer() ) ); - GBR_METADATA gbr_metadata; + const FOOTPRINT* parentFP = aShape->GetParentFootprint(); + GBR_METADATA gbr_metadata; + + if( parentFP ) + gbr_metadata.SetCmpReference( parentFP->GetReference() ); if( aShape->GetLayer() == Edge_Cuts ) + { gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_EDGECUT ); - - if( IsCopperLayer( aShape->GetLayer() ) ) - // Graphic items (PCB_SHAPE, TEXT) having no net have the NonConductor attribute - // Graphic items having a net have the Conductor attribute, but are not (yet?) - // supported in Pcbnew - gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_NONCONDUCTOR ); + } + else if( IsCopperLayer( aShape->GetLayer() ) ) + { + if( parentFP ) + { + gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_ETCHEDCMP ); + gbr_metadata.SetCopper( true ); + } + else + { + // Graphic items (PCB_SHAPE, TEXT) having no net have the NonConductor attribute + // Graphic items having a net have the Conductor attribute, but are not (yet?) + // supported in Pcbnew + gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_NONCONDUCTOR ); + } + } if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE ) { @@ -1086,7 +909,9 @@ void BRDITEMS_PLOTTER::PlotPcbShape( const PCB_SHAPE* aShape ) PlotPolyAsRegion( poly, fill, thickness, &gbr_metadata ); } else + { m_plotter->PlotPoly( poly, fill, thickness, &gbr_metadata ); + } } } } @@ -1104,7 +929,8 @@ void BRDITEMS_PLOTTER::PlotPcbShape( const PCB_SHAPE* aShape ) m_plotter->ThickSegment( pts[2], pts[3], thickness, GetPlotMode(), &gbr_metadata ); m_plotter->ThickSegment( pts[3], pts[0], thickness, GetPlotMode(), &gbr_metadata ); } - else + + if( !sketch ) { SHAPE_LINE_CHAIN poly; @@ -1122,7 +948,9 @@ void BRDITEMS_PLOTTER::PlotPcbShape( const PCB_SHAPE* aShape ) PlotPolyAsRegion( poly, fill_mode, thickness, &gbr_metadata ); } else + { m_plotter->PlotPoly( poly, fill_mode, thickness, &gbr_metadata ); + } } break; diff --git a/pcbnew/plugins/altium/altium_circuit_maker_plugin.h b/pcbnew/plugins/altium/altium_circuit_maker_plugin.h index 786a51c24d..8422fbebff 100644 --- a/pcbnew/plugins/altium/altium_circuit_maker_plugin.h +++ b/pcbnew/plugins/altium/altium_circuit_maker_plugin.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 Thomas Pointhuber - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,11 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pcad_plugin.h - * @brief Pcbnew PLUGIN for Altium *.PcbDoc format. - */ - #ifndef ALTIUM_CIRCUIT_MAKER_PLUGIN_H_ #define ALTIUM_CIRCUIT_MAKER_PLUGIN_H_ diff --git a/pcbnew/plugins/altium/altium_circuit_studio_plugin.h b/pcbnew/plugins/altium/altium_circuit_studio_plugin.h index f5216653e2..d280a7c5ae 100644 --- a/pcbnew/plugins/altium/altium_circuit_studio_plugin.h +++ b/pcbnew/plugins/altium/altium_circuit_studio_plugin.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 Thomas Pointhuber - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,11 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pcad_plugin.h - * @brief Pcbnew PLUGIN for Altium *.PcbDoc format. - */ - #ifndef ALTIUM_CIRCUIT_STUDIO_PLUGIN_H_ #define ALTIUM_CIRCUIT_STUDIO_PLUGIN_H_ diff --git a/pcbnew/plugins/altium/altium_designer_plugin.h b/pcbnew/plugins/altium/altium_designer_plugin.h index f9a9c5fef8..c4f377a118 100644 --- a/pcbnew/plugins/altium/altium_designer_plugin.h +++ b/pcbnew/plugins/altium/altium_designer_plugin.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 Thomas Pointhuber - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,11 +22,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pcad_plugin.h - * @brief Pcbnew #PLUGIN for Altium *.PcbDoc format. - */ - #ifndef ALTIUM_DESIGNER_PLUGIN_H_ #define ALTIUM_DESIGNER_PLUGIN_H_ diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp index 5bd8e59cc8..3c456d2378 100644 --- a/pcbnew/plugins/altium/altium_pcb.cpp +++ b/pcbnew/plugins/altium/altium_pcb.cpp @@ -35,9 +35,6 @@ #include #include #include - -#include -#include #include #include @@ -101,7 +98,7 @@ PCB_SHAPE* ALTIUM_PCB::HelperCreateAndAddShape( uint16_t aComponent ) } FOOTPRINT* footprint = m_components.at( aComponent ); - PCB_SHAPE* fpShape = new FP_SHAPE( footprint ); + PCB_SHAPE* fpShape = new PCB_SHAPE( footprint ); footprint->Add( fpShape, ADD_MODE::APPEND ); return fpShape; @@ -109,53 +106,6 @@ PCB_SHAPE* ALTIUM_PCB::HelperCreateAndAddShape( uint16_t aComponent ) } -void ALTIUM_PCB::HelperShapeSetLocalCoord( PCB_SHAPE* aShape, uint16_t aComponent ) -{ - if( aComponent != ALTIUM_COMPONENT_NONE ) - { - FP_SHAPE* fpShape = dynamic_cast( aShape ); - - if( fpShape ) - { - fpShape->SetLocalCoord(); - - // TODO: SetLocalCoord() does not update the polygon shape! - // This workaround converts the poly shape into the local coordinates - SHAPE_POLY_SET& polyShape = fpShape->GetPolyShape(); - - if( !polyShape.IsEmpty() ) - { - FOOTPRINT* fp = m_components.at( aComponent ); - - polyShape.Move( -fp->GetPosition() ); - polyShape.Rotate( fp->GetOrientation() ); - } - } - } -} - - -void ALTIUM_PCB::HelperShapeSetLocalCoord( FP_SHAPE* aShape ) -{ - aShape->SetLocalCoord(); - - // TODO: SetLocalCoord() does not update the polygon shape! - // This workaround converts the poly shape into the local coordinates - SHAPE_POLY_SET& polyShape = aShape->GetPolyShape(); - - if( !polyShape.IsEmpty() ) - { - FOOTPRINT* fp = dynamic_cast( aShape->GetParent() ); - - if( fp ) - { - polyShape.Move( -fp->GetPosition() ); - polyShape.Rotate( fp->GetOrientation() ); - } - } -} - - void HelperShapeLineChainFromAltiumVertices( SHAPE_LINE_CHAIN& aLine, const std::vector& aVertices ) { @@ -1982,7 +1932,7 @@ void ALTIUM_PCB::ConvertShapeBasedRegions6ToFootprintItem( FOOTPRINT* aFoot return; } - FP_ZONE* zone = new FP_ZONE( aFootprint ); + ZONE* zone = new ZONE( aFootprint ); aFootprint->Add( zone, ADD_MODE::APPEND ); zone->SetIsRuleArea( true ); @@ -2052,14 +2002,13 @@ void ALTIUM_PCB::ConvertShapeBasedRegions6ToFootprintItemOnLayer( FOOTPRINT* return; } - FP_SHAPE* shape = new FP_SHAPE( aFootprint, SHAPE_T::POLY ); + PCB_SHAPE* shape = new PCB_SHAPE( aFootprint, SHAPE_T::POLY ); shape->SetPolyShape( linechain ); shape->SetFilled( true ); shape->SetLayer( aLayer ); shape->SetStroke( STROKE_PARAMS( 0 ) ); - HelperShapeSetLocalCoord( shape ); aFootprint->Add( shape, ADD_MODE::APPEND ); } @@ -2283,13 +2232,12 @@ void ALTIUM_PCB::ConvertArcs6ToFootprintItem( FOOTPRINT* aFootprint, const AARC6 if( width > 1 ) { - FP_SHAPE* arc = new FP_SHAPE( aFootprint ); + PCB_SHAPE* arc = new PCB_SHAPE( aFootprint ); ConvertArcs6ToPcbShape( aElem, arc ); arc->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) ); arc->SetLayer( layerExpansionMask.first ); - arc->SetLocalCoord(); aFootprint->Add( arc, ADD_MODE::APPEND ); } } @@ -2339,13 +2287,12 @@ void ALTIUM_PCB::ConvertArcs6ToBoardItemOnLayer( const AARC6& aElem, PCB_LAYER_I void ALTIUM_PCB::ConvertArcs6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, const AARC6& aElem, PCB_LAYER_ID aLayer ) { - FP_SHAPE* arc = new FP_SHAPE( aFootprint ); + PCB_SHAPE* arc = new PCB_SHAPE( aFootprint ); ConvertArcs6ToPcbShape( aElem, arc ); arc->SetStroke( STROKE_PARAMS( aElem.width, PLOT_DASH_TYPE::SOLID ) ); arc->SetLayer( aLayer ); - arc->SetLocalCoord(); aFootprint->Add( arc, ADD_MODE::APPEND ); } @@ -2638,11 +2585,10 @@ void ALTIUM_PCB::ConvertPads6ToFootprintItemOnNonCopper( FOOTPRINT* aFootprint, klayer = Eco1_User; } - FP_SHAPE* pad = new FP_SHAPE( aFootprint ); + PCB_SHAPE* pad = new PCB_SHAPE( aFootprint ); HelperParsePad6NonCopper( aElem, klayer, pad ); - HelperShapeSetLocalCoord( pad ); aFootprint->Add( pad, ADD_MODE::APPEND ); } @@ -2984,14 +2930,13 @@ void ALTIUM_PCB::ConvertTracks6ToFootprintItem( FOOTPRINT* aFootprint, const ATR int width = aElem.width + ( layerExpansionMask.second * 2 ); if( width > 1 ) { - FP_SHAPE* seg = new FP_SHAPE( aFootprint, SHAPE_T::SEGMENT ); + PCB_SHAPE* seg = new PCB_SHAPE( aFootprint, SHAPE_T::SEGMENT ); seg->SetStart( aElem.start ); seg->SetEnd( aElem.end ); seg->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) ); seg->SetLayer( layerExpansionMask.first ); - seg->SetLocalCoord(); aFootprint->Add( seg, ADD_MODE::APPEND ); } } @@ -3029,14 +2974,13 @@ void ALTIUM_PCB::ConvertTracks6ToBoardItemOnLayer( const ATRACK6& aElem, PCB_LAY void ALTIUM_PCB::ConvertTracks6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, const ATRACK6& aElem, PCB_LAYER_ID aLayer ) { - FP_SHAPE* seg = new FP_SHAPE( aFootprint, SHAPE_T::SEGMENT ); + PCB_SHAPE* seg = new PCB_SHAPE( aFootprint, SHAPE_T::SEGMENT ); seg->SetStart( aElem.start ); seg->SetEnd( aElem.end ); seg->SetStroke( STROKE_PARAMS( aElem.width, PLOT_DASH_TYPE::SOLID ) ); seg->SetLayer( aLayer ); - seg->SetLocalCoord(); aFootprint->Add( seg, ADD_MODE::APPEND ); } @@ -3136,7 +3080,8 @@ void ALTIUM_PCB::ConvertTexts6ToBoardItemOnLayer( const ATEXT6& aElem, PCB_LAYER void ALTIUM_PCB::ConvertTexts6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, const ATEXT6& aElem, PCB_LAYER_ID aLayer ) { - FP_TEXT* fpText; + PCB_TEXT* fpText; + if( aElem.isDesignator ) { fpText = &aFootprint->Reference(); // TODO: handle multiple layers @@ -3147,7 +3092,7 @@ void ALTIUM_PCB::ConvertTexts6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, con } else { - fpText = new FP_TEXT( aFootprint ); + fpText = new PCB_TEXT( aFootprint, PCB_TEXT::TEXT_is_DIVERS ); aFootprint->Add( fpText, ADD_MODE::APPEND ); } @@ -3166,12 +3111,10 @@ void ALTIUM_PCB::ConvertTexts6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, con fpText->SetKeepUpright( false ); fpText->SetLayer( aLayer ); - fpText->SetPosition( aElem.position ); - fpText->SetTextAngle( EDA_ANGLE( aElem.rotation, DEGREES_T ) - aFootprint->GetOrientation() ); + fpText->SetFPRelativePosition( aElem.position ); + fpText->SetTextAngle( EDA_ANGLE( aElem.rotation, DEGREES_T ) ); ConvertTexts6ToEdaTextSettings( aElem, fpText ); - - fpText->SetLocalCoord(); } @@ -3395,7 +3338,7 @@ void ALTIUM_PCB::ConvertFills6ToBoardItemOnLayer( const AFILL6& aElem, PCB_LAYER void ALTIUM_PCB::ConvertFills6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, const AFILL6& aElem, PCB_LAYER_ID aLayer ) { - FP_SHAPE* fill = new FP_SHAPE( aFootprint, SHAPE_T::RECT ); + PCB_SHAPE* fill = new PCB_SHAPE( aFootprint, SHAPE_T::RECT ); fill->SetFilled( true ); fill->SetLayer( aLayer ); @@ -3411,7 +3354,6 @@ void ALTIUM_PCB::ConvertFills6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, con fill->Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) ); } - fill->SetLocalCoord(); aFootprint->Add( fill, ADD_MODE::APPEND ); } @@ -3475,7 +3417,7 @@ void ALTIUM_PCB::HelperPcpShapeAsFootprintKeepoutRegion( FOOTPRINT* aFoo const ALTIUM_LAYER aAltiumLayer, const uint8_t aKeepoutRestrictions ) { - FP_ZONE* zone = new FP_ZONE( aFootprint ); + ZONE* zone = new ZONE( aFootprint ); zone->SetIsRuleArea( true ); diff --git a/pcbnew/plugins/altium/altium_pcb.h b/pcbnew/plugins/altium/altium_pcb.h index 3cec9c0ae7..9faacfcb11 100644 --- a/pcbnew/plugins/altium/altium_pcb.h +++ b/pcbnew/plugins/altium/altium_pcb.h @@ -234,8 +234,6 @@ private: FOOTPRINT* HelperGetFootprint( uint16_t aComponent ) const; PCB_SHAPE* HelperCreateAndAddShape( uint16_t aComponent ); - void HelperShapeSetLocalCoord( PCB_SHAPE* aShape, uint16_t aComponent ); - void HelperShapeSetLocalCoord( FP_SHAPE* aShape ); BOARD* m_board; std::vector m_components; diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index b01798d70d..5680276c9b 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -2781,12 +2780,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarShape( const SHAPE& aCadstarShape, break; } - PCB_SHAPE* shape; - - if( isFootprint( aContainer ) ) - shape = new FP_SHAPE( (FOOTPRINT*) aContainer, SHAPE_T::POLY ); - else - shape = new PCB_SHAPE( aContainer, SHAPE_T::POLY ); + PCB_SHAPE* shape = new PCB_SHAPE( aContainer, SHAPE_T::POLY ); shape->SetFilled( true ); @@ -2919,11 +2913,7 @@ PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex( const POINT& aCadstar { case VERTEX_TYPE::POINT: - - if( isFootprint( aContainer ) ) - shape = new FP_SHAPE( static_cast( aContainer ), SHAPE_T::SEGMENT ); - else - shape = new PCB_SHAPE( aContainer, SHAPE_T::SEGMENT ); + shape = new PCB_SHAPE( aContainer, SHAPE_T::SEGMENT ); shape->SetStart( startPoint ); shape->SetEnd( endPoint ); @@ -2937,10 +2927,7 @@ PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex( const POINT& aCadstar case VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE: case VERTEX_TYPE::ANTICLOCKWISE_ARC: { - if( isFootprint( aContainer ) ) - shape = new FP_SHAPE((FOOTPRINT*) aContainer, SHAPE_T::ARC ); - else - shape = new PCB_SHAPE( aContainer, SHAPE_T::ARC ); + shape = new PCB_SHAPE( aContainer, SHAPE_T::ARC ); shape->SetCenter( centerPoint ); shape->SetStart( startPoint ); @@ -2977,9 +2964,6 @@ PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex( const POINT& aCadstar if( aMoveVector != VECTOR2I{ 0, 0 } ) shape->Move( aMoveVector ); - if( isFootprint( aContainer ) && shape != nullptr ) - static_cast( shape )->SetLocalCoord(); - if( !aCadstarGroupID.IsEmpty() ) addToGroup( aCadstarGroupID, shape ); @@ -2991,7 +2975,7 @@ ZONE* CADSTAR_PCB_ARCHIVE_LOADER::getZoneFromCadstarShape( const SHAPE& aCadstar const int& aLineThickness, BOARD_ITEM_CONTAINER* aParentContainer ) { - ZONE* zone = new ZONE( aParentContainer, isFootprint( aParentContainer ) ); + ZONE* zone = new ZONE( aParentContainer ); if( aCadstarShape.Type == SHAPE_TYPE::HATCHED ) { @@ -3084,39 +3068,18 @@ SHAPE_LINE_CHAIN CADSTAR_PCB_ARCHIVE_LOADER::getLineChainFromShapes( const std:: { case SHAPE_T::ARC: { - if( shape->GetClass() == wxT( "MGRAPHIC" ) ) - { - FP_SHAPE* fp_shape = (FP_SHAPE*) shape; - SHAPE_ARC arc( fp_shape->GetCenter0(), fp_shape->GetStart0(), fp_shape->GetArcAngle() ); + SHAPE_ARC arc( shape->GetCenter(), shape->GetStart(), shape->GetArcAngle() ); - if( shape->EndsSwapped() ) - arc.Reverse(); + if( shape->EndsSwapped() ) + arc.Reverse(); - lineChain.Append( arc ); - } - else - { - SHAPE_ARC arc( shape->GetCenter(), shape->GetStart(), shape->GetArcAngle() ); - - if( shape->EndsSwapped() ) - arc.Reverse(); - - lineChain.Append( arc ); - } + lineChain.Append( arc ); + break; } - break; + case SHAPE_T::SEGMENT: - if( shape->GetClass() == wxT( "MGRAPHIC" ) ) - { - FP_SHAPE* fp_shape = (FP_SHAPE*) shape; - lineChain.Append( fp_shape->GetStart0().x, fp_shape->GetStart0().y ); - lineChain.Append( fp_shape->GetEnd0().x, fp_shape->GetEnd0().y ); - } - else - { - lineChain.Append( shape->GetStartX(), shape->GetStartY() ); - lineChain.Append( shape->GetEndX(), shape->GetEndY() ); - } + lineChain.Append( shape->GetStartX(), shape->GetStartY() ); + lineChain.Append( shape->GetEndX(), shape->GetEndY() ); break; default: @@ -3173,40 +3136,20 @@ std::vector CADSTAR_PCB_ARCHIVE_LOADER::makeTracksFromShapes( switch( shape->GetShape() ) { case SHAPE_T::ARC: - if( shape->GetClass() == wxT( "MGRAPHIC" ) ) - { - FP_SHAPE* fp_shape = (FP_SHAPE*) shape; - SHAPE_ARC arc( fp_shape->GetStart0(), fp_shape->GetArcMid0(), fp_shape->GetEnd0(), 0 ); + { + SHAPE_ARC arc( shape->GetStart(), shape->GetArcMid(), shape->GetEnd(), 0 ); - if( fp_shape->EndsSwapped() ) - arc.Reverse(); + if( shape->EndsSwapped() ) + arc.Reverse(); - track = new PCB_ARC( aParentContainer, &arc ); - } - else - { - SHAPE_ARC arc( shape->GetStart(), shape->GetArcMid(), shape->GetEnd(), 0 ); - - if( shape->EndsSwapped() ) - arc.Reverse(); - - track = new PCB_ARC( aParentContainer, &arc ); - } + track = new PCB_ARC( aParentContainer, &arc ); break; + } + case SHAPE_T::SEGMENT: - if( shape->GetClass() == wxT( "MGRAPHIC" ) ) - { - FP_SHAPE* fp_shape = (FP_SHAPE*) shape; - track = new PCB_TRACK( aParentContainer ); - track->SetStart( fp_shape->GetStart0() ); - track->SetEnd( fp_shape->GetEnd0() ); - } - else - { - track = new PCB_TRACK( aParentContainer ); - track->SetStart( shape->GetStart() ); - track->SetEnd( shape->GetEnd() ); - } + track = new PCB_TRACK( aParentContainer ); + track->SetStart( shape->GetStart() ); + track->SetEnd( shape->GetEnd() ); break; default: @@ -3286,7 +3229,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::addAttribute( const ATTRIBUTE_LOCATION& aCadsta FOOTPRINT* aFootprint, const wxString& aAttributeValue ) { - FP_TEXT* txt; + PCB_TEXT* txt; if( aCadstarAttributeID == COMPONENT_NAME_ATTRID ) { @@ -3302,7 +3245,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::addAttribute( const ATTRIBUTE_LOCATION& aCadsta } else { - txt = new FP_TEXT( aFootprint ); + txt = new PCB_TEXT( aFootprint ); aFootprint->Add( txt ); txt->SetText( aAttributeValue ); } @@ -3323,21 +3266,17 @@ void CADSTAR_PCB_ARCHIVE_LOADER::addAttribute( const ATTRIBUTE_LOCATION& aCadsta } else { - txt = new FP_TEXT( aFootprint ); + txt = new PCB_TEXT( aFootprint ); aFootprint->Add( txt ); txt->SetText( aAttributeValue ); txt->SetVisible( false ); //make all user attributes invisible to avoid clutter. //TODO: Future improvement - allow user to decide what to do with attributes } - VECTOR2I rotatedTextPos = getKiCadPoint( aCadstarAttrLoc.Position ) - aFootprint->GetPosition(); - RotatePoint( rotatedTextPos, -aFootprint->GetOrientation() ); - - txt->SetTextPos( getKiCadPoint( aCadstarAttrLoc.Position ) ); - txt->SetPos0( rotatedTextPos ); + txt->SetPosition( getKiCadPoint( aCadstarAttrLoc.Position ) ); txt->SetLayer( getKiCadLayer( aCadstarAttrLoc.LayerID ) ); txt->SetMirrored( aCadstarAttrLoc.Mirror ); - txt->SetTextAngle( getAngle( aCadstarAttrLoc.OrientAngle ) - aFootprint->GetOrientation() ); + txt->SetTextAngle( getAngle( aCadstarAttrLoc.OrientAngle ) ); if( aCadstarAttrLoc.Mirror ) // If mirroring, invert angle to match CADSTAR txt->SetTextAngle( -txt->GetTextAngle() ); diff --git a/pcbnew/plugins/eagle/eagle_plugin.cpp b/pcbnew/plugins/eagle/eagle_plugin.cpp index 18b1c7f9ca..32f98718c4 100644 --- a/pcbnew/plugins/eagle/eagle_plugin.cpp +++ b/pcbnew/plugins/eagle/eagle_plugin.cpp @@ -70,7 +70,7 @@ Load() TODO's #include #include #include -#include +#include #include #include #include @@ -1393,10 +1393,6 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) orientFootprintAndText( footprint, e, nameAttr, valueAttr ); - // Set the local coordinates for the footprint text items - footprint->Reference().SetLocalCoord(); - footprint->Value().SetLocalCoord(); - // Get next element element = element->GetNext(); } @@ -1576,7 +1572,7 @@ void EAGLE_PLUGIN::orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT } -void EAGLE_PLUGIN::orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TEXT* aFPText, +void EAGLE_PLUGIN::orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, PCB_TEXT* aFPText, const EATTR* aAttr ) { // Smashed part ? @@ -1624,7 +1620,6 @@ void EAGLE_PLUGIN::orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TE // package's text field. If they did not want zero, they specify // what they want explicitly. double degrees = a.rot ? a.rot->degrees : 0.0; - double orient; // relative to parent int sign = 1; bool spin = false; @@ -1638,25 +1633,21 @@ void EAGLE_PLUGIN::orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TE if( degrees == 90 || degrees == 0 || spin ) { - orient = degrees - aFootprint->GetOrientation().AsDegrees(); - aFPText->SetTextAngle( EDA_ANGLE( sign * orient, DEGREES_T ) ); + aFPText->SetTextAngle( EDA_ANGLE( sign * degrees, DEGREES_T ) ); } else if( degrees == 180 ) { - orient = 0 - aFootprint->GetOrientation().AsDegrees(); - aFPText->SetTextAngle( EDA_ANGLE( sign * orient, DEGREES_T ) ); + aFPText->SetTextAngle( EDA_ANGLE( sign * 0, DEGREES_T ) ); align = -align; } else if( degrees == 270 ) { - orient = 90 - aFootprint->GetOrientation().AsDegrees(); align = -align; - aFPText->SetTextAngle( EDA_ANGLE( sign * orient, DEGREES_T ) ); + aFPText->SetTextAngle( EDA_ANGLE( sign * 90, DEGREES_T ) ); } else { - orient = 90 - degrees - aFootprint->GetOrientation().AsDegrees(); - aFPText->SetTextAngle( EDA_ANGLE( sign * orient, DEGREES_T ) ); + aFPText->SetTextAngle( EDA_ANGLE( sign * 90 - degrees, DEGREES_T ) ); } switch( align ) @@ -1820,28 +1811,29 @@ void EAGLE_PLUGIN::packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const } // FIXME: the cap attribute is ignored because KiCad can't create lines with flat ends. - FP_SHAPE* dwg; + PCB_SHAPE* dwg; if( !w.curve ) { - dwg = new FP_SHAPE( aFootprint, SHAPE_T::SEGMENT ); + dwg = new PCB_SHAPE( aFootprint, SHAPE_T::SEGMENT ); - dwg->SetStart0( start ); - dwg->SetEnd0( end ); + dwg->SetStart( start ); + dwg->SetEnd( end ); } else { - dwg = new FP_SHAPE( aFootprint, SHAPE_T::ARC ); + dwg = new PCB_SHAPE( aFootprint, SHAPE_T::ARC ); VECTOR2I center = ConvertArcCenter( start, end, *w.curve ); - dwg->SetCenter0( center ); - dwg->SetStart0( start ); - dwg->SetArcAngleAndEnd0( -EDA_ANGLE( *w.curve, DEGREES_T ), true ); // KiCad rotates the other way + dwg->SetCenter( center ); + dwg->SetStart( start ); + dwg->SetArcAngleAndEnd( -EDA_ANGLE( *w.curve, DEGREES_T ), true ); // KiCad rotates the other way } dwg->SetLayer( layer ); dwg->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) ); - dwg->SetDrawCoord(); + dwg->Rotate( { 0, 0 }, aFootprint->GetOrientation() ); + dwg->Move( aFootprint->GetPosition() ); aFootprint->Add( dwg ); } @@ -1964,7 +1956,7 @@ void EAGLE_PLUGIN::packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const return; } - FP_TEXT* textItem; + PCB_TEXT* textItem; if( t.text.Upper() == wxT( ">NAME" ) && aFootprint->GetReference().IsEmpty() ) { @@ -1980,8 +1972,7 @@ void EAGLE_PLUGIN::packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const } else { - // FIXME: graphical text items are rotated for some reason. - textItem = new FP_TEXT( aFootprint ); + textItem = new PCB_TEXT( aFootprint, PCB_TEXT::TEXT_is_DIVERS ); aFootprint->Add( textItem ); textItem->SetText( interpretText( t.text ) ); @@ -1989,9 +1980,7 @@ void EAGLE_PLUGIN::packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const VECTOR2I pos( kicad_x( t.x ), kicad_y( t.y ) ); - textItem->SetTextPos( pos ); - textItem->SetPos0( pos - aFootprint->GetPosition() ); - + textItem->SetPosition( pos ); textItem->SetLayer( layer ); double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default @@ -2084,7 +2073,7 @@ void EAGLE_PLUGIN::packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) c if( r.layer == EAGLE_LAYER::TRESTRICT || r.layer == EAGLE_LAYER::BRESTRICT || r.layer == EAGLE_LAYER::VRESTRICT ) { - FP_ZONE* zone = new FP_ZONE( aFootprint ); + ZONE* zone = new ZONE( aFootprint ); aFootprint->Add( zone, ADD_MODE::APPEND ); setKeepoutSettingsToZone( zone, r.layer ); @@ -2117,7 +2106,7 @@ void EAGLE_PLUGIN::packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) c return; } - FP_SHAPE* dwg = new FP_SHAPE( aFootprint, SHAPE_T::POLY ); + PCB_SHAPE* dwg = new PCB_SHAPE( aFootprint, SHAPE_T::POLY ); aFootprint->Add( dwg ); @@ -2139,6 +2128,9 @@ void EAGLE_PLUGIN::packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) c if( r.rot ) dwg->Rotate( dwg->GetCenter(), EDA_ANGLE( r.rot->degrees, DEGREES_T ) ); + + dwg->Rotate( { 0, 0 }, aFootprint->GetOrientation() ); + dwg->Move( aFootprint->GetPosition() ); } } @@ -2209,7 +2201,7 @@ void EAGLE_PLUGIN::packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) con || p.layer == EAGLE_LAYER::BRESTRICT || p.layer == EAGLE_LAYER::VRESTRICT ) { - FP_ZONE* zone = new FP_ZONE( aFootprint ); + ZONE* zone = new ZONE( aFootprint ); aFootprint->Add( zone, ADD_MODE::APPEND ); setKeepoutSettingsToZone( zone, p.layer ); @@ -2231,7 +2223,7 @@ void EAGLE_PLUGIN::packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) con return; } - FP_SHAPE* dwg = new FP_SHAPE( aFootprint, SHAPE_T::POLY ); + PCB_SHAPE* dwg = new PCB_SHAPE( aFootprint, SHAPE_T::POLY ); aFootprint->Add( dwg ); @@ -2240,7 +2232,8 @@ void EAGLE_PLUGIN::packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) con dwg->SetLayer( layer ); dwg->SetPolyPoints( pts ); - dwg->SetDrawCoord(); + dwg->Rotate( { 0, 0 }, aFootprint->GetOrientation() ); + dwg->Move( aFootprint->GetPosition() ); dwg->GetPolyShape().Inflate( p.width.ToPcbUnits() / 2, 32, SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS ); } @@ -2258,7 +2251,7 @@ void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) cons || e.layer == EAGLE_LAYER::BRESTRICT || e.layer == EAGLE_LAYER::VRESTRICT ) { - FP_ZONE* zone = new FP_ZONE( aFootprint ); + ZONE* zone = new ZONE( aFootprint ); aFootprint->Add( zone, ADD_MODE::APPEND ); setKeepoutSettingsToZone( zone, e.layer ); @@ -2306,7 +2299,7 @@ void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) cons return; } - FP_SHAPE* gr = new FP_SHAPE( aFootprint, SHAPE_T::CIRCLE ); + PCB_SHAPE* gr = new PCB_SHAPE( aFootprint, SHAPE_T::CIRCLE ); // width == 0 means filled circle if( width <= 0 ) @@ -2329,9 +2322,10 @@ void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) cons } gr->SetLayer( layer ); - gr->SetStart0( VECTOR2I( kicad_x( e.x ), kicad_y( e.y ) ) ); - gr->SetEnd0( VECTOR2I( kicad_x( e.x ) + radius, kicad_y( e.y ) ) ); - gr->SetDrawCoord(); + gr->SetStart( VECTOR2I( kicad_x( e.x ), kicad_y( e.y ) ) ); + gr->SetEnd( VECTOR2I( kicad_x( e.x ) + radius, kicad_y( e.y ) ) ); + gr->Rotate( { 0, 0 }, aFootprint->GetOrientation() ); + gr->Move( aFootprint->GetPosition() ); } } diff --git a/pcbnew/plugins/eagle/eagle_plugin.h b/pcbnew/plugins/eagle/eagle_plugin.h index 420741ae0c..fe90ef153b 100644 --- a/pcbnew/plugins/eagle/eagle_plugin.h +++ b/pcbnew/plugins/eagle/eagle_plugin.h @@ -37,7 +37,7 @@ #include class PAD; -class FP_TEXT; +class PCB_TEXT; class ZONE; typedef std::map FOOTPRINT_MAP; @@ -278,7 +278,7 @@ private: void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr, const EATTR* aValueAttr ); - void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TEXT* aFPText, + void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, PCB_TEXT* aFPText, const EATTR* aAttr ); diff --git a/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp b/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp index dd94a3e200..e724a9b753 100644 --- a/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp +++ b/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 BeagleBoard Foundation - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,7 +23,6 @@ */ /** - * @file pcad_plugin.cpp * @brief Pcbnew PLUGIN for FABMASTER ASCII *.txt / *.fab format. */ diff --git a/pcbnew/plugins/fabmaster/import_fabmaster.cpp b/pcbnew/plugins/fabmaster/import_fabmaster.cpp index f8df9c0e6d..8eb4696ecf 100644 --- a/pcbnew/plugins/fabmaster/import_fabmaster.cpp +++ b/pcbnew/plugins/fabmaster/import_fabmaster.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 BeagleBoard Foundation - * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors. * Author: Seth Hillbrand * * This program is free software; you can redistribute it and/or @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -2022,7 +2021,7 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) if( lsrc->text == src->refdes ) { - FP_TEXT* txt = nullptr; + PCB_TEXT* txt = nullptr; PCB_LAYER_ID layer = getLayer( ref->layer ); if( !IsPcbLayer( layer ) ) @@ -2034,7 +2033,7 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) if( layer == F_SilkS || layer == B_SilkS ) txt = &( fp->Reference() ); else - txt = new FP_TEXT( fp ); + txt = new PCB_TEXT( fp, PCB_TEXT::TEXT_is_DIVERS ); if( src->mirror ) { @@ -2053,7 +2052,6 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) txt->SetTextHeight( lsrc->height ); txt->SetTextWidth( lsrc->width ); txt->SetHorizJustify( lsrc->orient ); - txt->SetLocalCoord(); if( txt != &fp->Reference() ) fp->Add( txt, ADD_MODE::APPEND ); @@ -2092,7 +2090,7 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) { const GRAPHIC_LINE* lsrc = static_cast( seg.get() ); - FP_SHAPE* line = new FP_SHAPE( fp, SHAPE_T::SEGMENT ); + PCB_SHAPE* line = new PCB_SHAPE( fp, SHAPE_T::SEGMENT ); if( src->mirror ) { @@ -2108,7 +2106,9 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) } line->SetStroke( STROKE_PARAMS( lsrc->width, PLOT_DASH_TYPE::SOLID ) ); - line->SetLocalCoord(); + + line->Rotate( { 0, 0 }, fp->GetOrientation() ); + line->Move( fp->GetPosition() ); if( lsrc->width == 0 ) line->SetStroke( defaultStroke ); @@ -2120,13 +2120,15 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) { const GRAPHIC_ARC* lsrc = static_cast( seg.get() ); - FP_SHAPE* circle = new FP_SHAPE( fp, SHAPE_T::CIRCLE ); + PCB_SHAPE* circle = new PCB_SHAPE( fp, SHAPE_T::CIRCLE ); circle->SetLayer( layer ); circle->SetCenter( VECTOR2I( lsrc->center_x, lsrc->center_y ) ); circle->SetEnd( VECTOR2I( lsrc->end_x, lsrc->end_y ) ); circle->SetWidth( lsrc->width ); - circle->SetLocalCoord(); + + circle->Rotate( { 0, 0 }, fp->GetOrientation() ); + circle->Move( fp->GetPosition() ); if( lsrc->width == 0 ) circle->SetWidth( ds.GetLineThickness( circle->GetLayer() ) ); @@ -2141,14 +2143,16 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) { const GRAPHIC_ARC* lsrc = static_cast( seg.get() ); - FP_SHAPE* arc = new FP_SHAPE( fp, SHAPE_T::ARC ); + PCB_SHAPE* arc = new PCB_SHAPE( fp, SHAPE_T::ARC ); arc->SetLayer( layer ); arc->SetArcGeometry( lsrc->result.GetP0(), lsrc->result.GetArcMid(), lsrc->result.GetP1() ); arc->SetStroke( STROKE_PARAMS( lsrc->width, PLOT_DASH_TYPE::SOLID ) ); - arc->SetLocalCoord(); + + arc->Rotate( { 0, 0 }, fp->GetOrientation() ); + arc->Move( fp->GetPosition() ); if( lsrc->width == 0 ) arc->SetStroke( defaultStroke ); @@ -2164,7 +2168,7 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) const GRAPHIC_RECTANGLE *lsrc = static_cast( seg.get() ); - FP_SHAPE* rect = new FP_SHAPE( fp, SHAPE_T::RECT ); + PCB_SHAPE* rect = new PCB_SHAPE( fp, SHAPE_T::RECT ); if( src->mirror ) { @@ -2180,7 +2184,9 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) } rect->SetStroke( defaultStroke ); - rect->SetLocalCoord(); + + rect->Rotate( { 0, 0 }, fp->GetOrientation() ); + rect->Move( fp->GetPosition() ); fp->Add( rect, ADD_MODE::APPEND ); break; @@ -2190,7 +2196,7 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) const GRAPHIC_TEXT *lsrc = static_cast( seg.get() ); - FP_TEXT* txt = new FP_TEXT( fp ); + PCB_TEXT* txt = new PCB_TEXT( fp ); if( src->mirror ) { @@ -2209,7 +2215,6 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) txt->SetTextHeight( lsrc->height ); txt->SetTextWidth( lsrc->width ); txt->SetHorizJustify( lsrc->orient ); - txt->SetLocalCoord(); // FABMASTER doesn't have visibility flags but layers that are not silk should be hidden // by default to prevent clutter. diff --git a/pcbnew/plugins/geda/gpcb_plugin.cpp b/pcbnew/plugins/geda/gpcb_plugin.cpp index ee17211f06..3542698a88 100644 --- a/pcbnew/plugins/geda/gpcb_plugin.cpp +++ b/pcbnew/plugins/geda/gpcb_plugin.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 Wayne Stambaugh - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -413,8 +412,7 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader ) textPos.x -= thsize / 10; textPos.y += thsize / 2; - footprint->Reference().SetTextPos( textPos ); - footprint->Reference().SetPos0( textPos ); + footprint->Reference().SetFPRelativePosition( textPos ); footprint->Reference().SetTextSize( VECTOR2I( twsize, thsize ) ); footprint->Reference().SetTextThickness( thickness ); @@ -425,8 +423,7 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader ) footprint->Value().SetTextSize( footprint->Reference().GetTextSize() ); footprint->Value().SetTextThickness( footprint->Reference().GetTextThickness() ); textPos.y += thsize * 13 / 10; // 130% line height - footprint->Value().SetTextPos( textPos ); - footprint->Value().SetPos0( textPos ); + footprint->Value().SetFPRelativePosition( textPos ); while( aLineReader->ReadLine() ) { @@ -463,15 +460,18 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader ) aLineReader->LineNumber(), 0 ); } - FP_SHAPE* shape = new FP_SHAPE( footprint.get(), SHAPE_T::SEGMENT ); + PCB_SHAPE* shape = new PCB_SHAPE( footprint.get(), SHAPE_T::SEGMENT ); shape->SetLayer( F_SilkS ); - shape->SetStart0( VECTOR2I( parseInt( parameters[2], conv_unit ), - parseInt( parameters[3], conv_unit ) ) ); - shape->SetEnd0( VECTOR2I( parseInt( parameters[4], conv_unit ), - parseInt( parameters[5], conv_unit ) ) ); + shape->SetStart( VECTOR2I( parseInt( parameters[2], conv_unit ), + parseInt( parameters[3], conv_unit ) ) ); + shape->SetEnd( VECTOR2I( parseInt( parameters[4], conv_unit ), + parseInt( parameters[5], conv_unit ) ) ); shape->SetStroke( STROKE_PARAMS( parseInt( parameters[6], conv_unit ), PLOT_DASH_TYPE::SOLID ) ); - shape->SetDrawCoord(); + + shape->Rotate( { 0, 0 }, footprint->GetOrientation() ); + shape->Move( footprint->GetPosition() ); + footprint->Add( shape ); continue; } @@ -487,18 +487,18 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader ) } // Pcbnew does know ellipse so we must have Width = Height - FP_SHAPE* shape = new FP_SHAPE( footprint.get(), SHAPE_T::ARC ); + PCB_SHAPE* shape = new PCB_SHAPE( footprint.get(), SHAPE_T::ARC ); shape->SetLayer( F_SilkS ); footprint->Add( shape ); // for and arc: ibuf[3] = ibuf[4]. Pcbnew does not know ellipses - int radius = ( parseInt( parameters[4], conv_unit ) + - parseInt( parameters[5], conv_unit ) ) / 2; + int radius = ( parseInt( parameters[4], conv_unit ) + + parseInt( parameters[5], conv_unit ) ) / 2; VECTOR2I centre( parseInt( parameters[2], conv_unit ), parseInt( parameters[3], conv_unit ) ); - shape->SetCenter0( centre ); + shape->SetCenter( centre ); // Pcbnew start angles are inverted and 180 degrees from Geda PCB angles. EDA_ANGLE start_angle( (int) parseInt( parameters[6], -10.0 ), TENTHS_OF_A_DEGREE_T ); @@ -514,14 +514,16 @@ FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader ) // Calculate start point coordinate of arc VECTOR2I arcStart( radius, 0 ); RotatePoint( arcStart, -start_angle ); - shape->SetStart0( arcStart + centre ); + shape->SetStart( arcStart + centre ); // Angle value is clockwise in gpcb and Pcbnew. - shape->SetArcAngleAndEnd0( sweep_angle ); + shape->SetArcAngleAndEnd( sweep_angle ); shape->SetStroke( STROKE_PARAMS( parseInt( parameters[8], conv_unit ), PLOT_DASH_TYPE::SOLID ) ); - shape->SetDrawCoord(); + + shape->Rotate( { 0, 0 }, footprint->GetOrientation() ); + shape->Move( footprint->GetPosition() ); continue; } diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index 41b9cd48cc..9a423db0b0 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -36,8 +36,6 @@ #include #include -#include -#include #include #include #include @@ -825,7 +823,7 @@ BOARD* PCB_PARSER::parseBOARD_unchecked() case T_gr_poly: case T_gr_circle: case T_gr_rect: - item = parsePCB_SHAPE(); + item = parsePCB_SHAPE( m_board ); m_board->Add( item, ADD_MODE::BULK_APPEND, true ); bulkAddedItems.push_back( item ); break; @@ -837,19 +835,19 @@ BOARD* PCB_PARSER::parseBOARD_unchecked() break; case T_gr_text: - item = parsePCB_TEXT(); + item = parsePCB_TEXT( m_board ); m_board->Add( item, ADD_MODE::BULK_APPEND, true ); bulkAddedItems.push_back( item ); break; case T_gr_text_box: - item = parsePCB_TEXTBOX(); + item = parsePCB_TEXTBOX( m_board ); m_board->Add( item, ADD_MODE::BULK_APPEND, true ); bulkAddedItems.push_back( item ); break; case T_dimension: - item = parseDIMENSION( m_board, false ); + item = parseDIMENSION( m_board ); m_board->Add( item, ADD_MODE::BULK_APPEND, true ); bulkAddedItems.push_back( item ); break; @@ -1056,47 +1054,30 @@ void PCB_PARSER::resolveGroups( BOARD_ITEM* aParent ) wxString error; - for( size_t idx = 0; idx < m_groupInfos.size(); idx++ ) + for( PCB_PARSER::GROUP_INFO& groupInfo : m_groupInfos ) { - GROUP_INFO& aGrp = m_groupInfos[idx]; - BOARD_ITEM* bItem = getItem( aGrp.uuid ); - - if( bItem == nullptr || bItem->Type() != PCB_GROUP_T ) - continue; - - PCB_GROUP* group = static_cast( bItem ); - - for( const KIID& aUuid : aGrp.memberUuids ) + if( PCB_GROUP* group = dynamic_cast( getItem( groupInfo.uuid ) ) ) { - BOARD_ITEM* item; - - if( m_appendToExisting ) - item = getItem( m_resetKIIDMap[ aUuid.AsString() ] ); - else - item = getItem( aUuid ); - - if( item && item->Type() != NOT_USED ) + for( const KIID& aUuid : groupInfo.memberUuids ) { - switch( item->Type() ) + BOARD_ITEM* item; + + if( m_appendToExisting ) + item = getItem( m_resetKIIDMap[ aUuid.AsString() ] ); + else + item = getItem( aUuid ); + + if( item->Type() == NOT_USED ) { - // We used to allow fp items in non-footprint groups. It was a mistake. - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - case PCB_FP_ZONE_T: - case PCB_PAD_T: - if( item->GetParent() == group->GetParent() ) - group->AddItem( item ); - - break; - - // This is the deleted item singleton, which means we didn't find the uuid. - case NOT_USED: - break; - - default: - group->AddItem( item ); + // This is the deleted item singleton, which means we didn't find the uuid. + continue; } + + // We used to allow fp items in non-footprint groups. It was a mistake. Check + // to make sure they the item and group are owned by the same parent (will both + // be nullptr in the board case). + if( item->GetParentFootprint() == group->GetParentFootprint() ) + group->AddItem( item ); } } } @@ -2483,9 +2464,11 @@ void PCB_PARSER::parseNETCLASS() } -PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() +PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE( BOARD_ITEM* aParent ) { - wxCHECK_MSG( CurTok() == T_gr_arc || CurTok() == T_gr_circle || CurTok() == T_gr_curve || + wxCHECK_MSG( CurTok() == T_fp_arc || CurTok() == T_fp_circle || CurTok() == T_fp_curve || + CurTok() == T_fp_rect || CurTok() == T_fp_line || CurTok() == T_fp_poly || + CurTok() == T_gr_arc || CurTok() == T_gr_circle || CurTok() == T_gr_curve || CurTok() == T_gr_rect || CurTok() == T_gr_bbox || CurTok() == T_gr_line || CurTok() == T_gr_poly, nullptr, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_SHAPE." ) ); @@ -2493,11 +2476,12 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() T token; VECTOR2I pt; STROKE_PARAMS stroke( 0, PLOT_DASH_TYPE::SOLID ); - std::unique_ptr shape = std::make_unique( nullptr ); + std::unique_ptr shape = std::make_unique( aParent ); switch( CurTok() ) { case T_gr_arc: + case T_fp_arc: shape->SetShape( SHAPE_T::ARC ); token = NextTok(); @@ -2533,6 +2517,14 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() pt.y = parseBoardUnits( "Y coordinate" ); shape->SetStart( pt ); NeedRIGHT(); + NeedLEFT(); + token = NextTok(); + + if( token != T_angle ) + Expecting( T_angle ); + + shape->SetArcAngleAndEnd( EDA_ANGLE( parseDouble( "arc angle" ), DEGREES_T ), true ); + NeedRIGHT(); } else { @@ -2569,6 +2561,7 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() break; case T_gr_circle: + case T_fp_circle: shape->SetShape( SHAPE_T::CIRCLE ); token = NextTok(); @@ -2604,6 +2597,7 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() break; case T_gr_curve: + case T_fp_curve: shape->SetShape( SHAPE_T::BEZIER ); token = NextTok(); @@ -2630,6 +2624,7 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() case T_gr_bbox: case T_gr_rect: + case T_fp_rect: shape->SetShape( SHAPE_T::RECT ); token = NextTok(); @@ -2660,11 +2655,23 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() pt.x = parseBoardUnits( "X coordinate" ); pt.y = parseBoardUnits( "Y coordinate" ); shape->SetEnd( pt ); - shape->NormalizeRect(); + + if( aParent && aParent->Type() == PCB_FOOTPRINT_T ) + { + // I'm not aware of any reason to skip normalization of footprint rects, except + // that that's what we've always done. (And, FWIW, the Alitum test gold files + // currently depend on this behaviour.) + } + else + { + shape->NormalizeRect(); + } + NeedRIGHT(); break; case T_gr_line: + case T_fp_line: // Default PCB_SHAPE type is S_SEGMENT. token = NextTok(); @@ -2699,6 +2706,7 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() break; case T_gr_poly: + case T_fp_poly: { shape->SetShape( SHAPE_T::POLY ); shape->SetPolyPoints( {} ); @@ -2722,9 +2730,7 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() Expecting( T_pts ); while( (token = NextTok() ) != T_RIGHT ) - { parseOutlinePoints( outline ); - } break; } @@ -2744,21 +2750,9 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() switch( token ) { - case T_angle: - if( m_requiredVersion <= LEGACY_ARC_FORMATTING ) - { - EDA_ANGLE angle( parseDouble( "arc angle" ), DEGREES_T ); - - if( shape->GetShape() == SHAPE_T::ARC ) - shape->SetArcAngleAndEnd( angle, true ); - - NeedRIGHT(); - } - else - { - Unexpected( T_angle ); - } - + case T_angle: // legacy token; ignore value + parseDouble( "arc angle" ); + NeedRIGHT(); break; case T_layer: @@ -2857,6 +2851,12 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE() shape->SetStroke( stroke ); + if( FOOTPRINT* parentFP = dynamic_cast( aParent ) ) + { + shape->Rotate( { 0, 0 }, parentFP->GetOrientation() ); + shape->Move( parentFP->GetPosition() ); + } + return shape.release(); } @@ -2939,15 +2939,44 @@ PCB_BITMAP* PCB_PARSER::parsePCB_BITMAP( BOARD_ITEM* aParent ) } -PCB_TEXT* PCB_PARSER::parsePCB_TEXT() +PCB_TEXT* PCB_PARSER::parsePCB_TEXT( BOARD_ITEM* aParent ) { - wxCHECK_MSG( CurTok() == T_gr_text, nullptr, + wxCHECK_MSG( CurTok() == T_gr_text || CurTok() == T_fp_text, nullptr, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TEXT." ) ); - std::unique_ptr text = std::make_unique( m_board ); + FOOTPRINT* parentFP = dynamic_cast( aParent ); + std::unique_ptr text; T token = NextTok(); + if( parentFP ) + { + switch( token ) + { + case T_reference: + text = std::make_unique( parentFP, PCB_TEXT::TEXT_is_REFERENCE ); + break; + + case T_value: + text = std::make_unique( parentFP, PCB_TEXT::TEXT_is_VALUE ); + break; + + case T_user: + text = std::make_unique( parentFP, PCB_TEXT::TEXT_is_DIVERS ); + break; + + default: + THROW_IO_ERROR( wxString::Format( _( "Cannot handle footprint text type %s" ), + FromUTF8() ) ); + } + + token = NextTok(); + } + else + { + text = std::make_unique( aParent ); + } + if( token == T_locked ) { text->SetLocked( true ); @@ -2957,7 +2986,10 @@ PCB_TEXT* PCB_PARSER::parsePCB_TEXT() if( !IsSymbol( token ) && (int) token != DSN_NUMBER ) Expecting( "text value" ); - text->SetText( FromUTF8() ); + wxString value = FromUTF8(); + value.Replace( wxT( "%V" ), wxT( "${VALUE}" ) ); + value.Replace( wxT( "%R" ), wxT( "${REFERENCE}" ) ); + text->SetText( value ); NeedLEFT(); token = NextTok(); @@ -2974,22 +3006,27 @@ PCB_TEXT* PCB_PARSER::parsePCB_TEXT() // If there is no orientation defined, then it is the default value of 0 degrees. token = NextTok(); - if( token == T_NUMBER ) + if( CurTok() == T_NUMBER ) { text->SetTextAngle( EDA_ANGLE( parseDouble(), DEGREES_T ) ); - NeedRIGHT(); + NextTok(); } - else if( token != T_RIGHT ) + + if( parentFP && CurTok() == T_unlocked ) + { + text->SetKeepUpright( false ); + NextTok(); + } + + if( CurTok() != T_RIGHT ) { Unexpected( CurText() ); } for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); + if( token == T_LEFT ) + token = NextTok(); switch( token ) { @@ -3015,6 +3052,14 @@ PCB_TEXT* PCB_PARSER::parsePCB_TEXT() NeedRIGHT(); break; + case T_hide: + if( parentFP ) + text->SetVisible( false ); + else + Expecting( "layer, effects, locked, render_cache or tstamp" ); + + break; + case T_effects: parseEDA_TEXT( static_cast( text.get() ) ); break; @@ -3024,20 +3069,29 @@ PCB_TEXT* PCB_PARSER::parsePCB_TEXT() break; default: - Expecting( "layer, effects, locked, render_cache or tstamp" ); + if( parentFP ) + Expecting( "layer, hide, effects, locked, render_cache or tstamp" ); + else + Expecting( "layer, effects, locked, render_cache or tstamp" ); } } + if( parentFP ) + { + text->Rotate( { 0, 0 }, parentFP->GetOrientation() ); + text->Move( parentFP->GetPosition() ); + } + return text.release(); } -PCB_TEXTBOX* PCB_PARSER::parsePCB_TEXTBOX() +PCB_TEXTBOX* PCB_PARSER::parsePCB_TEXTBOX( BOARD_ITEM* aParent ) { - wxCHECK_MSG( CurTok() == T_gr_text_box, nullptr, + wxCHECK_MSG( CurTok() == T_gr_text_box || CurTok() == T_fp_text_box, nullptr, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TEXTBOX." ) ); - std::unique_ptr textbox = std::make_unique( m_board ); + std::unique_ptr textbox = std::make_unique( aParent ); STROKE_PARAMS stroke( -1, PLOT_DASH_TYPE::SOLID ); T token = NextTok(); @@ -3138,11 +3192,17 @@ PCB_TEXTBOX* PCB_PARSER::parsePCB_TEXTBOX() textbox->SetStroke( stroke ); + if( FOOTPRINT* parentFP = dynamic_cast( aParent ) ) + { + textbox->Rotate( { 0, 0 }, parentFP->GetOrientation() ); + textbox->Move( parentFP->GetPosition() ); + } + return textbox.release(); } -PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP ) +PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent ) { wxCHECK_MSG( CurTok() == T_dimension, nullptr, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DIMENSION." ) ); @@ -3171,9 +3231,8 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP if( token == T_width ) { isLegacyDimension = true; - dim = std::make_unique( aParent, aInFP ? PCB_FP_DIM_ALIGNED_T - : PCB_DIM_ALIGNED_T ); - dim->SetLineThickness( parseBoardUnits( "dim width value" ) ); + dim = std::make_unique( aParent ); + dim->SetLineThickness( parseBoardUnits( "dimension width value" ) ); NeedRIGHT(); } else @@ -3183,29 +3242,13 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP switch( NextTok() ) { - case T_aligned: - dim = std::make_unique( aParent, aInFP ? PCB_FP_DIM_ALIGNED_T - : PCB_DIM_ALIGNED_T ); - break; - - case T_orthogonal: - dim = std::make_unique( aParent, aInFP ); - break; - - case T_leader: - dim = std::make_unique( aParent, aInFP ); - break; - - case T_center: - dim = std::make_unique( aParent, aInFP ); - break; - - case T_radial: - dim = std::make_unique( aParent, aInFP ); - break; - - default: - wxFAIL_MSG( wxT( "Cannot parse unknown dim type %s" ) + GetTokenString( CurTok() ) ); + case T_aligned: dim = std::make_unique( aParent ); break; + case T_orthogonal: dim = std::make_unique( aParent ); break; + case T_leader: dim = std::make_unique( aParent ); break; + case T_center: dim = std::make_unique( aParent ); break; + case T_radial: dim = std::make_unique( aParent ); break; + default: wxFAIL_MSG( wxT( "Cannot parse unknown dimension type " ) + + GetTokenString( CurTok() ) ); } NeedRIGHT(); @@ -3233,7 +3276,7 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP case T_gr_text: { - PCB_TEXT* text = parsePCB_TEXT(); + PCB_TEXT* text = parsePCB_TEXT( m_board ); dim->EDA_TEXT::operator=( *text ); @@ -3270,11 +3313,10 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP case T_height: { - int height = parseBoardUnits( "dim height value" ); + int height = parseBoardUnits( "dimension height value" ); NeedRIGHT(); - if( dim->Type() == PCB_DIM_ORTHOGONAL_T || dim->Type() == PCB_FP_DIM_ORTHOGONAL_T - || dim->Type() == PCB_DIM_ALIGNED_T || dim->Type() == PCB_FP_DIM_ALIGNED_T ) + if( dim->Type() == PCB_DIM_ORTHOGONAL_T || dim->Type() == PCB_DIM_ALIGNED_T ) { PCB_DIM_ALIGNED* aligned = static_cast( dim.get() ); aligned->SetHeight( height ); @@ -3285,10 +3327,10 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP case T_leader_length: { - int length = parseBoardUnits( "dim leader length value" ); + int length = parseBoardUnits( "leader length value" ); NeedRIGHT(); - if( dim->Type() == PCB_DIM_RADIAL_T || dim->Type() == PCB_FP_DIM_RADIAL_T ) + if( dim->Type() == PCB_DIM_RADIAL_T ) { PCB_DIM_RADIAL* radial = static_cast( dim.get() ); radial->SetLeaderLength( length ); @@ -3299,10 +3341,10 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP case T_orientation: { - int orientation = parseInt( "orthogonal dim orientation" ); + int orientation = parseInt( "orthogonal dimension orientation" ); NeedRIGHT(); - if( dim->Type() == PCB_DIM_ORTHOGONAL_T || dim->Type() == PCB_FP_DIM_ORTHOGONAL_T ) + if( dim->Type() == PCB_DIM_ORTHOGONAL_T ) { PCB_DIM_ORTHOGONAL* ortho = static_cast( dim.get() ); orientation = std::max( 0, std::min( 1, orientation ) ); @@ -3335,7 +3377,7 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP case T_units: { - int mode = parseInt( "dim units mode" ); + int mode = parseInt( "dimension units mode" ); mode = std::max( 0, std::min( 4, mode ) ); dim->SetUnitsMode( static_cast( mode ) ); NeedRIGHT(); @@ -3344,7 +3386,7 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP case T_units_format: { - int format = parseInt( "dim units format" ); + int format = parseInt( "dimension units format" ); format = std::max( 0, std::min( 3, format ) ); dim->SetUnitsFormat( static_cast( format ) ); NeedRIGHT(); @@ -3352,7 +3394,7 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP } case T_precision: - dim->SetPrecision( static_cast( parseInt( "dim precision" ) ) ); + dim->SetPrecision( static_cast( parseInt( "dimension precision" ) ) ); NeedRIGHT(); break; @@ -3388,18 +3430,18 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP continue; case T_thickness: - dim->SetLineThickness( parseBoardUnits( "extension line thickness" ) ); + dim->SetLineThickness( parseBoardUnits( "extension line thickness value" ) ); NeedRIGHT(); break; case T_arrow_length: - dim->SetArrowLength( parseBoardUnits( "arrow length" ) ); + dim->SetArrowLength( parseBoardUnits( "arrow length value" ) ); NeedRIGHT(); break; case T_text_position_mode: { - int mode = parseInt( "dim text position mode" ); + int mode = parseInt( "text position mode" ); mode = std::max( 0, std::min( 3, mode ) ); dim->SetTextPositionMode( static_cast( mode ) ); NeedRIGHT(); @@ -3410,13 +3452,13 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP { PCB_DIM_ALIGNED* aligned = dynamic_cast( dim.get() ); wxCHECK_MSG( aligned, nullptr, wxT( "Invalid extension_height token" ) ); - aligned->SetExtensionHeight( parseBoardUnits( "extension height" ) ); + aligned->SetExtensionHeight( parseBoardUnits( "extension height value" ) ); NeedRIGHT(); break; } case T_extension_offset: - dim->SetExtensionOffset( parseBoardUnits( "extension offset" ) ); + dim->SetExtensionOffset( parseBoardUnits( "extension offset value" ) ); NeedRIGHT(); break; @@ -3426,13 +3468,12 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP case T_text_frame: { - KICAD_T expected_type = aInFP ? PCB_FP_DIM_LEADER_T : PCB_DIM_LEADER_T; - wxCHECK_MSG( dim->Type() == expected_type, nullptr, + wxCHECK_MSG( dim->Type() == PCB_DIM_LEADER_T, nullptr, wxT( "Invalid text_frame token" ) ); PCB_DIM_LEADER* leader = static_cast( dim.get() ); - int textFrame = parseInt( "dim text frame mode" ); + int textFrame = parseInt( "text frame mode" ); textFrame = std::max( 0, std::min( 3, textFrame ) ); leader->SetTextBorder( static_cast( textFrame )); NeedRIGHT(); @@ -3844,22 +3885,18 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments case T_fp_text: { - FP_TEXT* text = parseFP_TEXT(); - text->SetParent( footprint.get() ); - EDA_ANGLE orientation = text->GetTextAngle(); - orientation -= footprint->GetOrientation(); - text->SetTextAngle( orientation ); - text->SetDrawCoord(); + PCB_TEXT* text = parsePCB_TEXT( footprint.get() ); + text->SetTextAngle( text->GetTextAngle() - footprint->GetOrientation()); switch( text->GetType() ) { - case FP_TEXT::TEXT_is_REFERENCE: + case PCB_TEXT::TEXT_is_REFERENCE: footprint->Reference() = *text; const_cast( footprint->Reference().m_Uuid ) = text->m_Uuid; delete text; break; - case FP_TEXT::TEXT_is_VALUE: + case PCB_TEXT::TEXT_is_VALUE: footprint->Value() = *text; const_cast( footprint->Value().m_Uuid ) = text->m_Uuid; delete text; @@ -3874,9 +3911,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments case T_fp_text_box: { - FP_TEXTBOX* textbox = parseFP_TEXTBOX(); - textbox->SetParent( footprint.get() ); - textbox->SetDrawCoord(); + PCB_TEXTBOX* textbox = parsePCB_TEXTBOX( footprint.get() ); footprint->Add( textbox, ADD_MODE::APPEND, true ); break; } @@ -3888,9 +3923,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments case T_fp_line: case T_fp_poly: { - FP_SHAPE* shape = parseFP_SHAPE(); - shape->SetParent( footprint.get() ); - shape->SetDrawCoord(); + PCB_SHAPE* shape = parsePCB_SHAPE( footprint.get() ); footprint->Add( shape, ADD_MODE::APPEND, true ); break; } @@ -3904,7 +3937,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments case T_dimension: { - PCB_DIMENSION_BASE* dimension = parseDIMENSION( footprint.get(), true ); + PCB_DIMENSION_BASE* dimension = parseDIMENSION( footprint.get() ); footprint->Add( dimension, ADD_MODE::APPEND, true ); break; } @@ -3987,604 +4020,6 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments } -FP_TEXT* PCB_PARSER::parseFP_TEXT() -{ - wxCHECK_MSG( CurTok() == T_fp_text, nullptr, - wxString::Format( wxT( "Cannot parse %s as FP_TEXT at line %d, offset %d." ), - GetTokenString( CurTok() ), CurLineNumber(), CurOffset() ) ); - - T token = NextTok(); - - std::unique_ptr text = std::make_unique( nullptr ); - - switch( token ) - { - case T_reference: - text->SetType( FP_TEXT::TEXT_is_REFERENCE ); - break; - - case T_value: - text->SetType( FP_TEXT::TEXT_is_VALUE ); - break; - - case T_user: - break; // Default type is user text. - - default: - THROW_IO_ERROR( wxString::Format( _( "Cannot handle footprint text type %s" ), - FromUTF8() ) ); - } - - token = NextTok(); - - if( token == T_locked ) - { - text->SetLocked( true ); - token = NextTok(); - } - - if( !IsSymbol( token ) && (int) token != DSN_NUMBER ) - Expecting( "text value" ); - - wxString value = FromUTF8(); - value.Replace( wxT( "%V" ), wxT( "${VALUE}" ) ); - value.Replace( wxT( "%R" ), wxT( "${REFERENCE}" ) ); - text->SetText( value ); - NeedLEFT(); - token = NextTok(); - - if( token != T_at ) - Expecting( T_at ); - - VECTOR2I pt; - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - text->SetPos0( pt ); - - NextTok(); - - if( CurTok() == T_NUMBER ) - { - text->SetTextAngle( EDA_ANGLE( parseDouble(), DEGREES_T ) ); - NextTok(); - } - - if( CurTok() == T_unlocked ) - { - text->SetKeepUpright( false ); - NextTok(); - } - - if( CurTok() != T_RIGHT ) - { - Unexpected( CurText() ); - } - - for( token = NextTok(); token != T_RIGHT; token = NextTok() ) - { - if( token == T_LEFT ) - token = NextTok(); - - switch( token ) - { - case T_layer: - text->SetLayer( parseBoardItemLayer() ); - - token = NextTok(); - - if( token == T_knockout ) - { - text->SetIsKnockout( true ); - token = NextTok(); - } - - if( (int) token != DSN_RIGHT ) - Expecting( DSN_RIGHT ); - - break; - - case T_hide: - text->SetVisible( false ); - break; - - case T_effects: - parseEDA_TEXT( static_cast( text.get() ) ); - break; - - case T_render_cache: - parseRenderCache( static_cast( text.get() ) ); - break; - - case T_tstamp: - NextTok(); - const_cast( text->m_Uuid ) = CurStrToKIID(); - NeedRIGHT(); - break; - - default: - Expecting( "layer, hide, effects, render_cache or tstamp" ); - } - } - - return text.release(); -} - - -FP_TEXTBOX* PCB_PARSER::parseFP_TEXTBOX() -{ - wxCHECK_MSG( CurTok() == T_fp_text_box, nullptr, - wxString::Format( wxT( "Cannot parse %s as FP_TEXTBOX at line %d, offset %d." ), - GetTokenString( CurTok() ), CurLineNumber(), CurOffset() ) ); - - std::unique_ptr textbox = std::make_unique( nullptr ); - - STROKE_PARAMS stroke( -1, PLOT_DASH_TYPE::SOLID ); - T token = NextTok(); - - if( token == T_locked ) - { - textbox->SetLocked( true ); - token = NextTok(); - } - - if( !IsSymbol( token ) && (int) token != DSN_NUMBER ) - Expecting( "text value" ); - - textbox->SetText( FromUTF8() ); - - NeedLEFT(); - token = NextTok(); - - if( token == T_start ) - { - int x = parseBoardUnits( "X coordinate" ); - int y = parseBoardUnits( "Y coordinate" ); - textbox->SetStart0( VECTOR2I( x, y ) ); - NeedRIGHT(); - - NeedLEFT(); - token = NextTok(); - - if( token != T_end ) - Expecting( T_end ); - - x = parseBoardUnits( "X coordinate" ); - y = parseBoardUnits( "Y coordinate" ); - textbox->SetEnd0( VECTOR2I( x, y ) ); - NeedRIGHT(); - } - else if( token == T_pts ) - { - textbox->SetShape( SHAPE_T::POLY ); - textbox->GetPolyShape().RemoveAllContours(); - textbox->GetPolyShape().NewOutline(); - - while( (token = NextTok() ) != T_RIGHT ) - parseOutlinePoints( textbox->GetPolyShape().Outline( 0 ) ); - } - else - { - Expecting( "start or pts" ); - } - - for( token = NextTok(); token != T_RIGHT; token = NextTok() ) - { - if( token == T_LEFT ) - token = NextTok(); - - switch( token ) - { - case T_angle: - textbox->SetTextAngle( EDA_ANGLE( parseDouble( "text box angle" ), DEGREES_T ) ); - NeedRIGHT(); - break; - - case T_stroke: - { - STROKE_PARAMS_PARSER strokeParser( reader, pcbIUScale.IU_PER_MM ); - strokeParser.SyncLineReaderWith( *this ); - - strokeParser.ParseStroke( stroke ); - SyncLineReaderWith( strokeParser ); - break; - } - - case T_layer: - textbox->SetLayer( parseBoardItemLayer() ); - NeedRIGHT(); - break; - - case T_effects: - parseEDA_TEXT( static_cast( textbox.get() ) ); - break; - - case T_render_cache: - parseRenderCache( static_cast( textbox.get() ) ); - break; - - case T_tstamp: - NextTok(); - const_cast( textbox->m_Uuid ) = CurStrToKIID(); - NeedRIGHT(); - break; - - default: - Expecting( "angle, width, layer, effects, render_cache or tstamp" ); - } - } - - textbox->SetStroke( stroke ); - - return textbox.release(); -} - - -FP_SHAPE* PCB_PARSER::parseFP_SHAPE() -{ - wxCHECK_MSG( CurTok() == T_fp_arc || CurTok() == T_fp_circle || CurTok() == T_fp_curve || - CurTok() == T_fp_rect || CurTok() == T_fp_line || CurTok() == T_fp_poly, nullptr, - wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as FP_SHAPE." ) ); - - VECTOR2I pt; - STROKE_PARAMS stroke( 0, PLOT_DASH_TYPE::SOLID ); - T token; - - std::unique_ptr shape = std::make_unique( nullptr ); - - switch( CurTok() ) - { - case T_fp_arc: - shape->SetShape( SHAPE_T::ARC ); - token = NextTok(); - - if( token == T_locked ) - { - shape->SetLocked( true ); - token = NextTok(); - } - - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); - - if( m_requiredVersion <= LEGACY_ARC_FORMATTING ) - { - // In legacy files the start keyword actually gives the arc center... - if( token != T_start ) - Expecting( T_start ); - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - shape->SetCenter0( pt ); - NeedRIGHT(); - NeedLEFT(); - token = NextTok(); - - // ... and the end keyword gives the start point of the arc - if( token != T_end ) - Expecting( T_end ); - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - shape->SetStart0( pt ); - NeedRIGHT(); - NeedLEFT(); - token = NextTok(); - - if( token != T_angle ) - Expecting( T_angle ); - - shape->SetArcAngleAndEnd0( EDA_ANGLE( parseDouble( "arc angle" ), DEGREES_T ), true ); - NeedRIGHT(); - } - else - { - VECTOR2I arc_start, arc_mid, arc_end; - - if( token != T_start ) - Expecting( T_start ); - - arc_start.x = parseBoardUnits( "X coordinate" ); - arc_start.y = parseBoardUnits( "Y coordinate" ); - NeedRIGHT(); - NeedLEFT(); - token = NextTok(); - - if( token != T_mid ) - Expecting( T_mid ); - - arc_mid.x = parseBoardUnits( "X coordinate" ); - arc_mid.y = parseBoardUnits( "Y coordinate" ); - NeedRIGHT(); - NeedLEFT(); - token = NextTok(); - - if( token != T_end ) - Expecting( T_end ); - - arc_end.x = parseBoardUnits( "X coordinate" ); - arc_end.y = parseBoardUnits( "Y coordinate" ); - NeedRIGHT(); - - shape->SetArcGeometry0( arc_start, arc_mid, arc_end ); - } - - break; - - case T_fp_circle: - shape->SetShape( SHAPE_T::CIRCLE ); - token = NextTok(); - - if( token == T_locked ) - { - shape->SetLocked( true ); - token = NextTok(); - } - - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); - - if( token != T_center ) - Expecting( T_center ); - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - shape->SetStart0( pt ); - NeedRIGHT(); - NeedLEFT(); - token = NextTok(); - - if( token != T_end ) - Expecting( T_end ); - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - shape->SetEnd0( pt ); - NeedRIGHT(); - break; - - case T_fp_curve: - shape->SetShape( SHAPE_T::BEZIER ); - token = NextTok(); - - if( token == T_locked ) - { - shape->SetLocked( true ); - token = NextTok(); - } - - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); - - if( token != T_pts ) - Expecting( T_pts ); - - shape->SetStart0( parseXY() ); - shape->SetBezierC1_0( parseXY() ); - shape->SetBezierC2_0( parseXY() ); - shape->SetEnd0( parseXY() ); - NeedRIGHT(); - break; - - case T_fp_rect: - shape->SetShape( SHAPE_T::RECT ); - token = NextTok(); - - if( token == T_locked ) - { - shape->SetLocked( true ); - token = NextTok(); - } - - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); - - if( token != T_start ) - Expecting( T_start ); - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - shape->SetStart0( pt ); - - NeedRIGHT(); - NeedLEFT(); - token = NextTok(); - - if( token != T_end ) - Expecting( T_end ); - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - shape->SetEnd0( pt ); - NeedRIGHT(); - break; - - case T_fp_line: - // Default PCB_SHAPE type is S_SEGMENT. - token = NextTok(); - - if( token == T_locked ) - { - shape->SetLocked( true ); - token = NextTok(); - } - - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); - - if( token != T_start ) - Expecting( T_start ); - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - shape->SetStart0( pt ); - - NeedRIGHT(); - NeedLEFT(); - token = NextTok(); - - if( token != T_end ) - Expecting( T_end ); - - pt.x = parseBoardUnits( "X coordinate" ); - pt.y = parseBoardUnits( "Y coordinate" ); - shape->SetEnd0( pt ); - NeedRIGHT(); - break; - - case T_fp_poly: - { - shape->SetShape( SHAPE_T::POLY ); - shape->SetPolyPoints( {} ); - SHAPE_LINE_CHAIN& outline = shape->GetPolyShape().Outline( 0 ); - - token = NextTok(); - - if( token == T_locked ) - { - shape->SetLocked( true ); - token = NextTok(); - } - - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); - - if( token != T_pts ) - Expecting( T_pts ); - - while( (token = NextTok() ) != T_RIGHT ) - parseOutlinePoints( outline ); - - break; - } - - default: - Expecting( "fp_arc, fp_circle, fp_curve, fp_line, fp_poly, or fp_rect" ); - } - - bool foundFill = false; - - for( token = NextTok(); token != T_RIGHT; token = NextTok() ) - { - if( token != T_LEFT ) - Expecting( T_LEFT ); - - token = NextTok(); - - switch( token ) - { - case T_layer: - shape->SetLayer( parseBoardItemLayer() ); - NeedRIGHT(); - break; - - case T_width: // legacy token - stroke.SetWidth( parseBoardUnits( T_width ) ); - NeedRIGHT(); - break; - - case T_stroke: - { - STROKE_PARAMS_PARSER strokeParser( reader, pcbIUScale.IU_PER_MM ); - strokeParser.SyncLineReaderWith( *this ); - - strokeParser.ParseStroke( stroke ); - SyncLineReaderWith( strokeParser ); - break; - } - - case T_tstamp: - NextTok(); - const_cast( shape->m_Uuid ) = CurStrToKIID(); - NeedRIGHT(); - break; - - case T_fill: - foundFill = true; - - for( token = NextTok(); token != T_RIGHT; token = NextTok() ) - { - if( token == T_LEFT ) - token = NextTok(); - - switch( token ) - { - // T_yes was used to indicate filling when first introduced, - // so treat it like a solid fill since that was the only fill available - case T_yes: - case T_solid: - shape->SetFilled( true ); - break; - - case T_none: - shape->SetFilled( false ); - break; - - default: - Expecting( "yes, none, solid" ); - } - } - - break; - - // We continue to parse the status field but it is no longer written - case T_status: - parseHex(); - NeedRIGHT(); - break; - - // Continue to process "(locked)" format which was output during 5.99 development - case T_locked: - shape->SetLocked( true ); - NeedRIGHT(); - break; - - default: - Expecting( "layer, width, fill, tstamp, locked, or status" ); - } - } - - if( !foundFill ) - { - // Legacy versions didn't have a filled flag but allowed some shapes to indicate they - // should be filled by specifying a 0 stroke-width. - if( stroke.GetWidth() == 0 - && ( shape->GetShape() == SHAPE_T::RECT || shape->GetShape() == SHAPE_T::CIRCLE ) ) - { - shape->SetFilled( true ); - } - // Polygons on non-Edge_Cuts layers were always filled - else if( shape->GetShape() == SHAPE_T::POLY && shape->GetLayer() != Edge_Cuts ) - { - shape->SetFilled( true ); - } - } - - // Only filled shapes may have a zero line-width. This is not permitted in KiCad but some - // external tools can generate invalid files. - if( stroke.GetWidth() <= 0 && !shape->IsFilled() ) - { - stroke.SetWidth( pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ) ); - } - - shape->SetStroke( stroke ); - - return shape.release(); -} - - PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent ) { wxCHECK_MSG( CurTok() == T_pad, nullptr, @@ -4982,42 +4417,42 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent ) switch( token ) { case T_gr_arc: - dummyShape = parsePCB_SHAPE(); + dummyShape = parsePCB_SHAPE( nullptr ); pad->AddPrimitiveArc( dummyShape->GetCenter(), dummyShape->GetStart(), dummyShape->GetArcAngle(), dummyShape->GetWidth() ); break; case T_gr_line: - dummyShape = parsePCB_SHAPE(); + dummyShape = parsePCB_SHAPE( nullptr ); pad->AddPrimitiveSegment( dummyShape->GetStart(), dummyShape->GetEnd(), dummyShape->GetWidth() ); break; case T_gr_circle: - dummyShape = parsePCB_SHAPE(); + dummyShape = parsePCB_SHAPE( nullptr ); pad->AddPrimitiveCircle( dummyShape->GetCenter(), dummyShape->GetRadius(), dummyShape->GetWidth(), dummyShape->IsFilled() ); break; case T_gr_rect: - dummyShape = parsePCB_SHAPE(); + dummyShape = parsePCB_SHAPE( nullptr ); pad->AddPrimitiveRect( dummyShape->GetStart(), dummyShape->GetEnd(), dummyShape->GetWidth(), dummyShape->IsFilled() ); break; case T_gr_bbox: - dummyShape = parsePCB_SHAPE(); + dummyShape = parsePCB_SHAPE( nullptr ); pad->AddPrimitiveAnnotationBox( dummyShape->GetStart(), dummyShape->GetEnd() ); break; case T_gr_poly: - dummyShape = parsePCB_SHAPE(); + dummyShape = parsePCB_SHAPE( nullptr ); pad->AddPrimitivePoly( dummyShape->GetPolyShape(), dummyShape->GetWidth(), dummyShape->IsFilled() ); break; case T_gr_curve: - dummyShape = parsePCB_SHAPE(); + dummyShape = parsePCB_SHAPE( nullptr ); pad->AddPrimitiveCurve( dummyShape->GetStart(), dummyShape->GetEnd(), dummyShape->GetBezierC1(), dummyShape->GetBezierC2(), dummyShape->GetWidth() ); @@ -5537,20 +4972,11 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent ) // bigger scope since each filled_polygon is concatenated in here std::map pts; - bool inFootprint = false; PCB_LAYER_ID filledLayer; bool addedFilledPolygons = false; bool dropFilledPolygons = false; - if( dynamic_cast( aParent ) ) // The zone belongs a footprint - inFootprint = true; - - std::unique_ptr zone; - - if( inFootprint ) - zone = std::make_unique( aParent ); - else - zone = std::make_unique( aParent ); + std::unique_ptr zone = std::make_unique( aParent ); zone->SetAssignedPriority( 0 ); diff --git a/pcbnew/plugins/kicad/pcb_parser.h b/pcbnew/plugins/kicad/pcb_parser.h index 07630cd77e..3c29feb85b 100644 --- a/pcbnew/plugins/kicad/pcb_parser.h +++ b/pcbnew/plugins/kicad/pcb_parser.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 CERN - * Copyright (C) 2012-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -52,7 +52,6 @@ class PCB_SHAPE; class PCB_BITMAP; class EDA_TEXT; class FP_SHAPE; -class FP_TEXT; class PCB_TEXT; class PCB_TRACK; class FOOTPRINT; @@ -175,18 +174,15 @@ private: void parseNETINFO_ITEM(); void parseNETCLASS(); - PCB_SHAPE* parsePCB_SHAPE(); - PCB_TEXT* parsePCB_TEXT(); + PCB_SHAPE* parsePCB_SHAPE( BOARD_ITEM* aParent ); + PCB_TEXT* parsePCB_TEXT( BOARD_ITEM* aParent ); PCB_BITMAP* parsePCB_BITMAP( BOARD_ITEM* aParent ); - PCB_TEXTBOX* parsePCB_TEXTBOX(); - PCB_DIMENSION_BASE* parseDIMENSION( BOARD_ITEM* aParent, bool aInFP ); + PCB_TEXTBOX* parsePCB_TEXTBOX( BOARD_ITEM* aParent ); + PCB_DIMENSION_BASE* parseDIMENSION( BOARD_ITEM* aParent ); // Parse a footprint, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically. FOOTPRINT* parseFOOTPRINT_unchecked( wxArrayString* aInitialComments = nullptr ); - FP_TEXT* parseFP_TEXT(); - FP_TEXTBOX* parseFP_TEXTBOX(); - FP_SHAPE* parseFP_SHAPE(); PAD* parsePAD( FOOTPRINT* aParent = nullptr ); // Parse only the (option ...) inside a pad description diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index 7d2ef32cf2..014e0722b0 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 CERN - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,8 +31,6 @@ #include #include #include -#include -#include #include #include #include @@ -185,14 +183,13 @@ void FP_CACHE::Load() FILE_LINE_READER reader( fn.GetFullPath() ); PCB_PARSER parser( &reader, nullptr, nullptr ); - // use dynamic cast in case somebody renames a .kicad_pcb as .kicad_mod and chucks it into a library folder - // the parsing definitely fails then FOOTPRINT* footprint = dynamic_cast( parser.Parse() ); wxString fpName = fn.GetName(); if( !footprint ) { - THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ), fn.GetFullPath() ) ); + THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ), + fn.GetFullPath() ) ); } footprint->SetFPID( LIB_ID( wxEmptyString, fpName ) ); @@ -344,11 +341,6 @@ void PCB_PLUGIN::Format( const BOARD_ITEM* aItem, int aNestLevel ) const case PCB_DIM_RADIAL_T: case PCB_DIM_ORTHOGONAL_T: case PCB_DIM_LEADER_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_LEADER_T: format( static_cast( aItem ), aNestLevel ); break; @@ -360,10 +352,6 @@ void PCB_PLUGIN::Format( const BOARD_ITEM* aItem, int aNestLevel ) const format( static_cast( aItem ), aNestLevel ); break; - case PCB_FP_SHAPE_T: - format( static_cast( aItem ), aNestLevel ); - break; - case PCB_TARGET_T: format( static_cast( aItem ), aNestLevel ); break; @@ -384,14 +372,6 @@ void PCB_PLUGIN::Format( const BOARD_ITEM* aItem, int aNestLevel ) const format( static_cast( aItem ), aNestLevel ); break; - case PCB_FP_TEXT_T: - format( static_cast( aItem ), aNestLevel ); - break; - - case PCB_FP_TEXTBOX_T: - format( static_cast( aItem ), aNestLevel ); - break; - case PCB_GROUP_T: format( static_cast( aItem ), aNestLevel ); break; @@ -402,7 +382,6 @@ void PCB_PLUGIN::Format( const BOARD_ITEM* aItem, int aNestLevel ) const format( static_cast( aItem ), aNestLevel ); break; - case PCB_FP_ZONE_T: case PCB_ZONE_T: format( static_cast( aItem ), aNestLevel ); break; @@ -413,6 +392,31 @@ void PCB_PLUGIN::Format( const BOARD_ITEM* aItem, int aNestLevel ) const } +std::string formatInternalUnits( int aValue ) +{ + return EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aValue ); +} + + +std::string formatInternalUnits( const VECTOR2I& aCoord ) +{ + return EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aCoord ); +} + + +std::string formatInternalUnits( const VECTOR2I& aCoord, const FOOTPRINT* aParentFP ) +{ + if( aParentFP ) + { + VECTOR2I coord = aCoord - aParentFP->GetPosition(); + RotatePoint( coord, -aParentFP->GetOrientation() ); + return formatInternalUnits( coord ); + } + + return formatInternalUnits( aCoord ); +} + + void PCB_PLUGIN::formatLayer( PCB_LAYER_ID aLayer, bool aIsKnockout ) const { m_out->Print( 0, " (layer %s%s)", @@ -422,7 +426,7 @@ void PCB_PLUGIN::formatLayer( PCB_LAYER_ID aLayer, bool aIsKnockout ) const void PCB_PLUGIN::formatPolyPts( const SHAPE_LINE_CHAIN& outline, int aNestLevel, - bool aCompact ) const + bool aCompact, const FOOTPRINT* aParentFP ) const { m_out->Print( aNestLevel + 1, "(pts\n" ); @@ -437,16 +441,16 @@ void PCB_PLUGIN::formatPolyPts( const SHAPE_LINE_CHAIN& outline, int aNestLevel, if( ind < 0 ) { m_out->Print( nestLevel, "(xy %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, outline.CPoint( ii ) ).c_str() ); + formatInternalUnits( outline.CPoint( ii ), aParentFP ).c_str() ); needNewline = true; } else { const SHAPE_ARC& arc = outline.Arc( ind ); m_out->Print( nestLevel, "(arc (start %s) (mid %s) (end %s))", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, arc.GetP0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, arc.GetArcMid() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, arc.GetP1() ).c_str() ); + formatInternalUnits( arc.GetP0(), aParentFP ).c_str(), + formatInternalUnits( arc.GetArcMid(), aParentFP ).c_str(), + formatInternalUnits( arc.GetP1(), aParentFP ).c_str() ); needNewline = true; do @@ -522,18 +526,18 @@ void PCB_PLUGIN::formatSetup( const BOARD* aBoard, int aNestLevel ) const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings(); m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, dsnSettings.m_SolderMaskExpansion ).c_str() ); + formatInternalUnits( dsnSettings.m_SolderMaskExpansion ).c_str() ); if( dsnSettings.m_SolderMaskMinWidth ) { m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, dsnSettings.m_SolderMaskMinWidth ).c_str() ); + formatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() ); } if( dsnSettings.m_SolderPasteMargin != 0 ) { m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, dsnSettings.m_SolderPasteMargin ).c_str() ); + formatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() ); } if( dsnSettings.m_SolderPasteMarginRatio != 0 ) @@ -552,8 +556,8 @@ void PCB_PLUGIN::formatSetup( const BOARD* aBoard, int aNestLevel ) const if( origin != VECTOR2I( 0, 0 ) ) { m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, origin.x ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, origin.y ).c_str() ); + formatInternalUnits( origin.x ).c_str(), + formatInternalUnits( origin.y ).c_str() ); } origin = dsnSettings.GetGridOrigin(); @@ -561,8 +565,8 @@ void PCB_PLUGIN::formatSetup( const BOARD* aBoard, int aNestLevel ) const if( origin != VECTOR2I( 0, 0 ) ) { m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, origin.x ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, origin.y ).c_str() ); + formatInternalUnits( origin.x ).c_str(), + formatInternalUnits( origin.y ).c_str() ); } aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 ); @@ -578,7 +582,7 @@ void PCB_PLUGIN::formatGeneral( const BOARD* aBoard, int aNestLevel ) const m_out->Print( 0, "\n" ); m_out->Print( aNestLevel, "(general\n" ); m_out->Print( aNestLevel+1, "(thickness %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, dsnSettings.GetBoardThickness() ).c_str() ); + formatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() ); m_out->Print( aNestLevel, ")\n\n" ); @@ -786,21 +790,21 @@ void PCB_PLUGIN::format( const PCB_DIMENSION_BASE* aDimension, int aNestLevel ) m_out->Print( 0, "\n" ); m_out->Print( aNestLevel+1, "(pts (xy %s %s) (xy %s %s))\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetStart().x ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetStart().y ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetEnd().x ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetEnd().y ).c_str() ); + formatInternalUnits( aDimension->GetStart().x ).c_str(), + formatInternalUnits( aDimension->GetStart().y ).c_str(), + formatInternalUnits( aDimension->GetEnd().x ).c_str(), + formatInternalUnits( aDimension->GetEnd().y ).c_str() ); if( aligned ) { m_out->Print( aNestLevel+1, "(height %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aligned->GetHeight() ).c_str() ); + formatInternalUnits( aligned->GetHeight() ).c_str() ); } if( radial ) { m_out->Print( aNestLevel+1, "(leader_length %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, radial->GetLeaderLength() ).c_str() ); + formatInternalUnits( radial->GetLeaderLength() ).c_str() ); } if( ortho ) @@ -833,21 +837,21 @@ void PCB_PLUGIN::format( const PCB_DIMENSION_BASE* aDimension, int aNestLevel ) } m_out->Print( aNestLevel+1, "(style (thickness %s) (arrow_length %s) (text_position_mode %d)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetLineThickness() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetArrowLength() ).c_str(), + formatInternalUnits( aDimension->GetLineThickness() ).c_str(), + formatInternalUnits( aDimension->GetArrowLength() ).c_str(), static_cast( aDimension->GetTextPositionMode() ) ); if( aligned ) { m_out->Print( 0, " (extension_height %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aligned->GetExtensionHeight() ).c_str() ); + formatInternalUnits( aligned->GetExtensionHeight() ).c_str() ); } if( leader ) m_out->Print( 0, " (text_frame %d)", static_cast( leader->GetTextBorder() ) ); m_out->Print( 0, " (extension_offset %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aDimension->GetExtensionOffset() ).c_str() ); + formatInternalUnits( aDimension->GetExtensionOffset() ).c_str() ); if( aDimension->GetKeepTextAligned() ) m_out->Print( 0, " keep_text_aligned" ); @@ -860,37 +864,43 @@ void PCB_PLUGIN::format( const PCB_DIMENSION_BASE* aDimension, int aNestLevel ) void PCB_PLUGIN::format( const PCB_SHAPE* aShape, int aNestLevel ) const { + FOOTPRINT* parentFP = aShape->GetParentFootprint(); + std::string prefix = parentFP ? "fp" : "gr"; std::string locked = aShape->IsLocked() ? " locked" : ""; switch( aShape->GetShape() ) { case SHAPE_T::SEGMENT: - m_out->Print( aNestLevel, "(gr_line%s (start %s) (end %s)", + m_out->Print( aNestLevel, "(%s_line%s (start %s) (end %s)\n", + prefix.c_str(), locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() ); + formatInternalUnits( aShape->GetStart(), parentFP ).c_str(), + formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() ); break; case SHAPE_T::RECT: - m_out->Print( aNestLevel, "(gr_rect%s (start %s) (end %s)", + m_out->Print( aNestLevel, "(%s_rect%s (start %s) (end %s)\n", + prefix.c_str(), locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() ); + formatInternalUnits( aShape->GetStart(), parentFP ).c_str(), + formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() ); break; case SHAPE_T::CIRCLE: - m_out->Print( aNestLevel, "(gr_circle%s (center %s) (end %s)", + m_out->Print( aNestLevel, "(%s_circle%s (center %s) (end %s)\n", + prefix.c_str(), locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() ); + formatInternalUnits( aShape->GetStart(), parentFP ).c_str(), + formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() ); break; case SHAPE_T::ARC: - m_out->Print( aNestLevel, "(gr_arc%s (start %s) (mid %s) (end %s)", + m_out->Print( aNestLevel, "(%s_arc%s (start %s) (mid %s) (end %s)\n", + prefix.c_str(), locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetArcMid() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() ); + formatInternalUnits( aShape->GetStart(), parentFP ).c_str(), + formatInternalUnits( aShape->GetArcMid(), parentFP ).c_str(), + formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() ); break; case SHAPE_T::POLY: @@ -899,8 +909,10 @@ void PCB_PLUGIN::format( const PCB_SHAPE* aShape, int aNestLevel ) const const SHAPE_POLY_SET& poly = aShape->GetPolyShape(); const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 ); - m_out->Print( aNestLevel, "(gr_poly%s\n", locked.c_str() ); - formatPolyPts( outline, aNestLevel, ADVANCED_CFG::GetCfg().m_CompactSave ); + m_out->Print( aNestLevel, "(%s_poly%s\n", + prefix.c_str(), + locked.c_str() ); + formatPolyPts( outline, aNestLevel, ADVANCED_CFG::GetCfg().m_CompactSave, parentFP ); } else { @@ -911,12 +923,13 @@ void PCB_PLUGIN::format( const PCB_SHAPE* aShape, int aNestLevel ) const break; case SHAPE_T::BEZIER: - m_out->Print( aNestLevel, "(gr_curve%s (pts (xy %s) (xy %s) (xy %s) (xy %s))", + m_out->Print( aNestLevel, "(%s_curve%s (pts (xy %s) (xy %s) (xy %s) (xy %s))\n", + prefix.c_str(), locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetBezierC1() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetBezierC2() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aShape->GetEnd() ).c_str() ); + formatInternalUnits( aShape->GetStart(), parentFP ).c_str(), + formatInternalUnits( aShape->GetBezierC1(), parentFP ).c_str(), + formatInternalUnits( aShape->GetBezierC2(), parentFP ).c_str(), + formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() ); break; default: @@ -924,8 +937,6 @@ void PCB_PLUGIN::format( const PCB_SHAPE* aShape, int aNestLevel ) const return; }; - m_out->Print( 0, "\n" ); - aShape->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 ); // The filled flag represents if a solid fill is present on circles, rectangles and polygons @@ -933,10 +944,7 @@ void PCB_PLUGIN::format( const PCB_SHAPE* aShape, int aNestLevel ) const || ( aShape->GetShape() == SHAPE_T::RECT ) || ( aShape->GetShape() == SHAPE_T::CIRCLE ) ) { - if( aShape->IsFilled() ) - m_out->Print( 0, " (fill solid)" ); - else - m_out->Print( 0, " (fill none)" ); + m_out->Print( 0, aShape->IsFilled() ? " (fill solid)" : " (fill none)" ); } formatLayer( aShape->GetLayer() ); @@ -956,8 +964,8 @@ void PCB_PLUGIN::format( const PCB_BITMAP* aBitmap, int aNestLevel ) const wxCHECK_RET( image != nullptr, "wxImage* is NULL" ); m_out->Print( aNestLevel, "(image (at %s %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aBitmap->GetPosition().x ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aBitmap->GetPosition().y ).c_str() ); + formatInternalUnits( aBitmap->GetPosition().x ).c_str(), + formatInternalUnits( aBitmap->GetPosition().y ).c_str() ); formatLayer( aBitmap->GetLayer() ); @@ -995,103 +1003,15 @@ void PCB_PLUGIN::format( const PCB_BITMAP* aBitmap, int aNestLevel ) const } -void PCB_PLUGIN::format( const FP_SHAPE* aFPShape, int aNestLevel ) const -{ - std::string locked = aFPShape->IsLocked() ? " locked" : ""; - - switch( aFPShape->GetShape() ) - { - case SHAPE_T::SEGMENT: - m_out->Print( aNestLevel, "(fp_line%s (start %s) (end %s)", - locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetStart0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetEnd0() ).c_str() ); - break; - - case SHAPE_T::RECT: - m_out->Print( aNestLevel, "(fp_rect%s (start %s) (end %s)", - locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetStart0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetEnd0() ).c_str() ); - break; - - case SHAPE_T::CIRCLE: - m_out->Print( aNestLevel, "(fp_circle%s (center %s) (end %s)", - locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetStart0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetEnd0() ).c_str() ); - break; - - case SHAPE_T::ARC: - m_out->Print( aNestLevel, "(fp_arc%s (start %s) (mid %s) (end %s)", - locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetStart0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetArcMid0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetEnd0() ).c_str() ); - break; - - case SHAPE_T::POLY: - if( aFPShape->IsPolyShapeValid() ) - { - const SHAPE_POLY_SET& poly = aFPShape->GetPolyShape(); - const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 ); - - m_out->Print( aNestLevel, "(fp_poly%s\n", locked.c_str() ); - formatPolyPts( outline, aNestLevel, ADVANCED_CFG::GetCfg().m_CompactSave ); - } - else - { - wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) ); - return; - } - break; - - case SHAPE_T::BEZIER: - m_out->Print( aNestLevel, "(fp_curve%s (pts (xy %s) (xy %s) (xy %s) (xy %s))", - locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetStart0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetBezierC1_0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetBezierC2_0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFPShape->GetEnd0() ).c_str() ); - break; - - default: - wxFAIL_MSG( wxT( "PCB_PLUGIN::format not implemented for " ) + aFPShape->SHAPE_T_asString() ); - return; - }; - - m_out->Print( 0, "\n" ); - - aFPShape->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 ); - - // The filled flag represents if a solid fill is present on circles, rectangles and polygons - if( ( aFPShape->GetShape() == SHAPE_T::POLY ) - || ( aFPShape->GetShape() == SHAPE_T::RECT ) - || ( aFPShape->GetShape() == SHAPE_T::CIRCLE ) ) - { - if( aFPShape->IsFilled() ) - m_out->Print( 0, " (fill solid)" ); - else - m_out->Print( 0, " (fill none)" ); - } - - formatLayer( aFPShape->GetLayer() ); - - m_out->Print( 0, " (tstamp %s)", TO_UTF8( aFPShape->m_Uuid.AsString() ) ); - - m_out->Print( 0, ")\n" ); -} - - void PCB_PLUGIN::format( const PCB_TARGET* aTarget, int aNestLevel ) const { m_out->Print( aNestLevel, "(target %s (at %s) (size %s)", ( aTarget->GetShape() ) ? "x" : "plus", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTarget->GetPosition() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTarget->GetSize() ).c_str() ); + formatInternalUnits( aTarget->GetPosition() ).c_str(), + formatInternalUnits( aTarget->GetSize() ).c_str() ); if( aTarget->GetWidth() != 0 ) - m_out->Print( 0, " (width %s)", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTarget->GetWidth() ).c_str() ); + m_out->Print( 0, " (width %s)", formatInternalUnits( aTarget->GetWidth() ).c_str() ); formatLayer( aTarget->GetLayer() ); @@ -1145,8 +1065,7 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const if( !( m_ctl & CTL_OMIT_AT ) ) { - m_out->Print( aNestLevel+1, "(at %s", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFootprint->GetPosition() ).c_str() ); + m_out->Print( aNestLevel+1, "(at %s", formatInternalUnits( aFootprint->GetPosition() ).c_str() ); if( !aFootprint->GetOrientation().IsZero() ) m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aFootprint->GetOrientation() ).c_str() ); @@ -1184,13 +1103,13 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const if( aFootprint->GetLocalSolderMaskMargin() != 0 ) { m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFootprint->GetLocalSolderMaskMargin() ).c_str() ); + formatInternalUnits( aFootprint->GetLocalSolderMaskMargin() ).c_str() ); } if( aFootprint->GetLocalSolderPasteMargin() != 0 ) { m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFootprint->GetLocalSolderPasteMargin() ).c_str() ); + formatInternalUnits( aFootprint->GetLocalSolderPasteMargin() ).c_str() ); } if( aFootprint->GetLocalSolderPasteMarginRatio() != 0 ) @@ -1202,7 +1121,7 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const if( aFootprint->GetLocalClearance() != 0 ) { m_out->Print( aNestLevel+1, "(clearance %s)\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aFootprint->GetLocalClearance() ).c_str() ); + formatInternalUnits( aFootprint->GetLocalClearance() ).c_str() ); } if( aFootprint->GetZoneConnection() != ZONE_CONNECTION::INHERITED ) @@ -1258,10 +1177,7 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const m_out->Print( aNestLevel+1, "(net_tie_pad_groups" ); for( const wxString& group : aFootprint->GetNetTiePadGroups() ) - { - m_out->Print( 0, " \"%s\"", - EscapeString( group, CTX_QUOTED_STR ).ToStdString().c_str() ); - } + m_out->Print( 0, " \"%s\"", EscapeString( group, CTX_QUOTED_STR ).ToStdString().c_str() ); m_out->Print( 0, ")\n" ); } @@ -1274,8 +1190,8 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const std::set sorted_drawings( aFootprint->GraphicalItems().begin(), aFootprint->GraphicalItems().end() ); - std::set sorted_zones( aFootprint->Zones().begin(), - aFootprint->Zones().end() ); + std::set sorted_zones( aFootprint->Zones().begin(), + aFootprint->Zones().end() ); std::set sorted_groups( aFootprint->Groups().begin(), aFootprint->Groups().end() ); @@ -1480,17 +1396,17 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const if( aPad->IsLocked() ) m_out->Print( 0, " locked" ); - m_out->Print( 0, " (at %s", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetPos0() ).c_str() ); + m_out->Print( 0, " (at %s", formatInternalUnits( aPad->GetPos0() ).c_str() ); if( !aPad->GetOrientation().IsZero() ) m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aPad->GetOrientation() ).c_str() ); m_out->Print( 0, ")" ); - m_out->Print( 0, " (size %s)", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetSize() ).c_str() ); + m_out->Print( 0, " (size %s)", formatInternalUnits( aPad->GetSize() ).c_str() ); if( (aPad->GetDelta().x) != 0 || (aPad->GetDelta().y != 0 ) ) - m_out->Print( 0, " (rect_delta %s)", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetDelta() ).c_str() ); + m_out->Print( 0, " (rect_delta %s)", formatInternalUnits( aPad->GetDelta() ).c_str() ); VECTOR2I sz = aPad->GetDrillSize(); VECTOR2I shapeoffset = aPad->GetOffset(); @@ -1504,13 +1420,13 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const m_out->Print( 0, " oval" ); if( sz.x > 0 ) - m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, sz.x ).c_str() ); + m_out->Print( 0, " %s", formatInternalUnits( sz.x ).c_str() ); if( sz.y > 0 && sz.x != sz.y ) - m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, sz.y ).c_str() ); + m_out->Print( 0, " %s", formatInternalUnits( sz.y ).c_str() ); if( (shapeoffset.x != 0) || (shapeoffset.y != 0) ) - m_out->Print( 0, " (offset %s)", EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetOffset() ).c_str() ); + m_out->Print( 0, " (offset %s)", formatInternalUnits( aPad->GetOffset() ).c_str() ); m_out->Print( 0, ")" ); } @@ -1606,19 +1522,19 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const if( aPad->GetPadToDieLength() != 0 ) { StrPrintf( &output, " (die_length %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetPadToDieLength() ).c_str() ); + formatInternalUnits( aPad->GetPadToDieLength() ).c_str() ); } if( aPad->GetLocalSolderMaskMargin() != 0 ) { StrPrintf( &output, " (solder_mask_margin %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetLocalSolderMaskMargin() ).c_str() ); + formatInternalUnits( aPad->GetLocalSolderMaskMargin() ).c_str() ); } if( aPad->GetLocalSolderPasteMargin() != 0 ) { StrPrintf( &output, " (solder_paste_margin %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetLocalSolderPasteMargin() ).c_str() ); + formatInternalUnits( aPad->GetLocalSolderPasteMargin() ).c_str() ); } if( aPad->GetLocalSolderPasteMarginRatio() != 0 ) @@ -1630,7 +1546,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const if( aPad->GetLocalClearance() != 0 ) { StrPrintf( &output, " (clearance %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetLocalClearance() ).c_str() ); + formatInternalUnits( aPad->GetLocalClearance() ).c_str() ); } if( aPad->GetZoneConnection() != ZONE_CONNECTION::INHERITED ) @@ -1642,7 +1558,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const if( aPad->GetThermalSpokeWidth() != 0 ) { StrPrintf( &output, " (thermal_bridge_width %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetThermalSpokeWidth() ).c_str() ); + formatInternalUnits( aPad->GetThermalSpokeWidth() ).c_str() ); } if( ( aPad->GetShape() == PAD_SHAPE::CIRCLE && aPad->GetThermalSpokeAngle() != ANGLE_45 ) @@ -1655,7 +1571,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const if( aPad->GetThermalGap() != 0 ) { StrPrintf( &output, " (thermal_gap %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetThermalGap() ).c_str() ); + formatInternalUnits( aPad->GetThermalGap() ).c_str() ); } if( output.size() ) @@ -1701,44 +1617,44 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const { case SHAPE_T::SEGMENT: m_out->Print( nested_level, "(gr_line (start %s) (end %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() ); + formatInternalUnits( primitive->GetStart() ).c_str(), + formatInternalUnits( primitive->GetEnd() ).c_str() ); break; case SHAPE_T::RECT: if( primitive->IsAnnotationProxy() ) { m_out->Print( nested_level, "(gr_bbox (start %s) (end %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() ); + formatInternalUnits( primitive->GetStart() ).c_str(), + formatInternalUnits( primitive->GetEnd() ).c_str() ); } else { m_out->Print( nested_level, "(gr_rect (start %s) (end %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() ); + formatInternalUnits( primitive->GetStart() ).c_str(), + formatInternalUnits( primitive->GetEnd() ).c_str() ); } break; case SHAPE_T::ARC: m_out->Print( nested_level, "(gr_arc (start %s) (mid %s) (end %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetArcMid() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() ); + formatInternalUnits( primitive->GetStart() ).c_str(), + formatInternalUnits( primitive->GetArcMid() ).c_str(), + formatInternalUnits( primitive->GetEnd() ).c_str() ); break; case SHAPE_T::CIRCLE: m_out->Print( nested_level, "(gr_circle (center %s) (end %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() ); + formatInternalUnits( primitive->GetStart() ).c_str(), + formatInternalUnits( primitive->GetEnd() ).c_str() ); break; case SHAPE_T::BEZIER: m_out->Print( nested_level, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetBezierC1() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetBezierC2() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetEnd() ).c_str() ); + formatInternalUnits( primitive->GetStart() ).c_str(), + formatInternalUnits( primitive->GetBezierC1() ).c_str(), + formatInternalUnits( primitive->GetBezierC2() ).c_str(), + formatInternalUnits( primitive->GetEnd() ).c_str() ); break; case SHAPE_T::POLY: @@ -1757,8 +1673,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const break; } - m_out->Print( 0, " (width %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, primitive->GetWidth() ).c_str() ); + m_out->Print( 0, " (width %s)", formatInternalUnits( primitive->GetWidth() ).c_str() ); // The filled flag represents if a solid fill is present on circles, // rectangles and polygons @@ -1766,10 +1681,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const || ( primitive->GetShape() == SHAPE_T::RECT ) || ( primitive->GetShape() == SHAPE_T::CIRCLE ) ) { - if( primitive->IsFilled() ) - m_out->Print( 0, " (fill yes)" ); - else - m_out->Print( 0, " (fill none)" ); + m_out->Print( 0, primitive->IsFilled() ? " (fill yes)" : " (fill none)" ); } m_out->Print( 0, ")" ); @@ -1787,28 +1699,55 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const void PCB_PLUGIN::format( const PCB_TEXT* aText, int aNestLevel ) const { - m_out->Print( aNestLevel, "(gr_text" ); + FOOTPRINT* parentFP = aText->GetParentFootprint(); + std::string prefix; + std::string type; - if( aText->IsLocked() ) - m_out->Print( 0, " locked" ); + // Always format dimension text as gr_text + if( dynamic_cast( aText ) ) + parentFP = nullptr; - m_out->Print( 0, " %s (at %s", + if( parentFP ) + { + prefix = "fp"; + + switch( aText->GetType() ) + { + case PCB_TEXT::TEXT_is_REFERENCE: type = " reference"; break; + case PCB_TEXT::TEXT_is_VALUE: type = " value"; break; + case PCB_TEXT::TEXT_is_DIVERS: type = " user"; break; + } + } + else + { + prefix = "gr"; + } + + m_out->Print( aNestLevel, "(%s_text%s%s %s (at %s", + prefix.c_str(), + type.c_str(), + aText->IsLocked() ? " locked" : "", m_out->Quotew( aText->GetText() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aText->GetTextPos() ).c_str() ); - + formatInternalUnits( aText->GetFPRelativePosition() ).c_str() ); + // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle. if( !aText->GetTextAngle().IsZero() ) m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aText->GetTextAngle() ).c_str() ); + if( parentFP && !aText->IsKeepUpright() ) + m_out->Print( 0, " unlocked" ); + m_out->Print( 0, ")" ); formatLayer( aText->GetLayer(), aText->IsKnockout() ); + if( parentFP && !aText->IsVisible() ) + m_out->Print( 0, " hide" ); + m_out->Print( 0, " (tstamp %s)", TO_UTF8( aText->m_Uuid.AsString() ) ); m_out->Print( 0, "\n" ); - // PCB_TEXTS are never hidden, so always omit "hide" attribute aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE ); if( aText->GetFont() && aText->GetFont()->IsOutline() ) @@ -1820,32 +1759,41 @@ void PCB_PLUGIN::format( const PCB_TEXT* aText, int aNestLevel ) const void PCB_PLUGIN::format( const PCB_TEXTBOX* aTextBox, int aNestLevel ) const { - std::string locked = aTextBox->IsLocked() ? " locked" : ""; + FOOTPRINT* parentFP = aTextBox->GetParentFootprint(); - m_out->Print( aNestLevel, "(gr_text_box%s %s\n", - locked.c_str(), + m_out->Print( aNestLevel, "(%s_text_box%s %s\n", + parentFP ? "fp" : "gr", + aTextBox->IsLocked() ? " locked" : "", m_out->Quotew( aTextBox->GetText() ).c_str() ); if( aTextBox->GetShape() == SHAPE_T::RECT ) { - m_out->Print( aNestLevel + 1, "(start %s) (end %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTextBox->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTextBox->GetEnd() ).c_str() ); + m_out->Print( aNestLevel + 1, "(start %s) (end %s)\n", + formatInternalUnits( aTextBox->GetStart(), parentFP ).c_str(), + formatInternalUnits( aTextBox->GetEnd(), parentFP ).c_str() ); } else if( aTextBox->GetShape() == SHAPE_T::POLY ) { const SHAPE_POLY_SET& poly = aTextBox->GetPolyShape(); const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 ); - formatPolyPts( outline, aNestLevel + 1, true ); + formatPolyPts( outline, aNestLevel, true, parentFP ); } else { UNIMPLEMENTED_FOR( aTextBox->SHAPE_T_asString() ); } - if( !aTextBox->GetTextAngle().IsZero() ) - m_out->Print( 0, " (angle %s)", EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str() ); + EDA_ANGLE angle = aTextBox->GetTextAngle(); + + if( parentFP ) + { + angle -= parentFP->GetOrientation(); + angle.Normalize720(); + } + + if( !angle.IsZero() ) + m_out->Print( aNestLevel + 1, "(angle %s)", EDA_UNIT_UTILS::FormatAngle( angle ).c_str() ); formatLayer( aTextBox->GetLayer() ); @@ -1854,7 +1802,7 @@ void PCB_PLUGIN::format( const PCB_TEXTBOX* aTextBox, int aNestLevel ) const m_out->Print( 0, "\n" ); // PCB_TEXTBOXes are never hidden, so always omit "hide" attribute - aTextBox->EDA_TEXT::Format( m_out, aNestLevel + 1, m_ctl | CTL_OMIT_HIDE ); + aTextBox->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE ); if( aTextBox->GetStroke().GetWidth() > 0 ) aTextBox->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 ); @@ -1894,122 +1842,6 @@ void PCB_PLUGIN::format( const PCB_GROUP* aGroup, int aNestLevel ) const } -void PCB_PLUGIN::format( const FP_TEXT* aText, int aNestLevel ) const -{ - std::string type; - - switch( aText->GetType() ) - { - case FP_TEXT::TEXT_is_REFERENCE: type = "reference"; break; - case FP_TEXT::TEXT_is_VALUE: type = "value"; break; - case FP_TEXT::TEXT_is_DIVERS: type = "user"; - } - - std::string locked = aText->IsLocked() ? " locked" : ""; - - m_out->Print( aNestLevel, "(fp_text %s%s %s (at %s", - type.c_str(), - locked.c_str(), - m_out->Quotew( aText->GetText() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aText->GetPos0() ).c_str() ); - - // Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle, - // but internally the angle is held relative to its parent footprint. parent - // may be NULL when saving a footprint outside a BOARD. - EDA_ANGLE orient = aText->GetTextAngle(); - FOOTPRINT* parent = static_cast( aText->GetParent() ); - - if( parent ) - { - // GetTextAngle() is always in -360..+360 range because of - // FP_TEXT::SetTextAngle(), but summing that angle with an - // additional board angle could kick sum up >= 360 or <= -360, so to have - // consistent results, normalize again for the BOARD save. A footprint - // save does not use this code path since parent is NULL. -#if 0 - // This one could be considered reasonable if you like positive angles - // in your board text. - orient = NormalizeAnglePos( orient + parent->GetOrientation() ); -#else - // Choose compatibility for now, even though this is only a 720 degree clamp - // with two possible values for every angle. - orient = ( orient + parent->GetOrientation() ).Normalize720(); -#endif - } - - if( !orient.IsZero() ) - m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( orient ).c_str() ); - - if( !aText->IsKeepUpright() ) - m_out->Print( 0, " unlocked" ); - - m_out->Print( 0, ")" ); - formatLayer( aText->GetLayer(), aText->IsKnockout() ); - - if( !aText->IsVisible() ) - m_out->Print( 0, " hide" ); - - m_out->Print( 0, "\n" ); - - aText->EDA_TEXT::Format( m_out, aNestLevel + 1, m_ctl | CTL_OMIT_HIDE ); - - m_out->Print( aNestLevel + 1, "(tstamp %s)\n", TO_UTF8( aText->m_Uuid.AsString() ) ); - - if( aText->GetFont() && aText->GetFont()->IsOutline() ) - formatRenderCache( aText, aNestLevel + 1 ); - - m_out->Print( aNestLevel, ")\n" ); -} - - -void PCB_PLUGIN::format( const FP_TEXTBOX* aTextBox, int aNestLevel ) const -{ - std::string locked = aTextBox->IsLocked() ? " locked" : ""; - - m_out->Print( aNestLevel, "(fp_text_box%s %s\n", - locked.c_str(), - m_out->Quotew( aTextBox->GetText() ).c_str() ); - - if( aTextBox->GetShape() == SHAPE_T::RECT ) - { - m_out->Print( aNestLevel, "(start %s) (end %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTextBox->GetStart0() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTextBox->GetEnd0() ).c_str() ); - } - else if( aTextBox->GetShape() == SHAPE_T::POLY ) - { - const SHAPE_POLY_SET& poly = aTextBox->GetPolyShape(); - const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 ); - - formatPolyPts( outline, aNestLevel, true ); - } - else - { - UNIMPLEMENTED_FOR( aTextBox->SHAPE_T_asString() ); - } - - if( !aTextBox->GetTextAngle().IsZero() ) - m_out->Print( 0, " (angle %s)", EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str() ); - - formatLayer( aTextBox->GetLayer() ); - - m_out->Print( 0, " (tstamp %s)", TO_UTF8( aTextBox->m_Uuid.AsString() ) ); - - m_out->Print( 0, "\n" ); - - // FP_TEXTBOXes are never hidden, so always omit "hide" attribute - aTextBox->EDA_TEXT::Format( m_out, aNestLevel + 1, m_ctl | CTL_OMIT_HIDE ); - - if( aTextBox->GetStroke().GetWidth() > 0 ) - aTextBox->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 ); - - if( aTextBox->GetFont() && aTextBox->GetFont()->IsOutline() ) - formatRenderCache( aTextBox, aNestLevel + 1 ); - - m_out->Print( aNestLevel, ")\n" ); -} - - void PCB_PLUGIN::format( const PCB_TRACK* aTrack, int aNestLevel ) const { if( aTrack->Type() == PCB_VIA_T ) @@ -2046,8 +1878,8 @@ void PCB_PLUGIN::format( const PCB_TRACK* aTrack, int aNestLevel ) const m_out->Print( 0, " locked" ); m_out->Print( 0, " (at %s) (size %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTrack->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTrack->GetWidth() ).c_str() ); + formatInternalUnits( aTrack->GetStart() ).c_str(), + formatInternalUnits( aTrack->GetWidth() ).c_str() ); // Old boards were using UNDEFINED_DRILL_DIAMETER value in file for via drill when // via drill was the netclass value. @@ -2055,15 +1887,9 @@ void PCB_PLUGIN::format( const PCB_TRACK* aTrack, int aNestLevel ) const // always store the drill value, because netclass value is not stored in the board file. // Otherwise the drill value of some (old) vias can be unknown if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER ) - { - m_out->Print( 0, " (drill %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, via->GetDrill() ).c_str() ); - } - else // Probably old board! - { - m_out->Print( 0, " (drill %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, via->GetDrillValue() ).c_str() ); - } + m_out->Print( 0, " (drill %s)", formatInternalUnits( via->GetDrill() ).c_str() ); + else + m_out->Print( 0, " (drill %s)", formatInternalUnits( via->GetDrillValue() ).c_str() ); m_out->Print( 0, " (layers %s %s)", m_out->Quotew( LSET::Name( layer1 ) ).c_str(), @@ -2096,26 +1922,23 @@ void PCB_PLUGIN::format( const PCB_TRACK* aTrack, int aNestLevel ) const else if( aTrack->Type() == PCB_ARC_T ) { const PCB_ARC* arc = static_cast( aTrack ); - std::string locked = arc->IsLocked() ? " locked" : ""; m_out->Print( aNestLevel, "(arc%s (start %s) (mid %s) (end %s) (width %s)", - locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, arc->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, arc->GetMid() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, arc->GetEnd() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, arc->GetWidth() ).c_str() ); + arc->IsLocked() ? " locked" : "", + formatInternalUnits( arc->GetStart() ).c_str(), + formatInternalUnits( arc->GetMid() ).c_str(), + formatInternalUnits( arc->GetEnd() ).c_str(), + formatInternalUnits( arc->GetWidth() ).c_str() ); m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( arc->GetLayer() ) ).c_str() ); } else { - std::string locked = aTrack->IsLocked() ? " locked" : ""; - m_out->Print( aNestLevel, "(segment%s (start %s) (end %s) (width %s)", - locked.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTrack->GetStart() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTrack->GetEnd() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aTrack->GetWidth() ).c_str() ); + aTrack->IsLocked() ? " locked" : "", + formatInternalUnits( aTrack->GetStart() ).c_str(), + formatInternalUnits( aTrack->GetEnd() ).c_str(), + formatInternalUnits( aTrack->GetWidth() ).c_str() ); m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( aTrack->GetLayer() ) ).c_str() ); } @@ -2130,8 +1953,6 @@ void PCB_PLUGIN::format( const PCB_TRACK* aTrack, int aNestLevel ) const void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const { - std::string locked = aZone->IsLocked() ? " locked" : ""; - // Save the NET info. // For keepout and non copper zones, net code and net name are irrelevant // so be sure a dummy value is stored, just for ZONE compatibility @@ -2139,7 +1960,7 @@ void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const bool has_no_net = aZone->GetIsRuleArea() || !aZone->IsOnCopperLayer(); m_out->Print( aNestLevel, "(zone%s (net %d) (net_name %s)", - locked.c_str(), + aZone->IsLocked() ? " locked" : "", has_no_net ? 0 : m_mapping->Translate( aZone->GetNetCode() ), m_out->Quotew( has_no_net ? wxString( wxT("") ) : aZone->GetNetname() ).c_str() ); @@ -2170,7 +1991,7 @@ void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const } m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetBorderHatchPitch() ).c_str() ); + formatInternalUnits( aZone->GetBorderHatchPitch() ).c_str() ); if( aZone->GetAssignedPriority() > 0 ) m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetAssignedPriority() ); @@ -2216,11 +2037,9 @@ void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const break; } - m_out->Print( 0, " (clearance %s))\n", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetLocalClearance() ).c_str() ); + m_out->Print( 0, " (clearance %s))\n", formatInternalUnits( aZone->GetLocalClearance() ).c_str() ); - m_out->Print( aNestLevel+1, "(min_thickness %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetMinThickness() ).c_str() ); + m_out->Print( aNestLevel+1, "(min_thickness %s)", formatInternalUnits( aZone->GetMinThickness() ).c_str() ); // We continue to write this for 3rd-party parsers, but we no longer read it (as of V7). m_out->Print( 0, " (filled_areas_thickness no)" ); @@ -2250,8 +2069,8 @@ void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const m_out->Print( 0, " (mode hatch)" ); m_out->Print( 0, " (thermal_gap %s) (thermal_bridge_width %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetThermalReliefGap() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetThermalReliefSpokeWidth() ).c_str() ); + formatInternalUnits( aZone->GetThermalReliefGap() ).c_str(), + formatInternalUnits( aZone->GetThermalReliefSpokeWidth() ).c_str() ); if( aZone->GetCornerSmoothingType() != ZONE_SETTINGS::SMOOTHING_NONE ) { @@ -2274,23 +2093,22 @@ void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const m_out->Print( 0, ")" ); if( aZone->GetCornerRadius() != 0 ) - m_out->Print( 0, " (radius %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetCornerRadius() ).c_str() ); + m_out->Print( 0, " (radius %s)", formatInternalUnits( aZone->GetCornerRadius() ).c_str() ); } if( aZone->GetIslandRemovalMode() != ISLAND_REMOVAL_MODE::ALWAYS ) { m_out->Print( 0, " (island_removal_mode %d) (island_area_min %s)", static_cast( aZone->GetIslandRemovalMode() ), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetMinIslandArea() / pcbIUScale.IU_PER_MM ).c_str() ); + formatInternalUnits( aZone->GetMinIslandArea() / pcbIUScale.IU_PER_MM ).c_str() ); } if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN ) { m_out->Print( 0, "\n" ); m_out->Print( aNestLevel+2, "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)", - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetHatchThickness() ).c_str(), - EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aZone->GetHatchGap() ).c_str(), + formatInternalUnits( aZone->GetHatchThickness() ).c_str(), + formatInternalUnits( aZone->GetHatchGap() ).c_str(), FormatDouble2Str( aZone->GetHatchOrientation().AsDegrees() ).c_str() ); if( aZone->GetHatchSmoothingLevel() > 0 ) diff --git a/pcbnew/plugins/kicad/pcb_plugin.h b/pcbnew/plugins/kicad/pcb_plugin.h index 4b2df16634..0d33c17a54 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.h +++ b/pcbnew/plugins/kicad/pcb_plugin.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 CERN. - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -39,13 +39,10 @@ class PCB_PARSER; class NETINFO_MAPPING; class BOARD_DESIGN_SETTINGS; class PCB_DIMENSION_BASE; -class FP_SHAPE; class PCB_SHAPE; class PCB_BITMAP; class PCB_TARGET; class PAD; -class FP_TEXT; -class FP_TEXTBOX; class PCB_GROUP; class PCB_TRACK; class ZONE; @@ -378,8 +375,6 @@ private: void format( const PCB_DIMENSION_BASE* aDimension, int aNestLevel = 0 ) const; - void format( const FP_SHAPE* aFPShape, int aNestLevel = 0 ) const; - void format( const PCB_BITMAP* aBitmap, int aNestLevel = 0 ) const; void format( const PCB_GROUP* aGroup, int aNestLevel = 0 ) const; @@ -395,14 +390,12 @@ private: void format( const PCB_TEXT* aText, int aNestLevel = 0 ) const; void format( const PCB_TEXTBOX* aTextBox, int aNestLevel = 0 ) const; - void format( const FP_TEXT* aText, int aNestLevel = 0 ) const; - void format( const FP_TEXTBOX* aTextBox, int aNestLevel = 0 ) const; - void format( const PCB_TRACK* aTrack, int aNestLevel = 0 ) const; void format( const ZONE* aZone, int aNestLevel = 0 ) const; - void formatPolyPts( const SHAPE_LINE_CHAIN& outline, int aNestLevel, bool aCompact ) const; + void formatPolyPts( const SHAPE_LINE_CHAIN& outline, int aNestLevel, bool aCompact, + const FOOTPRINT* aParentFP = nullptr ) const; void formatRenderCache( const EDA_TEXT* aText, int aNestLevel ) const; @@ -413,20 +406,20 @@ private: friend class FP_CACHE; protected: - wxString m_error; ///< for throwing exceptions - BOARD* m_board; ///< which BOARD, no ownership here + wxString m_error; ///< for throwing exceptions + BOARD* m_board; ///< which BOARD, no ownership here - const STRING_UTF8_MAP* m_props; ///< passed via Save() or Load(), no ownership, may be NULL. - FP_CACHE* m_cache; ///< Footprint library cache. + const STRING_UTF8_MAP* m_props; ///< passed via Save() or Load(), no ownership, may be NULL + FP_CACHE* m_cache; ///< Footprint library cache - LINE_READER* m_reader; ///< no ownership here. - wxString m_filename; ///< for saves only, name is in m_reader for loads + LINE_READER* m_reader; ///< no ownership + wxString m_filename; ///< for saves only, name is in m_reader for loads - STRING_FORMATTER m_sf; - OUTPUTFORMATTER* m_out; ///< output any Format()s to this, no ownership - int m_ctl; - NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty net codes - ///< are stored with consecutive integers as net codes + STRING_FORMATTER m_sf; + OUTPUTFORMATTER* m_out; ///< output any Format()s to this, no ownership + int m_ctl; + NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty net codes + ///< are stored with consecutive integers as net codes std::function* m_queryUserCallback; }; diff --git a/pcbnew/plugins/legacy/legacy_plugin.cpp b/pcbnew/plugins/legacy/legacy_plugin.cpp index d1fb96cfff..52436f9bec 100644 --- a/pcbnew/plugins/legacy/legacy_plugin.cpp +++ b/pcbnew/plugins/legacy/legacy_plugin.cpp @@ -83,7 +83,6 @@ #include #include #include -#include #include #include #include @@ -1149,21 +1148,21 @@ void LEGACY_PLUGIN::loadFOOTPRINT( FOOTPRINT* aFootprint ) // e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n" int tnum = intParse( line + SZ( "T" ) ); - FP_TEXT* text = nullptr; + PCB_TEXT* text = nullptr; switch( tnum ) { - case FP_TEXT::TEXT_is_REFERENCE: + case PCB_TEXT::TEXT_is_REFERENCE: text = &aFootprint->Reference(); break; - case FP_TEXT::TEXT_is_VALUE: + case PCB_TEXT::TEXT_is_VALUE: text = &aFootprint->Value(); break; // All other fields greater than 1. default: - text = new FP_TEXT( aFootprint ); + text = new PCB_TEXT( aFootprint, PCB_TEXT::TEXT_is_DIVERS ); aFootprint->Add( text ); } @@ -1544,13 +1543,13 @@ void LEGACY_PLUGIN::loadFP_SHAPE( FOOTPRINT* aFootprint ) case 'A': shape = SHAPE_T::ARC; break; case 'P': shape = SHAPE_T::POLY; break; default: - m_error.Printf( _( "Unknown FP_SHAPE type:'%c=0x%02x' on line %d of footprint '%s'." ), + m_error.Printf( _( "Unknown PCB_SHAPE type:'%c=0x%02x' on line %d of footprint '%s'." ), (unsigned char) line[1], (unsigned char) line[1], m_reader->LineNumber(), aFootprint->GetFPID().GetLibItemName().wx_str() ); THROW_IO_ERROR( m_error ); } - std::unique_ptr dwg = std::make_unique( aFootprint, shape ); // a drawing + std::unique_ptr dwg = std::make_unique( aFootprint, shape ); // a drawing const char* data; @@ -1571,9 +1570,9 @@ void LEGACY_PLUGIN::loadFP_SHAPE( FOOTPRINT* aFootprint ) width = biuParse( data, &data ); layer = intParse( data ); - dwg->SetCenter0( VECTOR2I( center0_x, center0_y ) ); - dwg->SetStart0( VECTOR2I( start0_x, start0_y ) ); - dwg->SetArcAngleAndEnd0( angle, true ); + dwg->SetCenter( VECTOR2I( center0_x, center0_y ) ); + dwg->SetStart( VECTOR2I( start0_x, start0_y ) ); + dwg->SetArcAngleAndEnd( angle, true ); break; } @@ -1589,8 +1588,8 @@ void LEGACY_PLUGIN::loadFP_SHAPE( FOOTPRINT* aFootprint ) width = biuParse( data, &data ); layer = intParse( data ); - dwg->SetStart0( VECTOR2I( start0_x, start0_y ) ); - dwg->SetEnd0( VECTOR2I( end0_x, end0_y ) ); + dwg->SetStart( VECTOR2I( start0_x, start0_y ) ); + dwg->SetEnd( VECTOR2I( end0_x, end0_y ) ); break; } @@ -1606,8 +1605,8 @@ void LEGACY_PLUGIN::loadFP_SHAPE( FOOTPRINT* aFootprint ) width = biuParse( data, &data ); layer = intParse( data ); - dwg->SetStart0( VECTOR2I( start0_x, start0_y ) ); - dwg->SetEnd0( VECTOR2I( end0_x, end0_y ) ); + dwg->SetStart( VECTOR2I( start0_x, start0_y ) ); + dwg->SetEnd( VECTOR2I( end0_x, end0_y ) ); std::vector pts; pts.reserve( ptCount ); @@ -1650,17 +1649,13 @@ void LEGACY_PLUGIN::loadFP_SHAPE( FOOTPRINT* aFootprint ) dwg->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) ); dwg->SetLayer( leg_layer2new( m_cu_count, layer ) ); - FP_SHAPE* fpShape = dwg.release(); - - aFootprint->Add( fpShape ); - - // this had been done at the FOOTPRINT level before, presumably because the FP_SHAPE needs - // to be already added to a footprint before this function will work. - fpShape->SetDrawCoord(); + dwg->Rotate( { 0, 0 }, aFootprint->GetOrientation() ); + dwg->Move( aFootprint->GetPosition() ); + aFootprint->Add( dwg.release() ); } -void LEGACY_PLUGIN::loadMODULE_TEXT( FP_TEXT* aText ) +void LEGACY_PLUGIN::loadMODULE_TEXT( PCB_TEXT* aText ) { const char* data; const char* txt_end; @@ -1705,16 +1700,14 @@ void LEGACY_PLUGIN::loadMODULE_TEXT( FP_TEXT* aText ) char* hjust = strtok_r( (char*) txt_end, delims, (char**) &data ); char* vjust = strtok_r( nullptr, delims, (char**) &data ); - if( type != FP_TEXT::TEXT_is_REFERENCE && type != FP_TEXT::TEXT_is_VALUE ) - type = FP_TEXT::TEXT_is_DIVERS; + if( type != PCB_TEXT::TEXT_is_REFERENCE && type != PCB_TEXT::TEXT_is_VALUE ) + type = PCB_TEXT::TEXT_is_DIVERS; - aText->SetType( static_cast( type ) ); + aText->SetType( static_cast( type ) ); - aText->SetPos0( VECTOR2I( pos0_x, pos0_y ) ); + aText->SetFPRelativePosition( VECTOR2I( pos0_x, pos0_y ) ); aText->SetTextSize( VECTOR2I( size0_x, size0_y ) ); - orient -= ( static_cast( aText->GetParentFootprint() ) )->GetOrientation(); - aText->SetTextAngle( orient ); aText->SetTextThickness( thickn < 1 ? 0 : thickn ); @@ -1744,9 +1737,6 @@ void LEGACY_PLUGIN::loadMODULE_TEXT( FP_TEXT* aText ) layer_num = SILKSCREEN_N_FRONT; aText->SetLayer( leg_layer2new( m_cu_count, layer_num ) ); - - // Calculate the actual position. - aText->SetDrawCoord(); } diff --git a/pcbnew/plugins/legacy/legacy_plugin.h b/pcbnew/plugins/legacy/legacy_plugin.h index 303ead90e7..6b415397f0 100644 --- a/pcbnew/plugins/legacy/legacy_plugin.h +++ b/pcbnew/plugins/legacy/legacy_plugin.h @@ -5,7 +5,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,11 +42,10 @@ class PCB_TARGET; class FOOTPRINT; class NETCLASS; -class NETCLASSES; class ZONE; class PCB_DIMENSION_BASE; class NETINFO_ITEM; -class FP_TEXT; +class PCB_TEXT; class PAD; struct LP_CACHE; @@ -152,7 +151,7 @@ protected: void load3D( FOOTPRINT* aFootprint ); void loadPAD( FOOTPRINT* aFootprint ); - void loadMODULE_TEXT( FP_TEXT* aText ); + void loadMODULE_TEXT( PCB_TEXT* aText ); void loadFP_SHAPE( FOOTPRINT* aFootprint ); void loadPCB_LINE(); diff --git a/pcbnew/plugins/pcad/CMakeLists.txt b/pcbnew/plugins/pcad/CMakeLists.txt index ef6398617c..471932fe48 100644 --- a/pcbnew/plugins/pcad/CMakeLists.txt +++ b/pcbnew/plugins/pcad/CMakeLists.txt @@ -6,22 +6,22 @@ set( PCAD2PCBNEW_SRCS pcad2kicad_common.cpp pcad_plugin.cpp - pcb.cpp - pcb_arc.cpp - pcb_component.cpp + pcad_pcb.cpp + pcad_arc.cpp + pcad_pcb_component.cpp pcb_copper_pour.cpp pcb_cutout.cpp pcb_keepout.cpp - pcb_line.cpp - pcb_footprint.cpp + pcad_line.cpp + pcad_footprint.cpp pcb_net.cpp - pcb_pad.cpp - pcb_pad_shape.cpp + pcad_pad.cpp + pcad_pad_shape.cpp pcb_plane.cpp - pcb_polygon.cpp - pcb_text.cpp - pcb_via.cpp - pcb_via_shape.cpp + pcad_polygon.cpp + pcad_text.cpp + pcad_via.cpp + pcad_via_shape.cpp s_expr_loader.cpp ) diff --git a/pcbnew/plugins/pcad/pcb_arc.cpp b/pcbnew/plugins/pcad/pcad_arc.cpp similarity index 77% rename from pcbnew/plugins/pcad/pcb_arc.cpp rename to pcbnew/plugins/pcad/pcad_arc.cpp index 44e05ea00e..13798abbd4 100644 --- a/pcbnew/plugins/pcad/pcb_arc.cpp +++ b/pcbnew/plugins/pcad/pcad_arc.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,11 +23,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include -#include #include // for KiROUND #include #include @@ -37,8 +36,8 @@ namespace PCAD2KICAD { -PCB_ARC::PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : - PCB_COMPONENT( aCallbacks, aBoard ) +PCAD_ARC::PCAD_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : + PCAD_PCB_COMPONENT( aCallbacks, aBoard ) { m_objType = wxT( 'A' ); m_StartX = 0; @@ -48,13 +47,13 @@ PCB_ARC::PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : } -PCB_ARC::~PCB_ARC() +PCAD_ARC::~PCAD_ARC() { } -void PCB_ARC::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, - const wxString& aActualConversion ) +void PCAD_ARC::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, + const wxString& aActualConversion ) { XNODE* lNode; int r = 0; @@ -153,18 +152,18 @@ void PCB_ARC::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, } -void PCB_ARC::SetPosOffset( int aX_offs, int aY_offs ) +void PCAD_ARC::SetPosOffset( int aX_offs, int aY_offs ) { - PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs ); + PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs ); m_StartX += aX_offs; m_StartY += aY_offs; } -void PCB_ARC::Flip() +void PCAD_ARC::Flip() { - PCB_COMPONENT::Flip(); + PCAD_PCB_COMPONENT::Flip(); m_StartX = -m_StartX; m_Angle = -m_Angle; @@ -173,41 +172,27 @@ void PCB_ARC::Flip() } -void PCB_ARC::AddToFootprint( FOOTPRINT* aFootprint ) +void PCAD_ARC::AddToBoard( FOOTPRINT* aFootprint ) { - if( IsNonCopperLayer( m_KiCadLayer ) ) + PCB_SHAPE* arc = new PCB_SHAPE( aFootprint, IsCircle() ? SHAPE_T::CIRCLE : SHAPE_T::ARC ); + aFootprint->Add( arc ); + + arc->SetCenter( VECTOR2I( m_positionX, m_positionY ) ); + arc->SetStart( VECTOR2I( m_StartX, m_StartY ) ); + arc->SetArcAngleAndEnd( -m_Angle, true ); + + arc->SetStroke( STROKE_PARAMS( m_Width, PLOT_DASH_TYPE::SOLID ) ); + arc->SetLayer( m_KiCadLayer ); + + if( aFootprint ) { - FP_SHAPE* arc = new FP_SHAPE( aFootprint, IsCircle() ? SHAPE_T::CIRCLE : SHAPE_T::ARC ); - aFootprint->Add( arc ); - - arc->SetCenter0( VECTOR2I( m_positionX, m_positionY ) ); - arc->SetStart0( VECTOR2I( m_StartX, m_StartY ) ); - arc->SetArcAngleAndEnd0( -m_Angle, true ); - - arc->SetStroke( STROKE_PARAMS( m_Width, PLOT_DASH_TYPE::SOLID ) ); - arc->SetLayer( m_KiCadLayer ); - - arc->SetDrawCoord(); + arc->Rotate( { 0, 0 }, aFootprint->GetOrientation() ); + arc->Move( aFootprint->GetPosition() ); } } -void PCB_ARC::AddToBoard() -{ - PCB_SHAPE* arc = new PCB_SHAPE( m_board, IsCircle() ? SHAPE_T::CIRCLE : SHAPE_T::ARC ); - - m_board->Add( arc, ADD_MODE::APPEND ); - - arc->SetFilled( false ); - arc->SetLayer( m_KiCadLayer ); - arc->SetCenter( VECTOR2I( m_positionX, m_positionY ) ); - arc->SetStart( VECTOR2I( m_StartX, m_StartY ) ); - arc->SetArcAngleAndEnd( -m_Angle, true ); - arc->SetStroke( STROKE_PARAMS( m_Width, PLOT_DASH_TYPE::SOLID ) ); -} - - -bool PCB_ARC::IsCircle() +bool PCAD_ARC::IsCircle() { return ( m_Angle == ANGLE_360 ); } diff --git a/pcbnew/plugins/pcad/pcb_arc.h b/pcbnew/plugins/pcad/pcad_arc.h similarity index 81% rename from pcbnew/plugins/pcad/pcb_arc.h rename to pcbnew/plugins/pcad/pcad_arc.h index 630c83766e..269ccbefd0 100644 --- a/pcbnew/plugins/pcad/pcb_arc.h +++ b/pcbnew/plugins/pcad/pcad_arc.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_ARC_H_ -#define PCB_ARC_H_ +#ifndef PCAD_ARC_H +#define PCAD_ARC_H -#include +#include class BOARD; class FOOTPRINT; @@ -35,11 +35,11 @@ class XNODE; namespace PCAD2KICAD { -class PCB_ARC : public PCB_COMPONENT +class PCAD_ARC : public PCAD_PCB_COMPONENT { public: - PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_ARC(); + PCAD_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_ARC(); virtual void Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, const wxString& aActualConversion ); @@ -48,8 +48,7 @@ public: virtual void Flip() override; - void AddToFootprint( FOOTPRINT* aFootprint ) override; - void AddToBoard() override; + void AddToBoard( FOOTPRINT* aFootprint = nullptr ) override; int m_StartX; int m_StartY; @@ -62,4 +61,4 @@ private: } // namespace PCAD2KICAD -#endif // PCB_ARC_H_ +#endif // PCAD_ARC_H diff --git a/pcbnew/plugins/pcad/pcb_footprint.cpp b/pcbnew/plugins/pcad/pcad_footprint.cpp similarity index 85% rename from pcbnew/plugins/pcad/pcb_footprint.cpp rename to pcbnew/plugins/pcad/pcad_footprint.cpp index 0c5b5cc214..2e390da34e 100644 --- a/pcbnew/plugins/pcad/pcb_footprint.cpp +++ b/pcbnew/plugins/pcad/pcad_footprint.cpp @@ -23,19 +23,20 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include +#include #include #include @@ -44,8 +45,8 @@ namespace PCAD2KICAD { -PCB_FOOTPRINT::PCB_FOOTPRINT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : - PCB_COMPONENT( aCallbacks, aBoard ) +PCAD_FOOTPRINT::PCAD_FOOTPRINT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : + PCAD_PCB_COMPONENT( aCallbacks, aBoard ) { InitTTextValue( &m_Value ); m_Mirror = 0; @@ -54,7 +55,7 @@ PCB_FOOTPRINT::PCB_FOOTPRINT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : } -PCB_FOOTPRINT::~PCB_FOOTPRINT() +PCAD_FOOTPRINT::~PCAD_FOOTPRINT() { int i; @@ -65,7 +66,7 @@ PCB_FOOTPRINT::~PCB_FOOTPRINT() } -XNODE* PCB_FOOTPRINT::FindModulePatternDefName( XNODE* aNode, const wxString& aName ) +XNODE* PCAD_FOOTPRINT::FindModulePatternDefName( XNODE* aNode, const wxString& aName ) { XNODE* result, * lNode; wxString propValue1, propValue2; @@ -118,7 +119,7 @@ XNODE* PCB_FOOTPRINT::FindModulePatternDefName( XNODE* aNode, const wxString& aN } -XNODE* PCB_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPatGraphRefName ) +XNODE* PCAD_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPatGraphRefName ) { XNODE* result, * pNode, * lNode; wxString propValue, patName; @@ -214,20 +215,20 @@ XNODE* PCB_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPat } -void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootprint, +void PCAD_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCAD_FOOTPRINT* aFootprint, PCB_COMPONENTS_ARRAY* aList, wxStatusBar* aStatusBar, const wxString& aDefaultMeasurementUnit, const wxString& aActualConversion ) { - PCB_ARC* arc; - PCB_POLYGON* polygon; - PCB_POLYGON *plane_layer = nullptr; + PCAD_ARC* arc; + PCAD_POLYGON* polygon; + PCAD_POLYGON*plane_layer = nullptr; PCB_COPPER_POUR* copperPour; PCB_CUTOUT* cutout; PCB_PLANE* plane; VERTICES_ARRAY* plane_layer_polygon; - PCB_LINE* line; - PCB_TEXT* text; + PCAD_LINE* line; + PCAD_TEXT* text; XNODE* lNode, * tNode; wxString propValue; long long i; @@ -244,7 +245,7 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootpr if( m_callbacks->GetLayerType( PCadLayer ) == LAYER_TYPE_PLANE ) { - plane_layer = new PCB_POLYGON( m_callbacks, m_board, PCadLayer ); + plane_layer = new PCAD_POLYGON( m_callbacks, m_board, PCadLayer ); plane_layer->AssignNet( m_callbacks->GetLayerNetNameRef( PCadLayer ) ); plane_layer->SetOutline( &m_BoardOutline ); aList->Add( plane_layer ); @@ -263,14 +264,14 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootpr if( lNode->GetName() == wxT( "line" ) ) { - line = new PCB_LINE( m_callbacks, m_board ); + line = new PCAD_LINE( m_callbacks, m_board ); line->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion ); aList->Add( line ); } if( lNode->GetName() == wxT( "text" ) ) { - text = new PCB_TEXT( m_callbacks, m_board ); + text = new PCAD_TEXT( m_callbacks, m_board ); text->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion ); aList->Add( text ); } @@ -305,7 +306,7 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootpr // added as Sergeys request 02/2008 if( lNode->GetName() == wxT( "arc" ) || lNode->GetName() == wxT( "triplePointArc" ) ) { - arc = new PCB_ARC( m_callbacks, m_board ); + arc = new PCAD_ARC( m_callbacks, m_board ); arc->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion ); aList->Add( arc ); } @@ -321,7 +322,7 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootpr } else { - polygon = new PCB_POLYGON( m_callbacks, m_board, PCadLayer ); + polygon = new PCAD_POLYGON( m_callbacks, m_board, PCadLayer ); if( polygon->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) ) aList->Add( polygon ); @@ -365,7 +366,7 @@ void PCB_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootpr } -void PCB_FOOTPRINT::SetName( const wxString& aPin, const wxString& aName ) +void PCAD_FOOTPRINT::SetName( const wxString& aPin, const wxString& aName ) { int i; long num; @@ -376,20 +377,20 @@ void PCB_FOOTPRINT::SetName( const wxString& aPin, const wxString& aName ) { if( m_FootprintItems[i]->m_objType == wxT( 'P' ) ) { - if( ( (PCB_PAD*) m_FootprintItems[i] )->m_Number == num ) - ( (PCB_PAD*) m_FootprintItems[i] )->m_name.text = aName; + if( ( (PCAD_PAD*) m_FootprintItems[i] )->m_Number == num ) + ( (PCAD_PAD*) m_FootprintItems[i] )->m_name.text = aName; } } } -void PCB_FOOTPRINT::Parse( XNODE* aNode, wxStatusBar* aStatusBar, +void PCAD_FOOTPRINT::Parse( XNODE* aNode, wxStatusBar* aStatusBar, const wxString& aDefaultMeasurementUnit, const wxString& aActualConversion ) { XNODE* lNode, * tNode, * mNode; - PCB_PAD* pad; - PCB_VIA* via; + PCAD_PAD* pad; + PCAD_VIA* via; wxString propValue, str; FindNode( aNode, wxT( "originalName" ) )->GetAttribute( wxT( "Name" ), &propValue ); @@ -409,14 +410,14 @@ void PCB_FOOTPRINT::Parse( XNODE* aNode, wxStatusBar* aStatusBar, { if( tNode->GetName() == wxT( "pad" ) ) { - pad = new PCB_PAD( m_callbacks, m_board ); + pad = new PCAD_PAD( m_callbacks, m_board ); pad->Parse( tNode, aDefaultMeasurementUnit, aActualConversion ); m_FootprintItems.Add( pad ); } if( tNode->GetName() == wxT( "via" ) ) { - via = new PCB_VIA( m_callbacks, m_board ); + via = new PCAD_VIA( m_callbacks, m_board ); via->Parse( tNode, aDefaultMeasurementUnit, aActualConversion ); m_FootprintItems.Add( via ); } @@ -474,8 +475,11 @@ void PCB_FOOTPRINT::Parse( XNODE* aNode, wxStatusBar* aStatusBar, } -void PCB_FOOTPRINT::AddToBoard() +void PCAD_FOOTPRINT::AddToBoard( FOOTPRINT* aFootprint ) { + // No nested footprints.... + wxCHECK( aFootprint == nullptr, /* void */ ); + int i; EDA_ANGLE r; @@ -498,12 +502,13 @@ void PCB_FOOTPRINT::AddToBoard() footprint->SetFPID( fpID ); // reference text - FP_TEXT* ref_text = &footprint->Reference(); + PCB_TEXT* ref_text = &footprint->Reference(); ref_text->SetText( ValidateReference( m_name.text ) ); - ref_text->SetType( FP_TEXT::TEXT_is_REFERENCE ); + ref_text->SetType( PCB_TEXT::TEXT_is_REFERENCE ); - ref_text->SetPos0( VECTOR2I( m_name.correctedPositionX, m_name.correctedPositionY ) ); + ref_text->SetFPRelativePosition( VECTOR2I( m_name.correctedPositionX, + m_name.correctedPositionY ) ); if( m_name.isTrueType ) SetTextSizeFromTrueTypeFontHeight( ref_text, m_name.textHeight ); @@ -522,16 +527,14 @@ void PCB_FOOTPRINT::AddToBoard() ref_text->SetLayer( m_Mirror ? FlipLayer( m_KiCadLayer ) : m_KiCadLayer ); - // Calculate the actual position. - ref_text->SetDrawCoord(); - // value text - FP_TEXT* val_text = &footprint->Value(); + PCB_TEXT* val_text = &footprint->Value(); val_text->SetText( m_Value.text ); - val_text->SetType( FP_TEXT::TEXT_is_VALUE ); + val_text->SetType( PCB_TEXT::TEXT_is_VALUE ); - val_text->SetPos0( VECTOR2I( m_Value.correctedPositionX, m_Value.correctedPositionY ) ); + val_text->SetFPRelativePosition( VECTOR2I( m_Value.correctedPositionX, + m_Value.correctedPositionY ) ); if( m_Value.isTrueType ) SetTextSizeFromTrueTypeFontHeight( val_text, m_Value.textHeight ); @@ -550,16 +553,13 @@ void PCB_FOOTPRINT::AddToBoard() val_text->SetLayer( m_Value.mirror ? FlipLayer( m_KiCadLayer ) : m_KiCadLayer ); - // Calculate the actual position. - val_text->SetDrawCoord(); - // TEXTS for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ ) { if( m_FootprintItems[i]->m_objType == wxT( 'T' ) ) { - ( (PCB_TEXT*) m_FootprintItems[i] )->m_tag = i + 2; - m_FootprintItems[ i ]->AddToFootprint( footprint ); + ( (PCAD_TEXT*) m_FootprintItems[i] )->m_tag = i + 2; + m_FootprintItems[ i ]->AddToBoard( footprint ); } } @@ -567,40 +567,40 @@ void PCB_FOOTPRINT::AddToBoard() for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ ) { if( m_FootprintItems[i]->m_objType == wxT( 'L' ) ) - m_FootprintItems[ i ]->AddToFootprint( footprint ); + m_FootprintItems[ i ]->AddToBoard( footprint ); } // FOOTPRINT ARCS for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ ) { if( m_FootprintItems[i]->m_objType == wxT( 'A' ) ) - m_FootprintItems[ i ]->AddToFootprint( footprint ); + m_FootprintItems[ i ]->AddToBoard( footprint ); } // FOOTPRINT POLYGONS for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ ) { if( m_FootprintItems[i]->m_objType == wxT( 'Z' ) ) - m_FootprintItems[ i ]->AddToFootprint( footprint ); + m_FootprintItems[ i ]->AddToBoard( footprint ); } // PADS for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ ) { if( m_FootprintItems[i]->m_objType == wxT( 'P' ) ) - ((PCB_PAD*) m_FootprintItems[ i ] )->AddToFootprint( footprint, m_rotation, false ); + ((PCAD_PAD*) m_FootprintItems[ i ] )->AddToFootprint( footprint, m_rotation, false ); } // VIAS for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ ) { if( m_FootprintItems[i]->m_objType == wxT( 'V' ) ) - ((PCB_VIA*) m_FootprintItems[ i ] )->AddToFootprint( footprint, m_rotation, false ); + ((PCAD_VIA*) m_FootprintItems[ i ] )->AddToFootprint( footprint, m_rotation, false ); } } -void PCB_FOOTPRINT::Flip() +void PCAD_FOOTPRINT::Flip() { int i; diff --git a/pcbnew/plugins/pcad/pcb_footprint.h b/pcbnew/plugins/pcad/pcad_footprint.h similarity index 82% rename from pcbnew/plugins/pcad/pcb_footprint.h rename to pcbnew/plugins/pcad/pcad_footprint.h index 9c74aa67ac..613732261f 100644 --- a/pcbnew/plugins/pcad/pcb_footprint.h +++ b/pcbnew/plugins/pcad/pcad_footprint.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,12 +23,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_FOOTPRINT_H -#define PCB_FOOTPRINT_H +#ifndef PCAD_FOOTPRINT_H +#define PCAD_FOOTPRINT_H #include #include -#include +#include class BOARD; class FOOTPRINT; @@ -38,15 +38,15 @@ class XNODE; namespace PCAD2KICAD { -class PCB_FOOTPRINT : public PCB_COMPONENT +class PCAD_FOOTPRINT : public PCAD_PCB_COMPONENT { public: - PCB_FOOTPRINT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_FOOTPRINT(); + PCAD_FOOTPRINT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_FOOTPRINT(); XNODE* FindModulePatternDefName( XNODE* aNode, const wxString& aName ); - void DoLayerContentsObjects( XNODE* aNode, PCB_FOOTPRINT* aFootprint, + void DoLayerContentsObjects( XNODE* aNode, PCAD_FOOTPRINT* aFootprint, PCB_COMPONENTS_ARRAY* aList, wxStatusBar* aStatusBar, const wxString& aDefaultMeasurementUnit, const wxString& aActualConversion ); @@ -58,10 +58,10 @@ public: const wxString& aActualConversion ); virtual void Flip() override; - void AddToBoard() override; + void AddToBoard( FOOTPRINT* aFootprint = nullptr ) override; TTEXTVALUE m_Value; // has reference (Name from parent) and value - PCB_COMPONENTS_ARRAY m_FootprintItems; // set of objects like PCB_LINE, PCB_PAD, PCB_VIA.... + PCB_COMPONENTS_ARRAY m_FootprintItems; // set of objects like PCAD_LINE, PCAD_PAD, PCAD_VIA.... int m_Mirror; VERTICES_ARRAY m_BoardOutline; @@ -71,4 +71,4 @@ private: } // namespace PCAD2KICAD -#endif // PCB_FOOTPRINT_H +#endif // PCAD_FOOTPRINT_H diff --git a/pcbnew/plugins/pcad/pcad_item_types.h b/pcbnew/plugins/pcad/pcad_item_types.h index 4c89495475..ae8fbcb5a2 100644 --- a/pcbnew/plugins/pcad/pcad_item_types.h +++ b/pcbnew/plugins/pcad/pcad_item_types.h @@ -35,15 +35,15 @@ WX_DEFINE_ARRAY( VERTICES_ARRAY*, ISLANDS_ARRAY ); namespace PCAD2KICAD { -class PCB_COMPONENT; +class PCAD_PCB_COMPONENT; class PCB_NET; class PCB_NET_NODE; -class PCB_PAD_SHAPE; +class PCAD_PAD_SHAPE; -WX_DEFINE_ARRAY( PCB_COMPONENT*, PCB_COMPONENTS_ARRAY ); +WX_DEFINE_ARRAY( PCAD_PCB_COMPONENT*, PCB_COMPONENTS_ARRAY ); WX_DEFINE_ARRAY( PCB_NET*, PCB_NETS_ARRAY ); WX_DEFINE_ARRAY( PCB_NET_NODE*, PCB_NET_NODES_ARRAY ); -WX_DEFINE_ARRAY( PCB_PAD_SHAPE*, PCB_PAD_SHAPES_ARRAY ); +WX_DEFINE_ARRAY( PCAD_PAD_SHAPE*, PCB_PAD_SHAPES_ARRAY ); } #endif diff --git a/pcbnew/plugins/pcad/pcb_line.cpp b/pcbnew/plugins/pcad/pcad_line.cpp similarity index 70% rename from pcbnew/plugins/pcad/pcb_line.cpp rename to pcbnew/plugins/pcad/pcad_line.cpp index bbf29d631f..c3fdf3c261 100644 --- a/pcbnew/plugins/pcad/pcb_line.cpp +++ b/pcbnew/plugins/pcad/pcad_line.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,12 +23,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include #include -#include #include #include #include @@ -37,8 +36,8 @@ namespace PCAD2KICAD { -PCB_LINE::PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : - PCB_COMPONENT( aCallbacks, aBoard ) +PCAD_LINE::PCAD_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : + PCAD_PCB_COMPONENT( aCallbacks, aBoard ) { m_Width = 0; m_ToX = 0; @@ -47,25 +46,25 @@ PCB_LINE::PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : } -PCB_LINE::~PCB_LINE() +PCAD_LINE::~PCAD_LINE() { } -void PCB_LINE::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, - const wxString& aActualConversion ) +void PCAD_LINE::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, + const wxString& aActualConversion ) { XNODE* lNode; wxString propValue; - m_PCadLayer = aLayer; - m_KiCadLayer = GetKiCadLayer(); - m_positionX = 0; - m_positionY = 0; - m_ToX = 0; - m_ToY = 0; - m_Width = 0; - lNode = FindNode( aNode, wxT( "pt" ) ); + m_PCadLayer = aLayer; + m_KiCadLayer = GetKiCadLayer(); + m_positionX = 0; + m_positionY = 0; + m_ToX = 0; + m_ToY = 0; + m_Width = 0; + lNode = FindNode( aNode, wxT( "pt" ) ); if( lNode ) { @@ -97,45 +96,27 @@ void PCB_LINE::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, } -void PCB_LINE::SetPosOffset( int aX_offs, int aY_offs ) +void PCAD_LINE::SetPosOffset( int aX_offs, int aY_offs ) { - PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs ); + PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs ); m_ToX += aX_offs; m_ToY += aY_offs; } -void PCB_LINE::Flip() +void PCAD_LINE::Flip() { - PCB_COMPONENT::Flip(); + PCAD_PCB_COMPONENT::Flip(); m_ToX = -m_ToX; m_KiCadLayer = FlipLayer( m_KiCadLayer ); } -void PCB_LINE::AddToFootprint( FOOTPRINT* aFootprint ) +void PCAD_LINE::AddToBoard( FOOTPRINT* aFootprint ) { - if( IsNonCopperLayer( m_KiCadLayer ) ) - { - FP_SHAPE* segment = new FP_SHAPE( aFootprint, SHAPE_T::SEGMENT ); - aFootprint->Add( segment ); - - segment->SetStart0( VECTOR2I( m_positionX, m_positionY ) ); - segment->SetEnd0( VECTOR2I( m_ToX, m_ToY ) ); - - segment->SetStroke( STROKE_PARAMS( m_Width, PLOT_DASH_TYPE::SOLID ) ); - segment->SetLayer( m_KiCadLayer ); - - segment->SetDrawCoord(); - } -} - - -void PCB_LINE::AddToBoard() -{ - if( IsCopperLayer( m_KiCadLayer ) ) + if( IsCopperLayer( m_KiCadLayer ) && !aFootprint ) { PCB_TRACK* track = new PCB_TRACK( m_board ); m_board->Add( track ); @@ -157,6 +138,12 @@ void PCB_LINE::AddToBoard() segment->SetStart( VECTOR2I( m_positionX, m_positionY ) ); segment->SetEnd( VECTOR2I( m_ToX, m_ToY ) ); segment->SetStroke( STROKE_PARAMS( m_Width, PLOT_DASH_TYPE::SOLID ) ); + + if( aFootprint ) + { + segment->Rotate( { 0, 0 }, aFootprint->GetOrientation() ); + segment->Move( aFootprint->GetPosition() ); + } } } diff --git a/pcbnew/plugins/pcad/pcb_line.h b/pcbnew/plugins/pcad/pcad_line.h similarity index 81% rename from pcbnew/plugins/pcad/pcb_line.h rename to pcbnew/plugins/pcad/pcad_line.h index 5c7733b880..9d1f3c7ef3 100644 --- a/pcbnew/plugins/pcad/pcb_line.h +++ b/pcbnew/plugins/pcad/pcad_line.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_LINE_H_ -#define PCB_LINE_H_ +#ifndef PCAD_LINE_H +#define PCAD_LINE_H -#include +#include class BOARD; class FOOTPRINT; @@ -36,11 +36,11 @@ class XNODE; namespace PCAD2KICAD { // Line , routes and drawings -class PCB_LINE : public PCB_COMPONENT +class PCAD_LINE : public PCAD_PCB_COMPONENT { public: - PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_LINE(); + PCAD_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_LINE(); virtual void Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, const wxString& aActualConversion ); @@ -49,8 +49,7 @@ public: virtual void Flip() override; - void AddToFootprint( FOOTPRINT* aFootprint ) override; - void AddToBoard() override; + void AddToBoard( FOOTPRINT* aFootprint = nullptr ) override; int m_Width; int m_ToX; @@ -59,4 +58,4 @@ public: } // namespace PCAD2KICAD -#endif // PCB_LINE_H_ +#endif // PCAD_LINE_H diff --git a/pcbnew/plugins/pcad/pcb_pad.cpp b/pcbnew/plugins/pcad/pcad_pad.cpp similarity index 91% rename from pcbnew/plugins/pcad/pcb_pad.cpp rename to pcbnew/plugins/pcad/pcad_pad.cpp index c31cce7d0b..66f8cb8f55 100644 --- a/pcbnew/plugins/pcad/pcb_pad.cpp +++ b/pcbnew/plugins/pcad/pcad_pad.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,8 +23,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include +#include +#include #include #include @@ -38,8 +38,8 @@ namespace PCAD2KICAD { -PCB_PAD::PCB_PAD( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : - PCB_COMPONENT( aCallbacks, aBoard ) +PCAD_PAD::PCAD_PAD( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : + PCAD_PCB_COMPONENT( aCallbacks, aBoard ) { m_objType = wxT( 'P' ); m_Number = 0; @@ -49,7 +49,7 @@ PCB_PAD::PCB_PAD( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : } -PCB_PAD::~PCB_PAD() +PCAD_PAD::~PCAD_PAD() { int i; @@ -58,14 +58,14 @@ PCB_PAD::~PCB_PAD() } -void PCB_PAD::Parse( XNODE* aNode, const wxString& aDefaultUnits, +void PCAD_PAD::Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ) { XNODE* lNode; XNODE* cNode; long num; wxString propValue, str, emsg; - PCB_PAD_SHAPE* padShape; + PCAD_PAD_SHAPE* padShape; m_rotation = ANGLE_0; lNode = FindNode( aNode, wxT( "padNum" ) ); @@ -166,7 +166,7 @@ void PCB_PAD::Parse( XNODE* aNode, const wxString& aDefaultUnits, // we do not support pads on "Plane", "NonSignal" , "Signal" ... layerr if( FindNode( cNode, wxT( "layerNumRef" ) ) ) { - padShape = new PCB_PAD_SHAPE( m_callbacks, m_board ); + padShape = new PCAD_PAD_SHAPE( m_callbacks, m_board ); padShape->Parse( cNode, aDefaultUnits, aActualConversion ); m_Shapes.Add( padShape ); } @@ -177,11 +177,11 @@ void PCB_PAD::Parse( XNODE* aNode, const wxString& aDefaultUnits, } -void PCB_PAD::Flip() +void PCAD_PAD::Flip() { int i; - PCB_COMPONENT::Flip(); + PCAD_PCB_COMPONENT::Flip(); if( m_objType == wxT( 'P' ) ) m_rotation = -m_rotation; @@ -191,10 +191,10 @@ void PCB_PAD::Flip() } -void PCB_PAD::AddToFootprint( FOOTPRINT* aFootprint, const EDA_ANGLE& aRotation, +void PCAD_PAD::AddToFootprint( FOOTPRINT* aFootprint, const EDA_ANGLE& aRotation, bool aEncapsulatedPad ) { - PCB_PAD_SHAPE* padShape; + PCAD_PAD_SHAPE* padShape; wxString padShapeName = wxT( "Ellipse" ); PAD_ATTRIB padType; int i; @@ -324,9 +324,9 @@ void PCB_PAD::AddToFootprint( FOOTPRINT* aFootprint, const EDA_ANGLE& aRotation, } -void PCB_PAD::AddToBoard() +void PCAD_PAD::AddToBoard( FOOTPRINT* aFootprint ) { - PCB_PAD_SHAPE* padShape; + PCAD_PAD_SHAPE* padShape; int i; int width = 0; int height = 0; @@ -373,13 +373,16 @@ void PCB_PAD::AddToBoard() } else // pad { - FOOTPRINT* footprint = new FOOTPRINT( m_board ); - m_board->Add( footprint, ADD_MODE::APPEND ); + if( !aFootprint ) + { + aFootprint = new FOOTPRINT( m_board ); + m_board->Add( aFootprint, ADD_MODE::APPEND ); + aFootprint->SetPosition( VECTOR2I( m_positionX, m_positionY ) ); + } m_name.text = m_defaultPinDes; - footprint->SetPosition( VECTOR2I( m_positionX, m_positionY ) ); - AddToFootprint( footprint, ANGLE_0, true ); + AddToFootprint( aFootprint, ANGLE_0, true ); } } diff --git a/pcbnew/plugins/pcad/pcb_pad.h b/pcbnew/plugins/pcad/pcad_pad.h similarity index 80% rename from pcbnew/plugins/pcad/pcb_pad.h rename to pcbnew/plugins/pcad/pcad_pad.h index e97a09eb0d..5cd3638a5f 100644 --- a/pcbnew/plugins/pcad/pcb_pad.h +++ b/pcbnew/plugins/pcad/pcad_pad.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_PAD_H_ -#define PCB_PAD_H_ +#ifndef PCAD_PAD_H +#define PCAD_PAD_H -#include +#include class BOARD; class FOOTPRINT; @@ -35,25 +35,20 @@ class XNODE; namespace PCAD2KICAD { -class PCB_PAD : public PCB_COMPONENT +class PCAD_PAD : public PCAD_PCB_COMPONENT { public: - PCB_PAD( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_PAD(); + PCAD_PAD( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_PAD(); virtual void Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ); virtual void Flip() override; - void AddToFootprint( FOOTPRINT* aFootprint ) override - { - AddToFootprint( aFootprint, ANGLE_0, true ); - } - void AddToFootprint( FOOTPRINT* aFootprint, const EDA_ANGLE& aRotation, bool aEncapsulatedPad ); - void AddToBoard() override; + void AddToBoard( FOOTPRINT* aFootprint = nullptr ) override; int m_Number; int m_Hole; @@ -66,4 +61,4 @@ private: } // namespace PCAD2KICAD -#endif // PCB_PAD_H_ +#endif // PCAD_PAD_H diff --git a/pcbnew/plugins/pcad/pcb_pad_shape.cpp b/pcbnew/plugins/pcad/pcad_pad_shape.cpp similarity index 90% rename from pcbnew/plugins/pcad/pcb_pad_shape.cpp rename to pcbnew/plugins/pcad/pcad_pad_shape.cpp index 3d1899ce9a..92064f1424 100644 --- a/pcbnew/plugins/pcad/pcb_pad_shape.cpp +++ b/pcbnew/plugins/pcad/pcad_pad_shape.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,7 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include @@ -32,8 +32,8 @@ namespace PCAD2KICAD { -PCB_PAD_SHAPE::PCB_PAD_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : - PCB_COMPONENT( aCallbacks, aBoard ) +PCAD_PAD_SHAPE::PCAD_PAD_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : + PCAD_PCB_COMPONENT( aCallbacks, aBoard ) { m_Shape = wxEmptyString; m_Width = 0; @@ -41,12 +41,12 @@ PCB_PAD_SHAPE::PCB_PAD_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : } -PCB_PAD_SHAPE::~PCB_PAD_SHAPE() +PCAD_PAD_SHAPE::~PCAD_PAD_SHAPE() { } -void PCB_PAD_SHAPE::Parse( XNODE* aNode, const wxString& aDefaultUnits, +void PCAD_PAD_SHAPE::Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ) { wxString str, s; @@ -128,8 +128,4 @@ void PCB_PAD_SHAPE::Parse( XNODE* aNode, const wxString& aDefaultUnits, } -void PCB_PAD_SHAPE::AddToBoard() -{ -} - } // namespace PCAD2KICAD diff --git a/pcbnew/plugins/pcad/pcb_pad_shape.h b/pcbnew/plugins/pcad/pcad_pad_shape.h similarity index 79% rename from pcbnew/plugins/pcad/pcb_pad_shape.h rename to pcbnew/plugins/pcad/pcad_pad_shape.h index 3a9b27e60a..edba3ac41b 100644 --- a/pcbnew/plugins/pcad/pcb_pad_shape.h +++ b/pcbnew/plugins/pcad/pcad_pad_shape.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_PAD_SHAPE_H_ -#define PCB_PAD_SHAPE_H_ +#ifndef PCAD_PAD_SHAPE_H +#define PCAD_PAD_SHAPE_H -#include +#include class BOARD; class wxString; @@ -34,16 +34,16 @@ class XNODE; namespace PCAD2KICAD { -class PCB_PAD_SHAPE : public PCB_COMPONENT +class PCAD_PAD_SHAPE : public PCAD_PCB_COMPONENT { public: - PCB_PAD_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_PAD_SHAPE(); + PCAD_PAD_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_PAD_SHAPE(); virtual void Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ); - void AddToBoard() override; + void AddToBoard( FOOTPRINT* aFootprint = nullptr ) override {} wxString m_Shape; int m_Width; @@ -52,4 +52,4 @@ public: } // namespace PCAD2KICAD -#endif // PCB_PAD_SHAPE_H_ +#endif // PCAD_PAD_SHAPE_H diff --git a/pcbnew/plugins/pcad/pcb.cpp b/pcbnew/plugins/pcad/pcad_pcb.cpp similarity index 93% rename from pcbnew/plugins/pcad/pcb.cpp rename to pcbnew/plugins/pcad/pcad_pcb.cpp index a52ca95831..9b159bc59a 100644 --- a/pcbnew/plugins/pcad/pcb.cpp +++ b/pcbnew/plugins/pcad/pcad_pcb.cpp @@ -23,14 +23,14 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include -#include +#include #include -#include -#include -#include +#include +#include +#include #include #include @@ -42,7 +42,7 @@ namespace PCAD2KICAD { -PCB_LAYER_ID PCB::GetKiCadLayer( int aPCadLayer ) const +PCB_LAYER_ID PCAD_PCB::GetKiCadLayer( int aPCadLayer ) const { auto it = m_LayersMap.find( aPCadLayer ); @@ -53,7 +53,7 @@ PCB_LAYER_ID PCB::GetKiCadLayer( int aPCadLayer ) const } -LAYER_TYPE_T PCB::GetLayerType( int aPCadLayer ) const +LAYER_TYPE_T PCAD_PCB::GetLayerType( int aPCadLayer ) const { auto it = m_LayersMap.find( aPCadLayer ); @@ -64,7 +64,7 @@ LAYER_TYPE_T PCB::GetLayerType( int aPCadLayer ) const } -wxString PCB::GetLayerNetNameRef( int aPCadLayer ) const +wxString PCAD_PCB::GetLayerNetNameRef( int aPCadLayer ) const { auto it = m_LayersMap.find( aPCadLayer ); @@ -75,8 +75,7 @@ wxString PCB::GetLayerNetNameRef( int aPCadLayer ) const } -PCB::PCB( BOARD* aBoard ) : - PCB_FOOTPRINT( this, aBoard ) +PCAD_PCB::PCAD_PCB( BOARD* aBoard ) : PCAD_FOOTPRINT( this, aBoard ) { m_DefaultMeasurementUnit = wxT( "mil" ); @@ -105,7 +104,7 @@ PCB::PCB( BOARD* aBoard ) : } -PCB::~PCB() +PCAD_PCB::~PCAD_PCB() { int i; @@ -121,7 +120,7 @@ PCB::~PCB() } -int PCB::GetNetCode( const wxString& aNetName ) const +int PCAD_PCB::GetNetCode( const wxString& aNetName ) const { const PCB_NET* net; @@ -138,7 +137,7 @@ int PCB::GetNetCode( const wxString& aNetName ) const return 0; } -XNODE* PCB::FindCompDefName( XNODE* aNode, const wxString& aName ) const +XNODE* PCAD_PCB::FindCompDefName( XNODE* aNode, const wxString& aName ) const { XNODE* result = nullptr, * lNode; wxString propValue; @@ -166,7 +165,7 @@ XNODE* PCB::FindCompDefName( XNODE* aNode, const wxString& aName ) const } -void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& aPatGraphRefName, +void PCAD_PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& aPatGraphRefName, const wxString& aXmlName, const wxString& aActualConversion ) { XNODE* tNode, * t1Node; @@ -235,13 +234,13 @@ void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& } -void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString& aActualConversion, +void PCAD_PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString& aActualConversion, wxStatusBar* aStatusBar ) { XNODE* lNode, * tNode, * mNode; - PCB_FOOTPRINT* fp; - PCB_PAD* pad; - PCB_VIA* via; + PCAD_FOOTPRINT* fp; + PCAD_PAD* pad; + PCAD_VIA* via; PCB_KEEPOUT* keepOut; wxString cn, str, propValue; @@ -264,7 +263,7 @@ void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString& if( tNode ) { - fp = new PCB_FOOTPRINT( this, m_board ); + fp = new PCAD_FOOTPRINT( this, m_board ); mNode = FindNode( lNode, wxT( "patternGraphicsNameRef" ) ); @@ -399,13 +398,13 @@ void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString& } else if( lNode->GetName().IsSameAs( wxT( "pad" ), false ) ) { - pad = new PCB_PAD( this, m_board ); + pad = new PCAD_PAD( this, m_board ); pad->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion ); m_PcbComponents.Add( pad ); } else if( lNode->GetName().IsSameAs( wxT( "via" ), false ) ) { - via = new PCB_VIA( this, m_board ); + via = new PCAD_VIA( this, m_board ); via->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion ); m_PcbComponents.Add( via ); } @@ -424,16 +423,16 @@ void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString& } -void PCB::ConnectPinToNet( const wxString& aCompRef, const wxString& aPinRef, +void PCAD_PCB::ConnectPinToNet( const wxString& aCompRef, const wxString& aPinRef, const wxString& aNetName ) { - PCB_FOOTPRINT* footprint; - PCB_PAD* cp; + PCAD_FOOTPRINT* footprint; + PCAD_PAD* cp; int i, j; for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ ) { - footprint = (PCB_FOOTPRINT*) m_PcbComponents[i]; + footprint = (PCAD_FOOTPRINT*) m_PcbComponents[i]; if( footprint->m_objType == wxT( 'M' ) && footprint->m_name.text == aCompRef ) { @@ -441,7 +440,7 @@ void PCB::ConnectPinToNet( const wxString& aCompRef, const wxString& aPinRef, { if( footprint->m_FootprintItems[j]->m_objType == wxT( 'P' ) ) { - cp = (PCB_PAD*) footprint->m_FootprintItems[j]; + cp = (PCAD_PAD*) footprint->m_FootprintItems[j]; if( cp->m_name.text == aPinRef ) cp->m_net = aNetName; @@ -452,7 +451,7 @@ void PCB::ConnectPinToNet( const wxString& aCompRef, const wxString& aPinRef, } -int PCB::FindLayer( const wxString& aLayerName ) const +int PCAD_PCB::FindLayer( const wxString& aLayerName ) const { for( int i = 0; i < (int) m_layersStackup.size(); ++i ) { @@ -464,7 +463,7 @@ int PCB::FindLayer( const wxString& aLayerName ) const } -void PCB::MapLayer( XNODE* aNode ) +void PCAD_PCB::MapLayer( XNODE* aNode ) { wxString lName, layerType; PCB_LAYER_ID KiCadLayer; @@ -559,7 +558,7 @@ void PCB::MapLayer( XNODE* aNode ) } } -int PCB::FindOutlinePoint( const VERTICES_ARRAY* aOutline, wxRealPoint aPoint ) const +int PCAD_PCB::FindOutlinePoint( const VERTICES_ARRAY* aOutline, wxRealPoint aPoint ) const { int i; @@ -573,13 +572,13 @@ int PCB::FindOutlinePoint( const VERTICES_ARRAY* aOutline, wxRealPoint aPoint ) } -double PCB::GetDistance( const wxRealPoint* aPoint1, const wxRealPoint* aPoint2 ) const +double PCAD_PCB::GetDistance( const wxRealPoint* aPoint1, const wxRealPoint* aPoint2 ) const { return sqrt( ( aPoint1->x - aPoint2->x ) * ( aPoint1->x - aPoint2->x ) + ( aPoint1->y - aPoint2->y ) * ( aPoint1->y - aPoint2->y ) ); } -void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConversion ) +void PCAD_PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConversion ) { XNODE* iNode, *lNode, *pNode; long PCadLayer = 0; @@ -673,13 +672,13 @@ void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConver } -void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, +void PCAD_PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, const wxString& aActualConversion ) { XNODE* aNode;//, *aaNode; PCB_NET* net; - PCB_COMPONENT* comp; - PCB_FOOTPRINT* footprint; + PCAD_PCB_COMPONENT* comp; + PCAD_FOOTPRINT* footprint; wxString compRef, pinRef, layerName, layerType; int i, j, netCode; @@ -858,7 +857,7 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ ) { if( m_PcbComponents[i]->m_objType == wxT( 'M' ) ) - ( (PCB_FOOTPRINT*) m_PcbComponents[i] )->Flip(); + ( (PCAD_FOOTPRINT*) m_PcbComponents[i] )->Flip(); } // POSTPROCESS -- SET/OPTIMIZE NEW PCB POSITION @@ -928,7 +927,7 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, if( aNode->GetName().IsSameAs( wxT( "compDef" ), false ) ) { - footprint = new PCB_FOOTPRINT( this, m_board ); + footprint = new PCAD_FOOTPRINT( this, m_board ); footprint->Parse( aNode, aStatusBar, m_DefaultMeasurementUnit, aActualConversion ); m_PcbComponents.Add( footprint ); @@ -941,7 +940,7 @@ void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, } -void PCB::AddToBoard() +void PCAD_PCB::AddToBoard( FOOTPRINT* ) { int i; PCB_NET* net; diff --git a/pcbnew/plugins/pcad/pcb.h b/pcbnew/plugins/pcad/pcad_pcb.h similarity index 92% rename from pcbnew/plugins/pcad/pcb.h rename to pcbnew/plugins/pcad/pcad_pcb.h index 7a636c9b1b..d132a05490 100644 --- a/pcbnew/plugins/pcad/pcb.h +++ b/pcbnew/plugins/pcad/pcad_pcb.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -43,11 +43,11 @@ class wxXmlDocument; namespace PCAD2KICAD { -class PCB : public PCB_FOOTPRINT, public PCB_CALLBACKS +class PCAD_PCB : public PCAD_FOOTPRINT, public PCB_CALLBACKS { public: - PCB( BOARD* aBoard ); - ~PCB(); + PCAD_PCB( BOARD* aBoard ); + ~PCAD_PCB(); PCB_LAYER_ID GetKiCadLayer( int aPCadLayer ) const override; LAYER_TYPE_T GetLayerType( int aPCadLayer ) const override; @@ -57,7 +57,7 @@ public: void ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, const wxString& aActualConversion ); - void AddToBoard() override; + void AddToBoard( FOOTPRINT* aFootprint = nullptr ) override; PCB_COMPONENTS_ARRAY m_PcbComponents; // PCB footprints,Lines,Routes,Texts, .... and so on PCB_NETS_ARRAY m_PcbNetlist; // net objects collection diff --git a/pcbnew/plugins/pcad/pcb_component.cpp b/pcbnew/plugins/pcad/pcad_pcb_component.cpp similarity index 86% rename from pcbnew/plugins/pcad/pcb_component.cpp rename to pcbnew/plugins/pcad/pcad_pcb_component.cpp index a4dba93147..efae759480 100644 --- a/pcbnew/plugins/pcad/pcb_component.cpp +++ b/pcbnew/plugins/pcad/pcad_pcb_component.cpp @@ -23,7 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include @@ -34,7 +34,7 @@ namespace PCAD2KICAD { -PCB_COMPONENT::PCB_COMPONENT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : +PCAD_PCB_COMPONENT::PCAD_PCB_COMPONENT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : m_uuid(), m_callbacks( aCallbacks ), m_board( aBoard ) @@ -54,23 +54,18 @@ PCB_COMPONENT::PCB_COMPONENT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : } -PCB_COMPONENT::~PCB_COMPONENT() +PCAD_PCB_COMPONENT::~PCAD_PCB_COMPONENT() { } -void PCB_COMPONENT::AddToFootprint( FOOTPRINT* aFootprint ) -{ -} - - -void PCB_COMPONENT::SetPosOffset( int aX_offs, int aY_offs ) +void PCAD_PCB_COMPONENT::SetPosOffset( int aX_offs, int aY_offs ) { m_positionX += aX_offs; m_positionY += aY_offs; } -void PCB_COMPONENT::Flip() +void PCAD_PCB_COMPONENT::Flip() { m_positionX = -m_positionX; } diff --git a/pcbnew/plugins/pcad/pcb_component.h b/pcbnew/plugins/pcad/pcad_pcb_component.h similarity index 89% rename from pcbnew/plugins/pcad/pcb_component.h rename to pcbnew/plugins/pcad/pcad_pcb_component.h index 954ac92ab6..72a455a2aa 100644 --- a/pcbnew/plugins/pcad/pcb_component.h +++ b/pcbnew/plugins/pcad/pcad_pcb_component.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,16 +42,15 @@ class wxRealPoint; namespace PCAD2KICAD { // basic parent class for PCB objects -class PCB_COMPONENT : public wxObject +class PCAD_PCB_COMPONENT : public wxObject { public: - PCB_COMPONENT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_COMPONENT(); + PCAD_PCB_COMPONENT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_PCB_COMPONENT(); virtual void SetPosOffset( int aX_offs, int aY_offs ); virtual void Flip(); - virtual void AddToFootprint( FOOTPRINT* aFootprint ); - virtual void AddToBoard() = 0; + virtual void AddToBoard( FOOTPRINT* aFootprint = nullptr ) = 0; PCB_LAYER_ID GetKiCadLayer() const { return m_callbacks->GetKiCadLayer( m_PCadLayer ); } diff --git a/pcbnew/plugins/pcad/pcad_plugin.cpp b/pcbnew/plugins/pcad/pcad_plugin.cpp index 78975b90b0..ff3beb3e85 100644 --- a/pcbnew/plugins/pcad/pcad_plugin.cpp +++ b/pcbnew/plugins/pcad/pcad_plugin.cpp @@ -28,7 +28,7 @@ */ #include -#include +#include #include #include @@ -80,7 +80,7 @@ BOARD* PCAD_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, if( !aAppendToMe ) m_board->SetFileName( aFileName ); - PCB pcb( m_board ); + PCAD_PCB pcb( m_board ); LOCALE_IO toggle; // toggles on, then off, the C locale. diff --git a/pcbnew/plugins/pcad/pcb_polygon.cpp b/pcbnew/plugins/pcad/pcad_polygon.cpp similarity index 59% rename from pcbnew/plugins/pcad/pcb_polygon.cpp rename to pcbnew/plugins/pcad/pcad_polygon.cpp index 68a4d12cd1..1e899bd591 100644 --- a/pcbnew/plugins/pcad/pcb_polygon.cpp +++ b/pcbnew/plugins/pcad/pcad_polygon.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,11 +23,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include -#include +#include #include // for KiROUND #include #include @@ -36,8 +36,8 @@ namespace PCAD2KICAD { -PCB_POLYGON::PCB_POLYGON( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ) : - PCB_COMPONENT( aCallbacks, aBoard ) +PCAD_POLYGON::PCAD_POLYGON( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ) : + PCAD_PCB_COMPONENT( aCallbacks, aBoard ) { m_width = 0; @@ -53,21 +53,17 @@ PCB_POLYGON::PCB_POLYGON( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLay } -PCB_POLYGON::~PCB_POLYGON() +PCAD_POLYGON::~PCAD_POLYGON() { int i, island; for( i = 0; i < (int) m_outline.GetCount(); i++ ) - { delete m_outline[i]; - } for( island = 0; island < (int) m_cutouts.GetCount(); island++ ) { for( i = 0; i < (int) m_cutouts[island]->GetCount(); i++ ) - { delete (*m_cutouts[island])[i]; - } delete m_cutouts[island]; } @@ -75,21 +71,19 @@ PCB_POLYGON::~PCB_POLYGON() for( island = 0; island < (int) m_islands.GetCount(); island++ ) { for( i = 0; i < (int) m_islands[island]->GetCount(); i++ ) - { delete (*m_islands[island])[i]; - } delete m_islands[island]; } } -void PCB_POLYGON::AssignNet( const wxString& aNetName ) +void PCAD_POLYGON::AssignNet( const wxString& aNetName ) { m_net = aNetName; m_netCode = GetNetCode( m_net ); } -void PCB_POLYGON::SetOutline( VERTICES_ARRAY* aOutline ) +void PCAD_POLYGON::SetOutline( VERTICES_ARRAY* aOutline ) { int i; @@ -105,8 +99,8 @@ void PCB_POLYGON::SetOutline( VERTICES_ARRAY* aOutline ) } } -void PCB_POLYGON::FormPolygon( XNODE* aNode, VERTICES_ARRAY* aPolygon, - const wxString& aDefaultUnits, const wxString& aActualConversion ) +void PCAD_POLYGON::FormPolygon( XNODE* aNode, VERTICES_ARRAY* aPolygon, + const wxString& aDefaultUnits, const wxString& aActualConversion ) { XNODE* lNode; double x, y; @@ -127,7 +121,7 @@ void PCB_POLYGON::FormPolygon( XNODE* aNode, VERTICES_ARRAY* aPolygon, } -bool PCB_POLYGON::Parse( XNODE* aNode, const wxString& aDefaultUnits, +bool PCAD_POLYGON::Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ) { XNODE* lNode; @@ -158,95 +152,93 @@ bool PCB_POLYGON::Parse( XNODE* aNode, const wxString& aDefaultUnits, } -void PCB_POLYGON::AddToFootprint( FOOTPRINT* aFootprint ) +void PCAD_POLYGON::AddToBoard( FOOTPRINT* aFootprint ) { - if( IsNonCopperLayer( m_KiCadLayer ) ) - { - FP_SHAPE* dwg = new FP_SHAPE( aFootprint, SHAPE_T::POLY ); - aFootprint->Add( dwg ); - - dwg->SetStroke( STROKE_PARAMS( 0 ) ); - dwg->SetLayer( m_KiCadLayer ); - - auto outline = new std::vector; - for( auto point : m_outline ) - outline->push_back( VECTOR2I( point->x, point->y ) ); - - dwg->SetPolyPoints( *outline ); - dwg->SetStart0( *outline->begin() ); - dwg->SetEnd0( outline->back() ); - dwg->SetDrawCoord(); - - delete( outline ); - } -} - - -void PCB_POLYGON::AddToBoard() -{ - int i = 0; - if( m_outline.GetCount() > 0 ) { - ZONE* zone = new ZONE( m_board ); - m_board->Add( zone, ADD_MODE::APPEND ); - - zone->SetLayer( m_KiCadLayer ); - zone->SetNetCode( m_netCode ); - - // add outline - for( i = 0; i < (int) m_outline.GetCount(); i++ ) + if( aFootprint ) { - zone->AppendCorner( VECTOR2I( KiROUND( m_outline[i]->x ), - KiROUND( m_outline[i]->y ) ), -1 ); + PCB_SHAPE* dwg = new PCB_SHAPE( aFootprint, SHAPE_T::POLY ); + aFootprint->Add( dwg ); + + dwg->SetStroke( STROKE_PARAMS( 0 ) ); + dwg->SetLayer( m_KiCadLayer ); + + auto outline = new std::vector; + + for( auto point : m_outline ) + outline->push_back( VECTOR2I( point->x, point->y ) ); + + dwg->SetPolyPoints( *outline ); + dwg->SetStart( *outline->begin() ); + dwg->SetEnd( outline->back() ); + dwg->Rotate( { 0, 0 }, aFootprint->GetOrientation() ); + dwg->Move( aFootprint->GetPosition() ); + + delete( outline ); } - - zone->SetLocalClearance( m_width ); - - zone->SetAssignedPriority( m_priority ); - - zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE, - zone->GetDefaultHatchPitch(), true ); - - if ( m_objType == wxT( 'K' ) ) + else { - zone->SetIsRuleArea( true ); - zone->SetDoNotAllowTracks( true ); - zone->SetDoNotAllowVias( true ); - zone->SetDoNotAllowPads( true ); - zone->SetDoNotAllowCopperPour( true ); - zone->SetDoNotAllowFootprints( false ); - } - else if( m_objType == wxT( 'C' ) ) - { - // convert cutouts to keepouts because standalone cutouts are not supported in KiCad - zone->SetIsRuleArea( true ); - zone->SetDoNotAllowCopperPour( true ); - zone->SetDoNotAllowTracks( false ); - zone->SetDoNotAllowVias( false ); - zone->SetDoNotAllowPads( false ); - zone->SetDoNotAllowFootprints( false ); - } + ZONE* zone = new ZONE( m_board ); + m_board->Add( zone, ADD_MODE::APPEND ); - //if( m_filled ) - // zone->BuildFilledPolysListData( m_board ); + zone->SetLayer( m_KiCadLayer ); + zone->SetNetCode( m_netCode ); + + // add outline + for( int i = 0; i < (int) m_outline.GetCount(); i++ ) + { + zone->AppendCorner( VECTOR2I( KiROUND( m_outline[i]->x ), + KiROUND( m_outline[i]->y ) ), -1 ); + } + + zone->SetLocalClearance( m_width ); + + zone->SetAssignedPriority( m_priority ); + + zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE, + zone->GetDefaultHatchPitch(), true ); + + if ( m_objType == wxT( 'K' ) ) + { + zone->SetIsRuleArea( true ); + zone->SetDoNotAllowTracks( true ); + zone->SetDoNotAllowVias( true ); + zone->SetDoNotAllowPads( true ); + zone->SetDoNotAllowCopperPour( true ); + zone->SetDoNotAllowFootprints( false ); + } + else if( m_objType == wxT( 'C' ) ) + { + // convert cutouts to keepouts because standalone cutouts are not supported in KiCad + zone->SetIsRuleArea( true ); + zone->SetDoNotAllowCopperPour( true ); + zone->SetDoNotAllowTracks( false ); + zone->SetDoNotAllowVias( false ); + zone->SetDoNotAllowPads( false ); + zone->SetDoNotAllowFootprints( false ); + } + + //if( m_filled ) + // zone->BuildFilledPolysListData( m_board ); + } } } -void PCB_POLYGON::Flip() +void PCAD_POLYGON::Flip() { - PCB_COMPONENT::Flip(); + PCAD_PCB_COMPONENT::Flip(); m_KiCadLayer = FlipLayer( m_KiCadLayer ); } -void PCB_POLYGON::SetPosOffset( int aX_offs, int aY_offs ) +void PCAD_POLYGON::SetPosOffset( int aX_offs, int aY_offs ) { int i, island; - PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs ); + PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs ); for( i = 0; i < (int) m_outline.GetCount(); i++ ) { diff --git a/pcbnew/plugins/pcad/pcb_polygon.h b/pcbnew/plugins/pcad/pcad_polygon.h similarity index 83% rename from pcbnew/plugins/pcad/pcb_polygon.h rename to pcbnew/plugins/pcad/pcad_polygon.h index 436f773b5a..dd308eca8d 100644 --- a/pcbnew/plugins/pcad/pcb_polygon.h +++ b/pcbnew/plugins/pcad/pcad_polygon.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,11 +23,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_POLYGON_H_ -#define PCB_POLYGON_H_ +#ifndef PCAD_POLYGON_H +#define PCAD_POLYGON_H #include -#include +#include class BOARD; class FOOTPRINT; @@ -36,11 +36,11 @@ class XNODE; namespace PCAD2KICAD { -class PCB_POLYGON : public PCB_COMPONENT +class PCAD_POLYGON : public PCAD_PCB_COMPONENT { public: - PCB_POLYGON( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ); - ~PCB_POLYGON(); + PCAD_POLYGON( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ); + ~PCAD_POLYGON(); virtual bool Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ); @@ -49,9 +49,7 @@ public: virtual void Flip() override; - void AddToFootprint( FOOTPRINT* aFootprint ) override; - - void AddToBoard() override; + void AddToBoard( FOOTPRINT* aFootprint = nullptr ) override; // protected: void AssignNet( const wxString& aNetName ); @@ -73,4 +71,4 @@ protected: } // namespace PCAD2KICAD -#endif // PCB_POLYGON_H_ +#endif // PCAD_POLYGON_H diff --git a/pcbnew/plugins/pcad/pcb_text.cpp b/pcbnew/plugins/pcad/pcad_text.cpp similarity index 87% rename from pcbnew/plugins/pcad/pcb_text.cpp rename to pcbnew/plugins/pcad/pcad_text.cpp index 809e59f0fc..2734997de3 100644 --- a/pcbnew/plugins/pcad/pcb_text.cpp +++ b/pcbnew/plugins/pcad/pcad_text.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,7 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include @@ -34,19 +34,19 @@ namespace PCAD2KICAD { -PCB_TEXT::PCB_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : - PCB_COMPONENT( aCallbacks, aBoard ) +PCAD_TEXT::PCAD_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : + PCAD_PCB_COMPONENT( aCallbacks, aBoard ) { m_objType = wxT( 'T' ); } -PCB_TEXT::~PCB_TEXT() +PCAD_TEXT::~PCAD_TEXT() { } -void PCB_TEXT::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, +void PCAD_TEXT::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, const wxString& aActualConversion ) { XNODE* lNode; @@ -92,12 +92,7 @@ void PCB_TEXT::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, } -void PCB_TEXT::AddToFootprint( FOOTPRINT* aFootprint ) -{ -} - - -void PCB_TEXT::AddToBoard() +void PCAD_TEXT::AddToBoard( FOOTPRINT* aFootprint ) { m_name.textPositionX = m_positionX; m_name.textPositionY = m_positionY; @@ -130,9 +125,9 @@ void PCB_TEXT::AddToBoard() } -// void PCB_TEXT::SetPosOffset( int aX_offs, int aY_offs ) +// void PCAD_TEXT::SetPosOffset( int aX_offs, int aY_offs ) // { -// PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs ); +// PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs ); // m_name.textPositionX += aX_offs; // m_name.textPositionY += aY_offs; diff --git a/pcbnew/plugins/pcad/pcb_text.h b/pcbnew/plugins/pcad/pcad_text.h similarity index 80% rename from pcbnew/plugins/pcad/pcb_text.h rename to pcbnew/plugins/pcad/pcad_text.h index b65e2cce0e..98d8b97980 100644 --- a/pcbnew/plugins/pcad/pcb_text.h +++ b/pcbnew/plugins/pcad/pcad_text.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_TEXT_H_ -#define PCB_TEXT_H_ +#ifndef PCAD_TEXT_H +#define PCAD_TEXT_H -#include +#include class BOARD; class FOOTPRINT; @@ -36,22 +36,20 @@ class XNODE; namespace PCAD2KICAD { // Name property of parent is used for text value -class PCB_TEXT : public PCB_COMPONENT +class PCAD_TEXT : public PCAD_PCB_COMPONENT { public: - PCB_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_TEXT(); + PCAD_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_TEXT(); virtual void Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits, const wxString& aActualConversion ); - void AddToFootprint( FOOTPRINT* aFootprint ) override; - - void AddToBoard() override; + void AddToBoard( FOOTPRINT* aFootprint = nullptr ) override; // virtual void SetPosOffset( int aX_offs, int aY_offs ); }; } // namespace PCAD2KICAD -#endif // PCB_TEXT_H_ +#endif // PCAD_TEXT_H diff --git a/pcbnew/plugins/pcad/pcb_via.cpp b/pcbnew/plugins/pcad/pcad_via.cpp similarity index 89% rename from pcbnew/plugins/pcad/pcb_via.cpp rename to pcbnew/plugins/pcad/pcad_via.cpp index ce85ff83f1..962aeb9d17 100644 --- a/pcbnew/plugins/pcad/pcb_via.cpp +++ b/pcbnew/plugins/pcad/pcad_via.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,8 +23,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include +#include +#include #include @@ -33,24 +33,23 @@ namespace PCAD2KICAD { -PCB_VIA::PCB_VIA( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : - PCB_PAD( aCallbacks, aBoard ) +PCAD_VIA::PCAD_VIA( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCAD_PAD( aCallbacks, aBoard ) { m_objType = wxT( 'V' ); } -PCB_VIA::~PCB_VIA() +PCAD_VIA::~PCAD_VIA() { } -void PCB_VIA::Parse( XNODE* aNode, const wxString& aDefaultUnits, +void PCAD_VIA::Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ) { XNODE* lNode, * tNode; wxString propValue; - PCB_VIA_SHAPE* viaShape; + PCAD_VIA_SHAPE* viaShape; m_rotation = ANGLE_0; lNode = FindNode( aNode, wxT( "viaStyleRef" ) ); @@ -125,7 +124,7 @@ void PCB_VIA::Parse( XNODE* aNode, const wxString& aDefaultUnits, // we do not support vias on "Plane", "NonSignal" , "Signal" ... layerr if( FindNode( lNode, wxT( "layerNumRef" ) ) ) { - viaShape = new PCB_VIA_SHAPE( m_callbacks, m_board ); + viaShape = new PCAD_VIA_SHAPE( m_callbacks, m_board ); viaShape->Parse( lNode, aDefaultUnits, aActualConversion ); m_Shapes.Add( viaShape ); } diff --git a/pcbnew/plugins/pcad/pcb_via.h b/pcbnew/plugins/pcad/pcad_via.h similarity index 84% rename from pcbnew/plugins/pcad/pcb_via.h rename to pcbnew/plugins/pcad/pcad_via.h index 2b23624458..1570afc750 100644 --- a/pcbnew/plugins/pcad/pcb_via.h +++ b/pcbnew/plugins/pcad/pcad_via.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_VIA_H_ -#define PCB_VIA_H_ +#ifndef PCAD_VIA_H +#define PCAD_VIA_H -#include +#include class BOARD; class wxString; @@ -35,11 +35,11 @@ class XNODE; namespace PCAD2KICAD { // will be replaced by pad in next version ???? -class PCB_VIA : public PCB_PAD +class PCAD_VIA : public PCAD_PAD { public: - PCB_VIA( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_VIA(); + PCAD_VIA( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_VIA(); virtual void Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ) override; @@ -47,4 +47,4 @@ public: } // namespace PCAD2KICAD -#endif // PCB_VIA_H_ +#endif // PCAD_VIA_H diff --git a/pcbnew/plugins/pcad/pcb_via_shape.cpp b/pcbnew/plugins/pcad/pcad_via_shape.cpp similarity index 86% rename from pcbnew/plugins/pcad/pcb_via_shape.cpp rename to pcbnew/plugins/pcad/pcad_via_shape.cpp index e2104e122e..498c540fe1 100644 --- a/pcbnew/plugins/pcad/pcb_via_shape.cpp +++ b/pcbnew/plugins/pcad/pcad_via_shape.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,7 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include @@ -32,18 +32,18 @@ namespace PCAD2KICAD { -PCB_VIA_SHAPE::PCB_VIA_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : - PCB_PAD_SHAPE( aCallbacks, aBoard ) +PCAD_VIA_SHAPE::PCAD_VIA_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : + PCAD_PAD_SHAPE( aCallbacks, aBoard ) { } -PCB_VIA_SHAPE::~PCB_VIA_SHAPE() +PCAD_VIA_SHAPE::~PCAD_VIA_SHAPE() { } -void PCB_VIA_SHAPE::Parse( XNODE* aNode, const wxString& aDefaultUnits, +void PCAD_VIA_SHAPE::Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ) { XNODE* lNode; diff --git a/pcbnew/plugins/pcad/pcb_via_shape.h b/pcbnew/plugins/pcad/pcad_via_shape.h similarity index 81% rename from pcbnew/plugins/pcad/pcb_via_shape.h rename to pcbnew/plugins/pcad/pcad_via_shape.h index c75e9087da..6b049c1132 100644 --- a/pcbnew/plugins/pcad/pcb_via_shape.h +++ b/pcbnew/plugins/pcad/pcad_via_shape.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,10 +23,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_VIA_SHAPE_H_ -#define PCB_VIA_SHAPE_H_ +#ifndef PCAD_VIA_SHAPE_H +#define PCAD_VIA_SHAPE_H -#include +#include class BOARD; class wxString; @@ -34,11 +34,11 @@ class XNODE; namespace PCAD2KICAD { -class PCB_VIA_SHAPE : public PCB_PAD_SHAPE +class PCAD_VIA_SHAPE : public PCAD_PAD_SHAPE { public: - PCB_VIA_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); - ~PCB_VIA_SHAPE(); + PCAD_VIA_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ); + ~PCAD_VIA_SHAPE(); virtual void Parse( XNODE* aNode, const wxString& aDefaultUnits, const wxString& aActualConversion ) override; @@ -46,4 +46,4 @@ public: } // namespace PCAD2KICAD -#endif // PCB_VIA_SHAPE_H_ +#endif // PCAD_VIA_SHAPE_H diff --git a/pcbnew/plugins/pcad/pcb_copper_pour.cpp b/pcbnew/plugins/pcad/pcb_copper_pour.cpp index 4075c03fbd..51dd58b68b 100644 --- a/pcbnew/plugins/pcad/pcb_copper_pour.cpp +++ b/pcbnew/plugins/pcad/pcb_copper_pour.cpp @@ -33,7 +33,7 @@ namespace PCAD2KICAD { PCB_COPPER_POUR::PCB_COPPER_POUR( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ) : - PCB_POLYGON( aCallbacks, aBoard, aPCadLayer ) + PCAD_POLYGON( aCallbacks, aBoard, aPCadLayer ) { m_filled = false; } diff --git a/pcbnew/plugins/pcad/pcb_copper_pour.h b/pcbnew/plugins/pcad/pcb_copper_pour.h index ab743cdd62..00ef4d4b7f 100644 --- a/pcbnew/plugins/pcad/pcb_copper_pour.h +++ b/pcbnew/plugins/pcad/pcb_copper_pour.h @@ -26,7 +26,7 @@ #ifndef PCB_COPPER_POUR_H_ #define PCB_COPPER_POUR_H_ -#include +#include class BOARD; class wxString; @@ -34,7 +34,7 @@ class XNODE; namespace PCAD2KICAD { -class PCB_COPPER_POUR : public PCB_POLYGON +class PCB_COPPER_POUR : public PCAD_POLYGON { public: PCB_COPPER_POUR( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ); diff --git a/pcbnew/plugins/pcad/pcb_cutout.cpp b/pcbnew/plugins/pcad/pcb_cutout.cpp index aa99ab2ee8..e5d64970b7 100644 --- a/pcbnew/plugins/pcad/pcb_cutout.cpp +++ b/pcbnew/plugins/pcad/pcb_cutout.cpp @@ -37,7 +37,7 @@ namespace PCAD2KICAD { PCB_CUTOUT::PCB_CUTOUT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ) : - PCB_POLYGON( aCallbacks, aBoard, aPCadLayer ) + PCAD_POLYGON( aCallbacks, aBoard, aPCadLayer ) { m_objType = wxT( 'C' ); } diff --git a/pcbnew/plugins/pcad/pcb_cutout.h b/pcbnew/plugins/pcad/pcb_cutout.h index 3e394b84c9..eb83114af2 100644 --- a/pcbnew/plugins/pcad/pcb_cutout.h +++ b/pcbnew/plugins/pcad/pcb_cutout.h @@ -26,7 +26,7 @@ #ifndef PCB_CUTOUT_H_ #define PCB_CUTOUT_H_ -#include +#include class BOARD; class wxString; @@ -34,7 +34,7 @@ class XNODE; namespace PCAD2KICAD { -class PCB_CUTOUT : public PCB_POLYGON +class PCB_CUTOUT : public PCAD_POLYGON { public: PCB_CUTOUT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ); diff --git a/pcbnew/plugins/pcad/pcb_keepout.cpp b/pcbnew/plugins/pcad/pcb_keepout.cpp index ee8426ad7f..21174a05a0 100644 --- a/pcbnew/plugins/pcad/pcb_keepout.cpp +++ b/pcbnew/plugins/pcad/pcb_keepout.cpp @@ -34,7 +34,7 @@ namespace PCAD2KICAD { PCB_KEEPOUT::PCB_KEEPOUT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ) : - PCB_POLYGON( aCallbacks, aBoard, aPCadLayer ) + PCAD_POLYGON( aCallbacks, aBoard, aPCadLayer ) { m_objType = wxT( 'K' ); } diff --git a/pcbnew/plugins/pcad/pcb_keepout.h b/pcbnew/plugins/pcad/pcb_keepout.h index 2456fee137..74e366b745 100644 --- a/pcbnew/plugins/pcad/pcb_keepout.h +++ b/pcbnew/plugins/pcad/pcb_keepout.h @@ -25,7 +25,7 @@ #ifndef PCB_KEEPOUT_H_ #define PCB_KEEPOUT_H_ -#include +#include class BOARD; class wxString; @@ -33,7 +33,7 @@ class XNODE; namespace PCAD2KICAD { -class PCB_KEEPOUT : public PCB_POLYGON +class PCB_KEEPOUT : public PCAD_POLYGON { public: PCB_KEEPOUT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ); diff --git a/pcbnew/plugins/pcad/pcb_plane.cpp b/pcbnew/plugins/pcad/pcb_plane.cpp index a22165f364..46442e24c6 100644 --- a/pcbnew/plugins/pcad/pcb_plane.cpp +++ b/pcbnew/plugins/pcad/pcb_plane.cpp @@ -34,7 +34,7 @@ namespace PCAD2KICAD { PCB_PLANE::PCB_PLANE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ) : - PCB_POLYGON( aCallbacks, aBoard, aPCadLayer ) + PCAD_POLYGON( aCallbacks, aBoard, aPCadLayer ) { m_priority = 1; } diff --git a/pcbnew/plugins/pcad/pcb_plane.h b/pcbnew/plugins/pcad/pcb_plane.h index 4b9d55a765..5acb8abb6f 100644 --- a/pcbnew/plugins/pcad/pcb_plane.h +++ b/pcbnew/plugins/pcad/pcb_plane.h @@ -25,7 +25,7 @@ #ifndef PCB_PLANE_H_ #define PCB_PLANE_H_ -#include +#include class BOARD; class wxString; @@ -33,7 +33,7 @@ class XNODE; namespace PCAD2KICAD { -class PCB_PLANE : public PCB_POLYGON +class PCB_PLANE : public PCAD_POLYGON { public: PCB_PLANE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ); diff --git a/pcbnew/python/swig/board.i b/pcbnew/python/swig/board.i index 7ef1f70a0f..c7bde9b983 100644 --- a/pcbnew/python/swig/board.i +++ b/pcbnew/python/swig/board.i @@ -58,8 +58,6 @@ HANDLE_EXCEPTIONS(BOARD::TracksInNetBetweenPoints) %include pcb_dimension.i %include pcb_marker.i %include pcb_target.i -%include fp_shape.i -%include fp_text.i %include netinfo.i %include netclass.i %include pcb_plot_params.i diff --git a/pcbnew/python/swig/board_item.i b/pcbnew/python/swig/board_item.i index 30d932cc64..1a731650af 100644 --- a/pcbnew/python/swig/board_item.i +++ b/pcbnew/python/swig/board_item.i @@ -55,18 +55,14 @@ class PCB_DIM_CENTER; class PCB_DIM_RADIAL; class FOOTPRINT; class PCB_GROUP; -class FP_TEXT; -class FP_TEXTBOX; class PCB_SHAPE; class MARKER_PCB; class BOARD; -class FP_SHAPE; class PAD; class PCB_TRACK; class PCB_VIA; class PCB_ARC; class ZONE; -class FP_ZONE; class PCB_TARGET; class PCB_BITMAP; @@ -85,18 +81,14 @@ static PCB_DIM_CENTER* Cast_to_PCB_DIM_CENTER( BOARD_ITEM* ); static PCB_DIM_RADIAL* Cast_to_PCB_DIM_RADIAL( BOARD_ITEM* ); static FOOTPRINT* Cast_to_FOOTPRINT( BOARD_ITEM* ); static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* ); -static FP_TEXT* Cast_to_FP_TEXT( BOARD_ITEM* ); -static FP_TEXTBOX* Cast_to_FP_TEXTBOX( BOARD_ITEM* ); static PCB_SHAPE* Cast_to_PCB_SHAPE( BOARD_ITEM* ); static PCB_MARKER* Cast_to_PCB_MARKER( BOARD_ITEM* ); static BOARD* Cast_to_BOARD( BOARD_ITEM* ); -static FP_SHAPE* Cast_to_FP_SHAPE( BOARD_ITEM* ); static PAD* Cast_to_PAD( BOARD_ITEM* ); static PCB_TRACK* Cast_to_PCB_TRACK( BOARD_ITEM* ); static PCB_VIA* Cast_to_PCB_VIA( BOARD_ITEM* ); static PCB_ARC* Cast_to_PCB_ARC( BOARD_ITEM* ); static ZONE* Cast_to_ZONE( BOARD_ITEM* ); -static FP_ZONE* Cast_to_FP_ZONE( BOARD_ITEM* ); static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* ); static PCB_BITMAP* Cast_to_PCB_BITMAP( BOARD_ITEM* ); @@ -115,18 +107,14 @@ static PCB_DIM_CENTER* Cast_to_PCB_DIM_CENTER( BOARD_ITEM* ); static PCB_DIM_RADIAL* Cast_to_PCB_DIM_RADIAL( BOARD_ITEM* ); static FOOTPRINT* Cast_to_FOOTPRINT( BOARD_ITEM* ); static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* ); -static FP_TEXT* Cast_to_FP_TEXT( BOARD_ITEM* ); -static FP_TEXTBOX* Cast_to_FP_TEXTBOX( BOARD_ITEM* ); static PCB_SHAPE* Cast_to_PCB_SHAPE( BOARD_ITEM* ); static PCB_MARKER* Cast_to_PCB_MARKER( BOARD_ITEM* ); static BOARD* Cast_to_BOARD( BOARD_ITEM* ); -static FP_SHAPE* Cast_to_FP_SHAPE( BOARD_ITEM* ); static PAD* Cast_to_PAD( BOARD_ITEM* ); static PCB_TRACK* Cast_to_PCB_TRACK( BOARD_ITEM* ); static PCB_VIA* Cast_to_PCB_VIA( BOARD_ITEM* ); static PCB_ARC* Cast_to_PCB_ARC( BOARD_ITEM* ); static ZONE* Cast_to_ZONE( BOARD_ITEM* ); -static FP_ZONE* Cast_to_FP_ZONE( BOARD_ITEM* ); static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* ); static PCB_BITMAP* Cast_to_PCB_BITMAP( BOARD_ITEM* ); @@ -157,18 +145,12 @@ static PCB_BITMAP* Cast_to_PCB_BITMAP( BOARD_ITEM* ); return Cast_to_PCB_DIM_ORTHOGONAL(self) elif ct=="PCB_SHAPE": return Cast_to_PCB_SHAPE(self) - elif ct=="MGRAPHIC": - return Cast_to_FP_SHAPE(self) elif ct=="FOOTPRINT": return Cast_to_FOOTPRINT(self) elif ct=="PCB_GROUP": return Cast_to_PCB_GROUP(self) elif ct=="PAD": return Cast_to_PAD(self) - elif ct=="FP_TEXT": - return Cast_to_FP_TEXT(self) - elif ct=="FP_TEXTBOX": - return Cast_to_FP_TEXTBOX(self) elif ct=="PCB_VIA": return Cast_to_PCB_VIA(self) elif ct=="PCB_TRACK": @@ -218,18 +200,14 @@ static PCB_DIM_CENTER* Cast_to_PCB_DIM_CENTER( BOARD_ITEM* self ) { static PCB_DIM_RADIAL* Cast_to_PCB_DIM_RADIAL( BOARD_ITEM* self ) { return dynamic_cast(self); } static FOOTPRINT* Cast_to_FOOTPRINT( BOARD_ITEM* self ) { return dynamic_cast(self); } static PCB_GROUP* Cast_to_PCB_GROUP( BOARD_ITEM* self ) { return dynamic_cast(self); } -static FP_TEXT* Cast_to_FP_TEXT( BOARD_ITEM* self ) { return dynamic_cast(self); } -static FP_TEXTBOX* Cast_to_FP_TEXTBOX( BOARD_ITEM* self ) { return dynamic_cast(self); } static PCB_SHAPE* Cast_to_PCB_SHAPE( BOARD_ITEM* self ) { return dynamic_cast(self); } static PCB_MARKER* Cast_to_PCB_MARKER( BOARD_ITEM* self ) { return dynamic_cast(self); } static BOARD* Cast_to_BOARD( BOARD_ITEM* self ) { return dynamic_cast(self); } -static FP_SHAPE* Cast_to_FP_SHAPE( BOARD_ITEM* self ) { return dynamic_cast(self); } static PAD* Cast_to_PAD( BOARD_ITEM* self ) { return dynamic_cast(self); } static PCB_TRACK* Cast_to_PCB_TRACK( BOARD_ITEM* self ) { return dynamic_cast(self); } static PCB_VIA* Cast_to_PCB_VIA( BOARD_ITEM* self ) { return dynamic_cast(self); } static PCB_ARC* Cast_to_PCB_ARC( BOARD_ITEM* self ) { return dynamic_cast(self); } static ZONE* Cast_to_ZONE( BOARD_ITEM* self ) { return dynamic_cast(self); } -static FP_ZONE* Cast_to_FP_ZONE( BOARD_ITEM* self ) { return dynamic_cast(self); } static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* self ) { return dynamic_cast(self); } static PCB_BITMAP* Cast_to_PCB_BITMAP( BOARD_ITEM* self ) { return dynamic_cast(self); } %} diff --git a/pcbnew/python/swig/fp_shape.i b/pcbnew/python/swig/fp_shape.i deleted file mode 100644 index 0bc3efbe88..0000000000 --- a/pcbnew/python/swig/fp_shape.i +++ /dev/null @@ -1,5 +0,0 @@ - -%include fp_shape.h -%{ -#include -%} diff --git a/pcbnew/python/swig/fp_text.i b/pcbnew/python/swig/fp_text.i deleted file mode 100644 index 5dbcd91cd6..0000000000 --- a/pcbnew/python/swig/fp_text.i +++ /dev/null @@ -1,8 +0,0 @@ - -%include fp_text.h -%include fp_textbox.h -%{ -#include -#include -%} - diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 7a740bc80b..5e86a3fc7f 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -220,12 +219,8 @@ bool PNS_PCBNEW_RULE_RESOLVER::IsDiffPair( const PNS::ITEM* aA, const PNS::ITEM* bool PNS_PCBNEW_RULE_RESOLVER::IsInNetTie( const PNS::ITEM* aA ) { BOARD_ITEM* item = aA->Parent(); - BOARD_ITEM* parentFootprint = item ? item->GetParentFootprint() : nullptr; - if( parentFootprint ) - return static_cast( parentFootprint )->IsNetTie(); - - return false; + return item && item->GetParentFootprint() && item->GetParentFootprint()->IsNetTie(); } @@ -238,10 +233,8 @@ bool PNS_PCBNEW_RULE_RESOLVER::IsNetTieExclusion( const PNS::ITEM* aItem, std::shared_ptr drcEngine = m_board->GetDesignSettings().m_DRCEngine; BOARD_ITEM* collidingItem = aCollidingItem->Parent(); - FOOTPRINT* collidingFp = static_cast( collidingItem->GetParentFootprint() ); - FOOTPRINT* itemFp = aItem->Parent() - ? static_cast( aItem->Parent()->GetParentFootprint() ) - : nullptr; + FOOTPRINT* collidingFp = collidingItem->GetParentFootprint(); + FOOTPRINT* itemFp = aItem->Parent() ? aItem->Parent()->GetParentFootprint() : nullptr; if( collidingFp && itemFp && ( collidingFp == itemFp ) && itemFp->IsNetTie() ) { @@ -1569,18 +1562,18 @@ void PNS_KICAD_IFACE_BASE::SyncWorld( PNS::NODE *aWorld ) syncTextItem( aWorld, &footprint->Reference(), footprint->Reference().GetLayer() ); syncTextItem( aWorld, &footprint->Value(), footprint->Value().GetLayer() ); - for( FP_ZONE* zone : footprint->Zones() ) + for( ZONE* zone : footprint->Zones() ) syncZone( aWorld, zone, boardOutline ); - for( BOARD_ITEM* mgitem : footprint->GraphicalItems() ) + for( BOARD_ITEM* item : footprint->GraphicalItems() ) { - if( mgitem->Type() == PCB_FP_SHAPE_T || mgitem->Type() == PCB_FP_TEXTBOX_T ) + if( item->Type() == PCB_SHAPE_T || item->Type() == PCB_TEXTBOX_T ) { - syncGraphicalItem( aWorld, static_cast( mgitem ) ); + syncGraphicalItem( aWorld, static_cast( item ) ); } - else if( mgitem->Type() == PCB_FP_TEXT_T ) + else if( item->Type() == PCB_TEXT_T ) { - syncTextItem( aWorld, static_cast( mgitem ), mgitem->GetLayer() ); + syncTextItem( aWorld, static_cast( item ), item->GetLayer() ); } } } @@ -1591,17 +1584,17 @@ void PNS_KICAD_IFACE_BASE::SyncWorld( PNS::NODE *aWorld ) if( type == PCB_TRACE_T ) { - if( auto segment = syncTrack( t ) ) + if( std::unique_ptr segment = syncTrack( t ) ) aWorld->Add( std::move( segment ) ); } else if( type == PCB_ARC_T ) { - if( auto arc = syncArc( static_cast( t ) ) ) + if( std::unique_ptr arc = syncArc( static_cast( t ) ) ) aWorld->Add( std::move( arc ) ); } else if( type == PCB_VIA_T ) { - if( auto via = syncVia( static_cast( t ) ) ) + if( std::unique_ptr via = syncVia( static_cast( t ) ) ) aWorld->Add( std::move( via ) ); } } diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index b358556bbf..3e97ad80f3 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -260,7 +260,6 @@ bool ROUTER::isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aStartItem, break; case PCB_ZONE_T: - case PCB_FP_ZONE_T: { ZONE* zone = static_cast( parent ); @@ -277,14 +276,11 @@ bool ROUTER::isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aStartItem, break; case PCB_TEXT_T: - case PCB_FP_TEXT_T: case PCB_TEXTBOX_T: - case PCB_FP_TEXTBOX_T: failureReason = _( "Cannot start routing from a text item." ); break; case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: failureReason = _( "Cannot start routing from a graphic." ); default: diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index d7f370856c..e59e700772 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -2,7 +2,7 @@ * KiRouter - a push-and-(sometimes-)shove PCB router * * Copyright (C) 2013-2017 CERN - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * * @author Tomasz Wlostowski * @@ -33,7 +33,6 @@ using namespace std::placeholders; #include #include #include -#include #include #include #include @@ -2211,24 +2210,12 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) VECTOR2I offset = m_endSnapPoint - p; BOARD_ITEM* previewItem; - VECTOR2I fp_offset( offset ); - RotatePoint( fp_offset, -footprint->GetOrientation() ); - view()->ClearPreview(); for( BOARD_ITEM* drawing : footprint->GraphicalItems() ) { previewItem = static_cast( drawing->Clone() ); - - if( drawing->Type() == PCB_FP_SHAPE_T ) - { - FP_SHAPE* shape = static_cast( previewItem ); - shape->FP_SHAPE::Move( fp_offset ); - } - else - { - previewItem->Move( offset ); - } + previewItem->Move( offset ); view()->AddToPreview( previewItem ); view()->Hide( drawing, true ); diff --git a/pcbnew/specctra_import_export/specctra_export.cpp b/pcbnew/specctra_import_export/specctra_export.cpp index d8469a2364..7e3d717015 100644 --- a/pcbnew/specctra_import_export/specctra_export.cpp +++ b/pcbnew/specctra_import_export/specctra_export.cpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include #include @@ -197,6 +197,14 @@ static POINT mapPt( const VECTOR2I& pt ) } +static POINT mapPt( const VECTOR2I& pt, FOOTPRINT* aFootprint ) +{ + VECTOR2I fpRelative = pt - aFootprint->GetPosition(); + RotatePoint( fpRelative, -aFootprint->GetOrientation() ); + return mapPt( fpRelative ); +} + + /** * Decide if the pad is a copper-less through hole which needs to be made into a round keepout. */ @@ -695,14 +703,14 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) } } - // get all the FOOTPRINT's FP_SHAPEs and convert those to DSN outlines. - fpItems.Collect( aFootprint, { PCB_FP_SHAPE_T } ); + // get all the FOOTPRINT's SHAPEs and convert those to DSN outlines. + fpItems.Collect( aFootprint, { PCB_SHAPE_T } ); for( int i = 0; i < fpItems.GetCount(); ++i ) { - FP_SHAPE* graphic = (FP_SHAPE*) fpItems[i]; - SHAPE* outline; - PATH* path; + PCB_SHAPE* graphic = static_cast( fpItems[i] ); + SHAPE* outline; + PATH* path; switch( graphic->GetShape() ) { @@ -715,8 +723,8 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) outline->SetShape( path ); path->SetAperture( scale( graphic->GetWidth() ) ); path->SetLayerId( "signal" ); - path->AppendPoint( mapPt( graphic->GetStart0() ) ); - path->AppendPoint( mapPt( graphic->GetEnd0() ) ); + path->AppendPoint( mapPt( graphic->GetStart(), aFootprint ) ); + path->AppendPoint( mapPt( graphic->GetEnd(), aFootprint ) ); break; case SHAPE_T::CIRCLE: @@ -733,7 +741,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) path->SetLayerId( "signal" ); double radius = graphic->GetRadius(); - VECTOR2I circle_centre = graphic->GetStart0(); + VECTOR2I circle_centre = graphic->GetStart(); SHAPE_LINE_CHAIN polyline; ConvertArcToPolyline( polyline, VECTOR2I( circle_centre ), radius, ANGLE_0, ANGLE_360, @@ -742,7 +750,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) for( int ii = 0; ii < polyline.PointCount(); ++ii ) { VECTOR2I corner( polyline.CPoint( ii ).x, polyline.CPoint( ii ).y ); - path->AppendPoint( mapPt( corner ) ); + path->AppendPoint( mapPt( corner, aFootprint ) ); } break; @@ -758,17 +766,17 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) outline->SetShape( path ); path->SetAperture( scale( graphic->GetWidth() ) ); path->SetLayerId( "signal" ); - VECTOR2I corner = graphic->GetStart0(); - path->AppendPoint( mapPt( corner ) ); + VECTOR2I corner = graphic->GetStart(); + path->AppendPoint( mapPt( corner, aFootprint ) ); - corner.x = graphic->GetEnd0().x; - path->AppendPoint( mapPt( corner ) ); + corner.x = graphic->GetEnd().x; + path->AppendPoint( mapPt( corner, aFootprint ) ); - corner.y = graphic->GetEnd0().y; - path->AppendPoint( mapPt( corner ) ); + corner.y = graphic->GetEnd().y; + path->AppendPoint( mapPt( corner, aFootprint ) ); - corner.x = graphic->GetStart0().x; - path->AppendPoint( mapPt( corner ) ); + corner.x = graphic->GetStart().x; + path->AppendPoint( mapPt( corner, aFootprint ) ); break; } @@ -786,7 +794,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) path->SetAperture( 0 );//scale( graphic->GetWidth() ) ); path->SetLayerId( "signal" ); - VECTOR2I arc_centre = graphic->GetCenter0(); + VECTOR2I arc_centre = graphic->GetCenter(); double radius = graphic->GetRadius() + graphic->GetWidth()/2; EDA_ANGLE arcAngle = graphic->GetArcAngle(); @@ -844,7 +852,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) for( int ii = 0; ii < poly.PointCount(); ++ii ) { VECTOR2I corner( poly.CPoint( ii ).x, poly.CPoint( ii ).y ); - path->AppendPoint( mapPt( corner ) ); + path->AppendPoint( mapPt( corner, aFootprint ) ); } break; @@ -855,7 +863,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, FOOTPRINT* aFootprint ) } } - for( FP_ZONE* zone : aFootprint->Zones() ) + for( ZONE* zone : aFootprint->Zones() ) { if( !zone->GetIsRuleArea() ) continue; diff --git a/pcbnew/tools/board_inspection_tool.cpp b/pcbnew/tools/board_inspection_tool.cpp index 9a5acfe845..6c59c91b36 100644 --- a/pcbnew/tools/board_inspection_tool.cpp +++ b/pcbnew/tools/board_inspection_tool.cpp @@ -1246,9 +1246,7 @@ int BOARD_INSPECTION_TOOL::InspectConstraints( const TOOL_EVENT& aEvent ) r->Flush(); } - if( item->Type() == PCB_TEXT_T - || item->Type() == PCB_TEXTBOX_T - || item->Type() == PCB_FP_TEXT_T ) + if( item->Type() == PCB_TEXT_T || item->Type() == PCB_TEXTBOX_T ) { r = dialog->AddHTMLPage( _( "Text Size" ) ); reportHeader( _( "Text height resolution for:" ), item, r ); @@ -1547,7 +1545,7 @@ int BOARD_INSPECTION_TOOL::HighlightItem( const TOOL_EVENT& aEvent ) guide ); if( collector.GetCount() == 0 ) - collector.Collect( board, { PCB_ZONE_T, PCB_FP_ZONE_T }, aPosition, guide ); + collector.Collect( board, { PCB_ZONE_T }, aPosition, guide ); // Apply the active selection filter, except we want to allow picking locked items for // highlighting even if the user has disabled them for selection diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index d793190b37..213b1781eb 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. * @author Jon Evans * * This program is free software; you can redistribute it and/or @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -244,8 +243,7 @@ bool CONVERT_TOOL::Init() auto anyTracks = S_C::MoreThan( 0 ) && S_C::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) && P_S_C::SameLayer(); - auto anyPolys = S_C::OnlyTypes( { PCB_ZONE_T, PCB_FP_ZONE_T, - PCB_SHAPE_LOCATE_POLY_T, PCB_SHAPE_LOCATE_RECT_T } ); + auto anyPolys = S_C::OnlyTypes( { PCB_ZONE_T, PCB_SHAPE_LOCATE_POLY_T, PCB_SHAPE_LOCATE_RECT_T } ); auto canCreateArcs = S_C::Count( 1 ) && S_C::OnlyTypes( { PCB_TRACE_T, PCB_SHAPE_LOCATE_SEGMENT_T } ); @@ -340,17 +338,8 @@ int CONVERT_TOOL::CreatePolys( const TOOL_EVENT& aEvent ) if( !getPolys( preflightSettings ) ) return 0; - bool isFootprint = m_frame->IsType( FRAME_FOOTPRINT_EDITOR ); - - if( isFootprint ) - { - if( FP_SHAPE* graphic = dynamic_cast( selection.Front() ) ) - parentFootprint = graphic->GetParentFootprint(); - else if( FP_ZONE* zone = dynamic_cast( selection.Front() ) ) - parentFootprint = static_cast( zone->GetParent() ); - else - wxFAIL_MSG( wxT( "Unimplemented footprint parent in CONVERT_TOOL::CreatePolys" ) ); - } + if( BOARD_ITEM* item = dynamic_cast( selection.Front() ) ) + parentFootprint = item->GetParentFootprint(); BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings(); PCB_LAYER_ID layer = m_frame->GetActiveLayer(); @@ -379,7 +368,7 @@ int CONVERT_TOOL::CreatePolys( const TOOL_EVENT& aEvent ) for( const SHAPE_POLY_SET& poly : polys ) { - PCB_SHAPE* graphic = isFootprint ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE; + PCB_SHAPE* graphic = new PCB_SHAPE( parentFootprint ); if( resolvedSettings.m_Strategy == COPY_LINEWIDTH ) { @@ -457,7 +446,7 @@ int CONVERT_TOOL::CreatePolys( const TOOL_EVENT& aEvent ) for( const SHAPE_POLY_SET& poly : polys ) { - ZONE* zone = isFootprint ? new FP_ZONE( parent ) : new ZONE( parent ); + ZONE* zone = new ZONE( parent ); *zone->Outline() = poly; zone->HatchBorder(); @@ -555,7 +544,7 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromChainedSegs( const std::dequeType() == PCB_ARC_T - || ( ( aItem->Type() == PCB_SHAPE_T || aItem->Type() == PCB_FP_SHAPE_T ) + || ( aItem->Type() == PCB_SHAPE_T && static_cast( aItem )->GetShape() == SHAPE_T::ARC ) ) { SHAPE_ARC arc; @@ -657,7 +646,7 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromChainedSegs( const std::dequeType() == PCB_ARC_T - || ( ( candidate->Type() == PCB_SHAPE_T || candidate->Type() == PCB_FP_SHAPE_T ) + || ( candidate->Type() == PCB_SHAPE_T && static_cast( candidate )->GetShape() == SHAPE_T::ARC ) ) ) { insert( candidate, anchors->A, true ); @@ -723,7 +712,6 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromOpenGraphics( const std::dequeType() ) { case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: { PCB_SHAPE* shape = static_cast( item ); @@ -773,7 +761,6 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromClosedGraphics( const std::dequeType() ) { case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: { PCB_SHAPE* shape = static_cast( item ); FILL_T wasFilled = shape->GetFillMode(); @@ -791,7 +778,6 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromClosedGraphics( const std::deque( item )->Outline() ); item->SetFlags( SKIP_STRUCT ); break; @@ -817,7 +803,6 @@ int CONVERT_TOOL::CreateLines( const TOOL_EVENT& aEvent ) switch( item->Type() ) { case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: switch( static_cast( item )->GetShape() ) { case SHAPE_T::SEGMENT: @@ -833,7 +818,6 @@ int CONVERT_TOOL::CreateLines( const TOOL_EVENT& aEvent ) break; case PCB_ZONE_T: - case PCB_FP_ZONE_T: break; default: @@ -853,12 +837,10 @@ int CONVERT_TOOL::CreateLines( const TOOL_EVENT& aEvent ) switch( aItem->Type() ) { case PCB_ZONE_T: - case PCB_FP_ZONE_T: set = *static_cast( aItem )->Outline(); break; case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: { PCB_SHAPE* graphic = static_cast( aItem ); @@ -925,7 +907,7 @@ int CONVERT_TOOL::CreateLines( const TOOL_EVENT& aEvent ) auto handleGraphicSeg = [&]( EDA_ITEM* aItem ) { - if( aItem->Type() != PCB_SHAPE_T && aItem->Type() != PCB_FP_SHAPE_T ) + if( aItem->Type() != PCB_SHAPE_T ) return false; PCB_SHAPE* graphic = static_cast( aItem ); @@ -982,26 +964,12 @@ int CONVERT_TOOL::CreateLines( const TOOL_EVENT& aEvent ) { for( SEG& seg : segs ) { - if( fpEditor ) - { - FP_SHAPE* graphic = new FP_SHAPE( footprint, SHAPE_T::SEGMENT ); + PCB_SHAPE* graphic = new PCB_SHAPE( footprint, SHAPE_T::SEGMENT ); - graphic->SetLayer( targetLayer ); - graphic->SetStart( VECTOR2I( seg.A ) ); - graphic->SetStart0( VECTOR2I( seg.A ) ); - graphic->SetEnd( VECTOR2I( seg.B ) ); - graphic->SetEnd0( VECTOR2I( seg.B ) ); - commit.Add( graphic ); - } - else - { - PCB_SHAPE* graphic = new PCB_SHAPE( nullptr, SHAPE_T::SEGMENT ); - - graphic->SetLayer( targetLayer ); - graphic->SetStart( VECTOR2I( seg.A ) ); - graphic->SetEnd( VECTOR2I( seg.B ) ); - commit.Add( graphic ); - } + graphic->SetLayer( targetLayer ); + graphic->SetStart( VECTOR2I( seg.A ) ); + graphic->SetEnd( VECTOR2I( seg.B ) ); + commit.Add( graphic ); } } else @@ -1013,12 +981,10 @@ int CONVERT_TOOL::CreateLines( const TOOL_EVENT& aEvent ) // Creating segments on copper layer for( SEG& seg : segs ) { - FP_SHAPE* graphic = new FP_SHAPE( footprint, SHAPE_T::SEGMENT ); + PCB_SHAPE* graphic = new PCB_SHAPE( footprint, SHAPE_T::SEGMENT ); graphic->SetLayer( targetLayer ); graphic->SetStart( VECTOR2I( seg.A ) ); - graphic->SetStart0( VECTOR2I( seg.A ) ); graphic->SetEnd( VECTOR2I( seg.B ) ); - graphic->SetEnd0( VECTOR2I( seg.B ) ); commit.Add( graphic ); } } @@ -1054,8 +1020,7 @@ int CONVERT_TOOL::SegmentToArc( const TOOL_EVENT& aEvent ) BOARD_ITEM* item = aCollector[i]; if( !( item->Type() == PCB_SHAPE_T || - item->Type() == PCB_TRACE_T || - item->Type() == PCB_FP_SHAPE_T ) ) + item->Type() == PCB_TRACE_T ) ) { aCollector.Remove( item ); } @@ -1094,7 +1059,7 @@ int CONVERT_TOOL::SegmentToArc( const TOOL_EVENT& aEvent ) BOARD_COMMIT commit( m_frame ); - if( source->Type() == PCB_SHAPE_T || source->Type() == PCB_FP_SHAPE_T ) + if( source->Type() == PCB_SHAPE_T ) { PCB_SHAPE* line = static_cast( source ); PCB_SHAPE* arc = new PCB_SHAPE( parent, SHAPE_T::ARC ); @@ -1137,7 +1102,6 @@ std::optional CONVERT_TOOL::getStartEndPoints( EDA_ITEM* aItem ) switch( aItem->Type() ) { case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: { PCB_SHAPE* shape = static_cast( aItem ); diff --git a/pcbnew/tools/drawing_stackup_table_tool.cpp b/pcbnew/tools/drawing_stackup_table_tool.cpp index d8681e8661..f600ba009a 100644 --- a/pcbnew/tools/drawing_stackup_table_tool.cpp +++ b/pcbnew/tools/drawing_stackup_table_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2017 CERN - * Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index f393cd51d3..bb79c1d5b1 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -57,8 +57,6 @@ #include #include #include -#include -#include #include #include #include @@ -70,7 +68,6 @@ #include #include #include -#include #include #include @@ -294,7 +291,7 @@ void DRAWING_TOOL::UpdateStatusBar() const else constrained = mgr.GetAppSettings()->m_Use45Limit; - m_frame->DisplayConstraintsMsg( constrained ? _( "Constrain to H, V, 45" ) : wxString( wxT( "" ) ) ); + m_frame->DisplayConstraintsMsg( constrained ? _( "Constrain to H, V, 45" ) : wxString( "" ) ); } } @@ -309,11 +306,11 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) REENTRANCY_GUARD guard( &m_inDrawingTool ); - FOOTPRINT* parentFootprint = dynamic_cast( m_frame->GetModel() ); - PCB_SHAPE* line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE; - BOARD_COMMIT commit( m_frame ); - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE ); - std::optional startingPoint; + BOARD_ITEM* parent = m_frame->GetModel(); + PCB_SHAPE* line = new PCB_SHAPE( parent ); + BOARD_COMMIT commit( m_frame ); + SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE ); + std::optional startingPoint; line->SetShape( SHAPE_T::SEGMENT ); line->SetFlags( IS_NEW ); @@ -328,9 +325,6 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) { if( line ) { - if( m_isFootprintEditor ) - static_cast( line )->SetLocalCoord(); - commit.Add( line ); commit.Push( _( "Draw a line segment" ) ); startingPoint = VECTOR2D( line->GetEnd() ); @@ -340,7 +334,7 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) startingPoint = std::nullopt; } - line = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE; + line = new PCB_SHAPE( parent ); line->SetShape( SHAPE_T::SEGMENT ); line->SetFlags( IS_NEW ); } @@ -359,34 +353,14 @@ int DRAWING_TOOL::DrawRectangle( const TOOL_EVENT& aEvent ) REENTRANCY_GUARD guard( &m_inDrawingTool ); - bool isTextBox = aEvent.IsAction( &PCB_ACTIONS::drawTextBox ); - PCB_SHAPE* rect = nullptr; - BOARD_COMMIT commit( m_frame ); - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RECTANGLE ); - std::optional startingPoint; + bool isTextBox = aEvent.IsAction( &PCB_ACTIONS::drawTextBox ); + PCB_SHAPE* rect = nullptr; + BOARD_COMMIT commit( m_frame ); + BOARD_ITEM* parent = m_frame->GetModel(); + SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RECTANGLE ); + std::optional startingPoint; - auto makeNew = - [&]() -> PCB_SHAPE* - { - if( m_isFootprintEditor ) - { - FOOTPRINT* parentFootprint = dynamic_cast( m_frame->GetModel() ); - - if( isTextBox ) - return new FP_TEXTBOX( parentFootprint ); - else - return new FP_SHAPE( parentFootprint ); - } - else - { - if( isTextBox ) - return new PCB_TEXTBOX( m_frame->GetModel() ); - else - return new PCB_SHAPE(); - } - }; - - rect = makeNew(); + rect = isTextBox ? new PCB_TEXTBOX( parent ) : new PCB_SHAPE( parent ); rect->SetShape( SHAPE_T::RECT ); rect->SetFilled( false ); rect->SetFlags( IS_NEW ); @@ -401,10 +375,12 @@ int DRAWING_TOOL::DrawRectangle( const TOOL_EVENT& aEvent ) { if( rect ) { - if( m_isFootprintEditor ) - static_cast( rect )->SetLocalCoord(); + bool cancelled = false; - if( isTextBox && m_frame->ShowTextBoxPropertiesDialog( rect ) != wxID_OK ) + if( PCB_TEXTBOX* textbox = dynamic_cast( rect ) ) + cancelled = m_frame->ShowTextBoxPropertiesDialog( textbox ) != wxID_OK; + + if( cancelled ) { delete rect; rect = nullptr; @@ -419,7 +395,7 @@ int DRAWING_TOOL::DrawRectangle( const TOOL_EVENT& aEvent ) } } - rect = makeNew(); + rect = isTextBox ? new PCB_TEXTBOX( parent ) : new PCB_SHAPE( parent ); rect->SetShape( SHAPE_T::RECT ); rect->SetFilled( false ); rect->SetFlags( IS_NEW ); @@ -440,11 +416,11 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) REENTRANCY_GUARD guard( &m_inDrawingTool ); - FOOTPRINT* parentFootprint = dynamic_cast( m_frame->GetModel() ); - PCB_SHAPE* circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE; - BOARD_COMMIT commit( m_frame ); - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE ); - std::optional startingPoint; + BOARD_ITEM* parent = m_frame->GetModel(); + PCB_SHAPE* circle = new PCB_SHAPE( parent ); + BOARD_COMMIT commit( m_frame ); + SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE ); + std::optional startingPoint; circle->SetShape( SHAPE_T::CIRCLE ); circle->SetFilled( false ); @@ -460,16 +436,13 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) { if( circle ) { - if( m_isFootprintEditor ) - static_cast( circle )->SetLocalCoord(); - commit.Add( circle ); commit.Push( _( "Draw a circle" ) ); m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, circle ); } - circle = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE; + circle = new PCB_SHAPE( parent ); circle->SetShape( SHAPE_T::CIRCLE ); circle->SetFilled( false ); circle->SetFlags( IS_NEW ); @@ -491,11 +464,11 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) REENTRANCY_GUARD guard( &m_inDrawingTool ); - FOOTPRINT* parentFootprint = dynamic_cast( m_frame->GetModel() ); - PCB_SHAPE* arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE; - BOARD_COMMIT commit( m_frame ); - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC ); - std::optional startingPoint; + BOARD_ITEM* parent = m_frame->GetModel(); + PCB_SHAPE* arc = new PCB_SHAPE( parent ); + BOARD_COMMIT commit( m_frame ); + SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC ); + std::optional startingPoint; arc->SetShape( SHAPE_T::ARC ); arc->SetFlags( IS_NEW ); @@ -510,16 +483,13 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) { if( arc ) { - if( m_isFootprintEditor ) - static_cast( arc )->SetLocalCoord(); - commit.Add( arc ); commit.Push( _( "Draw an arc" ) ); m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, arc ); } - arc = m_isFootprintEditor ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE; + arc = new PCB_SHAPE( parent ); arc->SetShape( SHAPE_T::ARC ); arc->SetFlags( IS_NEW ); @@ -782,7 +752,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) REENTRANCY_GUARD guard( &m_inDrawingTool ); COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings(); - BOARD_ITEM* text = nullptr; + PCB_TEXT* text = nullptr; bool ignorePrimePosition = false; const BOARD_DESIGN_SETTINGS& bds = m_frame->GetDesignSettings(); BOARD_COMMIT commit( m_frame ); @@ -901,52 +871,36 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) // Init the new item attributes if( m_isFootprintEditor ) { - FP_TEXT* fpText = new FP_TEXT( (FOOTPRINT*) m_frame->GetModel() ); - - fpText->SetLayer( layer ); - fpText->SetAttributes( textAttrs ); - fpText->SetTextPos( cursorPos ); - - text = fpText; - - DIALOG_TEXT_PROPERTIES textDialog( m_frame, fpText ); - bool cancelled; - - RunMainStack( [&]() - { - cancelled = !textDialog.ShowModal(); - } ); - - if( cancelled || NoPrintableChars( fpText->GetText() ) ) - { - delete text; - text = nullptr; - } - else if( fpText->GetTextPos() != cursorPos ) - { - // If the user modified the location then go ahead and place it there. - // Otherwise we'll drag. - placing = true; - } + text = new PCB_TEXT( static_cast( m_frame->GetModel() ), + PCB_TEXT::TEXT_is_DIVERS ); } else { - PCB_TEXT* pcbText = new PCB_TEXT( m_frame->GetModel() ); - pcbText->SetFlags( IS_NEW ); + text = new PCB_TEXT( m_frame->GetModel() ); + } - pcbText->SetLayer( layer ); - pcbText->SetAttributes( textAttrs ); - pcbText->SetTextPos( cursorPos ); + text->SetLayer( layer ); + text->SetAttributes( textAttrs ); + text->SetTextPos( cursorPos ); - RunMainStack( [&]() - { - m_frame->ShowTextPropertiesDialog( pcbText ); - } ); + DIALOG_TEXT_PROPERTIES textDialog( m_frame, text ); + bool cancelled; - if( NoPrintableChars( pcbText->GetText() ) ) - delete pcbText; - else - text = pcbText; + RunMainStack( [&]() + { + cancelled = !textDialog.ShowModal(); + } ); + + if( cancelled || NoPrintableChars( text->GetText() ) ) + { + delete text; + text = nullptr; + } + else if( text->GetTextPos() != cursorPos ) + { + // If the user modified the location then go ahead and place it there. + // Otherwise we'll drag. + placing = true; } if( text ) @@ -1128,7 +1082,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() ); - if( step == SET_HEIGHT && t != PCB_DIM_ORTHOGONAL_T && t != PCB_FP_DIM_ORTHOGONAL_T ) + if( step == SET_HEIGHT && t != PCB_DIM_ORTHOGONAL_T ) { if( dimension->GetStart().x != dimension->GetEnd().x && dimension->GetStart().y != dimension->GetEnd().y ) @@ -1222,28 +1176,26 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) if( originalEvent.IsAction( &PCB_ACTIONS::drawAlignedDimension ) ) { - dimension = new PCB_DIM_ALIGNED( m_frame->GetModel(), - m_isFootprintEditor ? PCB_FP_DIM_ALIGNED_T - : PCB_DIM_ALIGNED_T ); + dimension = new PCB_DIM_ALIGNED( m_frame->GetModel() ); setMeasurementAttributes( dimension ); } else if( originalEvent.IsAction( &PCB_ACTIONS::drawOrthogonalDimension ) ) { - dimension = new PCB_DIM_ORTHOGONAL( m_frame->GetModel(), m_isFootprintEditor ); + dimension = new PCB_DIM_ORTHOGONAL( m_frame->GetModel() ); setMeasurementAttributes( dimension ); } else if( originalEvent.IsAction( &PCB_ACTIONS::drawCenterDimension ) ) { - dimension = new PCB_DIM_CENTER( m_frame->GetModel(), m_isFootprintEditor ); + dimension = new PCB_DIM_CENTER( m_frame->GetModel() ); } else if( originalEvent.IsAction( &PCB_ACTIONS::drawRadialDimension ) ) { - dimension = new PCB_DIM_RADIAL( m_frame->GetModel(), m_isFootprintEditor ); + dimension = new PCB_DIM_RADIAL( m_frame->GetModel() ); setMeasurementAttributes( dimension ); } else if( originalEvent.IsAction( &PCB_ACTIONS::drawLeader ) ) { - dimension = new PCB_DIM_LEADER( m_frame->GetModel(), m_isFootprintEditor ); + dimension = new PCB_DIM_LEADER( m_frame->GetModel() ); dimension->SetTextPos( cursorPos ); } else @@ -1286,8 +1238,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) break; } - if( t == PCB_DIM_CENTER_T || t == PCB_DIM_RADIAL_T || t == PCB_DIM_LEADER_T - || t == PCB_FP_DIM_CENTER_T || t == PCB_FP_DIM_RADIAL_T || t == PCB_FP_DIM_LEADER_T ) + if( t == PCB_DIM_CENTER_T || t == PCB_DIM_RADIAL_T || t == PCB_DIM_LEADER_T ) { // No separate height step ++step; @@ -1307,7 +1258,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) commit.Add( dimension ); commit.Push( _( "Draw a dimension" ) ); - if( t == PCB_DIM_LEADER_T || t == PCB_FP_DIM_LEADER_T ) + if( t == PCB_DIM_LEADER_T ) { // Run the edit immediately to set the leader text m_toolMgr->RunAction( PCB_ACTIONS::properties, true, dimension ); @@ -1337,10 +1288,10 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) case SET_END: dimension->SetEnd( cursorPos ); - if( Is45Limited() || t == PCB_DIM_CENTER_T || t == PCB_FP_DIM_CENTER_T ) + if( Is45Limited() || t == PCB_DIM_CENTER_T ) constrainDimension( dimension ); - if( t == PCB_DIM_ORTHOGONAL_T || t == PCB_FP_DIM_ORTHOGONAL_T ) + if( t == PCB_DIM_ORTHOGONAL_T ) { PCB_DIM_ORTHOGONAL* ortho = static_cast( dimension ); @@ -1353,7 +1304,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) ortho->SetOrientation( vert ? PCB_DIM_ORTHOGONAL::DIR::VERTICAL : PCB_DIM_ORTHOGONAL::DIR::HORIZONTAL ); } - else if( t == PCB_DIM_RADIAL_T || t == PCB_FP_DIM_RADIAL_T ) + else if( t == PCB_DIM_RADIAL_T ) { PCB_DIM_RADIAL* radialDim = static_cast( dimension ); VECTOR2I textOffset( radialDim->GetArrowLength() * 10, 0 ); @@ -1363,7 +1314,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) radialDim->SetTextPos( radialDim->GetKnee() + textOffset ); } - else if( t == PCB_DIM_LEADER_T || t == PCB_FP_DIM_LEADER_T ) + else if( t == PCB_DIM_LEADER_T ) { VECTOR2I textOffset( dimension->GetArrowLength() * 10, 0 ); @@ -1377,7 +1328,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) break; case SET_HEIGHT: - if( t == PCB_DIM_ALIGNED_T || t == PCB_FP_DIM_ALIGNED_T ) + if( t == PCB_DIM_ALIGNED_T ) { PCB_DIM_ALIGNED* aligned = static_cast( dimension ); @@ -1389,7 +1340,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) aligned->SetHeight( height ); aligned->Update(); } - else if( t == PCB_DIM_ORTHOGONAL_T || t == PCB_FP_DIM_ORTHOGONAL_T ) + else if( t == PCB_DIM_ORTHOGONAL_T ) { PCB_DIM_ORTHOGONAL* ortho = static_cast( dimension ); @@ -1546,11 +1497,6 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) { BOARD_ITEM* item = static_cast( ptr.get() ); - if( m_isFootprintEditor ) - wxASSERT( item->Type() == PCB_FP_SHAPE_T || item->Type() == PCB_FP_TEXT_T ); - else - wxASSERT( item->Type() == PCB_SHAPE_T || item->Type() == PCB_TEXT_T ); - newItems.push_back( item ); if( group ) @@ -1952,9 +1898,7 @@ bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, graphic->SetLayer( m_layer ); graphic->SetStroke( m_stroke ); - if( FP_TEXTBOX* fp_textbox = dynamic_cast( graphic ) ) - fp_textbox->SetAttributes( m_textAttrs ); - else if( PCB_TEXTBOX* pcb_textbox = dynamic_cast( graphic ) ) + if( PCB_TEXTBOX* pcb_textbox = dynamic_cast( graphic ) ) pcb_textbox->SetAttributes( m_textAttrs ); m_view->Update( &preview ); @@ -1993,9 +1937,7 @@ bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, graphic->SetLayer( m_layer ); } - if( FP_TEXTBOX* fp_textbox = dynamic_cast( graphic ) ) - fp_textbox->SetAttributes( m_textAttrs ); - else if( PCB_TEXTBOX* pcb_textbox = dynamic_cast( graphic ) ) + if( PCB_TEXTBOX* pcb_textbox = dynamic_cast( graphic ) ) pcb_textbox->SetAttributes( m_textAttrs ); grid.SetSkipPoint( cursorPos ); @@ -2905,8 +2847,7 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) if( !item ) continue; - if( ( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) - && !static_cast( item )->GetIsRuleArea() ) + if( item->Type() == PCB_ZONE_T && !static_cast( item )->GetIsRuleArea() ) { continue; // stitching vias bind to zones, so ignore them } @@ -2914,8 +2855,7 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) { continue; // check against children, but not against footprint itself } - else if( item->Type() == PCB_FP_TEXT_T - && !static_cast( item )->IsVisible() ) + else if( item->Type() == PCB_TEXT_T && !static_cast( item )->IsVisible() ) { continue; // ignore hidden items } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index bb01cd8799..f3ef8c3c85 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2017 CERN - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * @author Tomasz Wlostowski * @@ -29,8 +29,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -1114,12 +1113,7 @@ int EDIT_TOOL::FilletLines( const TOOL_EVENT& aEvent ) for( size_t jj = 1; jj < pts.size(); ++jj ) { - PCB_SHAPE *line; - - if( m_isFootprintEditor ) - line = new FP_SHAPE( static_cast( frame()->GetModel() ), SHAPE_T::SEGMENT ); - else - line = new PCB_SHAPE( frame()->GetModel(), SHAPE_T::SEGMENT ); + PCB_SHAPE *line = new PCB_SHAPE( frame()->GetModel(), SHAPE_T::SEGMENT ); line->SetStart( pts[jj - 1] ); line->SetEnd( pts[jj] ); @@ -1130,12 +1124,7 @@ int EDIT_TOOL::FilletLines( const TOOL_EVENT& aEvent ) if( pts.size() > 1 ) { - PCB_SHAPE *line; - - if( m_isFootprintEditor ) - line = new FP_SHAPE( static_cast( frame()->GetModel() ), SHAPE_T::SEGMENT ); - else - line = new PCB_SHAPE( frame()->GetModel(), SHAPE_T::SEGMENT ); + PCB_SHAPE *line = new PCB_SHAPE( frame()->GetModel(), SHAPE_T::SEGMENT ); line->SetStart( pts.back() ); line->SetEnd( pts.front() ); @@ -1251,12 +1240,7 @@ int EDIT_TOOL::FilletLines( const TOOL_EVENT& aEvent ) return; } - PCB_SHAPE* tArc; - - if( m_isFootprintEditor ) - tArc = new FP_SHAPE( static_cast( frame()->GetModel() ), SHAPE_T::ARC ); - else - tArc = new PCB_SHAPE( frame()->GetBoard(), SHAPE_T::ARC ); + PCB_SHAPE* tArc = new PCB_SHAPE( frame()->GetBoard(), SHAPE_T::ARC ); tArc->SetArcGeometry( sArc.GetP0(), sArc.GetArcMid(), sArc.GetP1() ); tArc->SetWidth( line_a->GetWidth() ); @@ -1291,13 +1275,6 @@ int EDIT_TOOL::FilletLines( const TOOL_EVENT& aEvent ) line_b->SetStart( seg_b.A ); line_b->SetEnd( seg_b.B ); - if( m_isFootprintEditor ) - { - static_cast( line_a )->SetLocalCoord(); - static_cast( line_b )->SetLocalCoord(); - static_cast( tArc )->SetLocalCoord(); - } - operationPerformedOnAtLeastOne = true; } ); @@ -1600,13 +1577,9 @@ static void mirrorPadY( PAD& aPad, const VECTOR2I& aMirrorPoint ) const std::vector EDIT_TOOL::MirrorableItems = { - PCB_FP_SHAPE_T, PCB_SHAPE_T, - PCB_FP_TEXT_T, PCB_TEXT_T, - PCB_FP_TEXTBOX_T, PCB_TEXTBOX_T, - PCB_FP_ZONE_T, PCB_ZONE_T, PCB_PAD_T, PCB_TRACE_T, @@ -1664,28 +1637,18 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) // modify each object as necessary switch( item->Type() ) { - case PCB_FP_SHAPE_T: case PCB_SHAPE_T: static_cast( item )->Mirror( mirrorPoint, mirrorAroundXaxis ); break; - case PCB_FP_ZONE_T: case PCB_ZONE_T: - static_cast( item )->Mirror( mirrorPoint, mirrorLeftRight ); - break; - - case PCB_FP_TEXT_T: - static_cast( item )->Mirror( mirrorPoint, mirrorAroundXaxis ); + static_cast( item )->Mirror( mirrorPoint, mirrorLeftRight ); break; case PCB_TEXT_T: static_cast( item )->Mirror( mirrorPoint, mirrorAroundXaxis ); break; - case PCB_FP_TEXTBOX_T: - static_cast( item )->Mirror( mirrorPoint, mirrorAroundXaxis ); - break; - case PCB_TEXTBOX_T: static_cast( item )->Mirror( mirrorPoint, mirrorAroundXaxis ); break; @@ -1818,33 +1781,31 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut ) for( EDA_ITEM* item : aItems ) { - PCB_GROUP* parentGroup = static_cast( item )->GetParentGroup(); + BOARD_ITEM* board_item = static_cast( item ); + FOOTPRINT* parentFP = board_item->GetParentFootprint(); + PCB_GROUP* parentGroup = board_item->GetParentGroup(); if( parentGroup ) { m_commit->Modify( parentGroup ); - parentGroup->RemoveItem( static_cast( item ) ); + parentGroup->RemoveItem( board_item ); } switch( item->Type() ) { - case PCB_FP_TEXT_T: - { - FP_TEXT* text = static_cast( item ); - FOOTPRINT* parent = static_cast( item->GetParent() ); - - switch( text->GetType() ) + case PCB_TEXT_T: + switch( static_cast( board_item )->GetType() ) { - case FP_TEXT::TEXT_is_VALUE: - case FP_TEXT::TEXT_is_REFERENCE: - m_commit->Modify( parent ); - text->SetVisible( false ); - getView()->Update( text ); + case PCB_TEXT::TEXT_is_VALUE: + case PCB_TEXT::TEXT_is_REFERENCE: + m_commit->Modify( parentFP ); + static_cast( board_item )->SetVisible( false ); + getView()->Update( board_item ); break; - case FP_TEXT::TEXT_is_DIVERS: - m_commit->Modify( parent ); - getView()->Remove( text ); - parent->Remove( text ); + case PCB_TEXT::TEXT_is_DIVERS: + m_commit->Modify( parentFP ); + getView()->Remove( board_item ); + parentFP->Remove( board_item ); break; default: wxFAIL; // Shouldn't get here @@ -1852,98 +1813,81 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut ) } break; - } - - case PCB_FP_TEXTBOX_T: - { - FP_TEXTBOX* textbox = static_cast( item ); - FOOTPRINT* parent = static_cast( item->GetParent() ); - - m_commit->Modify( parent ); - getView()->Remove( textbox ); - parent->Remove( textbox ); - break; - } + case PCB_SHAPE_T: + case PCB_TEXTBOX_T: case PCB_BITMAP_T: if( IsFootprintEditor() ) { - PCB_BITMAP* fp_bitmap = static_cast( item ); - FOOTPRINT* parent = static_cast( item->GetParent() ); - - m_commit->Modify( parent ); - getView()->Remove( fp_bitmap ); - parent->Remove( fp_bitmap ); + m_commit->Modify( parentFP ); + getView()->Remove( board_item ); + parentFP->Remove( board_item ); } else - m_commit->Remove( item ); + { + m_commit->Remove( board_item ); + } break; case PCB_PAD_T: if( IsFootprintEditor() || frame()->GetPcbNewSettings()->m_AllowFreePads ) { - PAD* pad = static_cast( item ); - FOOTPRINT* parent = static_cast( item->GetParent() ); - - m_commit->Modify( parent ); - getView()->Remove( pad ); - parent->Remove( pad ); + m_commit->Modify( parentFP ); + getView()->Remove( board_item ); + parentFP->Remove( board_item ); } break; - case PCB_FP_ZONE_T: - { - FP_ZONE* zone = static_cast( item ); - FOOTPRINT* parent = static_cast( item->GetParent() ); - - m_commit->Modify( parent ); - getView()->Remove( zone ); - parent->Remove( zone ); - break; - } - case PCB_ZONE_T: - // We process the zones special so that cutouts can be deleted when the delete tool - // is called from inside a cutout when the zone is selected. - { - // Only interact with cutouts when deleting and a single item is selected - if( !aIsCut && aItems.GetSize() == 1 ) + if( IsFootprintEditor() ) { - VECTOR2I curPos = getViewControls()->GetCursorPosition(); - ZONE* zone = static_cast( item ); - - int outlineIdx, holeIdx; - - if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) ) + m_commit->Modify( parentFP ); + getView()->Remove( board_item ); + parentFP->Remove( board_item ); + } + else + { + // We process the zones special so that cutouts can be deleted when the delete + // tool is called from inside a cutout when the zone is selected. + // Only interact with cutouts when deleting and a single item is selected + if( !aIsCut && aItems.GetSize() == 1 ) { - // Remove the cutout - m_commit->Modify( zone ); - zone->RemoveCutout( outlineIdx, holeIdx ); - zone->UnFill(); + VECTOR2I curPos = getViewControls()->GetCursorPosition(); + ZONE* zone = static_cast( board_item ); - // TODO Refill zone when KiCad supports auto re-fill + int outlineIdx, holeIdx; - // Update the display - zone->HatchBorder(); - canvas()->Refresh(); + if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) ) + { + // Remove the cutout + m_commit->Modify( zone ); + zone->RemoveCutout( outlineIdx, holeIdx ); + zone->UnFill(); - // Restore the selection on the original zone - m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, zone ); + // TODO Refill zone when KiCad supports auto re-fill - break; + // Update the display + zone->HatchBorder(); + canvas()->Refresh(); + + // Restore the selection on the original zone + m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, zone ); + + break; + } } + + // Remove the entire zone otherwise + m_commit->Remove( board_item ); } - // Remove the entire zone otherwise - m_commit->Remove( item ); break; - } case PCB_GROUP_T: { - PCB_GROUP* group = static_cast( item ); + PCB_GROUP* group = static_cast( board_item ); auto removeItem = [&]( BOARD_ITEM* bItem ) @@ -1952,11 +1896,11 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut ) { // Silently ignore delete of Reference or Value if they happen to be // in group. - if( bItem->Type() == PCB_FP_TEXT_T ) + if( bItem->Type() == PCB_TEXT_T ) { - FP_TEXT* textItem = static_cast( bItem ); + PCB_TEXT* textItem = static_cast( bItem ); - if( textItem->GetType() != FP_TEXT::TEXT_is_DIVERS ) + if( textItem->GetType() != PCB_TEXT::TEXT_is_DIVERS ) return; } else if( bItem->Type() == PCB_PAD_T ) @@ -1988,7 +1932,7 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut ) } default: - m_commit->Remove( item ); + m_commit->Remove( board_item ); break; } } @@ -2239,10 +2183,8 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) static_cast( dupe_item )->SetNumber( padNumber ); } } - else if( orig_item->GetParent() && orig_item->GetParent()->Type() == PCB_FOOTPRINT_T ) + else if( FOOTPRINT* parentFootprint = orig_item->GetParentFootprint() ) { - FOOTPRINT* parentFootprint = static_cast( orig_item->GetParent() ); - m_commit->Modify( parentFootprint ); dupe_item = parentFootprint->DuplicateItem( orig_item, true /* add to parent */ ); } @@ -2515,7 +2457,7 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent ) // We can't copy both a footprint and its text in the same operation, so if // both are selected, remove the text - if( item->Type() == PCB_FP_TEXT_T && aCollector.HasItem( item->GetParent() ) ) + if( item->Type() == PCB_TEXT_T && aCollector.HasItem( item->GetParentFootprint() ) ) aCollector.Remove( item ); } }, diff --git a/pcbnew/tools/edit_tool_move_fct.cpp b/pcbnew/tools/edit_tool_move_fct.cpp index 83a1c6f8fe..4bbc1e7bca 100644 --- a/pcbnew/tools/edit_tool_move_fct.cpp +++ b/pcbnew/tools/edit_tool_move_fct.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2017 CERN - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * @author Tomasz Wlostowski * @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -363,7 +363,7 @@ int EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, const wxString& aCommi else if( item->Type() == PCB_PAD_T ) { PAD* pad = static_cast( item ); - FOOTPRINT* fp = static_cast( pad->GetParentFootprint() ); + FOOTPRINT* fp = pad->GetParentFootprint(); msg = wxString::Format( _( "%s pad %s" ), fp->GetReference(), pad->GetNumber() ); } else diff --git a/pcbnew/tools/group_tool.cpp b/pcbnew/tools/group_tool.cpp index a3620c3494..52521c2fd8 100644 --- a/pcbnew/tools/group_tool.cpp +++ b/pcbnew/tools/group_tool.cpp @@ -240,19 +240,8 @@ int GROUP_TOOL::Group( const TOOL_EVENT& aEvent ) { BOARD_ITEM* item = aCollector[ i ]; - switch( item->Type() ) - { - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: - case PCB_FP_ZONE_T: - case PCB_PAD_T: + if( item->GetParentFootprint() ) aCollector.Remove( item ); - break; - - default: - break; - } } } ); } diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index dbbe2d6255..10ba70363a 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -580,6 +580,8 @@ int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent ) if( !m_isFootprintEditor ) return 0; + Activate(); + PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions(); PCB_RENDER_SETTINGS* settings = static_cast( view()->GetPainter()->GetSettings() ); WX_INFOBAR* infoBar = frame()->GetInfoBar(); @@ -681,7 +683,7 @@ PCB_LAYER_ID PAD_TOOL::explodePad( PAD* aPad ) for( const std::shared_ptr& primitive : aPad->GetPrimitives() ) { - FP_SHAPE* shape = new FP_SHAPE( board()->GetFirstFootprint() ); + PCB_SHAPE* shape = new PCB_SHAPE( board()->GetFirstFootprint() ); shape->SetShape( primitive->GetShape() ); shape->SetIsAnnotationProxy( primitive->IsAnnotationProxy()); @@ -718,7 +720,6 @@ PCB_LAYER_ID PAD_TOOL::explodePad( PAD* aPad ) UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() ); } - shape->SetLocalCoord(); shape->Move( aPad->GetPosition() ); shape->Rotate( aPad->GetPosition(), aPad->GetOrientation() ); shape->SetLayer( layer ); @@ -738,10 +739,10 @@ PCB_LAYER_ID PAD_TOOL::explodePad( PAD* aPad ) } -std::vector PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_COMMIT& aCommit ) +std::vector PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_COMMIT& aCommit ) { int maxError = board()->GetDesignSettings().m_MaxError; - FOOTPRINT* footprint = static_cast( aPad->GetParentFootprint() ); + FOOTPRINT* footprint = aPad->GetParentFootprint(); // Don't leave an object in the point editor that might no longer exist after // recombining the pad. @@ -751,14 +752,14 @@ std::vector PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_ item->ClearFlags( SKIP_STRUCT ); auto findNext = - [&]( PCB_LAYER_ID aLayer ) -> FP_SHAPE* + [&]( PCB_LAYER_ID aLayer ) -> PCB_SHAPE* { SHAPE_POLY_SET padPoly; aPad->TransformShapeToPolygon( padPoly, aLayer, 0, maxError, ERROR_INSIDE ); for( BOARD_ITEM* item : footprint->GraphicalItems() ) { - FP_SHAPE* shape = dynamic_cast( item ); + PCB_SHAPE* shape = dynamic_cast( item ); if( !shape || ( shape->GetFlags() & SKIP_STRUCT ) ) continue; @@ -767,27 +768,27 @@ std::vector PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_ continue; if( shape->IsAnnotationProxy() ) // Pad number (and net name) box - return (FP_SHAPE*) item; + return shape; SHAPE_POLY_SET drawPoly; shape->TransformShapeToPolygon( drawPoly, aLayer, 0, maxError, ERROR_INSIDE ); drawPoly.BooleanIntersection( padPoly, SHAPE_POLY_SET::PM_FAST ); if( !drawPoly.IsEmpty() ) - return (FP_SHAPE*) item; + return shape; } return nullptr; }; auto findMatching = - [&]( FP_SHAPE* aShape ) -> std::vector + [&]( PCB_SHAPE* aShape ) -> std::vector { - std::vector matching; + std::vector matching; for( BOARD_ITEM* item : footprint->GraphicalItems() ) { - FP_SHAPE* other = dynamic_cast( item ); + PCB_SHAPE* other = dynamic_cast( item ); if( !other || ( other->GetFlags() & SKIP_STRUCT ) ) continue; @@ -802,8 +803,8 @@ std::vector PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_ return matching; }; - PCB_LAYER_ID layer; - std::vector mergedShapes; + PCB_LAYER_ID layer; + std::vector mergedShapes; if( aPad->IsOnLayer( F_Cu ) ) layer = F_Cu; @@ -812,7 +813,7 @@ std::vector PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_ else layer = *aPad->GetLayerSet().UIOrder(); - while( FP_SHAPE* fpShape = findNext( layer ) ) + while( PCB_SHAPE* fpShape = findNext( layer ) ) { // We've found an intersecting item to combine. // @@ -861,53 +862,52 @@ std::vector PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_ if( !aIsDryRun ) { - PCB_SHAPE* pcbShape = new PCB_SHAPE; + PCB_SHAPE* primitive = new PCB_SHAPE; - pcbShape->SetShape( fpShape->GetShape() ); - pcbShape->SetFilled( fpShape->IsFilled() ); - pcbShape->SetStroke( fpShape->GetStroke() ); + primitive->SetShape( fpShape->GetShape() ); + primitive->SetFilled( fpShape->IsFilled() ); + primitive->SetStroke( fpShape->GetStroke() ); - switch( pcbShape->GetShape() ) + switch( primitive->GetShape() ) { case SHAPE_T::SEGMENT: case SHAPE_T::RECT: case SHAPE_T::CIRCLE: - pcbShape->SetStart( fpShape->GetStart() ); - pcbShape->SetEnd( fpShape->GetEnd() ); + primitive->SetStart( fpShape->GetStart() ); + primitive->SetEnd( fpShape->GetEnd() ); break; case SHAPE_T::ARC: - pcbShape->SetStart( fpShape->GetStart() ); - pcbShape->SetEnd( fpShape->GetEnd() ); - pcbShape->SetCenter( fpShape->GetCenter() ); + primitive->SetStart( fpShape->GetStart() ); + primitive->SetEnd( fpShape->GetEnd() ); + primitive->SetCenter( fpShape->GetCenter() ); break; case SHAPE_T::BEZIER: - pcbShape->SetStart( fpShape->GetStart() ); - pcbShape->SetEnd( fpShape->GetEnd() ); - pcbShape->SetBezierC1( fpShape->GetBezierC1() ); - pcbShape->SetBezierC2( fpShape->GetBezierC2() ); + primitive->SetStart( fpShape->GetStart() ); + primitive->SetEnd( fpShape->GetEnd() ); + primitive->SetBezierC1( fpShape->GetBezierC1() ); + primitive->SetBezierC2( fpShape->GetBezierC2() ); break; - case SHAPE_T::POLY: - pcbShape->SetPolyShape( fpShape->GetPolyShape() ); + case SHAPE_T::POLY: primitive->SetPolyShape( fpShape->GetPolyShape() ); break; default: - UNIMPLEMENTED_FOR( pcbShape->SHAPE_T_asString() ); + UNIMPLEMENTED_FOR( primitive->SHAPE_T_asString() ); } - pcbShape->Move( - aPad->GetPosition() ); - pcbShape->Rotate( VECTOR2I( 0, 0 ), - aPad->GetOrientation() ); - pcbShape->SetIsAnnotationProxy( fpShape->IsAnnotationProxy()); - aPad->AddPrimitive( pcbShape ); + primitive->Move( - aPad->GetPosition() ); + primitive->Rotate( VECTOR2I( 0, 0 ), - aPad->GetOrientation() ); + primitive->SetIsAnnotationProxy( fpShape->IsAnnotationProxy()); + aPad->AddPrimitive( primitive ); aCommit.Remove( fpShape ); } // See if there are other shapes that match and mark them for delete. (KiCad won't // produce these, but old footprints from other vendors have them.) - for( FP_SHAPE* other : findMatching( fpShape ) ) + for( PCB_SHAPE* other : findMatching( fpShape ) ) { other->SetFlags( SKIP_STRUCT ); mergedShapes.push_back( other ); diff --git a/pcbnew/tools/pad_tool.h b/pcbnew/tools/pad_tool.h index 6b2964a3b5..bb31006d2c 100644 --- a/pcbnew/tools/pad_tool.h +++ b/pcbnew/tools/pad_tool.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,7 +28,7 @@ #include class ACTION_MENU; -class FP_SHAPE; +class PCB_SHAPE; /** * Tool relating to pads and pad settings. @@ -70,9 +70,9 @@ public: * @param aPad the pad to run the recombination algorithm on * @param aIsDryRun if true the list will be generated but no changes will be made * @param aCommit the commit to add any changes to - * @return a list of FP_SHAPEs that will be combined + * @return a list of PCB_SHAPEs that will be combined */ - std::vector RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_COMMIT& aCommit ); + std::vector RecombinePad( PAD* aPad, bool aIsDryRun, BOARD_COMMIT& aCommit ); private: ///< Bind handlers to corresponding TOOL_ACTIONs. diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index ac5eff0251..8899fc14a1 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2016 CERN - * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -45,8 +45,6 @@ #include #include #include -#include -#include #include #include #include @@ -678,38 +676,31 @@ static void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOA aClipFootprint->Pads().clear(); // Not all graphic items can be added to the current footprint: - // Reference and value are already existing in the current footprint, and - // must be unique. + // Reference and value are already existing in the current footprint, and must be unique. // So they will be skipped for( BOARD_ITEM* item : aClipFootprint->GraphicalItems() ) { - if( item->Type() == PCB_FP_SHAPE_T || item->Type() == PCB_FP_TEXTBOX_T ) + if( item->Type() == PCB_TEXT_T ) { - FP_SHAPE* shape = static_cast( item ); + PCB_TEXT* text = static_cast( item ); - shape->SetParent( nullptr ); - shape->SetLocalCoord(); - } - else if( item->Type() == PCB_FP_TEXT_T ) - { - FP_TEXT* text = static_cast( item ); - - if( text->GetType() != FP_TEXT::TEXT_is_DIVERS ) + if( text->GetType() != PCB_TEXT::TEXT_is_DIVERS ) continue; - text->SetTextAngle( text->GetTextAngle() + aClipFootprint->GetOrientation() ); - - text->SetParent( nullptr ); - text->SetLocalCoord(); + text->SetTextAngle( text->GetTextAngle() - aClipFootprint->GetOrientation() ); + text->SetTextAngle( text->GetTextAngle() + editorFootprint->GetOrientation() ); } + VECTOR2I pos = item->GetFPRelativePosition(); item->SetParent( editorFootprint ); + item->SetFPRelativePosition( pos ); + aPastedItems.push_back( item ); } aClipFootprint->GraphicalItems().clear(); - for( FP_ZONE* zone : aClipFootprint->Zones() ) + for( ZONE* zone : aClipFootprint->Zones() ) { zone->SetParent( editorFootprint ); aPastedItems.push_back( zone ); @@ -882,68 +873,30 @@ int PCB_CONTROL::Paste( const TOOL_EVENT& aEvent ) for( BOARD_ITEM* clipDrawItem : clipBoard->Drawings() ) { - if( clipDrawItem->Type() == PCB_SHAPE_T ) + switch( clipDrawItem->Type() ) { - PCB_SHAPE* clipShape = static_cast( clipDrawItem ); - PCB_GROUP* parentGroup = clipDrawItem->GetParentGroup(); + case PCB_TEXT_T: + case PCB_TEXTBOX_T: + case PCB_SHAPE_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_LEADER_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_DIM_RADIAL_T: + clipDrawItem->SetParent( editorFootprint ); + pastedItems.push_back( clipDrawItem ); + break; - if( parentGroup ) + default: + if( PCB_GROUP* parentGroup = clipDrawItem->GetParentGroup() ) parentGroup->RemoveItem( clipDrawItem ); - // Convert to PCB_FP_SHAPE_T - FP_SHAPE* pastedShape = new FP_SHAPE( editorFootprint ); - static_cast( pastedShape )->SwapItemData( clipShape ); - pastedShape->SetLocalCoord(); - - if( parentGroup ) - parentGroup->AddItem( pastedShape ); - - pastedItems.push_back( pastedShape ); - } - else if( clipDrawItem->Type() == PCB_TEXT_T ) - { - PCB_TEXT* clipTextItem = static_cast( clipDrawItem ); - PCB_GROUP* parentGroup = clipDrawItem->GetParentGroup(); - - if( parentGroup ) - parentGroup->RemoveItem( clipDrawItem ); - - // Convert to PCB_FP_TEXT_T - FP_TEXT* pastedTextItem = new FP_TEXT( editorFootprint ); - static_cast( pastedTextItem )->SwapText( *clipTextItem ); - static_cast( pastedTextItem )->SwapAttributes( *clipTextItem ); - - if( parentGroup ) - parentGroup->AddItem( pastedTextItem ); - - pastedItems.push_back( pastedTextItem ); - } - else if( clipDrawItem->Type() == PCB_TEXTBOX_T ) - { - PCB_TEXTBOX* clipTextBox = static_cast( clipDrawItem ); - PCB_GROUP* parentGroup = clipDrawItem->GetParentGroup(); - - if( parentGroup ) - parentGroup->RemoveItem( clipDrawItem ); - - // Convert to PCB_FP_TEXTBOX_T - FP_TEXTBOX* pastedTextBox = new FP_TEXTBOX( editorFootprint ); - - // Handle shape data - static_cast( pastedTextBox )->SwapItemData( clipTextBox ); - pastedTextBox->SetLocalCoord(); - - // Handle text data - static_cast( pastedTextBox )->SwapText( *clipTextBox ); - static_cast( pastedTextBox )->SwapAttributes( *clipTextBox ); - - if( parentGroup ) - parentGroup->AddItem( pastedTextBox ); - - pastedItems.push_back( pastedTextBox ); + break; } } + clipBoard->Drawings().clear(); + clipBoard->Visit( [&]( EDA_ITEM* item, void* testData ) { diff --git a/pcbnew/tools/pcb_grid_helper.cpp b/pcbnew/tools/pcb_grid_helper.cpp index f0b1b6bd53..d69717f44c 100644 --- a/pcbnew/tools/pcb_grid_helper.cpp +++ b/pcbnew/tools/pcb_grid_helper.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -679,7 +679,6 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos break; - case PCB_FP_TEXTBOX_T: case PCB_TEXTBOX_T: if( aFrom ) { @@ -695,7 +694,6 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos handleShape( static_cast( aItem ) ); break; - case PCB_FP_SHAPE_T: case PCB_SHAPE_T: if( aFrom ) { @@ -776,31 +774,8 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos break; } - case PCB_FP_ZONE_T: - { - if( aFrom && aSelectionFilter && !aSelectionFilter->zones ) - break; - - const SHAPE_POLY_SET* outline = static_cast( aItem )->Outline(); - - SHAPE_LINE_CHAIN lc; - lc.SetClosed( true ); - - for( auto iter = outline->CIterateWithHoles(); iter; iter++ ) - { - addAnchor( *iter, CORNER | SNAPPABLE, aItem ); - lc.Append( *iter ); - } - - addAnchor( lc.NearestPoint( aRefPos ), OUTLINE, aItem ); - - break; - } - case PCB_DIM_ALIGNED_T: case PCB_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_ORTHOGONAL_T: { if( aFrom && aSelectionFilter && !aSelectionFilter->dimensions ) break; @@ -814,7 +789,6 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos } case PCB_DIM_CENTER_T: - case PCB_FP_DIM_CENTER_T: { if( aFrom && aSelectionFilter && !aSelectionFilter->dimensions ) break; @@ -836,7 +810,6 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos } case PCB_DIM_RADIAL_T: - case PCB_FP_DIM_RADIAL_T: { if( aFrom && aSelectionFilter && !aSelectionFilter->dimensions ) break; @@ -850,7 +823,6 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos } case PCB_DIM_LEADER_T: - case PCB_FP_DIM_LEADER_T: { if( aFrom && aSelectionFilter && !aSelectionFilter->dimensions ) break; @@ -862,7 +834,6 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos break; } - case PCB_FP_TEXT_T: case PCB_TEXT_T: if( aFrom && aSelectionFilter && !aSelectionFilter->text ) break; diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 8902c16dd7..775cc45f64 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -38,8 +38,6 @@ using namespace std::placeholders; #include #include #include -#include -#include #include #include #include @@ -181,7 +179,7 @@ std::shared_ptr PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) if( !aItem ) return points; - if( aItem->Type() == PCB_TEXTBOX_T || aItem->Type() == PCB_FP_TEXTBOX_T ) + if( aItem->Type() == PCB_TEXTBOX_T ) { const PCB_SHAPE* shape = static_cast( aItem ); @@ -209,9 +207,7 @@ std::shared_ptr PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) } case PCB_TEXTBOX_T: - case PCB_FP_TEXTBOX_T: case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: { const PCB_SHAPE* shape = static_cast( aItem ); @@ -306,21 +302,19 @@ std::shared_ptr PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) default: // suppress warnings break; } - } - break; - case PCB_FP_ZONE_T: + break; + } + case PCB_ZONE_T: { const ZONE* zone = static_cast( aItem ); buildForPolyOutline( points, zone->Outline() ); - } break; + } case PCB_DIM_ALIGNED_T: case PCB_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_ORTHOGONAL_T: { const PCB_DIM_ALIGNED* dimension = static_cast( aItem ); @@ -348,7 +342,6 @@ std::shared_ptr PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) } case PCB_DIM_CENTER_T: - case PCB_FP_DIM_CENTER_T: { const PCB_DIM_CENTER* dimension = static_cast( aItem ); @@ -365,7 +358,6 @@ std::shared_ptr PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) } case PCB_DIM_RADIAL_T: - case PCB_FP_DIM_RADIAL_T: { const PCB_DIM_RADIAL* dimension = static_cast( aItem ); @@ -389,7 +381,6 @@ std::shared_ptr PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) } case PCB_DIM_LEADER_T: - case PCB_FP_DIM_LEADER_T: { const PCB_DIM_LEADER* dimension = static_cast( aItem ); @@ -1117,9 +1108,7 @@ void PCB_POINT_EDITOR::updateItem() const } case PCB_TEXTBOX_T: - case PCB_FP_TEXTBOX_T: case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: { PCB_SHAPE* shape = static_cast( item ); @@ -1276,26 +1265,18 @@ void PCB_POINT_EDITOR::updateItem() const break; } - if( FP_SHAPE* fpShape = dynamic_cast( item ) ) + if( shape->IsAnnotationProxy() ) { - // Update relative coordinates for footprint shapes - fpShape->SetLocalCoord(); - - if( fpShape->IsAnnotationProxy() ) + for( PAD* pad : shape->GetParentFootprint()->Pads() ) { - for( PAD* pad : fpShape->GetParentFootprint()->Pads() ) - { - if( pad->GetFlags() & ENTERED ) - view()->Update( pad ); - } + if( pad->GetFlags() & ENTERED ) + view()->Update( pad ); } } // Nuke outline font render caches if( PCB_TEXTBOX* textBox = dynamic_cast( item ) ) textBox->ClearRenderCache(); - else if( FP_TEXTBOX* fpTextBox = dynamic_cast( item ) ) - fpTextBox->ClearRenderCache(); break; } @@ -1406,7 +1387,6 @@ void PCB_POINT_EDITOR::updateItem() const break; } - case PCB_FP_ZONE_T: case PCB_ZONE_T: { ZONE* zone = static_cast( item ); @@ -1435,7 +1415,6 @@ void PCB_POINT_EDITOR::updateItem() const } case PCB_DIM_ALIGNED_T: - case PCB_FP_DIM_ALIGNED_T: { PCB_DIM_ALIGNED* dimension = static_cast( item ); @@ -1500,7 +1479,6 @@ void PCB_POINT_EDITOR::updateItem() const } case PCB_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: { PCB_DIM_ORTHOGONAL* dimension = static_cast( item ); @@ -1566,7 +1544,6 @@ void PCB_POINT_EDITOR::updateItem() const } case PCB_DIM_CENTER_T: - case PCB_FP_DIM_CENTER_T: { PCB_DIM_CENTER* dimension = static_cast( item ); @@ -1581,7 +1558,6 @@ void PCB_POINT_EDITOR::updateItem() const } case PCB_DIM_RADIAL_T: - case PCB_FP_DIM_RADIAL_T: { PCB_DIM_RADIAL* dimension = static_cast( item ); @@ -1630,7 +1606,6 @@ void PCB_POINT_EDITOR::updateItem() const } case PCB_DIM_LEADER_T: - case PCB_FP_DIM_LEADER_T: { PCB_DIM_LEADER* dimension = static_cast( item ); @@ -1699,7 +1674,6 @@ void PCB_POINT_EDITOR::updatePoints() } case PCB_TEXTBOX_T: - case PCB_FP_TEXTBOX_T: { const PCB_SHAPE* shape = static_cast( item ); int target = shape->GetShape() == SHAPE_T::RECT ? 4 : 0; @@ -1736,7 +1710,6 @@ void PCB_POINT_EDITOR::updatePoints() } case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: { const PCB_SHAPE* shape = static_cast( item ); @@ -1881,7 +1854,6 @@ void PCB_POINT_EDITOR::updatePoints() } break; - case PCB_FP_ZONE_T: case PCB_ZONE_T: { ZONE* zone = static_cast( item ); @@ -1908,8 +1880,6 @@ void PCB_POINT_EDITOR::updatePoints() case PCB_DIM_ALIGNED_T: case PCB_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_ORTHOGONAL_T: { const PCB_DIM_ALIGNED* dimension = static_cast( item ); @@ -1922,7 +1892,6 @@ void PCB_POINT_EDITOR::updatePoints() } case PCB_DIM_CENTER_T: - case PCB_FP_DIM_CENTER_T: { const PCB_DIM_CENTER* dimension = static_cast( item ); @@ -1932,7 +1901,6 @@ void PCB_POINT_EDITOR::updatePoints() } case PCB_DIM_RADIAL_T: - case PCB_FP_DIM_RADIAL_T: { const PCB_DIM_RADIAL* dimension = static_cast( item ); @@ -1944,7 +1912,6 @@ void PCB_POINT_EDITOR::updatePoints() } case PCB_DIM_LEADER_T: - case PCB_FP_DIM_LEADER_T: { const PCB_DIM_LEADER* dimension = static_cast( item ); @@ -1995,12 +1962,10 @@ void PCB_POINT_EDITOR::setAltConstraint( bool aEnabled ) switch( parent->Type() ) { case PCB_ZONE_T: - case PCB_FP_ZONE_T: isPoly = true; break; case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: isPoly = static_cast( parent )->GetShape() == SHAPE_T::POLY; break; @@ -2035,7 +2000,6 @@ EDIT_POINT PCB_POINT_EDITOR::get45DegConstrainer() const switch( item->Type() ) { case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: switch( static_cast( item )->GetShape() ) { case SHAPE_T::SEGMENT: @@ -2052,7 +2016,6 @@ EDIT_POINT PCB_POINT_EDITOR::get45DegConstrainer() const break; case PCB_DIM_ALIGNED_T: - case PCB_FP_DIM_ALIGNED_T: { // Constraint for crossbar if( isModified( m_editPoints->Point( DIM_START ) ) ) @@ -2068,7 +2031,6 @@ EDIT_POINT PCB_POINT_EDITOR::get45DegConstrainer() const } case PCB_DIM_CENTER_T: - case PCB_FP_DIM_CENTER_T: { if( isModified( m_editPoints->Point( DIM_END ) ) ) return m_editPoints->Point( DIM_START ); @@ -2077,7 +2039,6 @@ EDIT_POINT PCB_POINT_EDITOR::get45DegConstrainer() const } case PCB_DIM_RADIAL_T: - case PCB_FP_DIM_RADIAL_T: { if( isModified( m_editPoints->Point( DIM_TEXT ) ) ) return m_editPoints->Point( DIM_KNEE ); @@ -2099,10 +2060,10 @@ bool PCB_POINT_EDITOR::canAddCorner( const EDA_ITEM& aItem ) const auto type = aItem.Type(); // Works only for zones and line segments - if( type == PCB_ZONE_T || type == PCB_FP_ZONE_T ) + if( type == PCB_ZONE_T ) return true; - if( type == PCB_SHAPE_T || type == PCB_FP_SHAPE_T ) + if( type == PCB_SHAPE_T ) { const PCB_SHAPE& shape = static_cast( aItem ); return shape.GetShape() == SHAPE_T::SEGMENT || shape.GetShape() == SHAPE_T::POLY; @@ -2153,12 +2114,10 @@ bool PCB_POINT_EDITOR::removeCornerCondition( const SELECTION& ) switch( item->Type() ) { case PCB_ZONE_T: - case PCB_FP_ZONE_T: polyset = static_cast( item )->Outline(); break; case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: if( static_cast( item )->GetShape() == SHAPE_T::POLY ) polyset = &static_cast( item )->GetPolyShape(); else @@ -2211,8 +2170,7 @@ int PCB_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) PCB_SHAPE* graphicItem = dynamic_cast( item ); BOARD_COMMIT commit( frame ); - if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T - || ( graphicItem && graphicItem->GetShape() == SHAPE_T::POLY ) ) + if( item->Type() == PCB_ZONE_T || ( graphicItem && graphicItem->GetShape() == SHAPE_T::POLY ) ) { unsigned int nearestIdx = 0; unsigned int nextNearestIdx = 0; @@ -2220,7 +2178,7 @@ int PCB_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) unsigned int firstPointInContour = 0; SHAPE_POLY_SET* zoneOutline; - if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) + if( item->Type() == PCB_ZONE_T ) { ZONE* zone = static_cast( item ); zoneOutline = zone->Outline(); @@ -2278,7 +2236,7 @@ int PCB_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) zoneOutline->InsertVertex( nextNearestIdx, nearestPoint ); // We re-hatch the filled zones but not polygons - if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) + if( item->Type() == PCB_ZONE_T ) static_cast( item )->HatchBorder(); @@ -2294,30 +2252,13 @@ int PCB_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) // Move the end of the line to the break point.. graphicItem->SetEnd( VECTOR2I( nearestPoint.x, nearestPoint.y ) ); - if( graphicItem->Type() == PCB_FP_SHAPE_T ) - static_cast( graphicItem )->SetLocalCoord(); - // and add another one starting from the break point - PCB_SHAPE* newSegment; - - if( item->Type() == PCB_FP_SHAPE_T ) - { - FP_SHAPE* edge = static_cast( graphicItem ); - assert( edge->GetParent()->Type() == PCB_FOOTPRINT_T ); - newSegment = new FP_SHAPE( *edge ); - } - else - { - newSegment = new PCB_SHAPE( *graphicItem ); - } + PCB_SHAPE* newSegment = new PCB_SHAPE( *graphicItem ); newSegment->ClearSelected(); newSegment->SetStart( VECTOR2I( nearestPoint.x, nearestPoint.y ) ); newSegment->SetEnd( VECTOR2I( seg.B.x, seg.B.y ) ); - if( newSegment->Type() == PCB_FP_SHAPE_T ) - static_cast( newSegment )->SetLocalCoord(); - commit.Add( newSegment ); commit.Push( _( "Split segment" ) ); } @@ -2339,13 +2280,13 @@ int PCB_POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent ) SHAPE_POLY_SET* polygon = nullptr; - if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) + if( item->Type() == PCB_ZONE_T ) { ZONE* zone = static_cast( item ); polygon = zone->Outline(); zone->SetNeedRefill( true ); } - else if( item->Type() == PCB_FP_SHAPE_T || item->Type() == PCB_SHAPE_T ) + else if( item->Type() == PCB_SHAPE_T ) { PCB_SHAPE* shape = static_cast( item ); @@ -2393,7 +2334,7 @@ int PCB_POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent ) commit.Push( _( "Remove a zone/polygon corner" ) ); // Refresh zone hatching - if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) + if( item->Type() == PCB_ZONE_T ) static_cast( item )->HatchBorder(); updatePoints(); diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 7affc9bdde..4512074d41 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -41,7 +41,6 @@ using namespace std::placeholders; #include #include #include -#include #include #include #include @@ -390,7 +389,7 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) for( EDA_ITEM* item : aCollector ) { - if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) + if( item->Type() == PCB_ZONE_T ) { ZONE* zone = static_cast( item ); @@ -2087,7 +2086,6 @@ static bool itemIsIncludedByFilter( const BOARD_ITEM& aItem, const BOARD& aBoard case PCB_VIA_T: return aFilterOptions.includeVias; - case PCB_FP_ZONE_T: case PCB_ZONE_T: return aFilterOptions.includeZones; @@ -2098,18 +2096,11 @@ static bool itemIsIncludedByFilter( const BOARD_ITEM& aItem, const BOARD& aBoard case PCB_DIM_RADIAL_T: case PCB_DIM_ORTHOGONAL_T: case PCB_DIM_LEADER_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_LEADER_T: if( aItem.GetLayer() == Edge_Cuts ) return aFilterOptions.includeBoardOutlineLayer; else return aFilterOptions.includeItemsOnTechLayers; - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: case PCB_TEXT_T: case PCB_TEXTBOX_T: return aFilterOptions.includePcbTexts; @@ -2219,7 +2210,6 @@ bool PCB_SELECTION_TOOL::itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect break; - case PCB_FP_ZONE_T: case PCB_ZONE_T: { ZONE* zone = static_cast( aItem ); @@ -2233,7 +2223,6 @@ bool PCB_SELECTION_TOOL::itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect break; } - case PCB_FP_SHAPE_T: case PCB_SHAPE_T: case PCB_TARGET_T: if( !m_filter.graphics ) @@ -2242,21 +2231,15 @@ bool PCB_SELECTION_TOOL::itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect break; case PCB_BITMAP_T: - // a bitmap living in a footprint must not be selected inside the board editor if( !m_filter.graphics ) return false; - if( !m_isFootprintEditor ) - { - if( dynamic_cast( aItem->GetParent() ) ) - return false; - } - + // a bitmap living in a footprint must not be selected inside the board editor + if( !m_isFootprintEditor && aItem->GetParentFootprint() ) + return false; break; - case PCB_FP_TEXT_T: - case PCB_FP_TEXTBOX_T: case PCB_TEXT_T: case PCB_TEXTBOX_T: if( !m_filter.text ) @@ -2269,11 +2252,6 @@ bool PCB_SELECTION_TOOL::itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect case PCB_DIM_RADIAL_T: case PCB_DIM_ORTHOGONAL_T: case PCB_DIM_LEADER_T: - case PCB_FP_DIM_ALIGNED_T: - case PCB_FP_DIM_CENTER_T: - case PCB_FP_DIM_RADIAL_T: - case PCB_FP_DIM_ORTHOGONAL_T: - case PCB_FP_DIM_LEADER_T: if( !m_filter.dimensions ) return false; @@ -2452,15 +2430,14 @@ bool PCB_SELECTION_TOOL::Selectable( const BOARD_ITEM* aItem, bool checkVisibili return false; } - const ZONE* zone = nullptr; - const PCB_VIA* via = nullptr; - const PAD* pad = nullptr; - const FP_TEXT* text = nullptr; + const ZONE* zone = nullptr; + const PCB_VIA* via = nullptr; + const PAD* pad = nullptr; + const PCB_TEXT* text = nullptr; switch( aItem->Type() ) { case PCB_ZONE_T: - case PCB_FP_ZONE_T: if( !board()->IsElementVisible( LAYER_ZONES ) ) return false; @@ -2511,32 +2488,32 @@ bool PCB_SELECTION_TOOL::Selectable( const BOARD_ITEM* aItem, bool checkVisibili break; - case PCB_FP_TEXT_T: + case PCB_TEXT_T: + text = static_cast( aItem ); + if( m_isFootprintEditor ) { - text = static_cast( aItem ); - if( !text->IsVisible() && !view()->IsLayerVisible( LAYER_MOD_TEXT_INVISIBLE ) ) return false; - if( !view()->IsLayerVisible( aItem->GetLayer() ) ) + if( !view()->IsLayerVisible( text->GetLayer() ) ) return false; } - else + else if( aItem->GetParentFootprint() ) { - if( !view()->IsVisible( aItem ) ) + if( !view()->IsVisible( text ) ) return false; - if( !board()->IsLayerVisible( aItem->GetLayer() ) ) + if( !board()->IsLayerVisible( text->GetLayer() ) ) return false; int controlLayer = UNDEFINED_LAYER; - switch( static_cast( aItem )->GetType() ) + switch( text->GetType() ) { - case FP_TEXT::TEXT_is_REFERENCE: controlLayer = LAYER_MOD_REFERENCES; break; - case FP_TEXT::TEXT_is_VALUE: controlLayer = LAYER_MOD_VALUES; break; - case FP_TEXT::TEXT_is_DIVERS: controlLayer = LAYER_MOD_TEXT; break; + case PCB_TEXT::TEXT_is_REFERENCE: controlLayer = LAYER_MOD_REFERENCES; break; + case PCB_TEXT::TEXT_is_VALUE: controlLayer = LAYER_MOD_VALUES; break; + case PCB_TEXT::TEXT_is_DIVERS: controlLayer = LAYER_MOD_TEXT; break; } if( controlLayer == UNDEFINED_LAYER ) @@ -2548,14 +2525,14 @@ bool PCB_SELECTION_TOOL::Selectable( const BOARD_ITEM* aItem, bool checkVisibili break; - case PCB_FP_SHAPE_T: - case PCB_FP_TEXTBOX_T: + case PCB_SHAPE_T: + case PCB_TEXTBOX_T: if( m_isFootprintEditor ) { if( !view()->IsLayerVisible( aItem->GetLayer() ) ) return false; } - else + else if( aItem->GetParentFootprint() ) { // Footprint shape selections are only allowed in footprint editor mode. if( !checkVisibilityOnly ) @@ -2795,20 +2772,6 @@ int PCB_SELECTION_TOOL::hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aIt break; } - case PCB_FP_TEXT_T: - { - FP_TEXT* text = static_cast( aItem ); - text->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance ); - break; - } - - case PCB_FP_TEXTBOX_T: - { - FP_TEXTBOX* textbox = static_cast( aItem ); - textbox->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance ); - break; - } - case PCB_ZONE_T: { ZONE* zone = static_cast( aItem ); @@ -2979,7 +2942,7 @@ void PCB_SELECTION_TOOL::GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector BOARD_ITEM* item = aCollector[i]; double area = 0.0; - if( ( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ) + if( item->Type() == PCB_ZONE_T && static_cast( item )->HitTestForEdge( where, maxSlop / 2 ) ) { // Zone borders are very specific, so make them "small" diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp index 464660a2e3..300da6327f 100644 --- a/pcbnew/tools/pcb_viewer_tools.cpp +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -131,7 +131,7 @@ int PCB_VIEWER_TOOLS::GraphicOutlines( const TOOL_EVENT& aEvent ) { KICAD_T t = item->Type(); - if( t == PCB_FP_SHAPE_T || BaseType( t ) == PCB_DIMENSION_T ) + if( t == PCB_SHAPE_T || BaseType( t ) == PCB_DIMENSION_T ) view()->Update( item, KIGFX::REPAINT ); } } @@ -162,7 +162,7 @@ int PCB_VIEWER_TOOLS::TextOutlines( const TOOL_EVENT& aEvent ) for( BOARD_ITEM* item : fp->GraphicalItems() ) { - if( item->Type() == PCB_FP_TEXT_T ) + if( item->Type() == PCB_TEXT_T ) view()->Update( item, KIGFX::REPAINT ); } } diff --git a/pcbnew/tools/zone_create_helper.cpp b/pcbnew/tools/zone_create_helper.cpp index 07df322381..eeb77e3bd0 100644 --- a/pcbnew/tools/zone_create_helper.cpp +++ b/pcbnew/tools/zone_create_helper.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,14 +28,11 @@ #include #include #include -#include #include #include #include -#include #include #include -#include ZONE_CREATE_HELPER::ZONE_CREATE_HELPER( DRAWING_TOOL& aTool, PARAMS& aParams ): m_tool( aTool ), @@ -142,13 +139,9 @@ std::unique_ptr ZONE_CREATE_HELPER::createNewZone( bool aKeepout ) controls->WarpMouseCursor( controls->GetCursorPosition(), true ); } - // The new zone is a ZONE if created in the board editor and a FP_ZONE if created in the - // footprint editor wxASSERT( !m_tool.m_isFootprintEditor || ( parent->Type() == PCB_FOOTPRINT_T ) ); - std::unique_ptr newZone = m_tool.m_isFootprintEditor ? - std::make_unique( parent ) : - std::make_unique( parent ); + std::unique_ptr newZone = std::make_unique( parent ); // Apply the selected settings zoneInfo.ExportSetting( *newZone ); @@ -254,12 +247,7 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) BOARD_COMMIT commit( &m_tool ); BOARD* board = m_tool.getModel(); PCB_LAYER_ID layer = m_params.m_layer; - PCB_SHAPE* poly; - - if( m_tool.m_isFootprintEditor ) - poly = new FP_SHAPE( static_cast( m_tool.m_frame->GetModel() ) ); - else - poly = new PCB_SHAPE(); + PCB_SHAPE* poly = new PCB_SHAPE( m_tool.m_frame->GetModel() ); poly->SetShape( SHAPE_T::POLY ); diff --git a/pcbnew/tools/zone_filler_tool.cpp b/pcbnew/tools/zone_filler_tool.cpp index 3505be2b08..3953ad6846 100644 --- a/pcbnew/tools/zone_filler_tool.cpp +++ b/pcbnew/tools/zone_filler_tool.cpp @@ -363,7 +363,7 @@ int ZONE_FILLER_TOOL::ZoneUnfill( const TOOL_EVENT& aEvent ) for( EDA_ITEM* item : selection() ) { - assert( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T ); + assert( item->Type() == PCB_ZONE_T ); ZONE* zone = static_cast( item ); diff --git a/pcbnew/widgets/pcb_properties_panel.cpp b/pcbnew/widgets/pcb_properties_panel.cpp index b3c561ee2c..e99efb9bb0 100644 --- a/pcbnew/widgets/pcb_properties_panel.cpp +++ b/pcbnew/widgets/pcb_properties_panel.cpp @@ -30,9 +30,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -196,14 +194,9 @@ void PCB_PROPERTIES_PANEL::valueChanging( wxPropertyGridEvent& aEvent ) void setLocalCoord( BOARD_ITEM* aItem ) { - // TODO: we really need to get rid of this local/draw coords stuff (and make FP_* items the - // same as PCB_* items), but for now, it is what it is. + // TODO: we really need to get rid of this local/draw coords stuff, but for now, it is what it is. - if( FP_SHAPE* shape = dynamic_cast( aItem ) ) - shape->SetLocalCoord(); - else if( FP_TEXT* text = dynamic_cast( aItem ) ) - text->SetLocalCoord(); - else if( PAD* pad = dynamic_cast( aItem ) ) + if( PAD* pad = dynamic_cast( aItem ) ) pad->SetLocalCoord(); } diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index e49a8e3cf3..1ad70ee962 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -41,26 +42,28 @@ #include -ZONE::ZONE( BOARD_ITEM_CONTAINER* aParent, bool aInFP ) : - BOARD_CONNECTED_ITEM( aParent, aInFP ? PCB_FP_ZONE_T : PCB_ZONE_T ), +ZONE::ZONE( BOARD_ITEM_CONTAINER* aParent ) : + BOARD_CONNECTED_ITEM( aParent, PCB_ZONE_T ), + m_Poly( nullptr ), + m_isFilled( false ), + m_CornerSelection( nullptr ), m_area( 0.0 ), m_outlinearea( 0.0 ) { m_Poly = new SHAPE_POLY_SET(); // Outlines m_cornerSmoothingType = ZONE_SETTINGS::SMOOTHING_NONE; m_cornerRadius = 0; - m_zoneName = wxEmptyString; - m_CornerSelection = nullptr; // no corner is selected - m_isFilled = false; // fill status : true when the zone is filled m_teardropType = TEARDROP_TYPE::TD_NONE; m_islandRemovalMode = ISLAND_REMOVAL_MODE::ALWAYS; m_borderStyle = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; m_borderHatchPitch = GetDefaultHatchPitch(); m_priority = 0; - SetIsRuleArea( aInFP ); // Zones living in footprints have the rule area option SetLocalFlags( 0 ); // flags temporary used in zone calculations m_fillVersion = 5; // set the "old" way to build filled polygon areas (< 6.0.x) + if( GetParentFootprint() ) + SetIsRuleArea( true ); // Zones living in footprints have the rule area option + // Technically not necesssary to set this here, but just ensure a safe min value is set m_ZoneMinThickness = pcbIUScale.mmToIU( ZONE_CLEARANCE_MM ); @@ -316,7 +319,26 @@ double ZONE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { constexpr double HIDE = std::numeric_limits::max(); - return aView->IsLayerVisible( LAYER_ZONES ) ? 0.0 : HIDE; + if( !aView ) + return 0; + + if( !aView->IsLayerVisible( LAYER_ZONES ) ) + return HIDE; + + if( FOOTPRINT* parentFP = GetParentFootprint() ) + { + bool flipped = parentFP->GetLayer() == B_Cu; + + // Handle Render tab switches + if( !flipped && !aView->IsLayerVisible( LAYER_MOD_FR ) ) + return HIDE; + + if( flipped && !aView->IsLayerVisible( LAYER_MOD_BK ) ) + return HIDE; + } + + // Other layers are shown without any conditions + return 0.0; } @@ -1002,7 +1024,7 @@ BITMAPS ZONE::GetMenuImage() const void ZONE::swapData( BOARD_ITEM* aImage ) { - assert( aImage->Type() == PCB_ZONE_T || aImage->Type() == PCB_FP_ZONE_T ); + assert( aImage->Type() == PCB_ZONE_T ); std::swap( *static_cast( this ), *static_cast( aImage) ); } @@ -1272,59 +1294,6 @@ void ZONE::TransformSmoothedOutlineToPolygon( SHAPE_POLY_SET& aBuffer, int aClea } -FP_ZONE::FP_ZONE( BOARD_ITEM_CONTAINER* aParent ) : - ZONE( aParent, true ) -{ - // in a footprint, net classes are not managed. - // so set the net to NETINFO_LIST::ORPHANED_ITEM - SetNetCode( -1, true ); -} - - -FP_ZONE::FP_ZONE( const FP_ZONE& aZone ) : - ZONE( aZone ) -{ - InitDataFromSrcInCopyCtor( aZone ); -} - - -FP_ZONE& FP_ZONE::operator=( const FP_ZONE& aOther ) -{ - ZONE::operator=( aOther ); - return *this; -} - - -EDA_ITEM* FP_ZONE::Clone() const -{ - return new FP_ZONE( *this ); -} - - -double FP_ZONE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const -{ - constexpr double HIDE = (double)std::numeric_limits::max(); - - if( !aView ) - return 0; - - if( !aView->IsLayerVisible( LAYER_ZONES ) ) - return HIDE; - - bool flipped = GetParent() && GetParent()->GetLayer() == B_Cu; - - // Handle Render tab switches - if( !flipped && !aView->IsLayerVisible( LAYER_MOD_FR ) ) - return HIDE; - - if( flipped && !aView->IsLayerVisible( LAYER_MOD_BK ) ) - return HIDE; - - // Other layers are shown without any conditions - return 0.0; -} - - std::shared_ptr ZONE::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const { if( m_FilledPolysList.find( aLayer ) == m_FilledPolysList.end() ) diff --git a/pcbnew/zone.h b/pcbnew/zone.h index 50794d491c..e2e8cc72be 100644 --- a/pcbnew/zone.h +++ b/pcbnew/zone.h @@ -67,22 +67,11 @@ struct ISOLATED_ISLANDS * * A zone is described by a main polygon, a time stamp, a layer or a layer set, and a net name. * Other polygons inside the main polygon are holes in the zone. - * - * a item ZONE is living in a board - * a variant FP_ZONE is living in a footprint */ class ZONE : public BOARD_CONNECTED_ITEM { public: - - /** - * The ctor to build ZONE, but compatible with FP_ZONE requirement. - * if aInFP is true, a FP_ZONE is actually built - * (same item, but with a specific type id: - * The type is PCB_ZONE_T for a ZONE - * The type is PCB_FP_ZONE_T for a FP_ZONE - */ - ZONE( BOARD_ITEM_CONTAINER* parent, bool aInFP = false ); + ZONE( BOARD_ITEM_CONTAINER* parent ); ZONE( const ZONE& aZone ); ZONE& operator=( const ZONE &aOther ); @@ -927,21 +916,6 @@ protected: }; -/** - * A specialization of ZONE for use in footprints. - */ -class FP_ZONE : public ZONE -{ -public: - FP_ZONE( BOARD_ITEM_CONTAINER* aParent ); - FP_ZONE( const FP_ZONE& aZone ); - FP_ZONE& operator=( const FP_ZONE &aOther ); - - EDA_ITEM* Clone() const override; - - double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; -}; - #ifndef SWIG DECLARE_ENUM_TO_WXANY( ZONE_CONNECTION ) DECLARE_ENUM_TO_WXANY( ZONE_FILL_MODE ) diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp index 004db46045..12e1bdd4ce 100644 --- a/pcbnew/zone_filler.cpp +++ b/pcbnew/zone_filler.cpp @@ -35,8 +35,6 @@ #include #include #include -#include -#include #include #include #include @@ -819,11 +817,9 @@ void ZONE_FILLER::addKnockout( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, int aGap, switch( aItem->Type() ) { - case PCB_TEXT_T: text = static_cast( aItem ); break; - case PCB_TEXTBOX_T: text = static_cast( aItem ); break; - case PCB_FP_TEXT_T: text = static_cast( aItem ); break; - case PCB_FP_TEXTBOX_T: text = static_cast( aItem ); break; - default: break; + case PCB_TEXT_T: text = static_cast( aItem ); break; + case PCB_TEXTBOX_T: text = static_cast( aItem ); break; + default: break; } if( text ) @@ -834,15 +830,8 @@ void ZONE_FILLER::addKnockout( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, int aGap, case PCB_SHAPE_T: case PCB_TEXT_T: case PCB_TEXTBOX_T: - case PCB_FP_TEXTBOX_T: - case PCB_FP_SHAPE_T: case PCB_TARGET_T: - aItem->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE, - aIgnoreLineWidth ); - break; - - case PCB_FP_TEXT_T: - if( text->IsVisible() ) + if( !text || text->IsVisible() ) { aItem->TransformShapeToPolygon( aHoles, aLayer, aGap, m_maxError, ERROR_OUTSIDE, aIgnoreLineWidth ); diff --git a/qa/pcbnew_utils/board_construction_utils.cpp b/qa/pcbnew_utils/board_construction_utils.cpp index f3ca7a2f9b..fe46c9ccb0 100644 --- a/qa/pcbnew_utils/board_construction_utils.cpp +++ b/qa/pcbnew_utils/board_construction_utils.cpp @@ -23,7 +23,7 @@ #include -#include +#include #include #include #include @@ -34,14 +34,17 @@ namespace KI_TEST void DrawSegment( FOOTPRINT& aFootprint, const SEG& aSeg, int aWidth, PCB_LAYER_ID aLayer ) { - std::unique_ptr seg = std::make_unique( &aFootprint, SHAPE_T::SEGMENT ); + std::unique_ptr seg = std::make_unique( &aFootprint, SHAPE_T::SEGMENT ); - seg->SetStart0( aSeg.A ); - seg->SetEnd0( aSeg.B ); + seg->SetStart( aSeg.A ); + seg->SetEnd( aSeg.B ); seg->SetStroke( STROKE_PARAMS( aWidth, PLOT_DASH_TYPE::SOLID ) ); seg->SetLayer( aLayer ); + seg->Rotate( { 0, 0 }, aFootprint.GetOrientation() ); + seg->Move( aFootprint.GetPosition() ); + aFootprint.Add( seg.release() ); } @@ -59,15 +62,18 @@ void DrawPolyline( FOOTPRINT& aFootprint, const std::vector& aPts, int void DrawArc( FOOTPRINT& aFootprint, const VECTOR2I& aCentre, const VECTOR2I& aStart, const EDA_ANGLE& aAngle, int aWidth, PCB_LAYER_ID aLayer ) { - std::unique_ptr arc = std::make_unique( &aFootprint, SHAPE_T::ARC ); + std::unique_ptr arc = std::make_unique( &aFootprint, SHAPE_T::ARC ); - arc->SetCenter0( aCentre ); - arc->SetStart0( aStart ); - arc->SetArcAngleAndEnd0( aAngle ); + arc->SetCenter( aCentre ); + arc->SetStart( aStart ); + arc->SetArcAngleAndEnd( aAngle ); arc->SetStroke( STROKE_PARAMS( aWidth, PLOT_DASH_TYPE::SOLID ) ); arc->SetLayer( aLayer ); + arc->Rotate( { 0, 0 }, aFootprint.GetOrientation() ); + arc->Move( aFootprint.GetPosition() ); + aFootprint.Add( arc.release() ); } diff --git a/qa/pcbnew_utils/board_test_utils.cpp b/qa/pcbnew_utils/board_test_utils.cpp index 1ead61ec1b..4a8d36b582 100644 --- a/qa/pcbnew_utils/board_test_utils.cpp +++ b/qa/pcbnew_utils/board_test_utils.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,8 +29,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -148,10 +148,10 @@ struct kitest_cmp_drawings if( itemA->GetLayerSet() != itemB->GetLayerSet() ) return itemA->GetLayerSet().Seq() < itemB->GetLayerSet().Seq(); - if( itemA->Type() == PCB_FP_TEXT_T ) + if( itemA->Type() == PCB_TEXT_T ) { - const FP_TEXT* textA = static_cast( itemA ); - const FP_TEXT* textB = static_cast( itemB ); + const PCB_TEXT* textA = static_cast( itemA ); + const PCB_TEXT* textB = static_cast( itemB ); TEST( textA->GetType(), textB->GetType() ); TEST_PT( textA->GetPosition(), textB->GetPosition() ); @@ -190,51 +190,62 @@ void CheckFootprint( const FOOTPRINT* expected, const FOOTPRINT* fp ) std::set expectedPads( expected->Pads().begin(), expected->Pads().end() ); std::set fpPads( fp->Pads().begin(), fp->Pads().end() ); + for( auto itExpected = expectedPads.begin(), itFp = fpPads.begin(); itExpected != expectedPads.end() && itFp != fpPads.end(); itExpected++, itFp++ ) { CheckFpPad( *itExpected, *itFp ); } - std::set expectedGraphicalItems( - expected->GraphicalItems().begin(), expected->GraphicalItems().end() ); + std::set expectedGraphicalItems( expected->GraphicalItems().begin(), + expected->GraphicalItems().end() ); std::set fpGraphicalItems( fp->GraphicalItems().begin(), fp->GraphicalItems().end() ); + for( auto itExpected = expectedGraphicalItems.begin(), itFp = fpGraphicalItems.begin(); itExpected != expectedGraphicalItems.end() && itFp != fpGraphicalItems.end(); itExpected++, itFp++ ) { BOOST_CHECK_EQUAL( ( *itExpected )->Type(), ( *itFp )->Type() ); + switch( ( *itExpected )->Type() ) { - case PCB_FP_TEXT_T: + case PCB_TEXT_T: { - const FP_TEXT* expectedText = static_cast( *itExpected ); - const FP_TEXT* text = static_cast( *itFp ); + const PCB_TEXT* expectedText = static_cast( *itExpected ); + const PCB_TEXT* text = static_cast( *itFp ); CheckFpText( expectedText, text ); + break; } - break; - case PCB_FP_SHAPE_T: + + case PCB_SHAPE_T: { - const FP_SHAPE* expectedShape = static_cast( *itExpected ); - const FP_SHAPE* shape = static_cast( *itFp ); + const PCB_SHAPE* expectedShape = static_cast( *itExpected ); + const PCB_SHAPE* shape = static_cast( *itFp ); CheckFpShape( expectedShape, shape ); + break; } - break; - /*case PCB_FP_DIM_ALIGNED_T: break; - case PCB_FP_DIM_LEADER_T: break; - case PCB_FP_DIM_CENTER_T: break; - case PCB_FP_DIM_RADIAL_T: break; - case PCB_FP_DIM_ORTHOGONAL_T: break;*/ - default: BOOST_ERROR( "KICAD_T not known" ); break; + + case PCB_DIM_ALIGNED_T: + case PCB_DIM_LEADER_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_ORTHOGONAL_T: + // TODO + break; + + default: + BOOST_ERROR( "KICAD_T not known" ); + break; } } - std::set expectedZones( expected->Zones().begin(), - expected->Zones().end() ); - std::set fpZones( fp->Zones().begin(), fp->Zones().end() ); + std::set expectedZones( expected->Zones().begin(), + expected->Zones().end() ); + std::set fpZones( fp->Zones().begin(), fp->Zones().end() ); + for( auto itExpected = expectedZones.begin(), itFp = fpZones.begin(); itExpected != expectedZones.end() && itFp != fpZones.end(); itExpected++, itFp++ ) { @@ -296,9 +307,9 @@ void CheckFpPad( const PAD* expected, const PAD* pad ) } -void CheckFpText( const FP_TEXT* expected, const FP_TEXT* text ) +void CheckFpText( const PCB_TEXT* expected, const PCB_TEXT* text ) { - BOOST_TEST_CONTEXT( "Assert FP_TEXT with KIID=" << expected->m_Uuid.AsString() ) + BOOST_TEST_CONTEXT( "Assert PCB_TEXT with KIID=" << expected->m_Uuid.AsString() ) { CHECK_ENUM_CLASS_EQUAL( expected->Type(), text->Type() ); @@ -330,9 +341,9 @@ void CheckFpText( const FP_TEXT* expected, const FP_TEXT* text ) } -void CheckFpShape( const FP_SHAPE* expected, const FP_SHAPE* shape ) +void CheckFpShape( const PCB_SHAPE* expected, const PCB_SHAPE* shape ) { - BOOST_TEST_CONTEXT( "Assert FP_SHAPE with KIID=" << expected->m_Uuid.AsString() ) + BOOST_TEST_CONTEXT( "Assert PCB_SHAPE with KIID=" << expected->m_Uuid.AsString() ) { CHECK_ENUM_CLASS_EQUAL( expected->Type(), shape->Type() ); @@ -342,6 +353,7 @@ void CheckFpShape( const FP_SHAPE* expected, const FP_SHAPE* shape ) BOOST_CHECK_EQUAL( expected->GetStart(), shape->GetStart() ); BOOST_CHECK_EQUAL( expected->GetEnd(), shape->GetEnd() ); + if( expected->GetShape() == SHAPE_T::ARC ) { // center and position might differ as they are calculated from start/mid/end -> compare mid instead @@ -352,6 +364,7 @@ void CheckFpShape( const FP_SHAPE* expected, const FP_SHAPE* shape ) BOOST_CHECK_EQUAL( expected->GetCenter(), shape->GetCenter() ); BOOST_CHECK_EQUAL( expected->GetPosition(), shape->GetPosition() ); } + BOOST_CHECK_EQUAL( expected->GetBezierC1(), shape->GetBezierC1() ); BOOST_CHECK_EQUAL( expected->GetBezierC2(), shape->GetBezierC2() ); @@ -367,9 +380,9 @@ void CheckFpShape( const FP_SHAPE* expected, const FP_SHAPE* shape ) } -void CheckFpZone( const FP_ZONE* expected, const FP_ZONE* zone ) +void CheckFpZone( const ZONE* expected, const ZONE* zone ) { - BOOST_TEST_CONTEXT( "Assert FP_ZONE with KIID=" << expected->m_Uuid.AsString() ) + BOOST_TEST_CONTEXT( "Assert ZONE with KIID=" << expected->m_Uuid.AsString() ) { CHECK_ENUM_CLASS_EQUAL( expected->Type(), zone->Type() ); diff --git a/qa/pcbnew_utils/include/pcbnew_utils/board_test_utils.h b/qa/pcbnew_utils/include/pcbnew_utils/board_test_utils.h index a71f4af25c..1bce2339f3 100644 --- a/qa/pcbnew_utils/include/pcbnew_utils/board_test_utils.h +++ b/qa/pcbnew_utils/include/pcbnew_utils/board_test_utils.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,9 +35,9 @@ class BOARD; class BOARD_ITEM; class FOOTPRINT; -class FP_TEXT; -class FP_SHAPE; -class FP_ZONE; +class PCB_TEXT; +class PCB_SHAPE; +class ZONE; class PAD; class SHAPE_POLY_SET; class SETTINGS_MANAGER; @@ -171,11 +171,11 @@ void CheckFootprint( const FOOTPRINT* expected, const FOOTPRINT* fp ); void CheckFpPad( const PAD* expected, const PAD* pad ); -void CheckFpText( const FP_TEXT* expected, const FP_TEXT* text ); +void CheckFpText( const PCB_TEXT* expected, const PCB_TEXT* text ); -void CheckFpShape( const FP_SHAPE* expected, const FP_SHAPE* shape ); +void CheckFpShape( const PCB_SHAPE* expected, const PCB_SHAPE* shape ); -void CheckFpZone( const FP_ZONE* expected, const FP_ZONE* zone ); +void CheckFpZone( const ZONE* expected, const ZONE* zone ); void CheckShapePolySet( const SHAPE_POLY_SET* expected, const SHAPE_POLY_SET* polyset ); diff --git a/qa/unittests/common/test_eda_shape.cpp b/qa/unittests/common/test_eda_shape.cpp index 7319c3220e..dee9da28e7 100644 --- a/qa/unittests/common/test_eda_shape.cpp +++ b/qa/unittests/common/test_eda_shape.cpp @@ -29,10 +29,6 @@ class EDA_SHAPE_MOCK : public EDA_SHAPE { public: EDA_SHAPE_MOCK( SHAPE_T aShapeType ) : EDA_SHAPE( aShapeType, 0, FILL_T::NO_FILL ){}; - -protected: - EDA_ANGLE getParentOrientation() const override { return ANGLE_0; } - VECTOR2I getParentPosition() const override { return VECTOR2I(); } }; diff --git a/qa/unittests/pcbnew/plugins/altium/test_altium_pcblib_import.cpp b/qa/unittests/pcbnew/plugins/altium/test_altium_pcblib_import.cpp index 30cf0bfd8e..a7bf042c33 100644 --- a/qa/unittests/pcbnew/plugins/altium/test_altium_pcblib_import.cpp +++ b/qa/unittests/pcbnew/plugins/altium/test_altium_pcblib_import.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -34,8 +34,6 @@ #include #include -#include -#include #include #include @@ -97,8 +95,8 @@ BOOST_AUTO_TEST_CASE( AltiumPcbLibImport ) BOOST_CHECK_EQUAL( wxT( "REF**" ), altiumFp->GetReference() ); BOOST_CHECK_EQUAL( footprintName, altiumFp->GetValue() ); - FOOTPRINT* kicadFp = - kicadPlugin.FootprintLoad( kicadLibraryPath, footprintName, true, nullptr ); + FOOTPRINT* kicadFp = kicadPlugin.FootprintLoad( kicadLibraryPath, footprintName, + true, nullptr ); BOOST_CHECK( kicadFp ); KI_TEST::CheckFootprint( kicadFp, altiumFp ); diff --git a/qa/unittests/pcbnew/plugins/eagle/test_eagle_lbr_import.cpp b/qa/unittests/pcbnew/plugins/eagle/test_eagle_lbr_import.cpp index 0e73b3f341..cf75a4e2a1 100644 --- a/qa/unittests/pcbnew/plugins/eagle/test_eagle_lbr_import.cpp +++ b/qa/unittests/pcbnew/plugins/eagle/test_eagle_lbr_import.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -34,8 +34,6 @@ #include #include -#include -#include #include #include diff --git a/qa/unittests/pcbnew/test_board_item.cpp b/qa/unittests/pcbnew/test_board_item.cpp index 1e81c99046..4f5a016322 100644 --- a/qa/unittests/pcbnew/test_board_item.cpp +++ b/qa/unittests/pcbnew/test_board_item.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2022 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,15 +35,11 @@ #include #include #include -#include -#include -#include #include #include #include #include #include -#include #include class TEST_BOARD_ITEM_FIXTURE @@ -83,26 +79,6 @@ public: case PCB_TEXT_T: return new PCB_TEXT( &m_board ); case PCB_TEXTBOX_T: return new PCB_TEXTBOX( &m_board ); case PCB_BITMAP_T: return new PCB_BITMAP( &m_board ); - case PCB_FP_TEXT_T: return new FP_TEXT( &m_footprint ); - case PCB_FP_TEXTBOX_T: return new FP_TEXTBOX( &m_footprint ); - case PCB_FP_SHAPE_T: return new FP_SHAPE( &m_footprint ); - case PCB_FP_DIM_ALIGNED_T: return new PCB_DIM_ALIGNED( &m_footprint, PCB_FP_DIM_ALIGNED_T ); - case PCB_FP_DIM_LEADER_T: return new PCB_DIM_LEADER( &m_footprint, true ); - case PCB_FP_DIM_CENTER_T: return new PCB_DIM_CENTER( &m_footprint, true ); - case PCB_FP_DIM_RADIAL_T: return new PCB_DIM_RADIAL( &m_footprint, true ); - case PCB_FP_DIM_ORTHOGONAL_T: return new PCB_DIM_ORTHOGONAL( &m_footprint, true ); - case PCB_FP_ZONE_T: - { - FP_ZONE* fpZone = new FP_ZONE( &m_footprint ); - - fpZone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( -100 ), pcbIUScale.mmToIU( -50 ) ), -1 ); - fpZone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( -100 ), pcbIUScale.mmToIU( 50 ) ), -1 ); - fpZone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 100 ), pcbIUScale.mmToIU( 50 ) ), -1 ); - fpZone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 100 ), pcbIUScale.mmToIU( -50 ) ), -1 ); - - return fpZone; - } - case PCB_TRACE_T: return new PCB_TRACK( &m_board ); case PCB_VIA_T: return new PCB_VIA( &m_board ); case PCB_ARC_T: return new PCB_ARC( &m_board ); @@ -183,11 +159,6 @@ BOOST_AUTO_TEST_CASE( Move ) item.get(), []( BOARD_ITEM* aOriginalItem, VECTOR2I aRef ) { - FP_SHAPE* originalFpShape = dynamic_cast( aOriginalItem ); - - if( originalFpShape != nullptr ) - originalFpShape->SetDrawCoord(); - // FIXME: Update() has to be called after SetPosition() to update dimension // shapes. PCB_DIMENSION_BASE* originalDimension = @@ -203,19 +174,9 @@ BOOST_AUTO_TEST_CASE( Move ) // This has to be an identity transformation. item->Move( aRef ); - - FP_SHAPE* fpShape = dynamic_cast( item.get() ); - - if( fpShape != nullptr ) - fpShape->SetDrawCoord(); - BOOST_CHECK_EQUAL( item->GetPosition(), originalPos + aRef ); item->Move( -aRef ); - - if( fpShape != nullptr ) - fpShape->SetDrawCoord(); - CompareItems( item.get(), aOriginalItem ); } ); } @@ -242,11 +203,6 @@ BOOST_AUTO_TEST_CASE( Rotate ) item.get(), []( BOARD_ITEM* aOriginalItem, VECTOR2I aRef ) { - FP_SHAPE* originalFpShape = dynamic_cast( aOriginalItem ); - - if( originalFpShape != nullptr ) - originalFpShape->SetDrawCoord(); - // FIXME: Update() has to be called after SetPosition() to update dimension // shapes. PCB_DIMENSION_BASE* originalDimension = @@ -264,11 +220,6 @@ BOOST_AUTO_TEST_CASE( Rotate ) item->Rotate( aRef, EDA_ANGLE( 90.0, DEGREES_T ) ); item->Rotate( aRef, EDA_ANGLE( 90.0, DEGREES_T ) ); - FP_SHAPE* fpShape = dynamic_cast( aOriginalItem ); - - if( fpShape != nullptr ) - fpShape->SetDrawCoord(); - CompareItems( item.get(), aOriginalItem ); } ); } @@ -293,11 +244,6 @@ BOOST_AUTO_TEST_CASE( FlipLeftRight ) item.get(), []( BOARD_ITEM* aOriginalItem, VECTOR2I aRef ) { - FP_SHAPE* originalFpShape = dynamic_cast( aOriginalItem ); - - if( originalFpShape != nullptr ) - originalFpShape->SetDrawCoord(); - // FIXME: Update() has to be called after SetPosition() to update dimension // shapes. PCB_DIMENSION_BASE* originalDimension = @@ -313,11 +259,6 @@ BOOST_AUTO_TEST_CASE( FlipLeftRight ) item->Flip( aRef, true ); item->Flip( aRef, true ); - FP_SHAPE* fpShape = dynamic_cast( aOriginalItem ); - - if( fpShape != nullptr ) - fpShape->SetDrawCoord(); - CompareItems( item.get(), aOriginalItem ); } ); } @@ -342,11 +283,6 @@ BOOST_AUTO_TEST_CASE( FlipUpDown ) item.get(), []( BOARD_ITEM* aOriginalItem, VECTOR2I aRef ) { - FP_SHAPE* originalFpShape = dynamic_cast( aOriginalItem ); - - if( originalFpShape != nullptr ) - originalFpShape->SetDrawCoord(); - // FIXME: Update() has to be called after SetPosition() to update dimension // shapes. PCB_DIMENSION_BASE* originalDimension = @@ -362,11 +298,6 @@ BOOST_AUTO_TEST_CASE( FlipUpDown ) item->Flip( aRef, false ); item->Flip( aRef, false ); - FP_SHAPE* fpShape = dynamic_cast( aOriginalItem ); - - if( fpShape != nullptr ) - fpShape->SetDrawCoord(); - CompareItems( item.get(), aOriginalItem ); } ); }