From 4bab8dde65f00699fed5ba4b934d502a014aa2e8 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 2 Mar 2015 09:28:49 +0100 Subject: [PATCH] Fix some minor coverity warnings. Fix a bug in pcad2kicad plugin. Scripting: map BASE_SET. Rename some python bom scripts with better names. Fix erroneous comments and add comments --- common/drawtxt.cpp | 17 ++++++++++------- common/kiway_player.cpp | 1 + eeschema/dialogs/dialog_eeschema_options.cpp | 2 +- eeschema/dialogs/dialog_eeschema_options.h | 6 +++--- eeschema/edit_label.cpp | 3 ++- eeschema/getpart.cpp | 6 +++--- eeschema/sch_component.cpp | 2 ++ pcbnew/class_module.cpp | 6 ++---- pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp | 2 +- scripting/kicad.i | 8 ++++++++ ...sv_by_ref_v2.py => bom_csv_sorted_by_ref.py} | 0 ...on.py => bom_html_with_advanced_grouping.py} | 4 ++-- .../{bom_csv_by_ref.py => bom_sorted_by_ref.py} | 0 scripts/bom-in-python/kicad_netlist_reader.py | 6 ++---- 14 files changed, 37 insertions(+), 26 deletions(-) rename scripts/bom-in-python/{bom_csv_by_ref_v2.py => bom_csv_sorted_by_ref.py} (100%) rename scripts/bom-in-python/{bom-generation.py => bom_html_with_advanced_grouping.py} (97%) rename scripts/bom-in-python/{bom_csv_by_ref.py => bom_sorted_by_ref.py} (100%) diff --git a/common/drawtxt.cpp b/common/drawtxt.cpp index ffbe29f268..fee636a291 100644 --- a/common/drawtxt.cpp +++ b/common/drawtxt.cpp @@ -227,15 +227,18 @@ static void DrawGraphicTextPline( EDA_RECT* aClipBox, coord[ik + 1].x, coord[ik + 1].y ); } } - else if( aSketchMode ) + else if( aDC ) { - for( int ik = 0; ik < (point_count - 1); ik++ ) - GRCSegm( aClipBox, aDC, coord[ik].x, coord[ik].y, - coord[ik + 1].x, coord[ik + 1].y, aWidth, aColor ); + if( aSketchMode ) + { + for( int ik = 0; ik < (point_count - 1); ik++ ) + GRCSegm( aClipBox, aDC, coord[ik].x, coord[ik].y, + coord[ik + 1].x, coord[ik + 1].y, aWidth, aColor ); + } + else + GRPoly( aClipBox, aDC, point_count, coord, 0, + aWidth, aColor, aColor ); } - else - GRPoly( aClipBox, aDC, point_count, coord, 0, - aWidth, aColor, aColor ); } diff --git a/common/kiway_player.cpp b/common/kiway_player.cpp index 5ae6823a61..4a1f98f088 100644 --- a/common/kiway_player.cpp +++ b/common/kiway_player.cpp @@ -48,6 +48,7 @@ KIWAY_PLAYER::KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType m_modal_loop( 0 ), m_modal_resultant_parent( 0 ) { // DBG( printf("KIWAY_EXPRESS::wxEVENT_ID:%d\n", KIWAY_EXPRESS::wxEVENT_ID );) + m_modal_ret_val = 0; } diff --git a/eeschema/dialogs/dialog_eeschema_options.cpp b/eeschema/dialogs/dialog_eeschema_options.cpp index 25bf0a74d3..d07abc529b 100644 --- a/eeschema/dialogs/dialog_eeschema_options.cpp +++ b/eeschema/dialogs/dialog_eeschema_options.cpp @@ -258,7 +258,7 @@ void DIALOG_EESCHEMA_OPTIONS::OnDeleteButtonClick( wxCommandEvent& event ) // If the selectedField is still not in the templateField range now, // make sure we stay in range and when there are no fields present // move to -1 - if( selectedField >= templateFields.size() ) + if( selectedField >= int( templateFields.size() ) ) selectedField = templateFields.size() - 1; // Update the display to reflect the new data diff --git a/eeschema/dialogs/dialog_eeschema_options.h b/eeschema/dialogs/dialog_eeschema_options.h index eb9646fa92..4e18ba35c8 100644 --- a/eeschema/dialogs/dialog_eeschema_options.h +++ b/eeschema/dialogs/dialog_eeschema_options.h @@ -44,13 +44,13 @@ protected: * edit panel * selectedField = -1 when no valid item selected */ - size_t selectedField; + int selectedField; /** @brief return true if aFieldId is a valid field selection */ - bool fieldSelectionValid( size_t aFieldId ) + bool fieldSelectionValid( int aFieldId ) { - return ( aFieldId >= 0 ) && ( aFieldId < templateFields.size() ); + return ( aFieldId >= 0 ) && ( aFieldId < int( templateFields.size() ) ); } /** diff --git a/eeschema/edit_label.cpp b/eeschema/edit_label.cpp index a8e1066852..049bdc8081 100644 --- a/eeschema/edit_label.cpp +++ b/eeschema/edit_label.cpp @@ -116,7 +116,8 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( wxDC* aDC, int aType ) lastTextItalic = textItem->IsItalic(); lastTextOrientation = textItem->GetOrientation(); - if( (aType == SCH_GLOBAL_LABEL_T) || (aType == SCH_HIERARCHICAL_LABEL_T) ) + if( ( textItem->Type() == SCH_GLOBAL_LABEL_T ) || + ( textItem->Type() == SCH_HIERARCHICAL_LABEL_T ) ) { lastGlobalLabelShape = textItem->GetShape(); } diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index c6ffbb22e2..ca3f7b9294 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -296,12 +296,12 @@ void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent ) if( LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetPartName() ) ) { - wxCHECK_RET( (unit >= 1) && (unit <= part->GetUnitCount()), + int unitCount = part->GetUnitCount(); + + wxCHECK_RET( (unit >= 1) && (unit <= unitCount), wxString::Format( wxT( "Cannot select unit %d from component " ), unit ) + part->GetName() ); - int unitCount = part->GetUnitCount(); - if( unitCount <= 1 || component->GetUnit() == unit ) return; diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index e9f137b590..84921b791c 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -115,6 +115,7 @@ SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) : SCH_ITEM( aParent, SCH_COMPONENT_T ) { Init( aPos ); + m_currentSheetPath = NULL; } @@ -128,6 +129,7 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, m_convert = convert; m_part_name = aPart.GetName(); m_part = aPart.SharedPtr(); + m_currentSheetPath = NULL; SetTimeStamp( GetNewTimeStamp() ); diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 7291c376ff..5e8fa65d14 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1035,13 +1035,11 @@ void MODULE::MoveAnchorPosition( const wxPoint& aMoveVector ) * but: * - the footprint position is not modified. * - the relative (local) coordinates of these items are modified + * - Draw coordinates are updated */ - wxPoint footprintPos = GetPosition(); - /* Update the relative coordinates: - * The coordinates are relative to the anchor point. - * Calculate deltaX and deltaY from the anchor. */ + // Update (move) the relative coordinates relative to the new anchor point. wxPoint moveVector = aMoveVector; RotatePoint( &moveVector, -GetOrientation() ); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp index ca1346dab6..01a3db3bef 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp @@ -207,7 +207,7 @@ void PCB_PAD::AddToModule( MODULE* aModule, int aRotation, bool aEncapsulatedPad pad->SetDrillSize( wxSize( m_hole, m_hole ) ); pad->SetSize( wxSize( m_hole, m_hole ) ); - pad->SetLayerSet( LSET::AllCuMask() | LSET( 3, B_Mask, F_Mask ) ); + pad->SetLayerSet( LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask ) ); } else { diff --git a/scripting/kicad.i b/scripting/kicad.i index 150ca3d805..073c11231e 100644 --- a/scripting/kicad.i +++ b/scripting/kicad.i @@ -28,6 +28,7 @@ */ %include +%include %include %include @@ -65,6 +66,7 @@ #include #include #include + #include #include #include @@ -114,6 +116,12 @@ %template(intVector) std::vector; %template(str_utf8_Map) std::map< std::string,UTF8 >; +// wrapper of BASE_SEQ (see typedef std::vector BASE_SEQ;) +%template(base_seqVect) std::vector; + +// TODO: wrapper of BASE_SET (see std::bitset BASE_SET;) + + /* KiCad plugin handling */ %include "kicadplugins.i" diff --git a/scripts/bom-in-python/bom_csv_by_ref_v2.py b/scripts/bom-in-python/bom_csv_sorted_by_ref.py similarity index 100% rename from scripts/bom-in-python/bom_csv_by_ref_v2.py rename to scripts/bom-in-python/bom_csv_sorted_by_ref.py diff --git a/scripts/bom-in-python/bom-generation.py b/scripts/bom-in-python/bom_html_with_advanced_grouping.py similarity index 97% rename from scripts/bom-in-python/bom-generation.py rename to scripts/bom-in-python/bom_html_with_advanced_grouping.py index 9d7d704af7..0b3c451065 100644 --- a/scripts/bom-in-python/bom-generation.py +++ b/scripts/bom-in-python/bom_html_with_advanced_grouping.py @@ -1,7 +1,7 @@ # # Example python script to generate a BOM from a KiCad generic netlist # -# Example: Sorted and Grouped HTML BOM with more advanced grouping +# Example: Sorted and Grouped HTML BOM with advanced grouping # """ @@ -75,7 +75,7 @@ def myEqu(self, other): kicad_netlist_reader.comp.__equ__ = myEqu # Generate an instance of a generic netlist, and load the netlist tree from -# video.tmp. If the file doesn't exist, execution will stop +# .tmp. If the file doesn't exist, execution will stop net = kicad_netlist_reader.netlist(sys.argv[1]) # Open a file to write too, if the file cannot be opened output to stdout diff --git a/scripts/bom-in-python/bom_csv_by_ref.py b/scripts/bom-in-python/bom_sorted_by_ref.py similarity index 100% rename from scripts/bom-in-python/bom_csv_by_ref.py rename to scripts/bom-in-python/bom_sorted_by_ref.py diff --git a/scripts/bom-in-python/kicad_netlist_reader.py b/scripts/bom-in-python/kicad_netlist_reader.py index c60e4432a9..6ccc893c19 100644 --- a/scripts/bom-in-python/kicad_netlist_reader.py +++ b/scripts/bom-in-python/kicad_netlist_reader.py @@ -9,10 +9,8 @@ """ @package - Generate a HTML BOM list. - Components are sorted and grouped by value - Fields are (if exist) - Ref, Quantity, Value, Part, Datasheet, Description, Vendor + Helper module for interpreting generic netlist and build custom + bom generators or netlists in foreign format """