void LIB_VIEW_FRAME::updatePreviewSymbol() { LIB_ALIAS* alias = getSelectedAlias(); KIGFX::SCH_VIEW* view = GetCanvas()->GetView(); if( m_previewItem ) { view->Remove( m_previewItem ); m_previewItem = nullptr; } ClearMsgPanel(); if( alias ) { GetRenderSettings()->m_ShowUnit = m_unit; GetRenderSettings()->m_ShowConvert = m_convert; view->Add( alias ); m_previewItem = alias; AppendMsgPanel( _( "Name" ), alias->GetName(), BLUE, 6 ); AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 6 ); AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY ); } GetCanvas()->ForceRefresh(); }
/** * Function RedrawActiveWindow * Display the current selected component. * If the component is an alias, the ROOT component is displayed */ void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) { LIB_COMPONENT* component; LIB_ALIAS* entry; CMP_LIBRARY* lib; wxString msg; wxString tmp; lib = CMP_LIBRARY::FindLibrary( m_libraryName ); if( lib == NULL ) return; entry = lib->FindEntry( m_entryName ); if( entry == NULL ) return; component = entry->GetComponent(); m_canvas->DrawBackGround( DC ); if( !entry->IsRoot() ) { if( component == NULL ) // Should not occur return; // Temporarily change the name field text to reflect the alias name. msg = entry->GetName(); tmp = component->GetName(); component->SetName( msg ); if( m_unit < 1 ) m_unit = 1; if( m_convert < 1 ) m_convert = 1; } else { msg = _( "None" ); } component->Draw( m_canvas, DC, wxPoint( 0, 0 ), m_unit, m_convert, GR_DEFAULT_DRAWMODE ); /* Redraw the cursor */ m_canvas->DrawCrossHair( DC ); if( !tmp.IsEmpty() ) component->SetName( tmp ); ClearMsgPanel(); AppendMsgPanel( _( "Part" ), component->GetName(), BLUE, 6 ); AppendMsgPanel( _( "Alias" ), msg, RED, 6 ); AppendMsgPanel( _( "Description" ), entry->GetDescription(), CYAN, 6 ); AppendMsgPanel( _( "Key words" ), entry->GetKeyWords(), DARKDARKGRAY ); }
void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) { LIB_ALIAS* entry = Prj().SchLibs()->FindLibraryAlias( m_entryName, m_libraryName ); if( !entry ) return; LIB_PART* part = entry->GetPart(); if( !part ) return; wxString msg; wxString tmp; m_canvas->DrawBackGround( DC ); if( !entry->IsRoot() ) { // Temporarily change the name field text to reflect the alias name. msg = entry->GetName(); tmp = part->GetName(); part->SetName( msg ); if( m_unit < 1 ) m_unit = 1; if( m_convert < 1 ) m_convert = 1; } else msg = _( "None" ); part->Draw( m_canvas, DC, wxPoint( 0, 0 ), m_unit, m_convert, GR_DEFAULT_DRAWMODE ); // Redraw the cursor m_canvas->DrawCrossHair( DC ); if( !tmp.IsEmpty() ) part->SetName( tmp ); ClearMsgPanel(); AppendMsgPanel( _( "Part" ), part->GetName(), BLUE, 6 ); AppendMsgPanel( _( "Alias" ), msg, RED, 6 ); AppendMsgPanel( _( "Description" ), entry->GetDescription(), CYAN, 6 ); AppendMsgPanel( _( "Key words" ), entry->GetKeyWords(), DARKDARKGRAY ); }
int PCB_EDIT_FRAME::Fill_Zone( ZONE_CONTAINER* aZone ) { aZone->ClearFilledPolysList(); aZone->UnFill(); // Cannot fill keepout zones: if( aZone->GetIsKeepout() ) return 1; wxString msg; ClearMsgPanel(); // Shows the net ZONE_SETTINGS zoneInfo = GetZoneSettings(); zoneInfo.m_NetcodeSelection = aZone->GetNetCode(); SetZoneSettings( zoneInfo ); msg = aZone->GetNetname(); if( msg.IsEmpty() ) msg = wxT( "No net" ); AppendMsgPanel( _( "NetName" ), msg, RED ); wxBusyCursor dummy; // Shows an hourglass cursor (removed by its destructor) aZone->BuildFilledSolidAreasPolygons( GetBoard() ); GetGalCanvas()->GetView()->Update( aZone, KIGFX::ALL ); GetBoard()->GetRatsnest()->Update( aZone ); OnModify(); return 0; }
/** * Function Compile_Ratsnest * Create the entire board ratsnest. * Must be called after a board change (changes for * pads, footprints or a read netlist ). * @param aDC = the current device context (can be NULL) * @param aDisplayStatus : if true, display the computation results */ void PCB_BASE_FRAME::Compile_Ratsnest( wxDC* aDC, bool aDisplayStatus ) { wxString msg; GetBoard()->m_Status_Pcb = 0; // we want a full ratsnest computation, from the scratch ClearMsgPanel(); // Rebuild the full pads and net info list RecalculateAllTracksNetcode(); if( aDisplayStatus ) { msg.Printf( wxT( " %d" ), m_Pcb->GetPadCount() ); AppendMsgPanel( wxT( "Pads" ), msg, RED ); msg.Printf( wxT( " %d" ), m_Pcb->GetNetCount() ); AppendMsgPanel( wxT( "Nets" ), msg, CYAN ); } /* Compute the full ratsnest * which can be see like all the possible links or logical connections. * some of them are active (no track connected) and others are inactive * (when tracks connect pads) * This full ratsnest is not modified by track editing. * It changes only when a netlist is read, or footprints are modified */ Build_Board_Ratsnest(); // Compute the pad connections due to the existing tracks (physical connections) TestConnections(); /* Compute the active ratsnest, i.e. the unconnected links */ TestForActiveLinksInRatsnest( 0 ); // Redraw the active ratsnest ( if enabled ) if( GetBoard()->IsElementVisible(RATSNEST_VISIBLE) && aDC ) DrawGeneralRatsnest( aDC, 0 ); if( aDisplayStatus ) SetMsgPanel( m_Pcb ); }
void LIB_EDIT_FRAME::DisplayCmpDoc() { LIB_ALIAS* alias; PART_LIB* lib = GetCurLib(); LIB_PART* part = GetCurPart(); ClearMsgPanel(); if( !lib || !part ) return; wxString msg = part->GetName(); AppendMsgPanel( _( "Name" ), msg, BLUE, 8 ); if( m_aliasName == part->GetName() ) msg = _( "None" ); else msg = m_aliasName; alias = part->GetAlias( m_aliasName ); wxCHECK_RET( alias != NULL, "Alias not found in component." ); AppendMsgPanel( _( "Alias" ), msg, RED, 8 ); static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); msg = UnitLetter[m_unit]; AppendMsgPanel( _( "Unit" ), msg, BROWN, 8 ); if( m_convert > 1 ) msg = _( "Convert" ); else msg = _( "Normal" ); AppendMsgPanel( _( "Body" ), msg, GREEN, 8 ); if( part->IsPower() ) msg = _( "Power Symbol" ); else msg = _( "Part" ); AppendMsgPanel( _( "Type" ), msg, MAGENTA, 8 ); AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 8 ); AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY ); AppendMsgPanel( _( "Datasheet" ), alias->GetDocFileName(), DARKDARKGRAY ); }
bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupFile ) { // please, keep it simple. prompting goes elsewhere. wxFileName pcbFileName = aFileName; if( pcbFileName.GetExt() == LegacyPcbFileExtension ) pcbFileName.SetExt( KiCadPcbFileExtension ); if( !IsWritable( pcbFileName ) ) { wxString msg = wxString::Format( _( "No access rights to write to file \"%s\"" ), GetChars( pcbFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } wxString backupFileName; if( aCreateBackupFile ) { backupFileName = createBackupFile( aFileName ); } GetBoard()->SynchronizeNetsAndNetClasses(); // Select default Netclass before writing file. // Useful to save default values in headers SetCurrentNetClass( NETCLASS::Default ); ClearMsgPanel(); wxString upperTxt; wxString lowerTxt; try { PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::KICAD_SEXP ) ); wxASSERT( pcbFileName.IsAbsolute() ); pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL ); } catch( const IO_ERROR& ioe ) { wxString msg = wxString::Format( _( "Error saving board file \"%s\".\n%s" ), GetChars( pcbFileName.GetFullPath() ), GetChars( ioe.What() ) ); DisplayError( this, msg ); lowerTxt.Printf( _( "Failed to create \"%s\"" ), GetChars( pcbFileName.GetFullPath() ) ); AppendMsgPanel( upperTxt, lowerTxt, CYAN ); return false; } GetBoard()->SetFileName( pcbFileName.GetFullPath() ); UpdateTitle(); // Put the saved file in File History, unless aCreateBackupFile // is false. // aCreateBackupFile == false is mainly used to write autosave files // and not need to have an autosave file in file history if( aCreateBackupFile ) UpdateFileHistory( GetBoard()->GetFileName() ); // Delete auto save file on successful save. wxFileName autoSaveFileName = pcbFileName; autoSaveFileName.SetName( GetAutoSaveFilePrefix() + pcbFileName.GetName() ); if( autoSaveFileName.FileExists() ) wxRemoveFile( autoSaveFileName.GetFullPath() ); if( !!backupFileName ) upperTxt.Printf( _( "Backup file: \"%s\"" ), GetChars( backupFileName ) ); lowerTxt.Printf( _( "Wrote board file: \"%s\"" ), GetChars( pcbFileName.GetFullPath() ) ); AppendMsgPanel( upperTxt, lowerTxt, CYAN ); GetScreen()->ClrModify(); GetScreen()->ClrSave(); return true; }
/* Route all traces * : * 1 if OK * -1 if escape (stop being routed) request * -2 if default memory allocation */ int PCB_EDIT_FRAME::Solve( wxDC* DC, int aLayersCount ) { int current_net_code; int row_source, col_source, row_target, col_target; int success, nbsucces = 0, nbunsucces = 0; NETINFO_ITEM* net; bool stop = false; wxString msg; int routedCount = 0; // routed ratsnest count bool two_sides = aLayersCount == 2; m_canvas->SetAbortRequest( false ); s_Clearance = GetBoard()->GetDesignSettings().GetDefault()->GetClearance(); // Prepare the undo command info s_ItemsListPicker.ClearListAndDeleteItems(); // Should not be necessary, but... // go until no more work to do GetWork( &row_source, &col_source, ¤t_net_code, &row_target, &col_target, &pt_cur_ch ); // First net to route. for( ; row_source != ILLEGAL; GetWork( &row_source, &col_source, ¤t_net_code, &row_target, &col_target, &pt_cur_ch ) ) { // Test to stop routing ( escape key pressed ) wxYield(); if( m_canvas->GetAbortRequest() ) { if( IsOK( this, _( "Abort routing?" ) ) ) { success = STOP_FROM_ESC; stop = true; break; } else { m_canvas->SetAbortRequest( false ); } } EraseMsgBox(); routedCount++; net = GetBoard()->FindNet( current_net_code ); if( net ) { msg.Printf( wxT( "[%8.8s]" ), GetChars( net->GetNetname() ) ); AppendMsgPanel( wxT( "Net route" ), msg, BROWN ); msg.Printf( wxT( "%d / %d" ), routedCount, RoutingMatrix.m_RouteCount ); AppendMsgPanel( wxT( "Activity" ), msg, BROWN ); } segm_oX = GetBoard()->GetBoundingBox().GetX() + (RoutingMatrix.m_GridRouting * col_source); segm_oY = GetBoard()->GetBoundingBox().GetY() + (RoutingMatrix.m_GridRouting * row_source); segm_fX = GetBoard()->GetBoundingBox().GetX() + (RoutingMatrix.m_GridRouting * col_target); segm_fY = GetBoard()->GetBoundingBox().GetY() + (RoutingMatrix.m_GridRouting * row_target); // Draw segment. GRLine( m_canvas->GetClipBox(), DC, segm_oX, segm_oY, segm_fX, segm_fY, 0, WHITE ); pt_cur_ch->m_PadStart->Draw( m_canvas, DC, GR_OR | GR_HIGHLIGHT ); pt_cur_ch->m_PadEnd->Draw( m_canvas, DC, GR_OR | GR_HIGHLIGHT ); success = Autoroute_One_Track( this, DC, two_sides, row_source, col_source, row_target, col_target, pt_cur_ch ); switch( success ) { case NOSUCCESS: pt_cur_ch->m_Status |= CH_UNROUTABLE; nbunsucces++; break; case STOP_FROM_ESC: stop = true; break; case ERR_MEMORY: stop = true; break; default: nbsucces++; break; } msg.Printf( wxT( "%d" ), nbsucces ); AppendMsgPanel( wxT( "OK" ), msg, GREEN ); msg.Printf( wxT( "%d" ), nbunsucces ); AppendMsgPanel( wxT( "Fail" ), msg, RED ); msg.Printf( wxT( " %d" ), GetBoard()->GetUnconnectedNetCount() ); AppendMsgPanel( wxT( "Not Connected" ), msg, CYAN ); // Delete routing from display. pt_cur_ch->m_PadStart->Draw( m_canvas, DC, GR_AND ); pt_cur_ch->m_PadEnd->Draw( m_canvas, DC, GR_AND ); if( stop ) break; } SaveCopyInUndoList( s_ItemsListPicker, UR_UNSPECIFIED ); s_ItemsListPicker.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items return SUCCESS; }
bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile ) { wxFileName fn; wxString msg; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); PART_LIB* lib = GetCurLib(); // Just in case the library hasn't been cached yet. lib->GetCount(); if( !lib ) { DisplayError( this, _( "No library specified." ) ); return false; } wxString oldFileName = lib->GetFullFileName(); if( GetScreen()->IsModify() ) { if( IsOK( this, _( "Include last component changes?" ) ) ) { lib->EnableBuffering(); try { SaveOnePart( lib, false ); } catch( ... ) { lib->EnableBuffering( false ); msg.Printf( _( "Unexpected error occured saving part to '%s' symbol library." ), lib->GetName() ); DisplayError( this, msg ); return false; } lib->EnableBuffering( false ); } } if( newFile ) { PROJECT& prj = Prj(); SEARCH_STACK* search = prj.SchSearchS(); // Get a new name for the library wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH ); if( !default_path ) default_path = search->LastVisitedPath(); wxFileDialog dlg( this, _( "Part Library Name:" ), default_path, wxEmptyString, SchematicLibraryFileWildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if( dlg.ShowModal() == wxID_CANCEL ) return false; fn = dlg.GetPath(); // The GTK file chooser doesn't return the file extension added to // file name so add it here. if( fn.GetExt().IsEmpty() ) fn.SetExt( SchematicLibraryFileExtension ); prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() ); } else { fn = wxFileName( lib->GetFullFileName() ); msg.Printf( _( "Modify library file '%s' ?" ), GetChars( fn.GetFullPath() ) ); if( !IsOK( this, msg ) ) return false; } // Verify the user has write privileges before attempting to save the library file. if( !IsWritable( fn ) ) return false; ClearMsgPanel(); wxFileName libFileName = fn; wxFileName backupFileName = fn; // Rename the old .lib file to .bak. if( libFileName.FileExists() ) { backupFileName.SetExt( "bak" ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( libFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { libFileName.MakeAbsolute(); msg = _( "Failed to rename old component library file " ) + backupFileName.GetFullPath(); DisplayError( this, msg ); } } wxFileName docFileName = libFileName; docFileName.SetExt( DOC_EXT ); // Rename .doc file to .bck. if( docFileName.FileExists() ) { backupFileName.SetExt( "bck" ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( docFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { msg = _( "Failed to save old library document file " ) + backupFileName.GetFullPath(); DisplayError( this, msg ); } } try { lib->SetFileName( fn.GetFullPath() ); lib->Save(); } catch( ... /* IO_ERROR ioe */ ) { lib->SetFileName( oldFileName ); msg.Printf( _( "Failed to create symbol library file '%s'" ), GetChars( docFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } lib->SetFileName( oldFileName ); msg.Printf( _( "Library file '%s' saved" ), GetChars( fn.GetFullPath() ) ); fn.SetExt( DOC_EXT ); wxString msg1; msg1.Printf( _( "Documentation file '%s' saved" ), GetChars( fn.GetFullPath() ) ); AppendMsgPanel( msg, msg1, BLUE ); UpdateAliasSelectList(); UpdatePartSelectList(); refreshSchematic(); return true; }