Skip to content

Commit

Permalink
Create Array dialog: some fixes:
Browse files Browse the repository at this point in the history
*  No initial copied object changed (this was a serious bug to modify these objects. Previous version modified references and other texts using a very stupid algorithm).
  It also fixes bug 1549231
* only new pads are numbered (therefore renumbering is used only in footprint editor)
*  remove not working and useless feature in circular array: now  only use number for pads (others options using alphabetical letters are removed: did not work corectly, and were useless)
* a more clear option is used to choose if the pads are numbered from a choosen value, or from the first avaible value
* Adding a warning messsage if a parameter is incorrect.
  • Loading branch information
jp-charras committed Mar 7, 2016
1 parent 92f5ab8 commit b237d81
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 468 deletions.
3 changes: 3 additions & 0 deletions pcbnew/class_module.cpp
Expand Up @@ -1176,6 +1176,7 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem,
new_item = new_pad;
break;
}

case PCB_MODULE_TEXT_T:
{
const TEXTE_MODULE* old_text = static_cast<const TEXTE_MODULE*>( aItem );
Expand All @@ -1191,6 +1192,7 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem,
}
break;
}

case PCB_MODULE_EDGE_T:
{
EDGE_MODULE* new_edge = new EDGE_MODULE(
Expand All @@ -1200,6 +1202,7 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem,
new_item = new_edge;
break;
}

case PCB_MODULE_T:
// Ignore the module itself
break;
Expand Down
94 changes: 35 additions & 59 deletions pcbnew/dialogs/dialog_create_array.cpp
Expand Up @@ -57,11 +57,9 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, wxPoint aOrig
};
m_choicePriAxisNumbering->Set( DIM( charSetDescriptions ), charSetDescriptions );
m_choiceSecAxisNumbering->Set( DIM( charSetDescriptions ), charSetDescriptions );
m_choiceCircNumberingType->Set( DIM( charSetDescriptions ), charSetDescriptions );;

m_choicePriAxisNumbering->SetSelection( 0 );
m_choiceSecAxisNumbering->SetSelection( 0 );
m_choiceCircNumberingType->SetSelection( 0 );

Add( m_entryNx, m_options.m_gridNx );
Add( m_entryNy, m_options.m_gridNy );
Expand Down Expand Up @@ -93,6 +91,9 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, wxPoint aOrig
Add( m_entryGridPriNumberingOffset, m_options.m_gridPriNumberingOffset );
Add( m_entryGridSecNumberingOffset, m_options.m_gridSecNumberingOffset );

Add( m_rbGridStartNumberingOpt, m_options.m_gridNumberingScheme );
Add( m_rbCircStartNumberingOpt, m_options.m_circNumberingScheme );

RestoreConfigToControls();

// Load units into labels
Expand All @@ -119,19 +120,8 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, wxPoint aOrig

void DIALOG_CREATE_ARRAY::OnParameterChanged( wxCommandEvent& event )
{
const wxObject* evObj = event.GetEventObject();

// some controls result in a change of enablement
if( evObj == m_radioBoxGridNumberingScheme
|| evObj == m_checkBoxGridRestartNumbering )
{
setControlEnablement();
}

if( evObj == m_entryCentreX || evObj == m_entryCentreY )
{
calculateCircularArrayProperties();
}
setControlEnablement();
calculateCircularArrayProperties();
}


