diff --git a/ldmicro/Makefile b/ldmicro/Makefile index 03d533b..ac44923 100644 --- a/ldmicro/Makefile +++ b/ldmicro/Makefile @@ -1,109 +1,113 @@ -DEFINES = /D_WIN32_WINNT=0x400 /DISOLATION_AWARE_ENABLED /D_WIN32_IE=0x400 /DWIN32_LEAN_AND_MEAN /DWIN32 /D$(D) -CFLAGS = /W3 /nologo -I..\common\win32 /O2 /D_CRT_SECURE_NO_WARNINGS /D_DEBUG /Zi - -HEADERS = ..\common\win32\freeze.h ldmicro.h mcutable.h intcode.h - -OBJDIR = obj - -COMPDIR = components - -FREEZE = $(OBJDIR)\freeze.obj - -LDOBJS = $(OBJDIR)\ldmicro.obj \ - $(OBJDIR)\maincontrols.obj \ - $(OBJDIR)\helpdialog.obj \ - $(OBJDIR)\schematic.obj \ - $(OBJDIR)\draw.obj \ - $(OBJDIR)\draw_outputdev.obj \ - $(OBJDIR)\circuit.obj \ - $(OBJDIR)\undoredo.obj \ - $(OBJDIR)\loadsave.obj \ - $(OBJDIR)\simulate.obj \ - $(OBJDIR)\commentdialog.obj \ - $(OBJDIR)\contactsdialog.obj \ - $(OBJDIR)\coildialog.obj \ - $(OBJDIR)\simpledialog.obj \ - $(OBJDIR)\resetdialog.obj \ - $(OBJDIR)\lutdialog.obj \ - $(OBJDIR)\confdialog.obj \ - $(OBJDIR)\iolist.obj \ - $(OBJDIR)\miscutil.obj \ - $(OBJDIR)\lang.obj \ - $(OBJDIR)\intcode.obj \ - $(OBJDIR)\compilecommon.obj \ - $(OBJDIR)\ansic.obj \ - $(OBJDIR)\interpreted.obj \ - $(OBJDIR)\pic16.obj \ - $(OBJDIR)\avr.obj \ - $(OBJDIR)\arduino.obj \ - $(OBJDIR)\advanceddialog.obj \ - $(OBJDIR)\componentlist.obj \ - $(OBJDIR)\componentimages.obj \ - $(OBJDIR)\naminglist.obj - - -COMPOBJS = $(OBJDIR)\components.obj \ - $(OBJDIR)\switch.obj \ - $(OBJDIR)\relay.obj - - -HELPOBJ = $(OBJDIR)\helptext.obj - -CLEANOBJ = $(OBJDIR)\helptext.cpp \ - $(OBJDIR)\helptext.obj \ - $(OBJDIR)\lang-tables.h \ - $(OBJDIR)\ldmicro.exe \ - $(OBJDIR)\ldmicro.obj \ - $(OBJDIR)\ldmicro.res \ - $(OBJDIR)\freeze.obj \ - $(OBJDIR)\ldinterpret.exe \ - $(OBJDIR)\ldmicro.ilk \ - $(OBJDIR)\ldmicro.pdb \ - ldinterpret.exe \ - ldinterpret.obj \ - ldmicro.exe \ - vc100.pdb \ - reg\results - -LIBS = user32.lib gdi32.lib comctl32.lib advapi32.lib windowscodecs.lib ole32.lib - -all: $(OBJDIR)/ldmicro.exe $(OBJDIR)/ldinterpret.exe - @cp $(OBJDIR)/ldmicro.exe . - @cp $(OBJDIR)/ldinterpret.exe . - @cd reg - @go.bat - @cd .. - -clean: - rm -rf $(LDOBJS) $(COMPOBJS) $(CLEANOBJ) - rmdir reg\results - -lang.cpp: $(OBJDIR)/lang-tables.h - -$(OBJDIR)/lang-tables.h: lang*.txt - perl lang-tables.pl > $(OBJDIR)/lang-tables.h - -$(OBJDIR)/ldinterpret.exe: ldinterpret.c - @$(CC) -Fe$(OBJDIR)/ldinterpret.exe $(LIBS) ldinterpret.c - -$(OBJDIR)/ldmicro.exe: $(LDOBJS) $(COMPOBJS) $(FREEZE) $(HELPOBJ) $(OBJDIR)/ldmicro.res - @$(CC) $(DEFINES) $(CFLAGS) -Fe$(OBJDIR)/ldmicro.exe $(LDOBJS) $(COMPOBJS) $(FREEZE) $(HELPOBJ) $(OBJDIR)/ldmicro.res $(LIBS) - -$(OBJDIR)/ldmicro.res: ldmicro.rc ldmicro.ico - @rc ldmicro.rc - @mv ldmicro.res $(OBJDIR) - -$(LDOBJS): $(@B).cpp $(HEADERS) - @$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj $(@B).cpp - -$(COMPOBJS): $(COMPDIR)/$(@B).cpp $(HEADERS) - @$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj $(COMPDIR)/$(@B).cpp - -$(FREEZE): ..\common\win32\$(@B).cpp $(HEADERS) - @$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj ..\common\win32\$(@B).cpp - -$(HELPOBJ): $(OBJDIR)/helptext.cpp - @$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/helptext.obj $(OBJDIR)/helptext.cpp - -$(OBJDIR)/helptext.cpp: manual.txt manual-*.txt - perl txt2c.pl > $(OBJDIR)/helptext.cpp +DEFINES = /D_WIN32_WINNT=0x400 /DISOLATION_AWARE_ENABLED /D_WIN32_IE=0x400 /DWIN32_LEAN_AND_MEAN /DWIN32 /D$(D) +CFLAGS = /W3 /nologo -I..\common\win32 /O2 /D_CRT_SECURE_NO_WARNINGS /D_DEBUG /Zi + +HEADERS = ..\common\win32\freeze.h ldmicro.h mcutable.h intcode.h + +OBJDIR = obj + +COMPDIR = components + +FREEZE = $(OBJDIR)\freeze.obj + +LDOBJS = $(OBJDIR)\ldmicro.obj \ + $(OBJDIR)\maincontrols.obj \ + $(OBJDIR)\helpdialog.obj \ + $(OBJDIR)\schematic.obj \ + $(OBJDIR)\draw.obj \ + $(OBJDIR)\draw_outputdev.obj \ + $(OBJDIR)\circuit.obj \ + $(OBJDIR)\undoredo.obj \ + $(OBJDIR)\loadsave.obj \ + $(OBJDIR)\simulate.obj \ + $(OBJDIR)\commentdialog.obj \ + $(OBJDIR)\contactsdialog.obj \ + $(OBJDIR)\coildialog.obj \ + $(OBJDIR)\simpledialog.obj \ + $(OBJDIR)\resetdialog.obj \ + $(OBJDIR)\lutdialog.obj \ + $(OBJDIR)\confdialog.obj \ + $(OBJDIR)\iolist.obj \ + $(OBJDIR)\miscutil.obj \ + $(OBJDIR)\lang.obj \ + $(OBJDIR)\intcode.obj \ + $(OBJDIR)\compilecommon.obj \ + $(OBJDIR)\ansic.obj \ + $(OBJDIR)\interpreted.obj \ + $(OBJDIR)\pic16.obj \ + $(OBJDIR)\avr.obj \ + $(OBJDIR)\arduino.obj \ + $(OBJDIR)\advanceddialog.obj \ + $(OBJDIR)\componentlist.obj \ + $(OBJDIR)\componentimages.obj \ + $(OBJDIR)\naminglist.obj + + +COMPOBJS = $(OBJDIR)\components.obj \ + $(OBJDIR)\switch.obj \ + $(OBJDIR)\relay.obj \ + $(OBJDIR)\spdt.obj \ + $(OBJDIR)\dpst.obj \ + $(OBJDIR)\dpdt.obj \ + + + +HELPOBJ = $(OBJDIR)\helptext.obj + +CLEANOBJ = $(OBJDIR)\helptext.cpp \ + $(OBJDIR)\helptext.obj \ + $(OBJDIR)\lang-tables.h \ + $(OBJDIR)\ldmicro.exe \ + $(OBJDIR)\ldmicro.obj \ + $(OBJDIR)\ldmicro.res \ + $(OBJDIR)\freeze.obj \ + $(OBJDIR)\ldinterpret.exe \ + $(OBJDIR)\ldmicro.ilk \ + $(OBJDIR)\ldmicro.pdb \ + ldinterpret.exe \ + ldinterpret.obj \ + ldmicro.exe \ + vc100.pdb \ + reg\results + +LIBS = user32.lib gdi32.lib comctl32.lib advapi32.lib windowscodecs.lib ole32.lib + +all: $(OBJDIR)/ldmicro.exe $(OBJDIR)/ldinterpret.exe + @cp $(OBJDIR)/ldmicro.exe . + @cp $(OBJDIR)/ldinterpret.exe . + @cd reg + @go.bat + @cd .. + +clean: + rm -rf $(LDOBJS) $(COMPOBJS) $(CLEANOBJ) + rmdir reg\results + +lang.cpp: $(OBJDIR)/lang-tables.h + +$(OBJDIR)/lang-tables.h: lang*.txt + perl lang-tables.pl > $(OBJDIR)/lang-tables.h + +$(OBJDIR)/ldinterpret.exe: ldinterpret.c + @$(CC) -Fe$(OBJDIR)/ldinterpret.exe $(LIBS) ldinterpret.c + +$(OBJDIR)/ldmicro.exe: $(LDOBJS) $(COMPOBJS) $(FREEZE) $(HELPOBJ) $(OBJDIR)/ldmicro.res + @$(CC) $(DEFINES) $(CFLAGS) -Fe$(OBJDIR)/ldmicro.exe $(LDOBJS) $(COMPOBJS) $(FREEZE) $(HELPOBJ) $(OBJDIR)/ldmicro.res $(LIBS) + +$(OBJDIR)/ldmicro.res: ldmicro.rc ldmicro.ico + @rc ldmicro.rc + @mv ldmicro.res $(OBJDIR) + +$(LDOBJS): $(@B).cpp $(HEADERS) + @$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj $(@B).cpp + +$(COMPOBJS): $(COMPDIR)/$(@B).cpp $(HEADERS) + @$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj $(COMPDIR)/$(@B).cpp + +$(FREEZE): ..\common\win32\$(@B).cpp $(HEADERS) + @$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj ..\common\win32\$(@B).cpp + +$(HELPOBJ): $(OBJDIR)/helptext.cpp + @$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/helptext.obj $(OBJDIR)/helptext.cpp + +$(OBJDIR)/helptext.cpp: manual.txt manual-*.txt + perl txt2c.pl > $(OBJDIR)/helptext.cpp diff --git a/ldmicro/components/componentfunctions.h b/ldmicro/components/componentfunctions.h index 9da4bfb..34d20d2 100644 --- a/ldmicro/components/componentfunctions.h +++ b/ldmicro/components/componentfunctions.h @@ -1,45 +1,66 @@ -#ifndef _COMPONENT_FUNCTIONS -#define _COMPONENT_FUNCTIONS - -//Few Prerequisites -extern HFONT MyNiceFont; -extern HFONT MyFixedFont; -extern HWND OkButton; -extern HWND CancelButton; -extern HINSTANCE* ComponentInstance; - -extern BOOL DlgDone; -extern BOOL DlgCancel; -extern HWND ComponentDialog; - -// Common Functions - -void FontNice(HWND h); -void FontFixed(HWND h); -HWND* CreateDialogWindow(LPCTSTR title, int x, int y, int width, int height, int style); -void ShowDialogWindow(void); -BOOL ProcessDialogWindow(void); - -/*Initialization Functions*/ -int InitSwitch(void* ComponentAddress); -int InitRelay(void* ComponentAddress); - -/*Event Handlers*/ -void HandleSwitchEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, - void* ImageLocation, UINT ImageId, HWND* h); -void HandleRelayEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, - void* ImageLocation, UINT ImageId, HWND* h); - -/*Request Handlers*/ -double SwitchVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, - double Volt, int Source, void* ImageLocation); -double RelayVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, - double Volt, int Source, void* ImageLocation); - -/*Program Reference Functions*/ -void SetSwitchIds(int*, void*); -void SetRelayIds(int*, void*); - -// Relay Functions - -#endif +#ifndef _COMPONENT_FUNCTIONS +#define _COMPONENT_FUNCTIONS + +//Few Prerequisites +extern HFONT MyNiceFont; +extern HFONT MyFixedFont; +extern HWND OkButton; +extern HWND CancelButton; +extern HINSTANCE* ComponentInstance; + +extern BOOL DlgDone; +extern BOOL DlgCancel; +extern HWND ComponentDialog; + +// Common Functions + +void FontNice(HWND h); +void FontFixed(HWND h); +HWND* CreateDialogWindow(LPCTSTR title, int x, int y, int width, int height, int style); +void ShowDialogWindow(void); +BOOL ProcessDialogWindow(void); + +/*Initialization Functions*/ +int InitSwitch(void* ComponentAddress); +int InitRelay(void* ComponentAddress); +int InitSpdt(void* ComponentAddress); +int InitDpst(void* ComponentAddress); +int InitDpdt(void* ComponentAddress); + + +/*Event Handlers*/ +void HandleSwitchEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h); +void HandleRelayEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h); +void HandleSpdtEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h); +void HandleDpstEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h); +void HandleDpdtEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h); + + +/*Request Handlers*/ +double SwitchVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, + double Volt, int Source, void* ImageLocation); +double RelayVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, + double Volt, int Source, void* ImageLocation); +double SpdtVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, + double Volt, int Source, void* ImageLocation); +double DpstVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, + double Volt, int Source, void* ImageLocation); +double DpdtVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, + double Volt, int Source, void* ImageLocation); + + + +/*Program Reference Functions*/ +void SetSwitchIds(int*, void*); +void SetRelayIds(int*, void*); +void SetSpdtIds(int*, void*); +void SetDpstIds(int*, void*); +void SetDpdtIds(int*, void*); +// Relay Functions + +#endif diff --git a/ldmicro/components/componentimages.h b/ldmicro/components/componentimages.h index 5c71ae6..b3908d1 100644 --- a/ldmicro/components/componentimages.h +++ b/ldmicro/components/componentimages.h @@ -1,39 +1,51 @@ -#ifndef __COMPONENTIMAGES_H -#define __COMPONENTIMAGES_H - -#define SWITCH_CONNECTED 8000 -#define SWITCH_DISCONNECTED 8001 -#define RELAY_NC 8002 -#define RELAY_NO 8003 - -#ifndef RC_INVOKED //Used to hide code from resource file(Guess) - -#define TOTAL_COMPONENTS 2 -#define COMPONENT_NAME_MAX_LENGTH 50 - -// Try to keep ComponentID's between 6000 - 6999 - -#define COMPONENT_SWITCH 6000 -#define COMPONENT_RELAY 6001 - - -#define MAX_PIN_COUNT 10 - -typedef struct ComponentDataTag{ - int Index; - int ComponentId; - TCHAR ComponentName[COMPONENT_NAME_MAX_LENGTH]; - int PinCount; - LPCTSTR PinNames[MAX_PIN_COUNT]; //Valid Number of images from below property -}ComponentData; - -void RefreshImages(); -void SetImage(int Component, void *il); - -static ComponentData rgCompData[TOTAL_COMPONENTS] = { - {0, COMPONENT_SWITCH, TEXT("Switch"), 2, {"Input:", "Output:"}}, - {1, COMPONENT_RELAY, TEXT("Relay"), 5, {"Coil1:", "Coil2:", "NO:", "COM:", "NC:"}} -}; - -#endif -#endif +#ifndef __COMPONENTIMAGES_H +#define __COMPONENTIMAGES_H + +#define SWITCH_CONNECTED 8000 +#define SWITCH_DISCONNECTED 8001 +#define RELAY_NC 8002 +#define RELAY_NO 8003 +#define SPDT_SWITCH_1 8004 +#define SPDT_SWITCH_2 8005 +#define DPST_SWITCH_1 8006 +#define DPST_SWITCH_2 8007 +#define DPDT_SWITCH_1 8008 +#define DPDT_SWITCH_2 8009 + +#ifndef RC_INVOKED //Used to hide code from resource file(Guess) + +#define TOTAL_COMPONENTS 5 +#define COMPONENT_NAME_MAX_LENGTH 50 + +// Try to keep ComponentID's between 6000 - 6999 + +#define COMPONENT_SWITCH 6000 +#define COMPONENT_RELAY 6001 +#define COMPONENT_SPDT 6002 +#define COMPONENT_DPST 6003 +#define COMPONENT_DPDT 6004 + +#define MAX_PIN_COUNT 10 + +typedef struct ComponentDataTag{ + int Index; + int ComponentId; + TCHAR ComponentName[COMPONENT_NAME_MAX_LENGTH]; + int PinCount; + LPCTSTR PinNames[MAX_PIN_COUNT]; //Valid Number of images from below property +}ComponentData; + +void RefreshImages(); +void SetImage(int Component, void *il); + +static ComponentData rgCompData[TOTAL_COMPONENTS] = { + {0, COMPONENT_SWITCH, TEXT("Switch"), 2, {"Input:", "Output:"}}, + {1, COMPONENT_RELAY, TEXT("Relay"), 5, {"Coil1:", "Coil2:", "NO:", "COM:", "NC:"}}, + {2, COMPONENT_SPDT, TEXT("SPDT"), 3, {"Input:", "Output1:", "Output2:"}}, + {3, COMPONENT_DPST, TEXT("DPST"), 4, {"Input1:","Input2:", "Output1:", "Output2:"}}, + {4, COMPONENT_DPDT, TEXT("DPDT"), 6, {"Input1:","Input2:", "Output1:", "Output2:","Output3:","Output4:"}} + +}; + +#endif +#endif diff --git a/ldmicro/components/components.cpp b/ldmicro/components/components.cpp index 7a27823..a527f9b 100644 --- a/ldmicro/components/components.cpp +++ b/ldmicro/components/components.cpp @@ -1,459 +1,510 @@ -#include -#include -#include -#include - -#include "components.h" -#include "componentstructs.h" -#include "componentfunctions.h" -// #include -// #include -// #include -#include "componentimages.h" -#include "../advanceddialog.h" - -//Component Structure -/*To add am entry in Componentlist on right pane, add entry to this structure as follows: -1. Index of the Component -2. ComponentId created in componentimages.h -3. Text to be displayed -4. No. of pins*/ - -HWND ComponentDialog = NULL; -HWND* MainWindowHandle; -static BOOL DlgDone = FALSE; -static BOOL DlgCancel =FALSE; -static HWND Textboxes[MAX_PIN_COUNT]; -static HWND Labels[MAX_PIN_COUNT]; -int *PinIds; - -void ShowNameDialog(int Index, void* PinName, void* ImageId); -void MakeControls(int Index, int Pins); - -void FontNice(HWND h) -{ - SendMessage(h, WM_SETFONT, (WPARAM)MyNiceFont, TRUE); -} -void FontFixed(HWND h) -{ - SendMessage(h, WM_SETFONT, (WPARAM)MyFixedFont, TRUE); -} - -/*Step : return size of memory required for the component to work.*/ -size_t GetStructSize(int ComponentId) -{ - switch(ComponentId){ - case COMPONENT_SWITCH: - return sizeof(SwitchStruct); - break; - case COMPONENT_RELAY: - return sizeof(RelayStruct); - break; - } - return (size_t)-1; -} - -/*Step : Initialize Respective component memory with initial parameters before drawing*/ - -int InitializeComponentProperties(void *ComponentAddress, int ComponentId) -{ - switch(ComponentId){ - case COMPONENT_SWITCH: - return InitSwitch(ComponentAddress); - break; - case COMPONENT_RELAY: - return InitRelay(ComponentAddress); - break; - } - return 0; -} - -// Step : Main Program will Call this function if voltage change event occurs on a pin assigned to a component - -double VoltSet(void* ComponentAddress, BOOL SimulationStarted, int ImageType, int Index, double Volt, - int Source, void* ImageLocation) -{ - - switch(ImageType) - { - case COMPONENT_SWITCH: - return SwitchVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); - break; - case COMPONENT_RELAY: - return RelayVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); - } - return Volt; -} - -void SetPinIds(int Index, void *PinName,int ComponentId, void *ComponentAddress, int Event) -{ - if(Event == EVENT_MOUSE_RCLICK && !SimulationStarted) - { - ShowNameDialog(Index, PinName, ComponentAddress); - switch(ComponentId) - { - case COMPONENT_SWITCH: - SetSwitchIds(PinIds, ComponentAddress); - break; - case COMPONENT_RELAY: - SetRelayIds(PinIds,ComponentAddress); - } - } -} - -/*Step: Handle events to images displayed on the Dialog*/ - -int NotifyComponent(void *ComponentAddress, void *PinName, int ComponentId, - int Event, BOOL SimulationStarted, HWND* h, int Index, UINT ImageId, void* ImageLocation) -{ - MainWindowHandle = h; - SetPinIds(Index, PinName, ComponentId, ComponentAddress, Event); - /*char Debug[256]; - sprintf_s(Debug, "Notify Component Address: %p\n",ComponentAddress); - OutputDebugString(Debug);*/ - switch(ComponentId){ - case COMPONENT_SWITCH: - HandleSwitchEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); - /*char vx[10],vy[10]; - _itoa((int) ComponentAddress,vy,10); - _itoa((int)ImageLocation,vx,10); - MessageBox(NULL, - (vx), (vy), MB_OK | MB_ICONWARNING);*/ - return 0; - break; - case COMPONENT_RELAY: - HandleRelayEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); - // return InitRelay(ComponentAddress); - break; - } - // return voltage - return 0; -} - - -//----------------------------------------------------------------------------- -// Window procedure to handle DialogBox events -//----------------------------------------------------------------------------- -static LRESULT CALLBACK ComponentDialogProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - switch (msg) { - case WM_NOTIFY: - break; - - case WM_COMMAND: { - HWND h = (HWND)lParam; - if(h == OkButton && wParam == BN_CLICKED) { - DlgDone = TRUE; - } else if(h == CancelButton && wParam == BN_CLICKED) { - DlgDone = TRUE; - DlgCancel = TRUE; - } - break; - } - - case WM_CLOSE: - case WM_DESTROY: - DlgDone = TRUE; - DlgCancel = TRUE; - break; - - default: - return DefWindowProc(hwnd, msg, wParam, lParam); - } - - return 1; -} -HWND* CreateDialogWindow(LPCTSTR title, int x, int y, int width, int height, int style) -{ - switch (style) { - case STYLE_VERTICAL: - { - if(height < V_DIALOG_HEIGHT) - { - height = V_DIALOG_HEIGHT; - } - ComponentDialog = CreateWindowEx(0, "ComponentDialog", title, - WS_OVERLAPPED | WS_SYSMENU, x, y, width + V_DIALOG_WIDTH, height, NULL, NULL, - NULL, NULL); - SetWindowPos(ComponentDialog, HWND_TOP, x, y, width + V_DIALOG_WIDTH, height, 0); - - OkButton = CreateWindowEx(0, WC_BUTTON, ("OK"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - (width + 13), 10, 70, 23, ComponentDialog, NULL, NULL, NULL); - FontNice(OkButton); - - CancelButton = CreateWindowEx(0, WC_BUTTON, ("Cancel"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - (width + 13), 40, 70, 23, ComponentDialog, NULL, NULL, NULL); - FontNice(CancelButton); - - return &ComponentDialog; - } - case STYLE_HORIZONTAL: - { - if(width < H_DIALOG_WIDTH) - { - width = H_DIALOG_WIDTH; - } - ComponentDialog = CreateWindowEx(0, "ComponentDialog", title, - WS_OVERLAPPED | WS_SYSMENU, x, y, width, height + H_DIALOG_HEIGHT, NULL, NULL, - NULL, NULL); - SetWindowPos(ComponentDialog, HWND_TOP, x, y, width, height + H_DIALOG_HEIGHT, 0); - - OkButton = CreateWindowEx(0, WC_BUTTON, ("OK"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - 13, (height + 10), 70, 23, ComponentDialog, NULL, NULL, NULL); - FontNice(OkButton); - - CancelButton = CreateWindowEx(0, WC_BUTTON, ("Cancel"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 96, (height + 10), 70, 23, ComponentDialog, NULL, NULL, NULL); - FontNice(CancelButton); - return &ComponentDialog; - } - default: - return NULL; - } - -} -void ShowDialogWindow() -{ - EnableWindow(*MainWindowHandle, FALSE); - ShowWindow(ComponentDialog, SW_SHOW); -} - -BOOL ProcessDialogWindow() -{ - MSG msg; - DWORD ret; - DlgDone = FALSE; - DlgCancel = FALSE; - while((ret = GetMessage(&msg, NULL, 0, 0)) && !DlgDone) { - if(msg.message == WM_KEYDOWN) { - if(msg.wParam == VK_RETURN) { - DlgDone = TRUE; - break; - } else if(msg.wParam == VK_ESCAPE) { - DlgDone = TRUE; - DlgCancel = TRUE; - break; - } - } - - if(IsDialogMessage(ComponentDialog , &msg)) continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - EnableWindow(*MainWindowHandle, TRUE); - /*if(DlgCancel == FALSE) - { - MessageBox(ComponentDialog, - ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); - }*/ - return DlgCancel; -} - -void MakeComponentDialogBoxClass(void) -{ - WNDCLASSEX wc; - memset(&wc, 0, sizeof(wc)); - wc.cbSize = sizeof(wc); - - wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC | - CS_DBLCLKS; - wc.lpfnWndProc = (WNDPROC)ComponentDialogProc; - wc.hInstance = *ComponentInstance; - wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW; - wc.lpszClassName = "ComponentDialog"; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hIcon = (HICON)LoadImage(*ComponentInstance, MAKEINTRESOURCE(4000), //Check This Today - IMAGE_ICON, 32, 32, 0); - wc.hIconSm = (HICON)LoadImage(*ComponentInstance, MAKEINTRESOURCE(4000), - IMAGE_ICON, 16, 16, 0); - - RegisterClassEx(&wc); - - MyNiceFont = CreateFont(16, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FF_DONTCARE, "Tahoma"); - if(!MyNiceFont) - MyNiceFont = (HFONT)GetStockObject(SYSTEM_FONT); - - MyFixedFont = CreateFont(14, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FF_DONTCARE, "Lucida Console"); - if(!MyFixedFont) - MyFixedFont = (HFONT)GetStockObject(SYSTEM_FONT); -} - -void InitComponents() -{ - MyNiceFont = CreateFont(16, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FF_DONTCARE, "Tahoma"); - if(!MyNiceFont) - MyNiceFont = (HFONT)GetStockObject(SYSTEM_FONT); - - MyFixedFont = CreateFont(14, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FF_DONTCARE, "Lucida Console"); - if(!MyFixedFont) - MyFixedFont = (HFONT)GetStockObject(SYSTEM_FONT); - MakeComponentDialogBoxClass(); -} - -size_t GetNameSize(int Index) -{ - int Pins; - Pins = rgCompData[Index].PinCount; - return sizeof(TCHAR) * Pins * MAX_PIN_NAME; -} - - -void MakeControls(int Index, int Pins) -{ - int i; - HDC hdc = GetDC(ComponentDialog); - SelectObject(hdc, MyNiceFont); - SIZE si; - - int maxLen = 0; - for(i = 0; i < Pins; i++) { - // MessageBox(ComponentDialog, - // rgCompData[Index]->PinNames[i], ("Mouse click"), MB_OK | MB_ICONWARNING); - GetTextExtentPoint32(hdc, rgCompData[Index].PinNames[i], - strlen(rgCompData[Index].PinNames[i]), &si); - if(si.cx > maxLen) maxLen = si.cx; - } - int adj; - if(maxLen > 70) { - adj = maxLen - 70; - } else { - adj = 0; - } - for(i = 0; i < Pins; i++) - { - GetTextExtentPoint32(hdc, rgCompData[Index].PinNames[i], - strlen(rgCompData[Index].PinNames[i]), &si); - - Labels[i] = CreateWindowEx(0, WC_STATIC, rgCompData[Index].PinNames[i], - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, - (80 + adj) - si.cx - 4, 13 + i*30, si.cx, 21, - ComponentDialog, NULL, NULL, NULL); - FontNice(Labels[i]); - SendMessage(Textboxes[i], WM_SETTEXT, 0, (LPARAM)rgCompData[Index].PinNames[i]); - - Textboxes[i] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | - WS_VISIBLE, 80 + adj, 12 + 30*i, 120 - adj, 21, - ComponentDialog, NULL, NULL, NULL); - FontFixed(Textboxes[i]); - } - ReleaseDC(ComponentDialog, hdc); -} -void LoadNameDialog(int Pins, void* Loc) -{ - TCHAR* values = (TCHAR*)Loc; - int i; - for (i = 0; i < Pins; ++i) - { - Edit_SetText(Textboxes[i], (LPSTR)(values + (i * MAX_PIN_NAME))); - } -} - -BOOL SaveNameDialog(int Pins, void* Loc, void* ImageId, int ImageType) -{ - TCHAR* values = (TCHAR*)Loc; - int i; - for (i = 0; i < Pins; ++i) - { - int PinId; - char PinValues[MAX_PIN_NAME]; - if (sizeof(TCHAR) == sizeof(char)) // String is non-unicode - strcpy(PinValues, (char*)(values + (i * MAX_PIN_NAME))); - else // String is unicode - wcstombs(PinValues, (wchar_t*)(values + (i * MAX_PIN_NAME)), MAX_PIN_NAME); - Edit_GetText(Textboxes[i], (LPSTR)(values + (i * MAX_PIN_NAME)), MAX_PIN_NAME); - char NewValue[MAX_PIN_NAME]; - if (sizeof(TCHAR) == sizeof(char)) // String is non-unicode - strcpy(NewValue, (char*)(values + (i * MAX_PIN_NAME))); - else // String is unicode - wcstombs(NewValue, (wchar_t*)(values + (i * MAX_PIN_NAME)), MAX_PIN_NAME); - /*char Debug[256]; - sprintf_s(Debug, "SaveNameDialog: %s %s\n",PinValues, NewValue); - OutputDebugString(Debug);*/ - if (lstrcmp(PinValues, NewValue) != 0) - { - /*sprintf_s(Debug, "Deleting: %s %s\n",PinValues, NewValue); - OutputDebugString(Debug);*/ - PinId = DeletePinImage((LPCTSTR)PinValues, ImageId, i); - // DeleteComponentPin(PinId, ImageId); - } - PinId = RegisterPinName((LPCTSTR)NewValue); - if(PinId) - { - PinIds[i] = PinId; - } - SetPinImage(PinId, ImageId, ImageType, i); - // if(PinId) - // { - // AddComponentPin(PinId, ImageId); - // } - } - return TRUE; -} -void ShowNameDialog(int Index, void* PinName, void* ImageId) -{ - HWND *NameDialog; - BOOL Canceled, Complete = FALSE; - int w, h, Pins; - Pins = rgCompData[Index].PinCount; - // char vx[3],vy[3]; - // _itoa(Pins,vy,10); - // _itoa(x,vx,10); - // MessageBox(AdvancedDialog, _(vx), _(vy), MB_OK | MB_ICONWARNING); - // MessageBox(ComponentDialog, - // (vy), ("Mouse click"), MB_OK | MB_ICONWARNING); - // if(Pins >MAX_PIN_COUNT) oops(); - w = 304 - V_DIALOG_WIDTH; - h = 15 + 30 * (Pins + 1); - PinIds = (int*)AllocImageHeap(sizeof(int)*Pins); - NameDialog = CreateDialogWindow("Pin Naming", 100, 100, w, h, STYLE_VERTICAL); - MakeControls(Index, Pins); - LoadNameDialog(Pins, PinName); - ShowDialogWindow(); - SetFocus(Textboxes[0]); - SendMessage(Textboxes[0], EM_SETSEL, 0, -1); - Canceled = ProcessDialogWindow(); - while(Canceled == FALSE) - { - Complete = SaveNameDialog(Pins, PinName, ImageId, rgCompData[Index].ComponentId); - if(Complete == TRUE) - { - // MessageBox(*SwitchDialog, - // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); - break; - }else - { - Complete =TRUE; - Canceled = ProcessDialogWindow(); - } - } - DestroyWindow(*NameDialog); -} - -double VoltRequest(int PinId, void* ComponentAddress) -{ - return GetGlobalVoltage(PinId,ComponentAddress); -} - -// double GlobalVoltChange(int PinId, void *ComponentAddress, double volt) -// { -// return RequestVoltChange(PinId,ComponentAddress,volt); -// } - -double VoltChange(int PinId, int Index, void* ComponentAddress, double Volt) -{ - return RequestVoltChange(PinId, Index, ComponentAddress, Volt); +#include +#include +#include +#include + +#include "components.h" +#include "componentstructs.h" +#include "componentfunctions.h" +// #include +// #include +// #include +#include "componentimages.h" +#include "../advanceddialog.h" + +//Component Structure +/*To add am entry in Componentlist on right pane, add entry to this structure as follows: +1. Index of the Component +2. ComponentId created in componentimages.h +3. Text to be displayed +4. No. of pins*/ + +HWND ComponentDialog = NULL; +HWND* MainWindowHandle; +static BOOL DlgDone = FALSE; +static BOOL DlgCancel =FALSE; +static HWND Textboxes[MAX_PIN_COUNT]; +static HWND Labels[MAX_PIN_COUNT]; +int *PinIds; + +void ShowNameDialog(int Index, void* PinName, void* ImageId); +void MakeControls(int Index, int Pins); + +void FontNice(HWND h) +{ + SendMessage(h, WM_SETFONT, (WPARAM)MyNiceFont, TRUE); +} +void FontFixed(HWND h) +{ + SendMessage(h, WM_SETFONT, (WPARAM)MyFixedFont, TRUE); +} + +/*Step : return size of memory required for the component to work.*/ +size_t GetStructSize(int ComponentId) +{ + switch(ComponentId){ + case COMPONENT_SWITCH: + return sizeof(SwitchStruct); + break; + case COMPONENT_RELAY: + return sizeof(RelayStruct); + break; + case COMPONENT_SPDT: + return sizeof(SpdtStruct); + break; + case COMPONENT_DPST: + return sizeof(DpstStruct); + break; + case COMPONENT_DPDT: + return sizeof(DpdtStruct); + break; + + } + return (size_t)-1; +} + +/*Step : Initialize Respective component memory with initial parameters before drawing*/ + +int InitializeComponentProperties(void *ComponentAddress, int ComponentId) +{ + switch(ComponentId){ + case COMPONENT_SWITCH: + return InitSwitch(ComponentAddress); + break; + case COMPONENT_RELAY: + return InitRelay(ComponentAddress); + break; + case COMPONENT_SPDT: + return InitSpdt(ComponentAddress); + break; + case COMPONENT_DPST: + return InitDpst(ComponentAddress); + break; + case COMPONENT_DPDT: + return InitDpdt(ComponentAddress); + break; + + } + return 0; +} + +// Step : Main Program will Call this function if voltage change event occurs on a pin assigned to a component + +double VoltSet(void* ComponentAddress, BOOL SimulationStarted, int ImageType, int Index, double Volt, + int Source, void* ImageLocation) +{ + + switch(ImageType) + { + case COMPONENT_SWITCH: + return SwitchVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + break; + case COMPONENT_RELAY: + return RelayVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + case COMPONENT_SPDT: + return SpdtVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + case COMPONENT_DPST: + return DpstVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + case COMPONENT_DPDT: + return DpdtVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + + } + return Volt; +} + +void SetPinIds(int Index, void *PinName,int ComponentId, void *ComponentAddress, int Event) +{ + if(Event == EVENT_MOUSE_RCLICK && !SimulationStarted) + { + ShowNameDialog(Index, PinName, ComponentAddress); + switch(ComponentId) + { + case COMPONENT_SWITCH: + SetSwitchIds(PinIds, ComponentAddress); + break; + case COMPONENT_RELAY: + SetRelayIds(PinIds,ComponentAddress); + break; + case COMPONENT_SPDT: + SetSpdtIds(PinIds, ComponentAddress); + break; + case COMPONENT_DPST: + SetDpstIds(PinIds, ComponentAddress); + break; + case COMPONENT_DPDT: + SetDpdtIds(PinIds, ComponentAddress); + break; + + } + } +} + +/*Step: Handle events to images displayed on the Dialog*/ + +int NotifyComponent(void *ComponentAddress, void *PinName, int ComponentId, + int Event, BOOL SimulationStarted, HWND* h, int Index, UINT ImageId, void* ImageLocation) +{ + MainWindowHandle = h; + SetPinIds(Index, PinName, ComponentId, ComponentAddress, Event); + /*char Debug[256]; + sprintf_s(Debug, "Notify Component Address: %p\n",ComponentAddress); + OutputDebugString(Debug);*/ + switch(ComponentId){ + case COMPONENT_SWITCH: + HandleSwitchEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); + /*char vx[10],vy[10]; + _itoa((int) ComponentAddress,vy,10); + _itoa((int)ImageLocation,vx,10); + MessageBox(NULL, + (vx), (vy), MB_OK | MB_ICONWARNING);*/ + return 0; + break; + case COMPONENT_RELAY: + HandleRelayEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); + // return InitRelay(ComponentAddress); + break; + case COMPONENT_SPDT: + HandleSpdtEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); + // return InitRelay(ComponentAddress); + break; + case COMPONENT_DPST: + HandleDpstEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); + // return InitRelay(ComponentAddress); + break; + case COMPONENT_DPDT: + HandleDpdtEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); + // return InitRelay(ComponentAddress); + break; + + } + // return voltage + return 0; +} + + +//----------------------------------------------------------------------------- +// Window procedure to handle DialogBox events +//----------------------------------------------------------------------------- +static LRESULT CALLBACK ComponentDialogProc(HWND hwnd, UINT msg, WPARAM wParam, + LPARAM lParam) +{ + switch (msg) { + case WM_NOTIFY: + break; + + case WM_COMMAND: { + HWND h = (HWND)lParam; + if(h == OkButton && wParam == BN_CLICKED) { + DlgDone = TRUE; + } else if(h == CancelButton && wParam == BN_CLICKED) { + DlgDone = TRUE; + DlgCancel = TRUE; + } + break; + } + + case WM_CLOSE: + case WM_DESTROY: + DlgDone = TRUE; + DlgCancel = TRUE; + break; + + default: + return DefWindowProc(hwnd, msg, wParam, lParam); + } + + return 1; +} +HWND* CreateDialogWindow(LPCTSTR title, int x, int y, int width, int height, int style) +{ + switch (style) { + case STYLE_VERTICAL: + { + if(height < V_DIALOG_HEIGHT) + { + height = V_DIALOG_HEIGHT; + } + ComponentDialog = CreateWindowEx(0, "ComponentDialog", title, + WS_OVERLAPPED | WS_SYSMENU, x, y, width + V_DIALOG_WIDTH, height, NULL, NULL, + NULL, NULL); + SetWindowPos(ComponentDialog, HWND_TOP, x, y, width + V_DIALOG_WIDTH, height, 0); + + OkButton = CreateWindowEx(0, WC_BUTTON, ("OK"), + WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, + (width + 13), 10, 70, 23, ComponentDialog, NULL, NULL, NULL); + FontNice(OkButton); + + CancelButton = CreateWindowEx(0, WC_BUTTON, ("Cancel"), + WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, + (width + 13), 40, 70, 23, ComponentDialog, NULL, NULL, NULL); + FontNice(CancelButton); + + return &ComponentDialog; + } + case STYLE_HORIZONTAL: + { + if(width < H_DIALOG_WIDTH) + { + width = H_DIALOG_WIDTH; + } + ComponentDialog = CreateWindowEx(0, "ComponentDialog", title, + WS_OVERLAPPED | WS_SYSMENU, x, y, width, height + H_DIALOG_HEIGHT, NULL, NULL, + NULL, NULL); + SetWindowPos(ComponentDialog, HWND_TOP, x, y, width, height + H_DIALOG_HEIGHT, 0); + + OkButton = CreateWindowEx(0, WC_BUTTON, ("OK"), + WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, + 13, (height + 10), 70, 23, ComponentDialog, NULL, NULL, NULL); + FontNice(OkButton); + + CancelButton = CreateWindowEx(0, WC_BUTTON, ("Cancel"), + WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, + 96, (height + 10), 70, 23, ComponentDialog, NULL, NULL, NULL); + FontNice(CancelButton); + return &ComponentDialog; + } + default: + return NULL; + } + +} +void ShowDialogWindow() +{ + EnableWindow(*MainWindowHandle, FALSE); + ShowWindow(ComponentDialog, SW_SHOW); +} + +BOOL ProcessDialogWindow() +{ + MSG msg; + DWORD ret; + DlgDone = FALSE; + DlgCancel = FALSE; + while((ret = GetMessage(&msg, NULL, 0, 0)) && !DlgDone) { + if(msg.message == WM_KEYDOWN) { + if(msg.wParam == VK_RETURN) { + DlgDone = TRUE; + break; + } else if(msg.wParam == VK_ESCAPE) { + DlgDone = TRUE; + DlgCancel = TRUE; + break; + } + } + + if(IsDialogMessage(ComponentDialog , &msg)) continue; + TranslateMessage(&msg); + DispatchMessage(&msg); + } + EnableWindow(*MainWindowHandle, TRUE); + /*if(DlgCancel == FALSE) + { + MessageBox(ComponentDialog, + ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); + }*/ + return DlgCancel; +} + +void MakeComponentDialogBoxClass(void) +{ + WNDCLASSEX wc; + memset(&wc, 0, sizeof(wc)); + wc.cbSize = sizeof(wc); + + wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC | + CS_DBLCLKS; + wc.lpfnWndProc = (WNDPROC)ComponentDialogProc; + wc.hInstance = *ComponentInstance; + wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW; + wc.lpszClassName = "ComponentDialog"; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = (HICON)LoadImage(*ComponentInstance, MAKEINTRESOURCE(4000), //Check This Today + IMAGE_ICON, 32, 32, 0); + wc.hIconSm = (HICON)LoadImage(*ComponentInstance, MAKEINTRESOURCE(4000), + IMAGE_ICON, 16, 16, 0); + + RegisterClassEx(&wc); + + MyNiceFont = CreateFont(16, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + FF_DONTCARE, "Tahoma"); + if(!MyNiceFont) + MyNiceFont = (HFONT)GetStockObject(SYSTEM_FONT); + + MyFixedFont = CreateFont(14, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + FF_DONTCARE, "Lucida Console"); + if(!MyFixedFont) + MyFixedFont = (HFONT)GetStockObject(SYSTEM_FONT); +} + +void InitComponents() +{ + MyNiceFont = CreateFont(16, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + FF_DONTCARE, "Tahoma"); + if(!MyNiceFont) + MyNiceFont = (HFONT)GetStockObject(SYSTEM_FONT); + + MyFixedFont = CreateFont(14, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + FF_DONTCARE, "Lucida Console"); + if(!MyFixedFont) + MyFixedFont = (HFONT)GetStockObject(SYSTEM_FONT); + MakeComponentDialogBoxClass(); +} + +size_t GetNameSize(int Index) +{ + int Pins; + Pins = rgCompData[Index].PinCount; + return sizeof(TCHAR) * Pins * MAX_PIN_NAME; +} + + +void MakeControls(int Index, int Pins) +{ + int i; + HDC hdc = GetDC(ComponentDialog); + SelectObject(hdc, MyNiceFont); + SIZE si; + + int maxLen = 0; + for(i = 0; i < Pins; i++) { + // MessageBox(ComponentDialog, + // rgCompData[Index]->PinNames[i], ("Mouse click"), MB_OK | MB_ICONWARNING); + GetTextExtentPoint32(hdc, rgCompData[Index].PinNames[i], + strlen(rgCompData[Index].PinNames[i]), &si); + if(si.cx > maxLen) maxLen = si.cx; + } + int adj; + if(maxLen > 70) { + adj = maxLen - 70; + } else { + adj = 0; + } + for(i = 0; i < Pins; i++) + { + GetTextExtentPoint32(hdc, rgCompData[Index].PinNames[i], + strlen(rgCompData[Index].PinNames[i]), &si); + + Labels[i] = CreateWindowEx(0, WC_STATIC, rgCompData[Index].PinNames[i], + WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, + (80 + adj) - si.cx - 4, 13 + i*30, si.cx, 21, + ComponentDialog, NULL, NULL, NULL); + FontNice(Labels[i]); + SendMessage(Textboxes[i], WM_SETTEXT, 0, (LPARAM)rgCompData[Index].PinNames[i]); + + Textboxes[i] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", + WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | + WS_VISIBLE, 80 + adj, 12 + 30*i, 120 - adj, 21, + ComponentDialog, NULL, NULL, NULL); + FontFixed(Textboxes[i]); + } + ReleaseDC(ComponentDialog, hdc); +} +void LoadNameDialog(int Pins, void* Loc) +{ + TCHAR* values = (TCHAR*)Loc; + int i; + for (i = 0; i < Pins; ++i) + { + Edit_SetText(Textboxes[i], (LPSTR)(values + (i * MAX_PIN_NAME))); + } +} + +BOOL SaveNameDialog(int Pins, void* Loc, void* ImageId, int ImageType) +{ + TCHAR* values = (TCHAR*)Loc; + int i; + for (i = 0; i < Pins; ++i) + { + int PinId; + char PinValues[MAX_PIN_NAME]; + if (sizeof(TCHAR) == sizeof(char)) // String is non-unicode + strcpy(PinValues, (char*)(values + (i * MAX_PIN_NAME))); + else // String is unicode + wcstombs(PinValues, (wchar_t*)(values + (i * MAX_PIN_NAME)), MAX_PIN_NAME); + Edit_GetText(Textboxes[i], (LPSTR)(values + (i * MAX_PIN_NAME)), MAX_PIN_NAME); + char NewValue[MAX_PIN_NAME]; + if (sizeof(TCHAR) == sizeof(char)) // String is non-unicode + strcpy(NewValue, (char*)(values + (i * MAX_PIN_NAME))); + else // String is unicode + wcstombs(NewValue, (wchar_t*)(values + (i * MAX_PIN_NAME)), MAX_PIN_NAME); + /*char Debug[256]; + sprintf_s(Debug, "SaveNameDialog: %s %s\n",PinValues, NewValue); + OutputDebugString(Debug);*/ + if (lstrcmp(PinValues, NewValue) != 0) + { + /*sprintf_s(Debug, "Deleting: %s %s\n",PinValues, NewValue); + OutputDebugString(Debug);*/ + PinId = DeletePinImage((LPCTSTR)PinValues, ImageId, i); + // DeleteComponentPin(PinId, ImageId); + } + PinId = RegisterPinName((LPCTSTR)NewValue); + if(PinId) + { + PinIds[i] = PinId; + } + SetPinImage(PinId, ImageId, ImageType, i); + // if(PinId) + // { + // AddComponentPin(PinId, ImageId); + // } + } + return TRUE; +} +void ShowNameDialog(int Index, void* PinName, void* ImageId) +{ + HWND *NameDialog; + BOOL Canceled, Complete = FALSE; + int w, h, Pins; + Pins = rgCompData[Index].PinCount; + // char vx[3],vy[3]; + // _itoa(Pins,vy,10); + // _itoa(x,vx,10); + // MessageBox(AdvancedDialog, _(vx), _(vy), MB_OK | MB_ICONWARNING); + // MessageBox(ComponentDialog, + // (vy), ("Mouse click"), MB_OK | MB_ICONWARNING); + // if(Pins >MAX_PIN_COUNT) oops(); + w = 304 - V_DIALOG_WIDTH; + h = 15 + 30 * (Pins + 1); + PinIds = (int*)AllocImageHeap(sizeof(int)*Pins); + NameDialog = CreateDialogWindow("Pin Naming", 100, 100, w, h, STYLE_VERTICAL); + MakeControls(Index, Pins); + LoadNameDialog(Pins, PinName); + ShowDialogWindow(); + SetFocus(Textboxes[0]); + SendMessage(Textboxes[0], EM_SETSEL, 0, -1); + Canceled = ProcessDialogWindow(); + while(Canceled == FALSE) + { + Complete = SaveNameDialog(Pins, PinName, ImageId, rgCompData[Index].ComponentId); + if(Complete == TRUE) + { + // MessageBox(*SwitchDialog, + // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); + break; + }else + { + Complete =TRUE; + Canceled = ProcessDialogWindow(); + } + } + DestroyWindow(*NameDialog); +} + +double VoltRequest(int PinId, void* ComponentAddress) +{ + return GetGlobalVoltage(PinId,ComponentAddress); +} + +// double GlobalVoltChange(int PinId, void *ComponentAddress, double volt) +// { +// return RequestVoltChange(PinId,ComponentAddress,volt); +// } + +double VoltChange(int PinId, int Index, void* ComponentAddress, double Volt) +{ + return RequestVoltChange(PinId, Index, ComponentAddress, Volt); } \ No newline at end of file diff --git a/ldmicro/components/components.h b/ldmicro/components/components.h index 810c2d2..6a2965e 100644 --- a/ldmicro/components/components.h +++ b/ldmicro/components/components.h @@ -1,51 +1,51 @@ -#ifndef _COMPONENTS_H -#define _COMPONENTS_H - -#define EVENT_VALUE_CHANGED 0 -#define EVENT_MOUSE_CLICK 1 -#define EVENT_MOUSE_DOWN 2 -#define EVENT_MOUSE_UP 3 -#define EVENT_MOUSE_RDOWN 4 -#define EVENT_MOUSE_RUP 5 -#define EVENT_MOUSE_DBLCLICK 6 -#define EVENT_MOUSE_RCLICK 7 - - - -#define SOURCE_PROGRAM_MAIN 1 -#define SOURCE_PROGRAM_NEW 2 -#define SOURCE_EVENT_MAIN 3 -#define SOURCE_EVENT_NEW 4 -#define SOURCE_FORCE_MAIN 5 -#define SOURCE_REQUEST_MAIN 6 - -/*#define EVENT_KEY_DOWN 6 -#define EVENT_KEY_RELEASE 7 -#define EVENT_KEY_PRESS 8*/ -#define V_DIALOG_WIDTH 96 -#define V_DIALOG_HEIGHT 115 -#define H_DIALOG_WIDTH 179 -#define H_DIALOG_HEIGHT 85 - -//Window styles for dialog box -#define STYLE_HORIZONTAL 1 -#define STYLE_VERTICAL 2 - -#define GND 0 -#define VOLT_5 5 -#define V_OPEN 4196 - -int NotifyComponent(void *ComponentAddress, void* PinName, int ComponentId, int Event, - BOOL SimulationStarted, HWND* h, int Index, UINT ImageId, void* ImageLocation); -int InitializeComponentProperties(void *ComponentAddress, int ComponentId); -double VoltSet(void* ComponentAddress, BOOL SimulationStarted, int ImageType, int Index, - double Volt, int Source, void* ImageLocation); - -double VoltRequest(int PinId, void* ComponentAddress); -// void RequestData(void* ComponentAddress); -// double GlobalVoltChange(int PinId, void *ComponentAddress, double volt); -double VoltChange(int PinId, int Index, void* ComponentAddress, double Volt); -size_t GetStructSize(int ComponentId); -size_t GetNameSize(int ComponentId); - -#endif +#ifndef _COMPONENTS_H +#define _COMPONENTS_H + +#define EVENT_VALUE_CHANGED 0 +#define EVENT_MOUSE_CLICK 1 +#define EVENT_MOUSE_DOWN 2 +#define EVENT_MOUSE_UP 3 +#define EVENT_MOUSE_RDOWN 4 +#define EVENT_MOUSE_RUP 5 +#define EVENT_MOUSE_DBLCLICK 6 +#define EVENT_MOUSE_RCLICK 7 + + + +#define SOURCE_PROGRAM_MAIN 1 +#define SOURCE_PROGRAM_NEW 2 +#define SOURCE_EVENT_MAIN 3 +#define SOURCE_EVENT_NEW 4 +#define SOURCE_FORCE_MAIN 5 +#define SOURCE_REQUEST_MAIN 6 + +/*#define EVENT_KEY_DOWN 6 +#define EVENT_KEY_RELEASE 7 +#define EVENT_KEY_PRESS 8*/ +#define V_DIALOG_WIDTH 96 +#define V_DIALOG_HEIGHT 115 +#define H_DIALOG_WIDTH 179 +#define H_DIALOG_HEIGHT 85 + +//Window styles for dialog box +#define STYLE_HORIZONTAL 1 +#define STYLE_VERTICAL 2 + +#define GND 0 +#define VOLT_5 5 +#define V_OPEN 4196 + +int NotifyComponent(void *ComponentAddress, void* PinName, int ComponentId, int Event, + BOOL SimulationStarted, HWND* h, int Index, UINT ImageId, void* ImageLocation); +int InitializeComponentProperties(void *ComponentAddress, int ComponentId); +double VoltSet(void* ComponentAddress, BOOL SimulationStarted, int ImageType, int Index, + double Volt, int Source, void* ImageLocation); + +double VoltRequest(int PinId, void* ComponentAddress); +// void RequestData(void* ComponentAddress); +// double GlobalVoltChange(int PinId, void *ComponentAddress, double volt); +double VoltChange(int PinId, int Index, void* ComponentAddress, double Volt); +size_t GetStructSize(int ComponentId); +size_t GetNameSize(int ComponentId); + +#endif diff --git a/ldmicro/components/componentstructs.h b/ldmicro/components/componentstructs.h index a7baca5..4cc7aa8 100644 --- a/ldmicro/components/componentstructs.h +++ b/ldmicro/components/componentstructs.h @@ -1,32 +1,66 @@ -#ifndef _COMPONENT_STRUCTS -#define _COMPONENT_STRUCTS - -typedef struct SwitchStructTag -{ - int id; - int Image; - BOOL Latched; //Temporary/Latched Action - BOOL NOpen; //Initial Open/Closed position - BOOL Open; - char Name[15]; - double Volt[2]; - int PinId[2]; -}SwitchStruct; - -typedef struct RelayStructTag -{ - int id; - int Image; - BOOL NC; //Whether relay is operated - double MinOperatingVolt; //Operating voltage - double MaxOperatingVolt; - double CoilVolt1; //Voltage at input pin - double CoilVolt2; //Voltage at input pin - double COMVolt; //Voltage at COM pin - double NOVolt; //Voltage at NO pin - double NCVolt; - int PinId[5]; //Voltage at NC pin - -}RelayStruct; - -#endif +#ifndef _COMPONENT_STRUCTS +#define _COMPONENT_STRUCTS + +typedef struct SwitchStructTag +{ + int id; + int Image; + BOOL Latched; //Temporary/Latched Action + BOOL NOpen; //Initial Open/Closed position + BOOL Open; + char Name[15]; + double Volt[2]; + int PinId[2]; +}SwitchStruct; + +typedef struct RelayStructTag +{ + int id; + int Image; + BOOL NC; //Whether relay is operated + double MinOperatingVolt; //Operating voltage + double MaxOperatingVolt; + double CoilVolt1; //Voltage at input pin + double CoilVolt2; //Voltage at input pin + double COMVolt; //Voltage at COM pin + double NOVolt; //Voltage at NO pin + double NCVolt; + int PinId[5]; //Voltage at NC pin + +}RelayStruct; + +typedef struct SpdtStructTag +{ + int id; + int Image; + BOOL Circuit; //Circuit Position 0 or 1 + char Name[15]; + double Volt[3]; + int PinId[3]; + +}SpdtStruct; + +typedef struct DpstStructTag +{ + int id; + int Image; + BOOL Open; //Switch Position open or closed + char Name[15]; + double Volt[4]; + int PinId[4]; + +}DpstStruct; + +typedef struct DpdtStructTag +{ + int id; + int Image; + BOOL Circuit; //Circuit1 Position 0 or 1 + char Name[15]; + double Volt[6]; + int PinId[6]; + +}DpdtStruct; + + +#endif diff --git a/ldmicro/components/dpdt.cpp b/ldmicro/components/dpdt.cpp new file mode 100644 index 0000000..52f6bec --- /dev/null +++ b/ldmicro/components/dpdt.cpp @@ -0,0 +1,316 @@ +#include +#include +//#include +#include +#include + +#include "componentstructs.h" +#include "componentfunctions.h" +#include "componentimages.h" +#include "components.h" + +static HWND TemporaryRadio; +static HWND Circuit1Radio; +static HWND Circuit2Radio; +static HWND NameTextbox; +HWND* DpdtDialog; + + +void DpdtStateChanged(DpdtStruct* DpdtData, void* ImageLocation); +void MakeDpdtControls() +{ + HWND ActionGrouper = CreateWindowEx(0, WC_BUTTON, ("Default Shorted Condition"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 7, 3, 120, 65, *DpdtDialog, NULL, NULL, NULL); + FontNice(ActionGrouper); + + Circuit1Radio = CreateWindowEx(0, WC_BUTTON, ("Circuit 1"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *DpdtDialog, NULL, NULL, NULL); + FontNice(Circuit1Radio); + + Circuit2Radio = CreateWindowEx(0, WC_BUTTON, ("Circuit 2"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *DpdtDialog, NULL, NULL, NULL); + FontNice(Circuit2Radio); + + HWND textLabel = CreateWindowEx(0, WC_STATIC, ("Name:"), + WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, + 100, 80, 50, 21, *DpdtDialog, NULL, NULL, NULL); + FontNice(textLabel); + + NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT,"", + WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, + 155, 80, 155, 21, *DpdtDialog, NULL, NULL, NULL); + FontFixed(NameTextbox); + + /*PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, + (LONG_PTR)MyNameProc);*/ +} + +void LoadState(DpdtStruct* Data) +{ + if(Data->Circuit) + { + Button_SetCheck(Circuit2Radio, BST_CHECKED); + }else + { + Button_SetCheck(Circuit1Radio, BST_CHECKED); + } +} + + +BOOL SaveDpdtDialog(DpdtStruct* Data) +{ + char temp[15]; + BOOL Circuit; + if(Button_GetState(Circuit1Radio) == BST_CHECKED) + { + Circuit = FALSE; + + }else if(Button_GetState(Circuit2Radio) == BST_CHECKED) + { + Circuit = TRUE; + }else + { + MessageBox(*DpdtDialog, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + } + + if(Edit_GetText(NameTextbox, (LPSTR)&temp, 15) < 1) + { + MessageBox(*DpdtDialog, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + }else + { + Data-> Circuit = Circuit; + strcpy(Data->Name, temp); + if(Circuit) + { + Data->Image =DPDT_SWITCH_2; + } + else + { + Data->Image =DPDT_SWITCH_1; + } + } + return TRUE; +} + +void ShowDpdtDialog(void* ComponentAddress) +{ + DpdtStruct* Data = (DpdtStruct*) ComponentAddress; + BOOL Canceled, Complete = TRUE; + DpdtDialog = CreateDialogWindow("Dpdt Dialog", 100, 100, 263, 145, STYLE_VERTICAL); + MakeDpdtControls(); + ShowDialogWindow(); + LoadState(Data); + Canceled = ProcessDialogWindow(); + while(Canceled == FALSE) + { + Complete = SaveDpdtDialog(Data); + if(Complete == TRUE) + { + // MessageBox(*SwitchDialog, + // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); + break; + }else + { + Complete =TRUE; + Canceled = ProcessDialogWindow(); + } + } + DestroyWindow(*DpdtDialog); +} + + +int InitDpdt(void* ComponentAddress) +{ + DpdtStruct* temp = (DpdtStruct*)ComponentAddress; + temp->Image = DPDT_SWITCH_1; + temp->Circuit = FALSE; + temp->Volt[0] = V_OPEN; + temp->Volt[1] = V_OPEN; + temp->Volt[2] = V_OPEN; + temp->Volt[3] = V_OPEN; + temp->Volt[4] = V_OPEN; + temp->Volt[5] = V_OPEN; + + + return DPDT_SWITCH_1; +} + + +double UpdateDpdtValues(void* ComponentAddress, int i=0) +{ + /*char Debug[256]; + sprintf_s(Debug, "Clicked: %p\n", ComponentAddress); + OutputDebugString(Debug);*/ + DpdtStruct* Switch = (DpdtStruct*)ComponentAddress; + + if(Switch->Circuit) + { + Switch->Volt[2] = + VoltChange(Switch->PinId[2], 2, ComponentAddress, V_OPEN); + Switch->Volt[4] = + VoltChange(Switch->PinId[4], 4, ComponentAddress, V_OPEN); + + double Voltage; + Voltage = VoltRequest(Switch->PinId[0], ComponentAddress); + Switch->Volt[0] = Voltage; + Voltage = VoltRequest(Switch->PinId[1], ComponentAddress); + Switch->Volt[1] = Voltage; + + Voltage = VoltRequest(Switch->PinId[3], ComponentAddress); + Switch->Volt[3] = Voltage; + Voltage = VoltRequest(Switch->PinId[5], ComponentAddress); + Switch->Volt[5] = Voltage; + + + if(Switch->Volt[0]==GND || Switch->Volt[3]==GND) + { + Switch->Volt[3]=VoltChange(Switch->PinId[3], 3, ComponentAddress, GND); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,GND); + } + else + { + double tempvolt=max(VoltRequest(Switch->PinId[0], ComponentAddress),VoltRequest(Switch->PinId[3], ComponentAddress)); + Switch->Volt[3]=VoltChange(Switch->PinId[3],3,ComponentAddress,tempvolt); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,tempvolt); + } + if(Switch->Volt[1]==GND || Switch->Volt[5]==GND) + { + Switch->Volt[5]=VoltChange(Switch->PinId[5], 5, ComponentAddress, GND); + Switch->Volt[1]=VoltChange(Switch->PinId[1],1,ComponentAddress,GND); + } + else + { + double tempvolt=max(VoltRequest(Switch->PinId[1], ComponentAddress),VoltRequest(Switch->PinId[5], ComponentAddress)); + Switch->Volt[5]=VoltChange(Switch->PinId[5],5,ComponentAddress,tempvolt); + Switch->Volt[1]=VoltChange(Switch->PinId[1],1,ComponentAddress,tempvolt); + } + + } + + + else + { + Switch->Volt[3] = + VoltChange(Switch->PinId[3], 3, ComponentAddress, V_OPEN); + Switch->Volt[5] = + VoltChange(Switch->PinId[5], 5, ComponentAddress, V_OPEN); + + double Voltage; + Voltage = VoltRequest(Switch->PinId[0], ComponentAddress); + Switch->Volt[0] = Voltage; + Voltage = VoltRequest(Switch->PinId[1], ComponentAddress); + Switch->Volt[1] = Voltage; + + Voltage = VoltRequest(Switch->PinId[2], ComponentAddress); + Switch->Volt[2] = Voltage; + Voltage = VoltRequest(Switch->PinId[4], ComponentAddress); + Switch->Volt[4] = Voltage; + + + if(Switch->Volt[0]==GND || Switch->Volt[2]==GND) + { + Switch->Volt[2]=VoltChange(Switch->PinId[2], 2, ComponentAddress, GND); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,GND); + } + else + { + double tempvolt=max(VoltRequest(Switch->PinId[0], ComponentAddress),VoltRequest(Switch->PinId[2], ComponentAddress)); + Switch->Volt[2]=VoltChange(Switch->PinId[2],2,ComponentAddress,tempvolt); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,tempvolt); + } + if(Switch->Volt[1]==GND || Switch->Volt[4]==GND) + { + Switch->Volt[4]=VoltChange(Switch->PinId[4], 4, ComponentAddress, GND); + Switch->Volt[1]=VoltChange(Switch->PinId[1],1,ComponentAddress,GND); + } + else + { + double tempvolt=max(VoltRequest(Switch->PinId[1], ComponentAddress),VoltRequest(Switch->PinId[4], ComponentAddress)); + Switch->Volt[4]=VoltChange(Switch->PinId[4],4,ComponentAddress,tempvolt); + Switch->Volt[1]=VoltChange(Switch->PinId[1],1,ComponentAddress,tempvolt); + } + + } + return Switch->Volt[i]; +} + + +void HandleDpdtEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h) +{ + DpdtStruct* temp = (DpdtStruct*)ComponentAddress; + + if(SimulationStarted) + { + switch(Event) + { + case EVENT_MOUSE_CLICK: + DpdtStateChanged(temp,ImageLocation); + UpdateDpdtValues(ComponentAddress); + break; + default: + break; + } + + } + else + { + switch(Event){ + case EVENT_MOUSE_DBLCLICK: + ShowDpdtDialog(ComponentAddress); + SetImage(temp->Image, ImageLocation); + RefreshImages(); + break; + default: + break; + } + } +} + +void DpdtStateChanged(DpdtStruct* DpdtData, void* ImageLocation) +{ + SetImage(DpdtData->Circuit ? DPDT_SWITCH_2 : DPDT_SWITCH_1, + ImageLocation); + RefreshImages(); +} + +double DpdtVoltChanged(void* DpdtData, BOOL SimulationStarted, int Index, + double Volt, int Source, void* ImageLocation) +{ + + // char Debug[256]; + DpdtStruct* temp = (DpdtStruct*)DpdtData; + if(SimulationStarted) + return UpdateDpdtValues(DpdtData,Index); + return Volt; +} + + +void SetDpdtIds(int* id,void* ComponentAddress) +{ + DpdtStruct* s = (DpdtStruct*)ComponentAddress; + s->PinId[0] = *id++; + s->PinId[1] = *id++; + s->PinId[2] = *id++; + s->PinId[3] = *id++; + s->PinId[4] = *id++; + s->PinId[5] = *id++; + + /*char Debug[256]; + sprintf_s(Debug, "SetSwitchIds: \tAddr1: %p \tAddr2: %p \tPin0:%d \t Pin1:%d \tVolt0: %f Volt1: %f\n", + ComponentAddress, s, s->PinId[0], s->PinId[1],VoltRequest(s->PinId[0], ComponentAddress), + VoltRequest(s->PinId[0], ComponentAddress)); + OutputDebugString(Debug); + char vx[4],vy[4]; + _itoa(s->PinId[0],vy,10); + _itoa(s->PinId[1],vx,10); + MessageBox(NULL, + (vy), (vx), MB_OK | MB_ICONWARNING);*/ +} diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp new file mode 100644 index 0000000..3de22b9 --- /dev/null +++ b/ldmicro/components/dpst.cpp @@ -0,0 +1,272 @@ +#include +#include +//#include +#include +#include + +#include "componentstructs.h" +#include "componentfunctions.h" +#include "componentimages.h" +#include "components.h" + +static HWND TemporaryRadio; +static HWND OpenRadio; +static HWND ClosedRadio; +static HWND NameTextbox; +HWND* DpstDialog; + + +void DpstStateChanged(DpstStruct* DpstData, void* ImageLocation); +void MakeDpstControls() +{ + HWND ActionGrouper = CreateWindowEx(0, WC_BUTTON, ("Default State"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 7, 3, 120, 65, *DpstDialog, NULL, NULL, NULL); + FontNice(ActionGrouper); + + OpenRadio = CreateWindowEx(0, WC_BUTTON, ("Open"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *DpstDialog, NULL, NULL, NULL); + FontNice(OpenRadio); + + ClosedRadio = CreateWindowEx(0, WC_BUTTON, ("Closed"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *DpstDialog, NULL, NULL, NULL); + FontNice(ClosedRadio); + + HWND textLabel = CreateWindowEx(0, WC_STATIC, ("Name:"), + WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, + 100, 80, 50, 21, *DpstDialog, NULL, NULL, NULL); + FontNice(textLabel); + + NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT,"", + WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, + 155, 80, 155, 21, *DpstDialog, NULL, NULL, NULL); + FontFixed(NameTextbox); + + /*PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, + (LONG_PTR)MyNameProc);*/ +} + +void LoadState(DpstStruct* Data) +{ + if(Data->Open) + { + Button_SetCheck(OpenRadio, BST_CHECKED); + }else + { + Button_SetCheck(ClosedRadio, BST_CHECKED); + } +} + + +BOOL SaveDpstDialog(DpstStruct* Data) +{ + char temp[15]; + BOOL Open; + if(Button_GetState(OpenRadio) == BST_CHECKED) + { + Open = TRUE; + + }else if(Button_GetState(ClosedRadio) == BST_CHECKED) + { + Open = FALSE; + }else + { + MessageBox(*DpstDialog, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + } + + if(Edit_GetText(NameTextbox, (LPSTR)&temp, 15) < 1) + { + MessageBox(*DpstDialog, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + }else + { + Data-> Open = Open; + strcpy(Data->Name, temp); + if(Open) + { + Data->Image =DPST_SWITCH_2; + } + else + { + Data->Image =DPST_SWITCH_1; + } + } + return TRUE; +} + +void ShowDpstDialog(void* ComponentAddress) +{ + DpstStruct* Data = (DpstStruct*) ComponentAddress; + BOOL Canceled, Complete = TRUE; + DpstDialog = CreateDialogWindow("Dpst Dialog", 100, 100, 263, 145, STYLE_VERTICAL); + MakeDpstControls(); + ShowDialogWindow(); + LoadState(Data); + Canceled = ProcessDialogWindow(); + while(Canceled == FALSE) + { + Complete = SaveDpstDialog(Data); + if(Complete == TRUE) + { + // MessageBox(*SwitchDialog, + // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); + break; + }else + { + Complete =TRUE; + Canceled = ProcessDialogWindow(); + } + } + DestroyWindow(*DpstDialog); +} + + +int InitDpst(void* ComponentAddress) +{ + DpstStruct* temp = (DpstStruct*)ComponentAddress; + temp->Image = DPST_SWITCH_2; + temp->Open = TRUE; + temp->Volt[0] = V_OPEN; + temp->Volt[1] = V_OPEN; + temp->Volt[2] = V_OPEN; + temp->Volt[3] = V_OPEN; + return DPST_SWITCH_2; +} + + +double UpdateValuesDpst(void* ComponentAddress, int i=0) +{ + /*char Debug[256]; + sprintf_s(Debug, "Clicked: %p\n", ComponentAddress); + OutputDebugString(Debug);*/ + DpstStruct* Switch = (DpstStruct*)ComponentAddress; + + if(Switch->Open) + { + Switch->Volt[0] = + VoltChange(Switch->PinId[0], 0, ComponentAddress, V_OPEN); + Switch->Volt[1] = + VoltChange(Switch->PinId[1], 1, ComponentAddress, V_OPEN); + Switch->Volt[2] = + VoltChange(Switch->PinId[2], 2, ComponentAddress, V_OPEN); + Switch->Volt[3] = + VoltChange(Switch->PinId[3], 3, ComponentAddress, V_OPEN); + } + + else + { + + double Voltage; + Voltage = VoltRequest(Switch->PinId[0], Switch); + Switch->Volt[0] = Voltage; + Voltage = VoltRequest(Switch->PinId[1], Switch); + Switch->Volt[1] = Voltage; + Voltage = VoltRequest(Switch->PinId[2], Switch); + Switch->Volt[2] = Voltage; + Voltage = VoltRequest(Switch->PinId[3], Switch); + Switch->Volt[3] = Voltage; + + + if(Switch->Volt[0]==GND || Switch->Volt[2]==GND) + { + Switch->Volt[2]=VoltChange(Switch->PinId[2], 2, ComponentAddress, GND); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,GND); + } + else + { + double tempvolt=max(VoltRequest(Switch->PinId[0], ComponentAddress),VoltRequest(Switch->PinId[2], ComponentAddress)); + Switch->Volt[2]=VoltChange(Switch->PinId[2],2,ComponentAddress,tempvolt); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,tempvolt); + } + + if(Switch->Volt[1]==GND || Switch->Volt[3]==GND) + { + Switch->Volt[1]=VoltChange(Switch->PinId[1], 1, ComponentAddress, GND); + Switch->Volt[3]=VoltChange(Switch->PinId[3],3,ComponentAddress,GND); + } + + else + { + double tempvolt=max(VoltRequest(Switch->PinId[3], ComponentAddress),VoltRequest(Switch->PinId[1], ComponentAddress)); + Switch->Volt[1]=VoltChange(Switch->PinId[1],1,ComponentAddress,tempvolt); + Switch->Volt[3]=VoltChange(Switch->PinId[3],3,ComponentAddress,tempvolt); + } + } + return Switch->Volt[i]; +} + + +void HandleDpstEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h) +{ + DpstStruct* temp = (DpstStruct*)ComponentAddress; + + if(SimulationStarted) + { + switch(Event) + { + case EVENT_MOUSE_CLICK: + DpstStateChanged(temp,ImageLocation); + UpdateValuesDpst(ComponentAddress); + break; + default: + break; + } + + } + else + { + switch(Event){ + case EVENT_MOUSE_DBLCLICK: + ShowDpstDialog(ComponentAddress); + SetImage(temp->Image, ImageLocation); + RefreshImages(); + break; + default: + break; + } + } +} + +void DpstStateChanged(DpstStruct* DpstData, void* ImageLocation) +{ + SetImage(DpstData->Open ? DPST_SWITCH_2 : DPST_SWITCH_1, + ImageLocation); + RefreshImages(); +} + +double DpstVoltChanged(void* DpstData, BOOL SimulationStarted, int Index, + double Volt, int Source, void* ImageLocation) +{ + + // char Debug[256]; + DpstStruct* temp = (DpstStruct*)DpstData; + if(SimulationStarted) + return UpdateValuesDpst(DpstData,Index); + return Volt; +} + + +void SetDpstIds(int* id,void* ComponentAddress) +{ + DpstStruct* s = (DpstStruct*)ComponentAddress; + s->PinId[0] = *id++; + s->PinId[1] = *id++; + s->PinId[2] = *id++; + s->PinId[3] = *id++; + /*char Debug[256]; + sprintf_s(Debug, "SetSwitchIds: \tAddr1: %p \tAddr2: %p \tPin0:%d \t Pin1:%d \tVolt0: %f Volt1: %f\n", + ComponentAddress, s, s->PinId[0], s->PinId[1],VoltRequest(s->PinId[0], ComponentAddress), + VoltRequest(s->PinId[0], ComponentAddress)); + OutputDebugString(Debug); + char vx[4],vy[4]; + _itoa(s->PinId[0],vy,10); + _itoa(s->PinId[1],vx,10); + MessageBox(NULL, + (vy), (vx), MB_OK | MB_ICONWARNING);*/ +} diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp new file mode 100644 index 0000000..9e4115f --- /dev/null +++ b/ldmicro/components/spdt.cpp @@ -0,0 +1,269 @@ +#include +#include +//#include +#include +#include + +#include "componentstructs.h" +#include "componentfunctions.h" +#include "componentimages.h" +#include "components.h" + +static HWND TemporaryRadio; +static HWND Circuit1Radio; +static HWND Circuit2Radio; +static HWND NameTextbox; +HWND* SpdtDialog; + + +void SpdtStateChanged(SpdtStruct* SpdtData, void* ImageLocation); +void MakeSpdtControls() +{ + HWND ActionGrouper = CreateWindowEx(0, WC_BUTTON, ("Default Shorted Circuit"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 7, 3, 120, 65, *SpdtDialog, NULL, NULL, NULL); + FontNice(ActionGrouper); + + Circuit1Radio = CreateWindowEx(0, WC_BUTTON, ("Circuit 1"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *SpdtDialog, NULL, NULL, NULL); + FontNice(Circuit1Radio); + + Circuit2Radio = CreateWindowEx(0, WC_BUTTON, ("Circuit 2"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *SpdtDialog, NULL, NULL, NULL); + FontNice(Circuit2Radio); + + HWND textLabel = CreateWindowEx(0, WC_STATIC, ("Name:"), + WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, + 100, 80, 50, 21, *SpdtDialog, NULL, NULL, NULL); + FontNice(textLabel); + + NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT,"", + WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, + 155, 80, 155, 21, *SpdtDialog, NULL, NULL, NULL); + FontFixed(NameTextbox); + + /*PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, + (LONG_PTR)MyNameProc);*/ +} + +void LoadState(SpdtStruct* Data) +{ + if(Data->Circuit) + { + Button_SetCheck(Circuit2Radio, BST_CHECKED); + }else + { + Button_SetCheck(Circuit1Radio, BST_CHECKED); + } +} + + +BOOL SaveSpdtDialog(SpdtStruct* Data) +{ + char temp[15]; + BOOL Circuit; + if(Button_GetState(Circuit1Radio) == BST_CHECKED) + { + Circuit = FALSE; + + }else if(Button_GetState(Circuit2Radio) == BST_CHECKED) + { + Circuit = TRUE; + }else + { + MessageBox(*SpdtDialog, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + } + + if(Edit_GetText(NameTextbox, (LPSTR)&temp, 15) < 1) + { + MessageBox(*SpdtDialog, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + }else + { + Data-> Circuit = Circuit; + strcpy(Data->Name, temp); + if(Circuit) + { + Data->Image =SPDT_SWITCH_2; + } + else + { + Data->Image =SPDT_SWITCH_1; + } + } + return TRUE; +} + +void ShowSpdtDialog(void* ComponentAddress) +{ + SpdtStruct* Data = (SpdtStruct*) ComponentAddress; + BOOL Canceled, Complete = TRUE; + SpdtDialog = CreateDialogWindow("Spdt Dialog", 100, 100, 263, 145, STYLE_VERTICAL); + MakeSpdtControls(); + ShowDialogWindow(); + LoadState(Data); + Canceled = ProcessDialogWindow(); + while(Canceled == FALSE) + { + Complete = SaveSpdtDialog(Data); + if(Complete == TRUE) + { + // MessageBox(*SwitchDialog, + // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); + break; + }else + { + Complete =TRUE; + Canceled = ProcessDialogWindow(); + } + } + DestroyWindow(*SpdtDialog); +} + + +int InitSpdt(void* ComponentAddress) +{ + SpdtStruct* temp = (SpdtStruct*)ComponentAddress; + temp->Image = SPDT_SWITCH_1; + temp->Circuit = FALSE; + temp->Volt[0] = V_OPEN; + temp->Volt[1] = V_OPEN; + temp->Volt[2] = V_OPEN; + + return SPDT_SWITCH_1; +} + + +double UpdateValues(void* ComponentAddress, int i=0) +{ + /*char Debug[256]; + sprintf_s(Debug, "Clicked: %p\n", ComponentAddress); + OutputDebugString(Debug);*/ + SpdtStruct* Switch = (SpdtStruct*)ComponentAddress; + + if(Switch->Circuit) + { + Switch->Volt[1] = + VoltChange(Switch->PinId[1], 1, ComponentAddress, V_OPEN); + + double Voltage; + Voltage = VoltRequest(Switch->PinId[0], ComponentAddress); + Switch->Volt[0] = Voltage; + Voltage = VoltRequest(Switch->PinId[2], ComponentAddress); + Switch->Volt[2] = Voltage; + + + if(Switch->Volt[0]==GND || Switch->Volt[2]==GND) + { + Switch->Volt[2]=VoltChange(Switch->PinId[2], 2, ComponentAddress, GND); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,GND); + } + else + { + double tempvolt=max(VoltRequest(Switch->PinId[0], ComponentAddress),VoltRequest(Switch->PinId[2], ComponentAddress)); + Switch->Volt[2]=VoltChange(Switch->PinId[2],2,ComponentAddress,tempvolt); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,tempvolt); + } + } + + else + { + Switch->Volt[2] = + VoltChange(Switch->PinId[2], 2, Switch, V_OPEN); + + double Voltage; + Voltage = VoltRequest(Switch->PinId[0], Switch); + Switch->Volt[0] = Voltage; + Voltage = VoltRequest(Switch->PinId[1], Switch); + Switch->Volt[1] = Voltage; + + + if(Switch->Volt[0]==GND || Switch->Volt[1]==GND) + { + Switch->Volt[1]=VoltChange(Switch->PinId[1], 1, ComponentAddress, GND); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,GND); + } + else + { + double tempvolt=max(VoltRequest(Switch->PinId[0], ComponentAddress),VoltRequest(Switch->PinId[1], ComponentAddress)); + Switch->Volt[1]=VoltChange(Switch->PinId[1],1,ComponentAddress,tempvolt); + Switch->Volt[0]=VoltChange(Switch->PinId[0],0,ComponentAddress,tempvolt); + } + } + return Switch->Volt[i]; +} + + +void HandleSpdtEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h) +{ + SpdtStruct* temp = (SpdtStruct*)ComponentAddress; + + if(SimulationStarted) + { + switch(Event) + { + case EVENT_MOUSE_CLICK: + SpdtStateChanged(temp,ImageLocation); + UpdateValues(ComponentAddress); + break; + default: + break; + } + + } + else + { + switch(Event){ + case EVENT_MOUSE_DBLCLICK: + ShowSpdtDialog(ComponentAddress); + SetImage(temp->Image, ImageLocation); + RefreshImages(); + break; + default: + break; + } + } +} + +void SpdtStateChanged(SpdtStruct* SpdtData, void* ImageLocation) +{ + SetImage(SpdtData->Circuit ? SPDT_SWITCH_2 : SPDT_SWITCH_1, + ImageLocation); + RefreshImages(); +} + +double SpdtVoltChanged(void* SpdtData, BOOL SimulationStarted, int Index, + double Volt, int Source, void* ImageLocation) +{ + + // char Debug[256]; + SpdtStruct* temp = (SpdtStruct*)SpdtData; + if(SimulationStarted) + return UpdateValues(SpdtData,Index); + return Volt; +} + + +void SetSpdtIds(int* id,void* ComponentAddress) +{ + SpdtStruct* s = (SpdtStruct*)ComponentAddress; + s->PinId[0] = *id++; + s->PinId[1] = *id++; + s->PinId[2] = *id++; + /*char Debug[256]; + sprintf_s(Debug, "SetSwitchIds: \tAddr1: %p \tAddr2: %p \tPin0:%d \t Pin1:%d \tVolt0: %f Volt1: %f\n", + ComponentAddress, s, s->PinId[0], s->PinId[1],VoltRequest(s->PinId[0], ComponentAddress), + VoltRequest(s->PinId[0], ComponentAddress)); + OutputDebugString(Debug); + char vx[4],vy[4]; + _itoa(s->PinId[0],vy,10); + _itoa(s->PinId[1],vx,10); + MessageBox(NULL, + (vy), (vx), MB_OK | MB_ICONWARNING);*/ +} diff --git a/ldmicro/ldmicro.rc b/ldmicro/ldmicro.rc index 46c3de1..317f6ed 100644 --- a/ldmicro/ldmicro.rc +++ b/ldmicro/ldmicro.rc @@ -1,13 +1,19 @@ - -// we need a manifest if we want visual styles; put in numbers since somethings a bit screwy -// with my SDK install (I don't think I've got *.rh right) - -#include "components/componentimages.h" - -1 24 "ldmicro.exe.manifest" - -4000 ICON "ldmicro.ico" -RELAY_NC PNG "img\\relay_nc.png" -RELAY_NO PNG "img\\relay_no.png" -SWITCH_CONNECTED PNG "img\\switch_connected.png" -SWITCH_DISCONNECTED PNG "img\\switch_disconnected.png" \ No newline at end of file + +// we need a manifest if we want visual styles; put in numbers since somethings a bit screwy +// with my SDK install (I don't think I've got *.rh right) + +#include "components/componentimages.h" + +1 24 "ldmicro.exe.manifest" + +4000 ICON "ldmicro.ico" +RELAY_NC PNG "img\\relay_nc.png" +RELAY_NO PNG "img\\relay_no.png" +SWITCH_CONNECTED PNG "img\\switch_connected.png" +SWITCH_DISCONNECTED PNG "img\\switch_disconnected.png" +SPDT_SWITCH_1 PNG "img\\spdt_switch_1.png" +SPDT_SWITCH_2 PNG "img\\spdt_switch_2.png" +DPST_SWITCH_1 PNG "img\\dpst_switch_1.png" +DPST_SWITCH_2 PNG "img\\dpst_switch_2.png" +DPDT_SWITCH_1 PNG "img\\dpdt_switch_2.png" +DPDT_SWITCH_2 PNG "img\\dpdt_switch_1.png" \ No newline at end of file