void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) { if( m_footprintList->GetCount() == 0 ) return; int ii = m_footprintList->GetSelection(); if( ii < 0 ) return; wxString name = m_footprintList->GetString( ii ); if( m_footprintName.CmpNoCase( name ) != 0 ) { m_footprintName = name; SetCurItem( NULL ); // Delete the current footprint GetBoard()->m_Modules.DeleteAll(); FPID id; id.SetLibNickname( m_libraryName ); id.SetFootprintName( m_footprintName ); try { GetBoard()->Add( loadFootprint( id ) ); } catch( const IO_ERROR& ioe ) { wxString msg; msg.Printf( _( "Could not load footprint \"%s\" from library \"%s\".\n\n" "Error %s." ), GetChars( m_footprintName ), GetChars( m_libraryName ), GetChars( ioe.errorText ) ); DisplayError( this, msg ); } UpdateTitle(); Zoom_Automatique( false ); m_canvas->Refresh(); Update3D_Frame(); } }
FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintName ) { if( aFootprintName.IsEmpty() ) return NULL; BOOST_FOREACH( FOOTPRINT_INFO& fp, m_list ) { FPID fpid; wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, NULL, wxString::Format( wxT( "'%s' is not a valid FPID." ), GetChars( aFootprintName ) ) ); wxString libNickname = fpid.GetLibNickname(); wxString footprintName = fpid.GetFootprintName(); if( libNickname == fp.GetNickname() && footprintName == fp.GetFootprintName() ) return &fp; }
MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName ) { MODULE* footprint = NULL; try { FPID fpid; if( fpid.Parse( aFootprintName ) >= 0 ) { DisplayInfoMessage( this, wxString::Format( wxT( "Footprint ID <%s> is not valid." ), GetChars( aFootprintName ) ) ); return NULL; } std::string nickname = fpid.GetLibNickname(); std::string fpname = fpid.GetFootprintName(); wxLogDebug( wxT( "Load footprint <%s> from library <%s>." ), fpname.c_str(), nickname.c_str() ); footprint = Prj().PcbFootprintLibs()->FootprintLoad( FROM_UTF8( nickname.c_str() ), FROM_UTF8( fpname.c_str() ) ); } catch( const IO_ERROR& ioe ) { DisplayError( this, ioe.errorText ); return NULL; } if( footprint ) { footprint->SetParent( (EDA_ITEM*) GetBoard() ); footprint->SetPosition( wxPoint( 0, 0 ) ); return footprint; } wxString msg = wxString::Format( _( "Footprint '%s' not found" ), aFootprintName.GetData() ); DisplayError( this, msg ); return NULL; }
bool CMP_READER::Load( NETLIST* aNetlist ) throw( IO_ERROR, PARSE_ERROR ) { wxCHECK_MSG( aNetlist != NULL,true, wxT( "No netlist passed to CMP_READER::Load()" ) ); wxString reference; // Stores value read from line like Reference = BUS1; wxString timestamp; // Stores value read from line like TimeStamp = /32307DE2/AA450F67; wxString footprint; // Stores value read from line like IdModule = CP6; wxString buffer; wxString value; bool ok = true; while( m_lineReader->ReadLine() ) { buffer = FROM_UTF8( m_lineReader->Line() ); if( !buffer.StartsWith( wxT( "BeginCmp" ) ) ) continue; // Begin component description. reference.Empty(); footprint.Empty(); timestamp.Empty(); while( m_lineReader->ReadLine() ) { buffer = FROM_UTF8( m_lineReader->Line() ); if( buffer.StartsWith( wxT( "EndCmp" ) ) ) break; // store string value, stored between '=' and ';' delimiters. value = buffer.AfterFirst( '=' ); value = value.BeforeLast( ';' ); value.Trim( true ); value.Trim( false ); if( buffer.StartsWith( wxT( "Reference" ) ) ) { reference = value; continue; } if( buffer.StartsWith( wxT( "IdModule =" ) ) ) { footprint = value; continue; } if( buffer.StartsWith( wxT( "TimeStamp =" ) ) ) { timestamp = value; continue; } } // Find the corresponding item in component list: COMPONENT* component = aNetlist->GetComponentByReference( reference ); // The corresponding component could no longer existing in the netlist. This // can happen when it is removed from schematic and still exists in footprint // assignment list. This is an usual case during the life of a design. if( component ) { FPID fpid; if( !footprint.IsEmpty() && fpid.Parse( footprint ) >= 0 ) { wxString error; error.Printf( _( "invalid footprint ID in\nfile: <%s>\nline: %d" ), GetChars( m_lineReader->GetSource() ), m_lineReader->LineNumber() ); THROW_IO_ERROR( error ); } // For checking purpose, store the existing FPID (if any) in the alternate fpid copy // if this existing FPID differs from the FPID read from the .cmp file. // CvPcb can ask for user to chose the right FPID. // It happens if the FPID was modified outside CvPcb. if( fpid != component->GetFPID() && !component->GetFPID().empty() ) component->SetAltFPID( component->GetFPID() ); component->SetFPID( fpid ); } else { ok = false; // can be used to display a warning in Pcbnew. } } return ok; }
void KICAD_NETLIST_PARSER::parseComponent() throw( IO_ERROR, PARSE_ERROR, boost::bad_pointer ) { /* Parses a section like * (comp (ref P1) * (value DB25FEMELLE) * (footprint DB25FC) * (libsource (lib conn) (part DB25)) * (sheetpath (names /) (tstamps /)) * (tstamp 3256759C)) * * other fields (unused) are skipped * A component need a reference, value, footprint name and a full time stamp * The full time stamp is the sheetpath time stamp + the component time stamp */ FPID fpid; wxString footprint; wxString tmp; wxString ref; wxString value; wxString library; wxString name; wxString pathtimestamp, timestamp; // The token comp was read, so the next data is (ref P1) while( (token = NextTok()) != T_RIGHT ) { if( token == T_LEFT ) token = NextTok(); switch( token ) { case T_ref: NeedSYMBOLorNUMBER(); ref = FROM_UTF8( CurText() ); NeedRIGHT(); break; case T_value: NeedSYMBOLorNUMBER(); value = FROM_UTF8( CurText() ); NeedRIGHT(); break; case T_footprint: NeedSYMBOLorNUMBER(); footprint = FromUTF8(); NeedRIGHT(); break; case T_libsource: // Read libsource while( (token = NextTok()) != T_RIGHT ) { if( token == T_LEFT ) token = NextTok(); if( token == T_lib ) { NeedSYMBOLorNUMBER(); library = FROM_UTF8( CurText() ); NeedRIGHT(); } else if( token == T_part ) { NeedSYMBOLorNUMBER(); name = FROM_UTF8( CurText() ); NeedRIGHT(); } else { Expecting( "part or lib" ); } } break; case T_sheetpath: while( ( token = NextTok() ) != T_tstamps ); NeedSYMBOLorNUMBER(); pathtimestamp = FROM_UTF8( CurText() ); NeedRIGHT(); NeedRIGHT(); break; case T_tstamp: NeedSYMBOLorNUMBER(); timestamp = FROM_UTF8( CurText() ); NeedRIGHT(); break; default: // Skip not used data (i.e all other tokens) skipCurrent(); break; } } if( !footprint.IsEmpty() && fpid.Parse( footprint ) >= 0 ) { wxString error; error.Printf( _( "invalid PFID in\nfile: <%s>\nline: %d\noffset: %d" ), GetChars( CurSource() ), CurLineNumber(), CurOffset() ); THROW_IO_ERROR( error ); } pathtimestamp += timestamp; COMPONENT* component = new COMPONENT( fpid, ref, value, pathtimestamp ); component->SetName( name ); component->SetLibrary( library ); m_netlist->AddComponent( component ); }
MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, FP_LIB_TABLE* aTable, bool aUseFootprintViewer, wxDC* aDC ) { MODULE* module = NULL; wxPoint curspos = GetCrossHairPosition(); wxString moduleName, keys; wxString libName = aLibrary; bool allowWildSeach = true; static wxArrayString HistoryList; static wxString lastComponentName; // Ask for a component name or key words DIALOG_GET_COMPONENT dlg( this, HistoryList, _( "Load Module" ), aUseFootprintViewer ); dlg.SetComponentName( lastComponentName ); if( dlg.ShowModal() == wxID_CANCEL ) return NULL; if( dlg.m_GetExtraFunction ) { // SelectFootprintFromLibBrowser() returns the "full" footprint name, i.e. // <lib_name>/<footprint name> or FPID format "lib_name:fp_name:rev#" moduleName = SelectFootprintFromLibBrowser(); } else { moduleName = dlg.GetComponentName(); } if( moduleName.IsEmpty() ) // Cancel command { m_canvas->MoveCursorToCrossHair(); return NULL; } if( dlg.IsKeyword() ) // Selection by keywords { allowWildSeach = false; keys = moduleName; moduleName = SelectFootprint( this, libName, wxEmptyString, keys, aTable ); if( moduleName.IsEmpty() ) // Cancel command { m_canvas->MoveCursorToCrossHair(); return NULL; } } else if( moduleName.Contains( wxT( "?" ) ) || moduleName.Contains( wxT( "*" ) ) ) // Selection wild card { allowWildSeach = false; moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable ); if( moduleName.IsEmpty() ) { m_canvas->MoveCursorToCrossHair(); return NULL; // Cancel command. } } FPID fpid; wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL, wxString::Format( wxT( "Could not parse FPID string '%s'." ), GetChars( moduleName ) ) ); try { module = loadFootprint( fpid ); } catch( const IO_ERROR& ioe ) { wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ), fpid.Format().c_str(), GetChars( ioe.errorText ) ); } if( !module && allowWildSeach ) // Search with wild card { allowWildSeach = false; wxString wildname = wxChar( '*' ) + moduleName + wxChar( '*' ); moduleName = wildname; moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable ); if( moduleName.IsEmpty() ) { m_canvas->MoveCursorToCrossHair(); return NULL; // Cancel command. } else { FPID fpid; wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL, wxString::Format( wxT( "Could not parse FPID string '%s'." ), GetChars( moduleName ) ) ); try { module = loadFootprint( fpid ); } catch( const IO_ERROR& ioe ) { wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ), fpid.Format().c_str(), GetChars( ioe.errorText ) ); } } } SetCrossHairPosition( curspos ); m_canvas->MoveCursorToCrossHair(); if( module ) { GetBoard()->Add( module, ADD_APPEND ); lastComponentName = moduleName; AddHistoryComponentName( HistoryList, moduleName ); module->SetFlags( IS_NEW ); module->SetLink( 0 ); module->SetPosition( curspos ); module->SetTimeStamp( GetNewTimeStamp() ); GetBoard()->m_Status_Pcb = 0; // Put it on FRONT layer, // (Can be stored flipped if the lib is an archive built from a board) if( module->IsFlipped() ) module->Flip( module->GetPosition() ); // Place it in orientation 0, // even if it is not saved with orientation 0 in lib // (Can happen if the lib is an archive built from a board) Rotate_Module( NULL, module, 0, false ); RecalculateAllTracksNetcode(); if( aDC ) module->Draw( m_canvas, aDC, GR_OR ); } return module; }
FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType ) : PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ), wxDefaultPosition, wxDefaultSize, aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT : KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintViewerFrameName() ) { wxASSERT( aFrameType==FRAME_PCB_MODULE_VIEWER || aFrameType==FRAME_PCB_MODULE_VIEWER_MODAL ); if( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ) SetModal( true ); wxAcceleratorTable table( DIM( accels ), accels ); m_FrameName = GetFootprintViewerFrameName(); m_configPath = wxT( "FootprintViewer" ); m_showAxis = true; // true to draw axis. // Give an icon wxIcon icon; icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) ); SetIcon( icon ); m_HotkeysZoomAndGridList = g_Module_Viewer_Hokeys_Descr; m_libList = new wxListBox( this, ID_MODVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL ); m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL ); SetBoard( new BOARD() ); // Ensure all layers and items are visible: GetBoard()->SetVisibleAlls(); SetScreen( new PCB_SCREEN( GetPageSizeIU() ) ); GetScreen()->m_Center = true; // Center coordinate origins on screen. LoadSettings( config() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); ReCreateHToolbar(); ReCreateVToolbar(); ReCreateLibraryList(); UpdateTitle(); // If a footprint was previously loaded, reload it if( getCurNickname().size() && getCurFootprintName().size() ) { FPID id; id.SetLibNickname( getCurNickname() ); id.SetFootprintName( getCurFootprintName() ); GetBoard()->Add( loadFootprint( id ) ); } if( m_canvas ) m_canvas->SetAcceleratorTable( table ); m_auimgr.SetManagedWindow( this ); wxSize minsize(100,-1); // Min size of list boxes // Main toolbar is initially docked at the top of the main window and dockable on any side. // The close button is disable because the footprint viewer has no main menu to re-enable it. // The tool bar will only be dockable on the top or bottom of the main frame window. This is // most likely due to the fact that the other windows are not dockable and are preventing the // tool bar from docking on the right and left. wxAuiPaneInfo toolbarPaneInfo; toolbarPaneInfo.Name( wxT( "m_mainToolBar" ) ).ToolbarPane().Top().CloseButton( false ); EDA_PANEINFO info; info.InfoToolbarPane(); EDA_PANEINFO mesg; mesg.MessageToolbarPane(); // Manage main toolbar, top pane m_auimgr.AddPane( m_mainToolBar, toolbarPaneInfo ); // Manage the list of libraries, left pane. m_auimgr.AddPane( m_libList, wxAuiPaneInfo( info ).Name( wxT( "m_libList" ) ) .Left().Row( 1 ).MinSize( minsize ) ); // Manage the list of footprints, center pane. m_auimgr.AddPane( m_footprintList, wxAuiPaneInfo( info ).Name( wxT( "m_footprintList" ) ) .Left().Row( 2 ).MinSize( minsize ) ); // Manage the draw panel, right pane. m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); // Manage the message panel, bottom pane. m_auimgr.AddPane( m_messagePanel, wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom() ); if( !m_perspective.IsEmpty() ) { // Restore last saved sizes, pos and other params // However m_mainToolBar size cannot be set to its last saved size // because the actual size change depending on the way modview was called: // the tool to export the current footprint exist or not. // and the saved size is not always OK // the trick is to get the default toolbar size, and set the size after // calling LoadPerspective wxSize tbsize = m_mainToolBar->GetSize(); m_auimgr.LoadPerspective( m_perspective, false ); m_auimgr.GetPane( m_mainToolBar ).BestSize( tbsize ); } #if 0 // no. // Set min size (overwrite params read in LoadPerspective(), if any) m_auimgr.GetPane( m_libList ).MinSize( minsize ); m_auimgr.GetPane( m_footprintList ).MinSize( minsize ); #endif // after changing something to the aui manager, // call Update()() to reflect the changes m_auimgr.Update(); // Now Drawpanel is sized, we can use BestZoom to show the component (if any) #ifdef USE_WX_GRAPHICS_CONTEXT GetScreen()->SetZoom( BestZoom() ); #else Zoom_Automatique( false ); #endif Show( true ); }
FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType ) : PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ), wxDefaultPosition, wxDefaultSize, aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ? aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | MODAL_MODE_EXTRASTYLE : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP : KICAD_DEFAULT_DRAWFRAME_STYLE, aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ? FOOTPRINT_VIEWER_FRAME_NAME_MODAL : FOOTPRINT_VIEWER_FRAME_NAME ) { wxASSERT( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL || aFrameType == FRAME_PCB_MODULE_VIEWER ); if( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ) SetModal( true ); // Force the frame name used in config. the footprint viewer frame has a name // depending on aFrameType (needed to identify the frame by wxWidgets), // but only one configuration is preferable. m_configFrameName = FOOTPRINT_VIEWER_FRAME_NAME; m_showAxis = true; // true to draw axis. // Give an icon wxIcon icon; icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) ); SetIcon( icon ); m_hotkeysDescrList = g_Module_Viewer_Hokeys_Descr; m_libList = new wxListBox( this, ID_MODVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL ); m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL ); SetBoard( new BOARD() ); // In viewer, the default net clearance is not known (it depends on the actual board). // So we do not show the default clearance, by setting it to 0 // The footprint or pad specific clearance will be shown GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0); // Ensure all layers and items are visible: GetBoard()->SetVisibleAlls(); SetScreen( new PCB_SCREEN( GetPageSizeIU() ) ); GetScreen()->m_Center = true; // Center coordinate origins on screen. LoadSettings( config() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); // Menu bar is not mandatory: uncomment/comment the next line // to add/remove the menubar ReCreateMenuBar(); ReCreateHToolbar(); ReCreateVToolbar(); ReCreateLibraryList(); UpdateTitle(); PCB_BASE_FRAME* parentFrame = static_cast<PCB_BASE_FRAME*>( Kiway().Player( FRAME_PCB, true ) ); // Create GAL canvas PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize, parentFrame->GetGalCanvas()->GetBackend() ); SetGalCanvas( drawPanel ); // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(), drawPanel->GetViewControls(), this ); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager ); drawPanel->SetEventDispatcher( m_toolDispatcher ); m_toolManager->RegisterTool( new PCBNEW_CONTROL ); m_toolManager->ResetTools( TOOL_BASE::RUN ); // If a footprint was previously loaded, reload it if( getCurNickname().size() && getCurFootprintName().size() ) { FPID id; id.SetLibNickname( getCurNickname() ); id.SetFootprintName( getCurFootprintName() ); GetBoard()->Add( loadFootprint( id ) ); } drawPanel->DisplayBoard( m_Pcb ); updateView(); m_auimgr.SetManagedWindow( this ); wxSize minsize(100,-1); // Min size of list boxes // Main toolbar is initially docked at the top of the main window and dockable on any side. // The close button is disable because the footprint viewer has no main menu to re-enable it. // The tool bar will only be dockable on the top or bottom of the main frame window. This is // most likely due to the fact that the other windows are not dockable and are preventing the // tool bar from docking on the right and left. wxAuiPaneInfo toolbarPaneInfo; toolbarPaneInfo.Name( wxT( "m_mainToolBar" ) ).ToolbarPane().Top().CloseButton( false ); EDA_PANEINFO info; info.InfoToolbarPane(); EDA_PANEINFO mesg; mesg.MessageToolbarPane(); // Manage main toolbar, top pane m_auimgr.AddPane( m_mainToolBar, toolbarPaneInfo ); // Manage the list of libraries, left pane. m_auimgr.AddPane( m_libList, wxAuiPaneInfo( info ).Name( wxT( "m_libList" ) ) .Left().Row( 1 ).MinSize( minsize ) ); // Manage the list of footprints, center pane. m_auimgr.AddPane( m_footprintList, wxAuiPaneInfo( info ).Name( wxT( "m_footprintList" ) ) .Left().Row( 2 ).MinSize( minsize ) ); // Manage the draw panel, right pane. m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); m_auimgr.AddPane( (wxWindow*) GetGalCanvas(), wxAuiPaneInfo().Name( wxT( "DrawFrameGal" ) ).CentrePane().Hide() ); // Manage the message panel, bottom pane. m_auimgr.AddPane( m_messagePanel, wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom() ); if( !m_perspective.IsEmpty() ) { // Restore last saved sizes, pos and other params // However m_mainToolBar size cannot be set to its last saved size // because the actual size change depending on the way modview was called: // the tool to export the current footprint exist or not. // and the saved size is not always OK // the trick is to get the default toolbar size, and set the size after // calling LoadPerspective wxSize tbsize = m_mainToolBar->GetSize(); m_auimgr.LoadPerspective( m_perspective, false ); m_auimgr.GetPane( m_mainToolBar ).BestSize( tbsize ); } // after changing something to the aui manager, // call Update()() to reflect the changes m_auimgr.Update(); // Now Drawpanel is sized, we can use BestZoom to show the component (if any) #ifdef USE_WX_GRAPHICS_CONTEXT GetScreen()->SetZoom( BestZoom() ); #else Zoom_Automatique( false ); #endif UseGalCanvas( parentFrame->IsGalCanvasActive() ); if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame { Raise(); // On some window managers, this is needed Show( true ); } }
COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText ) throw( PARSE_ERROR, boost::bad_pointer ) { char* text; wxString msg; wxString timeStamp; // the full time stamp read from netlist wxString footprintName; // the footprint name read from netlist wxString value; // the component value read from netlist wxString reference; // the component schematic reference designator read from netlist wxString name; // the name of component that was placed in the schematic char line[1024]; strcpy( line, aText ); value = wxT( "~" ); // Sample component line: /40C08647 $noname R20 4.7K {Lib=R} // Read time stamp (first word) if( ( text = strtok( line, " ()\t\n" ) ) == NULL ) { msg = _( "Cannot parse time stamp in component section of netlist." ); THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), line, m_lineReader->LineNumber(), m_lineReader->Length() ); } timeStamp = FROM_UTF8( text ); // Read footprint name (second word) if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL ) { msg = _( "Cannot parse footprint name in component section of netlist." ); THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(), m_lineReader->Length() ); } footprintName = FROM_UTF8( text ); // The footprint name will have to be looked up in the *.cmp file. if( footprintName == wxT( "$noname" ) ) footprintName = wxEmptyString; // Read schematic reference designator (third word) if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL ) { msg = _( "Cannot parse reference designator in component section of netlist." ); THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(), m_lineReader->Length() ); } reference = FROM_UTF8( text ); // Read schematic value (forth word) if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL ) { msg = _( "Cannot parse value in component section of netlist." ); THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(), m_lineReader->Length() ); } value = FROM_UTF8( text ); // Read component name (fifth word) {Lib=C} // This is an optional field (a comment), which does not always exists if( ( text = strtok( NULL, " ()\t\n" ) ) != NULL ) { name = FROM_UTF8( text ).AfterFirst( wxChar( '=' ) ).BeforeLast( wxChar( '}' ) ); } FPID fpid; if( !footprintName.IsEmpty() ) fpid.SetFootprintName( footprintName ); COMPONENT* component = new COMPONENT( fpid, reference, value, timeStamp ); component->SetName( name ); m_netlist->AddComponent( component ); return component; }
void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName ) { COMPONENT* component; bool hasFootprint = false; int componentIndex; if( m_netlist.IsEmpty() ) return; // If no component is selected, select the first one if( m_compListBox->GetFirstSelected() < 0 ) { componentIndex = 0; m_compListBox->SetSelection( componentIndex, true ); } // iterate over the selection while( m_compListBox->GetFirstSelected() != -1 ) { // Get the component for the current iteration componentIndex = m_compListBox->GetFirstSelected(); component = m_netlist.GetComponent( componentIndex ); if( component == NULL ) return; // Check to see if the component has already a footprint set. hasFootprint = !component->GetFPID().empty(); FPID fpid; if( !aFootprintName.IsEmpty() ) { wxCHECK_RET( fpid.Parse( aFootprintName ) < 0, wxString::Format( wxT( "<%s> is not a valid FPID." ), GetChars( aFootprintName ) ) ); } component->SetFPID( fpid ); // create the new component description wxString description = wxString::Format( CMP_FORMAT, componentIndex + 1, GetChars( component->GetReference() ), GetChars( component->GetValue() ), GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) ); // If the component hasn't had a footprint associated with it // it now has, so we decrement the count of components without // a footprint assigned. if( !hasFootprint ) { hasFootprint = true; m_undefinedComponentCnt -= 1; } // Set the new description and deselect the processed component m_compListBox->SetString( componentIndex, description ); m_compListBox->SetSelection( componentIndex, false ); } // Mark this "session" as modified m_modified = true; // select the next component, if there is one if( componentIndex < (m_compListBox->GetCount() - 1) ) componentIndex++; m_compListBox->SetSelection( componentIndex, true ); // update the statusbar DisplayStatus(); }
/** * Function convertFromLegacy * converts the footprint names in \a aNetList from the legacy format to the #FPID format. * * @param aNetList is the #NETLIST object to convert. * @param aLibNames is the list of legacy footprint library names from the currently loaded * project. * @param aReporter is the #REPORTER object to dump messages into. * @return true if all footprint names were successfully converted to a valid FPID. */ static bool convertFromLegacy( FP_LIB_TABLE* aTbl, SEARCH_STACK& aSStack, NETLIST& aNetList, const wxArrayString& aLibNames, REPORTER* aReporter = NULL ) throw( IO_ERROR ) { wxString msg; FPID lastFPID; COMPONENT* component; MODULE* module = 0; bool retv = true; if( aNetList.IsEmpty() ) return true; aNetList.SortByFPID(); wxString libPath; PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) ); for( unsigned ii = 0; ii < aNetList.GetCount(); ii++ ) { component = aNetList.GetComponent( ii ); // The footprint hasn't been assigned yet so ignore it. if( component->GetFPID().empty() ) continue; if( component->GetFPID() != lastFPID ) { module = NULL; for( unsigned ii = 0; ii < aLibNames.GetCount(); ii++ ) { wxFileName fn( wxEmptyString, aLibNames[ii], LegacyFootprintLibPathExtension ); libPath = aSStack.FindValidPath( fn.GetFullPath() ); if( !libPath ) { if( aReporter ) { msg.Printf( _( "Cannot find footprint library file '%s' in any of the " "KiCad legacy library search paths.\n" ), GetChars( fn.GetFullPath() ) ); aReporter->Report( msg ); } retv = false; continue; } module = pi->FootprintLoad( libPath, component->GetFPID().GetFootprintName() ); if( module ) { lastFPID = component->GetFPID(); break; } } } if( !module ) { if( aReporter ) { msg.Printf( _( "Component '%s' footprint '%s' was not found in any legacy " "library.\n" ), GetChars( component->GetReference() ), GetChars( component->GetFPID().Format() ) ); aReporter->Report( msg ); } // Clear the footprint assignment since the old library lookup method is no // longer valid. FPID emptyFPID; component->SetFPID( emptyFPID ); retv = false; continue; } else { wxString libNickname; const FP_LIB_TABLE::ROW* row; if( ( row = aTbl->FindRowByURI( libPath ) ) != NULL ) libNickname = row->GetNickName(); if( libNickname.IsEmpty() ) { if( aReporter ) { msg.Printf( _( "Component '%s' with footprint '%s' and legacy library path '%s' " "was not found in the footprint library table.\n" ), GetChars( component->GetReference() ), GetChars( component->GetFPID().Format() ), GetChars( libPath ) ); aReporter->Report( msg ); } retv = false; } else { FPID newFPID = lastFPID; newFPID.SetLibNickname( libNickname ); if( !newFPID.IsValid() ) { if( aReporter ) { msg.Printf( _( "Component '%s' FPID '%s' is not valid.\n" ), GetChars( component->GetReference() ), GetChars( newFPID.Format() ) ); aReporter->Report( msg ); } retv = false; } else { // The footprint name should already be set. component->SetFPID( newFPID ); } } } } return retv; }