diff options
Diffstat (limited to 'ldmicro/components')
-rw-r--r-- | ldmicro/components/components.cpp | 506 | ||||
-rw-r--r-- | ldmicro/components/dpdt.cpp | 539 | ||||
-rw-r--r-- | ldmicro/components/dpst.cpp | 417 | ||||
-rw-r--r-- | ldmicro/components/relay.cpp | 208 | ||||
-rw-r--r-- | ldmicro/components/spdt.cpp | 390 | ||||
-rw-r--r-- | ldmicro/components/switch.cpp | 355 |
6 files changed, 0 insertions, 2415 deletions
diff --git a/ldmicro/components/components.cpp b/ldmicro/components/components.cpp deleted file mode 100644 index 632f136..0000000 --- a/ldmicro/components/components.cpp +++ /dev/null @@ -1,506 +0,0 @@ -#include <wincodec.h> -#include <commctrl.h> -#include <stdio.h> -#include <Windowsx.h> - -#include "components.h" -#include "componentstructs.h" -#include "componentfunctions.h" -// #include <stdio.h> -// #include <stdlib.h> -// #include <setjmp.h> -#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); - break; - case COMPONENT_SPDT: - return SpdtVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); - break; - case COMPONENT_DPST: - return DpstVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); - break; - case COMPONENT_DPDT: - return DpdtVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); - break; - } - 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); - break; - case COMPONENT_DPST: - HandleDpstEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); - break; - case COMPONENT_DPDT: - HandleDpdtEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); - 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/dpdt.cpp b/ldmicro/components/dpdt.cpp deleted file mode 100644 index c04c901..0000000 --- a/ldmicro/components/dpdt.cpp +++ /dev/null @@ -1,539 +0,0 @@ -/* DPDT component file -* Code version: 2.0 -* Version description: Adds latching functionality to component -* Version steability: -* GUI -> Stable -* Functionality -> No known bugs. -* Bugs: -* 1. - -* -*/ - -///Includes -#include <wincodec.h> -#include <stdio.h> -//#include <string.h> -#include <commctrl.h> -#include <Windowsx.h> - -#include "componentstructs.h" -#include "componentfunctions.h" -#include "componentimages.h" -#include "components.h" - -///Window handles -static HWND DPDTState1; -static HWND DPDTState2; -static HWND ModeLatchedDPDT; -static HWND ModeTempDPDT; -HWND* SettingsDialogDPDT; - -///Global variables -enum DPDT_Pins { in1 = 0, in2, out11, out12, out21, out22 }; - -///Function definitions -int InitDpdt(void * ComponentAddress) -{ - DpdtStruct* d = (DpdtStruct*)ComponentAddress; - d->image = DPDT_1; - d->NS1 = TRUE; - d->latched = TRUE; - d->Volt[in1] = V_OPEN; - d->Volt[in2] = V_OPEN; - d->Volt[out11] = V_OPEN; - d->Volt[out12] = V_OPEN; - d->Volt[out21] = V_OPEN; - d->Volt[out22] = V_OPEN; - - return DPDT_1; -} - -void SetDpdtIds(int* id, void* ComponentAddress) -{ - DpdtStruct* d = (DpdtStruct*)ComponentAddress; - d->PinId[in1] = *id++; - d->PinId[in2] = *id++; - d->PinId[out11] = *id++; - d->PinId[out12] = *id++; - d->PinId[out21] = *id++; - d->PinId[out22] = *id++; -} - -void MakeSettingsDialogDPDT() -{ - ///Switch action mode - HWND InitLatched = CreateWindowEx(0, WC_BUTTON, ("Action mode"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 7, 3, 120, 65, *SettingsDialogDPDT, NULL, NULL, NULL); - FontNice(InitLatched); - - ModeLatchedDPDT = CreateWindowEx(0, WC_BUTTON, ("Latched"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); - FontNice(ModeLatchedDPDT); - - ModeTempDPDT = CreateWindowEx(0, WC_BUTTON, ("Temporary"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); - FontNice(ModeTempDPDT); - - ///Switch initial status - HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output state"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 140, 3, 120, 65, *SettingsDialogDPDT, NULL, NULL, NULL); - FontNice(InitOut); - - DPDTState1 = CreateWindowEx(0, WC_BUTTON, ("State 1"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 149, 21, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); - FontNice(DPDTState1); - - DPDTState2 = CreateWindowEx(0, WC_BUTTON, ("State 2"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 149, 41, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); - FontNice(DPDTState2); -} - -void LoadSettings(DpdtStruct* d) -{ - if (d->latched) - Button_SetCheck(ModeLatchedDPDT, BST_CHECKED); - else - Button_SetCheck(ModeTempDPDT, BST_CHECKED); - if (d->NS1) - Button_SetCheck(DPDTState1, BST_CHECKED); - else - Button_SetCheck(DPDTState2, BST_CHECKED); -} - -BOOL SaveSettings(DpdtStruct* d, void* ImageLocation) -{ - if (Button_GetState(ModeLatchedDPDT) == BST_CHECKED) - d->latched = TRUE; - else - d->latched = FALSE; - - if (Button_GetState(DPDTState1) == BST_CHECKED) - d->NS1 = TRUE; - else if (Button_GetState(DPDTState2) == BST_CHECKED) - d->NS1 = FALSE; - else - { - MessageBox(*SettingsDialogDPDT, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - } - - if (d->NS1) - d->image = DPDT_1; - else - d->image = DPDT_2; - - SetImage(d->image, ImageLocation); - RefreshImages(); - - return TRUE; -} - -void DpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) -{ - DpdtStruct* d = (DpdtStruct*)ComponentAddress; - BOOL exitStatus; - - //Create dialog window instance - SettingsDialogDPDT = CreateDialogWindow("SPDT Settings Dialog", 100, 100, 263, 145, STYLE_VERTICAL); - - //Make the settings dialog - MakeSettingsDialogDPDT(); - - //Load settings - LoadSettings(d); - - //Show dialog window - ShowDialogWindow(); - - exitStatus = ProcessDialogWindow(); - while (exitStatus == FALSE) - { - exitStatus = SaveSettings(d, ImageLocation); - if (exitStatus == TRUE) - break; - else - { - exitStatus = TRUE; - exitStatus = ProcessDialogWindow(); - } - } - - DestroyWindow(*SettingsDialogDPDT); -} - -//Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime -double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index, double volt) -{ - DpdtStruct* d = (DpdtStruct*)ComponentAdderss; - - ///Check if DPDT switch is in state 1; i.e Input 1 is connected to output11, Input 2 is connected to output21 - if (d->NS1) - { - ///If DPDT switch is in state 1 then output12 and output22 will be floating/open - if (index == out12) - { - d->Volt[out12] = V_OPEN; - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); - } - else if (index == out22) - { - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); - d->Volt[out22] = V_OPEN; - } - else - { - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); - } - - double Vin; - double Vout; - - ///Get voltages at the connected pins - if (index == in1) - { - Vin = volt; - Vout = VoltRequest(d->PinId[out11], ComponentAdderss); - } - else if (index == out11) - { - Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - Vout = volt; - } - else - { - Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - Vout = VoltRequest(d->PinId[out11], ComponentAdderss); - } - - ///Set 1: input 1, output11, output12 - ///If either pin is grounded then all pins are set to GND - if (Vin == GND || Vout == GND) - { - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, GND); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, max(Vin, Vout)); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); - } - - ///Get voltages at the connected pins - if (index == in2) - { - Vin = volt; - Vout = VoltRequest(d->PinId[out21], ComponentAdderss); - } - else if (index == out21) - { - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = volt; - } - else - { - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = VoltRequest(d->PinId[out21], ComponentAdderss); - } - - ///Set 2: input 2, output21, output22 - ///If either pin is grounded then all pins are set to GND - if (Vin == GND || Vout == GND) - { - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, GND); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, max(Vin, Vout)); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); - } - } - ///Check if DPDT switch is in state 2; i.e Input 1 is connected to output12, Input 2 is connected to output22 - else - { - ///If DPDT switch is in state 2 then output11 and output21 will be floating/open - if (index == out11) - { - d->Volt[out11] = V_OPEN; - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); - } - else if (index == out21) - { - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); - d->Volt[out21] = V_OPEN; - } - else - { - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); - } - - double Vin; - double Vout; - - ///Get voltages at the connected pins - if (index == in1) - { - Vin = volt; - Vout = VoltRequest(d->PinId[out12], ComponentAdderss); - } - else if (index == out12) - { - Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - Vout = volt; - } - else - { - Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - Vout = VoltRequest(d->PinId[out12], ComponentAdderss); - } - - ///Set 1: input 1, output11, output12 - ///If either pin is grounded then all pins are set to GND - if (Vin == GND || Vout == GND) - { - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, GND); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, max(Vin, Vout)); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); - } - - ///Get voltages at the connected pins - if (index == in2) - { - Vin = volt; - Vout = VoltRequest(d->PinId[out22], ComponentAdderss); - } - else if (index == out22) - { - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = volt; - } - else - { - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = VoltRequest(d->PinId[out22], ComponentAdderss); - } - - ///Set 2: input 2, output21, output22 - ///If either pin is grounded then all pins are set to GND - if (Vin == GND || Vout == GND) - { - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, GND); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, max(Vin, Vout)); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); - } - } - - return d->Volt[index]; -} - -//Perform a static check and equalise the voltage on all pins that are connected to DPST at runtime -void EqualiseStaticVoltageDPDT(void* ComponentAdderss) -{ - DpdtStruct* d = (DpdtStruct*)ComponentAdderss; - - ///Check if DPDT switch is in state 1; i.e Input 1 is connected to output11, Input 2 is connected to output21 - if (d->NS1) - { - ///If DPDT switch is in state 1 then output12 and output22 will be floating/open - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); - - ///Get voltages at the connected pins - double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - double Vout = VoltRequest(d->PinId[out11], ComponentAdderss); - - ///Set 1: input 1, output11, output12 - ///If either pin is grounded then all pins are set to GND - if (Vin == GND || Vout == GND) - { - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, GND); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, max(Vin, Vout)); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); - } - - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = VoltRequest(d->PinId[out21], ComponentAdderss); - ///Set 2: input 2, output21, output22 - ///If either pin is grounded then all pins are set to GND - if (Vin == GND || Vout == GND) - { - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, GND); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, max(Vin, Vout)); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); - } - } - ///Check if DPDT switch is in state 2; i.e Input 1 is connected to output12, Input 2 is connected to output22 - else - { - ///If DPDT switch is in state 2 then output11 and output21 will be floating/open - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); - - ///Get voltages at the connected pins - double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - double Vout = VoltRequest(d->PinId[out12], ComponentAdderss); - - ///Set 1: input 1, output11, output12 - ///If either pin is grounded then all pins are set to GND - if (Vin == GND || Vout == GND) - { - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, GND); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, max(Vin, Vout)); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); - } - - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = VoltRequest(d->PinId[out22], ComponentAdderss); - ///Set 2: input 2, output21, output22 - ///If either pin is grounded then all pins are set to GND - if (Vin == GND || Vout == GND) - { - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, GND); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, max(Vin, Vout)); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); - } - } -} - -void ToggleState(DpdtStruct* d, void* ImageLocation) -{ - d->image = (d->image == DPDT_1) ? DPDT_2 : DPDT_1; - d->NS1 = (d->NS1 == TRUE) ? FALSE : TRUE; - SetImage(d->image, ImageLocation); - RefreshImages(); -} - -void HandleDpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) -{ - - DpdtStruct* d = (DpdtStruct*)ComponentAddress; - - if (SimulationStarted) - { - switch (Event) - { - case EVENT_MOUSE_DOWN: - ToggleState(d, ImageLocation); - EqualiseStaticVoltageDPDT(ComponentAddress); - break; - case EVENT_MOUSE_UP: - if (!d->latched) - { - ToggleState(d, ImageLocation); - EqualiseStaticVoltageDPDT(ComponentAddress); - } - break; - default: - break; - } - } - else - { - switch (Event) - { - case EVENT_MOUSE_DBLCLICK: - DpdtSettingsDialog(ComponentAddress, ImageLocation); - break; - default: - break; - } - } -} - -double DpdtVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) -{ - - if (SimulationStarted) - return EqualiseRuntimeVoltageDPDT(ComponentAddress, index, Volt); - - return Volt; -}
\ No newline at end of file diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp deleted file mode 100644 index d806dbb..0000000 --- a/ldmicro/components/dpst.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* DPST component file -* Code version: 2.1 -* Version description: Fixes minor bugs in v2.0 -* Version steability: -* GUI -> Stable -* Functionality -> Bugs found. -* Bugs: -* 1. Voltages dont load properly during simulation when the "Switch" component controls input pin of the DPST component. -* -*/ - -///Includes -#include <wincodec.h> -#include <stdio.h> -//#include <string.h> -#include <commctrl.h> -#include <Windowsx.h> - -#include "componentstructs.h" -#include "componentfunctions.h" -#include "componentimages.h" -#include "components.h" - -///Window handles -static HWND State1; -static HWND State2; -static HWND ModeLatchedDPST; -static HWND ModeTempDPST; -HWND* SettingsDialogDPST; - -///Global variables -enum DPST_Pins { in1 = 0, in2, out1, out2 }; - -///Function definitions -int InitDpst(void * ComponentAddress) -{ - DpstStruct* d = (DpstStruct*)ComponentAddress; - d->image = DPST_1; - d->NO = FALSE; - d->latched = TRUE; - d->Volt[in1] = V_OPEN; - d->Volt[in2] = V_OPEN; - d->Volt[out1] = V_OPEN; - d->Volt[out2] = V_OPEN; - - return DPST_1; -} - -void SetDpstIds(int* id, void* ComponentAddress) -{ - DpstStruct* d = (DpstStruct*)ComponentAddress; - d->PinId[in1] = *id++; - d->PinId[in2] = *id++; - d->PinId[out1] = *id++; - d->PinId[out2] = *id++; -} - -void MakeSettingsDialogDPST() -{ - ///Switch action mode - HWND InitLatched = CreateWindowEx(0, WC_BUTTON, ("Action mode"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 7, 3, 120, 65, *SettingsDialogDPST, NULL, NULL, NULL); - FontNice(InitLatched); - - ModeLatchedDPST = CreateWindowEx(0, WC_BUTTON, ("Latched"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); - FontNice(ModeLatchedDPST); - - ModeTempDPST = CreateWindowEx(0, WC_BUTTON, ("Temporary"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); - FontNice(ModeTempDPST); - - ///Switch initial status - HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output state"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 140, 3, 120, 65, *SettingsDialogDPST, NULL, NULL, NULL); - FontNice(InitOut); - - State1 = CreateWindowEx(0, WC_BUTTON, ("State 1"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 149, 21, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); - FontNice(State1); - - State2 = CreateWindowEx(0, WC_BUTTON, ("State 2"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 149, 41, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); - FontNice(State2); -} - -void LoadSettings(DpstStruct* d) -{ - - if (d->latched) - Button_SetCheck(ModeLatchedDPST, BST_CHECKED); - else - Button_SetCheck(ModeTempDPST, BST_CHECKED); - - if (!d->NO) - Button_SetCheck(State1, BST_CHECKED); - else - Button_SetCheck(State2, BST_CHECKED); -} - -BOOL SaveSettings(DpstStruct* d, void* ImageLocation) -{ - if (Button_GetState(ModeLatchedDPST) == BST_CHECKED) - d->latched = TRUE; - else if (Button_GetState(ModeTempDPST) == BST_CHECKED) - d->latched = FALSE; - else - { - MessageBox(*SettingsDialogDPST, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - } - - if (Button_GetState(State1) == BST_CHECKED) - d->NO = FALSE; - else if (Button_GetState(State2) == BST_CHECKED) - d->NO = TRUE; - else - { - MessageBox(*SettingsDialogDPST, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - } - - if (!d->NO) - d->image = DPST_1; - else - d->image = DPST_2; - - SetImage(d->image, ImageLocation); - RefreshImages(); - - return TRUE; -} - -void DpstSettingsDialog(void* ComponentAddress, void* ImageLocation) -{ - DpstStruct* d = (DpstStruct*)ComponentAddress; - BOOL exitStatus; - - //Create dialog window instance - SettingsDialogDPST = CreateDialogWindow("SPDT Settings Dialog", 100, 100, 263, 145, STYLE_VERTICAL); - - //Make the settings dialog - MakeSettingsDialogDPST(); - - //Load settings - LoadSettings(d); - - //Show dialog window - ShowDialogWindow(); - - exitStatus = ProcessDialogWindow(); - while (exitStatus == FALSE) - { - exitStatus = SaveSettings(d, ImageLocation); - if (exitStatus == TRUE) - break; - else - { - exitStatus = TRUE; - exitStatus = ProcessDialogWindow(); - } - } - - DestroyWindow(*SettingsDialogDPST); -} - -//Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime -double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index, double volt) -{ - DpstStruct* d = (DpstStruct*)ComponentAdderss; - - ///Check if the switch is open - if (d->NO) - { - ///If switch is open then all terminals will be floating/open - switch (index) - { - case in1: - d->Volt[in1] = V_OPEN; - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - break; - case in2: - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[in2] = V_OPEN; - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - case out1: - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out1] = V_OPEN; - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - break; - case out2: - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - d->Volt[out2] = V_OPEN; - break; - default: - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - break; - } - } - ///If the switch is connected - else - { - double Vin; - double Vout; - - ///Get voltages at the connected pins - if (index == in1) - { - Vin = volt; - Vout = VoltRequest(d->PinId[out1], ComponentAdderss); - } - else if (index == out1) - { - Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - Vout = volt; - } - else - { - Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - Vout = VoltRequest(d->PinId[out1], ComponentAdderss); - } - - ///Equalise voltage for input 1 output 1 pair - ///If either pin is grounded then all pins are set to GND (Static event) - if (Vin == GND || Vout == GND) - { - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, GND); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) - else - { - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, max(Vin, Vout)); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); - } - - ///Get voltages at the connected pins - if (index == in2) - { - Vin = volt; - Vout = VoltRequest(d->PinId[out2], ComponentAdderss); - } - else if (index == out2) - { - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = volt; - } - else - { - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = VoltRequest(d->PinId[out2], ComponentAdderss); - } - - ///Equalise voltage for input 2 output 2 pair - ///If either pin is grounded then all pins are set to GND (Static event) - if (Vin == GND || Vout == GND) - { - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, GND); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) - else - { - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, max(Vin, Vout)); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); - } - } - - return d->Volt[index]; -} - -//Perform a static check and equalise the voltage on all pins that are connected to DPST at runtime -void EqualiseStaticVoltageDPST(void* ComponentAdderss) -{ - DpstStruct* d = (DpstStruct*)ComponentAdderss; - - ///Check if the switch is open - if (d->NO) - { - ///If switch is open then all terminals will be floating/open - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - - } - ///If the switch is connected - else - { - double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - double Vout = VoltRequest(d->PinId[out1], ComponentAdderss); - - ///Equalise voltage for input 1 output 1 pair - ///If either pin is grounded then all pins are set to GND (Static event) - if (Vin == GND || Vout == GND) - { - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, GND); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) - else - { - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, max(Vin, Vout)); - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); - } - - Vin = VoltRequest(d->PinId[in2], ComponentAdderss); - Vout = VoltRequest(d->PinId[out2], ComponentAdderss); - - ///Equalise voltage for input 2 output 2 pair - ///If either pin is grounded then all pins are set to GND (Static event) - if (Vin == GND || Vout == GND) - { - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, GND); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); - } - ///If Vin is set as open - else if (Vin == V_OPEN) - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); - ///If Vout is set as open - else if (Vout == V_OPEN) - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, Vin); - ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) - else - { - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, max(Vin, Vout)); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); - } - } -} - -void ToggleState(DpstStruct* d, void* ImageLocation) -{ - d->image = (d->image == DPST_1) ? DPST_2 : DPST_1; - d->NO = (d->NO == TRUE) ? FALSE : TRUE; - SetImage(d->image, ImageLocation); - RefreshImages(); -} - -void HandleDpstEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) -{ - DpstStruct* d = (DpstStruct*)ComponentAddress; - - if (SimulationStarted) - { - switch (Event) - { - case EVENT_MOUSE_DOWN: - ToggleState(d, ImageLocation); - EqualiseStaticVoltageDPST(ComponentAddress); - break; - case EVENT_MOUSE_UP: - if (!d->latched) - { - ToggleState(d, ImageLocation); - EqualiseStaticVoltageDPST(ComponentAddress); - } - break; - default: - break; - } - } - else - { - switch (Event) - { - case EVENT_MOUSE_DBLCLICK: - DpstSettingsDialog(ComponentAddress, ImageLocation); - break; - default: - break; - } - } -} - -double DpstVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) -{ - if (SimulationStarted) - return EqualiseRuntimeVoltageDPST(ComponentAddress, index, Volt); - - return Volt; -}
\ No newline at end of file diff --git a/ldmicro/components/relay.cpp b/ldmicro/components/relay.cpp deleted file mode 100644 index 262241f..0000000 --- a/ldmicro/components/relay.cpp +++ /dev/null @@ -1,208 +0,0 @@ -#include <wincodec.h> -#include <stdio.h> -#include <math.h> -//#include <string.h> -#include <commctrl.h> -#include <Windowsx.h> - -#include "components.h" -#include "componentstructs.h" -#include "componentfunctions.h" -#include "componentimages.h" - -HWND* RelayDialog; -HWND MinOperatingVoltTextbox; -HWND MaxOperatingVoltTextbox; - -enum RelayPins{ - Coil1 = 0, - Coil2 = 1, - COM = 2, - NO = 3, - NC = 4, -}; - -int InitRelay(void* ComponentAddress) -{ - RelayStruct* temp = (RelayStruct*)ComponentAddress; - temp->Image = RELAY_NC; - temp->MinOperatingVolt = 5; - temp->MaxOperatingVolt = 12; - temp->NC = TRUE; - - return RELAY_NC; -} - -void MakeRelayControls(void) -{ - HWND MinOperatingVoltLabel = CreateWindowEx(0, WC_STATIC, ("Minimum Operating Volt:"), - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, - 5, 21, 100, 21, *RelayDialog, NULL, NULL, NULL); - FontNice(MinOperatingVoltLabel); - - HWND MaxOperatingVoltLabel = CreateWindowEx(0, WC_STATIC, ("Maximum Operating Volt:"), - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, - 5, 41, 100, 21, *RelayDialog, NULL, NULL, NULL); - FontNice(MaxOperatingVoltLabel); - - MinOperatingVoltTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 110, 21, 155, 21, *RelayDialog, NULL, NULL, NULL); - FontFixed(MinOperatingVoltTextbox); - - MaxOperatingVoltTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 110, 41, 155, 21, *RelayDialog, NULL, NULL, NULL); - FontFixed(MaxOperatingVoltTextbox); - - /*PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, - (LONG_PTR)MyNameProc);*/ -} - -void LoadState(RelayStruct* Data) -{ - char Voltage[15]; - sprintf((char*)Voltage,"%f",Data->MinOperatingVolt); - Edit_SetText(MinOperatingVoltTextbox, Voltage); - sprintf((char*)Voltage,"%f",Data->MaxOperatingVolt); - Edit_SetText(MaxOperatingVoltTextbox, Voltage); -} - -BOOL SaveRelayDialog(RelayStruct* Data) -{ - double volt, volt2; - char Voltage[15]; - Edit_GetText(MinOperatingVoltTextbox, (LPSTR)&Voltage, 15); - volt = atof(Voltage); - Edit_GetText(MaxOperatingVoltTextbox, (LPSTR)&Voltage, 15); - volt2 = atof(Voltage); - if(volt == 0.0f) - { - MessageBox(*RelayDialog, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - } - else if((volt2 == 0.0f) || (volt2<volt)) - { - MessageBox(*RelayDialog, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - }else - { - Data->MinOperatingVolt = volt; - Data->MaxOperatingVolt = volt2; - } - return TRUE; -} - -void ShowRelayDialog(void* ComponentAddress) -{ - RelayStruct* Data = (RelayStruct*) ComponentAddress; - BOOL Canceled, Complete = TRUE; - RelayDialog = CreateDialogWindow("Relay Dialog", 100, 100, 290, 50, STYLE_HORIZONTAL); - MakeRelayControls(); - ShowDialogWindow(); - LoadState(Data); - Canceled = ProcessDialogWindow(); - while(Canceled == FALSE) - { - Complete = SaveRelayDialog(Data); - if(Complete == TRUE) - { - // MessageBox(*RelayDialog, - // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); - break; - }else - { - Complete =TRUE; - Canceled = ProcessDialogWindow(); - } - } - DestroyWindow(*RelayDialog); -} - -void HandleRelayEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, - void* ImageLocation, UINT ImageId, HWND* h) -{ - RelayStruct *temp = (RelayStruct*)ComponentAddress; - if(SimulationStarted) - { - /*Relay is a static component. It's value does not change with - direct user interaction hence this part is blank for relays*/ - } - else - { - switch(Event){ - case EVENT_MOUSE_DBLCLICK: - ShowRelayDialog(ComponentAddress); - // SetImage(temp->Image, ImageLocation); - // RefreshImages(); - break; - } - } -} - -double RelayVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, - double Volt, int Source, void* ImageLocation) -{ - if(SimulationStarted) - { - RelayStruct *Relay = (RelayStruct*)ComponentAddress; - /*if(index == Coil2) - { - char vx[10],vy[10]; - _gcvt(Volt, 10, vy); - _itoa(index, vx, 10); - MessageBox(NULL, - (LPSTR)(vx), (LPSTR)(vx), MB_OK | MB_ICONWARNING); - }*/ - double Volt2,diff; - switch(index) - { - case Coil1: - Volt2 = VoltRequest(Relay->PinId[Coil2], ComponentAddress); - break; - case Coil2: - Volt2 = VoltRequest(Relay->PinId[Coil1], ComponentAddress); - break; - default: - return Volt; - } - diff = fabs(Volt2-Volt); - if((diff >= Relay->MinOperatingVolt) && (diff <= Relay->MaxOperatingVolt)) - { - Relay->Image = RELAY_NO; - } - else - { - Relay->Image = RELAY_NC; - } - SetImage(Relay->Image, ImageLocation); - RefreshImages(); - } - /*char Debug[256]; - sprintf_s(Debug, "RelayVoltChanged: \tAddr1: %p \t Volt1: %f \t Volt2: %f\n", - ComponentAddress, Volt, Volt2); - OutputDebugString(Debug);*/ - return Volt; -} - -void SetRelayIds(int* id,void* ComponentAddress) -{ - RelayStruct *s = (RelayStruct*)ComponentAddress; - s->PinId[Coil1] = *id++; - s->PinId[Coil2] = *id++; - s->PinId[COM] = *id++; - s->PinId[NO] = *id++; - s->PinId[NC] = *id++; - - /*char Debug[256]; - sprintf_s(Debug, "SetRelayIds: \tAddr1: %p \tAddr2: %p \tPin0:%d \t Pin1:%d \tPin2: %d Pin3: %d\n", - ComponentAddress, s, s->PinId[0], s->PinId[1], s->PinId[2], s->PinId[3]); - 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);*/ -}
\ No newline at end of file diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp deleted file mode 100644 index e30a732..0000000 --- a/ldmicro/components/spdt.cpp +++ /dev/null @@ -1,390 +0,0 @@ -/* SPDT component file -* Code version: 2.0 -* Version description: Adds latching functionality to component -* Version steability: -* GUI -> Stable -* Functionality -> No known bugs. -* Bugs: -* 1. - -* -*/ - -///Includes -#include <wincodec.h> -#include <stdio.h> -//#include <string.h> -#include <commctrl.h> -#include <Windowsx.h> - -#include "componentstructs.h" -#include "componentfunctions.h" -#include "componentimages.h" -#include "components.h" - -///Window handles -static HWND StateOut1; -static HWND StateOut2; -static HWND ModeLatched; -static HWND ModeTemp; -HWND* SettingsDialogSPDT; - -///Global variables -enum SPDT_Pins {in = 0, out1, out2}; - -///Function definitions -void SetSpdtIds(int* id, void* ComponentAddress) -{ - SpdtStruct* s = (SpdtStruct*)ComponentAddress; - s->PinId[in] = *id++; - s->PinId[out1] = *id++; - s->PinId[out2] = *id++; -} - -int InitSpdt(void * ComponentAddress) -{ - SpdtStruct* s = (SpdtStruct*)ComponentAddress; - s->image = SPDT_1; - s->latched = TRUE; - s->NO1 = TRUE; - s->Volt[in] = V_OPEN; - s->Volt[out1] = V_OPEN; - s->Volt[out2] = V_OPEN; - - return SPDT_1; -} - -void MakeSettingsDialogSPDT() -{ - ///Switch action mode - HWND InitLatched = CreateWindowEx(0, WC_BUTTON, ("Action mode"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 7, 3, 120, 65, *SettingsDialogSPDT, NULL, NULL, NULL); - FontNice(InitLatched); - - ModeLatched = CreateWindowEx(0, WC_BUTTON, ("Latched"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); - FontNice(ModeLatched); - - ModeTemp = CreateWindowEx(0, WC_BUTTON, ("Temporary"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); - FontNice(ModeTemp); - - ///Switch initial status - HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 140, 3, 120, 65, *SettingsDialogSPDT, NULL, NULL, NULL); - FontNice(InitOut); - - StateOut1 = CreateWindowEx(0, WC_BUTTON, ("Output 1"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 149, 21, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); - FontNice(StateOut1); - - StateOut2 = CreateWindowEx(0, WC_BUTTON, ("Output 2"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 149, 41, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); - FontNice(StateOut2); -} - -void LoadSettings(SpdtStruct* s) -{ - if (s->latched) - Button_SetCheck(ModeLatched, BST_CHECKED); - else - Button_SetCheck(ModeTemp, BST_CHECKED); - if (s->NO1) - Button_SetCheck(StateOut1, BST_CHECKED); - else - Button_SetCheck(StateOut2, BST_CHECKED); -} - -BOOL SaveSettings(SpdtStruct* s, void* ImageLocation) -{ - if (Button_GetState(ModeLatched) == BST_CHECKED) - s->latched = TRUE; - else if (Button_GetState(ModeTemp) == BST_CHECKED) - s->latched = FALSE; - else - { - MessageBox(*SettingsDialogSPDT, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - } - - if (Button_GetState(StateOut1) == BST_CHECKED) - s->NO1 = TRUE; - else if (Button_GetState(StateOut2) == BST_CHECKED) - s->NO1 = FALSE; - else - { - MessageBox(*SettingsDialogSPDT, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - } - - - if (s->NO1) - s->image = SPDT_1; - else - s->image = SPDT_2; - - SetImage(s->image, ImageLocation); - RefreshImages(); - - return TRUE; -} - -void SpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) -{ - SpdtStruct* s = (SpdtStruct*)ComponentAddress; - BOOL exitStatus; - - //Create dialog window instance - SettingsDialogSPDT = CreateDialogWindow("SPDT Settings Dialog", 100, 100, 263, 145, STYLE_VERTICAL); - - //Make the settings dialog - MakeSettingsDialogSPDT(); - - //Load settings - LoadSettings(s); - - //Show dialog window - ShowDialogWindow(); - - exitStatus = ProcessDialogWindow(); - while (exitStatus == FALSE) - { - exitStatus = SaveSettings(s, ImageLocation); - if (exitStatus == TRUE) - break; - else - { - exitStatus = TRUE; - exitStatus = ProcessDialogWindow(); - } - } - - DestroyWindow(*SettingsDialogSPDT); - -} - -//Perform a static check and equalise the voltage on all pins that are connected to SPDT at runtime -void EqualiseStaticVoltageSPDT(void* ComponentAdderss) -{ - SpdtStruct* s = (SpdtStruct*)ComponentAdderss; - - ///Check if input and output 1 are connected - if (s->NO1) - { - ///If the input pin is connected to output 1 then output 2 will be open - s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, V_OPEN); - - ///Get voltages at the connected pins - double volt1 = VoltRequest(s->PinId[in], ComponentAdderss); - double volt2 = VoltRequest(s->PinId[out1], ComponentAdderss); - - ///If either pin is grounded then all pins are set to GND - if (volt1 == GND || volt2 == GND) - { - s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, GND); - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); - } - ///If volt1 is set as open - else if (volt1 == V_OPEN) - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, volt2); - ///If volt2 is set as open - else if (volt2 == V_OPEN) - s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, volt1); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, max(volt1, volt2)); - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, max(volt1, volt2)); - } - } - ///If input and output 2 are connected - else - { - ///If the input pin is connected to output 2 then output 1 will be open - s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, V_OPEN); - - ///Get voltages at the connected pins - double volt1 = VoltRequest(s->PinId[0], ComponentAdderss); - double volt2 = VoltRequest(s->PinId[out2], ComponentAdderss); - - ///If either pin is grounded then all pins are set to GND (Static event) - if (volt1 == GND || volt2 == GND) - { - s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, GND); - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); - } - ///If volt1 is set as open - else if (volt1 == V_OPEN) - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, volt2); - ///If volt2 is set as open - else if (volt2 == V_OPEN) - s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, volt1); - ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) - else - { - s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, max(volt1, volt2)); - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, max(volt1, volt2)); - } - } -} - -//Dynamically check and equalise the voltage on all pins that are connected to SPDT at runtime -double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index, double volt) -{ - SpdtStruct* s = (SpdtStruct*)ComponentAdderss; - - ///Check if input and output 1 are connected - if (s->NO1) - { - ///If the input pin is connected to output 1 then output 2 will be open - if (index == out2) - s->Volt[out2] = V_OPEN; - else - s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, V_OPEN); - - double volt1; - double volt2; - - ///Get voltages at the connected pins - if (index == in) - { - volt1 = volt; - volt2 = VoltRequest(s->PinId[out1], ComponentAdderss); - } - else if (index == out1) - { - volt1 = VoltRequest(s->PinId[in], ComponentAdderss); - volt2 = volt; - } - else - { - volt1 = VoltRequest(s->PinId[in], ComponentAdderss); - volt2 = VoltRequest(s->PinId[out1], ComponentAdderss); - } - - ///If either pin is grounded then all pins are set to GND - if (volt1 == GND || volt2 == GND) - { - s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, GND); - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); - } - ///If volt1 is set as open - else if (volt1 == V_OPEN) - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, volt2); - ///If volt2 is set as open - else if (volt2 == V_OPEN) - s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, volt1); - ///If no pin is grounded then all pins are set to the max voltage of the pins - else - { - s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, max(volt1, volt2)); - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, max(volt1, volt2)); - } - } - ///If input and output 2 are connected - else - { - ///If the input pin is connected to output 2 then output 1 will be open - s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, V_OPEN); - - double volt1; - double volt2; - - ///Get voltages at the connected pins - if (index == in) - { - volt1 = volt; - volt2 = VoltRequest(s->PinId[out2], ComponentAdderss); - } - else if (index == out1) - { - volt1 = VoltRequest(s->PinId[in], ComponentAdderss); - volt2 = volt; - } - else - { - volt1 = VoltRequest(s->PinId[in], ComponentAdderss); - volt2 = VoltRequest(s->PinId[out2], ComponentAdderss); - } - - ///If either pin is grounded then all pins are set to GND (Static event) - if (volt1 == GND || volt2 == GND) - { - s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, GND); - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); - } - ///If volt1 is set as open - else if (volt1 == V_OPEN) - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, volt2); - ///If volt2 is set as open - else if (volt2 == V_OPEN) - s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, volt1); - ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) - else - { - s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, max(volt1, volt2)); - s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, max(volt1, volt2)); - } - } - - return s->Volt[index]; -} - -double SpdtVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) -{ - if (SimulationStarted) - return EqualiseRuntimeVoltageSPDT(ComponentAddress, index, Volt); - - return Volt; -} - -void ToggleState(SpdtStruct* s, void* ImageLocation) -{ - s->image = (s->image == SPDT_1) ? SPDT_2 : SPDT_1; - s->NO1 = (s->NO1 == TRUE) ? FALSE : TRUE; - SetImage(s->image, ImageLocation); - RefreshImages(); -} - -void HandleSpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) -{ - SpdtStruct* s = (SpdtStruct*)ComponentAddress; - - if (SimulationStarted) - { - switch (Event) - { - case EVENT_MOUSE_DOWN: - ToggleState(s, ImageLocation); - EqualiseStaticVoltageSPDT(ComponentAddress); - break; - case EVENT_MOUSE_UP: - if (!s->latched) - { - ToggleState(s, ImageLocation); - EqualiseStaticVoltageSPDT(ComponentAddress); - } - break; - default: - break; - } - } - else - { - switch (Event) - { - case EVENT_MOUSE_DBLCLICK: - SpdtSettingsDialog(ComponentAddress, ImageLocation); - break; - default: - break; - } - } -}
\ No newline at end of file diff --git a/ldmicro/components/switch.cpp b/ldmicro/components/switch.cpp deleted file mode 100644 index ea74076..0000000 --- a/ldmicro/components/switch.cpp +++ /dev/null @@ -1,355 +0,0 @@ -#include <wincodec.h> -#include <stdio.h> -//#include <string.h> -#include <commctrl.h> -#include <Windowsx.h> - -#include "componentstructs.h" -#include "componentfunctions.h" -#include "componentimages.h" -#include "components.h" - -static HWND TemporaryRadio; -static HWND LatchedRadio; -static HWND ClosedRadio; -static HWND OpenRadio; -static HWND NameTextbox; -static HWND InNameTextbox; -static HWND OutNameTextbox; -HWND* SwitchDialog; - -void SwitchStateChanged(SwitchStruct* SwitchData, void* ImageLocation); -void MakeSwitchControls() -{ - HWND ActionGrouper = CreateWindowEx(0, WC_BUTTON, ("Action"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 7, 3, 120, 65, *SwitchDialog, NULL, NULL, NULL); - FontNice(ActionGrouper); - - LatchedRadio = CreateWindowEx(0, WC_BUTTON, ("Latched"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, *SwitchDialog, NULL, NULL, NULL); - FontNice(LatchedRadio); - - TemporaryRadio = CreateWindowEx(0, WC_BUTTON, ("Temporary"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, *SwitchDialog, NULL, NULL, NULL); - FontNice(TemporaryRadio); - - // SetOnlyRadio = CreateWindowEx(0, WC_BUTTON, _("(S) Set-Only"), - // WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - // 16, 61, 100, 20, CoilDialog, NULL, Instance, NULL); - // NiceFont(SetOnlyRadio); - - // ResetOnlyRadio = CreateWindowEx(0, WC_BUTTON, _("(R) Reset-Only"), - // WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - // 16, 81, 105, 20, CoilDialog, NULL, Instance, NULL); - // NiceFont(ResetOnlyRadio); - - HWND PositionGrouper = CreateWindowEx(0, WC_BUTTON, ("Position"), - WS_CHILD | BS_GROUPBOX | WS_VISIBLE, - 140, 3, 120, 65, *SwitchDialog, NULL, NULL, NULL); - FontNice(PositionGrouper); - - OpenRadio = CreateWindowEx(0, WC_BUTTON, ("Open"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_GROUP | WS_TABSTOP, - 149, 21, 100, 20, *SwitchDialog, NULL, NULL, NULL); - FontNice(OpenRadio); - - ClosedRadio = CreateWindowEx(0, WC_BUTTON, ("Closed"), - WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_TABSTOP, - 149, 41, 100, 20, *SwitchDialog, NULL, NULL, NULL); - FontNice(ClosedRadio); - - HWND textLabel = CreateWindowEx(0, WC_STATIC, ("Name:"), - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, - 100, 80, 50, 21, *SwitchDialog, 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, *SwitchDialog, NULL, NULL, NULL); - FontFixed(NameTextbox); - - /*PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, - (LONG_PTR)MyNameProc);*/ -} - -void LoadState(SwitchStruct* Data) -{ - if(Data->Latched) - { - Button_SetCheck(LatchedRadio, BST_CHECKED); - }else - { - Button_SetCheck(TemporaryRadio, BST_CHECKED); - } - if(Data->NOpen) - { - Button_SetCheck(OpenRadio, BST_CHECKED); - } - else - { - Button_SetCheck(ClosedRadio, BST_CHECKED); - } - Edit_SetText(NameTextbox, Data->Name); -} - -BOOL SaveSwitchDialog(SwitchStruct* Data) -{ - char temp[15]; - BOOL Latched, NOpen; - if(Button_GetState(LatchedRadio) == BST_CHECKED) - { - Latched = TRUE; - - }else if(Button_GetState(TemporaryRadio) == BST_CHECKED) - { - Latched = FALSE; - }else - { - MessageBox(*SwitchDialog, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - } - - if(Button_GetState(OpenRadio) == BST_CHECKED) - { - NOpen = TRUE; - - }else if(Button_GetState(ClosedRadio) == BST_CHECKED) - { - NOpen = FALSE; - }else - { - MessageBox(*SwitchDialog, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - } - - if(Edit_GetText(NameTextbox, (LPSTR)&temp, 15) < 1) - { - MessageBox(*SwitchDialog, - ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); - return FALSE; - }else - { - Data->Latched = Latched; - Data-> NOpen = NOpen; - Data-> Open = NOpen; - strcpy(Data->Name, temp); - if(NOpen) - { - Data->Image =SWITCH_DISCONNECTED; - } - else - { - Data->Image =SWITCH_CONNECTED; - } - } - return TRUE; -} - -void ShowSwitchDialog(void* ComponentAddress) -{ - SwitchStruct* Data = (SwitchStruct*) ComponentAddress; - BOOL Canceled, Complete = TRUE; - SwitchDialog = CreateDialogWindow("Switch Dialog", 100, 100, 263, 145, STYLE_VERTICAL); - MakeSwitchControls(); - ShowDialogWindow(); - LoadState(Data); - Canceled = ProcessDialogWindow(); - while(Canceled == FALSE) - { - Complete = SaveSwitchDialog(Data); - if(Complete == TRUE) - { - // MessageBox(*SwitchDialog, - // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); - break; - }else - { - Complete =TRUE; - Canceled = ProcessDialogWindow(); - } - } - DestroyWindow(*SwitchDialog); -} - -int InitSwitch(void* ComponentAddress) -{ - SwitchStruct* temp = (SwitchStruct*)ComponentAddress; - temp->Image = SWITCH_DISCONNECTED; - temp->Latched = TRUE; - temp->Open = TRUE; - temp->NOpen = TRUE; - temp->Volt[0] = V_OPEN; - temp->Volt[1] = V_OPEN; - - return SWITCH_DISCONNECTED; -} - -void UpdateValues(SwitchStruct* Switch, void* ComponentAddress) -{ - /*char Debug[256]; - sprintf_s(Debug, "Clicked: %p\n", ComponentAddress); - OutputDebugString(Debug);*/ - 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); - // char vx[3],vy[10]; - // _gcvt(Switch->Volt[0],8,vy); - // _itoa(Switch->PinId[0],vx,10); - // MessageBox(NULL, - // (vx),(vy), MB_OK | MB_ICONWARNING); - // Switch->Volt[1] = GlobalVoltChange(Switch->PinId[1], ComponentAddress, V_OPEN); - // MessageBox(NULL, - // "Open", "Test", MB_OK | MB_ICONWARNING); - } - else - { - double Voltage; - Voltage = VoltRequest(Switch->PinId[0], ComponentAddress); - Switch->Volt[0] = Voltage; - Voltage = VoltRequest(Switch->PinId[1], ComponentAddress); - Switch->Volt[1] = Voltage; - if(Switch->Volt[0] > Switch->Volt[1]) - { - /*sprintf_s(Debug, "Values2: Volt1:%f \t Volt2:%f \tAddr: %p \tPin0:%d \t Pin1:%d\n", - Switch->Volt[0], Switch->Volt[1], ComponentAddress, Switch->PinId[0], Switch->PinId[1]); - OutputDebugString(Debug);*/ - Switch->Volt[0] = VoltChange(Switch->PinId[0], 0, - ComponentAddress, Switch->Volt[1]); - } - else if(Switch->Volt[1] > Switch->Volt[0]) - { - /*sprintf_s(Debug, "Values3: Volt1:%f \t Volt2:%f \tAddr: %p \tPin0:%d \t Pin1:%d\n", - Switch->Volt[0], Switch->Volt[1], ComponentAddress, Switch->PinId[0], Switch->PinId[1]); - OutputDebugString(Debug);*/ - Switch->Volt[1] = VoltChange(Switch->PinId[1], 1, - ComponentAddress, Switch->Volt[0]); - - } - } - /*sprintf_s(Debug, "Values: Volt1:%f \t Volt2:%f \tAddr: %p \tPin0:%d \t Pin1:%d\n", - Switch->Volt[0], Switch->Volt[1], ComponentAddress, Switch->PinId[0], Switch->PinId[1]); - OutputDebugString(Debug);*/ -} - -void HandleSwitchEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, - void* ImageLocation, UINT ImageId, HWND* h) -{ - SwitchStruct *temp = (SwitchStruct*)ComponentAddress; - - if(SimulationStarted) - { - switch(Event){ - case EVENT_MOUSE_UP: - if(temp->Latched) - { - temp->Open = !temp->Open; - /*MessageBox(NULL, - "Latched", "Test", MB_OK | MB_ICONWARNING);*/ - } - else - { - temp->Open = temp->NOpen; - // MessageBox(NULL, - // "Latched", "Test", MB_OK | MB_ICONWARNING); - } - SwitchStateChanged(temp, ImageLocation); - UpdateValues(temp, ComponentAddress); - break; - case EVENT_MOUSE_DOWN: - if(!temp->Latched) - { - temp->Open = !temp->NOpen; - SwitchStateChanged(temp, ImageLocation); - UpdateValues(temp, ComponentAddress); - } - break; - } - - } - else - { - switch(Event){ - case EVENT_MOUSE_DBLCLICK: - ShowSwitchDialog(ComponentAddress); - SetImage(temp->Image, ImageLocation); - RefreshImages(); - break; - } - } -} - -void SwitchStateChanged(SwitchStruct* SwitchData, void* ImageLocation) -{ - SetImage(SwitchData->Open ? SWITCH_DISCONNECTED : SWITCH_CONNECTED, - ImageLocation); - RefreshImages(); -} - -double SwitchVoltChanged(void* SwitchData, BOOL SimulationStarted, int Index, - double Volt, int Source, void* ImageLocation) -{ - // char Debug[256]; - SwitchStruct* temp = (SwitchStruct*)SwitchData; - if(SimulationStarted) - { - double Voltage; - Voltage = VoltRequest(temp->PinId[!Index], SwitchData); - if(temp->Open) - { - temp->Volt[!Index] = VoltChange(temp->PinId[!Index], !Index, SwitchData, V_OPEN); - temp->Volt[Index] = V_OPEN; - /*sprintf_s(Debug, "SwitchVoltChanged: \tAddress: %p \tVolt0:%f \t Volt1:%f\n", - SwitchData, Voltage, Volt); - OutputDebugString(Debug);*/ - return temp->Volt[Index]; - } - if(Voltage > Volt) - { - temp->Volt[Index] = Volt; - temp->Volt[!Index] = VoltChange(temp->PinId[!Index], !Index, SwitchData, Volt); - /*sprintf_s(Debug, "SwitchVoltChanged2: \tAddress: %p \tVolt0:%f \t Volt1:%f\n", - SwitchData, Voltage, Volt); - OutputDebugString(Debug);*/ - return temp->Volt[Index]; - } - else - { - // temp->Volt[!Index] = VoltChange(temp->PinId[!Index], !Index, SwitchData, Volt); - Voltage = VoltChange(temp->PinId[!Index], !Index, SwitchData, Volt); - temp->Volt[Index] = Voltage; - // VoltChange(temp->PinId[!Index], !Index, SwitchData, Volt); - return Voltage; - } - } - else - { - temp->Volt[Index] = Volt; - return Volt; - } - return 0; -} - -void SetSwitchIds(int* id,void* ComponentAddress) -{ - SwitchStruct *s = (SwitchStruct*)ComponentAddress; - s->PinId[0] = *id++; - s->PinId[1] = *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);*/ -}
\ No newline at end of file |