Improve readability of flag checking.

This commit is contained in:
Jeff Young 2019-08-27 13:12:34 +01:00
parent 49a0907c55
commit a5a237ac32
14 changed files with 38 additions and 43 deletions

View File

@ -253,7 +253,7 @@ LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
for( LIB_ITEM& oldItem : aPart.m_drawings )
{
if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
if( oldItem.HasFlag( IS_NEW ) || oldItem.HasFlag( STRUCT_DELETED ) )
continue;
newItem = (LIB_ITEM*) oldItem.Clone();
@ -261,11 +261,8 @@ LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
m_drawings.push_back( newItem );
}
for( size_t i = 0; i < aPart.m_aliases.size(); i++ )
{
LIB_ALIAS* alias = new LIB_ALIAS( *aPart.m_aliases[i], this );
m_aliases.push_back( alias );
}
for( LIB_ALIAS* alias : aPart.m_aliases )
m_aliases.emplace_back( new LIB_ALIAS( *alias, this ) );
}

View File

@ -624,7 +624,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
}
else
{
if( ( aPin->GetFlags() & IS_DANGLING ) && aPin->IsPowerConnection() )
if( aPin->HasFlag( IS_DANGLING ) && aPin->IsPowerConnection() )
drawPinDanglingSymbol( pos, drawingShadows );
return;
@ -749,7 +749,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
aPin->ClearFlags( IS_DANGLING ); // PIN_NC pin type is always not connected and dangling.
}
if( ( aPin->GetFlags() & IS_DANGLING ) && ( aPin->IsVisible() || aPin->IsPowerConnection() ) )
if( aPin->HasFlag( IS_DANGLING ) && ( aPin->IsVisible() || aPin->IsPowerConnection() ) )
drawPinDanglingSymbol( pos, drawingShadows );
// Draw the labels

View File

