From 46fcb07bcb92a281c60b6b0e0523afc45a6342ea Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 23 Apr 2011 21:01:41 +0200 Subject: [PATCH 1/4] Gerbview: export_to_pcbnew enhancement and fixes. --- gerbview/CMakeLists.txt | 1 + gerbview/class_gerber_draw_item.cpp | 2 +- gerbview/export_to_pcbnew.cpp | 389 ++++++++++++++++++---------- gerbview/select_layers_to_pcb.cpp | 220 ++++++---------- 4 files changed, 325 insertions(+), 287 deletions(-) diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index f198295a5a..10c235b360 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -17,6 +17,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} set(DIALOGS_SRCS dialogs/gerbview_dialog_display_options_frame_base.cpp dialogs/gerbview_dialog_display_options_frame.cpp + dialogs/dialog_layers_select_to_pcb_base.cpp dialogs/dialog_print_using_printer.cpp dialogs/dialog_print_using_printer_base.cpp ) diff --git a/gerbview/class_gerber_draw_item.cpp b/gerbview/class_gerber_draw_item.cpp index ec0f679ea8..eb2d182aa9 100644 --- a/gerbview/class_gerber_draw_item.cpp +++ b/gerbview/class_gerber_draw_item.cpp @@ -419,7 +419,7 @@ void GERBER_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, break; case GBR_ARC: - // Currently, arcs plotted witha rectangular aperture are not supported. + // Currently, arcs plotted with a rectangular aperture are not supported. // a round pen only is expected. #if 0 // for arc debug only GRLine( &aPanel->m_ClipBox, aDC, GetABPosition( m_Start ), diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp index 8d0bed9f70..18948b342c 100644 --- a/gerbview/export_to_pcbnew.cpp +++ b/gerbview/export_to_pcbnew.cpp @@ -10,13 +10,50 @@ #include "confirm.h" #include "kicad_string.h" #include "gestfich.h" +#include "trigo.h" #include "gerbview.h" #include "class_board_design_settings.h" #include "class_gerber_draw_item.h" -static int SavePcbFormatAscii( GERBVIEW_FRAME* frame, - FILE* File, int* LayerLookUpTable ); + +/* A helper class to export a Gerber set of files to Pcbnew +*/ +class GBR_TO_PCB_EXPORTER +{ + GERBVIEW_FRAME* m_gerbview_frame; // the maint gerber frame + FILE * m_file; // .brd file to write to + BOARD* m_pcb; // the board to populate and export + +public: + GBR_TO_PCB_EXPORTER(GERBVIEW_FRAME * aFrame, FILE * aFile ); + ~GBR_TO_PCB_EXPORTER(); + bool ExportPcb( int* LayerLookUpTable ); + +private: + bool WriteSetup( ); // Write the SETUP section data file + bool WriteGeneralDescrPcb( ); + void export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); + void export_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); + void export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); + void export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); + void export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ); + void cleanBoard(); +}; + +GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME * aFrame, FILE * aFile ) +{ + m_gerbview_frame = aFrame; + m_file = aFile; + m_pcb = NULL; +} + +GBR_TO_PCB_EXPORTER::~GBR_TO_PCB_EXPORTER() +{ + // the destructor should destroy all owned sub-objects + delete m_pcb; +} + /* Export data in pcbnew format @@ -45,8 +82,6 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) wxString PcbExt( wxT( ".brd" ) ); - FILE* dest; - msg = wxT( "*" ) + PcbExt; FullFileName = EDA_FileSelector( _( "Board file name:" ), wxEmptyString, @@ -68,143 +103,24 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) if( !IsOK( this, _( "Ok to change the existing file ?" ) ) ) return; } - dest = wxFopen( FullFileName, wxT( "wt" ) ); - if( dest == 0 ) + FILE * file = wxFopen( FullFileName, wxT( "wt" ) ); + if( file == NULL ) { msg = _( "Unable to create " ) + FullFileName; DisplayError( this, msg ); return; } GetScreen()->SetFileName( FullFileName ); - SavePcbFormatAscii( this, dest, LayerLookUpTable ); - fclose( dest ); + GBR_TO_PCB_EXPORTER gbr_exporter( this, file ); + gbr_exporter.ExportPcb( LayerLookUpTable ); + fclose( file ); } } - -static int WriteSetup( FILE* File, BOARD* Pcb ) +void GBR_TO_PCB_EXPORTER::cleanBoard() { - char text[1024]; - - fprintf( File, "$SETUP\n" ); - sprintf( text, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT ); - fprintf( File, "%s", text ); - - fprintf( File, "Layers %d\n", Pcb->GetCopperLayerCount() ); - - fprintf( File, "$EndSETUP\n\n" ); - return 1; -} - - -static bool WriteGeneralDescrPcb( BOARD* Pcb, FILE* File ) -{ - int NbLayers; - - /* Print the copper layer count */ - NbLayers = Pcb->GetCopperLayerCount(); - fprintf( File, "$GENERAL\n" ); - fprintf( File, "LayerCount %d\n", NbLayers ); - - /* Compute and print the board bounding box */ - Pcb->ComputeBoundingBox(); - fprintf( File, "Di %d %d %d %d\n", - Pcb->m_BoundaryBox.GetX(), Pcb->m_BoundaryBox.GetY(), - Pcb->m_BoundaryBox.GetRight(), - Pcb->m_BoundaryBox.GetBottom() ); - - fprintf( File, "$EndGENERAL\n\n" ); - return TRUE; -} - - -/* Routine to save the board - * @param frame = pointer to the main frame - * @param File = FILE * pointer to an already opened file - * @param LayerLookUpTable = look up table: pcbnew layer for each gerber layer - * @return 1 if OK, 0 if fail - */ -static int SavePcbFormatAscii( GERBVIEW_FRAME* frame, FILE* aFile, - int* LayerLookUpTable ) -{ - char line[256]; - BOARD* gerberPcb = frame->GetBoard(); - BOARD* pcb; - - wxBeginBusyCursor(); - - // create an image of gerber data - pcb = new BOARD( NULL, frame ); - BOARD_ITEM* item = gerberPcb->m_Drawings; - for( ; item; item = item->Next() ) - { - GERBER_DRAW_ITEM* gerb_item = (GERBER_DRAW_ITEM*) item; - int layer = gerb_item->GetLayer(); - int pcb_layer_number = LayerLookUpTable[layer]; - if( pcb_layer_number < 0 || pcb_layer_number > LAST_NO_COPPER_LAYER ) - continue; - - if( pcb_layer_number > LAST_COPPER_LAYER ) - { - DRAWSEGMENT* drawitem = new DRAWSEGMENT( pcb, TYPE_DRAWSEGMENT ); - - drawitem->SetLayer( pcb_layer_number ); - drawitem->m_Start = gerb_item->m_Start; - drawitem->m_End = gerb_item->m_End; - drawitem->m_Width = gerb_item->m_Size.x; - - if( gerb_item->m_Shape == GBR_ARC ) - { - double cx = gerb_item->m_ArcCentre.x; - double cy = gerb_item->m_ArcCentre.y; - double a = atan2( gerb_item->m_Start.y - cy, - gerb_item->m_Start.x - cx ); - double b = atan2( gerb_item->m_End.y - cy, gerb_item->m_End.x - cx ); - - drawitem->m_Shape = S_ARC; - drawitem->m_Angle = (int) fmod( - (a - b) / M_PI * 1800.0 + 3600.0, 3600.0 ); - drawitem->m_Start.x = (int) cx; - drawitem->m_Start.y = (int) cy; - } - - pcb->Add( drawitem ); - } - else - { - TRACK* newtrack; - - // replace spots with vias when possible - if( gerb_item->m_Shape == GBR_SPOT_CIRCLE - || gerb_item->m_Shape == GBR_SPOT_RECT - || gerb_item->m_Shape == GBR_SPOT_OVAL ) - { - newtrack = new SEGVIA( pcb ); - - // A spot is found, and can be a via: change it to via, and - // delete other - // spots at same location - newtrack->m_Shape = VIA_THROUGH; - newtrack->SetLayer( 0x0F ); // Layers are 0 to 15 (Cu/Cmp) - newtrack->SetDrillDefault(); - newtrack->m_Start = newtrack->m_End = gerb_item->m_Start; - newtrack->m_Width = (gerb_item->m_Size.x + gerb_item->m_Size.y) / 2; - } - else // a true TRACK - { - newtrack = new TRACK( pcb ); - newtrack->SetLayer( pcb_layer_number ); - newtrack->m_Start = gerb_item->m_Start; - newtrack->m_End = gerb_item->m_End; - newtrack->m_Width = gerb_item->m_Size.x; - } - - pcb->Add( newtrack ); - } - } - // delete redundant vias - for( TRACK * track = pcb->m_Track; track; track = track->Next() ) + for( TRACK * track = m_pcb->m_Track; track; track = track->Next() ) { if( track->m_Shape != VIA_THROUGH ) continue; @@ -226,24 +142,211 @@ static int SavePcbFormatAscii( GERBVIEW_FRAME* frame, FILE* aFile, delete alt_track; } } +} - // Switch the locale to standard C (needed to print floating point numbers - // like 1.3) +bool GBR_TO_PCB_EXPORTER::WriteSetup( ) +{ + fprintf( m_file, "$SETUP\n" ); + fprintf( m_file, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT ); + + fprintf( m_file, "Layers %d\n", m_pcb->GetCopperLayerCount() ); + + fprintf( m_file, "$EndSETUP\n\n" ); + return true; +} + + +bool GBR_TO_PCB_EXPORTER::WriteGeneralDescrPcb( ) +{ + int nbLayers; + + /* Print the copper layer count */ + nbLayers = m_pcb->GetCopperLayerCount(); + if( nbLayers <= 1 ) // Minimal layers count in Pcbnew is 2 + { + nbLayers = 2; + m_pcb->SetCopperLayerCount(2); + } + fprintf( m_file, "$GENERAL\n" ); + fprintf( m_file, "encoding utf-8\n"); + fprintf( m_file, "LayerCount %d\n", nbLayers ); + + /* Compute and print the board bounding box */ + m_pcb->ComputeBoundingBox(); + fprintf( m_file, "Di %d %d %d %d\n", + m_pcb->m_BoundaryBox.GetX(), m_pcb->m_BoundaryBox.GetY(), + m_pcb->m_BoundaryBox.GetRight(), + m_pcb->m_BoundaryBox.GetBottom() ); + + fprintf( m_file, "$EndGENERAL\n\n" ); + return true; +} + + +/* Routine to save the board + * @param frame = pointer to the main frame + * @param File = FILE * pointer to an already opened file + * @param LayerLookUpTable = look up table: pcbnew layer for each gerber layer + * @return 1 if OK, 0 if fail + */ +bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable ) +{ + char line[256]; + BOARD* gerberPcb = m_gerbview_frame->GetBoard(); + + // create an image of gerber data + m_pcb = new BOARD( NULL, m_gerbview_frame ); + BOARD_ITEM* item = gerberPcb->m_Drawings; + for( ; item; item = item->Next() ) + { + GERBER_DRAW_ITEM* gerb_item = (GERBER_DRAW_ITEM*) item; + int layer = gerb_item->GetLayer(); + int pcb_layer_number = LayerLookUpTable[layer]; + if( pcb_layer_number < 0 || pcb_layer_number > LAST_NO_COPPER_LAYER ) + continue; + + if( pcb_layer_number > LAST_COPPER_LAYER ) + export_non_copper_item( gerb_item, pcb_layer_number ); + + else + export_copper_item( gerb_item, pcb_layer_number ); + } + + cleanBoard(); + + // Switch the locale to standard C (needed to print floating point numbers) SetLocaleTo_C_standard(); - // write the PCB heading - fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB, + // write PCB header + fprintf( m_file, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB, DateAndTime( line ) ); - WriteGeneralDescrPcb( pcb, aFile ); - WriteSetup( aFile, pcb ); + WriteGeneralDescrPcb( ); + WriteSetup( ); - // write the useful part of the pcb - pcb->Save( aFile ); - - // the destructor should destroy all owned sub-objects - delete pcb; + // write items on file + m_pcb->Save( m_file ); SetLocaleTo_Default(); // revert to the current locale - wxEndBusyCursor(); - return 1; + return true; +} + +void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ) +{ + DRAWSEGMENT* drawitem = new DRAWSEGMENT( m_pcb, TYPE_DRAWSEGMENT ); + + drawitem->SetLayer( aLayer ); + drawitem->m_Start = aGbrItem->m_Start; + drawitem->m_End = aGbrItem->m_End; + drawitem->m_Width = aGbrItem->m_Size.x; + + if( aGbrItem->m_Shape == GBR_ARC ) + { + double a = atan2( (double)( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y), + (double)( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) ); + double b = atan2( (double)( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ), + (double)( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) ); + + drawitem->m_Shape = S_ARC; + drawitem->m_Angle = wxRound( (a - b) / M_PI * 1800.0 ); + drawitem->m_Start = aGbrItem->m_ArcCentre; + if( drawitem->m_Angle < 0 ) + { + NEGATE( drawitem->m_Angle ); + drawitem->m_End = aGbrItem->m_Start; + } + } + + m_pcb->Add( drawitem ); +} + +void GBR_TO_PCB_EXPORTER::export_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ) +{ + switch( aGbrItem->m_Shape ) + { + case GBR_SPOT_CIRCLE: + case GBR_SPOT_RECT: + case GBR_SPOT_OVAL: + // replace spots with vias when possible + export_flashed_copper_item( aGbrItem, aLayer ); + break; + + case GBR_ARC: +// export_segarc_copper_item( aGbrItem, aLayer ); + break; + + default: + export_segline_copper_item( aGbrItem, aLayer ); + break; + } +} + +void GBR_TO_PCB_EXPORTER::export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ) +{ + TRACK * newtrack = new TRACK( m_pcb ); + newtrack->SetLayer( aLayer ); + newtrack->m_Start = aGbrItem->m_Start; + newtrack->m_End = aGbrItem->m_End; + newtrack->m_Width = aGbrItem->m_Size.x; + m_pcb->Add( newtrack ); +} + +void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ) +{ + double a = atan2( (double)( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ), + (double)( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) ); + double b = atan2( (double)( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ), + (double)( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) ); + + int arc_angle = wxRound( ( (a - b) / M_PI * 1800.0 ) ); + wxPoint start = aGbrItem->m_Start; + wxPoint end = aGbrItem->m_End; + /* Because Pcbnew does not know arcs in tracks, + * approximate arc by segments (16 segment per 360 deg) + */ + #define DELTA 3600/16 + if( arc_angle < 0 ) + { + NEGATE( arc_angle ); + EXCHG( start, end ); + } + wxPoint curr_start = start; + for( int rot = DELTA; rot < (arc_angle - DELTA); rot += DELTA ) + { + TRACK * newtrack = new TRACK( m_pcb ); + newtrack->SetLayer( aLayer ); + newtrack->m_Start = curr_start; + wxPoint curr_end = start; + RotatePoint( &curr_end, aGbrItem->m_ArcCentre, rot ); + newtrack->m_End = curr_end; + newtrack->m_Width = aGbrItem->m_Size.x; + m_pcb->Add( newtrack ); + curr_start = curr_end; + } + if( end != curr_start ) + { + TRACK * newtrack = new TRACK( m_pcb ); + newtrack->SetLayer( aLayer ); + newtrack->m_Start = curr_start; + newtrack->m_End = end; + newtrack->m_Width = aGbrItem->m_Size.x; + m_pcb->Add( newtrack ); + } +} + + +/* + * creates a via from a flashed gerber item. + * Flashed items are usually pads or vias, so we try to export all of them + * using vias + */ +void GBR_TO_PCB_EXPORTER::export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer ) +{ + SEGVIA * newtrack = new SEGVIA( m_pcb ); + + newtrack->m_Shape = VIA_THROUGH; + newtrack->SetLayer( 0x0F ); // Layers are 0 to 15 (Cu/Cmp) + newtrack->SetDrillDefault(); + newtrack->m_Start = newtrack->m_End = aGbrItem->m_Start; + newtrack->m_Width = (aGbrItem->m_Size.x + aGbrItem->m_Size.y) / 2; + m_pcb->Add( newtrack ); } diff --git a/gerbview/select_layers_to_pcb.cpp b/gerbview/select_layers_to_pcb.cpp index ef234349f3..ec8e9819f2 100644 --- a/gerbview/select_layers_to_pcb.cpp +++ b/gerbview/select_layers_to_pcb.cpp @@ -2,16 +2,19 @@ /* Dialog frame to choose gerber layers and pcb layers */ /*******************************************************/ -/* select_layers_to_pcb.cpp */ +/** + * @file select_layers_to_pcb.cpp + */ #include "fctsys.h" #include "common.h" #include "gerbview.h" #include "class_board_design_settings.h" #include "class_GERBER.h" - #include "wx/statline.h" +#include "dialogs/dialog_layers_select_to_pcb_base.h" + #define LAYER_UNSELECTED NB_LAYERS static int ButtonTable[32]; // Indexes buttons to Gerber layers @@ -25,23 +28,18 @@ enum swap_layer_id { }; -class SWAP_LAYERS_DIALOG : public wxDialog +class LAYERS_TABLE_DIALOG : public LAYERS_TABLE_DIALOG_BASE { private: GERBVIEW_FRAME* m_Parent; - wxBoxSizer* OuterBoxSizer; - wxBoxSizer* MainBoxSizer; - wxFlexGridSizer* FlexColumnBoxSizer; wxStaticText* label; wxButton* Button; wxStaticText* text; - wxStaticLine* Line; - wxStdDialogButtonSizer* StdDialogButtonSizer; public: - SWAP_LAYERS_DIALOG( GERBVIEW_FRAME* parent ); - ~SWAP_LAYERS_DIALOG() {}; + LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ); + ~LAYERS_TABLE_DIALOG() {}; private: void OnSelectLayer( wxCommandEvent& event ); @@ -52,12 +50,10 @@ private: }; -BEGIN_EVENT_TABLE( SWAP_LAYERS_DIALOG, wxDialog ) +BEGIN_EVENT_TABLE( LAYERS_TABLE_DIALOG, wxDialog ) EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + 31, wxEVT_COMMAND_BUTTON_CLICKED, - SWAP_LAYERS_DIALOG::OnSelectLayer ) - EVT_BUTTON( wxID_OK, SWAP_LAYERS_DIALOG::OnOkClick ) - EVT_BUTTON( wxID_CANCEL, SWAP_LAYERS_DIALOG::OnCancelClick ) + LAYERS_TABLE_DIALOG::OnSelectLayer ) END_EVENT_TABLE() @@ -67,30 +63,24 @@ END_EVENT_TABLE() */ int* GERBVIEW_FRAME::InstallDialogLayerPairChoice( ) { - SWAP_LAYERS_DIALOG* frame = new SWAP_LAYERS_DIALOG( this ); + LAYERS_TABLE_DIALOG* frame = new LAYERS_TABLE_DIALOG( this ); int ii = frame->ShowModal(); frame->Destroy(); - if( ii >= 0 ) + if( ii == wxID_OK ) return LayerLookUpTable; else return NULL; } -SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( GERBVIEW_FRAME* parent ) : - wxDialog( parent, -1, _( "Layer selection:" ), wxPoint( -1, -1 ), - wxDefaultSize, wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER ) +LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : + LAYERS_TABLE_DIALOG_BASE( parent ) { - OuterBoxSizer = NULL; - MainBoxSizer = NULL; - FlexColumnBoxSizer = NULL; label = NULL; Button = NULL; text = NULL; - Line = NULL; - StdDialogButtonSizer = NULL; m_Parent = parent; @@ -118,113 +108,90 @@ SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( GERBVIEW_FRAME* parent ) : // buttons should be some other size in that version. // Compute a reasonable number of copper layers - int pcb_layer_number = 0; + int pcb_copper_layer_count = 0; for( ii = 0; ii < 32; ii++ ) { if( g_GERBER_List[ii] != NULL ) - pcb_layer_number++; + pcb_copper_layer_count++; // Specify the default value for each member of these arrays. ButtonTable[ii] = -1; LayerLookUpTable[ii] = LAYER_UNSELECTED; } - m_Parent->GetBoard()->SetCopperLayerCount(pcb_layer_number); - pcb_layer_number = 0; + // Ensure we have at least 2 copper layers and NB_COPPER_LAYERS copper layers max + if( pcb_copper_layer_count < 2 ) + pcb_copper_layer_count = 2; + if( pcb_copper_layer_count > NB_COPPER_LAYERS ) + pcb_copper_layer_count = NB_COPPER_LAYERS; + m_Parent->GetBoard()->SetCopperLayerCount(pcb_copper_layer_count); + + int pcb_layer_num = 0; for( nb_items = 0, ii = 0; ii < 32; ii++ ) { if( g_GERBER_List[ii] == NULL ) continue; - if( (pcb_layer_number == m_Parent->GetBoard()->GetCopperLayerCount() - 1) + if( (pcb_layer_num == m_Parent->GetBoard()->GetCopperLayerCount() - 1) && (m_Parent->GetBoard()->GetCopperLayerCount() > 1) ) - pcb_layer_number = LAYER_N_FRONT; + pcb_layer_num = LAYER_N_FRONT; ButtonTable[nb_items] = ii; - LayerLookUpTable[ii] = pcb_layer_number; + LayerLookUpTable[ii] = pcb_layer_num; nb_items++; - pcb_layer_number++; + pcb_layer_num++; } - OuterBoxSizer = new wxBoxSizer( wxVERTICAL ); - SetSizer( OuterBoxSizer ); - - MainBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 ); + if( nb_items <= 16 ) + m_staticlineSep->Hide(); + wxFlexGridSizer* flexColumnBoxSizer = m_flexLeftColumnBoxSizer; for( ii = 0; ii < nb_items; ii++ ) { - // If more than 16 Gerber layers are used, provide a vertical line to - // separate the two FlexGrid sizers - if( (nb_items > 16) && (ii == 16) ) - { - Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, - wxLI_VERTICAL ); - MainBoxSizer->Add( Line, 0, wxGROW | wxLEFT | wxRIGHT, 5 ); - } + // Each Gerber layer has an associated static text string (to + // identify that layer), a button (for invoking a child dialog + // box to change which pcbnew layer that the Gerber layer is + // mapped to), and a second static text string (to depict which + // pcbnew layer that the Gerber layer has been mapped to). Each + // of those items are placed into the left hand column, middle + // column, and right hand column (respectively) of the Flexgrid + // sizer, and the color of the second text string is set to + // fuchsia or blue (to respectively indicate whether the Gerber + // layer has been mapped to a pcbnew layer or is not being + // exported at all). (Experimentation has shown that if a text + // control is used to depict which pcbnew layer that each Gerber + // layer is mapped to (instead of a static text string), then + // those controls do not behave in a fully satisfactory manner + // in the Linux version. Even when the read-only attribute is + // specified for all of those controls, they can still be selected + // when the arrow keys or Tab key is used to step through all of + // the controls within the dialog box, and directives to set the + // foreground color of the text of each such control to blue (to + // indicate that the text is of a read-only nature) are disregarded. + // Specify a FlexGrid sizer with an appropriate number of rows + // and three columns. If nb_items < 16, then the number of rows + // is nb_items; otherwise, the number of rows is 16 (with two + // separate columns of controls being used if nb_items > 16). - // Provide a separate FlexGrid sizer for every sixteen sets of controls - if( ii % 16 == 0 ) - { - // Each Gerber layer has an associated static text string (to - // identify that layer), a button (for invoking a child dialog - // box to change which pcbnew layer that the Gerber layer is - // mapped to), and a second static text string (to depict which - // pcbnew layer that the Gerber layer has been mapped to). Each - // of those items are placed into the left hand column, middle - // column, and right hand column (respectively) of the Flexgrid - // sizer, and the color of the second text string is set to - // fuchsia or blue (to respectively indicate whether the Gerber - // layer has been mapped to a pcbnew layer or is not being - // exported at all). (Experimentation has shown that if a text - // control is used to depict which pcbnew layer that each Gerber - // layer is mapped to (instead of a static text string), then - // those controls do not behave in a fully satisfactory manner - // in the Linux version. Even when the read-only attribute is - // specified for all of those controls, they can still be selected - // when the arrow keys or Tab key is used to step through all of - // the controls within the dialog box, and directives to set the - // foreground color of the text of each such control to blue (to - // indicate that the text is of a read-only nature) are disregarded. - // Specify a FlexGrid sizer with an appropriate number of rows - // and three columns. If nb_items < 16, then the number of rows - // is nb_items; otherwise, the number of rows is 16 (with two - // separate columns of controls being used if nb_items > 16). - - if( nb_items < 16 ) - FlexColumnBoxSizer = new wxFlexGridSizer( nb_items, 4, 0, 0 ); - else - FlexColumnBoxSizer = new wxFlexGridSizer( 16, 4, 0, 0 ); - - // Specify that all of the rows can be expanded. - for( int jj = 0; jj < MIN( nb_items, 16 ); jj++ ) - { - FlexColumnBoxSizer->AddGrowableRow( jj ); - } - - // Specify that (just) the right-hand column can be expanded. - FlexColumnBoxSizer->AddGrowableCol( 2 ); - - MainBoxSizer->Add( FlexColumnBoxSizer, 1, wxGROW | wxTOP, 5 ); - } + if( ii == 16 ) + flexColumnBoxSizer = m_flexRightColumnBoxSizer; // Provide a text string to identify the Gerber layer - msg = _( "Layer " ); - msg << ButtonTable[ii] + 1; + msg.Printf( _( "Layer %d" ), ButtonTable[ii] + 1 ); label = new wxStaticText( this, wxID_STATIC, msg, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT ); - FlexColumnBoxSizer->Add( label, 0, + flexColumnBoxSizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | - wxALL, 5 ); + wxRIGHT|wxLEFT, 5 ); /* Add file name and extension without path. */ wxFileName fn( g_GERBER_List[ii]->m_FileName ); label = new wxStaticText( this, wxID_STATIC, fn.GetFullName(), wxDefaultPosition, wxDefaultSize ); - FlexColumnBoxSizer->Add( label, 0, + flexColumnBoxSizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | - wxALL, 5 ); + wxRIGHT|wxLEFT, 5 ); // Provide a button for this layer (which will invoke a child dialog box) item_ID = ID_BUTTON_0 + ii; @@ -232,9 +199,9 @@ SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( GERBVIEW_FRAME* parent ) : Button = new wxButton( this, item_ID, wxT( "..." ), wxDefaultPosition, wxSize( w, h ), 0 ); - FlexColumnBoxSizer->Add( Button, 0, + flexColumnBoxSizer->Add( Button, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | - wxALL, 5 ); + wxRIGHT|wxLEFT, 5 ); // Provide another text string to specify which pcbnew layer that this // Gerber layer is initially mapped to, and set the initial text to @@ -273,57 +240,20 @@ SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( GERBVIEW_FRAME* parent ) : wxDefaultSize, 0 ); } text->SetMinSize( goodSize ); - FlexColumnBoxSizer->Add( text, 1, - wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, + flexColumnBoxSizer->Add( text, 1, + wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT| wxLEFT, 5 ); layer_list[ii] = text; } - // If required, provide spacers to occupy otherwise blank cells within the - // second FlexGrid sizer. (As it incorporates three columns, three spacers - // are thus required for each otherwise unused row.) - if( 16 < nb_items && nb_items < 32 ) - { - for( ii = 4 * nb_items; ii < 96; ii++ ) - { - FlexColumnBoxSizer->Add( 5, h, 0, - wxALIGN_CENTER_HORIZONTAL | - wxALIGN_CENTER_VERTICAL | wxLEFT | - wxRIGHT | wxBOTTOM, 5 ); - } - } - - // Provide a line to separate the controls which have been provided so far - // from the OK and Cancel buttons (which will be provided after this line) - Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, - wxLI_HORIZONTAL ); - OuterBoxSizer->Add( Line, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 ); - - // Provide a StdDialogButtonSizer to accommodate the OK and Cancel buttons; - // using that type of sizer results in those buttons being automatically - // located in positions appropriate for each (OS) version of KiCad. - StdDialogButtonSizer = new wxStdDialogButtonSizer; - OuterBoxSizer->Add( StdDialogButtonSizer, 0, wxGROW | wxALL, 10 ); - - Button = new wxButton( this, wxID_OK, _( "&OK" ), wxDefaultPosition, - wxDefaultSize, 0 ); - StdDialogButtonSizer->AddButton( Button ); - - Button = new wxButton( this, wxID_CANCEL, _( "&Cancel" ), - wxDefaultPosition, wxDefaultSize, 0 ); - StdDialogButtonSizer->AddButton( Button ); - StdDialogButtonSizer->Realize(); - // Resize the dialog - if( GetSizer() ) - { - GetSizer()->SetSizeHints( this ); - } + GetSizer()->SetSizeHints( this ); + Centre(); } -void SWAP_LAYERS_DIALOG::OnSelectLayer( wxCommandEvent& event ) +void LAYERS_TABLE_DIALOG::OnSelectLayer( wxCommandEvent& event ) { int ii, jj; @@ -365,13 +295,13 @@ void SWAP_LAYERS_DIALOG::OnSelectLayer( wxCommandEvent& event ) } -void SWAP_LAYERS_DIALOG::OnCancelClick( wxCommandEvent& event ) +void LAYERS_TABLE_DIALOG::OnCancelClick( wxCommandEvent& event ) { - EndModal( -1 ); + EndModal( wxID_CANCEL ); } -void SWAP_LAYERS_DIALOG::OnOkClick( wxCommandEvent& event ) +void LAYERS_TABLE_DIALOG::OnOkClick( wxCommandEvent& event ) { int ii; bool AsCmpLayer = false; @@ -395,10 +325,14 @@ void SWAP_LAYERS_DIALOG::OnOkClick( wxCommandEvent& event ) if( AsCmpLayer ) layers_count++; + if( layers_count > NB_COPPER_LAYERS ) // should not occur. layers_count = NB_COPPER_LAYERS; + if( layers_count < 2 ) + layers_count = 2; + m_Parent->GetBoard()->SetCopperLayerCount( layers_count ); - EndModal( 1 ); + EndModal( wxID_OK ); } From a7a4dab4e69c6926955fea2e47d5bd9633632b8c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 23 Apr 2011 21:08:00 +0200 Subject: [PATCH 2/4] Gerbview: export_to_pcbnew enhancement and fixes. --- .../dialog_layers_select_to_pcb_base.cpp | 86 +++ .../dialog_layers_select_to_pcb_base.fbp | 551 ++++++++++++++++++ .../dialog_layers_select_to_pcb_base.h | 68 +++ 3 files changed, 705 insertions(+) create mode 100644 gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp create mode 100644 gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp create mode 100644 gerbview/dialogs/dialog_layers_select_to_pcb_base.h diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp b/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp new file mode 100644 index 0000000000..d24b388438 --- /dev/null +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp @@ -0,0 +1,86 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Nov 17 2010) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_layers_select_to_pcb_base.h" + +/////////////////////////////////////////////////////////////////////////// + +BEGIN_EVENT_TABLE( LAYERS_TABLE_DIALOG_BASE, wxDialog ) + EVT_BUTTON( wxID_CANCEL, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnCancelClick ) + EVT_BUTTON( wxID_OK, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnOkClick ) +END_EVENT_TABLE() + +LAYERS_TABLE_DIALOG_BASE::LAYERS_TABLE_DIALOG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizerMain; + bSizerMain = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* sbUpperSizer; + sbUpperSizer = new wxBoxSizer( wxHORIZONTAL ); + + sbSizerLayersTable = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Layers selection:") ), wxHORIZONTAL ); + + m_flexLeftColumnBoxSizer = new wxFlexGridSizer( 16, 4, 0, 0 ); + m_flexLeftColumnBoxSizer->AddGrowableCol( 0 ); + m_flexLeftColumnBoxSizer->AddGrowableCol( 1 ); + m_flexLeftColumnBoxSizer->AddGrowableCol( 2 ); + m_flexLeftColumnBoxSizer->AddGrowableCol( 3 ); + m_flexLeftColumnBoxSizer->SetFlexibleDirection( wxBOTH ); + m_flexLeftColumnBoxSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + sbSizerLayersTable->Add( m_flexLeftColumnBoxSizer, 1, wxEXPAND, 5 ); + + m_staticlineSep = new wxStaticLine( this, ID_M_STATICLINESEP, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL ); + sbSizerLayersTable->Add( m_staticlineSep, 0, wxEXPAND | wxALL, 5 ); + + m_flexRightColumnBoxSizer = new wxFlexGridSizer( 16, 4, 0, 0 ); + m_flexRightColumnBoxSizer->AddGrowableCol( 0 ); + m_flexRightColumnBoxSizer->AddGrowableCol( 1 ); + m_flexRightColumnBoxSizer->AddGrowableCol( 2 ); + m_flexRightColumnBoxSizer->AddGrowableCol( 3 ); + m_flexRightColumnBoxSizer->SetFlexibleDirection( wxBOTH ); + m_flexRightColumnBoxSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + sbSizerLayersTable->Add( m_flexRightColumnBoxSizer, 1, wxEXPAND, 5 ); + + sbUpperSizer->Add( sbSizerLayersTable, 1, wxEXPAND, 5 ); + + wxBoxSizer* bSizerButtons; + bSizerButtons = new wxBoxSizer( wxVERTICAL ); + + m_buttonStore = new wxButton( this, wxID_ANY, _("Store Choice"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButtons->Add( m_buttonStore, 0, wxALL|wxEXPAND, 5 ); + + m_buttonRetrieve = new wxButton( this, wxID_ANY, _("Get Stored Choice"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButtons->Add( m_buttonRetrieve, 0, wxALL|wxEXPAND, 5 ); + + sbUpperSizer->Add( bSizerButtons, 0, wxALIGN_CENTER_VERTICAL, 5 ); + + bSizerMain->Add( sbUpperSizer, 1, wxEXPAND, 5 ); + + m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + bSizerMain->Add( m_staticline1, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); + + m_sdbSizerButtons = new wxStdDialogButtonSizer(); + m_sdbSizerButtonsOK = new wxButton( this, wxID_OK ); + m_sdbSizerButtons->AddButton( m_sdbSizerButtonsOK ); + m_sdbSizerButtonsCancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizerButtons->AddButton( m_sdbSizerButtonsCancel ); + m_sdbSizerButtons->Realize(); + bSizerMain->Add( m_sdbSizerButtons, 0, wxALIGN_RIGHT|wxALL, 5 ); + + this->SetSizer( bSizerMain ); + this->Layout(); + + this->Centre( wxBOTH ); +} + +LAYERS_TABLE_DIALOG_BASE::~LAYERS_TABLE_DIALOG_BASE() +{ +} diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp b/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp new file mode 100644 index 0000000000..a5a0e4b644 --- /dev/null +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp @@ -0,0 +1,551 @@ + + + + + + C++ + 1 + source_name + 0 + UTF-8 + table + dialog_layers_select_to_pcb_base + 1000 + none + 1 + dialog_layers_select_to_pcb_base + + . + + 1 + 1 + 1 + 0 + + 1 + 1 + 1 + 1 + 0 + + + + 1 + wxBOTH + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + impl_virtual + + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 1 + LAYERS_TABLE_DIALOG_BASE + 1 + + + 1 + + + Resizable + + 1 + 400,286 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + + Layer selection: + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bSizerMain + wxVERTICAL + none + + 5 + wxEXPAND + 1 + + + sbUpperSizer + wxHORIZONTAL + none + + 5 + wxEXPAND + 1 + + wxID_ANY + Layers selection: + + sbSizerLayersTable + wxHORIZONTAL + protected + + + 5 + wxEXPAND + 1 + + 4 + wxBOTH + 0,1,2,3 + + 0 + + m_flexLeftColumnBoxSizer + wxFLEX_GROWMODE_SPECIFIED + protected + 16 + 0 + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + ID_M_STATICLINESEP + + 0 + + 0 + + 1 + m_staticlineSep + 1 + + + protected + 1 + + + Resizable + + 1 + + wxLI_VERTICAL + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 1 + + 4 + wxBOTH + 0,1,2,3 + + 0 + + m_flexRightColumnBoxSizer + wxFLEX_GROWMODE_SPECIFIED + protected + 16 + 0 + + + + + + 5 + wxALIGN_CENTER_VERTICAL + 0 + + + bSizerButtons + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Store Choice + + 0 + + 0 + + 1 + m_buttonStore + 1 + + + protected + 1 + + + Resizable + + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Get Stored Choice + + 0 + + 0 + + 1 + m_buttonRetrieve + 1 + + + protected + 1 + + + Resizable + + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 1 + m_staticline1 + 1 + + + protected + 1 + + + Resizable + + 1 + + wxLI_HORIZONTAL + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_RIGHT|wxALL + 0 + + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizerButtons + protected + + OnCancelClick + + + + OnOkClick + + + + + + + + diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.h b/gerbview/dialogs/dialog_layers_select_to_pcb_base.h new file mode 100644 index 0000000000..a6796eeb48 --- /dev/null +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.h @@ -0,0 +1,68 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Nov 17 2010) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __dialog_layers_select_to_pcb_base__ +#define __dialog_layers_select_to_pcb_base__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +/// Class LAYERS_TABLE_DIALOG_BASE +/////////////////////////////////////////////////////////////////////////////// +class LAYERS_TABLE_DIALOG_BASE : public wxDialog +{ + DECLARE_EVENT_TABLE() + private: + + // Private event handlers + void _wxFB_OnCancelClick( wxCommandEvent& event ){ OnCancelClick( event ); } + void _wxFB_OnOkClick( wxCommandEvent& event ){ OnOkClick( event ); } + + + protected: + enum + { + ID_M_STATICLINESEP = 1000, + }; + + wxStaticBoxSizer* sbSizerLayersTable; + wxFlexGridSizer* m_flexLeftColumnBoxSizer; + wxStaticLine* m_staticlineSep; + wxFlexGridSizer* m_flexRightColumnBoxSizer; + wxButton* m_buttonStore; + wxButton* m_buttonRetrieve; + wxStaticLine* m_staticline1; + wxStdDialogButtonSizer* m_sdbSizerButtons; + wxButton* m_sdbSizerButtonsOK; + wxButton* m_sdbSizerButtonsCancel; + + // Virtual event handlers, overide them in your derived class + virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } + virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } + + + public: + + LAYERS_TABLE_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Layer selection:"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 400,286 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~LAYERS_TABLE_DIALOG_BASE(); + +}; + +#endif //__dialog_layers_select_to_pcb_base__ From 81947a4f5a3e7b23b4e14d6de14a28c1f77df0a2 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 24 Apr 2011 20:26:42 +0200 Subject: [PATCH 3/4] Gerbview: export_to_pcbnew enhancements. --- .../dialog_layers_select_to_pcb_base.cpp | 10 +- .../dialog_layers_select_to_pcb_base.fbp | 93 +++++++++- .../dialog_layers_select_to_pcb_base.h | 10 ++ gerbview/select_layers_to_pcb.cpp | 168 +++++++++++++----- 4 files changed, 230 insertions(+), 51 deletions(-) diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp b/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp index d24b388438..8c00e9232f 100644 --- a/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp @@ -10,6 +10,9 @@ /////////////////////////////////////////////////////////////////////////// BEGIN_EVENT_TABLE( LAYERS_TABLE_DIALOG_BASE, wxDialog ) + EVT_BUTTON( ID_STORE_CHOICE, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnStoreSetup ) + EVT_BUTTON( ID_GET_PREVIOUS_CHOICE, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnGetSetup ) + EVT_BUTTON( ID_RESET_CHOICE, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnResetClick ) EVT_BUTTON( wxID_CANCEL, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnCancelClick ) EVT_BUTTON( wxID_OK, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnOkClick ) END_EVENT_TABLE() @@ -54,12 +57,15 @@ LAYERS_TABLE_DIALOG_BASE::LAYERS_TABLE_DIALOG_BASE( wxWindow* parent, wxWindowID wxBoxSizer* bSizerButtons; bSizerButtons = new wxBoxSizer( wxVERTICAL ); - m_buttonStore = new wxButton( this, wxID_ANY, _("Store Choice"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonStore = new wxButton( this, ID_STORE_CHOICE, _("Store Choice"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerButtons->Add( m_buttonStore, 0, wxALL|wxEXPAND, 5 ); - m_buttonRetrieve = new wxButton( this, wxID_ANY, _("Get Stored Choice"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonRetrieve = new wxButton( this, ID_GET_PREVIOUS_CHOICE, _("Get Stored Choice"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerButtons->Add( m_buttonRetrieve, 0, wxALL|wxEXPAND, 5 ); + m_buttonReset = new wxButton( this, ID_RESET_CHOICE, _("Reset"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButtons->Add( m_buttonReset, 0, wxALL|wxEXPAND, 5 ); + sbUpperSizer->Add( bSizerButtons, 0, wxALIGN_CENTER_VERTICAL, 5 ); bSizerMain->Add( sbUpperSizer, 1, wxEXPAND, 5 ); diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp b/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp index a5a0e4b644..5bdb4183c0 100644 --- a/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp @@ -291,7 +291,7 @@ 0 0 - wxID_ANY + ID_STORE_CHOICE Store Choice 0 @@ -322,7 +322,7 @@ - + OnStoreSetup @@ -376,7 +376,7 @@ 0 0 - wxID_ANY + ID_GET_PREVIOUS_CHOICE Get Stored Choice 0 @@ -407,7 +407,92 @@ - + OnGetSetup + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + ID_RESET_CHOICE + Reset + + 0 + + 0 + + 1 + m_buttonReset + 1 + + + protected + 1 + + + Resizable + + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnResetClick diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.h b/gerbview/dialogs/dialog_layers_select_to_pcb_base.h index a6796eeb48..203438ac71 100644 --- a/gerbview/dialogs/dialog_layers_select_to_pcb_base.h +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.h @@ -32,6 +32,9 @@ class LAYERS_TABLE_DIALOG_BASE : public wxDialog private: // Private event handlers + void _wxFB_OnStoreSetup( wxCommandEvent& event ){ OnStoreSetup( event ); } + void _wxFB_OnGetSetup( wxCommandEvent& event ){ OnGetSetup( event ); } + void _wxFB_OnResetClick( wxCommandEvent& event ){ OnResetClick( event ); } void _wxFB_OnCancelClick( wxCommandEvent& event ){ OnCancelClick( event ); } void _wxFB_OnOkClick( wxCommandEvent& event ){ OnOkClick( event ); } @@ -40,6 +43,9 @@ class LAYERS_TABLE_DIALOG_BASE : public wxDialog enum { ID_M_STATICLINESEP = 1000, + ID_STORE_CHOICE, + ID_GET_PREVIOUS_CHOICE, + ID_RESET_CHOICE, }; wxStaticBoxSizer* sbSizerLayersTable; @@ -48,12 +54,16 @@ class LAYERS_TABLE_DIALOG_BASE : public wxDialog wxFlexGridSizer* m_flexRightColumnBoxSizer; wxButton* m_buttonStore; wxButton* m_buttonRetrieve; + wxButton* m_buttonReset; wxStaticLine* m_staticline1; wxStdDialogButtonSizer* m_sdbSizerButtons; wxButton* m_sdbSizerButtonsOK; wxButton* m_sdbSizerButtonsCancel; // Virtual event handlers, overide them in your derived class + virtual void OnStoreSetup( wxCommandEvent& event ) { event.Skip(); } + virtual void OnGetSetup( wxCommandEvent& event ) { event.Skip(); } + virtual void OnResetClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } diff --git a/gerbview/select_layers_to_pcb.cpp b/gerbview/select_layers_to_pcb.cpp index ec8e9819f2..7b8b1d98ca 100644 --- a/gerbview/select_layers_to_pcb.cpp +++ b/gerbview/select_layers_to_pcb.cpp @@ -8,6 +8,7 @@ #include "fctsys.h" #include "common.h" +#include "appl_wxstruct.h" #include "gerbview.h" #include "class_board_design_settings.h" #include "class_GERBER.h" @@ -17,12 +18,12 @@ #define LAYER_UNSELECTED NB_LAYERS -static int ButtonTable[32]; // Indexes buttons to Gerber layers -static int LayerLookUpTable[32]; // Indexes Gerber layers to PCB file layers -wxStaticText* layer_list[32]; // Indexes text strings to buttons +static int ButtonTable[32]; // Indexes buttons to Gerber layers +static int LayerLookUpTable[32]; // Indexes Gerber layers to PCB file layers +wxStaticText* layer_list[32]; // Indexes text strings to buttons enum swap_layer_id { - ID_WINEDA_SWAPLAYERFRAME = 1800, + ID_LAYERS_TABLE_DIALOG = 1800, ID_BUTTON_0, ID_TEXT_0 = ID_BUTTON_0 + 32 }; @@ -31,29 +32,30 @@ enum swap_layer_id { class LAYERS_TABLE_DIALOG : public LAYERS_TABLE_DIALOG_BASE { private: - GERBVIEW_FRAME* m_Parent; - wxStaticText* label; - wxButton* Button; - wxStaticText* text; + GERBVIEW_FRAME* m_Parent; + int m_itemsCount; -public: - - LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ); +public: LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ); ~LAYERS_TABLE_DIALOG() {}; private: + void initDialog(); void OnSelectLayer( wxCommandEvent& event ); void OnOkClick( wxCommandEvent& event ); void OnCancelClick( wxCommandEvent& event ); + void OnStoreSetup( wxCommandEvent& event ); + void OnGetSetup( wxCommandEvent& event ); + void OnResetClick( wxCommandEvent& event ); + DECLARE_EVENT_TABLE() }; -BEGIN_EVENT_TABLE( LAYERS_TABLE_DIALOG, wxDialog ) - EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + 31, - wxEVT_COMMAND_BUTTON_CLICKED, - LAYERS_TABLE_DIALOG::OnSelectLayer ) +BEGIN_EVENT_TABLE( LAYERS_TABLE_DIALOG, LAYERS_TABLE_DIALOG_BASE ) +EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + 31, + wxEVT_COMMAND_BUTTON_CLICKED, + LAYERS_TABLE_DIALOG::OnSelectLayer ) END_EVENT_TABLE() @@ -61,8 +63,7 @@ END_EVENT_TABLE() * between gerber layers and pcbnew layers * return the "lookup table" if ok, or NULL */ -int* GERBVIEW_FRAME::InstallDialogLayerPairChoice( ) -{ +int* GERBVIEW_FRAME::InstallDialogLayerPairChoice() { LAYERS_TABLE_DIALOG* frame = new LAYERS_TABLE_DIALOG( this ); int ii = frame->ShowModal(); @@ -78,15 +79,22 @@ int* GERBVIEW_FRAME::InstallDialogLayerPairChoice( ) LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : LAYERS_TABLE_DIALOG_BASE( parent ) { - label = NULL; - Button = NULL; - text = NULL; - m_Parent = parent; + initDialog(); - int item_ID, ii, nb_items; - wxString msg; - wxSize goodSize; + // Resize the dialog + GetSizer()->SetSizeHints( this ); + Centre(); +} + + +void LAYERS_TABLE_DIALOG::initDialog() +{ + wxStaticText* label; + wxStaticText* text; + int item_ID, ii; + wxString msg; + wxSize goodSize; // Experimentation has shown that buttons in the Windows version can be 20 // pixels wide and 20 pixels high, but that they need to be 26 pixels wide @@ -124,10 +132,11 @@ LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : pcb_copper_layer_count = 2; if( pcb_copper_layer_count > NB_COPPER_LAYERS ) pcb_copper_layer_count = NB_COPPER_LAYERS; - m_Parent->GetBoard()->SetCopperLayerCount(pcb_copper_layer_count); + m_Parent->GetBoard()->SetCopperLayerCount( pcb_copper_layer_count ); int pcb_layer_num = 0; - for( nb_items = 0, ii = 0; ii < 32; ii++ ) + m_itemsCount = 0; + for( ii = 0; ii < 32; ii++ ) { if( g_GERBER_List[ii] == NULL ) continue; @@ -136,17 +145,19 @@ LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : && (m_Parent->GetBoard()->GetCopperLayerCount() > 1) ) pcb_layer_num = LAYER_N_FRONT; - ButtonTable[nb_items] = ii; + ButtonTable[m_itemsCount] = ii; LayerLookUpTable[ii] = pcb_layer_num; - nb_items++; + m_itemsCount++; pcb_layer_num++; } - if( nb_items <= 16 ) + if( m_itemsCount <= 16 ) // Only one list is enough + { m_staticlineSep->Hide(); + } wxFlexGridSizer* flexColumnBoxSizer = m_flexLeftColumnBoxSizer; - for( ii = 0; ii < nb_items; ii++ ) + for( ii = 0; ii < m_itemsCount; ii++ ) { // Each Gerber layer has an associated static text string (to // identify that layer), a button (for invoking a child dialog @@ -183,7 +194,7 @@ LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : wxDefaultSize, wxALIGN_RIGHT ); flexColumnBoxSizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | - wxRIGHT|wxLEFT, 5 ); + wxRIGHT | wxLEFT, 5 ); /* Add file name and extension without path. */ wxFileName fn( g_GERBER_List[ii]->m_FileName ); @@ -191,17 +202,15 @@ LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : wxDefaultPosition, wxDefaultSize ); flexColumnBoxSizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | - wxRIGHT|wxLEFT, 5 ); + wxRIGHT | wxLEFT, 5 ); // Provide a button for this layer (which will invoke a child dialog box) item_ID = ID_BUTTON_0 + ii; - - Button = new wxButton( this, item_ID, wxT( "..." ), - wxDefaultPosition, wxSize( w, h ), 0 ); + wxButton * Button = new wxButton( this, item_ID, wxT( "..." ), + wxDefaultPosition, wxSize( w, h ), 0 ); flexColumnBoxSizer->Add( Button, 0, - wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | - wxRIGHT|wxLEFT, 5 ); + wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL ); // Provide another text string to specify which pcbnew layer that this // Gerber layer is initially mapped to, and set the initial text to @@ -218,7 +227,7 @@ LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : // layers are selected.) if( ii == 0 ) { - msg = _( "Do not export" ); + msg = _( "Do not export" ); text = new wxStaticText( this, item_ID, msg, wxDefaultPosition, wxDefaultSize, 0 ); goodSize = text->GetSize(); @@ -241,18 +250,86 @@ LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : } text->SetMinSize( goodSize ); flexColumnBoxSizer->Add( text, 1, - wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT| wxLEFT, + wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 5 ); layer_list[ii] = text; } - - // Resize the dialog - GetSizer()->SetSizeHints( this ); - Centre(); } +/* + * reset pcb layers selection to the default value + */ +void LAYERS_TABLE_DIALOG::OnResetClick( wxCommandEvent& event ) +{ + wxString msg; + int ii, layer; + for( ii = 0, layer = 0; ii < m_itemsCount; ii++, layer++ ) + { + if( (layer == m_Parent->GetBoard()->GetCopperLayerCount() - 1) + && (m_Parent->GetBoard()->GetCopperLayerCount() > 1) ) + layer = LAYER_N_FRONT; + LayerLookUpTable[ii] = layer; + msg = BOARD::GetDefaultLayerName( layer ); + layer_list[ii]->SetLabel( msg ); + layer_list[ii]->SetForegroundColour( wxNullColour ); + ButtonTable[ii] = ii; + } +} + + +/* Stores the current mayers selection in config + */ +void LAYERS_TABLE_DIALOG::OnStoreSetup( wxCommandEvent& event ) +{ + wxConfig* config = wxGetApp().m_EDA_Config; + config->Write( wxT("BrdLayersCount"), m_itemsCount ); + + wxString key; + for( int ii = 0; ii < 32; ii++ ) + { + key.Printf( wxT("GbrLyr%dToPcb"), ii ); + config->Write( key, LayerLookUpTable[ii] ); + } +} + +void LAYERS_TABLE_DIALOG::OnGetSetup( wxCommandEvent& event ) +{ + wxConfig* config = wxGetApp().m_EDA_Config; + int lyrcnt = 0; + config->Read( wxT("BrdLayersCount"), &lyrcnt ); + if( lyrcnt == 0 || lyrcnt != m_itemsCount ) + { + wxString msg; + msg.Printf( _("Previous stored setup as %d layers, and there are %d loaded layers"), + lyrcnt, m_itemsCount ); + wxMessageBox( msg ); + return; + } + wxString key; + for( int ii = 0; ii < 32; ii++ ) + { + key.Printf( wxT("GbrLyr%dToPcb"), ii ); + config->Read( key, &LayerLookUpTable[ii] ); + } + + for( int ii = 0; ii < m_itemsCount; ii++ ) + { + int layer = LayerLookUpTable[ii]; + if( layer == LAYER_UNSELECTED ) + { + layer_list[ii]->SetLabel( _( "Do not export" ) ); + layer_list[ii]->SetForegroundColour( *wxBLUE ); + } + else + { + layer_list[ii]->SetLabel( BOARD::GetDefaultLayerName( layer ) ); + layer_list[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) ); + } + } +} + void LAYERS_TABLE_DIALOG::OnSelectLayer( wxCommandEvent& event ) { int ii, jj; @@ -266,7 +343,7 @@ void LAYERS_TABLE_DIALOG::OnSelectLayer( wxCommandEvent& event ) jj = LayerLookUpTable[ButtonTable[ii]]; if( ( jj < 0 ) || ( jj > LAYER_UNSELECTED ) ) - jj = 0; // (Defaults to "Copper" layer.) + jj = 0; // (Defaults to "Copper" layer.) jj = m_Parent->SelectLayer( jj, -1, -1, true ); if( ( jj < 0 ) || ( jj > LAYER_UNSELECTED ) ) @@ -310,6 +387,7 @@ void LAYERS_TABLE_DIALOG::OnOkClick( wxCommandEvent& event ) * this is the max layer number + 1 (if some internal layers exist) */ int layers_count = 1; + for( ii = 0; ii < 32; ii++ ) { if( LayerLookUpTable[ii] == LAYER_N_FRONT ) @@ -317,7 +395,7 @@ void LAYERS_TABLE_DIALOG::OnOkClick( wxCommandEvent& event ) else { if( LayerLookUpTable[ii] >= LAST_COPPER_LAYER ) - continue; // not a copper layer + continue; // not a copper layer if( LayerLookUpTable[ii] >= layers_count ) layers_count++; } From 57604b0a03f653bafe8aa6ca357c4d3e98396a8c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 26 Apr 2011 10:30:16 +0200 Subject: [PATCH 4/4] Gerbview: export_to_pcbnew enhancement and fixes. --- common/build_version.cpp | 2 +- .../dialog_layers_select_to_pcb_base.cpp | 57 +- .../dialog_layers_select_to_pcb_base.fbp | 703 +++++++++++------- .../dialog_layers_select_to_pcb_base.h | 21 +- gerbview/export_to_pcbnew.cpp | 46 +- gerbview/gerbview_frame.h | 8 - gerbview/select_layers_to_pcb.cpp | 263 ++++--- gerbview/select_layers_to_pcb.h | 57 ++ packaging/windows/nsis/install.nsi | 2 +- pcbnew/sel_layer.cpp | 51 +- version.txt | 4 +- 11 files changed, 732 insertions(+), 482 deletions(-) create mode 100644 gerbview/select_layers_to_pcb.h diff --git a/common/build_version.cpp b/common/build_version.cpp index c5b99a19a6..876120a7df 100644 --- a/common/build_version.cpp +++ b/common/build_version.cpp @@ -6,7 +6,7 @@ #endif #ifndef KICAD_BUILD_VERSION -#define KICAD_BUILD_VERSION "(2011-04-17)" +#define KICAD_BUILD_VERSION "(2011-04-24)" #endif diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp b/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp index 8c00e9232f..757c1b9da5 100644 --- a/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.cpp @@ -9,15 +9,16 @@ /////////////////////////////////////////////////////////////////////////// -BEGIN_EVENT_TABLE( LAYERS_TABLE_DIALOG_BASE, wxDialog ) - EVT_BUTTON( ID_STORE_CHOICE, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnStoreSetup ) - EVT_BUTTON( ID_GET_PREVIOUS_CHOICE, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnGetSetup ) - EVT_BUTTON( ID_RESET_CHOICE, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnResetClick ) - EVT_BUTTON( wxID_CANCEL, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnCancelClick ) - EVT_BUTTON( wxID_OK, LAYERS_TABLE_DIALOG_BASE::_wxFB_OnOkClick ) +BEGIN_EVENT_TABLE( LAYERS_MAP_DIALOG_BASE, wxDialog ) + EVT_COMBOBOX( ID_M_COMBOCOPPERLAYERSCOUNT, LAYERS_MAP_DIALOG_BASE::_wxFB_OnBrdLayersCountSelection ) + EVT_BUTTON( ID_STORE_CHOICE, LAYERS_MAP_DIALOG_BASE::_wxFB_OnStoreSetup ) + EVT_BUTTON( ID_GET_PREVIOUS_CHOICE, LAYERS_MAP_DIALOG_BASE::_wxFB_OnGetSetup ) + EVT_BUTTON( ID_RESET_CHOICE, LAYERS_MAP_DIALOG_BASE::_wxFB_OnResetClick ) + EVT_BUTTON( wxID_CANCEL, LAYERS_MAP_DIALOG_BASE::_wxFB_OnCancelClick ) + EVT_BUTTON( wxID_OK, LAYERS_MAP_DIALOG_BASE::_wxFB_OnOkClick ) END_EVENT_TABLE() -LAYERS_TABLE_DIALOG_BASE::LAYERS_TABLE_DIALOG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) +LAYERS_MAP_DIALOG_BASE::LAYERS_MAP_DIALOG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); @@ -42,18 +43,34 @@ LAYERS_TABLE_DIALOG_BASE::LAYERS_TABLE_DIALOG_BASE( wxWindow* parent, wxWindowID m_staticlineSep = new wxStaticLine( this, ID_M_STATICLINESEP, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL ); sbSizerLayersTable->Add( m_staticlineSep, 0, wxEXPAND | wxALL, 5 ); - m_flexRightColumnBoxSizer = new wxFlexGridSizer( 16, 4, 0, 0 ); - m_flexRightColumnBoxSizer->AddGrowableCol( 0 ); - m_flexRightColumnBoxSizer->AddGrowableCol( 1 ); - m_flexRightColumnBoxSizer->AddGrowableCol( 2 ); - m_flexRightColumnBoxSizer->AddGrowableCol( 3 ); - m_flexRightColumnBoxSizer->SetFlexibleDirection( wxBOTH ); - m_flexRightColumnBoxSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - - sbSizerLayersTable->Add( m_flexRightColumnBoxSizer, 1, wxEXPAND, 5 ); - sbUpperSizer->Add( sbSizerLayersTable, 1, wxEXPAND, 5 ); + wxBoxSizer* bRightSizer; + bRightSizer = new wxBoxSizer( wxVERTICAL ); + + wxBoxSizer* bSizerLyrCnt; + bSizerLyrCnt = new wxBoxSizer( wxVERTICAL ); + + m_staticTextCopperlayerCount = new wxStaticText( this, ID_M_STATICTEXTCOPPERLAYERCOUNT, _("Copper layers count:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextCopperlayerCount->Wrap( -1 ); + bSizerLyrCnt->Add( m_staticTextCopperlayerCount, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + + m_comboCopperLayersCount = new wxComboBox( this, ID_M_COMBOCOPPERLAYERSCOUNT, _("2 Layers"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); + m_comboCopperLayersCount->Append( _("2 Layers") ); + m_comboCopperLayersCount->Append( _("4 Layers") ); + m_comboCopperLayersCount->Append( _("6 Layers") ); + m_comboCopperLayersCount->Append( _("8 Layers") ); + m_comboCopperLayersCount->Append( _("10 Layers") ); + m_comboCopperLayersCount->Append( _("12 Layers") ); + m_comboCopperLayersCount->Append( _("14 Layers") ); + m_comboCopperLayersCount->Append( _("16 Layers") ); + bSizerLyrCnt->Add( m_comboCopperLayersCount, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + + bRightSizer->Add( bSizerLyrCnt, 0, wxEXPAND, 5 ); + + + bRightSizer->Add( 5, 15, 1, wxEXPAND, 5 ); + wxBoxSizer* bSizerButtons; bSizerButtons = new wxBoxSizer( wxVERTICAL ); @@ -66,7 +83,9 @@ LAYERS_TABLE_DIALOG_BASE::LAYERS_TABLE_DIALOG_BASE( wxWindow* parent, wxWindowID m_buttonReset = new wxButton( this, ID_RESET_CHOICE, _("Reset"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerButtons->Add( m_buttonReset, 0, wxALL|wxEXPAND, 5 ); - sbUpperSizer->Add( bSizerButtons, 0, wxALIGN_CENTER_VERTICAL, 5 ); + bRightSizer->Add( bSizerButtons, 0, wxEXPAND, 5 ); + + sbUpperSizer->Add( bRightSizer, 0, wxALIGN_CENTER_VERTICAL, 5 ); bSizerMain->Add( sbUpperSizer, 1, wxEXPAND, 5 ); @@ -87,6 +106,6 @@ LAYERS_TABLE_DIALOG_BASE::LAYERS_TABLE_DIALOG_BASE( wxWindow* parent, wxWindowID this->Centre( wxBOTH ); } -LAYERS_TABLE_DIALOG_BASE::~LAYERS_TABLE_DIALOG_BASE() +LAYERS_MAP_DIALOG_BASE::~LAYERS_MAP_DIALOG_BASE() { } diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp b/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp index 5bdb4183c0..4856eb8d8a 100644 --- a/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp @@ -48,14 +48,14 @@ 0 0 - wxID_ANY + ID_LAYERS_MAP_DIALOG_BASE 0 0 1 - LAYERS_TABLE_DIALOG_BASE + LAYERS_MAP_DIALOG_BASE 1 @@ -234,24 +234,6 @@ - - 5 - wxEXPAND - 1 - - 4 - wxBOTH - 0,1,2,3 - - 0 - - m_flexRightColumnBoxSizer - wxFLEX_GROWMODE_SPECIFIED - protected - 16 - 0 - - @@ -260,262 +242,465 @@ 0 - bSizerButtons + bRightSizer wxVERTICAL none 5 - wxALL|wxEXPAND + wxEXPAND 0 - - 1 - 1 - 1 - 1 - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - ID_STORE_CHOICE - Store Choice - - 0 - - 0 + - 1 - m_buttonStore - 1 - - - protected - 1 - - - Resizable - - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnStoreSetup - - - - - - - - - - - - - - - - - - - - - - - + bSizerLyrCnt + wxVERTICAL + none + + 5 + wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + ID_M_STATICTEXTCOPPERLAYERCOUNT + Copper layers count: + + 0 + + 0 + + 1 + m_staticTextCopperlayerCount + 1 + + + protected + 1 + + + Resizable + + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + "2 Layers" "4 Layers" "6 Layers" "8 Layers" "10 Layers" "12 Layers" "14 Layers" "16 Layers" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + ID_M_COMBOCOPPERLAYERSCOUNT + + 0 + + 0 + + 1 + m_comboCopperLayersCount + 1 + + + protected + 1 + + + Resizable + + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 2 Layers + + + + + OnBrdLayersCountSelection + + + + + + + + + + + + + + + + + + + + + + + + + + 5 - wxALL|wxEXPAND - 0 - - 1 - 1 - 1 - 1 - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - ID_GET_PREVIOUS_CHOICE - Get Stored Choice - - 0 - - 0 - - 1 - m_buttonRetrieve - 1 - - + wxEXPAND + 1 + + 15 protected - 1 - - - Resizable - - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnGetSetup - - - - - - - - - - - - - - - - - - - - - - - + 5 5 - wxALL|wxEXPAND + wxEXPAND 0 - - 1 - 1 - 1 - 1 - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - ID_RESET_CHOICE - Reset - - 0 - - 0 + - 1 - m_buttonReset - 1 - - - protected - 1 - - - Resizable - - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnResetClick - - - - - - - - - - - - - - - - - - - - - - - + bSizerButtons + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + ID_STORE_CHOICE + Store Choice + + 0 + + 0 + + 1 + m_buttonStore + 1 + + + protected + 1 + + + Resizable + + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnStoreSetup + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + ID_GET_PREVIOUS_CHOICE + Get Stored Choice + + 0 + + 0 + + 1 + m_buttonRetrieve + 1 + + + protected + 1 + + + Resizable + + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnGetSetup + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + ID_RESET_CHOICE + Reset + + 0 + + 0 + + 1 + m_buttonReset + 1 + + + protected + 1 + + + Resizable + + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnResetClick + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.h b/gerbview/dialogs/dialog_layers_select_to_pcb_base.h index 203438ac71..57aa8f42b1 100644 --- a/gerbview/dialogs/dialog_layers_select_to_pcb_base.h +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.h @@ -18,20 +18,23 @@ #include #include #include +#include +#include #include #include /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -/// Class LAYERS_TABLE_DIALOG_BASE +/// Class LAYERS_MAP_DIALOG_BASE /////////////////////////////////////////////////////////////////////////////// -class LAYERS_TABLE_DIALOG_BASE : public wxDialog +class LAYERS_MAP_DIALOG_BASE : public wxDialog { DECLARE_EVENT_TABLE() private: // Private event handlers + void _wxFB_OnBrdLayersCountSelection( wxCommandEvent& event ){ OnBrdLayersCountSelection( event ); } void _wxFB_OnStoreSetup( wxCommandEvent& event ){ OnStoreSetup( event ); } void _wxFB_OnGetSetup( wxCommandEvent& event ){ OnGetSetup( event ); } void _wxFB_OnResetClick( wxCommandEvent& event ){ OnResetClick( event ); } @@ -42,7 +45,10 @@ class LAYERS_TABLE_DIALOG_BASE : public wxDialog protected: enum { - ID_M_STATICLINESEP = 1000, + ID_LAYERS_MAP_DIALOG_BASE = 1000, + ID_M_STATICLINESEP, + ID_M_STATICTEXTCOPPERLAYERCOUNT, + ID_M_COMBOCOPPERLAYERSCOUNT, ID_STORE_CHOICE, ID_GET_PREVIOUS_CHOICE, ID_RESET_CHOICE, @@ -51,7 +57,9 @@ class LAYERS_TABLE_DIALOG_BASE : public wxDialog wxStaticBoxSizer* sbSizerLayersTable; wxFlexGridSizer* m_flexLeftColumnBoxSizer; wxStaticLine* m_staticlineSep; - wxFlexGridSizer* m_flexRightColumnBoxSizer; + wxStaticText* m_staticTextCopperlayerCount; + wxComboBox* m_comboCopperLayersCount; + wxButton* m_buttonStore; wxButton* m_buttonRetrieve; wxButton* m_buttonReset; @@ -61,6 +69,7 @@ class LAYERS_TABLE_DIALOG_BASE : public wxDialog wxButton* m_sdbSizerButtonsCancel; // Virtual event handlers, overide them in your derived class + virtual void OnBrdLayersCountSelection( wxCommandEvent& event ) { event.Skip(); } virtual void OnStoreSetup( wxCommandEvent& event ) { event.Skip(); } virtual void OnGetSetup( wxCommandEvent& event ) { event.Skip(); } virtual void OnResetClick( wxCommandEvent& event ) { event.Skip(); } @@ -70,8 +79,8 @@ class LAYERS_TABLE_DIALOG_BASE : public wxDialog public: - LAYERS_TABLE_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Layer selection:"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 400,286 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); - ~LAYERS_TABLE_DIALOG_BASE(); + LAYERS_MAP_DIALOG_BASE( wxWindow* parent, wxWindowID id = ID_LAYERS_MAP_DIALOG_BASE, const wxString& title = _("Layer selection:"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 400,286 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~LAYERS_MAP_DIALOG_BASE(); }; diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp index 18948b342c..2496dfefd0 100644 --- a/gerbview/export_to_pcbnew.cpp +++ b/gerbview/export_to_pcbnew.cpp @@ -15,7 +15,7 @@ #include "gerbview.h" #include "class_board_design_settings.h" #include "class_gerber_draw_item.h" - +#include "select_layers_to_pcb.h" /* A helper class to export a Gerber set of files to Pcbnew */ @@ -29,6 +29,7 @@ public: GBR_TO_PCB_EXPORTER(GERBVIEW_FRAME * aFrame, FILE * aFile ); ~GBR_TO_PCB_EXPORTER(); bool ExportPcb( int* LayerLookUpTable ); + BOARD* GetBoard() { return m_pcb; } private: bool WriteSetup( ); // Write the SETUP section data file @@ -45,12 +46,11 @@ GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME * aFrame, FILE * aFile { m_gerbview_frame = aFrame; m_file = aFile; - m_pcb = NULL; + m_pcb = new BOARD( NULL, m_gerbview_frame ); } GBR_TO_PCB_EXPORTER::~GBR_TO_PCB_EXPORTER() { - // the destructor should destroy all owned sub-objects delete m_pcb; } @@ -95,26 +95,31 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) if( FullFileName == wxEmptyString ) return; - int* LayerLookUpTable; - if( ( LayerLookUpTable = InstallDialogLayerPairChoice( ) ) != NULL ) + /* Install a dialog frame to choose the mapping + * between gerber layers and pcbnew layers + */ + LAYERS_MAP_DIALOG* dlg = new LAYERS_MAP_DIALOG( this ); + int ok = dlg->ShowModal(); + dlg->Destroy(); + if( ok != wxID_OK ) + return; + + if( wxFileExists( FullFileName ) ) { - if( wxFileExists( FullFileName ) ) - { - if( !IsOK( this, _( "Ok to change the existing file ?" ) ) ) - return; - } - FILE * file = wxFopen( FullFileName, wxT( "wt" ) ); - if( file == NULL ) - { - msg = _( "Unable to create " ) + FullFileName; - DisplayError( this, msg ); + if( !IsOK( this, _( "Ok to change the existing file ?" ) ) ) return; - } - GetScreen()->SetFileName( FullFileName ); - GBR_TO_PCB_EXPORTER gbr_exporter( this, file ); - gbr_exporter.ExportPcb( LayerLookUpTable ); - fclose( file ); } + + FILE * file = wxFopen( FullFileName, wxT( "wt" ) ); + if( file == NULL ) + { + msg = _( "Unable to create " ) + FullFileName; + DisplayError( this, msg ); + return; + } + GBR_TO_PCB_EXPORTER gbr_exporter( this, file ); + gbr_exporter.ExportPcb( dlg->GetLayersLookUpTable() ); + fclose( file ); } void GBR_TO_PCB_EXPORTER::cleanBoard() @@ -195,7 +200,6 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable ) BOARD* gerberPcb = m_gerbview_frame->GetBoard(); // create an image of gerber data - m_pcb = new BOARD( NULL, m_gerbview_frame ); BOARD_ITEM* item = gerberPcb->m_Drawings; for( ; item; item = item->Next() ) { diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 4c3432e7d7..55973ec9a6 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -509,14 +509,6 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, virtual void PrintPage( wxDC* aDC, int aPrintMasklayer, bool aPrintMirrorMode, void* aData = NULL ); - /** - * Function InstallDialogLayerPairChoice - * Install a dialog frame to choose the equivalence - * between gerber layers and pcbnew layers - * @return the "lookup table" if ok, or NULL - */ - int* InstallDialogLayerPairChoice(); - /** * Function DrawItemsDCodeID * Draw the DCode value (if exists) corresponding to gerber item diff --git a/gerbview/select_layers_to_pcb.cpp b/gerbview/select_layers_to_pcb.cpp index 7b8b1d98ca..b375788c7d 100644 --- a/gerbview/select_layers_to_pcb.cpp +++ b/gerbview/select_layers_to_pcb.cpp @@ -10,74 +10,36 @@ #include "common.h" #include "appl_wxstruct.h" #include "gerbview.h" +#include "gerbview_id.h" #include "class_board_design_settings.h" #include "class_GERBER.h" #include "wx/statline.h" -#include "dialogs/dialog_layers_select_to_pcb_base.h" +#include "select_layers_to_pcb.h" #define LAYER_UNSELECTED NB_LAYERS -static int ButtonTable[32]; // Indexes buttons to Gerber layers -static int LayerLookUpTable[32]; // Indexes Gerber layers to PCB file layers -wxStaticText* layer_list[32]; // Indexes text strings to buttons - enum swap_layer_id { - ID_LAYERS_TABLE_DIALOG = 1800, + ID_LAYERS_MAP_DIALOG = ID_GERBER_END_LIST, ID_BUTTON_0, ID_TEXT_0 = ID_BUTTON_0 + 32 }; +/* + * This dialog shows the gerber files loaded, and allows user to choose: + * what gerber file and what board layer are used + * the number of copper layers + */ -class LAYERS_TABLE_DIALOG : public LAYERS_TABLE_DIALOG_BASE -{ -private: - GERBVIEW_FRAME* m_Parent; - int m_itemsCount; - -public: LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ); - ~LAYERS_TABLE_DIALOG() {}; - -private: - void initDialog(); - void OnSelectLayer( wxCommandEvent& event ); - void OnOkClick( wxCommandEvent& event ); - void OnCancelClick( wxCommandEvent& event ); - - void OnStoreSetup( wxCommandEvent& event ); - void OnGetSetup( wxCommandEvent& event ); - void OnResetClick( wxCommandEvent& event ); - - DECLARE_EVENT_TABLE() -}; - - -BEGIN_EVENT_TABLE( LAYERS_TABLE_DIALOG, LAYERS_TABLE_DIALOG_BASE ) +BEGIN_EVENT_TABLE( LAYERS_MAP_DIALOG, LAYERS_MAP_DIALOG_BASE ) EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + 31, wxEVT_COMMAND_BUTTON_CLICKED, - LAYERS_TABLE_DIALOG::OnSelectLayer ) + LAYERS_MAP_DIALOG::OnSelectLayer ) END_EVENT_TABLE() -/* Install a dialog frame to choose the equivalence - * between gerber layers and pcbnew layers - * return the "lookup table" if ok, or NULL - */ -int* GERBVIEW_FRAME::InstallDialogLayerPairChoice() { - LAYERS_TABLE_DIALOG* frame = new LAYERS_TABLE_DIALOG( this ); - - int ii = frame->ShowModal(); - - frame->Destroy(); - if( ii == wxID_OK ) - return LayerLookUpTable; - else - return NULL; -} - - -LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : - LAYERS_TABLE_DIALOG_BASE( parent ) +LAYERS_MAP_DIALOG::LAYERS_MAP_DIALOG( GERBVIEW_FRAME* parent ) : + LAYERS_MAP_DIALOG_BASE( parent ) { m_Parent = parent; initDialog(); @@ -88,14 +50,16 @@ LAYERS_TABLE_DIALOG::LAYERS_TABLE_DIALOG( GERBVIEW_FRAME* parent ) : } -void LAYERS_TABLE_DIALOG::initDialog() +void LAYERS_MAP_DIALOG::initDialog() { wxStaticText* label; wxStaticText* text; - int item_ID, ii; + int item_ID; wxString msg; wxSize goodSize; + m_flexRightColumnBoxSizer = NULL; + // Experimentation has shown that buttons in the Windows version can be 20 // pixels wide and 20 pixels high, but that they need to be 26 pixels wide // and 26 pixels high in the Linux version. (And although the dimensions @@ -116,37 +80,39 @@ void LAYERS_TABLE_DIALOG::initDialog() // buttons should be some other size in that version. // Compute a reasonable number of copper layers - int pcb_copper_layer_count = 0; - for( ii = 0; ii < 32; ii++ ) + m_exportBoardCopperLayersCount = 0; + for( int ii = 0; ii < 32; ii++ ) { if( g_GERBER_List[ii] != NULL ) - pcb_copper_layer_count++; + m_exportBoardCopperLayersCount++; // Specify the default value for each member of these arrays. - ButtonTable[ii] = -1; - LayerLookUpTable[ii] = LAYER_UNSELECTED; + m_buttonTable[ii] = -1; + m_layersLookUpTable[ii] = LAYER_UNSELECTED; } - // Ensure we have at least 2 copper layers and NB_COPPER_LAYERS copper layers max - if( pcb_copper_layer_count < 2 ) - pcb_copper_layer_count = 2; - if( pcb_copper_layer_count > NB_COPPER_LAYERS ) - pcb_copper_layer_count = NB_COPPER_LAYERS; - m_Parent->GetBoard()->SetCopperLayerCount( pcb_copper_layer_count ); + // Ensure we have: + // at least 2 copper layers and NB_COPPER_LAYERS copper layers max + // an even layers count because board *must* have even layers count + // and maxi NB_COPPER_LAYERS copper layers count + normalizeBrdLayersCount(); + + int idx = ( m_exportBoardCopperLayersCount / 2 ) - 1; + m_comboCopperLayersCount->SetSelection( idx ); int pcb_layer_num = 0; m_itemsCount = 0; - for( ii = 0; ii < 32; ii++ ) + for( int ii = 0; ii < 32; ii++ ) { if( g_GERBER_List[ii] == NULL ) continue; - if( (pcb_layer_num == m_Parent->GetBoard()->GetCopperLayerCount() - 1) - && (m_Parent->GetBoard()->GetCopperLayerCount() > 1) ) + if( (pcb_layer_num == m_exportBoardCopperLayersCount - 1) + && (m_exportBoardCopperLayersCount > 1) ) pcb_layer_num = LAYER_N_FRONT; - ButtonTable[m_itemsCount] = ii; - LayerLookUpTable[ii] = pcb_layer_num; + m_buttonTable[m_itemsCount] = ii; + m_layersLookUpTable[ii] = pcb_layer_num; m_itemsCount++; pcb_layer_num++; } @@ -155,9 +121,17 @@ void LAYERS_TABLE_DIALOG::initDialog() { m_staticlineSep->Hide(); } + else // Add the second list of gerber files + { + m_flexRightColumnBoxSizer = new wxFlexGridSizer( 16, 4, 0, 0 ); + for( int ii = 0; ii < 4; ii++ ) + m_flexRightColumnBoxSizer->AddGrowableCol( ii ); + m_flexRightColumnBoxSizer->SetFlexibleDirection( wxBOTH ); + m_flexRightColumnBoxSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + } wxFlexGridSizer* flexColumnBoxSizer = m_flexLeftColumnBoxSizer; - for( ii = 0; ii < m_itemsCount; ii++ ) + for( int ii = 0; ii < m_itemsCount; ii++ ) { // Each Gerber layer has an associated static text string (to // identify that layer), a button (for invoking a child dialog @@ -188,7 +162,7 @@ void LAYERS_TABLE_DIALOG::initDialog() flexColumnBoxSizer = m_flexRightColumnBoxSizer; // Provide a text string to identify the Gerber layer - msg.Printf( _( "Layer %d" ), ButtonTable[ii] + 1 ); + msg.Printf( _( "Layer %d" ), m_buttonTable[ii] + 1 ); label = new wxStaticText( this, wxID_STATIC, msg, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT ); @@ -239,12 +213,12 @@ void LAYERS_TABLE_DIALOG::initDialog() goodSize.x = text->GetSize().x; } - msg = BOARD::GetDefaultLayerName( LayerLookUpTable[ButtonTable[ii]] ); + msg = BOARD::GetDefaultLayerName( m_layersLookUpTable[m_buttonTable[ii]] ); text->SetLabel( msg ); } else { - msg = BOARD::GetDefaultLayerName( LayerLookUpTable[ButtonTable[ii]] ); + msg = BOARD::GetDefaultLayerName( m_layersLookUpTable[m_buttonTable[ii]] ); text = new wxStaticText( this, item_ID, msg, wxDefaultPosition, wxDefaultSize, 0 ); } @@ -253,35 +227,59 @@ void LAYERS_TABLE_DIALOG::initDialog() wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 5 ); - layer_list[ii] = text; + m_layersList[ii] = text; } } +/* Ensure m_exportBoardCopperLayersCount = 2 to NB_COPPER_LAYERS + * and it is an even value because Boards have always an even layer count + */ +void LAYERS_MAP_DIALOG::normalizeBrdLayersCount() +{ + if( ( m_exportBoardCopperLayersCount & 1 ) ) + m_exportBoardCopperLayersCount++; + + if( m_exportBoardCopperLayersCount > NB_COPPER_LAYERS ) + m_exportBoardCopperLayersCount = NB_COPPER_LAYERS; + + if( m_exportBoardCopperLayersCount < 2 ) + m_exportBoardCopperLayersCount = 2; + +} + +/* + * Called when user change the current board copper layers count + */ +void LAYERS_MAP_DIALOG::OnBrdLayersCountSelection( wxCommandEvent& event ) +{ + int id = event.GetSelection(); + m_exportBoardCopperLayersCount = (id+1) * 2; +} /* * reset pcb layers selection to the default value */ -void LAYERS_TABLE_DIALOG::OnResetClick( wxCommandEvent& event ) +void LAYERS_MAP_DIALOG::OnResetClick( wxCommandEvent& event ) { wxString msg; int ii, layer; for( ii = 0, layer = 0; ii < m_itemsCount; ii++, layer++ ) { - if( (layer == m_Parent->GetBoard()->GetCopperLayerCount() - 1) - && (m_Parent->GetBoard()->GetCopperLayerCount() > 1) ) + if( (layer == m_exportBoardCopperLayersCount - 1) + && (m_exportBoardCopperLayersCount > 1) ) layer = LAYER_N_FRONT; - LayerLookUpTable[ii] = layer; + m_layersLookUpTable[ii] = layer; msg = BOARD::GetDefaultLayerName( layer ); - layer_list[ii]->SetLabel( msg ); - layer_list[ii]->SetForegroundColour( wxNullColour ); - ButtonTable[ii] = ii; + m_layersList[ii]->SetLabel( msg ); + m_layersList[ii]->SetForegroundColour( wxNullColour ); + m_buttonTable[ii] = ii; } } /* Stores the current mayers selection in config */ -void LAYERS_TABLE_DIALOG::OnStoreSetup( wxCommandEvent& event ) +void LAYERS_MAP_DIALOG::OnStoreSetup( wxCommandEvent& event ) { wxConfig* config = wxGetApp().m_EDA_Config; config->Write( wxT("BrdLayersCount"), m_itemsCount ); @@ -290,47 +288,44 @@ void LAYERS_TABLE_DIALOG::OnStoreSetup( wxCommandEvent& event ) for( int ii = 0; ii < 32; ii++ ) { key.Printf( wxT("GbrLyr%dToPcb"), ii ); - config->Write( key, LayerLookUpTable[ii] ); + config->Write( key, m_layersLookUpTable[ii] ); } } -void LAYERS_TABLE_DIALOG::OnGetSetup( wxCommandEvent& event ) +void LAYERS_MAP_DIALOG::OnGetSetup( wxCommandEvent& event ) { wxConfig* config = wxGetApp().m_EDA_Config; - int lyrcnt = 0; - config->Read( wxT("BrdLayersCount"), &lyrcnt ); - if( lyrcnt == 0 || lyrcnt != m_itemsCount ) - { - wxString msg; - msg.Printf( _("Previous stored setup as %d layers, and there are %d loaded layers"), - lyrcnt, m_itemsCount ); - wxMessageBox( msg ); - return; - } + + config->Read( wxT("BrdLayersCount"), &m_exportBoardCopperLayersCount ); + normalizeBrdLayersCount(); + + int idx = ( m_exportBoardCopperLayersCount / 2 ) - 1; + m_comboCopperLayersCount->SetSelection( idx ); + wxString key; for( int ii = 0; ii < 32; ii++ ) { key.Printf( wxT("GbrLyr%dToPcb"), ii ); - config->Read( key, &LayerLookUpTable[ii] ); + config->Read( key, &m_layersLookUpTable[ii] ); } for( int ii = 0; ii < m_itemsCount; ii++ ) { - int layer = LayerLookUpTable[ii]; + int layer = m_layersLookUpTable[ii]; if( layer == LAYER_UNSELECTED ) { - layer_list[ii]->SetLabel( _( "Do not export" ) ); - layer_list[ii]->SetForegroundColour( *wxBLUE ); + m_layersList[ii]->SetLabel( _( "Do not export" ) ); + m_layersList[ii]->SetForegroundColour( *wxBLUE ); } else { - layer_list[ii]->SetLabel( BOARD::GetDefaultLayerName( layer ) ); - layer_list[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) ); + m_layersList[ii]->SetLabel( BOARD::GetDefaultLayerName( layer ) ); + m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) ); } } } -void LAYERS_TABLE_DIALOG::OnSelectLayer( wxCommandEvent& event ) +void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event ) { int ii, jj; @@ -341,76 +336,70 @@ void LAYERS_TABLE_DIALOG::OnSelectLayer( wxCommandEvent& event ) ii = event.GetId() - ID_BUTTON_0; - jj = LayerLookUpTable[ButtonTable[ii]]; + jj = m_layersLookUpTable[m_buttonTable[ii]]; if( ( jj < 0 ) || ( jj > LAYER_UNSELECTED ) ) - jj = 0; // (Defaults to "Copper" layer.) + jj = LAYER_N_BACK; // (Defaults to "Copper" layer.) + jj = m_Parent->SelectLayer( jj, -1, -1, true ); if( ( jj < 0 ) || ( jj > LAYER_UNSELECTED ) ) return; - if( jj != LayerLookUpTable[ButtonTable[ii]] ) + if( jj != m_layersLookUpTable[m_buttonTable[ii]] ) { - LayerLookUpTable[ButtonTable[ii]] = jj; + m_layersLookUpTable[m_buttonTable[ii]] = jj; if( jj == LAYER_UNSELECTED ) { - layer_list[ii]->SetLabel( _( "Do not export" ) ); + m_layersList[ii]->SetLabel( _( "Do not export" ) ); // Change the text color to blue (to highlight // that this layer is *not* being exported) - layer_list[ii]->SetForegroundColour( *wxBLUE ); + m_layersList[ii]->SetForegroundColour( *wxBLUE ); } else { - layer_list[ii]->SetLabel( BOARD::GetDefaultLayerName( jj ) ); + m_layersList[ii]->SetLabel( BOARD::GetDefaultLayerName( jj ) ); // Change the text color to fuchsia (to highlight // that this layer *is* being exported) - layer_list[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) ); + m_layersList[ii]->SetForegroundColour( wxColour( 255, 0, 128 ) ); } } } -void LAYERS_TABLE_DIALOG::OnCancelClick( wxCommandEvent& event ) +void LAYERS_MAP_DIALOG::OnCancelClick( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); } -void LAYERS_TABLE_DIALOG::OnOkClick( wxCommandEvent& event ) +void LAYERS_MAP_DIALOG::OnOkClick( wxCommandEvent& event ) { - int ii; - bool AsCmpLayer = false; - - /* Compute the number of copper layers - * this is the max layer number + 1 (if some internal layers exist) + /* Make some test about copper layers: + * Board must have enough copper layers to handle selected internal layers */ - int layers_count = 1; + normalizeBrdLayersCount(); - for( ii = 0; ii < 32; ii++ ) + int inner_layer_max = 0; + for( int ii = 0; ii < 32; ii++ ) { - if( LayerLookUpTable[ii] == LAYER_N_FRONT ) - AsCmpLayer = true; - else - { - if( LayerLookUpTable[ii] >= LAST_COPPER_LAYER ) - continue; // not a copper layer - if( LayerLookUpTable[ii] >= layers_count ) - layers_count++; - } + if( m_layersLookUpTable[ii] < LAYER_N_FRONT ) + { + if( m_layersLookUpTable[ii ] > inner_layer_max ) + inner_layer_max = m_layersLookUpTable[ii]; + } } - if( AsCmpLayer ) - layers_count++; - - if( layers_count > NB_COPPER_LAYERS ) // should not occur. - layers_count = NB_COPPER_LAYERS; - - if( layers_count < 2 ) - layers_count = 2; - - m_Parent->GetBoard()->SetCopperLayerCount( layers_count ); - + // inner_layer_max must be less than (or equal to) the number of + // internal copper layers + // internal copper layers = m_exportBoardCopperLayersCount-2 + if( inner_layer_max > m_exportBoardCopperLayersCount-2 ) + { + wxMessageBox( + _("The exported board has not enough copper layers to handle selected inner layers") ); + return; + } + m_layersLookUpTable[32] = m_exportBoardCopperLayersCount; EndModal( wxID_OK ); } diff --git a/gerbview/select_layers_to_pcb.h b/gerbview/select_layers_to_pcb.h new file mode 100644 index 0000000000..107717a601 --- /dev/null +++ b/gerbview/select_layers_to_pcb.h @@ -0,0 +1,57 @@ +/*******************************************************/ +/* Dialog frame to choose gerber layers and pcb layers */ +/*******************************************************/ + +/** + * @file select_layers_to_pcb.h + */ + +#ifndef _SELECT_LAYERS_TO_PCB_H_ +#define _SELECT_LAYERS_TO_PCB_H_ + +#include "wx/statline.h" + +#include "dialogs/dialog_layers_select_to_pcb_base.h" + +#define LAYER_UNSELECTED NB_LAYERS + +/* + * This dialog shows the gerber files loaded, and allows user to choose: + * what gerber file and what board layer are used + * the number of copper layers + */ +class LAYERS_MAP_DIALOG : public LAYERS_MAP_DIALOG_BASE +{ +private: + GERBVIEW_FRAME* m_Parent; + int m_itemsCount; + int m_exportBoardCopperLayersCount; + wxFlexGridSizer* m_flexRightColumnBoxSizer; // An extra wxFlexGridSizer used + // when we have more than 16 gerber files loaded + int m_layersLookUpTable[32+1]; // Indexes Gerber layers to PCB file layers + // the last value in table is the number of copper layers + int m_buttonTable[32]; // Indexes buttons to Gerber layers + wxStaticText* m_layersList[32]; // Indexes text strings to buttons + +public: LAYERS_MAP_DIALOG( GERBVIEW_FRAME* parent ); + ~LAYERS_MAP_DIALOG() {}; + + int * GetLayersLookUpTable() { return m_layersLookUpTable; } + int GetCopperLayersCount() { return m_exportBoardCopperLayersCount; } + +private: + void initDialog(); + void normalizeBrdLayersCount(); + void OnBrdLayersCountSelection( wxCommandEvent& event ); + void OnSelectLayer( wxCommandEvent& event ); + void OnOkClick( wxCommandEvent& event ); + void OnCancelClick( wxCommandEvent& event ); + + void OnStoreSetup( wxCommandEvent& event ); + void OnGetSetup( wxCommandEvent& event ); + void OnResetClick( wxCommandEvent& event ); + + DECLARE_EVENT_TABLE() +}; + +#endif // _SELECT_LAYERS_TO_PCB_H_ diff --git a/packaging/windows/nsis/install.nsi b/packaging/windows/nsis/install.nsi index 55e66badde..e57e7073d1 100644 --- a/packaging/windows/nsis/install.nsi +++ b/packaging/windows/nsis/install.nsi @@ -17,7 +17,7 @@ ; General Product Description Definitions !define PRODUCT_NAME "KiCad" -!define PRODUCT_VERSION "2011.04.17" +!define PRODUCT_VERSION "2011.04.24" !define PRODUCT_WEB_SITE "http://iut-tice.ujf-grenoble.fr/kicad/" !define SOURCEFORGE_WEB_SITE "http://kicad.sourceforge.net/" !define COMPANY_NAME "" diff --git a/pcbnew/sel_layer.cpp b/pcbnew/sel_layer.cpp index 32ac4a222e..af53ba66da 100644 --- a/pcbnew/sel_layer.cpp +++ b/pcbnew/sel_layer.cpp @@ -1,14 +1,12 @@ /* Set up the basic primitives for Layer control */ #include "fctsys.h" -#include "gr_basic.h" #include "common.h" #include "class_drawpanel.h" #include "confirm.h" #include "pcbnew.h" #include "class_board_design_settings.h" -#include "protos.h" enum layer_sel_id { @@ -18,7 +16,7 @@ enum layer_sel_id { }; -class WinEDA_SelLayerFrame : public wxDialog +class SELECT_LAYER_DIALOG : public wxDialog { private: PCB_BASE_FRAME* m_Parent; @@ -28,9 +26,9 @@ private: public: // Constructor and destructor - WinEDA_SelLayerFrame( PCB_BASE_FRAME* parent, int default_layer, + SELECT_LAYER_DIALOG( PCB_BASE_FRAME* parent, int default_layer, int min_layer, int max_layer, bool null_layer ); - ~WinEDA_SelLayerFrame() { }; + ~SELECT_LAYER_DIALOG() { }; private: void Sel_Layer( wxCommandEvent& event ); @@ -40,10 +38,10 @@ private: }; -BEGIN_EVENT_TABLE( WinEDA_SelLayerFrame, wxDialog ) - EVT_BUTTON( wxID_OK, WinEDA_SelLayerFrame::Sel_Layer ) - EVT_BUTTON( wxID_CANCEL, WinEDA_SelLayerFrame::OnCancelClick ) - EVT_RADIOBOX( ID_LAYER_SELECT, WinEDA_SelLayerFrame::Sel_Layer ) +BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, wxDialog ) + EVT_BUTTON( wxID_OK, SELECT_LAYER_DIALOG::Sel_Layer ) + EVT_BUTTON( wxID_CANCEL, SELECT_LAYER_DIALOG::OnCancelClick ) + EVT_RADIOBOX( ID_LAYER_SELECT, SELECT_LAYER_DIALOG::Sel_Layer ) END_EVENT_TABLE() @@ -70,7 +68,7 @@ int PCB_BASE_FRAME::SelectLayer( int default_layer, bool null_layer ) { int layer; - WinEDA_SelLayerFrame* frame = new WinEDA_SelLayerFrame( this, + SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this, default_layer, min_layer, max_layer, @@ -88,7 +86,7 @@ int PCB_BASE_FRAME::SelectLayer( int default_layer, * radiobuttons, in which case they are positioned (in a vertical line) * to the right of that radiobox. */ -WinEDA_SelLayerFrame::WinEDA_SelLayerFrame( PCB_BASE_FRAME* parent, +SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( PCB_BASE_FRAME* parent, int default_layer, int min_layer, int max_layer, bool null_layer ) : wxDialog( parent, -1, _( "Select Layer:" ), wxPoint( -1, -1 ), @@ -165,14 +163,11 @@ WinEDA_SelLayerFrame::WinEDA_SelLayerFrame( PCB_BASE_FRAME* parent, Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) ); ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 ); - if( GetSizer() ) - { - GetSizer()->SetSizeHints( this ); - } + GetSizer()->SetSizeHints( this ); } -void WinEDA_SelLayerFrame::Sel_Layer( wxCommandEvent& event ) +void SELECT_LAYER_DIALOG::Sel_Layer( wxCommandEvent& event ) { int ii = m_LayerId[m_LayerList->GetSelection()]; @@ -180,7 +175,7 @@ void WinEDA_SelLayerFrame::Sel_Layer( wxCommandEvent& event ) } -void WinEDA_SelLayerFrame::OnCancelClick( wxCommandEvent& event ) +void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event ) { EndModal( -1 ); } @@ -190,7 +185,7 @@ void WinEDA_SelLayerFrame::OnCancelClick( wxCommandEvent& event ) /* Dialog for the selecting pairs of layers. */ /*********************************************/ -class WinEDA_SelLayerPairFrame : public wxDialog +class SELECT_LAYERS_PAIR_DIALOG : public wxDialog { private: PCB_BASE_FRAME* m_Parent; @@ -198,8 +193,8 @@ private: wxRadioBox* m_LayerListBOTTOM; int m_LayerId[NB_COPPER_LAYERS]; -public: WinEDA_SelLayerPairFrame( PCB_BASE_FRAME* parent ); - ~WinEDA_SelLayerPairFrame() { }; +public: SELECT_LAYERS_PAIR_DIALOG( PCB_BASE_FRAME* parent ); + ~SELECT_LAYERS_PAIR_DIALOG() { }; private: void OnOkClick( wxCommandEvent& event ); @@ -209,9 +204,9 @@ private: }; -BEGIN_EVENT_TABLE( WinEDA_SelLayerPairFrame, wxDialog ) - EVT_BUTTON( wxID_OK, WinEDA_SelLayerPairFrame::OnOkClick ) - EVT_BUTTON( wxID_CANCEL, WinEDA_SelLayerPairFrame::OnCancelClick ) +BEGIN_EVENT_TABLE( SELECT_LAYERS_PAIR_DIALOG, wxDialog ) + EVT_BUTTON( wxID_OK, SELECT_LAYERS_PAIR_DIALOG::OnOkClick ) + EVT_BUTTON( wxID_CANCEL, SELECT_LAYERS_PAIR_DIALOG::OnCancelClick ) END_EVENT_TABLE() @@ -232,8 +227,8 @@ void PCB_BASE_FRAME::SelectLayerPair() return; } - WinEDA_SelLayerPairFrame* frame = - new WinEDA_SelLayerPairFrame( this ); + SELECT_LAYERS_PAIR_DIALOG* frame = + new SELECT_LAYERS_PAIR_DIALOG( this ); int result = frame->ShowModal(); frame->Destroy(); @@ -248,7 +243,7 @@ void PCB_BASE_FRAME::SelectLayerPair() } -WinEDA_SelLayerPairFrame::WinEDA_SelLayerPairFrame( PCB_BASE_FRAME* parent ) : +SELECT_LAYERS_PAIR_DIALOG::SELECT_LAYERS_PAIR_DIALOG( PCB_BASE_FRAME* parent ) : wxDialog( parent, -1, _( "Select Layer Pair:" ), wxPoint( -1, -1 ), wxSize( 470, 250 ), DIALOG_STYLE ) { @@ -325,7 +320,7 @@ WinEDA_SelLayerPairFrame::WinEDA_SelLayerPairFrame( PCB_BASE_FRAME* parent ) : } -void WinEDA_SelLayerPairFrame::OnOkClick( wxCommandEvent& event ) +void SELECT_LAYERS_PAIR_DIALOG::OnOkClick( wxCommandEvent& event ) { // select the same layer for top and bottom is allowed (normal in some // boards) @@ -343,7 +338,7 @@ void WinEDA_SelLayerPairFrame::OnOkClick( wxCommandEvent& event ) } -void WinEDA_SelLayerPairFrame::OnCancelClick( wxCommandEvent& event ) +void SELECT_LAYERS_PAIR_DIALOG::OnCancelClick( wxCommandEvent& event ) { EndModal( -1 ); } diff --git a/version.txt b/version.txt index 075505211a..d8eaea9ec3 100644 --- a/version.txt +++ b/version.txt @@ -1,4 +1,4 @@ release version: -2011 apr 17 +2011 apr 24 files (.zip,.tgz): -kicad-2011-04-17 +kicad-2011-04-24