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
// 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;

View File

@ -304,9 +304,14 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& 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<PCB_SHAPE*>& 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<PCB_SHAPE*>& 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;

View File

@ -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 );

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 )
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<wxPoint> PCB_SHAPE::GetRectCorners() const
{
std::vector<wxPoint> pts;
MODULE* module = GetParentModule();
MODULE* module = GetParentFootprint();
wxPoint topLeft = GetStart();
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
* belong to a module.
* @return MODULE* - pointer to the parent module or NULL.
*/
MODULE* GetParentModule() const;
MODULE* GetParentFootprint() const;
// Accessors:
const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; }
@ -235,7 +235,8 @@ public:
*/
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;

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
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<wxPoint> &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<wxPoint> cornerList;

View File

@ -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,13 +118,12 @@ 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 );
EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS, sTool );
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 );
if( FP_SHAPE* graphic = dynamic_cast<FP_SHAPE*>( 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 );
@ -572,8 +573,10 @@ 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 );
}
}
} );
EDA_ITEM* source = selection.Front();

View File

@ -233,14 +233,14 @@ bool EDIT_TOOL::Init()
int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
{
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::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<BOARD_ITEM*>( item );
MODULE* module = dynamic_cast<MODULE*>( item );
MODULE* footprint = dynamic_cast<MODULE*>( 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 );
}
}