@ -309,7 +309,7 @@ void SCH_SCREEN::MarkConnections( SCH_LINE* aSegment )
for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
{
if( item->GetFlags() & CANDIDATE )
if( item->HasFlag( CANDIDATE ) )
continue;
if( item->Type() == SCH_JUNCTION_T )

View File

@ -561,9 +561,9 @@ void EE_POINT_EDITOR::updateItem() const
if( connection )
{
if( ( connection->GetFlags() & STARTPOINT ) != 0 )
if( connection->HasFlag( STARTPOINT ) )
connection->SetStartPoint( line->GetPosition() );
else if( ( connection->GetFlags() & ENDPOINT ) != 0 )
else if( connection->HasFlag( ENDPOINT ) )
connection->SetEndPoint( line->GetPosition() );
getView()->Update( connection, KIGFX::GEOMETRY );
@ -573,9 +573,9 @@ void EE_POINT_EDITOR::updateItem() const
if( connection )
{
if( ( connection->GetFlags() & STARTPOINT ) != 0 )
if( connection->HasFlag( STARTPOINT ) )
connection->SetStartPoint( line->GetEndPoint() );
else if( ( connection->GetFlags() & ENDPOINT ) != 0 )
else if( connection->HasFlag( ENDPOINT ) )
connection->SetEndPoint( line->GetEndPoint() );
getView()->Update( connection, KIGFX::GEOMETRY );

View File

@ -829,7 +829,7 @@ int EE_SELECTION_TOOL::SelectConnection( const TOOL_EVENT& aEvent )
for( EDA_ITEM* item = m_frame->GetScreen()->GetDrawItems(); item; item = item->Next() )
{
if( item->GetFlags() & CANDIDATE )
if( item->HasFlag( CANDIDATE ) )
select( item );
}

View File

@ -620,7 +620,7 @@ int LIB_EDIT_TOOL::Copy( const TOOL_EVENT& aEvent )
if( item.Type() == LIB_FIELD_T )
continue;
wxASSERT( ( item.GetFlags() & STRUCT_DELETED ) == 0 );
wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
if( !item.IsSelected() )
item.SetFlags( STRUCT_DELETED );

View File

@ -143,7 +143,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
//
m_cursor = controls->GetCursorPosition();
if( ( lib_item->GetFlags() & IS_NEW ) != 0 )
if( lib_item->IsNew() )
{
m_anchorPos = selection.GetReferencePoint();
VECTOR2I delta = m_cursor - mapCoords( m_anchorPos );

View File

@ -172,7 +172,7 @@ bool LIB_PIN_TOOL::PlacePin( LIB_PIN* aPin )
}
}
if( aPin->IsNew() && !( aPin->GetFlags() & IS_PASTED ) )
if( aPin->IsNew() && !aPin->HasFlag( IS_PASTED ) )
{
g_LastPinOrient = aPin->GetOrientation();
g_LastPinType = aPin->GetType();

View File

@ -457,10 +457,10 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
{
SCH_LINE* line = (SCH_LINE*) item;
if( item->GetFlags() & STARTPOINT )
if( item->HasFlag( STARTPOINT ) )
line->RotateStart( rotPoint );
if( item->GetFlags() & ENDPOINT )
if( item->HasFlag( ENDPOINT ) )
line->RotateEnd( rotPoint );
}
else if( item->Type() == SCH_SHEET_PIN_T )
@ -934,7 +934,7 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
if( !junction )
continue;
if( ( junction->GetFlags() & STRUCT_DELETED ) > 0 || !screen->IsJunctionNeeded( point ) )
if( junction->HasFlag( STRUCT_DELETED ) || !screen->IsJunctionNeeded( point ) )
m_frame->DeleteJunction( junction, appendToUndo );
}

View File

@ -779,7 +779,7 @@ void SCH_LINE_WIRE_BUS_TOOL::finishSegments()
// Check each new segment for possible junctions and add/split if needed
for( SCH_LINE* wire = s_wires.GetFirst(); wire; wire = wire->Next() )
{
if( wire->GetFlags() & SKIP_STRUCT )
if( wire->HasFlag( SKIP_STRUCT ) )
continue;
wire->GetConnectionPoints( new_ends );

View File

@ -232,7 +232,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{
if( item->IsNew() )
{
if( ( item->GetFlags() & SELECTEDNODE ) != 0 && m_isDragOperation )
if( item->HasFlag( SELECTEDNODE ) && m_isDragOperation )
{
// Item was added in getConnectedDragItems
saveCopyInUndoList( (SCH_ITEM*) item, UR_NEW, appendUndo );
@ -267,7 +267,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{
wxASSERT_MSG( m_anchorPos, "Should be already set from previous cmd" );
}
else if( selection.Front()->GetFlags() & IS_NEW )
else if( selection.Front()->HasFlag( IS_NEW ) )
{
m_anchorPos = selection.GetReferencePoint();
}
@ -294,7 +294,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
else if( selection.Size() == 1 && sch_item->IsMovableFromAnchorPoint()
&& m_frame->GetMoveWarpsCursor() )
{
if( sch_item->Type() == SCH_LINE_T && !( sch_item->GetFlags() & STARTPOINT ) )
if( sch_item->Type() == SCH_LINE_T && !sch_item->HasFlag( STARTPOINT ) )
m_anchorPos = static_cast<SCH_LINE*>( sch_item )->GetEndPoint();
else
m_anchorPos = sch_item->GetPosition();
@ -477,14 +477,14 @@ void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aOriginalItem, wxPoint aPoi
if( testLine->GetStartPoint() == aPoint )
{
if( !( testLine->GetFlags() & SELECTEDNODE ) )
if( !testLine->HasFlag( SELECTEDNODE ) )
aList.push_back( testLine );
testLine->SetFlags( STARTPOINT | SELECTEDNODE );
}
else if( testLine->GetEndPoint() == aPoint )
{
if( !( testLine->GetFlags() & SELECTEDNODE ) )
if( !testLine->HasFlag( SELECTEDNODE ) )
aList.push_back( testLine );
testLine->SetFlags( ENDPOINT | SELECTEDNODE );
@ -550,10 +550,10 @@ void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta, bool isDrag )
switch( aItem->Type() )
{
case SCH_LINE_T:
if( aItem->GetFlags() & STARTPOINT )
if( aItem->HasFlag( STARTPOINT ) )
static_cast<SCH_LINE*>( aItem )->MoveStart( (wxPoint) aDelta );
if( aItem->GetFlags() & ENDPOINT )
if( aItem->HasFlag( ENDPOINT ) )
static_cast<SCH_LINE*>( aItem )->MoveEnd( (wxPoint) aDelta );
break;

View File

@ -265,6 +265,7 @@ public:
void SetFlags( STATUS_FLAGS aMask ) { m_Flags |= aMask; }
void ClearFlags( STATUS_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_Flags &= ~aMask; }
STATUS_FLAGS GetFlags() const { return m_Flags; }
bool HasFlag( STATUS_FLAGS aFlag ) { return ( m_Flags & aFlag ) == aFlag; }
STATUS_FLAGS GetEditFlags() const
{

View File

@ -709,7 +709,7 @@ static void moveNoFlagToVector( ZONE_CONTAINERS& aList, std::vector<BOARD_ITEM*
for( ; obj ; )
{
if( obj->GetFlags() & FLAG0 )
if( obj->HasFlag( FLAG0 ) )
obj->ClearFlags( FLAG0 );
else
aTarget.push_back( obj );

View File

@ -408,15 +408,14 @@ bool TRACKS_CLEANER::cleanupSegments()
{
auto track1 = *it;
if( track1->Type() != PCB_TRACE_T || ( track1->GetFlags() & IS_DELETED )
|| track1->IsLocked() )
if( track1->Type() != PCB_TRACE_T || track1->HasFlag( IS_DELETED ) || track1->IsLocked() )
continue;
for( auto it2 = it + 1; it2 != m_brd->Tracks().end(); it2++ )
{
auto track2 = *it2;
if( track2->GetFlags() & IS_DELETED )
if( track2->HasFlag( IS_DELETED ) )
continue;
if( track1->IsPointOnEnds( track2->GetStart() )
@ -446,7 +445,7 @@ bool TRACKS_CLEANER::cleanupSegments()
if( segment->Type() != PCB_TRACE_T ) // one can merge only track collinear segments, not vias.
continue;
if( segment->GetFlags() & IS_DELETED ) // already taken in account
if( segment->HasFlag( IS_DELETED ) ) // already taken in account
continue;
auto connectivity = m_brd->GetConnectivity();
@ -457,24 +456,22 @@ bool TRACKS_CLEANER::cleanupSegments()
{
for( auto connected : citem->ConnectedItems() )
{
if( !connected->Valid() || connected->Parent()->Type() != PCB_TRACE_T ||
( connected->Parent()->GetFlags() & IS_DELETED ) )
if( !connected->Valid() )
continue;
if( !( connected->Parent()->GetFlags() & IS_DELETED ) )
BOARD_CONNECTED_ITEM* candidateItem = connected->Parent();
if( candidateItem->Type() == PCB_TRACE_T && !candidateItem->HasFlag( IS_DELETED ) )
{
TRACK* candidate = static_cast<TRACK*>( connected->Parent() );
TRACK* candidateSegment = static_cast<TRACK*>( candidateItem );
// Do not merge segments having different widths: it is a frequent case
// to draw a track between 2 pads:
if( candidate->GetWidth() != segment->GetWidth() )
if( candidateSegment->GetWidth() != segment->GetWidth() )
continue;
if( segment->ApproxCollinear( *candidate ) )
{
modified |= mergeCollinearSegments(
segment, static_cast<TRACK*>( connected->Parent() ) );
}
if( segment->ApproxCollinear( *candidateSegment ) )
modified |= mergeCollinearSegments( segment, candidateSegment );
}
}
}