Expand All @@ -142,12 +132,12 @@ static const std::string& alphabetFromNumberingScheme(
static const std::string alphaHex = "0123456789ABCDEF";
static const std::string alphaFull = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const std::string alphaNoIOSQXZ = "ABCDEFGHJKLMNPRTUVWY";
static const std::string alphaEmpty = "";

switch( type )
{
default:
case DIALOG_CREATE_ARRAY::NUMBERING_NUMERIC:
return alphaNumeric;
break;

case DIALOG_CREATE_ARRAY::NUMBERING_HEX:
return alphaHex;
Expand All @@ -157,12 +147,9 @@ static const std::string& alphabetFromNumberingScheme(

case DIALOG_CREATE_ARRAY::NUMBERING_ALPHA_FULL:
return alphaFull;

default:
wxASSERT_MSG( false, wxString( "Un-handled numbering scheme: " ) << type );
}

return alphaEmpty;
return alphaNumeric;
}


Expand All @@ -183,9 +170,6 @@ static bool getNumberingOffset( const std::string& str,
{
const std::string alphabet = alphabetFromNumberingScheme( type );

wxASSERT_MSG( !alphabet.empty(), wxString(
"Unable to determine alphabet for numbering scheme: " ) << type );

int offset = 0;
const int radix = alphabet.length();

Expand Down Expand Up @@ -242,8 +226,8 @@ void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event )
newGrid->m_2dArrayNumbering = m_radioBoxGridNumberingScheme->GetSelection() != 0;

// this is only correct if you set the choice up according to the enum size and order
ok = ok && m_choicePriAxisNumbering->GetSelection() < NUMBERING_TYPE_Max
&& m_choiceSecAxisNumbering->GetSelection() < NUMBERING_TYPE_Max;
ok = ok && m_choicePriAxisNumbering->GetSelection() <= NUMBERING_TYPE_MAX
&& m_choiceSecAxisNumbering->GetSelection() <= NUMBERING_TYPE_MAX;

// mind undefined casts to enums (should not be able to happen)
if( ok )
Expand All @@ -264,7 +248,7 @@ void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event )
m_entryGridSecNumberingOffset->GetValue().ToStdString(),
newGrid->m_secAxisNumType, newGrid->m_numberingOffsetY );

newGrid->m_shouldRenumber = m_checkBoxGridRestartNumbering->GetValue();
newGrid->m_shouldRenumber = m_rbGridStartNumberingOpt->GetSelection() == 1;

// Only use settings if all values are good
if( ok )
Expand All @@ -284,16 +268,8 @@ void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event )
ok = ok && m_entryCircCount->GetValue().ToLong( &newCirc->m_nPts );

newCirc->m_rotateItems = m_entryRotateItemsCb->GetValue();

newCirc->m_shouldRenumber = m_checkBoxCircRestartNumbering->GetValue();

// This is only correct if you set the choice up according to the enum size and order
ok = ok && m_choiceCircNumberingType->GetSelection() < NUMBERING_TYPE_Max;

// Mind undefined casts to enums (should not be able to happen)
if( ok )
newCirc->m_numberingType =
(ARRAY_NUMBERING_TYPE_T) m_choiceCircNumberingType->GetSelection();
newCirc->m_shouldRenumber = m_rbCircStartNumberingOpt->GetSelection() == 1;
newCirc->m_numberingType = NUMBERING_NUMERIC;

ok = ok && m_entryCircNumberingStart->GetValue().ToLong( &newCirc->m_numberingOffset );

Expand All @@ -311,17 +287,19 @@ void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event )

// assign pointer and ownership here
*m_settings = newSettings;

ReadConfigFromControls();

EndModal( wxID_OK );
}

else
wxMessageBox( _(" Bad parameters" ) );
}


void DIALOG_CREATE_ARRAY::setControlEnablement()
{
const bool renumber = m_checkBoxGridRestartNumbering->GetValue();
const bool renumber = m_rbGridStartNumberingOpt->GetSelection() == 1;

// If we're not renumbering, we can't set the numbering scheme
// or axis numbering types
Expand All @@ -341,10 +319,7 @@ void DIALOG_CREATE_ARRAY::setControlEnablement()
m_entryGridPriNumberingOffset->Enable( renumber );
m_entryGridSecNumberingOffset->Enable( renumber && num2d );


// Circular array options
const bool circRenumber = m_checkBoxCircRestartNumbering->GetValue();
m_choiceCircNumberingType->Enable( circRenumber );
m_entryCircNumberingStart->Enable( m_rbCircStartNumberingOpt->GetSelection() == 1 );
}


