Module -> footprint.

This commit is contained in:
Jeff Young 2020-11-07 17:35:24 +00:00
parent bfd8a62852
commit 7c60c2e404
8 changed files with 112 additions and 88 deletions

View File

@ -454,12 +454,12 @@ void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuf
{ {
// The polygon is expected to be a simple polygon // The polygon is expected to be a simple polygon
// not self intersecting, no hole. // not self intersecting, no hole.
MODULE* module = GetParentModule(); // NULL for items not in footprints MODULE* footprint = GetParentFootprint(); // NULL for items not in footprints
double orientation = module ? module->GetOrientation() : 0.0; double orientation = footprint ? footprint->GetOrientation() : 0.0;
wxPoint offset; wxPoint offset;
if( module ) if( footprint )
offset = module->GetPosition(); offset = footprint->GetPosition();
// Build the polygon with the actual position and orientation: // Build the polygon with the actual position and orientation:
std::vector< wxPoint> poly; std::vector< wxPoint> poly;

View File

@ -304,9 +304,14 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
case S_POLYGON: case S_POLYGON:
{ {
const SHAPE_POLY_SET poly = graphic->GetPolyShape(); const SHAPE_POLY_SET poly = graphic->GetPolyShape();
MODULE* module = aSegList[0]->GetParentModule(); double orientation = 0.0;
double orientation = module ? module->GetOrientation() : 0.0; VECTOR2I offset = VECTOR2I( 0, 0 );
VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 );
if( aSegList[0]->GetParentFootprint() )
{
orientation = aSegList[0]->GetParentFootprint()->GetOrientation();
offset = aSegList[0]->GetParentFootprint()->GetPosition();
}
for( auto iter = poly.CIterate(); iter; iter++ ) for( auto iter = poly.CIterate(); iter; iter++ )
{ {
@ -358,15 +363,20 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
} }
else if( graphic->GetShape() == S_POLYGON ) else if( graphic->GetShape() == S_POLYGON )
{ {
MODULE* module = graphic->GetParentModule(); // NULL for items not in footprints double orientation = 0.0;
double orientation = module ? module->GetOrientation() : 0.0; VECTOR2I offset = VECTOR2I( 0, 0 );
VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 );
if( graphic->GetParentFootprint() )
{
orientation = graphic->GetParentFootprint()->GetOrientation();
offset = graphic->GetParentFootprint()->GetPosition();
}
aPolygons.NewOutline(); aPolygons.NewOutline();
for( auto it = graphic->GetPolyShape().CIterate( 0 ); it; it++ ) for( auto it = graphic->GetPolyShape().CIterate( 0 ); it; it++ )
{ {
auto pt = *it; VECTOR2I pt = *it;
RotatePoint( pt, orientation ); RotatePoint( pt, orientation );
pt += offset; pt += offset;
aPolygons.Append( pt ); aPolygons.Append( pt );
@ -542,13 +552,18 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
// do not connect to other elements, so we process them independently // do not connect to other elements, so we process them independently
if( graphic->GetShape() == S_POLYGON ) if( graphic->GetShape() == S_POLYGON )
{ {
MODULE* module = graphic->GetParentModule(); // NULL for items not in footprints double orientation = 0.0;
double orientation = module ? module->GetOrientation() : 0.0; VECTOR2I offset = VECTOR2I( 0, 0 );
VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 );
if( graphic->GetParentFootprint() )
{
orientation = graphic->GetParentFootprint()->GetOrientation();
offset = graphic->GetParentFootprint()->GetPosition();
}
for( auto it = graphic->GetPolyShape().CIterate(); it; it++ ) for( auto it = graphic->GetPolyShape().CIterate(); it; it++ )
{ {
auto val = *it; VECTOR2I val = *it;
RotatePoint( val, orientation ); RotatePoint( val, orientation );
val += offset; val += offset;

View File

@ -1195,10 +1195,10 @@ void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
m_gal->Save(); m_gal->Save();
if( MODULE* module = aShape->GetParentModule() ) if( MODULE* parentFootprint = aShape->GetParentFootprint() )
{ {
m_gal->Translate( module->GetPosition() ); m_gal->Translate( parentFootprint->GetPosition() );
m_gal->Rotate( -module->GetOrientationRadians() ); m_gal->Rotate( -parentFootprint->GetOrientationRadians() );
} }
m_gal->SetLineWidth( thickness ); m_gal->SetLineWidth( thickness );

View File

@ -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 ) if( !m_Parent || m_Parent->Type() != PCB_MODULE_T )
return NULL; return NULL;
@ -580,7 +580,7 @@ const EDA_RECT PCB_SHAPE::GetBoundingBox() const
if( m_Poly.IsEmpty() ) if( m_Poly.IsEmpty() )
break; break;
MODULE* module = GetParentModule(); MODULE* module = GetParentFootprint();
bbox = EDA_RECT(); // re-init for merging bbox = EDA_RECT(); // re-init for merging
for( auto iter = m_Poly.CIterate(); iter; iter++ ) for( auto iter = m_Poly.CIterate(); iter; iter++ )
@ -942,7 +942,7 @@ const BOX2I PCB_SHAPE::ViewBBox() const
std::vector<wxPoint> PCB_SHAPE::GetRectCorners() const std::vector<wxPoint> PCB_SHAPE::GetRectCorners() const
{ {
std::vector<wxPoint> pts; std::vector<wxPoint> pts;
MODULE* module = GetParentModule(); MODULE* module = GetParentFootprint();
wxPoint topLeft = GetStart(); wxPoint topLeft = GetStart();
wxPoint botRight = GetEnd(); wxPoint botRight = GetEnd();

View File

@ -218,12 +218,12 @@ public:
} }
/** /**
* Function GetParentModule * Function GetParentFootprint
* returns a pointer to the parent module, or NULL if PCB_SHAPE does not * returns a pointer to the parent module, or NULL if PCB_SHAPE does not
* belong to a module. * belong to a module.
* @return MODULE* - pointer to the parent module or NULL. * @return MODULE* - pointer to the parent module or NULL.
*/ */
MODULE* GetParentModule() const; MODULE* GetParentFootprint() const;
// Accessors: // Accessors:
const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; } const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; }
@ -235,7 +235,8 @@ public:
*/ */
const std::vector<wxPoint> BuildPolyPointsList() const; const std::vector<wxPoint> BuildPolyPointsList() const;
/** @return the number of corners of the polygonal shape /**
* @return the number of corners of the polygonal shape
*/ */
int GetPointCount() const; int GetPointCount() const;

View File

@ -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 // when startAngle == endAngle ThickArc() doesn't know whether it's 0 deg and 360 deg
if( std::abs( aShape->GetAngle() ) == 3600.0 ) if( std::abs( aShape->GetAngle() ) == 3600.0 )
{
m_plotter->ThickCircle( pos, radius * 2, thickness, GetPlotMode(), &gbr_metadata ); m_plotter->ThickCircle( pos, radius * 2, thickness, GetPlotMode(), &gbr_metadata );
}
else else
m_plotter->ThickArc( pos, -endAngle, -startAngle, radius, thickness, GetPlotMode(), &gbr_metadata ); {
m_plotter->ThickArc( pos, -endAngle, -startAngle, radius, thickness, GetPlotMode(),
&gbr_metadata );
}
} }
break; break;
@ -615,9 +620,9 @@ void BRDITEMS_PLOTTER::PlotFootprintGraphicItem( FP_SHAPE* aShape )
{ {
const std::vector<wxPoint> &polyPoints = aShape->BuildPolyPointsList(); const std::vector<wxPoint> &polyPoints = aShape->BuildPolyPointsList();
// We must compute true coordinates from m_PolyList // We must compute board coordinates from m_PolyList which are relative to the parent
// which are relative to module position, orientation 0 // position at orientation 0
MODULE *module = aShape->GetParentModule(); MODULE *module = aShape->GetParentFootprint();
std::vector<wxPoint> cornerList; std::vector<wxPoint> cornerList;

View File

@ -44,8 +44,10 @@
CONVERT_TOOL::CONVERT_TOOL() : CONVERT_TOOL::CONVERT_TOOL() :
TOOL_INTERACTIVE( "pcbnew.Convert" ), m_selectionTool( NULL ), TOOL_INTERACTIVE( "pcbnew.Convert" ),
m_menu( NULL ), m_frame( NULL ) m_selectionTool( NULL ),
m_menu( NULL ),
m_frame( NULL )
{ {
} }
@ -116,13 +118,12 @@ bool CONVERT_TOOL::Init()
int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent )
{ {
MODULE* mod = nullptr; MODULE* parentFootprint = nullptr;
auto& selection = m_selectionTool->RequestSelection( auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
{ {
EditToolSelectionFilter( aCollector, EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS, sTool );
EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS, sTool );
for( int i = aCollector.GetCount() - 1; i >= 0; --i ) for( int i = aCollector.GetCount() - 1; i >= 0; --i )
{ {
@ -173,7 +174,7 @@ int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent )
bool isFootprint = m_frame->IsType( FRAME_FOOTPRINT_EDITOR ); bool isFootprint = m_frame->IsType( FRAME_FOOTPRINT_EDITOR );
if( FP_SHAPE* graphic = dynamic_cast<FP_SHAPE*>( selection.Front() ) ) if( FP_SHAPE* graphic = dynamic_cast<FP_SHAPE*>( selection.Front() ) )
mod = graphic->GetParentModule(); parentFootprint = graphic->GetParentFootprint();
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
@ -187,7 +188,7 @@ int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent )
{ {
for( const SHAPE_POLY_SET& poly : polys ) 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->SetShape( S_POLYGON );
graphic->SetLayer( destLayer ); graphic->SetLayer( destLayer );
@ -572,8 +573,10 @@ int CONVERT_TOOL::SegmentToArc( const TOOL_EVENT& aEvent )
if( !( item->Type() == PCB_SHAPE_T || if( !( item->Type() == PCB_SHAPE_T ||
item->Type() == PCB_TRACE_T || item->Type() == PCB_TRACE_T ||
item->Type() == PCB_FP_SHAPE_T ) ) item->Type() == PCB_FP_SHAPE_T ) )
{
aCollector.Remove( item ); aCollector.Remove( item );
} }
}
} ); } );
EDA_ITEM* source = selection.Front(); EDA_ITEM* source = selection.Front();

View File

@ -233,14 +233,14 @@ bool EDIT_TOOL::Init()
int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent ) int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
{ {
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>(); SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
MODULE* module = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference(); MODULE* fp = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference();
if( module ) if( fp )
{ {
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); 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 ); 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 ) for( EDA_ITEM* item : selection )
{ {
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ); BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
MODULE* module = dynamic_cast<MODULE*>( item ); MODULE* footprint = dynamic_cast<MODULE*>( item );
if( boardItem ) if( boardItem )
sel_items.push_back( 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 ); sel_items.push_back( pad );
} }
} }