bool PANEL_FP_LIB_TABLE::TransferDataFromWindow() { if( !m_cur_grid->CommitPendingChanges() ) return false; if( verifyTables() ) { if( *global_model() != *m_global ) { m_parent->m_GlobalTableChanged = true; m_global->Clear(); m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(), global_model()->rows.end(), global_model()->rows ); m_global->reindex(); } if( *project_model() != *m_project ) { m_parent->m_ProjectTableChanged = true; m_project->Clear(); m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(), project_model()->rows.end(), project_model()->rows ); m_project->reindex(); } return true; } return false; }
/* * Same thing for a universal model: * - value[i] = model = array of constant value such that value[i] is the value of ef->all_uvar[i] * - uvar = subset of the universal variables (of size n) * - uval = restriction of value to uvar (as above) */ static void ef_project_forall_model(ef_prob_t *prob, term_t *value, term_t *uvar, term_t *uval, uint32_t n) { project_model(prob->all_uvars, value, uvar, uval, n); }
/* * Project model onto a subset of the existential variables * - value[i] = exist model = array of constant values * - evar = an array of n existential variables: every element of evar occurs in ef->all_evars * - then this function builds the model restricted to evar into array eval * * Assumption: * - value[i] = value mapped to ef->all_evars[i] for i=0 ... num_evars-1 * - every x in sub_var occurs somewhere in ef->all_evars * - then if evar[i] = x and x is equal to all_evar[k] the function copies * value[k] into eval[i] */ static void ef_project_exists_model(ef_prob_t *prob, term_t *value, term_t *evar, term_t *eval, uint32_t n) { project_model(prob->all_evars, value, evar, eval, n); }
/// Populate the readonly environment variable table with names and values /// by examining all the full_uri columns. void PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable() { wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED ); wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required. std::set< wxString > unique; // clear the table m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() ); for( FP_LIB_TABLE_GRID* tbl : { global_model(), project_model() } ) { for( int row = 0; row < tbl->GetNumberRows(); ++row ) { wxString uri = tbl->GetValue( row, COL_URI ); while( re.Matches( uri ) ) { wxString envvar = re.GetMatch( uri, 2 ); // if not ${...} form then must be $(...) if( envvar.IsEmpty() ) envvar = re.GetMatch( uri, 4 ); // ignore duplicates unique.insert( envvar ); // delete the last match and search again uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); } } } // Make sure this special environment variable shows up even if it was // not used yet. It is automatically set by KiCad to the directory holding // the current project. unique.insert( PROJECT_VAR_NAME ); unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() ); // This special environment variable is used to locate 3d shapes unique.insert( KISYS3DMOD ); for( wxString evName : unique ) { int row = m_path_subs_grid->GetNumberRows(); m_path_subs_grid->AppendRows( 1 ); m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) ); m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() ); wxString evValue; wxGetEnv( evName, &evValue ); m_path_subs_grid->SetCellValue( row, 1, evValue ); m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() ); } // No combobox editors here, but it looks better if its consistent with the other // grids in the dialog. m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 ); adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() ); }
bool PANEL_FP_LIB_TABLE::verifyTables() { for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } ) { for( int r = 0; r < model->GetNumberRows(); ) { wxString nick = model->GetValue( r, COL_NICKNAME ).Trim( false ).Trim(); wxString uri = model->GetValue( r, COL_URI ).Trim( false ).Trim(); unsigned illegalCh = 0; if( !nick || !uri ) { // Delete the "empty" row, where empty means missing nick or uri. // This also updates the UI which could be slow, but there should only be a few // rows to delete, unless the user fell asleep on the Add Row // button. model->DeleteRows( r, 1 ); } else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_PCB ) ) ) { wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ), illegalCh, nick ); // show the tabbed panel holding the grid we have flunked: if( model != cur_model() ) m_auinotebook->SetSelection( model == global_model() ? 0 : 1 ); m_cur_grid->MakeCellVisible( r, 0 ); m_cur_grid->SetGridCursor( r, 1 ); wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) ); errdlg.ShowModal(); return false; } else { // set the trimmed values back into the table so they get saved to disk. model->SetValue( r, COL_NICKNAME, nick ); model->SetValue( r, COL_URI, uri ); ++r; // this row was OK. } } } // check for duplicate nickNames, separately in each table. for( FP_LIB_TABLE_GRID* model : { global_model(), project_model() } ) { for( int r1 = 0; r1 < model->GetNumberRows() - 1; ++r1 ) { wxString nick1 = model->GetValue( r1, COL_NICKNAME ); for( int r2 = r1 + 1; r2 < model->GetNumberRows(); ++r2 ) { wxString nick2 = model->GetValue( r2, COL_NICKNAME ); if( nick1 == nick2 ) { wxString msg = wxString::Format( _( "Duplicate Nicknames \"%s\"." ), nick1 ); // show the tabbed panel holding the grid we have flunked: if( model != cur_model() ) m_auinotebook->SetSelection( model == global_model() ? 0 : 1 ); // go to the lower of the two rows, it is technically the duplicate: m_cur_grid->MakeCellVisible( r2, 0 ); m_cur_grid->SetGridCursor( r2, 1 ); wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) ); errdlg.ShowModal(); return false; } } } } return true; }