Expand All @@ -371,25 +346,22 @@ std::string DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::getCoordinateNumber( int n,
std::string itemNum;
const std::string& alphabet = alphabetFromNumberingScheme( type );

if( !alphabet.empty() )
{
const bool nonUnitColsStartAt0 = schemeNonUnitColsStartAt0( type );
const bool nonUnitColsStartAt0 = schemeNonUnitColsStartAt0( type );

bool firstRound = true;
int radix = alphabet.length();
bool firstRound = true;
int radix = alphabet.length();

do {
int modN = n % radix;
do {
int modN = n % radix;

if( nonUnitColsStartAt0 && !firstRound )
modN--; // Start the "tens/hundreds/etc column" at "Ax", not "Bx"
if( nonUnitColsStartAt0 && !firstRound )
modN--; // Start the "tens/hundreds/etc column" at "Ax", not "Bx"

itemNum.insert( 0, 1, alphabet[modN] );
itemNum.insert( 0, 1, alphabet[modN] );

n /= radix;
firstRound = false;
} while( n );
}
n /= radix;
firstRound = false;
} while( n );

return itemNum;
}
Expand Down Expand Up @@ -493,7 +465,7 @@ void DIALOG_CREATE_ARRAY::ARRAY_CIRCULAR_OPTIONS::TransformItem( int n, BOARD_IT

if( m_angle == 0 )
// angle is zero, divide evenly into m_nPts
angle = 3600.0 * n / float(m_nPts);
angle = 3600.0 * n / double( m_nPts );
else
// n'th step
angle = m_angle * n;
Expand All @@ -508,5 +480,9 @@ void DIALOG_CREATE_ARRAY::ARRAY_CIRCULAR_OPTIONS::TransformItem( int n, BOARD_IT

wxString DIALOG_CREATE_ARRAY::ARRAY_CIRCULAR_OPTIONS::GetItemNumber( int aN ) const
{
return getCoordinateNumber( aN + m_numberingOffset, m_numberingType );
// The first new pad has aN number == 1, not 0
if( m_shouldRenumber ) // numbering pad from initial user value
return getCoordinateNumber( aN - 1 + m_numberingOffset, m_numberingType );
else // numbering pad from inital pad number
return getCoordinateNumber( aN + m_numberingOffset, m_numberingType );
}
10 changes: 6 additions & 4 deletions pcbnew/dialogs/dialog_create_array.h
Expand Up @@ -190,9 +190,10 @@ class DIALOG_CREATE_ARRAY : public DIALOG_CREATE_ARRAY_BASE,
* for pin numbering on BGAs, etc
*/
NUMBERING_ALPHA_FULL, ///< Full 26-character alphabet
NUMBERING_TYPE_Max ///< Invalid maximum value, insert above here
};

#define NUMBERING_TYPE_MAX NUMBERING_ALPHA_FULL

/**
* Persistent dialog options
*/
Expand All @@ -217,11 +218,11 @@ class DIALOG_CREATE_ARRAY : public DIALOG_CREATE_ARRAY_BASE,
*/
virtual void TransformItem( int n, BOARD_ITEM* item,
const wxPoint& rotPoint ) const = 0;
virtual int GetArraySize() const = 0;
virtual int GetArraySize() const = 0;
virtual wxString GetItemNumber( int n ) const = 0;
virtual wxString InterpolateNumberIntoString( int n, const wxString& pattern ) const;

bool ShouldRenumberItems() const
bool ShouldRenumberItems() const
{
return m_shouldRenumber;
}
Expand Down Expand Up @@ -342,8 +343,9 @@ class DIALOG_CREATE_ARRAY : public DIALOG_CREATE_ARRAY_BASE,
std::string m_circCentreX, m_circCentreY,
m_circAngle, m_circCount, m_circNumberingOffset;
bool m_circRotate;

int m_arrayTypeTab;
int m_gridNumberingScheme;
int m_circNumberingScheme;
};

static CREATE_ARRAY_DIALOG_ENTRIES m_options;
Expand Down

0 comments on commit b237d81

Please sign in to comment.