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
This commit is contained in:
parent
502f3160cb
commit
9880975eb0
|
@ -10,6 +10,7 @@
|
||||||
#include "class_libentry.h"
|
#include "class_libentry.h"
|
||||||
|
|
||||||
#include "pinedit-dialog.h"
|
#include "pinedit-dialog.h"
|
||||||
|
#include "dialog_display_info_HTML_base.h"
|
||||||
|
|
||||||
static int CodeOrient[4] =
|
static int CodeOrient[4] =
|
||||||
{
|
{
|
||||||
|
@ -206,7 +207,8 @@ void WinEDA_LibeditFrame::PlacePin( wxDC* DC )
|
||||||
if( ask_for_pin && !g_EditPinByPinIsOn )
|
if( ask_for_pin && !g_EditPinByPinIsOn )
|
||||||
{
|
{
|
||||||
DrawPanel->m_IgnoreMouseEvents = true;
|
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?" ) );
|
another pin. Continue?" ) );
|
||||||
DrawPanel->MouseToCursorSchema();
|
DrawPanel->MouseToCursorSchema();
|
||||||
DrawPanel->m_IgnoreMouseEvents = false;
|
DrawPanel->m_IgnoreMouseEvents = false;
|
||||||
|
@ -566,7 +568,7 @@ void WinEDA_LibeditFrame::CreatePin( wxDC* DC )
|
||||||
CurrentPin->m_Unit = m_unit;
|
CurrentPin->m_Unit = m_unit;
|
||||||
CurrentPin->m_Convert = m_convert;
|
CurrentPin->m_Convert = m_convert;
|
||||||
|
|
||||||
/* Marquage des pins a traiter */
|
/* Flag pins to consider */
|
||||||
if( g_EditPinByPinIsOn == false )
|
if( g_EditPinByPinIsOn == false )
|
||||||
CurrentPin->m_Flags |= IS_LINKED;
|
CurrentPin->m_Flags |= IS_LINKED;
|
||||||
|
|
||||||
|
@ -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;
|
int test = ref->m_PinNum - tst->m_PinNum;
|
||||||
const LIB_PIN* Tst = *(LIB_PIN**) tst;
|
|
||||||
|
|
||||||
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 )
|
void WinEDA_LibeditFrame::OnCheckComponent( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
int nb_pins, ii, error;
|
int error;
|
||||||
LIB_PIN* Pin;
|
LIB_PIN* Pin;
|
||||||
LIB_PIN** PinList;
|
|
||||||
wxString msg;
|
wxString msg;
|
||||||
|
|
||||||
if( m_component == NULL )
|
if( m_component == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Construction de la liste des pins:
|
// Build the pin list:
|
||||||
|
std::vector <LIB_PIN* >PinList;
|
||||||
Pin = m_component->GetNextPin();
|
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
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( Pin->Type() == COMPONENT_PIN_DRAW_TYPE )
|
if( Pin->Type() == COMPONENT_PIN_DRAW_TYPE )
|
||||||
PinList[ii++] = Pin;
|
PinList.push_back( Pin );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Classement des pins par numero de pin
|
if( PinList.size() == 0 )
|
||||||
qsort( PinList, nb_pins, sizeof(LIB_PIN*), sort_by_pin_number );
|
|
||||||
|
|
||||||
// Controle des duplicates:
|
|
||||||
error = 0;
|
|
||||||
for( ii = 1; ii < nb_pins; ii++ )
|
|
||||||
{
|
{
|
||||||
wxString aux_msg, StringPinNum;
|
DisplayInfoMessage( this, _( "No pins!" ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 );
|
||||||
|
|
||||||
|
// Test for duplicates:
|
||||||
|
error = 0;
|
||||||
|
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;
|
||||||
|
wxString stringPinNum, stringCurrPinNum;
|
||||||
|
|
||||||
LIB_PIN* curr_pin = PinList[ii];
|
LIB_PIN* curr_pin = PinList[ii];
|
||||||
Pin = PinList[ii - 1];
|
Pin = PinList[ii - 1];
|
||||||
|
|
||||||
|
@ -963,14 +980,17 @@ void WinEDA_LibeditFrame::OnCheckComponent( wxCommandEvent& event )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
error++;
|
error++;
|
||||||
curr_pin->ReturnPinStringNum( StringPinNum );
|
Pin->ReturnPinStringNum( stringPinNum );
|
||||||
msg.Printf( _( "Duplicate pin %s at location (%d, %d) conflicts \
|
curr_pin->ReturnPinStringNum( stringCurrPinNum );
|
||||||
with pin %s at location (%d, %d)" ),
|
msg.Printf( _(
|
||||||
GetChars( StringPinNum ),
|
"<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 ),
|
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 ),
|
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 )
|
if( m_component->GetPartCount() > 1 )
|
||||||
{
|
{
|
||||||
|
@ -986,13 +1006,13 @@ with pin %s at location (%d, %d)" ),
|
||||||
msg += _( " of normal" );
|
msg += _( " of normal" );
|
||||||
}
|
}
|
||||||
|
|
||||||
msg += wxT( "." );
|
msg += wxT( ".<br>" );
|
||||||
|
|
||||||
DisplayError( this, msg );
|
error_display.m_htmlWindow->AppendToPage( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
free( PinList );
|
|
||||||
|
|
||||||
if( error == 0 )
|
if( error == 0 )
|
||||||
DisplayInfoMessage( this, _( "No duplicate pins were found." ) );
|
DisplayInfoMessage( this, _( "No duplicate pins were found." ) );
|
||||||
|
else
|
||||||
|
error_display.ShowModal();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue