/* * Convert predicted values from cartesian to Jacobi coordinates. */ void get_jacobi(struct particle parts[], int pcount) { _enter_function(_UL_KEPLER, _UL_KEPLER_GET_JACOBI); int i, j; double x_[3], v_[3]; for(j = pcount - 1; j > 0; j--) { if(parts[j].is_jacobi) continue; get_common(parts, j, x_, 'x'); get_common(parts, j, v_, 'v'); for(i = 0; i < DIMENSIONS; i++) { parts[j].xp[i] -= x_[i]; parts[j].vp[i] -= v_[i]; } parts[j].is_jacobi = 1; } for(i = 0; i < DIMENSIONS; i++) { parts[0].xp[i] = .0; parts[0].vp[i] = .0; } parts[0].is_jacobi = 1; _exit_function(); }
/* in the Shypothesis struc. Thus, it must be passed explicitly */ void write_row_val (DCELL *row, long easting, Shypothesis *frame, long hyp, int val , double woc) { switch ( val ) { case BEL: row[easting] = get_bel (frame,hyp); break; case PL: row[easting] = get_pl (frame,hyp); break; case DOUBT: row[easting] = get_doubt (frame,hyp); break; case COMMON: row[easting] = get_common (frame,hyp); break; case BINT: row[easting] = get_bint (frame,hyp); break; case WOC: /* need to process a bit differently */ row[easting] = woc; break; case MAXBPA: row[easting] = get_maxbpn (frame,hyp); break; case MINBPA: row[easting] = get_minbpn (frame,hyp); break; } }
int FeOverlay::filters_dialog() { sf::Vector2i size; sf::Vector2f text_scale; int char_size; get_common( size, text_scale, char_size ); std::vector<std::string> list; m_feSettings.get_current_list_filter_names( list ); if ( list.size() > 8 ) char_size /= 2; std::vector<sf::Drawable *> draw_list; sf::RectangleShape bg( sf::Vector2f( size.x, size.y ) ); bg.setFillColor( m_bgColour ); bg.setOutlineColor( m_textColour ); bg.setOutlineThickness( -2 ); draw_list.push_back( &bg ); FeTextPrimative heading( m_fePresent.get_font(), m_selColour, sf::Color::Transparent, char_size ); heading.setSize( size.x, size.y / 8 ); heading.setOutlineColor( m_textColour ); heading.setOutlineThickness( -2 ); heading.setTextScale( text_scale ); std::string temp; m_feSettings.get_resource( "Filters", temp ); heading.setString( temp ); draw_list.push_back( &heading ); FeListBox dialog( m_fePresent.get_font(), m_textColour, sf::Color::Transparent, m_selColour, m_selBgColour, char_size, size.y / ( char_size * 1.5 * text_scale.y ) ); dialog.setPosition( 2, size.y / 8 ); dialog.setSize( size.x - 4, size.y * 7 / 8 ); dialog.init(); dialog.setTextScale( text_scale ); draw_list.push_back( &dialog ); int current_i = m_feSettings.get_current_filter_index(); int sel = current_i; dialog.setText( sel, list ); FeEventLoopCtx c( draw_list, sel, current_i, list.size() - 1 ); while ( event_loop( c ) == false ) dialog.setText( sel, list ); return sel; }
int FeOverlay::internal_dialog( const std::string &msg_str, const std::vector<std::string> &list ) { sf::Vector2i size; sf::Vector2f text_scale; int char_size; get_common( size, text_scale, char_size ); float slice = size.y / 2; sf::RectangleShape bg( sf::Vector2f( size.x, size.y ) ); bg.setFillColor( m_bgColour ); bg.setOutlineColor( m_textColour ); bg.setOutlineThickness( -2 ); FeTextPrimative message( m_fePresent.get_font(), m_textColour, sf::Color::Transparent, char_size ); message.setWordWrap( true ); message.setTextScale( text_scale ); FeListBox dialog( m_fePresent.get_font(), m_textColour, sf::Color::Transparent, m_selColour, m_selBgColour, char_size, ( size.y - slice ) / ( char_size * 1.5 * text_scale.y ) ); message.setPosition( 2, 2 ); message.setSize( size.x - 4, slice ); message.setString( msg_str ); dialog.setPosition( 2, slice ); dialog.setSize( size.x - 4, size.y - 4 - slice ); dialog.init(); dialog.setTextScale( text_scale ); std::vector<sf::Drawable *> draw_list; draw_list.push_back( &bg ); draw_list.push_back( &message ); draw_list.push_back( &dialog ); int sel=1; dialog.setText( sel, list ); FeEventLoopCtx c( draw_list, sel, 1, list.size() - 1 ); while ( event_loop( c ) == false ) dialog.setText( sel, list ); return sel; }
static PyObject *ncOpGet(ncSessionObject *self, PyObject *args, PyObject *keywords) { const char *filter = NULL; int wdmode = NCWD_MODE_NOTSET; char *kwlist[] = {"filter", "wd", NULL}; SESSION_CHECK(self); /* Get input parameters */ if (! PyArg_ParseTupleAndKeywords(args, keywords, "|zi", kwlist, &filter, &wdmode)) { return (NULL); } return (get_common(self, filter, wdmode, NC_DATASTORE_ERROR)); }
void FeOverlay::edit_dialog( const std::string &msg_str, std::string &text ) { sf::Vector2i size; sf::Vector2f text_scale; int char_size; get_common( size, text_scale, char_size ); FeTextPrimative message( m_fePresent.get_font(), m_textColour, m_bgColour, char_size ); message.setWordWrap( true ); FeTextPrimative tp( m_fePresent.get_font(), m_textColour, m_bgColour, char_size ); float slice = size.y / 3; message.setSize( size.x, slice ); message.setTextScale( text_scale ); message.setString( msg_str ); tp.setPosition( 0, slice ); tp.setSize( size.x, size.y - slice ); tp.setTextScale( text_scale ); std::vector<sf::Drawable *> draw_list; draw_list.push_back( &message ); draw_list.push_back( &tp ); std::basic_string<sf::Uint32> str; sf::Utf8::toUtf32( text.begin(), text.end(), std::back_inserter( str ) ); if ( edit_loop( draw_list, str, &tp ) == true ) { text.clear(); sf::Utf32::toUtf8( str.begin(), str.end(), std::back_inserter( text ) ); } }
void FeOverlay::splash_message( const std::string &msg, const std::string &rep ) { sf::Vector2i size; sf::Vector2f text_scale; int char_size; get_common( size, text_scale, char_size ); sf::RectangleShape bg( sf::Vector2f( size.x, size.y ) ); bg.setFillColor( m_bgColour ); bg.setOutlineColor( m_textColour ); bg.setOutlineThickness( -2 ); FeTextPrimative message( m_fePresent.get_font(), m_textColour, sf::Color::Transparent, char_size ); message.setWordWrap( true ); message.setPosition( 2, 2 ); message.setSize( size.x - 4, size.y - 4 ); message.setTextScale( text_scale ); std::string msg_str; m_feSettings.get_resource( msg, rep, msg_str ); message.setString( msg_str ); const sf::Transform &t = m_fePresent.get_transform(); m_fePresent.tick( NULL ); m_wnd.clear(); m_wnd.draw( m_fePresent, t ); m_wnd.draw( bg, t ); m_wnd.draw( message, t ); m_wnd.display(); }
static PyObject *ncOpGetConfig(ncSessionObject *self, PyObject *args, PyObject *keywords) { const char *filter = NULL; int wdmode = NCWD_MODE_NOTSET; int source = NC_DATASTORE_ERROR; char *kwlist[] = {"source", "filter", "wd", NULL}; SESSION_CHECK(self); /* Get input parameters */ if (! PyArg_ParseTupleAndKeywords(args, keywords, "i|zi", kwlist, &source, &filter, &wdmode)) { return (NULL); } if (source != NC_DATASTORE_RUNNING && source != NC_DATASTORE_STARTUP && source != NC_DATASTORE_CANDIDATE) { PyErr_SetString(PyExc_ValueError, "Invalid \'source\' value."); return (NULL); } return (get_common(self, filter, wdmode, source)); }
int main(int argc, char *argv[]) { char a[] = "abedfck"; char b[] = "bcfkc"; printf("%s\n", get_common(a, b)); return 0; }
wplist storage::get_all() const { wplist ret = get_mine(); wplist common = get_common(); concat(common, ret); return ret; }
int FeOverlay::display_config_dialog( FeBaseConfigMenu *m, bool &parent_setting_changed ) { FeConfigContextImp ctx( m_feSettings, *this ); ctx.update_to_menu( m ); // // Set up display objects // sf::Vector2i size; sf::Vector2f text_scale; int char_size; get_common( size, text_scale, char_size ); const sf::Font *font = m_fePresent.get_font(); std::vector<sf::Drawable *> draw_list; float slice = size.y / 8; sf::RectangleShape bg( sf::Vector2f( size.x, size.y ) ); bg.setFillColor( m_bgColour ); bg.setOutlineColor( m_textColour ); bg.setOutlineThickness( -2 ); draw_list.push_back( &bg ); FeTextPrimative heading( font, m_selColour, sf::Color::Transparent, char_size / 2 ); heading.setSize( size.x, slice ); heading.setOutlineColor( m_textColour ); heading.setOutlineThickness( -2 ); heading.setTextScale( text_scale ); heading.setString( ctx.title ); draw_list.push_back( &heading ); unsigned int width = size.x - 4; if ( ctx.style == FeConfigContext::EditList ) width = size.x / 2 - 2; int rows = ( size.y - slice * 2 ) / ( char_size * 0.75 * text_scale.y ); // // The "settings" (left) list, also used to list submenu and exit options... // FeListBox sdialog( font, m_textColour, sf::Color::Transparent, m_selColour, sf::Color( 0, 0, 200, 200 ), char_size / 2, rows ); sdialog.setPosition( 2, slice ); sdialog.setSize( width, size.y - slice * 2 ); sdialog.init(); sdialog.setTextScale( text_scale ); draw_list.push_back( &sdialog ); // // The "values" (right) list shows the values corresponding to a setting. // FeListBox vdialog( font, m_textColour, sf::Color::Transparent, m_textColour, sf::Color( 0, 0, 200, 200 ), char_size / 2, rows ); if ( ctx.style == FeConfigContext::EditList ) { // // We only use the values listbox in the "EditList" mode // vdialog.setPosition( width + 2, slice ); vdialog.setSize( width, size.y - slice * 2 ); vdialog.init(); vdialog.setTextScale( text_scale ); draw_list.push_back( &vdialog ); } FeTextPrimative footer( font, m_textColour, sf::Color::Transparent, char_size / 3 ); footer.setPosition( 0, size.y - slice ); footer.setSize( size.x, slice ); footer.setOutlineColor( m_textColour ); footer.setOutlineThickness( -2 ); footer.setWordWrap( true ); footer.setTextScale( text_scale ); draw_list.push_back( &footer ); ctx.curr_sel = sdialog.getRowCount() / 2; if ( ctx.curr_sel >= (int)ctx.left_list.size() ) ctx.curr_sel = ctx.left_list.size() - 1; sdialog.setText( ctx.curr_sel, ctx.left_list ); vdialog.setText( ctx.curr_sel, ctx.right_list ); if ( !ctx.help_msg.empty() ) { footer.setString( ctx.help_msg ); ctx.help_msg = ""; } else { footer.setString( ctx.curr_opt().help_msg ); } // // Event loop processing // while ( true ) { FeEventLoopCtx c( draw_list, ctx.curr_sel, ctx.exit_sel, ctx.left_list.size() - 1 ); while ( event_loop( c ) == false ) { footer.setString( ctx.curr_opt().help_msg ); sdialog.setText( ctx.curr_sel, ctx.left_list ); vdialog.setText( ctx.curr_sel, ctx.right_list ); } // // User selected something, process it // if ( ctx.curr_sel < 0 ) // exit { if ( ctx.save_req ) { if ( m->save( ctx ) ) parent_setting_changed = true; } return ctx.curr_sel; } FeBaseConfigMenu *sm( NULL ); if ( m->on_option_select( ctx, sm ) == false ) continue; if ( !ctx.help_msg.empty() ) { footer.setString( ctx.help_msg ); ctx.help_msg = ""; } int t = ctx.curr_opt().type; if ( t > Opt::INFO ) { if ( ctx.save_req ) { if ( m->save( ctx ) ) parent_setting_changed = true; ctx.save_req=false; } switch (t) { case Opt::RELOAD: return display_config_dialog( m, parent_setting_changed ); case Opt::MENU: if ( sm ) return display_config_dialog( sm, parent_setting_changed ); break; case Opt::SUBMENU: if ( sm ) { bool test( false ); int sm_ret = display_config_dialog( sm, test ); if ( sm_ret < 0 ) return sm_ret; if ( test ) ctx.save_req = true; // // The submenu may have changed stuff in this menu, need // to update our variables as a result // ctx.update_to_menu( m ); sdialog.setText( ctx.curr_sel, ctx.left_list ); vdialog.setText( ctx.curr_sel, ctx.right_list ); } break; case Opt::EXIT: case Opt::DEFAULTEXIT: default: return ctx.curr_sel; } } else if ( t != Opt::INFO ) // Opt::EDIT and Opt::LIST { // // User has selected to edit a specific entry. // Update the UI and enter the appropriate // event loop // sdialog.setSelColor( m_textColour ); FeTextPrimative *tp = vdialog.setEditMode( true, m_selColour ); if ( tp == NULL ) continue; if ( t == Opt::LIST ) { int original_value = ctx.curr_opt().get_vindex(); int new_value = original_value; FeEventLoopCtx c( draw_list, new_value, -1, ctx.curr_opt().values_list.size() - 1 ); while ( event_loop( c ) == false ) { tp->setString(ctx.curr_opt().values_list[new_value]); } if (( new_value >= 0 ) && ( new_value != original_value )) { ctx.save_req = true; ctx.curr_opt().set_value( new_value ); ctx.right_list[ctx.curr_sel] = ctx.curr_opt().get_value(); } } else { const std::string &e_str( ctx.curr_opt().get_value() ); std::basic_string<sf::Uint32> str; sf::Utf8::toUtf32( e_str.begin(), e_str.end(), std::back_inserter( str ) ); if ( edit_loop( draw_list, str, tp ) == true ) { ctx.save_req = true; std::string d_str; sf::Utf32::toUtf8( str.begin(), str.end(), std::back_inserter( d_str ) ); ctx.curr_opt().set_value( d_str ); ctx.right_list[ctx.curr_sel] = d_str; } } tp->setString( ctx.right_list[ctx.curr_sel] ); sdialog.setSelColor( m_selColour ); vdialog.setEditMode( false, m_textColour ); } } return ctx.curr_sel; }
void FeOverlay::input_map_dialog( const std::string &msg_str, std::string &map_str, FeInputMap::Command &conflict ) { sf::Vector2i s; sf::Vector2f text_scale; int char_size; get_common( s, text_scale, char_size ); FeTextPrimative message( m_fePresent.get_font(), m_textColour, m_bgColour, char_size ); message.setWordWrap( true ); message.setTextScale( text_scale ); // Make sure the appropriate mouse capture variables are set, in case // the user has just changed the mouse threshold // m_feSettings.init_mouse_capture( s.x, s.y ); message.setSize( s.x, s.y ); message.setString( msg_str ); // Centre the mouse in case the user is mapping a mouse move event s.x /= 2; s.y /= 2; sf::Mouse::setPosition( sf::Vector2i( s ), m_wnd ); // empty the window event queue sf::Event ev; while ( m_wnd.pollEvent(ev) ) { // no op } bool redraw=true; const sf::Transform &t = m_fePresent.get_transform(); while ( m_wnd.isOpen() ) { while (m_wnd.pollEvent(ev)) { if ( ev.type == sf::Event::Closed ) return; if ( m_feSettings.config_map_input( ev, map_str, conflict ) ) return; } if ( m_fePresent.tick( NULL ) ) redraw = true; if ( redraw ) { m_wnd.clear(); m_wnd.draw( m_fePresent, t ); m_wnd.draw( message, t ); m_wnd.display(); redraw = false; } else sf::sleep( sf::milliseconds( 30 ) ); } }
int FeOverlay::tags_dialog() { std::vector< std::pair<std::string, bool> > tags_list; m_feSettings.get_current_tags_list( tags_list ); sf::Vector2i size; sf::Vector2f text_scale; int char_size; get_common( size, text_scale, char_size ); if ( tags_list.size() > 8 ) char_size /= 2; std::vector<std::string> list; for ( std::vector< std::pair<std::string, bool> >::iterator itr=tags_list.begin(); itr!=tags_list.end(); ++itr ) { std::string msg; m_feSettings.get_resource( (*itr).second ? "Remove tag: '$1'" : "Add tag: '$1'", (*itr).first, msg ); list.push_back( msg ); } list.push_back( std::string() ); m_feSettings.get_resource( "Create new tag", list.back() ); std::vector<sf::Drawable *> draw_list; sf::RectangleShape bg( sf::Vector2f( size.x, size.y ) ); bg.setFillColor( m_bgColour ); bg.setOutlineColor( m_textColour ); bg.setOutlineThickness( -2 ); draw_list.push_back( &bg ); FeTextPrimative heading( m_fePresent.get_font(), m_selColour, sf::Color::Transparent, char_size ); heading.setSize( size.x, size.y / 8 ); heading.setOutlineColor( m_textColour ); heading.setOutlineThickness( -2 ); heading.setTextScale( text_scale ); std::string temp; m_feSettings.get_resource( "Tags", temp ); heading.setString( temp ); draw_list.push_back( &heading ); FeListBox dialog( m_fePresent.get_font(), m_textColour, sf::Color::Transparent, m_selColour, m_selBgColour, char_size, size.y / ( char_size * 1.5 * text_scale.y ) ); dialog.setPosition( 2, size.y / 8 ); dialog.setSize( size.x - 4, size.y * 7 / 8 ); dialog.init(); dialog.setTextScale( text_scale ); draw_list.push_back( &dialog ); int current_i = list.size(); int sel = current_i - 1; dialog.setText( sel, list ); FeEventLoopCtx c( draw_list, sel, current_i, list.size() - 1 ); while ( event_loop( c ) == false ) dialog.setText( sel, list ); if ( sel == (int)tags_list.size() ) { std::string name; edit_dialog( "Enter new tag name", name ); if ( !name.empty() ) { if ( m_feSettings.set_current_tag( name, true ) ) m_fePresent.update_to_new_list( &m_wnd ); // changing tag status altered our current list } } else if (( sel >=0 ) && ( sel < (int)tags_list.size() )) { if ( m_feSettings.set_current_tag( tags_list[sel].first, !(tags_list[sel].second) ) ) m_fePresent.update_to_new_list( &m_wnd ); // changing tag status altered our current list } return sel; }
int FeOverlay::languages_dialog() { std::vector<std::string> ll; m_feSettings.get_languages_list( ll ); if ( ll.size() <= 1 ) { // if there is nothing to select, then set what we can and get out of here // m_feSettings.set_language( ll.empty() ? "en" : ll.front() ); return 0; } // Try and get a useful default setting based on POSIX locale value... // // TODO: figure out how to do this right on Windows... // std::string loc, test( "en" ); try { loc = std::locale("").name(); } catch (...) {} if ( loc.size() > 1 ) test = loc; int status( -2 ), current_i( 0 ), i( 0 ); std::vector<std::string> pl; for ( std::vector<std::string>::iterator itr=ll.begin(); itr != ll.end(); ++itr ) { if (( status < 0 ) && ( test.compare( 0, 5, (*itr) ) == 0 )) { current_i = i; status = 0; } else if (( status < -1 ) && ( test.compare( 0, 2, (*itr)) == 0 )) { current_i = i; status = -1; } pl.push_back( std::string() ); m_feSettings.get_resource( (*itr), pl.back() ); i++; } sf::Vector2i size; sf::Vector2f text_scale; int char_size; get_common( size, text_scale, char_size ); FeListBox dialog( m_fePresent.get_font(), m_textColour, m_bgColour, m_selColour, m_selBgColour, char_size, size.y / ( char_size * 1.5 * text_scale.y ) ); dialog.setPosition( 0, 0 ); dialog.setSize( size.x, size.y ); dialog.init(); dialog.setTextScale( text_scale ); std::vector<sf::Drawable *> draw_list( 1, &dialog ); int sel = current_i; dialog.setText( sel, pl ); FeEventLoopCtx c( draw_list, sel, current_i, pl.size() - 1 ); while ( event_loop( c ) == false ) dialog.setText( sel, pl ); if ( sel >= 0 ) m_feSettings.set_language( ll[sel] ); return sel; }
int FeOverlay::lists_dialog() { sf::Vector2i size; sf::Vector2f text_scale; int char_size; get_common( size, text_scale, char_size ); std::vector<std::string> list; m_feSettings.get_list_names( list ); if ( list.size() > 8 ) char_size /= 2; std::vector<sf::Drawable *> draw_list; sf::RectangleShape bg( sf::Vector2f( size.x, size.y ) ); bg.setFillColor( m_bgColour ); bg.setOutlineColor( m_textColour ); bg.setOutlineThickness( -2 ); draw_list.push_back( &bg ); FeTextPrimative heading( m_fePresent.get_font(), m_selColour, sf::Color::Transparent, char_size ); heading.setSize( size.x, size.y / 8 ); heading.setOutlineColor( m_textColour ); heading.setOutlineThickness( -2 ); heading.setTextScale( text_scale ); std::string temp; m_feSettings.get_resource( "Lists", temp ); heading.setString( temp ); draw_list.push_back( &heading ); FeListBox dialog( m_fePresent.get_font(), m_textColour, sf::Color::Transparent, m_selColour, m_selBgColour, char_size, size.y / ( char_size * 1.5 * text_scale.y ) ); dialog.setPosition( 2, size.y / 8 ); dialog.setSize( size.x - 4, size.y * 7 / 8 ); dialog.init(); dialog.setTextScale( text_scale ); draw_list.push_back( &dialog ); int last_list = list.size() - 1; if ( m_feSettings.get_lists_menu_exit() ) { // // Add an exit option at the end of the lists menu // std::string exit_str; m_feSettings.get_resource( "Exit Attract-Mode", exit_str ); list.push_back( exit_str ); } int current_i = m_feSettings.get_current_list_index(); int sel = current_i; dialog.setText( sel, list ); FeEventLoopCtx c( draw_list, sel, current_i, list.size() - 1 ); while ( event_loop( c ) == false ) dialog.setText( sel, list ); // test if the exit option selected, return -2 if it has been if ( sel > last_list ) sel = -2; return sel; }