select VA wave to draw when run simulator master
authoryu.dongliang <18588496441@163.com>
Mon, 16 Jun 2025 15:06:02 +0000 (23:06 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 16 Jun 2025 15:06:09 +0000 (23:06 +0800)
ses_ui.c
ses_ui.h

index 6b7d840bcf3d4d663ab52579eeaf45a5798d0b5d..8913f1a629b8de4a35251bdac9f5fd18df1da37a 100644 (file)
--- a/ses_ui.c
+++ b/ses_ui.c
@@ -1126,18 +1126,27 @@ static int ui_save_file(ses_ui_t* ui)
        return 0;
 }
 
-static void apply_clicked(GtkButton* self, gpointer user_data)
+static void apply_response(GtkDialog* self, gint response_id, gpointer user_data)
 {
-       ses_ui_t* ui = user_data;
+       scf_logi("\n");
 
-       int ret = ui_save_file(ui);
-       if (ret < 0)
-               return;
+       ses_ui_t*   ui    = user_data;
+
+       float       ns    = atof(gtk_entry_get_text(ui->entry_ns));
+       int         count = atoi(gtk_entry_get_text(ui->entry_count));
+       const char* V     =      gtk_entry_get_text(ui->entry_V);
+       const char* A     =      gtk_entry_get_text(ui->entry_A);
 
-       float ns    = atof(gtk_entry_get_text(ui->entry_ns));
-       int   count = atoi(gtk_entry_get_text(ui->entry_count));
+       if (V && *V) {
+               if (A && *A)
+                       printf("./ses %s -l 0 -t %fns -c %d -V %s -A %s\n", ui->save_path, ns, count, V, A);
+               else
+                       printf("./ses %s -l 0 -t %fns -c %d -V %s\n", ui->save_path, ns, count, V);
 
-       printf("./ses %s -l 0 -t %fns -c %d\n", ui->save_path, ns, count);
+       } else if (A && *A)
+               printf("./ses %s -l 0 -t %fns -c %d -A %s\n", ui->save_path, ns, count, A);
+       else
+               printf("./ses %s -l 0 -t %fns -c %d\n", ui->save_path, ns, count);
        fflush(stdout);
 
        gtk_widget_set_sensitive(ui->back,    FALSE);
@@ -1147,6 +1156,94 @@ static void apply_clicked(GtkButton* self, gpointer user_data)
        ui->show_index  = -1;
 
        ui->status = SES_UI_RUN;
+
+       ui->entry_V = NULL;
+       ui->entry_A = NULL;
+
+       gtk_widget_destroy(GTK_WIDGET(self));
+}
+
+static int apply_dialog(ses_ui_t* ui)
+{
+       GtkWidget*  dialog;
+       GtkWidget*  content_area;
+       GtkWidget*  grid;
+
+       GtkWidget*  label_V;
+       GtkWidget*  label_A;
+       GtkWidget*  entry_V;
+       GtkWidget*  entry_A;
+
+       dialog = gtk_dialog_new_with_buttons ("apply",
+                       ui->window,
+                       GTK_DIALOG_DESTROY_WITH_PARENT,
+                       "_OK",
+                       GTK_RESPONSE_NONE,
+                       NULL);
+
+       if (!dialog)
+               return -ENOMEM;
+
+       grid = gtk_grid_new();
+       if (!grid)
+               goto grid_error;
+
+       label_V = gtk_label_new("V wave / 电压波形");
+       if (!label_V)
+               goto label_V_error;
+
+       label_A = gtk_label_new("A wave / 电流波形");
+       if (!label_A)
+               goto label_A_error;
+
+       entry_V = gtk_entry_new();
+       if (!entry_V)
+               goto entry_V_error;
+
+       entry_A = gtk_entry_new();
+       if (!entry_A)
+               goto entry_A_error;
+
+       content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
+       gtk_container_add(GTK_CONTAINER(content_area), grid);
+
+       gtk_grid_attach(GTK_GRID(grid), label_V,     0, 0, 1, 1);
+       gtk_grid_attach(GTK_GRID(grid), entry_V,     1, 0, 1, 1);
+
+       gtk_grid_attach(GTK_GRID(grid), label_A,     0, 1, 1, 1);
+       gtk_grid_attach(GTK_GRID(grid), entry_A,     1, 1, 1, 1);
+
+       g_signal_connect(dialog, "response", G_CALLBACK(apply_response), ui);
+
+       ui->entry_V = GTK_ENTRY(entry_V);
+       ui->entry_A = GTK_ENTRY(entry_A);
+
+       gtk_widget_show_all(dialog);
+       return 0;
+
+entry_A_error:
+       gtk_widget_destroy(entry_V);
+entry_V_error:
+       gtk_widget_destroy(label_A);
+label_A_error:
+       gtk_widget_destroy(label_V);
+label_V_error:
+       gtk_widget_destroy(grid);
+grid_error:
+       gtk_widget_destroy(dialog);
+       return -ENOMEM;
+}
+
+static void apply_clicked(GtkButton* self, gpointer user_data)
+{
+       ses_ui_t* ui = user_data;
+
+       int ret = ui_save_file(ui);
+       if (ret < 0)
+               return;
+
+       ret = apply_dialog(ui);
 }
 
 static int load_file(ses_ui_t* ui, const char* cpk)
@@ -1711,6 +1808,8 @@ static gboolean timer_handler(gpointer user_data)
                GtkTextBuffer* log = gtk_text_view_get_buffer(ui->text_log);
 
                gtk_text_buffer_set_text(log, buf, -1);
+       } else {
+               scf_logi("%s\n", buf);
        }
 
        if (ui->show_index < 0 && ui->apply_index > 0) {
index fcc87ad8862cb9b2904f63a11b5fa57878d2777c..8fca0f9f06ca28654508dc90975e83cccf13f9a6 100644 (file)
--- a/ses_ui.h
+++ b/ses_ui.h
@@ -68,6 +68,8 @@ struct ses_ui_s
 
        GtkEntry*         entry_ns;
        GtkEntry*         entry_count;
+       GtkEntry*         entry_V;
+       GtkEntry*         entry_A;
 
        GtkEntry*         entry_data;
        ScfEcomponent*    setc;
@@ -109,7 +111,7 @@ struct ses_ui_s
        NULL,NULL,NULL,NULL, \
        NULL,NULL,NULL,NULL, \
        NULL,NULL,NULL, \
-       NULL,NULL, \
+       NULL,NULL,NULL,NULL, \
        NULL,NULL, \
        NULL,NULL,NULL, \
        NULL, \