static void oregano_application (GApplication *app, GFile *file) { Schematic *schematic = NULL; SchematicView *schematic_view = NULL; gchar *msg; Splash *splash = NULL; GError *error = NULL; // Keep non localized input for ngspice setlocale (LC_NUMERIC, "C"); if (oregano.show_splash) { splash = oregano_splash_new (&error); if (error) { msg = g_strdup_printf (_ ("Failed to spawn splash-screen \'%s\''. Code %i - %s"), OREGANO_UIDIR "splash.ui", error->code, error->message); oregano_error (msg); g_free (msg); g_clear_error (&error); // non fatal issue } } // splash == NULL if showing splash is disabled oregano_lookup_libraries (splash); if (oregano.libraries == NULL) { oregano_error (_ ("Could not find a parts library.\n\n" "Supposed to be in " OREGANO_LIBRARYDIR)); return; } oregano.clipboard = NULL; schematic = NULL; if (file) { GError *error = NULL; char *fname = g_file_get_parse_name (file); schematic = schematic_read (fname, &error); if (schematic) { schematic_view = schematic_view_new (schematic); gtk_widget_show_all (schematic_view_get_toplevel (schematic_view)); schematic_set_filename (schematic, fname); schematic_set_title (schematic, g_path_get_basename (fname)); } } else { schematic = schematic_new (); schematic_view = schematic_view_new (schematic); gtk_widget_show_all (schematic_view_get_toplevel (schematic_view)); } g_signal_add_emission_hook (g_signal_lookup ("last_schematic_destroyed", TYPE_SCHEMATIC), 0, quit_hook, NULL, NULL); if (oregano.show_splash && splash) oregano_splash_done (splash, _ ("Welcome to Oregano")); }
void simulation_show (GtkWidget *widget, SchematicView *sv) { GtkWidget *w; GladeXML *gui; Simulation *s; Schematic *sm; g_return_if_fail (sv != NULL); sm = schematic_view_get_schematic (sv); s = schematic_get_simulation (sm); /* Only allow one instance of the dialog box per schematic. */ if (s->dialog){ gdk_window_raise (GTK_WIDGET (s->dialog)->window); return; } if (!g_file_test (OREGANO_GLADEDIR "/simulation.glade2", G_FILE_TEST_EXISTS)) { oregano_error (_("Could not create simulation dialog")); return; } gui = glade_xml_new (OREGANO_GLADEDIR "/simulation.glade2", "toplevel", NULL); if (!gui) { oregano_error (_("Could not create simulation dialog")); return; } w = glade_xml_get_widget (gui, "toplevel"); if (!w) { oregano_error (_("Could not create simulation dialog")); return; } s->dialog = GTK_DIALOG (w); g_signal_connect (G_OBJECT (w), "delete_event", G_CALLBACK (delete_event_cb), s); w = glade_xml_get_widget (gui, "progressbar"); s->progress = GTK_PROGRESS_BAR (w); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (s->progress), 0.0); w = glade_xml_get_widget (gui, "progress_label"); s->progress_label = GTK_LABEL (w); g_signal_connect (G_OBJECT (s->dialog), "response", G_CALLBACK (cancel_cb), s); gtk_widget_show_all (GTK_WIDGET (s->dialog)); s->sv = sv; simulate_cmd (s); }
static void engine_aborted_cb (OreganoEngine *engine, Simulation *s) { GtkWidget *dialog; int answer; if (s->progress_timeout_id != 0) { g_source_remove (s->progress_timeout_id); s->progress_timeout_id = 0; } gtk_widget_destroy (GTK_WIDGET (s->dialog)); s->dialog = NULL; if (!schematic_view_log_window_exists (s->sv)) { dialog = gtk_message_dialog_new_with_markup ( GTK_WINDOW (s->sv->toplevel), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, _("<span weight=\"bold\" size=\"large\">The simulation was aborted due to an error.</span>\n\n" "Would you like to view the error log?")); answer = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); if (answer == GTK_RESPONSE_YES) { schematic_view_log_show (s->sv, TRUE); } } else { oregano_error (_("The simulation was aborted due to an error")); schematic_view_log_show (s->sv, FALSE); } }
NetlistEditor * netlist_editor_new_from_schematic_view (SchematicView *sv) { NetlistEditor *editor; gchar *name = "/tmp/oregano.netlist"; GError *error = 0; Schematic *sm; OreganoEngine *engine; sm = schematic_view_get_schematic (sv); engine = oregano_engine_factory_create_engine (oregano.engine, sm); oregano_engine_generate_netlist (engine, name, &error); g_object_unref (engine); if (error != NULL) { if (g_error_matches (error, OREGANO_ERROR, OREGANO_SIMULATE_ERROR_NO_CLAMP) || g_error_matches (error, OREGANO_ERROR, OREGANO_SIMULATE_ERROR_NO_GND) || g_error_matches (error, OREGANO_ERROR, OREGANO_SIMULATE_ERROR_IO_ERROR)) { oregano_error_with_title (_("Could not create a netlist"), error->message); g_clear_error (&error); } else { oregano_error (_("An unexpected error has occurred")); } return NULL; } editor = netlist_editor_new_from_file (name); if (editor) { editor->priv->sv = sv; } return editor; }
void netlist_editor_simulate (GtkWidget * widget, NetlistEditor * nle) { Schematic *sm; gchar *name; GtkTextView *tview; GtkTextBuffer *buffer; GtkTextIter start, end; FILE *fp; GError *error = 0; OreganoEngine *engine; // FIXME: OreganoEngine now override the netlist when start! return; tview = nle->priv->view; buffer = gtk_text_view_get_buffer (tview); gtk_text_buffer_get_start_iter (buffer, &start); gtk_text_buffer_get_end_iter (buffer, &end); sm = schematic_view_get_schematic (nle->priv->sv); //name = nl_generate (sm, NULL, &error); if (error != NULL) { if (g_error_matches (error, OREGANO_ERROR, OREGANO_SIMULATE_ERROR_NO_CLAMP) || g_error_matches (error, OREGANO_ERROR, OREGANO_SIMULATE_ERROR_NO_GND) || g_error_matches (error, OREGANO_ERROR, OREGANO_SIMULATE_ERROR_IO_ERROR)) { oregano_error_with_title (_("Could not create a netlist"), error->message); g_clear_error (&error); } else { oregano_error ( _("An unexpected error has occurred")); } return; } /* Save TextBuffer to 'name' */ fp = fopen (name, "wt"); if (!fp) { gchar *msg; msg = g_strdup_printf (_("The file %s could not be saved"), name); oregano_error_with_title (_("Could not save temporary netlist file"), msg); g_free (msg); return; } fputs (gtk_text_buffer_get_text (buffer, &start, &end, FALSE), fp); fclose (fp); schematic_set_netlist_filename (sm, name); simulation_show (NULL, nle->priv->sv); g_free (name); }
Splash * oregano_splash_new () { GtkBuilder *gui; GError *perror = NULL; Splash *sp; GtkEventBox *event; gchar *msg; if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create splash message.")); return NULL; } else gtk_builder_set_translation_domain (gui, NULL); if (!g_file_test (OREGANO_UIDIR "/splash.ui", G_FILE_TEST_EXISTS) || !g_file_test (OREGANO_UIDIR "/splash.xpm", G_FILE_TEST_EXISTS)) { msg = g_strdup_printf ( _("The files %s or %s could not be found. You might need to reinstall Oregano to fix this."), OREGANO_UIDIR "/splash.ui", OREGANO_UIDIR "/splash.xpm"); oregano_error_with_title (_("Could not create splash message."), msg); g_free (msg); return NULL; } if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/splash.ui", &perror) <= 0) { msg = perror->message; oregano_error_with_title (_("Could not create splash message."), msg); g_error_free (perror); return NULL; } sp = g_new0 (Splash, 1); sp->can_destroy = FALSE; sp->win = GTK_WINDOW (gtk_builder_get_object (gui, "splash")); sp->lbl = GTK_LABEL (gtk_builder_get_object (gui, "label")); sp->progress = GTK_WIDGET (gtk_builder_get_object (gui, "pbar")); event = GTK_EVENT_BOX (gtk_builder_get_object (gui, "event")); sp->event = GTK_WIDGET (event); gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (sp->progress), 0.07); gtk_widget_show_all (GTK_WIDGET (sp->win)); while (gtk_events_pending ()) gtk_main_iteration (); return sp; }
static void edit_textbox (SheetItem *sheet_item) { TextboxItem *item; Textbox *textbox; const char *value; GtkBuilder *builder; GError *e = NULL; Sheet *sheet = sheet_item_get_sheet (sheet_item); g_return_if_fail (sheet_item != NULL); g_return_if_fail (IS_TEXTBOX_ITEM (sheet_item)); if ((builder = gtk_builder_new ()) == NULL) { oregano_error (_ ("Could not create textbox properties dialog")); return; } gtk_builder_set_translation_domain (builder, NULL); item = TEXTBOX_ITEM (sheet_item); textbox = TEXTBOX (sheet_item_get_data (sheet_item)); if (!gtk_builder_add_from_file (builder, OREGANO_UIDIR "/textbox-properties-dialog.ui", &e)) { oregano_error_with_title (_ ("Could not create textbox properties dialog."), e->message); g_clear_error (&e); return; } prop_dialog = g_new0 (TextboxPropDialog, 1); prop_dialog->dialog = GTK_DIALOG (gtk_builder_get_object (builder, "textbox-properties-dialog")); prop_dialog->entry = GTK_ENTRY (gtk_builder_get_object (builder, "entry")); value = textbox_get_text (textbox); gtk_entry_set_text (GTK_ENTRY (prop_dialog->entry), value); gtk_dialog_run (GTK_DIALOG (prop_dialog->dialog)); edit_dialog_ok (item); gtk_widget_destroy (GTK_WIDGET (prop_dialog->dialog)); g_free (prop_dialog); g_object_unref (builder); }
static void place_cmd (GtkWidget *widget, Browser *br) { LibraryPart *library_part; char *part_name; Coords pos; Sheet *sheet; Part *part; GtkTreeModel *model; GtkTreeIter iter; GtkTreeSelection *selection; schematic_view_reset_tool (br->schematic_view); sheet = schematic_view_get_sheet (br->schematic_view); // Get the current selected row selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (br->list)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (br->list)); if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) { return; } gtk_tree_model_get (model, &iter, 0, &part_name, -1); library_part = library_get_part (br->library, part_name); part = part_new_from_library_part (library_part); if (!part) { oregano_error (_("Unable to load required part")); return; } pos.x = pos.y = 0; item_data_set_pos (ITEM_DATA (part), &pos); sheet_connect_part_item_to_floating_group (sheet, (gpointer) br->schematic_view); sheet_select_all (sheet, FALSE); sheet_clear_ghosts (sheet); sheet_add_ghost_item (sheet, ITEM_DATA (part)); }
void part_browser_dnd (GtkSelectionData *selection_data, int x, int y) { LibraryPart *library_part; Coords pos; DndData *data; Sheet *sheet; Part *part; data = (DndData *) (gtk_selection_data_get_data (selection_data)); g_return_if_fail (data != NULL); pos.x = x; pos.y = y; sheet = schematic_view_get_sheet (data->schematic_view); snap_to_grid (sheet->grid, &pos.x, &pos.y); library_part = library_get_part (data->br->library, data->part_name); part = part_new_from_library_part (library_part); if (!part) { oregano_error (_("Unable to load required part")); return; } item_data_set_pos (ITEM_DATA (part), &pos); sheet_connect_part_item_to_floating_group (sheet, (gpointer) data->schematic_view); sheet_select_all (sheet, FALSE); sheet_clear_ghosts (schematic_view_get_sheet (data->schematic_view)); sheet_add_ghost_item (sheet, ITEM_DATA (part)); }
void settings_show (GtkWidget *widget, SchematicView *sv) { gint i; GtkWidget *engine_group = NULL; GtkWidget *w, *pbox, *toplevel; GtkBuilder *gui; GError *perror = NULL; gchar *msg; Settings *s; Schematic *sm; g_return_if_fail (sv != NULL); // If no engine available, stop oregano if ((g_find_program_in_path (engine[0]) == NULL) && (g_find_program_in_path (engine[1]) == NULL)) { gchar *msg; msg = g_strdup_printf ( _("No engine allowing analysis is available.\n" "You might install one, at least! \n" "Either ngspice or gnucap.")); oregano_error_with_title (_("Could not create settings dialog"), msg); g_free (msg); return; } g_return_if_fail (sv != NULL); if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create settings dialog")); return; } gtk_builder_set_translation_domain (gui, NULL); sm = schematic_view_get_schematic (sv); s = schematic_get_settings (sm); // Only allow one instance of the property box per schematic. if (GTK_WIDGET (SETTINGS (s)->pbox)) { gdk_window_raise (gtk_widget_get_window ( GTK_WIDGET (SETTINGS (s)->pbox))); return; } if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/settings.ui", &perror) <= 0) { msg = perror->message; oregano_error_with_title (_("Could not create settings dialog"), msg); g_error_free (perror); return; } w = toplevel = GTK_WIDGET (gtk_builder_get_object (gui, "toplevel")); if (!w) { oregano_error (_("Could not create settings dialog")); return; } g_signal_connect (G_OBJECT (w), "delete_event", G_CALLBACK (delete_event_callback), s); pbox = toplevel; s->pbox = GTK_WIDGET (pbox); w = GTK_WIDGET (gtk_builder_get_object (gui, "close_bt")); g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (apply_callback), s); w = GTK_WIDGET (gtk_builder_get_object (gui, "splash-enable")); s->w_show_splash = w; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), oregano.show_splash); w = GTK_WIDGET (gtk_builder_get_object (gui, "compress-enable")); s->w_compress_files = w; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), oregano.compress_files); w = GTK_WIDGET (gtk_builder_get_object (gui, "log-enable")); s->w_show_log = w; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), oregano.show_log); w = GTK_WIDGET (gtk_builder_get_object (gui, "grid-size")); gtk_widget_set_sensitive (w, FALSE); w = GTK_WIDGET (gtk_builder_get_object (gui, "realtime-enable")); gtk_widget_set_sensitive (w, FALSE); w = GTK_WIDGET (gtk_builder_get_object (gui, "engine_table")); for (i = 0; i < OREGANO_ENGINE_COUNT; i++) { if (engine_group) button[i] = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON (engine_group), engine[i]); else button[i] = engine_group = gtk_radio_button_new_with_label_from_widget (NULL, engine[i]); g_object_set_data (G_OBJECT (button[i]), "id", GUINT_TO_POINTER (i)); gtk_grid_attach (GTK_GRID (w), button[i], 0, i, 1, 1); g_signal_connect (G_OBJECT (button[i]), "clicked", G_CALLBACK (set_engine_name), s); } // Is the engine available? // In that case the button is active if (g_find_program_in_path (engine[oregano.engine]) != NULL) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button[oregano.engine]), TRUE); // Otherwise the button is inactive else gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button[oregano.engine]), FALSE); // If no engine available, stop oregano if ((g_find_program_in_path (engine[0]) == NULL) && (g_find_program_in_path (engine[1]) == NULL)) { gchar *msg; msg = g_strdup_printf ( _("No engine allowing analysis is available.\n" "You might install one, at least! \n" "Either ngspice or gnucap.")); oregano_error_with_title (_("Could not create settings dialog"), msg); g_free (msg); } gtk_widget_show_all (toplevel); }
void plot_add_function_show (OreganoEngine *engine, SimulationData *current) { GtkBuilder *gui; GError *perror = NULL; GtkDialog *dialog; GtkComboBoxText *op1, *op2, *functiontype; int i; gint result = 0; GtkWidget *warning; GtkWidget *container_temp; SimulationFunction *func = g_new0 (SimulationFunction, 1); if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create plot window.")); return; } gtk_builder_set_translation_domain (gui, NULL); if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/plot-add-function.ui", &perror) <= 0) { oregano_error_with_title (_("Could not create plot window."), perror->message); g_error_free (perror); return; } dialog = GTK_DIALOG (gtk_builder_get_object (gui, "toplevel")); container_temp = GTK_WIDGET (gtk_builder_get_object (gui, "op1_alignment")); op1 = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new ()); gtk_container_add (GTK_CONTAINER (container_temp), GTK_WIDGET (op1)); gtk_widget_show (GTK_WIDGET (op1)); container_temp = GTK_WIDGET (gtk_builder_get_object (gui, "op2_alignment")); op2 = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new ()); gtk_container_add (GTK_CONTAINER (container_temp), GTK_WIDGET (op2)); gtk_widget_show (GTK_WIDGET (op2)); container_temp = GTK_WIDGET (gtk_builder_get_object (gui, "function_alignment")); functiontype = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new ()); gtk_container_add (GTK_CONTAINER (container_temp), GTK_WIDGET (functiontype)); gtk_widget_show (GTK_WIDGET (functiontype)); gtk_combo_box_text_append_text (functiontype, _("Substraction")); gtk_combo_box_text_append_text (functiontype, _("Division")); for (i = 1; i < current->n_variables; i++) { if (current->type != DC_TRANSFER) { if (strchr (current->var_names[i], '#') == NULL) { gtk_combo_box_text_append_text (op1, current->var_names[i]); gtk_combo_box_text_append_text (op2, current->var_names[i]); } } else { gtk_combo_box_text_append_text (op1, current->var_names[i]); gtk_combo_box_text_append_text (op2, current->var_names[i]); } } gtk_combo_box_set_active (GTK_COMBO_BOX (op1),0); gtk_combo_box_set_active (GTK_COMBO_BOX (op2),1); gtk_combo_box_set_active (GTK_COMBO_BOX (functiontype),0); result = gtk_dialog_run (GTK_DIALOG (dialog)); if ((result == GTK_RESPONSE_OK) && ((gtk_combo_box_get_active (GTK_COMBO_BOX (op1)) == -1) || (gtk_combo_box_get_active (GTK_COMBO_BOX (op2)) == -1) || (gtk_combo_box_get_active (GTK_COMBO_BOX (functiontype)) == -1))) { warning = gtk_message_dialog_new_with_markup ( NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("<span weight=\"bold\" size=\"large\">Neither function, nor operators have been chosen</span>\n\n" "Please, take care to choose a function and their associated operators")); if (gtk_dialog_run (GTK_DIALOG (warning)) == GTK_RESPONSE_OK) { gtk_widget_destroy (GTK_WIDGET (warning)); plot_add_function_show (engine, current); gtk_widget_destroy (GTK_WIDGET (dialog)); return; } } if ((result == GTK_RESPONSE_OK) && ((gtk_combo_box_get_active (GTK_COMBO_BOX (op1)) != -1) && (gtk_combo_box_get_active (GTK_COMBO_BOX (op2)) != -1) && (gtk_combo_box_get_active (GTK_COMBO_BOX (functiontype)) != -1))) { for (i = 1; i < current->n_variables; i++) { if (g_strcmp0 (current->var_names[i], gtk_combo_box_text_get_active_text (op1)) == 0) func->first = i; if (g_strcmp0 (current->var_names[i], gtk_combo_box_text_get_active_text (op2)) == 0) func->second = i; } current->functions = g_list_append (current->functions, func); } gtk_widget_destroy (GTK_WIDGET (dialog)); }
NetlistEditor * netlist_editor_new (GtkSourceBuffer * textbuffer) { NetlistEditor * nle; GtkBuilder *gui; GError *perror = NULL; GtkWidget * toplevel; GtkScrolledWindow * scroll; GtkSourceView * source_view; GtkSourceLanguageManager * lm; GtkButton * save, * close; GtkSourceLanguage *lang=NULL; if (!textbuffer) return NULL; if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create the netlist dialog")); return NULL; } gtk_builder_set_translation_domain (gui, NULL); nle = NETLIST_EDITOR (g_object_new (netlist_editor_get_type (), NULL)); if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/view-netlist.ui", &perror) <= 0) { gchar *msg; msg = perror->message; oregano_error_with_title (_("Could not create the netlist dialog"), msg); g_error_free (perror); return NULL; } toplevel = GTK_WIDGET (gtk_builder_get_object (gui, "toplevel")); gtk_window_set_default_size (GTK_WINDOW (toplevel), 800, 600); gtk_window_set_title (GTK_WINDOW (toplevel), "Net List Editor\n"); scroll = GTK_SCROLLED_WINDOW (gtk_builder_get_object (gui, "netlist-scrolled-window")); source_view = GTK_SOURCE_VIEW (gtk_source_view_new ()); lm = GTK_SOURCE_LANGUAGE_MANAGER (gtk_source_language_manager_new ()); setup_language_manager_path (lm); g_object_set_data_full (G_OBJECT (source_view), "language-manager", lm, (GDestroyNotify) g_object_unref); lang = gtk_source_language_manager_get_language (lm, "netlist"); if (lang) { NG_DEBUG ("\"%s\" from \"%s\"", gtk_source_language_get_name (lang), OREGANO_LANGDIR "/netlist.lang"); gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (textbuffer), lang); gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (textbuffer), TRUE); gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (textbuffer), TRUE); } else { g_warning ("Can't load netlist.lang in %s", OREGANO_LANGDIR "/netlist.lang"); } gtk_text_view_set_editable (GTK_TEXT_VIEW (source_view), TRUE); gtk_text_view_set_buffer (GTK_TEXT_VIEW (source_view), GTK_TEXT_BUFFER (textbuffer)); gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (source_view)); close = GTK_BUTTON (gtk_builder_get_object (gui, "btn_close")); g_signal_connect_swapped (G_OBJECT (close), "clicked", G_CALLBACK (g_object_unref), G_OBJECT (nle)); save = GTK_BUTTON (gtk_builder_get_object (gui, "btn_save")); g_signal_connect (G_OBJECT (save), "clicked", G_CALLBACK (netlist_editor_save), nle); // Set tab, fonts, wrap mode, colors, etc. according // to preferences nle->priv->view = GTK_TEXT_VIEW (source_view); nle->priv->toplevel = GTK_WINDOW (toplevel); nle->priv->save = save; nle->priv->close = close; nle->priv->buffer = textbuffer; gtk_widget_show_all (GTK_WIDGET (toplevel)); return nle; }
// part_browser_create // // Creates a new part browser. This is only called once per schematic window. GtkWidget * part_browser_create (SchematicView *schematic_view) { Browser *br; GtkBuilder *gui; GError *perror = NULL; char *msg; GtkWidget *w, *view; GtkCellRenderer *cell_text; GtkTreeViewColumn *cell_column; static GtkTargetEntry dnd_types[] = { { "x-application/oregano-part", 0, DRAG_PART_INFO } }; static int dnd_num_types = sizeof (dnd_types) / sizeof (dnd_types[0]); GtkTreePath *path; if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create part browser")); return NULL; } else gtk_builder_set_translation_domain (gui, NULL); br = g_new0 (Browser, 1); br->preview = NULL; br->schematic_view = schematic_view; br->hidden = FALSE; schematic_view_set_browser (schematic_view, br); if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/part-browser.ui", &perror) <= 0) { msg = perror->message; oregano_error_with_title (_("Could not create part browser"), msg); g_error_free (perror); return NULL; } view = GTK_WIDGET (gtk_builder_get_object (gui, "viewport1")); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (view), 115); w = goo_canvas_new (); gtk_container_add (GTK_CONTAINER (view), GTK_WIDGET (w)); br->canvas = w; g_signal_connect (w, "realize", (GCallback) preview_realized, br); //gtk_widget_set_size_request (w, PREVIEW_WIDTH, // PREVIEW_HEIGHT + PREVIEW_TEXT_HEIGHT); goo_canvas_set_bounds (GOO_CANVAS (w), 0, 0, PREVIEW_WIDTH, (PREVIEW_HEIGHT + PREVIEW_TEXT_HEIGHT)); br->description = GOO_CANVAS_TEXT (goo_canvas_text_new ( goo_canvas_get_root_item (GOO_CANVAS (br->canvas)), "", 0.0, PREVIEW_HEIGHT - 9.0, 100.0, GOO_CANVAS_ANCHOR_NORTH_WEST, "font", "sans 9", NULL)); // Set up dnd. g_signal_connect (G_OBJECT (br->canvas), "drag_data_get", G_CALLBACK (drag_data_get), br); gtk_drag_source_set (br->canvas, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK, dnd_types, dnd_num_types, GDK_ACTION_MOVE); br->filter_entry = GTK_ENTRY (gtk_builder_get_object (gui, "part_search")); g_signal_connect (G_OBJECT (br->filter_entry), "changed", G_CALLBACK (part_search_change), br); g_signal_connect (G_OBJECT (br->filter_entry), "activate", G_CALLBACK (part_search_activate), br); // Buttons. w = GTK_WIDGET (gtk_builder_get_object (gui, "place_button")); g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (place_cmd), br); // Update the libraries option menu br->library = g_list_nth_data (oregano.libraries, 0); part_browser_setup_libs (br, gui); // Parts list. w = GTK_WIDGET (gtk_builder_get_object (gui, "parts_list")); br->list = w; // Create the List Model for TreeView, this is a Real model br->real_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); cell_text = gtk_cell_renderer_text_new (); cell_column = gtk_tree_view_column_new_with_attributes ( "", cell_text, "text", 0, NULL); // Create the sort model for the items, this sort the real model br->sort_model = gtk_tree_model_sort_new_with_model ( GTK_TREE_MODEL (br->real_model)); gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE (br->sort_model), 0, GTK_SORT_ASCENDING); // Create the filter sorted model. This filter items based on user // request for fast item search br->filter_model = gtk_tree_model_filter_new (br->sort_model, NULL); gtk_tree_model_filter_set_visible_func ( GTK_TREE_MODEL_FILTER (br->filter_model), part_list_filter_func, br, NULL); // If we have TreeFilter use it, if not, just use sorting model only if (br->filter_model) gtk_tree_view_set_model (GTK_TREE_VIEW (w), br->filter_model); else gtk_tree_view_set_model (GTK_TREE_VIEW (w), br->sort_model); gtk_tree_view_append_column (GTK_TREE_VIEW (w), cell_column); update_list (br); // Set up TreeView dnd. g_signal_connect (G_OBJECT (w), "drag_data_get", G_CALLBACK (drag_data_get), br); gtk_drag_source_set (w, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK, dnd_types, dnd_num_types, GDK_ACTION_MOVE); g_signal_connect (G_OBJECT (w), "cursor_changed", G_CALLBACK (select_row), br); g_signal_connect (G_OBJECT (w), "row_activated", G_CALLBACK (part_selected), br); br->viewport = GTK_WIDGET (gtk_builder_get_object (gui, "part_browser_vbox")); path = gtk_tree_path_new_first (); gtk_tree_view_set_cursor (GTK_TREE_VIEW (w), path, NULL, FALSE); gtk_tree_path_free (path); gtk_widget_unparent (br->viewport); return br->viewport; }
static void edit_properties (SheetItem *object) { GSList *properties; PartItem *item; Part *part; char *internal, *msg; GtkBuilder *gui; GError *error = NULL; GtkGrid *prop_grid; GtkNotebook *notebook; gint response, y = 0; gboolean has_model; gchar *model_name = NULL; g_return_if_fail (object != NULL); g_return_if_fail (IS_PART_ITEM (object)); item = PART_ITEM (object); part = PART (sheet_item_get_data (SHEET_ITEM (item))); internal = part_get_property (part, "internal"); if (internal) { if (g_ascii_strcasecmp (internal, "ground") == 0) { g_free (internal); return; } if (g_ascii_strcasecmp (internal, "point") == 0) { edit_properties_point (item); return; } } g_free (internal); if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create part properties dialog.")); return; } else gtk_builder_set_translation_domain (gui, NULL); if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/part-properties-dialog.ui", &error) <= 0) { msg = error->message; oregano_error_with_title (_("Could not create part properties dialog."), msg); g_error_free (error); return; } prop_dialog = g_new0 (PartPropDialog, 1); prop_dialog->part_item = item; prop_dialog->dialog = GTK_DIALOG (gtk_builder_get_object (gui, "part-properties-dialog")); prop_grid = GTK_GRID (gtk_builder_get_object (gui, "prop_grid")); notebook = GTK_NOTEBOOK (gtk_builder_get_object (gui, "notebook")); g_signal_connect (prop_dialog->dialog, "destroy", G_CALLBACK (prop_dialog_destroy), prop_dialog); prop_dialog->widgets = NULL; has_model = FALSE; for (properties = part_get_properties (part); properties; properties = properties->next) { Property *prop; prop = properties->data; if (prop->name) { GtkWidget *entry; GtkWidget *label; gchar *temp=NULL; if (!g_ascii_strcasecmp (prop->name, "internal")) continue; if (!g_ascii_strcasecmp (prop->name, "model")) { has_model = TRUE; model_name = g_strdup (prop->value); } // Find the Refdes and replace by their real value temp = prop->name; if (!g_ascii_strcasecmp (temp, "Refdes")) temp = _("Designation"); if (!g_ascii_strcasecmp (temp, "Template")) temp = _("Template"); if (!g_ascii_strcasecmp (temp, "Res")) temp = _("Resistor"); if (!g_ascii_strcasecmp (temp, "Cap")) temp = _("Capacitor"); if (!g_ascii_strcasecmp (temp, "Ind")) temp = _("Inductor"); label = gtk_label_new (temp); entry = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (entry), prop->value); g_object_set_data (G_OBJECT (entry), "user", g_strdup (prop->name)); gtk_grid_attach (prop_grid, label, 0,y, 1,1); gtk_grid_attach (prop_grid, entry, 1,y, 1,1); y++; gtk_widget_show (label); gtk_widget_show (entry); prop_dialog->widgets = g_list_prepend (prop_dialog->widgets, entry); } } if (!has_model) { gtk_notebook_remove_page (notebook, 1); } else { GtkTextBuffer *txtbuffer; GtkTextView *txtmodel; gchar *filename, *str; GError *read_error = NULL; txtmodel = GTK_TEXT_VIEW (gtk_builder_get_object (gui, "txtmodel")); txtbuffer = gtk_text_buffer_new (NULL); filename = g_strdup_printf ("%s/%s.model", OREGANO_MODELDIR, model_name); if (g_file_get_contents (filename, &str, NULL, &read_error)) { gtk_text_buffer_set_text (txtbuffer, str, -1); g_free (str); } else { gtk_text_buffer_set_text (txtbuffer, read_error->message, -1); g_error_free (read_error); } g_free (filename); g_free (model_name); gtk_text_view_set_buffer (txtmodel, txtbuffer); } gtk_dialog_set_default_response (prop_dialog->dialog, 1); response = gtk_dialog_run (prop_dialog->dialog); prop_dialog_response (GTK_WIDGET (prop_dialog->dialog), response, prop_dialog); g_slist_free_full (properties, g_object_unref); gtk_widget_destroy (GTK_WIDGET (prop_dialog->dialog)); }
static void edit_properties_point (PartItem *item) { GSList *properties; Part *part; GtkBuilder *gui; GError *error = NULL; GtkRadioButton *radio_v, *radio_c; GtkRadioButton *ac_r, *ac_m, *ac_i, *ac_p; GtkCheckButton *chk_db; part = PART (sheet_item_get_data (SHEET_ITEM (item))); if ((gui = gtk_builder_new ()) == NULL) { oregano_error (_("Could not create part properties dialog.")); return; } gtk_builder_set_translation_domain (gui, NULL); if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/clamp-properties-dialog.ui", &error) <= 0) { oregano_error_with_title (_("Could not create part properties dialog."), error->message); g_error_free (error); return; } prop_dialog = g_new0 (PartPropDialog, 1); prop_dialog->part_item = item; prop_dialog->dialog = GTK_DIALOG (gtk_builder_get_object (gui, "clamp-properties-dialog")); radio_v = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_v")); radio_c = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_c")); gtk_widget_set_sensitive (GTK_WIDGET (radio_c), FALSE); ac_r = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_r")); ac_m = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_m")); ac_p = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_p")); ac_i = GTK_RADIO_BUTTON (gtk_builder_get_object (gui, "radio_i")); chk_db = GTK_CHECK_BUTTON (gtk_builder_get_object (gui, "check_db")); // Setup GUI from properties for (properties = part_get_properties (part); properties; properties = properties->next) { Property *prop; prop = properties->data; if (prop->name) { if (!g_ascii_strcasecmp (prop->name, "internal")) continue; if (!g_ascii_strcasecmp (prop->name, "type")) { if (!g_ascii_strcasecmp (prop->value, "v")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_v), TRUE); } else { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_c), TRUE); } } else if (!g_ascii_strcasecmp (prop->name, "ac_type")) { if (!g_ascii_strcasecmp (prop->value, "m")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ac_m), TRUE); } else if (!g_ascii_strcasecmp (prop->value, "i")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ac_i), TRUE); } else if (!g_ascii_strcasecmp (prop->value, "p")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ac_p), TRUE); } else if (!g_ascii_strcasecmp (prop->value, "r")) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ac_r), TRUE); } } else if (!g_ascii_strcasecmp (prop->name, "ac_db")) { if (!g_ascii_strcasecmp (prop->value, "true")) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chk_db), TRUE); } } } gtk_dialog_run (prop_dialog->dialog); // Save properties from GUI for (properties = part_get_properties (part); properties; properties = properties->next) { Property *prop; prop = properties->data; if (prop->name) { if (!g_ascii_strcasecmp (prop->name, "internal")) continue; if (!g_ascii_strcasecmp (prop->name, "type")) { g_free (prop->value); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_v))) { prop->value = g_strdup ("v"); } else { prop->value = g_strdup ("i"); } } else if (!g_ascii_strcasecmp (prop->name, "ac_type")) { g_free (prop->value); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ac_m))) { prop->value = g_strdup ("m"); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ac_i))) { prop->value = g_strdup ("i"); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ac_p))) { prop->value = g_strdup ("p"); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ac_r))) { prop->value = g_strdup ("r"); } } else if (!g_ascii_strcasecmp (prop->name, "ac_db")) { g_free (prop->value); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chk_db))) prop->value = g_strdup ("true"); else prop->value = g_strdup ("false"); } } } g_slist_free_full (properties, g_object_unref); gtk_widget_destroy (GTK_WIDGET (prop_dialog->dialog)); }