summaryrefslogtreecommitdiff
path: root/ldmicro
diff options
context:
space:
mode:
authorRr422018-06-25 14:02:19 +0530
committerRr422018-06-25 14:02:19 +0530
commitac8a6d77801b438a298f537969ed1bd2f60e9458 (patch)
treeae76e8e0e397d476e2b7c6a04733923f1aca7844 /ldmicro
parent64c5d19d9febf624c6e5e7f586b781ee66097761 (diff)
downloadLDMicroGtk-ac8a6d77801b438a298f537969ed1bd2f60e9458.tar.gz
LDMicroGtk-ac8a6d77801b438a298f537969ed1bd2f60e9458.tar.bz2
LDMicroGtk-ac8a6d77801b438a298f537969ed1bd2f60e9458.zip
Added functionality to update IoList table under the paint window.
Diffstat (limited to 'ldmicro')
-rw-r--r--ldmicro/iolist.cpp252
-rw-r--r--ldmicro/ldmicro.cpp66
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h45
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h26
-rw-r--r--ldmicro/maincontrols.cpp11
-rw-r--r--ldmicro/simulate.cpp50
6 files changed, 268 insertions, 182 deletions
diff --git a/ldmicro/iolist.cpp b/ldmicro/iolist.cpp
index ca24042..d06b7a6 100644
--- a/ldmicro/iolist.cpp
+++ b/ldmicro/iolist.cpp
@@ -551,8 +551,8 @@ void ShowAnalogSliderPopup(char *name)
//-----------------------------------------------------------------------------
// Create our window class; nothing exciting.
//-----------------------------------------------------------------------------
-// static BOOL MakeWindowClass()
-// {
+static BOOL MakeWindowClass()
+{
// WNDCLASSEX wc;
// memset(&wc, 0, sizeof(wc));
// wc.cbSize = sizeof(wc);
@@ -571,10 +571,10 @@ void ShowAnalogSliderPopup(char *name)
// IMAGE_ICON, 16, 16, 0);
// return RegisterClassEx(&wc);
-// }
+}
-// static void MakeControls(void)
-// {
+static void MakeControls(void)
+{
// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Assign:"),
// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
// 6, 1, 80, 17, IoDialog, NULL, Instance, NULL);
@@ -594,10 +594,10 @@ void ShowAnalogSliderPopup(char *name)
// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE,
// 6, 356, 95, 23, IoDialog, NULL, Instance, NULL);
// NiceFont(CancelButton);
-// }
+}
-// void ShowIoDialog(int item)
-// {
+void ShowIoDialog(int item)
+{
// if(!Prog.mcu) {
// MessageBox(MainWindow,
// _("No microcontroller has been selected. You must select a "
@@ -759,7 +759,7 @@ void ShowAnalogSliderPopup(char *name)
// EnableWindow(MainWindow, TRUE);
// DestroyWindow(IoDialog);
// return;
-// }
+}
//-----------------------------------------------------------------------------
// Called in response to a notify for the listview. Handles click, text-edit
@@ -767,119 +767,129 @@ void ShowAnalogSliderPopup(char *name)
// where (LPSTR_TEXTCALLBACK); that way we don't have two parallel copies of
// the I/O list to keep in sync.
//-----------------------------------------------------------------------------
-// void IoListProc(NMHDR *h)
-// {
-// switch(h->code) {
-// case LVN_GETDISPINFO: {
-// NMLVDISPINFO *i = (NMLVDISPINFO *)h;
-// int item = i->item.iItem;
-// switch(i->item.iSubItem) {
-// case LV_IO_PIN:
-// // Don't confuse people by displaying bogus pin assignments
-// // for the C target.
-// if(Prog.mcu && (Prog.mcu->whichIsa == ISA_ANSIC ||
-// Prog.mcu->whichIsa == ISA_INTERPRETED) )
-// {
-// strcpy(i->item.pszText, "");
-// break;
-// }
-
-// PinNumberForIo(i->item.pszText,
-// &(Prog.io.assignment[item]));
-// break;
+void IoListProc(NMHDR *h)
+{
+ switch(h->code) {
+ case LVN_GETDISPINFO: {
+
+ int item = h->item.iItem;
+ /// Don't confuse people by displaying bogus pin assignments
+ /// for the C target.
-// case LV_IO_TYPE: {
-// char *s = IoTypeToString(Prog.io.assignment[item].type);
-// strcpy(i->item.pszText, s);
-// break;
-// }
-// case LV_IO_NAME:
-// strcpy(i->item.pszText, Prog.io.assignment[item].name);
-// break;
+ char IO_value_holder[60];
-// case LV_IO_PORT: {
-// // Don't confuse people by displaying bogus pin assignments
-// // for the C target.
-// if(Prog.mcu && Prog.mcu->whichIsa == ISA_ANSIC) {
-// strcpy(i->item.pszText, "");
-// break;
-// }
-
-// int type = Prog.io.assignment[item].type;
-// if(type != IO_TYPE_DIG_INPUT && type != IO_TYPE_DIG_OUTPUT
-// && type != IO_TYPE_READ_ADC)
-// {
-// strcpy(i->item.pszText, "");
-// break;
-// }
-
-// int pin = Prog.io.assignment[item].pin;
-// if(pin == NO_PIN_ASSIGNED || !Prog.mcu) {
-// strcpy(i->item.pszText, "");
-// break;
-// }
-
-// if(UartFunctionUsed() && Prog.mcu) {
-// if((Prog.mcu->uartNeeds.rxPin == pin) ||
-// (Prog.mcu->uartNeeds.txPin == pin))
-// {
-// strcpy(i->item.pszText, _("<UART needs!>"));
-// break;
-// }
-// }
-
-// if(PwmFunctionUsed() && Prog.mcu) {
-// if(Prog.mcu->pwmNeedsPin == pin) {
-// strcpy(i->item.pszText, _("<PWM needs!>"));
-// break;
-// }
-// }
-
-// int j;
-// for(j = 0; j < Prog.mcu->pinCount; j++) {
-// if(Prog.mcu->pinInfo[j].pin == pin) {
-// sprintf(i->item.pszText, "%c%c%d",
-// Prog.mcu->portPrefix,
-// Prog.mcu->pinInfo[j].port,
-// Prog.mcu->pinInfo[j].bit);
-// break;
-// }
-// }
-// if(j == Prog.mcu->pinCount) {
-// sprintf(i->item.pszText, _("<not an I/O!>"));
-// }
-// break;
-// }
+ GValue val = G_VALUE_INIT;
+ g_value_init (&val, G_TYPE_STRING);
-// case LV_IO_STATE: {
-// if(InSimulationMode) {
-// char *name = Prog.io.assignment[item].name;
-// DescribeForIoList(name, i->item.pszText);
-// } else {
-// strcpy(i->item.pszText, "");
-// }
-// break;
-// }
+ /// case LV_IO_PIN:
+ if(Prog.mcu && (Prog.mcu->whichIsa == ISA_ANSIC ||
+ Prog.mcu->whichIsa == ISA_INTERPRETED) )
+ {
+ strcpy(IO_value_holder, "");
-// }
-// break;
-// }
-// case LVN_ITEMACTIVATE: {
-// NMITEMACTIVATE *i = (NMITEMACTIVATE *)h;
-// if(InSimulationMode) {
-// char *name = Prog.io.assignment[i->iItem].name;
-// if(name[0] == 'X') {
-// SimulationToggleContact(name);
-// } else if(name[0] == 'A') {
-// ShowAnalogSliderPopup(name);
-// }
-// } else {
-// UndoRemember();
-// ShowIoDialog(i->iItem);
-// ProgramChanged();
-// InvalidateRect(MainWindow, NULL, FALSE);
-// }
-// break;
-// }
-// }
-// }
+ g_value_set_string(&val, (const char*)&IO_value_holder);
+ gtk_list_store_set_value (GTK_LIST_STORE(h->hlistFrom), h->hlistIter, LV_IO_PIN, &val);
+ }
+ else
+ {
+ PinNumberForIo(IO_value_holder, &(Prog.io.assignment[item]));
+ g_value_set_string(&val, (const char*)&IO_value_holder);
+ gtk_list_store_set_value (GTK_LIST_STORE(h->hlistFrom), h->hlistIter, LV_IO_PIN, &val);
+ }
+
+ /// case LV_IO_TYPE:
+ char *s = IoTypeToString(Prog.io.assignment[item].type);
+
+ g_value_set_string(&val, (const char*)s);
+ gtk_list_store_set_value (GTK_LIST_STORE(h->hlistFrom), h->hlistIter, LV_IO_TYPE, &val);
+
+ /// case LV_IO_NAME:
+ g_value_set_string(&val, (const char*)Prog.io.assignment[item].name);
+ gtk_list_store_set_value (GTK_LIST_STORE(h->hlistFrom), h->hlistIter, LV_IO_NAME, &val);
+
+ /// case LV_IO_PORT:
+ /// Don't confuse people by displaying bogus pin assignments
+ /// for the C target.
+ if(Prog.mcu && Prog.mcu->whichIsa == ISA_ANSIC) {
+ strcpy(IO_value_holder, "");
+ break;
+ }
+
+ int type = Prog.io.assignment[item].type;
+ if(type != IO_TYPE_DIG_INPUT && type != IO_TYPE_DIG_OUTPUT
+ && type != IO_TYPE_READ_ADC)
+ {
+ strcpy(IO_value_holder, "");
+ break;
+ }
+
+ int pin = Prog.io.assignment[item].pin;
+ if(pin == NO_PIN_ASSIGNED || !Prog.mcu) {
+ strcpy(IO_value_holder, "");
+ break;
+ }
+
+ if(UartFunctionUsed() && Prog.mcu) {
+ if((Prog.mcu->uartNeeds.rxPin == pin) ||
+ (Prog.mcu->uartNeeds.txPin == pin))
+ {
+ strcpy(IO_value_holder, _("<UART needs!>"));
+ break;
+ }
+ }
+
+ if(PwmFunctionUsed() && Prog.mcu) {
+ if(Prog.mcu->pwmNeedsPin == pin) {
+ strcpy(IO_value_holder, _("<PWM needs!>"));
+ break;
+ }
+ }
+
+ int j;
+ for(j = 0; j < Prog.mcu->pinCount; j++) {
+ if(Prog.mcu->pinInfo[j].pin == pin) {
+ sprintf(IO_value_holder, "%c%c%d",
+ Prog.mcu->portPrefix,
+ Prog.mcu->pinInfo[j].port,
+ Prog.mcu->pinInfo[j].bit);
+ break;
+ }
+ }
+ if(j == Prog.mcu->pinCount) {
+ sprintf(IO_value_holder, _("<not an I/O!>"));
+ }
+
+ g_value_set_string(&val, (const char*)IO_value_holder);
+ gtk_list_store_set_value (GTK_LIST_STORE(h->hlistFrom), h->hlistIter, LV_IO_PORT, &val);
+
+ /// case LV_IO_STATE:
+ if(InSimulationMode) {
+ char *name = Prog.io.assignment[item].name;
+ DescribeForIoList(name, IO_value_holder);
+ } else {
+ strcpy(IO_value_holder, "");
+ }
+
+ g_value_set_string(&val, (const char*)IO_value_holder);
+ gtk_list_store_set_value (GTK_LIST_STORE(h->hlistFrom), h->hlistIter, LV_IO_STATE, &val);
+
+ break;
+ }
+ case LVN_ITEMACTIVATE: {
+ // if(InSimulationMode) {
+ // char *name = Prog.io.assignment[h->item.iItem].name;
+ // if(name[0] == 'X') {
+ // SimulationToggleContact(name);
+ // } else if(name[0] == 'A') {
+ // ShowAnalogSliderPopup(name);
+ // }
+ // } else {
+ // UndoRemember();
+ // ShowIoDialog(h->item.iItem);
+ // ProgramChanged();
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // }
+ break;
+ }
+ }
+}
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index e975429..e0c2141 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -624,20 +624,12 @@ cmp:
// // case WM_SIZE:
// // case WM_NOTIFY: {
-// // NMHDR *h = (NMHDR *)lParam;
-// // if(h->hwndFrom == IoList) {
-// // IoListProc(h);
-// // }
-// // return 0;
-// // }
+
// // case WM_VSCROLL:
// // case WM_HSCROLL:
// // case WM_COMMAND:
-// // ProcessMenu(LOWORD(wParam));
-// // InvalidateRect(MainWindow, NULL, FALSE);
-// // break;
// // case WM_CLOSE:
// // case WM_DESTROY:
@@ -804,7 +796,7 @@ gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data)
/// This draws the schematic.
MainWindowResized();
PaintWindow(cr);
-
+
return FALSE;
}
@@ -850,6 +842,57 @@ gboolean LD_WM_SetFocus_call(GtkWidget *widget, GdkEvent *event, gpointer user_d
return FALSE;
}
+void LD_WM_Notify_Row_Activate_call(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
+{
+ /* Handles:
+ * WM_NOTIFY
+ */
+
+ g_print("Row activated!\n");
+
+ int *ip = gtk_tree_path_get_indices ( path );
+
+ NMHDR h;
+ h.code = LVN_ITEMACTIVATE;
+ h.item.iItem = ip[0];
+ h.hlistFrom = IoList;
+
+ IoListProc(&h);
+}
+
+void LD_WM_Notify_Cursor_Change_call(GtkTreeView *tree_view, gpointer user_data)
+{
+ /* Handles:
+ * WM_NOTIFY
+ */
+
+ ITLIST iter;
+
+ BOOL empty = !gtk_tree_model_get_iter_first (IoList, &iter);
+ // g_print("empty = %i\n", (empty == TRUE) );
+
+ HLIST pTreeModel;
+ int *ip;
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+ gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
+
+ if(gtk_tree_selection_get_selected (selection, &pTreeModel, &iter))
+ {
+ GtkTreePath *path = gtk_tree_model_get_path ( pTreeModel , &iter ) ;
+ ip = gtk_tree_path_get_indices ( path );
+ }
+ else
+ gtk_tree_model_get_iter_first (IoList, &iter);
+
+ NMHDR h;
+ h.code = LVN_GETDISPINFO;
+ h.item.iItem = (ip == NULL) ? 0 : ip[0];
+ h.hlistFrom = IoList;
+ h.hlistIter = &iter;
+
+ IoListProc(&h);
+}
+
inline void MenuHandler ()
{
g_signal_connect(G_OBJECT(NewMenu), "activate",
@@ -1143,8 +1186,9 @@ int main(int argc, char** argv)
g_signal_connect (DrawWindow, "draw", G_CALLBACK (LD_WM_Paint_call), NULL);
g_signal_connect (MainWindow, "destroy_event", G_CALLBACK (LD_WM_Destroy_call), NULL);
g_signal_connect (MainWindow, "configure_event", G_CALLBACK (LD_WM_Size_call), NULL);
- g_signal_connect (MainWindow, "configure_event", G_CALLBACK (LD_WM_Size_call), NULL);
g_signal_connect (MainWindow, "focus_in_event", G_CALLBACK (LD_WM_SetFocus_call), NULL);
+ g_signal_connect (view, "row_activated", G_CALLBACK (LD_WM_Notify_Row_Activate_call), NULL);
+ g_signal_connect (view, "cursor_changed", G_CALLBACK (LD_WM_Notify_Cursor_Change_call), NULL);
MenuHandler();
/// Keyboard and mouse hooks equivalent to MainWndProc - end
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index 50ffabb..28116b2 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -68,14 +68,16 @@ typedef HANDLE HGDIOBJ;
typedef cairo_t *HCRDC;
typedef GtkWidget *HWID;
-typedef GtkWidget *HMENU;
typedef GtkWindow *HWND;
typedef GtkTreeModel *HLIST;
+typedef GtkTreeIter ITLIST;
typedef GtkApplication *HAPP;
typedef GtkTreeViewColumn *HTVC;
typedef GdkPixbuf *HICON;
typedef GdkRectangle GDRECT;
-typedef GdkRectangle *PGDRECT;
+typedef GDRECT *PGDRECT;
+typedef HWID HMENU;
+typedef ITLIST *HITLIST;
/// Check if system is x64 or x86
#if defined(__UNIX64)
@@ -140,19 +142,38 @@ typedef struct HeapRecordTag{
} HEAPRECORD;
typedef struct tagSCROLLINFO {
- UINT cbSize;
- UINT fMask;
- int nMin;
- int nMax;
- UINT nPage;
- int nPos;
- int nTrackPos;
+ UINT cbSize;
+ UINT fMask;
+ int nMin;
+ int nMax;
+ UINT nPage;
+ int nPos;
+ int nTrackPos;
} SCROLLINFO, *LPCSCROLLINFO;
+typedef struct {
+ UINT mask;
+ int iItem;
+ int iSubItem;
+// UINT state;
+// UINT stateMask;
+ LPTSTR pszText;
+// int cchTextMax;
+// int iImage;
+// LPARAM lParam;
+// int iIndent;
+// int iGroupId;
+// UINT cColumns;
+// PUINT puColumns;
+// int *piColFmt;
+// int iGroup;
+} LVITEM, *LPLVITEM;
+
typedef struct tagNMHDR {
- HWND hwndFrom;
- UINT_PTR idFrom;
- UINT code;
+ HLIST hlistFrom;
+ HITLIST hlistIter;
+ UINT code;
+ LVITEM item;
} NMHDR;
typedef struct FontTag {
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index a1f1547..e970e42 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -34,16 +34,20 @@
#define MB_ICONINFORMATION 0x00000080L
/// Scroll
-#define SB_LINEUP 0x00000001
-#define SB_PAGEUP 0x00000002
-#define SB_LINEDOWN 0x00000004
-#define SB_PAGEDOWN 0x00000008
-#define SB_TOP 0x00000010
-#define SB_BOTTOM 0x00000020
-#define SB_THUMBTRACK 0x00000040
-#define SB_THUMBPOSITION 0x00000040
-
-/// open/save file
+#define SB_LINEUP 0x00000001
+#define SB_PAGEUP 0x00000002
+#define SB_LINEDOWN 0x00000004
+#define SB_PAGEDOWN 0x00000008
+#define SB_TOP 0x00000010
+#define SB_BOTTOM 0x00000020
+#define SB_THUMBTRACK 0x00000040
+#define SB_THUMBPOSITION 0x00000080
+
+/// List view flags
+#define LVN_ITEMACTIVATE 0x00000001
+#define LVN_GETDISPINFO 0x00000002
+
+/// Open/save file
#define OFN_PATHMUSTEXIST 0x00000001L
#define OFN_HIDEREADONLY 0x00000002L
#define OFN_OVERWRITEPROMPT 0x00000004L
@@ -51,7 +55,7 @@
/// PatBlt paint flags
#define PATINVERT 0x00000100L
-/// window brushes
+/// Window brushes
#define BS_SOLID 0x00000001L
#define BS_HOLLOW 0x00000002L
#define BLACK_BRUSH 0x00000004L
diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp
index 4f04a17..ff68860 100644
--- a/ldmicro/maincontrols.cpp
+++ b/ldmicro/maincontrols.cpp
@@ -947,7 +947,7 @@ void RefreshControlsToSettings(void)
{
GtkTreeIter iter;
BOOL path_not_empty = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(IoList), &iter);
- g_print("path e = %i\n", path_not_empty);
+ // g_print("path e = %i\n", path_not_empty);
int * ip;
int i = 0;
@@ -970,9 +970,16 @@ void RefreshControlsToSettings(void)
gtk_list_store_clear (GTK_LIST_STORE(IoList));
+ /// Fill IO List
+ NMHDR h;
+ h.code = LVN_GETDISPINFO;
+ h.hlistFrom = IoList;
+
for(i = 0; i < Prog.io.count; i++) {
gtk_list_store_append (GTK_LIST_STORE(IoList), &iter);
-
+ h.item.iItem = i;
+ h.hlistIter = &iter;
+ IoListProc(&h);
}
if(IoListSelectionPoint >= 0) {
diff --git a/ldmicro/simulate.cpp b/ldmicro/simulate.cpp
index a4a5d1a..1ed0167 100644
--- a/ldmicro/simulate.cpp
+++ b/ldmicro/simulate.cpp
@@ -764,32 +764,32 @@ void ClearSimulationData(void)
// Provide a description for an item (Xcontacts, Ycoil, Rrelay, Ttimer,
// or other) in the I/O list.
//-----------------------------------------------------------------------------
-// void DescribeForIoList(char *name, char *out)
-// {
-// switch(name[0]) {
-// case 'R':
-// case 'X':
-// case 'Y':
-// sprintf(out, "%d", SingleBitOn(name));
-// break;
+void DescribeForIoList(char *name, char *out)
+{
+ switch(name[0]) {
+ case 'R':
+ case 'X':
+ case 'Y':
+ sprintf(out, "%d", SingleBitOn(name));
+ break;
-// case 'T': {
-// double dtms = GetSimulationVariable(name) *
-// (Prog.cycleTime / 1000.0);
-// if(dtms < 1000) {
-// sprintf(out, "%.2f ms", dtms);
-// } else {
-// sprintf(out, "%.3f s", dtms / 1000);
-// }
-// break;
-// }
-// default: {
-// SWORD v = GetSimulationVariable(name);
-// sprintf(out, "%hd (0x%04hx)", v, v);
-// break;
-// }
-// }
-// }
+ case 'T': {
+ double dtms = GetSimulationVariable(name) *
+ (Prog.cycleTime / 1000.0);
+ if(dtms < 1000) {
+ sprintf(out, "%.2f ms", dtms);
+ } else {
+ sprintf(out, "%.3f s", dtms / 1000);
+ }
+ break;
+ }
+ default: {
+ SWORD v = GetSimulationVariable(name);
+ sprintf(out, "%hd (0x%04hx)", v, v);
+ break;
+ }
+ }
+}
//-----------------------------------------------------------------------------
// Toggle the state of a contact input; for simulation purposes, so that we