From 6624f87436a53f707f4f9708d94bea53345dd924 Mon Sep 17 00:00:00 2001 From: NatsuDrag9 Date: Wed, 27 Jun 2018 15:39:42 +0530 Subject: Testing lutdialog.cpp --- ldmicro/lutdialog.cpp | 40 +++++++++++++++++++++++----------------- ldmicro/schematic.cpp | 4 ++-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/ldmicro/lutdialog.cpp b/ldmicro/lutdialog.cpp index 188b1a8..919b9bd 100644 --- a/ldmicro/lutdialog.cpp +++ b/ldmicro/lutdialog.cpp @@ -58,6 +58,8 @@ static LONG_PTR PrevIndexProc; static LONG_PTR PrevCountProc; static HWID OkButton; static HWID CancelButton; +static int GLOBAL_LUT_DIALOG_TIMER; +static bool destroyCheck; HWID LutGrid; HWID LutPackingBox; @@ -74,7 +76,6 @@ struct ShowLookUpTableDialogBuffer{ void LutDialogMyNumberProc (GtkEditable *editable, gchar *NewText, gint length, gint *position, gpointer data){ - // gtk_widget_set_sensitive (MainWindow, TRUE); for (int i = 0; i < length; i++){ if (!(isdigit (NewText[i]) || NewText[i] == '\b' || NewText[i] == '-')){ g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); @@ -89,7 +90,6 @@ void LutDialogMyNumberProc (GtkEditable *editable, gchar *NewText, gint length, void LutDialogMyDigitsProc (GtkEditable *editable, gchar *NewText, gint length, gint *position, gpointer data){ - // gtk_widget_set_sensitive (MainWindow, TRUE); for (int i = 0; i < length; i++){ if (!(isdigit (NewText[i]) || NewText[i] == '\b' )){ g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); @@ -104,7 +104,6 @@ void LutDialogMyDigitsProc (GtkEditable *editable, gchar *NewText, gint length, void LutDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, gint *position, gpointer data){ - // gtk_widget_set_sensitive (MainWindow, TRUE); for (int i = 0; i < length; i++){ if (!(isalpha (NewText[i]) || NewText[i] == '_' || isdigit (NewText[i]) || NewText[i] == '\b' )){ @@ -122,7 +121,6 @@ void LutDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, //----------------------------------------------------------------------------- static void MakeFixedControls(BOOL forPwl) { - // cout << "Inside MakeFixedControls ()" << "\n"; Labels[0] = gtk_label_new ("Destination"); Labels[1] = gtk_label_new ("Index:"); Labels[2] = forPwl ? gtk_label_new ("Points:") : gtk_label_new ("Count:"); @@ -134,15 +132,11 @@ static void MakeFixedControls(BOOL forPwl) CountTextbox = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (CountTextbox), 0); - // cout << "Created Labels, Dest, Index and Count text boxes" << "\n"; - if(!forPwl) { AsStringCheckbox = gtk_check_button_new_with_label ("Edit table of ASCII values like a string"); - // cout << "Created CheckButton" << "\n"; } - OkButton = gtk_button_new_with_label ("OK"); CancelButton = gtk_button_new_with_label ("Cancel"); @@ -182,7 +176,6 @@ static void DestroyLutControls(void) int i; for(i = 0; i < WasCount; i++) { char buf[20]; - // SendMessage(ValuesTextbox[i], WM_GETTEXT, (WPARAM)16, (LPARAM)buf); strcpy (buf, gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i]))); ValuesCache[i] = atoi(buf); } @@ -248,7 +241,7 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) } str[j++] = '\0'; StringTextbox = gtk_entry_new (); - gtk_grid_attach (GTK_GRID (LutGrid), StringTextbox, 1, 9, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), StringTextbox, 0, 9, 1, 1); checkString = TRUE; gtk_widget_show_all (LutGrid); gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), FALSE); @@ -279,7 +272,6 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) sprintf(buf, "%d", ValuesCache[i]); ValuesTextbox[i] = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (ValuesTextbox[i]), 0); - // cout << "Made ValuesTextbox" << "\n"; if(forPwl) { sprintf(buf, "%c%d:", (i & 1) ? 'y' : 'x', i/2); @@ -350,7 +342,7 @@ BOOL StringToValuesCache(char *str, int *c) return TRUE; } -void LookUpTableGetData (HWID widget, gpointer data){ +void LookUpTableGetData (gpointer data){ ElemLeaf *l = (ElemLeaf *) data; ElemLookUpTable *t = &(l->d.lookUpTable); strcpy (t->dest, gtk_entry_get_text (GTK_ENTRY (DestTextbox))); @@ -367,6 +359,10 @@ void LookUpTableGetData (HWID widget, gpointer data){ t->count = temp.tmpcount; t->editAsString = temp.tmpasString; gtk_widget_set_sensitive (MainWindow, TRUE); + if (destroyCheck){ + // g_source_remove (GLOBAL_LUT_DIALOG_TIMER); + DestroyWindow (LutDialog); + } } void LookUpTableCheckMode (void){ @@ -378,6 +374,7 @@ void LookUpTableCheckMode (void){ char buf[20]; // buf = const_cast (gtk_entry_get_text (GTK_ENTRY (CountTextbox))); strcpy (buf, gtk_entry_get_text (GTK_ENTRY (CountTextbox))); + g_print("%s\n", buf); if(atoi(buf) != count && !asString) { count = atoi(buf); if(count < 0 || count > 32) { @@ -428,23 +425,33 @@ void LookUpTableCheckMode (void){ gboolean LookUpTableKeyPress (HWID widget, GdkEventKey* event, gpointer data){ LookUpTableCheckMode (); if (event -> keyval == GDK_KEY_Return){ - LookUpTableGetData(NULL, (gpointer) data); + // destroyCheck = TRUE; + LookUpTableGetData((gpointer) data); } else if (event -> keyval == GDK_KEY_Escape){ + // g_source_remove (GLOBAL_LUT_DIALOG_TIMER); DestroyWindow (LutDialog); gtk_widget_set_sensitive (MainWindow, TRUE); } return FALSE; } +BOOL LutRefreshDialog (gpointer data){ + LookUpTableCheckMode (); + LookUpTableGetData((gpointer) data); + return TRUE; +} + // Mouse click callback void LutDialogMouseClick (HWID widget, gpointer data){ + destroyCheck = TRUE; LookUpTableCheckMode (); - LookUpTableGetData(NULL, (gpointer) data); + LookUpTableGetData((gpointer) data); } // Calls DestroyWindow void LutCallDestroyWindow (HWID widget, gpointer data){ + // g_source_remove (GLOBAL_LUT_DIALOG_TIMER); DestroyWindow (LutDialog); gtk_widget_set_sensitive (MainWindow, TRUE); } @@ -479,8 +486,6 @@ void ShowLookUpTableDialog(ElemLeaf *l) // on show style/entry count) controls for the initial configuration. LutGrid = gtk_grid_new(); - // LutGrid[1] = gtk_grid_new(); - // gtk_grid_set_column_spacing (GTK_GRID (LutGrid), 1); LutPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); LutDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); @@ -493,7 +498,7 @@ void ShowLookUpTableDialog(ElemLeaf *l) gtk_widget_add_events (LutDialog, GDK_BUTTON_PRESS_MASK); MakeFixedControls(FALSE); MakeLutControls(asString, count, FALSE); - + // Set up the controls to reflect the initial configuration. gtk_entry_set_text (GTK_ENTRY (DestTextbox), t->dest); gtk_entry_set_text (GTK_ENTRY (IndexTextbox), t->index); @@ -522,6 +527,7 @@ void ShowLookUpTableDialog(ElemLeaf *l) G_CALLBACK(LutDialogMouseClick), (gpointer)l); g_signal_connect (G_OBJECT (CancelButton), "clicked", G_CALLBACK(LutCallDestroyWindow), NULL); + // GLOBAL_LUT_DIALOG_TIMER = g_timeout_add(100, (GSourceFunc)LutRefreshDialog, (gpointer)l); } //----------------------------------------------------------------------------- diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index a53c9c2..5a3954e 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -400,9 +400,9 @@ void MoveCursorKeyboard(int keyCode) //----------------------------------------------------------------------------- void EditSelectedElement(void) -{ +{ ShowLookUpTableDialog(Selected); - // ShowContactsDialog(&(Selected->d.contacts.negated),Selected->d.contacts.name); + // ShowCommentDialog(Selected->d.comment.str); // if(!Selected || Selected->selectedState == SELECTED_NONE) return; -- cgit From 8b1f25cfb7b201c873b39ca0e4521b971a085d48 Mon Sep 17 00:00:00 2001 From: NatsuDrag9 Date: Thu, 28 Jun 2018 09:49:09 +0530 Subject: Testing piecewise dialog --- ldmicro/lutdialog.cpp | 188 ++++++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 89 deletions(-) diff --git a/ldmicro/lutdialog.cpp b/ldmicro/lutdialog.cpp index 919b9bd..c28f6d3 100644 --- a/ldmicro/lutdialog.cpp +++ b/ldmicro/lutdialog.cpp @@ -530,99 +530,109 @@ void ShowLookUpTableDialog(ElemLeaf *l) // GLOBAL_LUT_DIALOG_TIMER = g_timeout_add(100, (GSourceFunc)LutRefreshDialog, (gpointer)l); } +gboolean PiecewiseDialogKeyPress (HWID widget, + GdkEventKey* event, gpointer data){ + if (event->keyval = GDK_KEY_Return){ + PiecewiseDialogGetData(); + } + else if (event->keyval = GDK_KEY_Return){ + + } +} + //----------------------------------------------------------------------------- // Show the piecewise linear table dialog. This one can only be edited in // only a single format, which makes things easier than before. // //----------------------------------------------------------------------------- -// void ShowPiecewiseLinearDialog(ElemLeaf *l) -// { -// ElemPiecewiseLinear *t = &(l->d.piecewiseLinear); - -// // First copy over all the stuff from the leaf structure; in particular, -// // we need our own local copy of the table entries, because it would be -// // bad to update those in the leaf before the user clicks okay (as he -// // might cancel). -// int count = t->count; -// memset(ValuesCache, 0, sizeof(ValuesCache)); -// int i; -// for(i = 0; i < count*2; i++) { -// ValuesCache[i] = t->vals[i]; -// } - -// // Now create the dialog's fixed controls, plus the changing (depending -// // on show style/entry count) controls for the initial configuration. - -// LutDialog = gtk_dialog_new_with_buttons ("Piecewise Linear Table", GTK_WINDOW (MainWindow), -// GTK_DIALOG_MODAL, "Ok", GTK_RESPONSE_ACCEPT, -// "Cancel", GTK_RESPONSE_REJECT, NULL); -// gtk_widget_add_events (LutDialog, GDK_KEY_PRESS_MASK); -// gtk_widget_add_events (LutDialog, GDK_BUTTON_PRESS_MASK); -// MakeFixedControls(TRUE); -// MakeLutControls(FALSE, count*2, TRUE); +void ShowPiecewiseLinearDialog(ElemLeaf *l) +{ + ElemPiecewiseLinear *t = &(l->d.piecewiseLinear); + + // First copy over all the stuff from the leaf structure; in particular, + // we need our own local copy of the table entries, because it would be + // bad to update those in the leaf before the user clicks okay (as he + // might cancel). + int count = t->count; + memset(ValuesCache, 0, sizeof(ValuesCache)); + int i; + for(i = 0; i < count*2; i++) { + ValuesCache[i] = t->vals[i]; + } + + // Now create the dialog's fixed controls, plus the changing (depending + // on show style/entry count) controls for the initial configuration. + + LutDialog = gtk_dialog_new_with_buttons ("Piecewise Linear Table", GTK_WINDOW (MainWindow), + GTK_DIALOG_MODAL, "Ok", GTK_RESPONSE_ACCEPT, + "Cancel", GTK_RESPONSE_REJECT, NULL); + gtk_widget_add_events (LutDialog, GDK_KEY_PRESS_MASK); + gtk_widget_add_events (LutDialog, GDK_BUTTON_PRESS_MASK); + MakeFixedControls(TRUE); + MakeLutControls(FALSE, count*2, TRUE); -// // Set up the controls to reflect the initial configuration. -// gtk_entry_set_text (GTK_ENTRY (DestTextbox), t->dest); -// gtk_entry_set_text (GTK_ENTRY (IndexTextbox), t->index); -// char buf[30]; -// sprintf(buf, "%d", t->count); -// gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf); - -// // And show the window -// gtk_widget_set_sensitive (MainWindow, FALSE); -// gtk_widget_show_all (LutDialog); -// gtk_widget_grab_focus (DestTextbox); -// // SendMessage(DestTextbox, EM_SETSEL, 0, -1); - -// // MSG msg; -// // DWORD ret; -// // DialogDone = FALSE; -// // DialogCancel = FALSE; -// // while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { -// // if(msg.message == WM_KEYDOWN) { -// // if(msg.wParam == VK_RETURN) { -// // DialogDone = TRUE; -// // break; -// // } else if(msg.wParam == VK_ESCAPE) { -// // DialogDone = TRUE; -// // DialogCancel = TRUE; -// // break; -// // } -// // } - -// // if(!IsDialogMessage(LutDialog, &msg)) { -// // TranslateMessage(&msg); -// // DispatchMessage(&msg); -// // } - -// // Watch the (user-editable) count field, and use that to -// // determine how many textboxes to show. -// char* buf; -// buf = gtk_entry_get_text (GTK_ENTRY (CountTextbox)); -// // SendMessage(CountTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)buf); -// if(atoi(buf) != count) { -// count = atoi(buf); -// if(count < 0 || count > 10) { -// count = 0; -// gtk_entry_set_text (GTK_ENTRY (CountTextbox), ""); + // Set up the controls to reflect the initial configuration. + gtk_entry_set_text (GTK_ENTRY (DestTextbox), t->dest); + gtk_entry_set_text (GTK_ENTRY (IndexTextbox), t->index); + char buf[30]; + sprintf(buf, "%d", t->count); + gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf); + + // And show the window + gtk_widget_set_sensitive (MainWindow, FALSE); + gtk_widget_show_all (LutDialog); + gtk_widget_grab_focus (DestTextbox); +// SendMessage(DestTextbox, EM_SETSEL, 0, -1); + +// MSG msg; +// DWORD ret; +// DialogDone = FALSE; +// DialogCancel = FALSE; + // while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { +// if(msg.message == WM_KEYDOWN) { +// if(msg.wParam == VK_RETURN) { +// DialogDone = TRUE; +// break; +// } else if(msg.wParam == VK_ESCAPE) { +// DialogDone = TRUE; +// DialogCancel = TRUE; +// break; // } -// DestroyLutControls(); -// MakeLutControls(FALSE, count*2, TRUE); // } -// } - -// // if(!DialogCancel) { -// // SendMessage(DestTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->dest)); -// // SendMessage(IndexTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->index)); -// // DestroyLutControls(); -// // // The call to DestroyLutControls updated ValuesCache, so just read -// // // them out of there. -// // int i; -// // for(i = 0; i < count*2; i++) { -// // t->vals[i] = ValuesCache[i]; -// // } -// // t->count = count; -// // } - -// // EnableWindow(MainWindow, TRUE); -// // DestroyWindow(LutDialog); -// } + +// if(!IsDialogMessage(LutDialog, &msg)) { +// TranslateMessage(&msg); +// DispatchMessage(&msg); + // } + + // Watch the (user-editable) count field, and use that to + // determine how many textboxes to show. + char* buf; + strcpy (buf, gtk_entry_get_text (GTK_ENTRY (CountTextbox))); + // SendMessage(CountTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)buf); + if(atoi(buf) != count) { + count = atoi(buf); + if(count < 0 || count > 10) { + count = 0; + gtk_entry_set_text (GTK_ENTRY (CountTextbox), ""); + } + // DestroyLutControls(); + MakeLutControls(FALSE, count*2, TRUE); + } + } + + if(!DialogCancel) { + SendMessage(DestTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->dest)); + SendMessage(IndexTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->index)); + DestroyLutControls(); + // The call to DestroyLutControls updated ValuesCache, so just read + // them out of there. + int i; + for(i = 0; i < count*2; i++) { + t->vals[i] = ValuesCache[i]; + } + t->count = count; + } + + EnableWindow(MainWindow, TRUE); + DestroyWindow(LutDialog); +} -- cgit From f573d931f1777e47e8ad5e5415b7170dfa0af579 Mon Sep 17 00:00:00 2001 From: NatsuDrag9 Date: Thu, 28 Jun 2018 17:27:37 +0530 Subject: Ported lutdialog.cpp --- ldmicro/lib/linuxUI/linuxUI.cpp | 5 +- ldmicro/lutdialog.cpp | 302 +++++++++++++++++++++++++--------------- ldmicro/schematic.cpp | 2 +- 3 files changed, 194 insertions(+), 115 deletions(-) diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index d7248b7..64f7690 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -531,5 +531,8 @@ BOOL KillTimer(HWID hWid, UINT uIDEvent) void DestroyWindow (HWID widget) { - gtk_widget_destroy (widget); + if (GTK_IS_WIDGET(widget)) + { + gtk_widget_destroy (widget); + } } diff --git a/ldmicro/lutdialog.cpp b/ldmicro/lutdialog.cpp index 8c63f3b..e106e31 100644 --- a/ldmicro/lutdialog.cpp +++ b/ldmicro/lutdialog.cpp @@ -58,22 +58,20 @@ static LONG_PTR PrevIndexProc; static LONG_PTR PrevCountProc; static HWID OkButton; static HWID CancelButton; -<<<<<<< HEAD -static int GLOBAL_LUT_DIALOG_TIMER; -static bool destroyCheck; -======= -static UINT LUT_DIALOG_REFRESH_TIMER_ID = 0; ->>>>>>> akshay-c-GUI_port +static UINT LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; +static UINT LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; HWID LutGrid; HWID LutPackingBox; -struct ShowLookUpTableDialogBuffer{ +struct LookUpTableDialogBuffer{ int tmpcount; bool tmpasString; char PrevTableAsString[1024] = ""; } temp; +static int piecewiseTmpCount; + //----------------------------------------------------------------------------- // Don't allow any characters other than 0-9 and minus in the values. //----------------------------------------------------------------------------- @@ -125,6 +123,7 @@ void LutDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, //----------------------------------------------------------------------------- static void MakeFixedControls(BOOL forPwl) { + bool madeCheckbox = FALSE; Labels[0] = gtk_label_new ("Destination"); Labels[1] = gtk_label_new ("Index:"); Labels[2] = forPwl ? gtk_label_new ("Points:") : gtk_label_new ("Count:"); @@ -139,6 +138,7 @@ static void MakeFixedControls(BOOL forPwl) if(!forPwl) { AsStringCheckbox = gtk_check_button_new_with_label ("Edit table of ASCII values like a string"); + madeCheckbox = TRUE; } OkButton = gtk_button_new_with_label ("OK"); @@ -152,7 +152,9 @@ static void MakeFixedControls(BOOL forPwl) gtk_grid_attach (GTK_GRID (LutGrid), CancelButton, 3, 4, 1, 1); gtk_grid_attach (GTK_GRID (LutGrid), Labels[2], 0, 6, 1, 1); gtk_grid_attach (GTK_GRID (LutGrid), CountTextbox, 1, 6, 1, 1); - gtk_grid_attach (GTK_GRID (LutGrid), AsStringCheckbox, 0, 8, 1, 1); + if (madeCheckbox){ + gtk_grid_attach (GTK_GRID (LutGrid), AsStringCheckbox, 0, 8, 1, 1); + } g_signal_connect (G_OBJECT(DestTextbox), "insert-text", G_CALLBACK(LutDialogMyNameProc), NULL); @@ -167,35 +169,59 @@ static void MakeFixedControls(BOOL forPwl) // because if the size of the LUT changes, or if the user switches from // table entry to string entry, we must completely reconfigure the dialog. //----------------------------------------------------------------------------- -static void DestroyLutControls(void) +static void DestroyLutControls(BOOL destroyFlag = TRUE) { - cout << "Inside DestroyLutControls ()" << "\n"; if(WasAsString) { // Nothing to do; we constantly update the cache from the user- // specified string, because we might as well do that when we // calculate the length. } else { - cout << "In DestroyLut WasCount : " << WasCount << "\n"; int i; for(i = 0; i < WasCount; i++) { char buf[20]; - strcpy (buf, gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i]))); + char *tmpB = (char*)gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i])); + strcpy (buf, tmpB); ValuesCache[i] = atoi(buf); } - cout << "Exiting else of WasAsString" << "\n"; } - if (checkString){ - DestroyWindow(StringTextbox); - cout << "Destroyed StringTextbox" << "\n"; + + if (destroyFlag){ + for(int i = 0; i < temp.tmpcount; i++) + { + if (GTK_IS_ENTRY(ValuesTextbox[i])) + { + DestroyWindow(ValuesTextbox[i]); + DestroyWindow(ValuesLabel[i]); + } + } } - int i; - // *** Changed from MAX_LOOK_UP_TABLE_LEN to count ***** // - for(i = 0; i < temp.tmpcount; i++) { - cout << "Destroy ValueTextbox i = " << i << "\n"; - DestroyWindow(ValuesTextbox[i]); - DestroyWindow(ValuesLabel[i]); - cout << "Called DestroyWindow() for ValuesTextbox and ValuesLabels" << "\n"; +} + +static void DestroyLutControlsPiecewise(BOOL destroyFlag = TRUE) +{ + if(WasAsString) { + // Nothing to do; we constantly update the cache from the user- + // specified string, because we might as well do that when we + // calculate the length. + } + else { + int i; + for(i = 0; i < WasCount; i++) { + char buf[20]; + char *tmpB = (char*)gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i])); + strcpy (buf, tmpB); + ValuesCache[i] = atoi(buf); + } + } + + if (destroyFlag) + { + int i; + for(i = 0; i < WasCount; i++) { + DestroyWindow(ValuesTextbox[i]); + DestroyWindow(ValuesLabel[i]); + } } } @@ -210,14 +236,11 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) // Remember these, so that we know from where to cache stuff if we have // to destroy these textboxes and make something new later. WasAsString = asString; - cout << "asString in MakeLutControls : " << asString <<"\n"; WasCount = count; - cout << "Count in MakeLutControls : " << count << "\n"; if(forPwl && asString) oops(); if(asString) { char str[3*MAX_LOOK_UP_TABLE_LEN+1]; - cout << "Inside if (asString) in MakeLutControls" << "\n"; int i, j; j = 0; for(i = 0; i < count; i++) { @@ -249,7 +272,6 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) checkString = TRUE; gtk_widget_show_all (LutGrid); gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), FALSE); - // MoveWindow(StringTextbox, 100, 30, 320, 185, TRUE); // Changed LutDialog to StringTextbox } else { int i; @@ -276,6 +298,7 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) sprintf(buf, "%d", ValuesCache[i]); ValuesTextbox[i] = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (ValuesTextbox[i]), 0); + gtk_entry_set_text (GTK_ENTRY (ValuesTextbox[i]), buf); if(forPwl) { sprintf(buf, "%c%d:", (i & 1) ? 'y' : 'x', i/2); @@ -303,8 +326,6 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) } if(count > 16) count = 16; gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), TRUE); - - // MoveWindow(LutDialog, 100, 30, 320, base + 30 + count*30, TRUE); } } @@ -316,7 +337,6 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) //----------------------------------------------------------------------------- BOOL StringToValuesCache(char *str, int *c) { - // cout << "Inside StringToValuesCache" << "\n"; int count = 0; while(*str) { if(*str == '\\') { @@ -350,9 +370,8 @@ void LookUpTableGetData (gpointer data){ ElemLeaf *l = (ElemLeaf *) data; ElemLookUpTable *t = &(l->d.lookUpTable); strcpy (t->dest, gtk_entry_get_text (GTK_ENTRY (DestTextbox))); - // t->index = const_cast (gtk_entry_get_text (GTK_ENTRY (IndexTextbox))); strcpy (t->index, gtk_entry_get_text (GTK_ENTRY (IndexTextbox))); - // DestroyLutControls(); + DestroyLutControls(FALSE); // The call to DestroyLutControls updated ValuesCache, so just read // them out of there (whichever mode we were in before). @@ -363,10 +382,6 @@ void LookUpTableGetData (gpointer data){ t->count = temp.tmpcount; t->editAsString = temp.tmpasString; gtk_widget_set_sensitive (MainWindow, TRUE); - if (destroyCheck){ - // g_source_remove (GLOBAL_LUT_DIALOG_TIMER); - DestroyWindow (LutDialog); - } } void LookUpTableCheckMode (void){ @@ -378,14 +393,12 @@ void LookUpTableCheckMode (void){ char buf[20]; // buf = const_cast (gtk_entry_get_text (GTK_ENTRY (CountTextbox))); strcpy (buf, gtk_entry_get_text (GTK_ENTRY (CountTextbox))); - g_print("%s\n", buf); if(atoi(buf) != count && !asString) { count = atoi(buf); if(count < 0 || count > 32) { count = 0; gtk_entry_set_text (GTK_ENTRY (CountTextbox), ""); } - cout << "Count in LookUpTableCheckMode : " << count << "\n"; DestroyLutControls(); MakeLutControls(asString, count, FALSE); } @@ -394,8 +407,6 @@ void LookUpTableCheckMode (void){ // and use that to update the (read-only) count field. if(asString) { char scratch[1024]; - // scratch = const_cast (gtk_entry_get_text - // (GTK_ENTRY (StringTextbox))); strcpy (scratch, gtk_entry_get_text (GTK_ENTRY (StringTextbox))); if(strcmp(scratch, temp.PrevTableAsString)!=0) { if(StringToValuesCache(scratch, &count)) { @@ -410,14 +421,27 @@ void LookUpTableCheckMode (void){ } // Did we just change modes? BOOL x = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (AsStringCheckbox)); + checkString = x; if((x && !asString) || (!x && asString)) { - cout << "x is " << x << "\n"; asString = x; if (x == 1){ MakeLutControls(asString, count, FALSE); + + for(int i = 0; i < temp.tmpcount; i++) { + if (GTK_IS_ENTRY(ValuesTextbox[i])) + { + DestroyWindow(ValuesTextbox[i]); + DestroyWindow(ValuesLabel[i]); + } + } } else { DestroyLutControls(); + if (!x && GTK_IS_ENTRY(StringTextbox)) + { + DestroyWindow(StringTextbox); + gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), TRUE); + } } } @@ -427,15 +451,20 @@ void LookUpTableCheckMode (void){ // Checks for the required key press gboolean LookUpTableKeyPress (HWID widget, GdkEventKey* event, gpointer data){ - LookUpTableCheckMode (); + if (event -> keyval == GDK_KEY_Return){ - // destroyCheck = TRUE; + LookUpTableCheckMode (); LookUpTableGetData((gpointer) data); + DestroyWindow (LutDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); + g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1); + LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; } else if (event -> keyval == GDK_KEY_Escape){ - // g_source_remove (GLOBAL_LUT_DIALOG_TIMER); DestroyWindow (LutDialog); gtk_widget_set_sensitive (MainWindow, TRUE); + g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1); + LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; } return FALSE; } @@ -444,19 +473,19 @@ gboolean LookUpTableKeyPress (HWID widget, GdkEventKey* event, gpointer data){ BOOL LutDialogRefresh(gpointer data) { LookUpTableCheckMode (); - LookUpTableGetData(NULL, (gpointer) data); + LookUpTableGetData((gpointer) data); return TRUE; } // Ok button call void LutDialogOk (HWID widget, gpointer data) { LookUpTableCheckMode (); - LookUpTableGetData(NULL, (gpointer) data); + LookUpTableGetData((gpointer) data); DestroyWindow (LutDialog); gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID); - LUT_DIALOG_REFRESH_TIMER_ID = 0; + g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1); + LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; } // Cancel button call @@ -464,8 +493,8 @@ void LutCallCancel (HWID widget, gpointer data) { DestroyWindow (LutDialog); gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID); - LUT_DIALOG_REFRESH_TIMER_ID = 0; + g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1); + LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; } //----------------------------------------------------------------------------- @@ -477,7 +506,6 @@ void LutCallCancel (HWID widget, gpointer data) void ShowLookUpTableDialog(ElemLeaf *l) { ElemLookUpTable *t = &(l->d.lookUpTable); - GdkEventKey* event; // First copy over all the stuff from the leaf structure; in particular, // we need our own local copy of the table entries, because it would be @@ -485,9 +513,7 @@ void ShowLookUpTableDialog(ElemLeaf *l) // might cancel). int count = t->count; - cout << "Initially count is " << count << "\n"; BOOL asString = t->editAsString; - cout << "Initially asString is " << asString << "\n"; memset(ValuesCache, 0, sizeof(ValuesCache)); int i; for(i = 0; i < count; i++) { @@ -529,9 +555,7 @@ void ShowLookUpTableDialog(ElemLeaf *l) gtk_widget_grab_focus(OkButton); temp.tmpcount = count; - cout << "Count in ShowLookUp : " << count << "\n"; temp.tmpasString = asString; - cout << "asString in ShowLookUp : " << asString << "\n"; g_signal_connect (G_OBJECT (LutDialog), "key-press-event", G_CALLBACK(LookUpTableKeyPress), (gpointer)l); @@ -540,8 +564,95 @@ void ShowLookUpTableDialog(ElemLeaf *l) g_signal_connect (G_OBJECT (CancelButton), "clicked", G_CALLBACK(LutCallCancel), NULL); - if (LUT_DIALOG_REFRESH_TIMER_ID == 0) - LUT_DIALOG_REFRESH_TIMER_ID = g_timeout_add(100, (GSourceFunc)LutDialogRefresh, (gpointer)l); + if (LUT_DIALOG_REFRESH_TIMER_ID_1 == 0) + LUT_DIALOG_REFRESH_TIMER_ID_1 = g_timeout_add(100, (GSourceFunc)LutDialogRefresh, (gpointer)l); +} + +// Piecewise Dialog + +void PiecewiseDialogGetData(gpointer data){ + + ElemLeaf *l = (ElemLeaf *) data; + ElemPiecewiseLinear *t = &(l->d.piecewiseLinear); + int count = piecewiseTmpCount; + strcpy (t->dest, gtk_entry_get_text (GTK_ENTRY (DestTextbox))); + strcpy (t->index, gtk_entry_get_text (GTK_ENTRY (IndexTextbox))); + DestroyLutControlsPiecewise(FALSE); + // MakeLutControls(FALSE, count*2, TRUE); + + // The call to DestroyLutControlsPiecewise updated ValuesCache, so just read + // them out of there. + int i; + for(i = 0; i < count*2; i++) { + t->vals[i] = ValuesCache[i]; + } + t->count = count; +} + +void PiecewiseDialogPointTextbox (int count){ + char* buf; + char *tmpBuf = (char*)gtk_entry_get_text (GTK_ENTRY (CountTextbox)); + buf = (char*)malloc(strlen(tmpBuf)); + strcpy (buf, tmpBuf); + if(atoi(buf) != count) { + count = atoi(buf); + if(count < 0 || count > 10) { + count = 0; + gtk_entry_set_text (GTK_ENTRY (CountTextbox), ""); + } + DestroyLutControlsPiecewise(); + MakeLutControls(FALSE, count*2, TRUE); + } + piecewiseTmpCount = count; +} + +/// Dialog refresh function +BOOL PiecewiseDialogRefresh(gpointer data) +{ + PiecewiseDialogPointTextbox (piecewiseTmpCount); + PiecewiseDialogGetData((gpointer) data); + return TRUE; +} + +// Ok button call +void PiecewiseDialogOk (HWID widget, gpointer data) +{ + PiecewiseDialogPointTextbox (piecewiseTmpCount); + PiecewiseDialogGetData((gpointer) data); + + DestroyWindow (LutDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); + g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2); + LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; +} + +// Checks for the required key press +gboolean PiecewiseDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data){ + + if (event -> keyval == GDK_KEY_Return){ + PiecewiseDialogPointTextbox (piecewiseTmpCount); + PiecewiseDialogGetData((gpointer) data); + DestroyWindow (LutDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); + g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2); + LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; + } + else if (event -> keyval == GDK_KEY_Escape){ + DestroyWindow (LutDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); + g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2); + LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; + } + return FALSE; +} + +// Cancel button call +void PiecewiseCallCancel (HWID widget, gpointer data) +{ + DestroyWindow (LutDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); + g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2); + LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; } //----------------------------------------------------------------------------- @@ -566,11 +677,18 @@ void ShowPiecewiseLinearDialog(ElemLeaf *l) // Now create the dialog's fixed controls, plus the changing (depending // on show style/entry count) controls for the initial configuration. - LutDialog = gtk_dialog_new_with_buttons ("Piecewise Linear Table", GTK_WINDOW (MainWindow), - GTK_DIALOG_MODAL, "Ok", GTK_RESPONSE_ACCEPT, - "Cancel", GTK_RESPONSE_REJECT, NULL); + LutGrid = gtk_grid_new(); + LutPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + LutDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(LutDialog), "Piecewise Linear Table"); + gtk_window_set_default_size(GTK_WINDOW(LutDialog), 100, 200); + gtk_window_set_resizable (GTK_WINDOW (LutDialog), FALSE); + gtk_box_pack_start(GTK_BOX(LutPackingBox), LutGrid, TRUE, TRUE, 0); + gtk_container_add(GTK_CONTAINER(LutDialog), LutPackingBox); gtk_widget_add_events (LutDialog, GDK_KEY_PRESS_MASK); gtk_widget_add_events (LutDialog, GDK_BUTTON_PRESS_MASK); + MakeFixedControls(TRUE); MakeLutControls(FALSE, count*2, TRUE); @@ -584,59 +702,17 @@ void ShowPiecewiseLinearDialog(ElemLeaf *l) // And show the window gtk_widget_set_sensitive (MainWindow, FALSE); gtk_widget_show_all (LutDialog); - gtk_widget_grab_focus (DestTextbox); -// SendMessage(DestTextbox, EM_SETSEL, 0, -1); - -// MSG msg; -// DWORD ret; -// DialogDone = FALSE; -// DialogCancel = FALSE; - // while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { -// if(msg.message == WM_KEYDOWN) { -// if(msg.wParam == VK_RETURN) { -// DialogDone = TRUE; -// break; -// } else if(msg.wParam == VK_ESCAPE) { -// DialogDone = TRUE; -// DialogCancel = TRUE; -// break; -// } -// } - -// if(!IsDialogMessage(LutDialog, &msg)) { -// TranslateMessage(&msg); -// DispatchMessage(&msg); - // } - - // Watch the (user-editable) count field, and use that to - // determine how many textboxes to show. - char* buf; - strcpy (buf, gtk_entry_get_text (GTK_ENTRY (CountTextbox))); - // SendMessage(CountTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)buf); - if(atoi(buf) != count) { - count = atoi(buf); - if(count < 0 || count > 10) { - count = 0; - gtk_entry_set_text (GTK_ENTRY (CountTextbox), ""); - } - // DestroyLutControls(); - MakeLutControls(FALSE, count*2, TRUE); - } - } + // gtk_widget_grab_focus (DestTextbox); - if(!DialogCancel) { - SendMessage(DestTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->dest)); - SendMessage(IndexTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->index)); - DestroyLutControls(); - // The call to DestroyLutControls updated ValuesCache, so just read - // them out of there. - int i; - for(i = 0; i < count*2; i++) { - t->vals[i] = ValuesCache[i]; - } - t->count = count; - } + piecewiseTmpCount = count; + + g_signal_connect (G_OBJECT (LutDialog), "key-press-event", + G_CALLBACK(PiecewiseDialogKeyPress), (gpointer)l); + g_signal_connect (G_OBJECT (OkButton), "clicked", + G_CALLBACK(PiecewiseDialogOk), (gpointer)l); + g_signal_connect (G_OBJECT (CancelButton), "clicked", + G_CALLBACK(PiecewiseCallCancel), NULL); - EnableWindow(MainWindow, TRUE); - DestroyWindow(LutDialog); + if (LUT_DIALOG_REFRESH_TIMER_ID_2 == 0) + LUT_DIALOG_REFRESH_TIMER_ID_2 = g_timeout_add(100, (GSourceFunc)PiecewiseDialogRefresh, (gpointer)l); } diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index 728a588..8a6fa04 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -488,7 +488,7 @@ void EditSelectedElement(void) break; case ELEM_PIECEWISE_LINEAR: - // ShowPiecewiseLinearDialog(Selected); + ShowPiecewiseLinearDialog(Selected); break; case ELEM_LOOK_UP_TABLE: -- cgit