Commit 9880975e authored by charras's avatar charras

LibEdit: fixed a bug (bad format in a Printf) that crashes libedit when...

LibEdit: fixed a bug (bad format in a Printf) that crashes libedit when testing a component with duplicate pins.
Also cleaned and enhanced WinEDA_LibeditFrame::OnCheckComponent() code
parent 502f3160
......@@ -10,6 +10,7 @@
#include "class_libentry.h"
#include "pinedit-dialog.h"
#include "dialog_display_info_HTML_base.h"
static int CodeOrient[4] =
{
......@@ -206,7 +207,8 @@ void WinEDA_LibeditFrame::PlacePin( wxDC* DC )
if( ask_for_pin && !g_EditPinByPinIsOn )
{
DrawPanel->m_IgnoreMouseEvents = true;
status = IsOK( this, _( "This position is already occupied by \
status =
IsOK( this, _( "This position is already occupied by \
another pin. Continue?" ) );
DrawPanel->MouseToCursorSchema();
DrawPanel->m_IgnoreMouseEvents = false;
......@@ -566,7 +568,7 @@ void WinEDA_LibeditFrame::CreatePin( wxDC* DC )
CurrentPin->m_Unit = m_unit;
CurrentPin->m_Convert = m_convert;
/* Marquage des pins a traiter */
/* Flag pins to consider */
if( g_EditPinByPinIsOn == false )
CurrentPin->m_Flags |= IS_LINKED;
......@@ -799,7 +801,7 @@ static void CreateImagePins( LIB_PIN* Pin, int unit, int convert,
if( CreateConv == false )
continue;
NewPin = (LIB_PIN*)Pin->GenCopy();
NewPin = (LIB_PIN*) Pin->GenCopy();
NewPin->m_Convert = 2;
if( Pin->m_Unit != 0 )
NewPin->m_Unit = ii;
......@@ -876,7 +878,7 @@ void WinEDA_LibeditFrame::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin )
|| SourcePin->Type() != COMPONENT_PIN_DRAW_TYPE )
return;
Pin = (LIB_PIN*)SourcePin->GenCopy();
Pin = (LIB_PIN*) SourcePin->GenCopy();
m_component->AddDrawItem( Pin );
Pin->m_Flags = IS_NEW;
......@@ -912,48 +914,63 @@ void WinEDA_LibeditFrame::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin )
}
int sort_by_pin_number( const void* ref, const void* tst )
/* helper function to sort pins by pin num */
bool sort_by_pin_number( const LIB_PIN* ref, const LIB_PIN* tst )
{
const LIB_PIN* Ref = *(LIB_PIN**) ref;
const LIB_PIN* Tst = *(LIB_PIN**) tst;
int test = ref->m_PinNum - tst->m_PinNum;
return Ref->m_PinNum - Tst->m_PinNum;
if( test == 0 )
{
test = ref->m_Convert - tst->m_Convert;
}
if( test == 0 )
{
test = ref->m_Unit - tst->m_Unit;
}
return test < 0;
}
/* Test for duplicate pins:
*/
void WinEDA_LibeditFrame::OnCheckComponent( wxCommandEvent& event )
{
int nb_pins, ii, error;
int error;
LIB_PIN* Pin;
LIB_PIN** PinList;
wxString msg;
if( m_component == NULL )
return;
// Construction de la liste des pins:
// Build the pin list:
std::vector <LIB_PIN* >PinList;
Pin = m_component->GetNextPin();
for( nb_pins = 0; Pin != NULL; Pin = m_component->GetNextPin( Pin ) )
for( ; Pin != NULL; Pin = m_component->GetNextPin( Pin ) )
{
nb_pins++;
if( Pin->Type() == COMPONENT_PIN_DRAW_TYPE )
PinList.push_back( Pin );
}
PinList = (LIB_PIN**) MyZMalloc( (nb_pins + 1) * sizeof(LIB_PIN*) );
Pin = m_component->GetNextPin();
for( ii = 0; Pin != NULL; Pin = m_component->GetNextPin( Pin ) )
if( PinList.size() == 0 )
{
if( Pin->Type() == COMPONENT_PIN_DRAW_TYPE )
PinList[ii++] = Pin;
DisplayInfoMessage( this, _( "No pins!" ) );
return;
}
// Classement des pins par numero de pin
qsort( PinList, nb_pins, sizeof(LIB_PIN*), sort_by_pin_number );
// Sort pins by pin num, so 2 duplicate pins
// (pins with the same number) will be consecutive in list
sort( PinList.begin(), PinList.end(), sort_by_pin_number );
// Controle des duplicates:
// Test for duplicates:
error = 0;
for( ii = 1; ii < nb_pins; ii++ )
DIALOG_DISPLAY_HTML_TEXT_BASE
error_display( this, wxID_ANY, _( "Marker Info" ),
wxDefaultPosition, wxSize( 750, 600 ) );
for( unsigned ii = 1; ii < PinList.size(); ii++ )
{
wxString aux_msg, StringPinNum;
wxString aux_msg;
wxString stringPinNum, stringCurrPinNum;
LIB_PIN* curr_pin = PinList[ii];
Pin = PinList[ii - 1];
......@@ -963,14 +980,17 @@ void WinEDA_LibeditFrame::OnCheckComponent( wxCommandEvent& event )
continue;
error++;
curr_pin->ReturnPinStringNum( StringPinNum );
msg.Printf( _( "Duplicate pin %s at location (%d, %d) conflicts \
with pin %s at location (%d, %d)" ),
GetChars( StringPinNum ),
Pin->ReturnPinStringNum( stringPinNum );
curr_pin->ReturnPinStringNum( stringCurrPinNum );
msg.Printf( _(
"<b>Duplicate pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b> conflicts \
with pin %s \"%s\" at location <b>(%.3f, %.3f)</b>" ),
GetChars( stringCurrPinNum ),
GetChars( curr_pin->m_PinName ),
curr_pin->m_Pos.x, -curr_pin->m_Pos.y,
(float) curr_pin->m_Pos.x / 1000.0, (float) -curr_pin->m_Pos.y / 1000.0,
GetChars( stringPinNum ),
GetChars( Pin->m_PinName ),
Pin->m_Pos.x, -Pin->m_Pos.y );
(float) Pin->m_Pos.x / 1000.0, (float) -Pin->m_Pos.y / 1000.0 );
if( m_component->GetPartCount() > 1 )
{
......@@ -986,13 +1006,13 @@ with pin %s at location (%d, %d)" ),
msg += _( " of normal" );
}
msg += wxT( "." );
msg += wxT( ".<br>" );
DisplayError( this, msg );
error_display.m_htmlWindow->AppendToPage( msg );
}
free( PinList );
if( error == 0 )
DisplayInfoMessage( this, _( "No duplicate pins were found." ) );
else
error_display.ShowModal();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment