Shape poly set: fix bug in BBox calculation. Class MARKER : fix broken code and clean code. Fix bug #1369682 (EESchema Erc not show error count) due to this broken code.

This commit is contained in:
jean-pierre charras 2015-07-29 14:18:53 +02:00
parent 63b0e63152
commit 32f0ea621f
11 changed files with 94 additions and 100 deletions

View File

@ -66,7 +66,8 @@ static const wxPoint MarkerShapeCorners[CORNERS_COUNT] =
void MARKER_BASE::init()
{
m_MarkerType = 0;
m_MarkerType = MARKER_UNSPEC;
m_ErrorLevel = 0;
m_Color = RED;
wxPoint start = MarkerShapeCorners[0];
wxPoint end = MarkerShapeCorners[0];

View File

@ -596,11 +596,10 @@ bool SHAPE_POLY_SET::Parse( std::stringstream& aStream )
const BOX2I SHAPE_POLY_SET::BBox( int aClearance ) const
{
BOX2I bb;
bool first = true;
for( unsigned i = 0; i < m_polys.size(); i++ )
{
if( first )
if( i == 0 )
bb = m_polys[i][0].BBox();
else
bb.Merge( m_polys[i][0].BBox() );

View File

@ -103,14 +103,15 @@ void DIALOG_ERC::Init()
void DIALOG_ERC::updateMarkerCounts( SCH_SCREENS *screens )
{
int markers = screens->GetMarkerCount();
int warnings = screens->GetMarkerCount( WAR );
int markers = screens->GetMarkerCount(MARKER_BASE::MARKER_ERC, -1 );
int warnings = screens->GetMarkerCount( MARKER_BASE::MARKER_ERC, WAR );
int errors = screens->GetMarkerCount( MARKER_BASE::MARKER_ERC, ERR );
wxString num;
num.Printf( wxT( "%d" ), markers );
m_TotalErrCount->SetValue( num );
num.Printf( wxT( "%d" ), markers - warnings );
num.Printf( wxT( "%d" ), errors );
m_LastErrCount->SetValue( num );
num.Printf( wxT( "%d" ), warnings );
@ -124,7 +125,7 @@ void DIALOG_ERC::OnEraseDrcMarkersClick( wxCommandEvent& event )
{
SCH_SCREENS ScreenList;
ScreenList.DeleteAllMarkers( MARK_ERC );
ScreenList.DeleteAllMarkers( MARKER_BASE::MARKER_ERC );
updateMarkerCounts( &ScreenList );
m_MarkersList->ClearList();
@ -364,7 +365,7 @@ void DIALOG_ERC::DisplayERC_MarkersList()
SCH_MARKER* Marker = (SCH_MARKER*) item;
if( Marker->GetMarkerType() != MARK_ERC )
if( Marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
continue;
// Add marker without refresh the displayed list:
@ -450,7 +451,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
SCH_SCREENS screens;
// Erase all previous DRC markers.
screens.DeleteAllMarkers( MARK_ERC );
screens.DeleteAllMarkers( MARKER_BASE::MARKER_ERC );
for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
{
@ -546,7 +547,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
wxFileDialog dlg( this, _( "ERC File" ), fn.GetPath(), fn.GetFullName(),
_( "Electronic rule check file (.erc)|*.erc" ),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
wxFD_SAVE );
if( dlg.ShowModal() == wxID_CANCEL )
return;

View File

@ -1,9 +1,9 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -41,6 +41,8 @@
#include <sch_component.h>
#include <sch_sheet.h>
#include <wx/ffile.h>
/* ERC tests :
* 1 - conflicts between connected pins ( example: 2 connected outputs )
@ -206,7 +208,7 @@ int TestDuplicateSheetNames( bool aCreateMarker )
( (SCH_SHEET*) test_item )->GetPosition(),
_( "Duplicate sheet name" ),
( (SCH_SHEET*) test_item )->GetPosition() );
marker->SetMarkerType( MARK_ERC );
marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
marker->SetErrorLevel( ERR );
screen->Append( marker );
}
@ -235,7 +237,7 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst,
marker = new SCH_MARKER();
marker->SetTimeStamp( GetNewTimeStamp() );
marker->SetMarkerType( MARK_ERC );
marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
marker->SetErrorLevel( WAR );
screen = aNetItemRef->m_SheetPath.LastScreen();
screen->Append( marker );
@ -508,52 +510,61 @@ int CountPinsInNet( NETLIST_OBJECT_LIST* aList, unsigned aNetStart )
return count;
}
bool WriteDiagnosticERC( const wxString& aFullFileName )
{
SCH_ITEM* item;
SCH_MARKER* marker;
static FILE* file;
SCH_SHEET_PATH* sheet;
wxString msg;
int count = 0;
wxString msg;
if( ( file = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL )
wxFFile file( aFullFileName, wxT( "wt" ) );
if( !file.IsOpened() )
return false;
msg = _( "ERC report" );
msg << wxT(" (") << DateAndTime() << wxT( ", " )
<< _( "Encoding UTF8" ) << wxT( " )\n" );
fprintf( file, "%s (%s)\n", TO_UTF8( msg ), TO_UTF8( DateAndTime() ) );
int err_count = 0;
int warn_count = 0;
int total_count = 0;
SCH_SHEET_LIST sheetList;
SCH_SHEET_PATH* sheet;
for( sheet = sheetList.GetFirst(); sheet != NULL; sheet = sheetList.GetNext() )
{
msg.Printf( _( "\n***** Sheet %s\n" ), GetChars( sheet->PathHumanReadable() ) );
msg << wxString::Format( _( "\n***** Sheet %s\n" ),
GetChars( sheet->PathHumanReadable() ) );
fprintf( file, "%s", TO_UTF8( msg ) );
for( item = sheet->LastDrawList(); item != NULL; item = item->Next() )
for( SCH_ITEM* item = sheet->LastDrawList(); item != NULL; item = item->Next() )
{
if( item->Type() != SCH_MARKER_T )
continue;
marker = (SCH_MARKER*) item;
SCH_MARKER* marker = (SCH_MARKER*) item;
if( marker->GetMarkerType() != MARK_ERC )
if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
continue;
if( marker->GetMarkerType() == ERR )
count++;
total_count++;
msg = marker->GetReporter().ShowReport();
fprintf( file, "%s", TO_UTF8( msg ) );
if( marker->GetErrorLevel() == ERR )
err_count++;
if( marker->GetErrorLevel() == WAR )
warn_count++;
msg << marker->GetReporter().ShowReport();
}
}
msg.Printf( _( "\n >> Errors ERC: %d\n" ), count );
fprintf( file, "%s", TO_UTF8( msg ) );
fclose( file );
msg << wxString::Format( _( "\n ** ERC messages: %d Errors %d Warnings %d\n" ),
total_count, err_count, warn_count );
// Currently: write report unsing UTF8 (as usual in Kicad).
// TODO: see if we can use the current encoding page (mainly for Windows users),
// Or other format (HTML?)
file.Write( msg );
// wxFFile dtor will close the file.
return true;
}
@ -564,7 +575,7 @@ void TestLabel( NETLIST_OBJECT_LIST* aList, unsigned aNetItemRef, unsigned aStar
unsigned netItemTst = aStartNet;
int erc = 1;
/* Review the list of labels connected to NetItemRef. */
// Review the list of labels connected to NetItemRef:
for( ; ; netItemTst++ )
{
if( netItemTst == aNetItemRef )

View File

@ -65,6 +65,9 @@ wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
ret.Replace( wxT( "%I" ), in.GetFullPath().GetData(), true );
ret.Replace( wxT( "%O" ), out.GetFullPath().GetData(), true );
// Use Unix like notation, which always works
ret.Replace( wxT( "\\" ), "/", true );
return ret;
}

View File

@ -38,21 +38,6 @@
#include <erc.h>
/* Marker are mainly used to show an ERC error
* but they could be used to give a specific info
*/
const wxChar* NameMarqueurType[] =
{
wxT( "" ),
wxT( "ERC" ),
wxT( "PCB" ),
wxT( "SIMUL" ),
wxT( "???" )
};
/********************/
/* class SCH_MARKER */
/********************/
@ -104,7 +89,7 @@ void SCH_MARKER::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
EDA_COLOR_T color = m_Color;
EDA_COLOR_T tmp = color;
if( GetMarkerType() == MARK_ERC )
if( GetMarkerType() == MARKER_BASE::MARKER_ERC )
{
color = ( GetErrorLevel() == WAR ) ? GetLayerColor( LAYER_ERC_WARN ) :
GetLayerColor( LAYER_ERC_ERR );

View File

@ -34,19 +34,6 @@
#include <class_marker_base.h>
/* Marker are mainly used to show an ERC error
*/
enum TypeMarker {
/* Markers type */
MARK_UNSPEC,
MARK_ERC,
MARK_PCB,
MARK_SIMUL,
MARK_NMAX /* Lats value: end of list */
};
/* Names for corresponding types of markers: */
extern const wxChar* NameMarqueurType[];

View File

@ -1493,7 +1493,7 @@ int SCH_SCREENS::ReplaceDuplicateTimeStamps()
}
void SCH_SCREENS::DeleteAllMarkers( int aMarkerType )
void SCH_SCREENS::DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType )
{
SCH_ITEM* item;
SCH_ITEM* nextItem;
@ -1520,29 +1520,25 @@ void SCH_SCREENS::DeleteAllMarkers( int aMarkerType )
}
int SCH_SCREENS::GetMarkerCount( int aMarkerType )
int SCH_SCREENS::GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType, int aSeverity )
{
SCH_ITEM* item;
SCH_ITEM* nextItem;
SCH_MARKER* marker;
SCH_SCREEN* screen;
int count = 0;
for( screen = GetFirst(); screen; screen = GetNext() )
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
{
for( item = screen->GetDrawItems(); item; item = nextItem )
for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
{
nextItem = item->Next();
if( item->Type() != SCH_MARKER_T )
continue;
marker = (SCH_MARKER*) item;
SCH_MARKER* marker = (SCH_MARKER*) item;
if( (aMarkerType != -1) && (marker->GetMarkerType() != aMarkerType) )
if( ( aMarkerType != MARKER_BASE::MARKER_UNSPEC ) &&
( marker->GetMarkerType() != aMarkerType ) )
continue;
count++;
if( aSeverity < 0 || aSeverity == marker->GetErrorLevel() )
count++;
}
}

View File

@ -29,12 +29,26 @@
#include <class_drc_item.h>
#include <gr_basic.h>
/* Marker are mainly used to show an ERC error
*/
class MARKER_BASE
{
public:
enum TYPEMARKER { // Marker type: can be used to identify the purpose of the marker
MARKER_UNSPEC,
MARKER_ERC,
MARKER_PCB,
MARKER_SIMUL
};
wxPoint m_Pos; ///< position of the marker
protected:
int m_MarkerType; ///< Can be used as a flag
TYPEMARKER m_MarkerType; ///< The type of marker (useful to filter markers)
int m_ErrorLevel; ///< a flag to specify the severity of the error
EDA_COLOR_T m_Color; ///< color
EDA_RECT m_ShapeBoundingBox; ///< Bounding box of the graphic symbol, relative
///< to the position of the shape, used for Hit
@ -108,34 +122,28 @@ public:
}
/**
* Function to set/get error levels (warning, fatal ..)
* this value is stored in m_MarkerType
* accessors to set/get error levels (warning, error, fatal error..)
*/
void SetErrorLevel( int aErrorLevel )
{
m_MarkerType &= ~0xFF00;
aErrorLevel &= 0xFF;
m_MarkerType |= aErrorLevel << 8;
m_ErrorLevel = aErrorLevel;
}
int GetErrorLevel() const
{
return (m_MarkerType >> 8) & 0xFF;
return m_ErrorLevel;
}
/** Functions to set/get marker type (DRC, ERC, or other)
* this value is stored in m_MarkerType
/** accessors to set/get marker type (DRC, ERC, or other)
*/
void SetMarkerType( int aMarkerType )
void SetMarkerType( enum TYPEMARKER aMarkerType )
{
m_MarkerType &= ~0xFF;
aMarkerType &= 0xFF;
m_MarkerType |= aMarkerType;
m_MarkerType = aMarkerType;
}
int GetMarkerType() const
enum TYPEMARKER GetMarkerType() const
{
return m_MarkerType & 0xFF;
return m_MarkerType;
}
/**

View File

@ -37,6 +37,7 @@
#include <class_title_block.h>
#include <class_page_info.h>
#include <kiway_player.h>
#include <sch_marker.h>
#include <../eeschema/general.h>
@ -575,17 +576,19 @@ public:
* the list.
* @param aMarkerType Type of markers to be deleted.
*/
void DeleteAllMarkers( int aMarkerType );
void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType );
/**
* Function GetMarkerCount
* returns the number of ERC markers of \a aMarkerType from all of the screens in the list.
*
* @param aMarkerType Indicates the type of marker to count. A value less then zero
* indicates all markers are counted.
* @param aMarkerType Indicates the type of marker to count. if MARKER_UNSPEC
* all markers are counted.
* @param aSeverity Indicates the error level of marker to count. -1 to count all markers
* of the specified type
* @return int count of the markers found.
*/
int GetMarkerCount( int aMarkerType = -1 );
int GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType, int aSeverity );
private:
void AddScreenToList( SCH_SCREEN* aScreen );

View File

@ -46,7 +46,7 @@
#define MIN_GRID_SIZE ( 0.001 * IU_PER_MM )
// Min/Max value for grid offset
#define MAX_GRID_OFFSET double(INT_MAX/2)
#define MAX_GRID_OFFSET ((double)INT_MAX/2)
class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE
{