diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 6edcfbb12b..b9e8293b87 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -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 ) ); } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 2ef330d6a6..bc31d8ee5c 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -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 diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index b8976c4aff..394fe4d788 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -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 ) diff --git a/eeschema/tools/ee_point_editor.cpp b/eeschema/tools/ee_point_editor.cpp index dc708dcad2..4324387e91 100644 --- a/eeschema/tools/ee_point_editor.cpp +++ b/eeschema/tools/ee_point_editor.cpp @@ -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 ); diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index f37163fedd..c21443ccb6 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -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 ); } diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index 0cddf47246..8eae01a6e8 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -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 ); diff --git a/eeschema/tools/lib_move_tool.cpp b/eeschema/tools/lib_move_tool.cpp index 80ec907c8e..584a4481dc 100644 --- a/eeschema/tools/lib_move_tool.cpp +++ b/eeschema/tools/lib_move_tool.cpp @@ -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 ); diff --git a/eeschema/tools/lib_pin_tool.cpp b/eeschema/tools/lib_pin_tool.cpp index f28b11428d..3e7088124d 100644 --- a/eeschema/tools/lib_pin_tool.cpp +++ b/eeschema/tools/lib_pin_tool.cpp @@ -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(); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 699562b6fc..71eace35e0 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -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 ); } diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 53be8fec6b..f0f49f5a93 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -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 ); diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 93e6a046b3..152978f06e 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -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_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( aItem )->MoveStart( (wxPoint) aDelta ); - if( aItem->GetFlags() & ENDPOINT ) + if( aItem->HasFlag( ENDPOINT ) ) static_cast( aItem )->MoveEnd( (wxPoint) aDelta ); break; diff --git a/include/base_struct.h b/include/base_struct.h index ecb2aadc5b..1ec7c1f440 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -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 { diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index b9963d6d61..a47c8f371c 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -709,7 +709,7 @@ static void moveNoFlagToVector( ZONE_CONTAINERS& aList, std::vectorGetFlags() & FLAG0 ) + if( obj->HasFlag( FLAG0 ) ) obj->ClearFlags( FLAG0 ); else aTarget.push_back( obj ); diff --git a/pcbnew/tracks_cleaner.cpp b/pcbnew/tracks_cleaner.cpp index b2fe45640e..0f6d0b70a9 100644 --- a/pcbnew/tracks_cleaner.cpp +++ b/pcbnew/tracks_cleaner.cpp @@ -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( connected->Parent() ); + TRACK* candidateSegment = static_cast( 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( connected->Parent() ) ); - } + if( segment->ApproxCollinear( *candidateSegment ) ) + modified |= mergeCollinearSegments( segment, candidateSegment ); } } }