2011-10-07 14:41:30 +00:00
|
|
|
/*
|
|
|
|
* 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) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 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
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file dialog_erc.cpp
|
|
|
|
* @brief Electrical Rules Check dialog implementation.
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <class_sch_screen.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <netlist.h>
|
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <protos.h>
|
|
|
|
|
|
|
|
#include <dialog_erc.h>
|
|
|
|
#include <dialog_erc_listbox.h>
|
|
|
|
#include <erc.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2010-11-11 21:10:27 +00:00
|
|
|
bool DIALOG_ERC::m_writeErcFile = false;
|
|
|
|
|
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
BEGIN_EVENT_TABLE( DIALOG_ERC, DIALOG_ERC_BASE )
|
2011-10-07 14:41:30 +00:00
|
|
|
EVT_COMMAND_RANGE( ID_MATRIX_0, ID_MATRIX_0 + ( PIN_NMAX * PIN_NMAX ) - 1,
|
|
|
|
wxEVT_COMMAND_BUTTON_CLICKED, DIALOG_ERC::ChangeErrorLevel )
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) :
|
2009-07-08 15:42:45 +00:00
|
|
|
DIALOG_ERC_BASE( parent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-08 15:42:45 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
Init();
|
2009-07-03 18:25:06 +00:00
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
2009-12-06 18:04:41 +00:00
|
|
|
Centre();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
void DIALOG_ERC::Init()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
m_Initialized = false;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
for( int ii = 0; ii < PIN_NMAX; ii++ )
|
|
|
|
for( int jj = 0; jj < PIN_NMAX; jj++ )
|
|
|
|
m_ButtonList[ii][jj] = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-11 21:10:27 +00:00
|
|
|
m_WriteResultOpt->SetValue( m_writeErcFile );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
SCH_SCREENS screens;
|
|
|
|
int markers = screens.GetMarkerCount();
|
|
|
|
int warnings = screens.GetMarkerCount( WAR );
|
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
wxString num;
|
2011-10-07 14:41:30 +00:00
|
|
|
num.Printf( wxT( "%d" ), markers );
|
2009-07-08 15:42:45 +00:00
|
|
|
m_TotalErrCount->SetLabel( num );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
num.Printf( wxT( "%d" ), markers - warnings );
|
2009-07-08 15:42:45 +00:00
|
|
|
m_LastErrCount->SetLabel( num );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
num.Printf( wxT( "%d" ), warnings );
|
2009-07-08 15:42:45 +00:00
|
|
|
m_LastWarningCount->SetLabel( num );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
DisplayERC_MarkersList();
|
2009-07-05 12:09:41 +00:00
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
// Init Panel Matrix
|
|
|
|
ReBuildMatrixPanel();
|
2010-11-11 21:10:27 +00:00
|
|
|
|
|
|
|
// Set the run ERC button as the default button.
|
|
|
|
m_buttonERC->SetDefault();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2009-07-05 12:09:41 +00:00
|
|
|
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ERASE_DRC_MARKERS */
|
2009-07-03 18:25:06 +00:00
|
|
|
/* Delete the old ERC markers, over the whole hierarchy
|
|
|
|
*/
|
2011-10-07 14:41:30 +00:00
|
|
|
void DIALOG_ERC::OnEraseDrcMarkersClick( wxCommandEvent& event )
|
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
SCH_SCREENS ScreenList;
|
2011-09-11 11:38:01 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
ScreenList.DeleteAllMarkers( MARK_ERC );
|
2009-07-08 18:06:11 +00:00
|
|
|
m_MarkersList->ClearList();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2009-07-05 12:09:41 +00:00
|
|
|
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL */
|
2009-07-03 18:25:06 +00:00
|
|
|
void DIALOG_ERC::OnCancelClick( wxCommandEvent& event )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2009-07-08 15:42:45 +00:00
|
|
|
EndModal( 0 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
|
2009-07-05 12:09:41 +00:00
|
|
|
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RESET_MATRIX */
|
2009-07-03 18:25:06 +00:00
|
|
|
void DIALOG_ERC::OnResetMatrixClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-08 15:42:45 +00:00
|
|
|
ResetDefaultERCDiag( event );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
|
2009-07-05 12:09:41 +00:00
|
|
|
/* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ERC_CMP */
|
2009-07-03 18:25:06 +00:00
|
|
|
void DIALOG_ERC::OnErcCmpClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-08 15:42:45 +00:00
|
|
|
wxBusyCursor();
|
2009-07-08 18:06:11 +00:00
|
|
|
m_MarkersList->Clear();
|
2009-07-03 18:25:06 +00:00
|
|
|
m_MessagesList->Clear();
|
2009-07-08 18:06:11 +00:00
|
|
|
wxSafeYield(); // m_MarkersList must be redraw
|
2009-07-08 15:42:45 +00:00
|
|
|
wxArrayString messageList;
|
|
|
|
TestErc( &messageList );
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
for( unsigned ii = 0; ii < messageList.GetCount(); ii++ )
|
|
|
|
m_MessagesList->AppendText( messageList[ii] );
|
2009-07-08 15:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Double click on a marker info:
|
|
|
|
void DIALOG_ERC::OnLeftDClickMarkersList( wxCommandEvent& event )
|
|
|
|
{
|
2009-07-08 18:06:11 +00:00
|
|
|
int index = m_MarkersList->GetSelection();
|
2009-07-08 15:42:45 +00:00
|
|
|
|
|
|
|
if( index < 0 )
|
|
|
|
return;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
const SCH_MARKER* marker = m_MarkersList->GetItem( (unsigned) index );
|
2009-07-08 15:42:45 +00:00
|
|
|
|
|
|
|
EndModal( 1 );
|
|
|
|
|
|
|
|
|
|
|
|
// Search for the selected marker
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet;
|
|
|
|
bool NotFound;
|
|
|
|
wxPoint pos = marker->m_Pos;
|
|
|
|
wxPoint curpos, old_cursor_position;
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
NotFound = true;
|
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
/* Search for the selected marker */
|
2011-10-07 14:41:30 +00:00
|
|
|
for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
|
2009-07-08 15:42:45 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
SCH_ITEM* item = (SCH_ITEM*) sheet->LastDrawList();
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
while( item && NotFound )
|
|
|
|
{
|
|
|
|
if( item == marker )
|
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
NotFound = false;
|
2009-07-08 15:42:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-08 15:42:45 +00:00
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( NotFound == false )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( NotFound ) // Error
|
|
|
|
{
|
|
|
|
wxMessageBox( wxT( "OnLeftDClickMarkersList() error: Marker Not Found" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-08 21:05:43 +00:00
|
|
|
if( *sheet != m_Parent->GetCurrentSheet() )
|
2009-07-08 15:42:45 +00:00
|
|
|
{
|
|
|
|
sheet->LastScreen()->SetZoom( m_Parent->GetScreen()->GetZoom() );
|
2011-12-08 21:05:43 +00:00
|
|
|
m_Parent->SetCurrentSheet( *sheet );
|
|
|
|
m_Parent->GetCurrentSheet().UpdateAllScreenReferences();
|
2009-07-08 15:42:45 +00:00
|
|
|
}
|
|
|
|
|
2011-09-11 11:38:01 +00:00
|
|
|
m_Parent->GetScreen()->SetCrossHairPosition( pos );
|
2011-02-11 20:48:13 +00:00
|
|
|
m_Parent->RedrawScreen( pos, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Build or rebuild the panel showing the ERC conflict matrix
|
2009-07-03 18:25:06 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void DIALOG_ERC::ReBuildMatrixPanel()
|
|
|
|
{
|
2009-07-03 18:25:06 +00:00
|
|
|
int ii, jj, event_id, text_height;
|
|
|
|
wxPoint pos, BoxMatrixPosition;
|
|
|
|
wxStaticText* text;
|
|
|
|
wxSize BoxMatrixMinSize;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-11 13:48:04 +00:00
|
|
|
// Try to know the size of bitmap button used in drc matrix
|
|
|
|
wxBitmapButton * dummy = new wxBitmapButton( m_PanelERCOptions, wxID_ANY,
|
2011-10-07 14:41:30 +00:00
|
|
|
KiBitmap( ercerr_xpm ) );
|
2011-09-11 13:48:04 +00:00
|
|
|
wxSize bitmap_size = dummy->GetSize();
|
|
|
|
delete dummy;
|
2011-09-11 11:38:01 +00:00
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
if( !DiagErcTableInit )
|
|
|
|
{
|
|
|
|
memcpy( DiagErc, DefaultDiagErc, sizeof(DefaultDiagErc) );
|
2011-10-07 14:41:30 +00:00
|
|
|
DiagErcTableInit = true;
|
2009-07-03 18:25:06 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
// Get the current text size: this is a dummy text.
|
|
|
|
text = new wxStaticText( m_PanelERCOptions, -1, wxT( "W" ), pos );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-11 11:38:01 +00:00
|
|
|
text_height = text->GetRect().GetHeight();
|
2012-09-22 11:19:37 +00:00
|
|
|
bitmap_size.y = std::max( bitmap_size.y, text_height );
|
2009-07-03 18:25:06 +00:00
|
|
|
SAFE_DELETE( text );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
// compute the Y pos interval:
|
2011-09-11 11:38:01 +00:00
|
|
|
BoxMatrixMinSize.y = ( bitmap_size.y * (PIN_NMAX + 1) ) + 5;
|
2009-07-03 18:25:06 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
pos = m_MatrixSizer->GetPosition();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
// Size computation is not made in constructor, in some wxWidgets version,
|
|
|
|
// and m_BoxSizerForERC_Opt position is always 0,0. and we can't use it
|
2012-09-22 11:19:37 +00:00
|
|
|
pos.x = std::max( pos.x, 5 );
|
|
|
|
pos.y = std::max( pos.y, m_ResetOptButton->GetRect().GetHeight() + 30 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
BoxMatrixPosition = pos;
|
|
|
|
|
|
|
|
pos.y += text_height;
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
if( m_Initialized == false )
|
2009-07-03 18:25:06 +00:00
|
|
|
{
|
2011-09-11 11:38:01 +00:00
|
|
|
// Print row labels
|
2009-07-03 18:25:06 +00:00
|
|
|
for( ii = 0; ii < PIN_NMAX; ii++ )
|
|
|
|
{
|
2011-09-11 11:38:01 +00:00
|
|
|
int y = pos.y + (ii * bitmap_size.y);
|
2009-11-03 13:26:31 +00:00
|
|
|
text = new wxStaticText( m_PanelERCOptions, -1, CommentERC_H[ii],
|
2011-10-07 14:41:30 +00:00
|
|
|
wxPoint( 5, y + ( bitmap_size.y / 2) - (text_height / 2) ) );
|
2009-07-03 18:25:06 +00:00
|
|
|
|
2011-09-11 11:38:01 +00:00
|
|
|
int x = text->GetRect().GetRight();
|
2012-09-22 11:19:37 +00:00
|
|
|
pos.x = std::max( pos.x, x );
|
2009-07-03 18:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pos.x += 5;
|
|
|
|
}
|
|
|
|
else
|
2011-10-07 14:41:30 +00:00
|
|
|
{
|
2009-07-03 18:25:06 +00:00
|
|
|
pos = m_ButtonList[0][0]->GetPosition();
|
2011-10-07 14:41:30 +00:00
|
|
|
}
|
2009-07-03 18:25:06 +00:00
|
|
|
|
|
|
|
for( ii = 0; ii < PIN_NMAX; ii++ )
|
|
|
|
{
|
2011-09-11 11:38:01 +00:00
|
|
|
int y = pos.y + (ii * bitmap_size.y);
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
for( jj = 0; jj <= ii; jj++ )
|
|
|
|
{
|
2011-09-11 11:38:01 +00:00
|
|
|
// Add column labels (only once)
|
2009-07-03 18:25:06 +00:00
|
|
|
int diag = DiagErc[ii][jj];
|
2011-09-11 11:38:01 +00:00
|
|
|
int x = pos.x + (jj * bitmap_size.x);
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-03 18:25:06 +00:00
|
|
|
if( (ii == jj) && !m_Initialized )
|
|
|
|
{
|
|
|
|
wxPoint txtpos;
|
2011-09-11 11:38:01 +00:00
|
|
|
txtpos.x = x + (bitmap_size.x / 2);
|
|
|
|
txtpos.y = y - text_height;
|
2009-11-03 13:26:31 +00:00
|
|
|
text = new wxStaticText( m_PanelERCOptions,
|
|
|
|
-1,
|
|
|
|
CommentERC_V[ii],
|
|
|
|
txtpos );
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
BoxMatrixMinSize.x = std::max( BoxMatrixMinSize.x, text->GetRect().GetRight() );
|
2009-07-03 18:25:06 +00:00
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
event_id = ID_MATRIX_0 + ii + ( jj * PIN_NMAX );
|
2009-07-03 18:25:06 +00:00
|
|
|
delete m_ButtonList[ii][jj];
|
|
|
|
|
2011-09-11 11:38:01 +00:00
|
|
|
// Add button on matrix
|
2009-07-03 18:25:06 +00:00
|
|
|
switch( diag )
|
|
|
|
{
|
|
|
|
case OK:
|
|
|
|
m_ButtonList[ii][jj] = new wxBitmapButton( m_PanelERCOptions,
|
2011-10-07 14:41:30 +00:00
|
|
|
event_id,
|
|
|
|
KiBitmap( erc_green_xpm ),
|
|
|
|
wxPoint( x, y ) );
|
2009-07-03 18:25:06 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WAR:
|
|
|
|
m_ButtonList[ii][jj] = new wxBitmapButton( m_PanelERCOptions,
|
2011-10-07 14:41:30 +00:00
|
|
|
event_id,
|
|
|
|
KiBitmap( ercwarn_xpm ),
|
|
|
|
wxPoint( x, y ) );
|
2009-07-03 18:25:06 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERR:
|
|
|
|
m_ButtonList[ii][jj] = new wxBitmapButton( m_PanelERCOptions,
|
2011-10-07 14:41:30 +00:00
|
|
|
event_id,
|
|
|
|
KiBitmap( ercerr_xpm ),
|
|
|
|
wxPoint( x, y ) );
|
2009-07-03 18:25:06 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_Initialized )
|
|
|
|
{
|
|
|
|
BoxMatrixMinSize.x += 5;
|
|
|
|
m_MatrixSizer->SetMinSize( BoxMatrixMinSize );
|
|
|
|
BoxMatrixMinSize.y += BoxMatrixPosition.y;
|
|
|
|
m_PanelMatrixSizer->SetMinSize( BoxMatrixMinSize );
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
|
|
|
m_Initialized = true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2009-07-03 18:25:06 +00:00
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function DisplayERC_MarkersList
|
2009-07-07 17:50:02 +00:00
|
|
|
* read the schematic and display the list of ERC markers
|
|
|
|
*/
|
|
|
|
void DIALOG_ERC::DisplayERC_MarkersList()
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2009-07-07 17:50:02 +00:00
|
|
|
|
2009-07-08 18:06:11 +00:00
|
|
|
m_MarkersList->ClearList();
|
2009-07-08 15:42:45 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
for( SCH_SHEET_PATH* Sheet = SheetList.GetFirst(); Sheet != NULL; Sheet = SheetList.GetNext() )
|
2009-07-07 17:50:02 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* DrawStruct = Sheet->LastDrawList();
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
for( ; DrawStruct != NULL; DrawStruct = DrawStruct->Next() )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( DrawStruct->Type() != SCH_MARKER_T )
|
2009-07-07 17:50:02 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_MARKER* Marker = (SCH_MARKER*) DrawStruct;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-07 17:50:02 +00:00
|
|
|
if( Marker->GetMarkerType() != MARK_ERC )
|
|
|
|
continue;
|
2011-09-11 11:38:01 +00:00
|
|
|
|
2011-08-05 19:53:42 +00:00
|
|
|
// Add marker without refresh the displayed list:
|
|
|
|
m_MarkersList->AppendToList( Marker, false );
|
2009-07-07 17:50:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-11 11:38:01 +00:00
|
|
|
|
2011-08-05 19:53:42 +00:00
|
|
|
m_MarkersList->Refresh();
|
2009-07-07 17:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Resets the default values of the ERC matrix.
|
2009-07-07 17:50:02 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void DIALOG_ERC::ResetDefaultERCDiag( wxCommandEvent& event )
|
|
|
|
{
|
2009-07-07 17:50:02 +00:00
|
|
|
memcpy( DiagErc, DefaultDiagErc, sizeof(DiagErc) );
|
|
|
|
ReBuildMatrixPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Change the error level for the pressed button, on the matrix table
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void DIALOG_ERC::ChangeErrorLevel( wxCommandEvent& event )
|
|
|
|
{
|
2009-07-07 17:50:02 +00:00
|
|
|
int id, level, ii, x, y;
|
|
|
|
wxBitmapButton* Butt;
|
2011-08-29 03:04:59 +00:00
|
|
|
BITMAP_DEF new_bitmap_xpm = NULL;
|
2009-07-07 17:50:02 +00:00
|
|
|
wxPoint pos;
|
|
|
|
|
|
|
|
id = event.GetId();
|
|
|
|
ii = id - ID_MATRIX_0;
|
|
|
|
Butt = (wxBitmapButton*) event.GetEventObject();
|
|
|
|
pos = Butt->GetPosition();
|
|
|
|
|
|
|
|
x = ii / PIN_NMAX; y = ii % PIN_NMAX;
|
|
|
|
|
|
|
|
level = DiagErc[y][x];
|
|
|
|
|
|
|
|
switch( level )
|
|
|
|
{
|
|
|
|
case OK:
|
|
|
|
level = WAR;
|
2011-09-11 11:38:01 +00:00
|
|
|
new_bitmap_xpm = ercwarn_xpm;
|
2009-07-07 17:50:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WAR:
|
|
|
|
level = ERR;
|
2011-09-11 11:38:01 +00:00
|
|
|
new_bitmap_xpm = ercerr_xpm;
|
2009-07-07 17:50:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ERR:
|
|
|
|
level = OK;
|
|
|
|
new_bitmap_xpm = erc_green_xpm;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( new_bitmap_xpm )
|
|
|
|
{
|
|
|
|
delete Butt;
|
2011-08-28 20:02:27 +00:00
|
|
|
Butt = new wxBitmapButton( m_PanelERCOptions, id, KiBitmap( new_bitmap_xpm ), pos );
|
2009-07-07 17:50:02 +00:00
|
|
|
|
|
|
|
m_ButtonList[y][x] = Butt;
|
|
|
|
DiagErc[y][x] = DiagErc[x][y] = level;
|
|
|
|
}
|
|
|
|
}
|
2010-11-11 21:10:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
2011-10-07 14:41:30 +00:00
|
|
|
unsigned net;
|
|
|
|
unsigned lastNet;
|
|
|
|
unsigned nextNet;
|
2010-11-11 21:10:27 +00:00
|
|
|
|
|
|
|
int NetNbItems, MinConn;
|
|
|
|
|
|
|
|
if( !DiagErcTableInit )
|
|
|
|
{
|
|
|
|
memcpy( DiagErc, DefaultDiagErc, sizeof(DefaultDiagErc) );
|
2011-10-07 14:41:30 +00:00
|
|
|
DiagErcTableInit = true;
|
2010-11-11 21:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_writeErcFile = m_WriteResultOpt->GetValue();
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
/* Build the whole sheet list in hierarchy (sheet, not screen) */
|
2011-09-11 11:38:01 +00:00
|
|
|
SCH_SHEET_LIST sheets;
|
2010-12-31 19:47:39 +00:00
|
|
|
sheets.AnnotatePowerSymbols();
|
2010-11-11 21:10:27 +00:00
|
|
|
|
|
|
|
if( m_Parent->CheckAnnotate( aMessagesList, false ) )
|
|
|
|
{
|
|
|
|
if( aMessagesList )
|
|
|
|
{
|
|
|
|
wxString msg = _( "Annotation required!" );
|
|
|
|
msg += wxT( "\n" );
|
|
|
|
aMessagesList->Add( msg );
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2010-11-11 21:10:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
SCH_SCREENS screens;
|
2010-11-11 21:10:27 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
// Erase all previous DRC markers.
|
|
|
|
screens.DeleteAllMarkers( MARK_ERC );
|
2010-11-11 21:10:27 +00:00
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
|
2010-11-11 21:10:27 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
/* Ff wire list has changed, delete Undo Redo list to avoid pointers on deleted
|
|
|
|
* data problems.
|
|
|
|
*/
|
|
|
|
if( screen->SchematicCleanUp( NULL ) )
|
|
|
|
screen->ClearUndoRedoList();
|
2010-11-11 21:10:27 +00:00
|
|
|
}
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/* Test duplicate sheet names inside a given sheet, one cannot have sheets with
|
|
|
|
* duplicate names (file names can be duplicated).
|
2010-11-11 21:10:27 +00:00
|
|
|
*/
|
2011-10-07 14:41:30 +00:00
|
|
|
TestDuplicateSheetNames( true );
|
2010-11-11 21:10:27 +00:00
|
|
|
|
|
|
|
m_Parent->BuildNetListBase();
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/* Reset the flag m_FlagOfConnection, that will be used next, in calculations */
|
2010-11-11 21:10:27 +00:00
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
|
|
|
g_NetObjectslist[ii]->m_FlagOfConnection = UNCONNECTED;
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
nextNet = lastNet = 0;
|
2010-11-11 21:10:27 +00:00
|
|
|
NetNbItems = 0;
|
|
|
|
MinConn = NOC;
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
for( net = 0; net < g_NetObjectslist.size(); net++ )
|
2010-11-11 21:10:27 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
if( g_NetObjectslist[lastNet]->GetNet() != g_NetObjectslist[net]->GetNet() )
|
2011-09-11 11:38:01 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
// New net found:
|
2010-11-11 21:10:27 +00:00
|
|
|
MinConn = NOC;
|
|
|
|
NetNbItems = 0;
|
2011-10-07 14:41:30 +00:00
|
|
|
nextNet = net;
|
2010-11-11 21:10:27 +00:00
|
|
|
}
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
switch( g_NetObjectslist[net]->m_Type )
|
2010-11-11 21:10:27 +00:00
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
// These items do not create erc problems
|
2010-11-11 21:10:27 +00:00
|
|
|
case NET_ITEM_UNSPECIFIED:
|
|
|
|
case NET_SEGMENT:
|
|
|
|
case NET_BUS:
|
2011-10-07 14:41:30 +00:00
|
|
|
case NET_JUNCTION:
|
2010-11-11 21:10:27 +00:00
|
|
|
case NET_LABEL:
|
|
|
|
case NET_BUSLABELMEMBER:
|
|
|
|
case NET_PINLABEL:
|
|
|
|
case NET_GLOBLABEL:
|
|
|
|
case NET_GLOBBUSLABELMEMBER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_HIERLABEL:
|
|
|
|
case NET_HIERBUSLABELMEMBER:
|
|
|
|
case NET_SHEETLABEL:
|
|
|
|
case NET_SHEETBUSLABELMEMBER:
|
|
|
|
|
|
|
|
// ERC problems when pin sheets do not match hierarchical labels.
|
|
|
|
// Each pin sheet must match a hierarchical label
|
|
|
|
// Each hierarchical label must match a pin sheet
|
2011-10-07 14:41:30 +00:00
|
|
|
TestLabel( net, nextNet );
|
2010-11-11 21:10:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_NOCONNECT:
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
// ERC problems when a noconnect symbol is connected to more than one pin.
|
2010-11-11 21:10:27 +00:00
|
|
|
MinConn = NET_NC;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2010-11-11 21:10:27 +00:00
|
|
|
if( NetNbItems != 0 )
|
2011-10-07 14:41:30 +00:00
|
|
|
Diagnose( g_NetObjectslist[net], NULL, MinConn, UNC );
|
|
|
|
|
2010-11-11 21:10:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_PIN:
|
|
|
|
|
|
|
|
// Look for ERC problems between pins:
|
2011-10-07 14:41:30 +00:00
|
|
|
TestOthersItems( net, nextNet, &NetNbItems, &MinConn );
|
2010-11-11 21:10:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
lastNet = net;
|
2010-11-11 21:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Displays global results:
|
|
|
|
wxString num;
|
2011-10-07 14:41:30 +00:00
|
|
|
int markers = screens.GetMarkerCount();
|
|
|
|
int warnings = screens.GetMarkerCount( WAR );
|
|
|
|
|
|
|
|
num.Printf( wxT( "%d" ), markers );
|
2010-11-11 21:10:27 +00:00
|
|
|
m_TotalErrCount->SetLabel( num );
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
num.Printf( wxT( "%d" ), markers - warnings );
|
2010-11-11 21:10:27 +00:00
|
|
|
m_LastErrCount->SetLabel( num );
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
num.Printf( wxT( "%d" ), warnings );
|
2010-11-11 21:10:27 +00:00
|
|
|
m_LastWarningCount->SetLabel( num );
|
|
|
|
|
|
|
|
// Display diags:
|
|
|
|
DisplayERC_MarkersList();
|
|
|
|
|
|
|
|
// Display new markers:
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh();
|
2010-11-11 21:10:27 +00:00
|
|
|
|
|
|
|
if( m_writeErcFile )
|
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
fn = g_RootSheet->GetScreen()->GetFileName();
|
2010-11-11 21:10:27 +00:00
|
|
|
fn.SetExt( wxT( "erc" ) );
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "ERC File" ), fn.GetPath(), fn.GetFullName(),
|
|
|
|
_( "Electronic rule check file (.erc)|*.erc" ),
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( WriteDiagnosticERC( dlg.GetPath() ) )
|
|
|
|
{
|
2011-10-07 14:41:30 +00:00
|
|
|
Close( true );
|
2010-11-11 21:10:27 +00:00
|
|
|
ExecuteFile( this, wxGetApp().GetEditorName(), QuoteFullPath( fn ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|