From 7c60c2e404a012c4e62791fc2c436c7e3029ce82 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 7 Nov 2020 17:35:24 +0000 Subject: [PATCH] Module -> footprint. --- ...board_items_to_polygon_shape_transform.cpp | 8 +- .../convert_drawsegment_list_to_polygon.cpp | 37 ++++-- pcbnew/pcb_painter.cpp | 6 +- pcbnew/pcb_shape.cpp | 6 +- pcbnew/pcb_shape.h | 7 +- pcbnew/plot_brditems_plotter.cpp | 13 ++- pcbnew/tools/convert_tool.cpp | 109 +++++++++--------- pcbnew/tools/edit_tool.cpp | 14 +-- 8 files changed, 112 insertions(+), 88 deletions(-) diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index 7681f85819..2539eb7d38 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -454,12 +454,12 @@ void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf { // The polygon is expected to be a simple polygon // not self intersecting, no hole. - MODULE* module = GetParentModule(); // NULL for items not in footprints - double orientation = module ? module->GetOrientation() : 0.0; + MODULE* footprint = GetParentFootprint(); // NULL for items not in footprints + double orientation = footprint ? footprint->GetOrientation() : 0.0; wxPoint offset; - if( module ) - offset = module->GetPosition(); + if( footprint ) + offset = footprint->GetPosition(); // Build the polygon with the actual position and orientation: std::vector< wxPoint> poly; diff --git a/pcbnew/convert_drawsegment_list_to_polygon.cpp b/pcbnew/convert_drawsegment_list_to_polygon.cpp index ddb0692d47..c5e3381fe3 100644 --- a/pcbnew/convert_drawsegment_list_to_polygon.cpp +++ b/pcbnew/convert_drawsegment_list_to_polygon.cpp @@ -304,9 +304,14 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SET& case S_POLYGON: { const SHAPE_POLY_SET poly = graphic->GetPolyShape(); - MODULE* module = aSegList[0]->GetParentModule(); - double orientation = module ? module->GetOrientation() : 0.0; - VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 ); + double orientation = 0.0; + VECTOR2I offset = VECTOR2I( 0, 0 ); + + if( aSegList[0]->GetParentFootprint() ) + { + orientation = aSegList[0]->GetParentFootprint()->GetOrientation(); + offset = aSegList[0]->GetParentFootprint()->GetPosition(); + } for( auto iter = poly.CIterate(); iter; iter++ ) { @@ -358,15 +363,20 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SET& } else if( graphic->GetShape() == S_POLYGON ) { - MODULE* module = graphic->GetParentModule(); // NULL for items not in footprints - double orientation = module ? module->GetOrientation() : 0.0; - VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 ); + double orientation = 0.0; + VECTOR2I offset = VECTOR2I( 0, 0 ); + + if( graphic->GetParentFootprint() ) + { + orientation = graphic->GetParentFootprint()->GetOrientation(); + offset = graphic->GetParentFootprint()->GetPosition(); + } aPolygons.NewOutline(); for( auto it = graphic->GetPolyShape().CIterate( 0 ); it; it++ ) { - auto pt = *it; + VECTOR2I pt = *it; RotatePoint( pt, orientation ); pt += offset; aPolygons.Append( pt ); @@ -542,13 +552,18 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SET& // do not connect to other elements, so we process them independently if( graphic->GetShape() == S_POLYGON ) { - MODULE* module = graphic->GetParentModule(); // NULL for items not in footprints - double orientation = module ? module->GetOrientation() : 0.0; - VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 ); + double orientation = 0.0; + VECTOR2I offset = VECTOR2I( 0, 0 ); + + if( graphic->GetParentFootprint() ) + { + orientation = graphic->GetParentFootprint()->GetOrientation(); + offset = graphic->GetParentFootprint()->GetPosition(); + } for( auto it = graphic->GetPolyShape().CIterate(); it; it++ ) { - auto val = *it; + VECTOR2I val = *it; RotatePoint( val, orientation ); val += offset; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 90d6a8b9b6..a87036063d 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1195,10 +1195,10 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer ) m_gal->Save(); - if( MODULE* module = aShape->GetParentModule() ) + if( MODULE* parentFootprint = aShape->GetParentFootprint() ) { - m_gal->Translate( module->GetPosition() ); - m_gal->Rotate( -module->GetOrientationRadians() ); + m_gal->Translate( parentFootprint->GetPosition() ); + m_gal->Rotate( -parentFootprint->GetOrientationRadians() ); } m_gal->SetLineWidth( thickness ); diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp index 76bbdbd3be..c96d65323f 100644 --- a/pcbnew/pcb_shape.cpp +++ b/pcbnew/pcb_shape.cpp @@ -454,7 +454,7 @@ void PCB_SHAPE::SetAngle( double aAngle, bool aUpdateEnd ) } -MODULE* PCB_SHAPE::GetParentModule() const +MODULE* PCB_SHAPE::GetParentFootprint() const { if( !m_Parent || m_Parent->Type() != PCB_MODULE_T ) return NULL; @@ -580,7 +580,7 @@ const EDA_RECT PCB_SHAPE::GetBoundingBox() const if( m_Poly.IsEmpty() ) break; - MODULE* module = GetParentModule(); + MODULE* module = GetParentFootprint(); bbox = EDA_RECT(); // re-init for merging for( auto iter = m_Poly.CIterate(); iter; iter++ ) @@ -942,7 +942,7 @@ const BOX2I PCB_SHAPE::ViewBBox() const std::vector PCB_SHAPE::GetRectCorners() const { std::vector pts; - MODULE* module = GetParentModule(); + MODULE* module = GetParentFootprint(); wxPoint topLeft = GetStart(); wxPoint botRight = GetEnd(); diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h index 65f1d1a704..771177b269 100644 --- a/pcbnew/pcb_shape.h +++ b/pcbnew/pcb_shape.h @@ -218,12 +218,12 @@ public: } /** - * Function GetParentModule + * Function GetParentFootprint * returns a pointer to the parent module, or NULL if PCB_SHAPE does not * belong to a module. * @return MODULE* - pointer to the parent module or NULL. */ - MODULE* GetParentModule() const; + MODULE* GetParentFootprint() const; // Accessors: const std::vector& GetBezierPoints() const { return m_BezierPoints; } @@ -235,7 +235,8 @@ public: */ const std::vector BuildPolyPointsList() const; - /** @return the number of corners of the polygonal shape + /** + * @return the number of corners of the polygonal shape */ int GetPointCount() const; diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 80f889b607..9758fd7967 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -604,9 +604,14 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( FP_SHAPE* aShape ) // when startAngle == endAngle ThickArc() doesn't know whether it's 0 deg and 360 deg if( std::abs( aShape->GetAngle() ) == 3600.0 ) + { m_plotter->ThickCircle( pos, radius * 2, thickness, GetPlotMode(), &gbr_metadata ); + } else - m_plotter->ThickArc( pos, -endAngle, -startAngle, radius, thickness, GetPlotMode(), &gbr_metadata ); + { + m_plotter->ThickArc( pos, -endAngle, -startAngle, radius, thickness, GetPlotMode(), + &gbr_metadata ); + } } break; @@ -615,9 +620,9 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( FP_SHAPE* aShape ) { const std::vector &polyPoints = aShape->BuildPolyPointsList(); - // We must compute true coordinates from m_PolyList - // which are relative to module position, orientation 0 - MODULE *module = aShape->GetParentModule(); + // We must compute board coordinates from m_PolyList which are relative to the parent + // position at orientation 0 + MODULE *module = aShape->GetParentFootprint(); std::vector cornerList; diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index 074f97f4ea..53d3f2cb65 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -44,8 +44,10 @@ CONVERT_TOOL::CONVERT_TOOL() : - TOOL_INTERACTIVE( "pcbnew.Convert" ), m_selectionTool( NULL ), - m_menu( NULL ), m_frame( NULL ) + TOOL_INTERACTIVE( "pcbnew.Convert" ), + m_selectionTool( NULL ), + m_menu( NULL ), + m_frame( NULL ) { } @@ -116,44 +118,43 @@ bool CONVERT_TOOL::Init() int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) { - MODULE* mod = nullptr; + MODULE* parentFootprint = nullptr; auto& selection = m_selectionTool->RequestSelection( - []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) - { - EditToolSelectionFilter( aCollector, - EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS, sTool ); - - for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - BOARD_ITEM* item = aCollector[i]; + EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS, sTool ); - switch( item->Type() ) + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) { - case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: - switch( static_cast( item )->GetShape() ) + BOARD_ITEM* item = aCollector[i]; + + switch( item->Type() ) { - case S_SEGMENT: - case S_RECT: + case PCB_SHAPE_T: + case PCB_FP_SHAPE_T: + switch( static_cast( item )->GetShape() ) + { + case S_SEGMENT: + case S_RECT: // case S_ARC: // Not yet + break; + + default: + aCollector.Remove( item ); + } + + break; + + case PCB_TRACE_T: + // case PCB_ARC_T: // Not yet break; default: aCollector.Remove( item ); } - - break; - - case PCB_TRACE_T: - // case PCB_ARC_T: // Not yet - break; - - default: - aCollector.Remove( item ); } - } - } ); + } ); if( selection.Empty() ) return 0; @@ -173,7 +174,7 @@ int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) bool isFootprint = m_frame->IsType( FRAME_FOOTPRINT_EDITOR ); if( FP_SHAPE* graphic = dynamic_cast( selection.Front() ) ) - mod = graphic->GetParentModule(); + parentFootprint = graphic->GetParentFootprint(); BOARD_COMMIT commit( m_frame ); @@ -187,7 +188,7 @@ int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) { for( const SHAPE_POLY_SET& poly : polys ) { - PCB_SHAPE* graphic = isFootprint ? new FP_SHAPE( mod ) : new PCB_SHAPE; + PCB_SHAPE* graphic = isFootprint ? new FP_SHAPE( parentFootprint ) : new PCB_SHAPE; graphic->SetShape( S_POLYGON ); graphic->SetLayer( destLayer ); @@ -363,42 +364,42 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromRects( const std::deque& aI int CONVERT_TOOL::PolyToLines( const TOOL_EVENT& aEvent ) { auto& selection = m_selectionTool->RequestSelection( - []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) - { - EditToolSelectionFilter( aCollector, - EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS, sTool ); - - for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - BOARD_ITEM* item = aCollector[i]; + EditToolSelectionFilter( aCollector, + EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS, sTool ); - switch( item->Type() ) + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) { - case PCB_SHAPE_T: - case PCB_FP_SHAPE_T: - switch( static_cast( item )->GetShape() ) + BOARD_ITEM* item = aCollector[i]; + + switch( item->Type() ) { - case S_POLYGON: + case PCB_SHAPE_T: + case PCB_FP_SHAPE_T: + switch( static_cast( item )->GetShape() ) + { + case S_POLYGON: + break; + + case S_RECT: + break; + + default: + aCollector.Remove( item ); + } + break; - case S_RECT: + case PCB_ZONE_AREA_T: + case PCB_FP_ZONE_AREA_T: break; default: aCollector.Remove( item ); } - - break; - - case PCB_ZONE_AREA_T: - case PCB_FP_ZONE_AREA_T: - break; - - default: - aCollector.Remove( item ); } - } - } ); + } ); if( selection.Empty() ) return 0; @@ -572,7 +573,9 @@ int CONVERT_TOOL::SegmentToArc( const TOOL_EVENT& aEvent ) if( !( item->Type() == PCB_SHAPE_T || item->Type() == PCB_TRACE_T || item->Type() == PCB_FP_SHAPE_T ) ) + { aCollector.Remove( item ); + } } } ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index d01d0882fa..b068f877d2 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -233,14 +233,14 @@ bool EDIT_TOOL::Init() int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent ) { SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - MODULE* module = getEditFrame()->GetFootprintFromBoardByReference(); + MODULE* fp = getEditFrame()->GetFootprintFromBoardByReference(); - if( module ) + if( fp ) { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, (void*) module ); + m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, (void*) fp ); - selectionTool->GetSelection().SetReferencePoint( module->GetPosition() ); + selectionTool->GetSelection().SetReferencePoint( fp->GetPosition() ); m_toolMgr->RunAction( PCB_ACTIONS::move, false ); } @@ -390,14 +390,14 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) for( EDA_ITEM* item : selection ) { BOARD_ITEM* boardItem = dynamic_cast( item ); - MODULE* module = dynamic_cast( item ); + MODULE* footprint = dynamic_cast( item ); if( boardItem ) sel_items.push_back( boardItem ); - if( module ) + if( footprint ) { - for( D_PAD* pad : module->Pads() ) + for( D_PAD* pad : footprint->Pads() ) sel_items.push_back( pad ); } }