static void
ide_preferences_spin_button_setting_changed (IdePreferencesSpinButton *self,
                                             const gchar              *key,
                                             GSettings                *settings)
{
  GtkAdjustment *adj;
  GVariant *value;

  g_assert (IDE_IS_PREFERENCES_SPIN_BUTTON (self));
  g_assert (key != NULL);
  g_assert (G_IS_SETTINGS (settings));

  if (self->updating)
    return;

  self->updating = TRUE;

  adj = gtk_spin_button_get_adjustment (self->spin_button);

  value = g_settings_get_value (settings, key);
  apply_value (adj, value, "value");
  g_variant_unref (value);

  self->updating = FALSE;
}
static void
ide_preferences_spin_button_connect (IdePreferencesBin *bin,
                                     GSettings         *settings)
{
  IdePreferencesSpinButton *self = (IdePreferencesSpinButton *)bin;
  GSettingsSchema *schema = NULL;
  GSettingsSchemaKey *key = NULL;
  GVariant *range = NULL;
  GVariant *values = NULL;
  GVariant *lower = NULL;
  GVariant *upper = NULL;
  gchar *type = NULL;
  gchar *signal_detail = NULL;
  GtkAdjustment *adj;
  GVariantIter iter;

  g_assert (IDE_IS_PREFERENCES_SPIN_BUTTON (self));

  self->settings = g_object_ref (settings);

  g_object_get (self->settings, "settings-schema", &schema, NULL);

  adj = gtk_spin_button_get_adjustment (self->spin_button);
  key = g_settings_schema_get_key (schema, self->key);
  range = g_settings_schema_key_get_range (key);

  g_variant_get (range, "(sv)", &type, &values);

  if (!ide_str_equal0 (type, "range") || (2 != g_variant_iter_init (&iter, values)))
    {
      gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
      goto cleanup;
    }

  lower = g_variant_iter_next_value (&iter);
  upper = g_variant_iter_next_value (&iter);

  self->type = g_variant_get_type (lower);

  apply_value (adj, lower, "lower");
  apply_value (adj, upper, "upper");

  signal_detail = g_strdup_printf ("changed::%s", self->key);

  self->handler =
    g_signal_connect_object (self->settings,
                             signal_detail,
                             G_CALLBACK (ide_preferences_spin_button_setting_changed),
                             self,
                             G_CONNECT_SWAPPED);

  ide_preferences_spin_button_setting_changed (self, self->key, self->settings);

cleanup:
  g_clear_pointer (&key, g_settings_schema_key_unref);
  g_clear_pointer (&type, g_free);
  g_clear_pointer (&signal_detail, g_free);
  g_clear_pointer (&range, g_variant_unref);
  g_clear_pointer (&values, g_variant_unref);
  g_clear_pointer (&lower, g_variant_unref);
  g_clear_pointer (&upper, g_variant_unref);
  g_clear_pointer (&schema, g_settings_schema_unref);
}
Exemplo n.º 3
0
/*Apply options, check data*/
void apply_options( int res_mode )
{
    int i = 0;
    int j;
    int* cid;
    for( i = 0; i < size_input_prm; ++i )
    {
        char* value = input_strs_file ? input_strs_file[i] : NULL;
        value = input_strs_args[i] ? input_strs_args[i] : value;
        if( value )
        {
            /* from command line are setted in parse_args at the end,
             * but in restart mode their are overwrited in read of rst_file */
            if( res_mode || ( input_strs_file && value == input_strs_file[i] ) )
            {
                apply_value( input_prm[i], value );
            }
        }
        else if( !res_mode ) /* in case of restart we don't show warning */
        {
            char buff[128];
            sprintf( buff, "Parameter not set %s", input_prm[i]->name );
            warning( buff, __FILE__, __LINE__ );
        }
    }

    if( bc == BC_BOX )
    {
        if( xbox <= 0.0 || ybox <= 0.0 || zbox <= 0.0)
        {
            UNERR("Wrong box size");
        }
        inv_L[0] = 1 / xbox;
        inv_L[1] = 1 / ybox;
        inv_L[2] = 1 / zbox;
        inv_L[3] = 0.0;

        ewald = (hydro != DIFF_NONE);/* Run Ewald summation */
        if( ewald )
        {
            if( xbox!=ybox || ybox!=zbox ) UNERR("In Ewald box must be cube");

            for( i = 0; i < size; ++i )
            {
                if( LJ[ i*2 ] < coord[ i *DIMS1 + 3 ] )
                {
                    UNERR("LJ radii too small, should be at least 2 * bead radii");
                }
            }
            if( ewald_real != ewald_recip )
            {
                UNERR("ewald_real != ewald_recip");
            }
            if( ewald_real < 0 || ewald_real > 5 )
            {
                UNERR("ewald_real wrong value, only 0..5");
            }
        }

        box[0] = xbox;
        box[1] = ybox;
        box[2] = zbox;
        box[3] = 0.0;

        if( cutoff_c > xbox/2 ) warning("cutoff_c greater than half of xbox", __FILE__, __LINE__ );
        if( cutoff_c > ybox/2 ) warning("cutoff_c greater than half of ybox", __FILE__, __LINE__ );
        if( cutoff_c > zbox/2 ) warning("cutoff_c greater than half of zbox", __FILE__, __LINE__ );

        if( cutoff_lj > xbox/2 ) warning("cutoff_lj greater than half of xbox", __FILE__, __LINE__ );
        if( cutoff_lj > ybox/2 ) warning("cutoff_lj greater than half of ybox", __FILE__, __LINE__ );
        if( cutoff_lj > zbox/2 ) warning("cutoff_lj greater than half of zbox", __FILE__, __LINE__ );
        if( cutoff_lj < 0.0 && cutoff_lj != -1 ) UNERR("Wrong cutoff_lj value");
        if( cutoff_c < 0.0 ) UNERR("Wrong cutoff_c value");
#if USE_SSE
        UNERR("Currently, bc periodic is not implemented for SSE");
#endif
    }
    cid = (int*) malloc( sizeof(int)*size );
    if ( cid )
    {
        for( i = 0; i < size; ++i )
        {
            cid[i] = ids[i];
        }
        qsort( cid, size, sizeof(int), simple_int_cmp );
        for( i = 0; i < size-1; ++i )
        {
            if ( cid[i] == cid[i+1] ) UNERR( "Wrong atom numeration");
        }
        free( cid );
    }
    else
    {
        for( i = 0; i < size; ++i )
        {
            for( j = i + 1; j < size; ++j )
            {
                if( ids[i] == ids[j] ) UNERR("Wrong atom numeration");
            }
        }
    }
    for( i = 0; i < size; ++i )
    {
        if( coord[DIMS1*i +3] <= 0.0 ) UNERR( "Wrong atom radii");
    }

    if( vfactor == 0.0 ) UNERR("Wrong value for vfactor");
    if( visc == 0.0 ) UNERR( "Wrong value for visc");
    if ( alpha_lj < 0.0 ) UNERR( "Wrong value for alpha_lj");
    if( vel_grad_tensor && bc == BC_SPHERE )
    {
        warning( "Simulations in a flowing solvent turned off because of sphere bc", __FILE__, __LINE__ );
        free(vel_grad_tensor);
        vel_grad_tensor = NULL;
        MAKE_STR_SIZE(vel_grad_tensor,0);
    }
    if(lj_6_term) lj_6_term=1;/* 'y' - 'n' = 11 */
    if(E_ext)
    {
        if(E_dir1!='x'&&E_dir1!='y'&&E_dir1!='z')
            UNERR("Wrong value for E_dir1");
        if(E_type==2) if(E_dir2!='x'&&E_dir2!='y'&&E_dir2!='z')
                UNERR("Wrong value for E_dir2");
    }
#if USE_SSE
    if( ( 4 - 2*(sizeof(DOUBLE) == sizeof(double)) ) != SSECOUNT )
    {
        UNERR("SSE wrong data.h header");
    }
    if ( nb_list != BUCKET_NONE )
    {
        UNERR("nb_list not implemented in SSE mode, use brute");
    }
#endif
    if( elec && kappa_c < 0.0) UNERR("Wrong kappa_c value");
    if( algorithm == DIFF_ALG_ERMAK_NEWTON )
    {
        int i;
        for( i = 0; i < size; ++i )
        {
            if( masses[i] <= 0.0 ) UNERR("Wrong mass value");
            if( LJ[2*i] <= 0.0 ) UNERR("Wrong LJ value");
        }
    }
    if(hydro != DIFF_GEYER || algorithm >= DIFF_ALG_IGT_CONST )
    {
        geyer_on_the_fly = 0; /* force turn off */
        warning("Geyer on the fly turned off", __FILE__, __LINE__ );
    }
    if( sboundary_n < 0 ) UNERR("Wrong value for sboundary_n > 0");
}
Exemplo n.º 4
0
/*parsing*/
INT parse_args( int argc, char* argv[] )
{
    int i;
    if( argc == 1 )
    {
        IFP print_help();
        return 0;
    }
    else
    {
        int i;
        int files = 0;/*number of input files*/

        /*prepare place for arguments*/
        input_strs_args = (STR*) malloc( sizeof(STR) * size_input_prm );
        CHMEM(input_strs_args);
        memset( input_strs_args, 0, sizeof(STR) * size_input_prm );

        /*parse arguments*/
        for( i = 1; i < argc; ++i )
        {
            STR cmd = argv[i];
            if( CHECK_OPT2( cmd, STR_HELP, STR_HELPs) )
            {
                IFP print_help();
                return 0;
            }
            else if( CHECK_OPT2( cmd, STR_USAGE, STR_USAGEs) )
            {
                IFP print_usage();
                return 0;
            }
            else if( CHECK_OPT2( cmd, STR_VER, STR_VERs) )
            {
                IFP print_version();
                return 0;
            }
            else
            {
                int find_prm_args = 0;
                int j;
                size_t len_cmd = strlen(cmd);
                if( len_cmd > 3 && cmd[0] =='-'  && cmd[1] =='-' )
                {
                    for( j = 0; j < size_input_prm; ++j )
                    {
                        size_t name_len = strlen(input_prm[j]->name);
                        if( name_len + 3 < len_cmd  &&
                                strncmp( input_prm[j]->name, cmd + 2, name_len ) == 0 &&
                                cmd[ name_len + 2 ] == '=' )
                        {
                            STR tmp_str;
                            char buff[64];
                            find_prm_args = 1;
                            if( input_strs_args[j] != NULL )
                            {
                                sprintf( buff, "Arg option duplicated %s\n", input_prm[j]->name );
                                warning( buff, __FILE__, __LINE__ );
                            }
                            tmp_str = STRDUP( cmd + name_len + 3 );
                            input_strs_args[j] = STRDUP( cmd + name_len + 3 );
                            if( !check_type( input_prm[j]->type, tmp_str ) )
                            {
                                sprintf( buff, "Arg option has wrong value type %s\n", input_prm[j]->name );
                                UNERR(buff);
                            }
                            free( tmp_str );
                            break;
                        }
                    }
                }

                if( find_prm_args )
                {
                    continue;
                }
                else if( strlen( cmd ) && cmd[0] == '-' )
                {
                    IFP printf( "Unknown option: %s\n", cmd );
                    IFP print_usage();
                    return 0;
                }
                else
                {
                    if( files )
                    {
                        IFP printf("Too many files\n");
                        IFP print_usage();
                        return 0;
                    }
                    else
                    {
                        files++;
                        prm_filename = cmd;
                    }
                }
            }
        }
    }
    for( i = 0; i < size_input_prm; ++i )
    {
        char* value = input_strs_args[i];
        if( value )
        {
            apply_value( input_prm[i], value );
        }
    }
    return 1;
}