diff options
30 files changed, 4 insertions, 5538 deletions
diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt index 9af4450..8c568fa 100644 --- a/ldmicro/CMakeLists.txt +++ b/ldmicro/CMakeLists.txt @@ -60,11 +60,7 @@ IF(UNIX) ## Dummy compile and install to test linuxUI ## to compile LDmicro uncomment the below 2 line2 - set (COMPILE_CPP_SOURCES windows.cpp - #naminglist.cpp - #componentimages.cpp - #componentlist.cpp - #advanceddialog.cpp + set (COMPILE_CPP_SOURCES #naminglist.cpp arduino.cpp avr.cpp pic16.cpp @@ -95,8 +91,8 @@ IF(UNIX) add_executable (LDMicro ${COMPILE_CPP_SOURCES}) install (TARGETS LDMicro DESTINATION bin) - #add_executable (testMain testMain.cpp) target_link_libraries (LDMicro LinuxUI) target_link_libraries (LDMicro FreezeLD) + #add_executable (testMain testMain.cpp) #install (TARGETS testMain DESTINATION bin) ENDIF(UNIX) diff --git a/ldmicro/advanceddialog.cpp b/ldmicro/advanceddialog.cpp deleted file mode 100644 index a2b1444..0000000 --- a/ldmicro/advanceddialog.cpp +++ /dev/null @@ -1,1840 +0,0 @@ -#include <windows.h> -#include <commctrl.h> -#include <stdio.h> -#include <stdlib.h> -#include <wincodec.h> -#include <Windowsx.h> -#include <math.h> -// #include "stdafx.h" -// #include <gdiplus.h> - -#include "ldmicro.h" -#include "componentlist.h" -#include "advanceddialog.h" -#include "components\components.h" -#include "naminglist.h" -#include "simulate.h" - - -static HWND HorizScrollBar; -static HWND VertScrollBar; -static HHOOK MouseHookHandle; -static HMENU AdvancedTopMenu; -static int MouseX; -static int MouseY; -static BOOL Clicked = FALSE; -static BOOL DblClicked = FALSE; -static BOOL AdvDialogDone; -static BOOL AdvDialogCancel; -static HMENU AdvancedFileMenu; -static HMENU AdvancedEditMenu; -static HMENU AdvancedSimulateMenu; -static HMENU AdvancedHelpMenu; -static int CyclesPerTimerTick; - - -HWND AdvancedDialog; -HWND AdvancedWorkspace; -HWND ComponentList; -HWND NamingList; -HDC hdc; -HDC HdcMem; -HBITMAP test = NULL; -HANDLE ImageHeap; -BOOL SimulationStarted = FALSE; -HFONT AdvNiceFont; -HFONT AdvFixedFont; -HINSTANCE *ComponentInstance = &Instance; -char MainProgramComponent; - -int AdvWrkspRight; -int AdvWrkspBottom; -int CompListWidth; -int ResizeSwitch; -int NamingListHeight = 100; -UINT TIMERID = 100; -UINT DblClickTimer; -UINT UniquePinId = 0; -UINT MCUCount=0; -UINT NameCount; -BOOL AdvancedWindowOpen = FALSE; -// HBITMAP CreateBitmapMask(HBITMAP hbmColour, COLORREF crTransparent); - -void RefreshDialogScrollbars(void); -void StartAdvSimulationTimer(void); -void CALLBACK CycleAdvTimer(HWND hwnd, UINT msg, UINT_PTR id, DWORD time); - -// PinInfo PinData[MAX_PINS]; -PinMcu McuPin[MAX_MCU_PINS]; -PinName NameId[MAX_PINS]; -PinComponent ComponentPin; - -//----------------------------------------------------------------------------- -// Hook that we install when the user starts dragging the `splitter,' in case -// they drag it out of the narrow area of the drawn splitter bar. Resize -// the listview in response to mouse move, and unhook ourselves when they -// release the mouse button. -//----------------------------------------------------------------------------- -static LRESULT CALLBACK MouseHook(int code, WPARAM wParam, LPARAM lParam) -{ - switch(code) { - case HC_ACTION: { - MSLLHOOKSTRUCT *mhs = (MSLLHOOKSTRUCT *)lParam; - - switch(wParam) { - case WM_MOUSEMOVE: { - /* char vx[3],vy[3]; - _itoa(10,vy,10); - _itoa(ResizeSwitch,vx,10); - MessageBox(AdvancedDialog, - _(vx), _(vy), MB_OK | MB_ICONWARNING);*/ - switch(ResizeSwitch) - { - case 1: - { - int dx = MouseX - mhs->pt.x; - CompListWidth += dx; - if(CompListWidth < 50) CompListWidth = 50; - MouseX = mhs->pt.x; - AdvancedDialogResized(); - break; - } - case 2: - { - int dy = MouseY - mhs->pt.y; - NamingListHeight += dy; - if(NamingListHeight < 50) NamingListHeight = 50; - MouseY = mhs->pt.y; - AdvancedDialogResized(); - } - break; - } - break; - } - - case WM_LBUTTONUP: - ResizeSwitch = 0; - UnhookWindowsHookEx(MouseHookHandle); - break; - } - break; - } - } - return CallNextHookEx(MouseHookHandle, code, wParam, lParam); -} - -static void ProcessAdvancedMenu(int code) -{ - switch(code) { - case MNU_ADV_SIMULATION_MODE: - ToggleSimulationMode(); - ToggleAdvancedSimulationMode(); - break; - - case MNU_ADV_START_SIMULATION: - StartSimulation(); - StartAdvSimulation(); - break; - - case MNU_ADV_STOP_SIMULATION: - StopSimulation(); - StopAdvSimulation(); - break; - - case MNU_ADV_SINGLE_CYCLE: - SimulateOneCycle(TRUE); - SimulateOneAdvCycle(TRUE); - break; - default: - return; - } -} - -void ToggleAdvancedSimulationMode() -{ - - if(InSimulationMode) { - SimulationStarted = TRUE; - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_START_SIMULATION, MF_ENABLED); - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_SINGLE_CYCLE, MF_ENABLED); - - EnableMenuItem(AdvancedFileMenu, MNU_ADV_OPEN, MF_GRAYED); - EnableMenuItem(AdvancedFileMenu, MNU_ADV_SAVE, MF_GRAYED); - EnableMenuItem(AdvancedFileMenu, MNU_ADV_SAVE_AS, MF_GRAYED); - EnableMenuItem(AdvancedFileMenu, MNU_ADV_NEW, MF_GRAYED); - - EnableMenuItem(AdvancedTopMenu, 1, MF_GRAYED | MF_BYPOSITION); - /*EnableMenuItem(AdvancedTopMenu, 2, MF_GRAYED | MF_BYPOSITION); - EnableMenuItem(AdvancedTopMenu, 3, MF_GRAYED | MF_BYPOSITION); - EnableMenuItem(AdvancedTopMenu, 5, MF_GRAYED | MF_BYPOSITION);*/ - - CheckMenuItem(AdvancedSimulateMenu, MNU_ADV_SIMULATION_MODE, MF_CHECKED); - - // ClearSimulationData(); - // Recheck InSimulationMode, because there could have been a compile - // error, which would have kicked us out of simulation mode. - /*if(UartFunctionUsed() && InSimulationMode) { - ShowUartSimulationWindow(); - }*/ - } else { - // RealTimeSimulationRunning = FALSE; - //KillTimer(MainWindow, TIMER_SIMULATE); - - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_START_SIMULATION, MF_GRAYED); - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_STOP_SIMULATION, MF_GRAYED); - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_SINGLE_CYCLE, MF_GRAYED); - - EnableMenuItem(AdvancedFileMenu, MNU_ADV_OPEN, MF_ENABLED); - EnableMenuItem(AdvancedFileMenu, MNU_ADV_SAVE, MF_ENABLED); - EnableMenuItem(AdvancedFileMenu, MNU_ADV_SAVE_AS, MF_ENABLED); - EnableMenuItem(AdvancedFileMenu, MNU_ADV_NEW, MF_ENABLED); - - EnableMenuItem(AdvancedTopMenu, 1, MF_ENABLED | MF_BYPOSITION); - /*EnableMenuItem(AdvancedTopMenu, 2, MF_ENABLED | MF_BYPOSITION); - EnableMenuItem(AdvancedTopMenu, 3, MF_ENABLED | MF_BYPOSITION); - EnableMenuItem(AdvancedTopMenu, 5, MF_ENABLED | MF_BYPOSITION);*/ - - CheckMenuItem(AdvancedSimulateMenu, MNU_ADV_SIMULATION_MODE, MF_UNCHECKED); - SimulationStarted = FALSE; - - /*if(UartFunctionUsed()) { - DestroyUartSimulationWindow(); - }*/ - } - - // UpdateMainWindowTitleBar(); - - DrawMenuBar(AdvancedDialog); - InvalidateRect(AdvancedDialog, NULL, FALSE); - // ListView_RedrawItems(, 0, Prog.io.count - 1); -} - -static void CALLBACK DoubleClickProc(HWND hWnd, UINT msg, UINT Id, DWORD sysTime) -{ - KillTimer(AdvancedWorkspace, TIMERID); - if(Clicked) - { - Clicked = FALSE; - } - // MessageBox(AdvancedDialog, "Double click duration", "Mouse Clicked", MB_OK | MB_ICONWARNING); -} - -//----------------------------------------------------------------------------- -// Window procedure for Advanced Simulation Dialog Box -//----------------------------------------------------------------------------- -static LRESULT CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - switch (msg) { - case WM_NOTIFY: { - NMHDR *h = (NMHDR *)lParam; - if(h->hwndFrom == ComponentList) { - ComponentListProc(h); - } - if(h->hwndFrom == NamingList) { - NamingListProc(h); - } - return 0; - break; - } - - case WM_COMMAND: { - HWND h = (HWND)lParam; - if(h == OkButton && wParam == BN_CLICKED) { - AdvDialogDone = TRUE; - } else if(h == CancelButton && wParam == BN_CLICKED) { - AdvDialogDone = TRUE; - AdvDialogCancel = TRUE; - } - ProcessAdvancedMenu(LOWORD(wParam)); - break; - } - case WM_PAINT: { - RECT r; - PAINTSTRUCT ps; - Hdc = BeginPaint(hwnd, &ps); - // Draw the splitter thing to grab to resize componentList - GetClientRect(AdvancedDialog, &r); - r.left = AdvWrkspRight + 1; - r.right = AdvWrkspRight + 2; - FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); - r.left = AdvWrkspRight - 1; - r.right = AdvWrkspRight; - FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); - r.left = AdvWrkspRight; - r.right = AdvWrkspRight + 1; - FillRect(Hdc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH)); - EndPaint(hwnd, &ps); - - // Draw the splitter thing to grab to resize componentList - GetClientRect(AdvancedDialog, &r); - r.top = AdvWrkspBottom + 1; - r.bottom = AdvWrkspBottom + 2; - FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); - r.top = AdvWrkspBottom - 1; - r.bottom = AdvWrkspBottom; - FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); - r.top = AdvWrkspBottom; - r.bottom = AdvWrkspBottom + 1; - FillRect(Hdc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH)); - EndPaint(hwnd, &ps); - return 1; - } - case WM_LBUTTONDOWN: { - // MessageBox(AdvancedDialog, - // _("Mouse Button Clicked"), _("Mouse click"), MB_OK | MB_ICONWARNING); - int x = GET_X_LPARAM(lParam); - int y = GET_Y_LPARAM(lParam); - - POINT pt; - pt.x = x; pt.y = y; - ClientToScreen(AdvancedWorkspace, &pt); - MouseX = pt.x; - MouseY = pt.y; - if((x > (AdvWrkspRight - 9)) && (x < (AdvWrkspRight + 3))) { - - // char vx[3],vy[3]; - // _itoa(y,vy,10); - // _itoa(x,vx,10); - // MessageBox(AdvancedDialog, - // _(vx), _(vy), MB_OK | MB_ICONWARNING); - ResizeSwitch =1; - // InvalidateRect(AdvancedWorkspace, NULL, FALSE); - } - else if((y > (AdvWrkspBottom - 9)) && (y < (AdvWrkspBottom + 3))) - { - ResizeSwitch = 2; - } - if(ResizeSwitch > 0) - { - MouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, - (HOOKPROC)MouseHook, Instance, 0); - SetFocus(AdvancedWorkspace); - } - break; - } - case WM_MOUSEMOVE: { - int x = GET_X_LPARAM(lParam); - int y = GET_Y_LPARAM(lParam); - if((y >(AdvWrkspBottom - 9)) && (y < (AdvWrkspBottom + 3)) && (x < (AdvWrkspRight + 3))) - { - SetCursor(LoadCursor(NULL, IDC_SIZENS)); - } - else if((x > (AdvWrkspRight - 9)) && (x < (AdvWrkspRight + 3))) - { - SetCursor(LoadCursor(NULL, IDC_SIZEWE)); - } - else - { - SetCursor(LoadCursor(NULL, IDC_ARROW)); - } - break; - } - case WM_SIZE: - AdvancedDialogResized(); - break; - case WM_CLOSE: - case WM_DESTROY: - AdvancedWindowClosing(); - AdvDialogDone = TRUE; - AdvDialogCancel = TRUE; - break; - - default: - return DefWindowProc(hwnd, msg, wParam, lParam); - } - - return 1; -} - -//----------------------------------------------------------------------------- -// Window procedure for Advanced Workspace -// Black workspace area within the Advanced Dialog -//----------------------------------------------------------------------------- -static LRESULT CALLBACK AdvancedWrkspProc(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) { - AdvDialogDone = TRUE; - } else if(h == CancelButton && wParam == BN_CLICKED) { - AdvDialogDone = TRUE; - AdvDialogCancel = TRUE; - } - break; - } - case WM_CREATE:{ - // test=LoadBitmap(GetModuleHandle(NULL),"relay_nc.bmp"); - /*test = (HBITMAP) LoadBitmap (Instance, MAKEINTRESOURCE(RELAY_NC));//,IMAGE_BITMAP, - // 0,0, LR_LOADTRANSPARENT); - if(test ==NULL){ - MessageBox(hwnd, "Could not load Bitmap!", "Error", MB_OK | MB_ICONEXCLAMATION); - }*/ - /*testmask = CreateBitmapMask(test, RGB(255, 255, 255)); - if(testmask ==NULL){ - MessageBox(hwnd, "Could not create mask!", "Error", MB_OK | MB_ICONEXCLAMATION); - }*/ - } - break; - case WM_PAINT:{ - PAINTSTRUCT ps; - int i; - hdc = BeginPaint(hwnd, &ps); - for(i=0; i < ImagesDrawn; i++) - { - ImageList_Draw(ImageStack[i].Image->Images, 0, hdc, - ImageStack[i].x, ImageStack[i].y, ILD_TRANSPARENT); - } - // if(ComponentDiagrams == NULL){ - // InitializeImageList(); - // } - // InitializeComponentImage(0); - // DeleteDC(HdcMem); - EndPaint(hwnd, &ps); - } - break; - case WM_LBUTTONDOWN:{ - // left button down - int x = GET_X_LPARAM(lParam); - int y = GET_Y_LPARAM(lParam); - if(!SimulationStarted) - { - // char vx[3],vy[3]; - // _itoa(y,vy,10); - // _itoa(x,vx,10); - // MessageBox(AdvancedDialog, _(vx), _(vy), MB_OK | MB_ICONWARNING); - BeginComponentDrag(x, y); - } - else{ - // Send message to respective component - - } - ProcessEvent(x, y, EVENT_MOUSE_DOWN); - } - break; - case WM_LBUTTONUP:{ - int x = GET_X_LPARAM(lParam); - int y = GET_Y_LPARAM(lParam); - if(!SimulationStarted){ - EndComponentDrag(x, y); - } - else{ - // Send message to respective component - ProcessEvent(x, y, EVENT_MOUSE_UP); - } - // if((DragX < (x + 3)) && (DragX > (x-3)) && (DragY < (y + 3)) && (DragY > (y-3))) - { - /*MessageBox(NULL, - ("Reached"), ("Info"), MB_OK | MB_ICONWARNING);*/ - ProcessEvent(x, y, EVENT_MOUSE_CLICK); - // char vx[3],vy[3]; - // _itoa(y,vy,10); - // _itoa(x,vx,10); - // MessageBox(AdvancedDialog, _(vx), _(vy), MB_OK | MB_ICONWARNING); - // MessageBox(AdvancedDialog, "Mouse Clicked", "Mouse Clicked", MB_OK | MB_ICONWARNING); - } - } - break; - // case WM_LBUTTONDBLCLK: - // { - // int x = GET_X_LPARAM(lParam); - // int y = GET_Y_LPARAM(lParam); - // // MessageBox(AdvancedDialog, "Mouse DoubleClicked", "Mouse Double Clicked", MB_OK | MB_ICONWARNING); - // if(SimulationStarted){ - // // Send message to respective component - // } - // else - // { - // } - // ProcessEvent(x, y, EVENT_MOUSE_DBLCLICK); - // } - // break; - case WM_RBUTTONUP: - { - int x = GET_X_LPARAM(lParam); - int y = GET_Y_LPARAM(lParam); - if(!SimulationStarted) - { - // Get Pin Parameters Here - } - ProcessEvent(x,y,EVENT_MOUSE_RCLICK); - } - break; - case WM_MOUSEMOVE:{ - int x = GET_X_LPARAM(lParam); - int y = GET_Y_LPARAM(lParam); - ComponentDrag(x, y); - } - break; - // case WM_SIZE: - // AdvancedDialogResized(); - // break; - case WM_CLOSE: - case WM_DESTROY:{ - AdvDialogDone = TRUE; - AdvDialogCancel = TRUE; - // HeapDestroy(ImageHeap); - } - break; - - default: - return DefWindowProc(hwnd, msg, wParam, lParam); - } - - return 1; -} -/*HBITMAP CreateBitmapMask(HBITMAP hbmColour, COLORREF crTransparent) -{ - HDC HdcMem, HdcMem2; - HBITMAP HbmMask; - BITMAP bm; - // Create monochrome (1 bit) mask bitmap. - GetObject(hbmColour, sizeof(BITMAP), &bm); - HbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL); - // Get some HDCs that are compatible with the display driver - HdcMem = CreateCompatibleDC(0); - HdcMem2 = CreateCompatibleDC(0); - SelectObject(HdcMem, hbmColour); - SelectObject(HdcMem2, HbmMask); - // Set the background colour of the colour image to the colour - // you want to be transparent. - SetBkColor(HdcMem, crTransparent); - - BitBlt(HdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, HdcMem, 0, 0, SRCCOPY); - BitBlt(HdcMem, 0, 0, bm.bmWidth, bm.bmHeight, HdcMem2, 0, 0, SRCINVERT); - DeleteDC(HdcMem); - DeleteDC(HdcMem2); - return HbmMask; -}*/ - -//----------------------------------------------------------------------------- -//Create dialog box classes specifically for Advanced Simulation -//----------------------------------------------------------------------------- - -void MakeAdvancedDialogClass(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)AdvancedDlgProc; - wc.hInstance = Instance; - wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.lpszClassName = "AdvancedDialog"; - wc.lpszMenuName = NULL; - wc.hCursor = LoadCursor(NULL, IDC_SIZEWE); - wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), - IMAGE_ICON, 32, 32, 0); - wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), - IMAGE_ICON, 16, 16, 0); - - RegisterClassEx(&wc); - - AdvNiceFont = CreateFont(16, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FF_DONTCARE, "Tahoma"); - if(!AdvNiceFont) - AdvNiceFont = (HFONT)GetStockObject(SYSTEM_FONT); - - AdvFixedFont = 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(!AdvFixedFont) - AdvFixedFont = (HFONT)GetStockObject(SYSTEM_FONT); -} - -void MakeAdvancedWorkspaceClass(void) -{ - WNDCLASSEX wc; - memset(&wc, 0, sizeof(wc)); - wc.cbSize = sizeof(wc); - - wc.style = CS_BYTEALIGNWINDOW | CS_BYTEALIGNWINDOW | CS_OWNDC; - wc.lpfnWndProc = (WNDPROC)AdvancedWrkspProc; - wc.hInstance = Instance; - wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.lpszClassName = "AdvancedWorkspace"; - wc.lpszMenuName = NULL; - RegisterClassEx(&wc); - -} -void MakeComponentListClass(void) -{ - WNDCLASSEX wc; - memset(&wc, 0, sizeof(wc)); - wc.cbSize = sizeof(wc); - - wc.style = CS_BYTEALIGNWINDOW | CS_BYTEALIGNWINDOW | CS_OWNDC | - CS_DBLCLKS; - wc.lpfnWndProc = (WNDPROC)AdvancedWrkspProc; - wc.hInstance = Instance; - // wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.lpszClassName = "ComponentList"; - // wc.lpszMenuName = NULL; - RegisterClassEx(&wc); -} - -void MakeNamingListClass(void) -{ - WNDCLASSEX wc; - memset(&wc, 0, sizeof(wc)); - wc.cbSize = sizeof(wc); - - wc.style = CS_BYTEALIGNWINDOW | CS_BYTEALIGNWINDOW | CS_OWNDC | - CS_DBLCLKS; - wc.lpfnWndProc = (WNDPROC)AdvancedDlgProc; - wc.hInstance = Instance; - // wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wc.lpszClassName = "NamingList"; - // wc.lpszMenuName = NULL; - RegisterClassEx(&wc); -} - -void ShowAdvancedDialog() -{ - // int itmcount = Prog.io.count; - // char vx[3],vy[3]; - // _itoa(10,vy,10); - // _itoa(itmcount,vx,10); - // MessageBox(MainWindow, - // _(vx), _(vy), MB_OK | MB_ICONWARNING); - if(AdvancedWindowOpen) - { - return; - } - ComponentPin.Count = 0; - ImageHeap = HeapCreate(0, 1024*64, 0); - MakeAdvancedWindowMenus(); - AdvancedDialog = CreateWindowClient(WS_EX_CONTROLPARENT, "AdvancedDialog", - _("Advanced Simulation Mode"), WS_OVERLAPPED | WS_SYSMENU - | WS_THICKFRAME | WS_CLIPCHILDREN | WS_SIZEBOX, - 10 , 10 , 800 , 600 , NULL , AdvancedTopMenu , Instance , NULL ); - InitComponents(); - RECT r; - CompListWidth = 160; - MakeAdvancedDialogControls(); - // AdvancedDialogResized(); - //RefreshDialogScrollbars(); - GetClientRect(AdvancedDialog , &r ); - - // EnableWindow(MainWindow, FALSE); - ShowWindow(AdvancedDialog, SW_SHOW); - AdvancedWindowOpen = TRUE; - ToggleAdvancedSimulationMode(); - - MSG msg; - DWORD ret; - AdvDialogDone = FALSE; - AdvDialogCancel = FALSE; - while((ret = GetMessage(&msg, NULL, 0, 0)) && !AdvDialogDone) { - // if(msg.message == WM_KEYDOWN) { - // if(msg.wParam == VK_RETURN) { - // AdvDialogDone = TRUE; - // break; - // } else if(msg.wParam == VK_ESCAPE) { - // AdvDialogDone = TRUE; - // AdvDialogCancel = TRUE; - // break; - // } - // } - - if(IsDialogMessage(AdvancedDialog , &msg)) continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - // EnableWindow(MainWindow, TRUE); - DestroyWindow(AdvancedDialog); - AdvancedWindowOpen = FALSE; - return; -} - -void MakeAdvancedDialogControls(void) -{ - LVCOLUMN lvc; - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - lvc.fmt = LVCFMT_LEFT; -#define LV_ADD_COLUMN(hWnd, i, w, s) do { \ - lvc.iSubItem = i; \ - lvc.pszText = s; \ - lvc.iOrder = 0; \ - lvc.cx = w; \ - ListView_InsertColumn(hWnd, i, &lvc); \ - } while(0) - - AdvancedWorkspace = CreateWindowEx(WS_EX_CLIENTEDGE, "AdvancedWorkspace", "", - WS_CHILD | WS_CLIPSIBLINGS | WS_TABSTOP, - 0 , 0 , 640 , 600 , AdvancedDialog , NULL , Instance , NULL ); - - ComponentList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "ComponentList", WS_CHILD | - LVS_REPORT | LVS_NOSORTHEADER | LVS_SORTASCENDING | LVS_SHOWSELALWAYS | WS_TABSTOP | - LVS_SINGLESEL | WS_CLIPSIBLINGS, - 12, 25, 300, 300, AdvancedDialog, NULL, Instance, NULL); - ListView_SetExtendedListViewStyle(ComponentList, LVS_EX_FULLROWSELECT); - LV_ADD_COLUMN(ComponentList, 0, 150, _("Components")); - ComponentListInitiate(); - - NamingList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "NamingList", WS_CHILD | - LVS_REPORT | LVS_NOSORTHEADER | LVS_SORTASCENDING | LVS_SHOWSELALWAYS | WS_TABSTOP | - LVS_SINGLESEL | WS_CLIPSIBLINGS, 312, 325, 300, 300, AdvancedDialog, NULL, Instance, NULL); - LV_ADD_COLUMN(NamingList, 0, 250, _("Name")); - LV_ADD_COLUMN(NamingList, 1, 100, _("State/Volt")); - LV_ADD_COLUMN(NamingList, 2, 100, _("Pin on Processor")); - LV_ADD_COLUMN(NamingList, 3, 100, _("MCU Port")); - PopulateNamingList(); - RefreshNamingList(); - // HorizScrollBar = CreateWindowEx(0, WC_SCROLLBAR, "", WS_CHILD | - // SBS_HORZ | SBS_BOTTOMALIGN | WS_VISIBLE | WS_CLIPSIBLINGS, - // 100, 100, 100, 100, AdvancedDialog, NULL, Instance, NULL); - // VertScrollBar = CreateWindowEx(0, WC_SCROLLBAR, "", WS_CHILD | - // SBS_VERT | SBS_LEFTALIGN | WS_VISIBLE | WS_CLIPSIBLINGS, - // 200, 100, 100, 100, AdvancedDialog, NULL, Instance, NULL); - // RECT scroll; - // GetWindowRect(HorizScrollBar, &scroll); - // ScrollHeight = scroll.bottom - scroll.top; - // GetWindowRect(VertScrollBar, &scroll); - // ScrollWidth = scroll.right - scroll.left; - /*ComponentList = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("listbox"), "Test", WS_CHILD - | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL | WS_CLIPSIBLINGS | WS_TABSTOP, - 240, 40, 150, 20, AdvancedDialog, NULL, Instance, NULL); - SendMessage(ComponentList, LB_ADDSTRING, 0, (LPARAM)"name"); - SendMessage(ComponentList, LB_ADDSTRING, 0, (LPARAM)"extension"); - SendMessage(ComponentList, LB_ADDSTRING, 0, (LPARAM)"date"); - SendMessage(ComponentList, LB_ADDSTRING, 0, (LPARAM)"size");*/ - ShowWindow(AdvancedWorkspace, SW_SHOW); - ShowWindow(ComponentList, SW_SHOW); - ShowWindow(NamingList, SW_SHOW); -} - -void AdvancedDialogResized(void) -{ - RECT AdvDial; - GetClientRect(AdvancedDialog, &AdvDial); - - if(CompListWidth < 30) { - CompListWidth = 30; - } - if(CompListWidth > AdvDial.right - 250){ - CompListWidth = AdvDial.right - 250; - } - if(NamingListHeight < 30) { - NamingListHeight = 30; - } - if(NamingListHeight > AdvDial.bottom - 250){ - NamingListHeight = AdvDial.bottom - 250; - } - AdvWrkspRight = AdvDial.right - CompListWidth; - AdvWrkspBottom = AdvDial.bottom - NamingListHeight; - MoveWindow(AdvancedWorkspace, 0, 0, - AdvWrkspRight - 1, AdvWrkspBottom - 1, TRUE); - MoveWindow(ComponentList, AdvWrkspRight + 2, 0, - CompListWidth, AdvDial.bottom, TRUE); - MoveWindow(NamingList, 0, AdvWrkspBottom + 2, - AdvWrkspRight - 1, AdvDial.bottom - AdvWrkspBottom - 2, TRUE); - ListView_SetColumnWidth(ComponentList, 0, AdvDial.right - AdvWrkspRight - 5); -} - -void MakeAdvancedWindowMenus(void) -{ - AdvancedFileMenu = CreatePopupMenu(); - AppendMenu(AdvancedFileMenu, MF_STRING, MNU_ADV_NEW, _("&New\tCtrl+N")); - AppendMenu(AdvancedFileMenu, MF_STRING, MNU_ADV_OPEN, _("&Open...\tCtrl+O")); - AppendMenu(AdvancedFileMenu, MF_STRING, MNU_ADV_SAVE, _("&Save\tCtrl+S")); - AppendMenu(AdvancedFileMenu, MF_STRING, MNU_ADV_SAVE_AS, _("Save &As...")); - AppendMenu(AdvancedFileMenu, MF_SEPARATOR, 0, ""); - AppendMenu(AdvancedFileMenu, MF_STRING, MNU_EXIT, _("E&xit")); - - AdvancedEditMenu = CreatePopupMenu(); - AppendMenu(AdvancedEditMenu, MF_STRING, MNU_ADV_UNDO, _("&Undo\tCtrl+Z")); - AppendMenu(AdvancedEditMenu, MF_STRING, MNU_ADV_REDO, _("&Redo\tCtrl+Y")); - AppendMenu(AdvancedEditMenu, MF_SEPARATOR, 0, NULL); - AppendMenu(AdvancedEditMenu, MF_STRING, MNU_ADV_CUT, _("Cu&t\tCtrl+X")); - AppendMenu(AdvancedEditMenu, MF_STRING, MNU_ADV_COPY, _("&Copy\tCtrl+C")); - AppendMenu(AdvancedEditMenu, MF_STRING, MNU_ADV_PASTE, _("&Paste\tCtrl+V")); - AppendMenu(AdvancedEditMenu, MF_SEPARATOR, 0, NULL); - AppendMenu(AdvancedEditMenu, MF_STRING, MNU_ADV_DEL, _("De&lete\tCtrl+Y")); - - AdvancedSimulateMenu = CreatePopupMenu(); - AppendMenu(AdvancedSimulateMenu, MF_STRING, MNU_ADV_SIMULATION_MODE, - _("Si&mulation Mode\tCtrl+M")); - AppendMenu(AdvancedSimulateMenu, MF_STRING | MF_GRAYED, - MNU_ADV_START_SIMULATION, _("Start &Real-Time Simulation\tCtrl+R")); - AppendMenu(AdvancedSimulateMenu, MF_STRING | MF_GRAYED, - MNU_ADV_STOP_SIMULATION, _("&Halt Simulation\tCtrl+H")); - AppendMenu(AdvancedSimulateMenu, MF_STRING | MF_GRAYED, - MNU_ADV_SINGLE_CYCLE, _("Single &Cycle\tSpace")); - - AdvancedHelpMenu = CreatePopupMenu(); - AppendMenu(AdvancedHelpMenu, MF_STRING, MNU_ADV_MANUAL, _("&Manual...\tF1")); - AppendMenu(AdvancedHelpMenu, MF_STRING, MNU_ADV_ABOUT, _("&About...")); - - AdvancedTopMenu = CreateMenu(); - AppendMenu(AdvancedTopMenu, MF_STRING | MF_POPUP, - (UINT_PTR)AdvancedFileMenu, _("&File")); - AppendMenu(AdvancedTopMenu, MF_STRING | MF_POPUP, - (UINT_PTR)AdvancedEditMenu, _("&Edit")); - AppendMenu(AdvancedTopMenu, MF_STRING | MF_POPUP, - (UINT_PTR)AdvancedSimulateMenu, _("Si&mulate")); - AppendMenu(AdvancedTopMenu, MF_STRING | MF_POPUP, - (UINT_PTR)AdvancedHelpMenu, _("&Help")); - -} - -void ProcessEvent(int x, int y, int Event) -{ - int i = 0; - switch(Event) - { - case EVENT_MOUSE_CLICK: - { - if(Clicked) - { - KillTimer(AdvancedWorkspace, TIMERID); - Event = EVENT_MOUSE_DBLCLICK; - Clicked = FALSE; - }else - { - Clicked = TRUE; - DblClickTimer = SetTimer(AdvancedWorkspace, TIMERID, - GetDoubleClickTime(), DoubleClickProc); - } - break; - } - } - - for(i = 0; i < ImagesDrawn; i++) - { - if((((ImageStack[i].x + COMPONENT_WIDTH) > x) && - (ImageStack[i].x < x) && - (ImageStack[i].y < y) && - ((ImageStack[i].y + COMPONENT_HEIGHT) > y))) - { - /*char Debug[256]; - sprintf_s(Debug, "Editing Component Address: %p\n",ImageStack[i].Properties); - OutputDebugString(Debug);*/ - NotifyComponent(ImageStack[i].Properties, ImageStack[i].PinName, - ImageStack[i].Image->ComponentId, Event, SimulationStarted, - &AdvancedDialog, ImageStack[i].Index, ImageStack[i].Id, - &ImageStack[i].Image->Images); //Replace Image in Imagelist here - } - } -} - -void* AllocImageHeap(size_t n) -{ - void *p = HeapAlloc(ImageHeap, HEAP_ZERO_MEMORY, n); - return p; -} - -void* ReallocImageHeap(LPVOID lpMem, size_t n) -{ - // char Debug[256]; - void *p = HeapReAlloc(ImageHeap, HEAP_ZERO_MEMORY, - lpMem, n); - if(p == NULL) - { - /*sprintf_s(Debug, "Cannot Reallocate Memory\n"); - OutputDebugString(Debug);*/ - return lpMem; - } - return p; -} - -void FreeImageHeap(void *p) -{ - HeapFree(ImageHeap, 0, p); -} - -void SetMcu(int PinId, int Type) -{ - UINT i; - for(i=0; i<MCUCount; i++) - { - if(McuPin[i].PinId == PinId) - { - McuPin[i].type = Type; - McuPin[i].InternalPullup = TRUE; - return; - } - } - McuPin[MCUCount].type = Type; - McuPin[MCUCount].InternalPullup = TRUE; - McuPin[MCUCount++].PinId = PinId; - /*char vx[3],vy[3]; - _itoa(MCUCount,vy,10); - _itoa(McuPin[MCUCount].type,vx,10); - MessageBox(NULL, - _("SetMcu"), _(vx), MB_OK | MB_ICONWARNING);*/ -} - -void ToggleInternalPullup(int PinId) -{ - for(UINT i=0;i<MCUCount;i++) - { - if(McuPin[i].PinId == PinId) - { - McuPin[i].InternalPullup = !(McuPin[i].InternalPullup); - } - } -} - -int RegisterPinName(LPCTSTR Name) -{ - UINT i; - if(Name[0] == 0) - { - return 0; - } - for(i=0; i<NameCount; i++) - { - if((strcmp(NameId[i].Name, Name)) == 0) - { - return NameId[i].PinId; - } - } - // NameId[NameCount].PinData->ImageId = (void**)AllocImageHeap(sizeof(void*)); - NameId[NameCount].PinData.ImageId = (void**)AllocImageHeap(sizeof(void*)); - NameId[NameCount].PinData.ImageType = (int*)AllocImageHeap(sizeof(int)); - NameId[NameCount].PinData.Index = (int*)AllocImageHeap(sizeof(int)); - // NameId[NameCount].PinData = &PinData[NameCount]; - NameId[NameCount].PinData.LinkCount = 0; - //SetMcu(NameCount, ImageId); - NameId[NameCount].PinId = ++UniquePinId; - - if (sizeof(TCHAR) == sizeof(char)) // String is non-unicode - strcpy(NameId[NameCount].Name, (char*)(Name)); - else // String is unicode - wcstombs(NameId[NameCount].Name, (wchar_t*)Name, MAX_NAME_LENGTH); - // MessageBox(AdvancedDialog, (LPCTSTR)NameId[NameCount].Name, "Registered", MB_OK | MB_ICONWARNING); - - /*char vx[3],vy[3]; - _itoa(10,vy,10); - _itoa(NameId[NameCount].PinId,vx,10); - MessageBox(AdvancedDialog, - _(vx), Name, MB_OK | MB_ICONWARNING);*/ - NameCount++; - RefreshNamingList(); - return NameId[i].PinId; -} -int DeletePinImage(LPCTSTR Name, void* ImageId, int Index) -{ - UINT i; - int Count, j, index; - int PinId = -1; - void* Value; - - if(Name[0] == 0) - { - return PinId; - } - for(i=0; i<NameCount; i++) - { - if((strcmp(NameId[i].Name, Name)) == 0) - { - PinId = NameId[i].PinId; - Count = NameId[i].PinData.LinkCount; - if(Count == 0) - { - DeletePinName(i); - return PinId; - } - /*char vx[3],vy[3]; - // _itoa(Index,vy,10); - _itoa(Count,vx,10); - MessageBox(AdvancedDialog, - _(vx), "Deleting", MB_OK | MB_ICONWARNING);*/ - for(j =0; j < Count; j++) - { - Value =(void*) NameId[i].PinData.ImageId[j]; - index = NameId[i].PinData.Index[j]; - /*char vx[20],vy[3]; - // _itoa(Index,vy,10); - _itoa((int)Value,vx,10); - MessageBox(AdvancedDialog, - _(vx), "Deleting", MB_OK | MB_ICONWARNING);*/ - if((ImageId == Value) /*&& (Index == index)*/) - { - // MessageBox(NULL,"Value found","Info",MB_OK|MB_ICONWARNING); - if(index==Index) - { - NameId[i].PinData.ImageId[j] = - NameId[i].PinData.ImageId[--Count]; - NameId[i].PinData.ImageType[j] = - NameId[i].PinData.ImageType[Count]; - NameId[i].PinData.Index[j] = - NameId[i].PinData.Index[Count]; - NameId[i].PinData.LinkCount = Count; - NameId[i].PinData.ImageId = - (void**)ReallocImageHeap( - (void**)NameId[i].PinData.ImageId, - (Count * sizeof(void*))); - NameId[i].PinData.ImageType = - (int*)ReallocImageHeap(NameId[i].PinData.ImageType, - (Count * sizeof(int))); - NameId[i].PinData.Index = - (int*)ReallocImageHeap(NameId[i].PinData.Index, - (Count * sizeof(int))); - /*char Debug[256]; - sprintf_s(Debug, "Deleting Index[%d]", j); - OutputDebugString(Debug);*/ - /*char vx[3],vy[3]; - // _itoa(Index,vy,10); - _itoa(Count,vx,10); - MessageBox(AdvancedDialog, - _(vx), "Deleting", MB_OK | MB_ICONWARNING);*/ - /*char vx[3],vy[3]; - _itoa(Index,vy,10); - _itoa(Count,vx,10); - MessageBox(AdvancedDialog, - _(vx), _(vy), MB_OK | MB_ICONWARNING);*/ - if(Count == 0) - { - DeletePinName(i); - } - return PinId; - } - } - } - } - } - return -1; -} - -int DeleteComponentPin(int PinId, void* ComponentAddress) -{ - PinComponent* temp = (PinComponent*)ComponentPin.Next; - PinComponent* Prev = &ComponentPin; - if(ComponentPin.PinId == NULL) - { - return -1; - } - else if(ComponentPin.PinId == PinId) - { - for(int i=0;i<ComponentPin.Count;i++) - { - if(ComponentPin.ComponentAddress[i] == ComponentAddress) - { - ComponentPin.ComponentAddress[i] = - ComponentPin.ComponentAddress[(--ComponentPin.Count)]; - ReallocImageHeap(ComponentPin.ComponentAddress, - sizeof(void*)*ComponentPin.Count); - return PinId; - } - } - if(ComponentPin.Count == 0) - { - if(ComponentPin.Next == NULL) - { - ComponentPin.PinId = NULL; - return PinId; - } - else - { - ComponentPin = *temp; - FreeImageHeap((void*)temp); - } - return PinId; - } - } - else - { - while(temp != NULL) - { - if(temp->PinId == PinId) - { - for(int i=0; i<temp->Count; i++) - { - if(temp->ComponentAddress[i] == ComponentAddress) - { - if(temp->Count == 1) - { - Prev->Next = temp->Next; - FreeImageHeap((void*)temp); - } - else - { - temp->ComponentAddress[i] = - temp->ComponentAddress[ - (--temp->Count)]; - ReallocImageHeap(temp->ComponentAddress, - sizeof(void*) * (temp->Count)); - return PinId; - } - } - Prev = temp; - temp = (PinComponent*)temp->Next; - } - } - } - } - return -1; -} -int AddComponentPin(int PinId, void* ComponentAddress) -{ - PinComponent* temp = (PinComponent*)ComponentPin.Next; - if(ComponentPin.PinId == NULL) - { - ComponentPin.PinId = PinId; - ComponentPin.Count = 1; - ComponentPin.ComponentAddress = (void**)AllocImageHeap(sizeof(void*)); - ComponentPin.ComponentAddress[0] = ComponentAddress; - return PinId; - } - else if(ComponentPin.PinId == PinId) - { - ComponentPin.ComponentAddress = (void**)ReallocImageHeap( - (void*)ComponentPin.ComponentAddress, - (sizeof(void*)) * (++ComponentPin.Count)); - ComponentPin.ComponentAddress[(ComponentPin.Count-1)] =ComponentAddress; - return PinId; - } - else - { - PinComponent* Prev = &ComponentPin; - while(temp != NULL) - { - if(temp->PinId == PinId) - { - temp->ComponentAddress = (void**)ReallocImageHeap( - (void*)ComponentPin.ComponentAddress, - (sizeof(void*) * (++ComponentPin.Count))); - temp->ComponentAddress[ - (ComponentPin.Count-1)] = ComponentAddress; - return PinId; - } - Prev = temp; - temp = (PinComponent*) temp->Next; - } - temp = (PinComponent*) AllocImageHeap(sizeof(PinComponent)); - temp->PinId =PinId; - temp->ComponentAddress = (void**)AllocImageHeap(sizeof(void*)); - temp->Count = 1; - temp->ComponentAddress[0] = ComponentAddress; - Prev->Next = (void*)temp; - return PinId; - } - return -1; -} - -int SetPinImage(int PinId, void* ImageId, int ImageType, int Index) -{ - UINT i,j, Count; - void* Value; - int index; - for(i=0; i<NameCount; i++) - { - if(NameId[i].PinId == PinId) - { - Count = NameId[i].PinData.LinkCount; - for(j =0; j<Count; j++) - { - Value =(void*) NameId[i].PinData.ImageId[j]; - index = NameId[i].PinData.Index[j]; - if((ImageId == Value) && (index == Index)) - { - /*char Debug[256]; - sprintf_s(Debug, "Already Exists\n"); - OutputDebugString(Debug);*/ - return NameId[i].PinId; - } - } - NameId[i].PinData.LinkCount = ++Count; - NameId[i].PinData.ImageId = - (void**)ReallocImageHeap((void**)NameId[i].PinData.ImageId, - (Count) * sizeof(void*)); - NameId[i].PinData.ImageType = - (int*)ReallocImageHeap(NameId[i].PinData.ImageType, - (Count) * sizeof(int)); - NameId[i].PinData.Index = - (int*)ReallocImageHeap(NameId[i].PinData.Index, - (Count) * sizeof(int)); - NameId[i].PinData.ImageId[Count-1] = ImageId; - NameId[i].PinData.ImageType[Count-1] = ImageType; - NameId[i].PinData.Index[Count-1] = Index; - /*char Debug[256]; - sprintf_s(Debug, "Adding ImageId[%d]: %p \t Previous: %p\n", - Count-1,NameId[i].PinData.ImageId[Count-1],NameId[i].PinData.ImageId[0]); - OutputDebugString(Debug);*/ - /*for(j =0; j<Count; j++) - { - char vx[20],vy[3]; - // _itoa(Index,vy,10); - _itoa((int)NameId[i].PinData.ImageId[j],vx,10); - MessageBox(AdvancedDialog, - _(vx), "Count", MB_OK | MB_ICONWARNING); - }*/ - /*char vx[20],vy[3]; - // _itoa(Index,vy,10); - _itoa((int)ImageId,vx,10); - MessageBox(AdvancedDialog, - _(vx), "Count", MB_OK | MB_ICONWARNING);*/ - return NameId[i].PinId; - } - } - return -1; -} - -int DeletePinName(UINT Index) -{ - UINT i; - UINT PinId = NameId[Index].PinId; - for(i=0;i<MCUCount;i++) - { - if(PinId == McuPin[i].PinId) - { - return 0; - } - } - FreeImageHeap(NameId[Index].PinData.ImageId); - FreeImageHeap(NameId[Index].PinData.ImageType); - FreeImageHeap(NameId[Index].PinData.Index); - NameId[Index] = NameId[--NameCount]; - RefreshNamingList(); - return 1; -} - -void AdvancedWindowClosing() -{ - FlushPinNames(); -} - -int FlushPinNames() -{ - UINT i; - int Count = 0; - for(i=0; i<NameCount && NameCount>0; i++) - { - if(NameId[i].PinData.LinkCount<=0) - { - // MessageBox(NULL, (LPCTSTR)NameId[i].Name,"Deleted", MB_OK | MB_ICONWARNING); - NameId[i--] = NameId[--NameCount]; - Count++; - } - } - RefreshNamingList(); - /*char vx[3],vy[3]; - _itoa(10,vy,10); - _itoa(NameCount,vx,10); - MessageBox(NULL, - _(vx), _(vy), MB_OK | MB_ICONWARNING);*/ - MCUCount =0; - return Count; -} - -void StartAdvSimulation() -{ - // RealTimeSimulationRunning = TRUE; - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_START_SIMULATION, MF_GRAYED); - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_STOP_SIMULATION, MF_ENABLED); - StartAdvSimulationTimer(); - - // UpdateMainWindowTitleBar(); -} - -//----------------------------------------------------------------------------- -// Stop real-time simulation. Have to update the controls grayed status -// to reflect this. -//----------------------------------------------------------------------------- -void StopAdvSimulation() -{ - // RealTimeSimulationRunning = FALSE; - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_START_SIMULATION, MF_ENABLED); - EnableMenuItem(AdvancedSimulateMenu, MNU_ADV_STOP_SIMULATION, MF_GRAYED); - KillTimer(MainWindow, TIMER_SIMULATE); - // UpdateMainWindowTitleBar(); -} - -void SimulateOneAdvCycle(BOOL ForceRefresh) -{ - static BOOL Simulating = FALSE; - if(Simulating) return; - Simulating = TRUE; - /*Code here*/ - Simulating = FALSE; -} - -void StartAdvSimulationTimer() -{ - int p = Prog.cycleTime/1000; - if(p < 5) - { - SetTimer(AdvancedDialog, TIMER_ADV_SIMULATE, 10, CycleAdvTimer); - CyclesPerTimerTick = 10000 / Prog.cycleTime; - }else - { - SetTimer(AdvancedDialog, TIMER_ADV_SIMULATE, p, CycleAdvTimer); - CyclesPerTimerTick = 1; - } -} - -void CALLBACK CycleAdvTimer(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) -{ - int i; - for(i = 0; i < CyclesPerTimerTick; i++) - { - SimulateOneAdvCycle(FALSE); - } -} - -// void CreateVoltRequest(int Index, double VoltReq) -// { -// void* Value; -// UINT Count,j; -// Count = NameId[Index].PinData.LinkCount; -// /*char vx[4],vy[4]; -// _itoa(NameId[i].PinData.Volt,vy,10); -// _itoa(VoltReq,vx,10); -// MessageBox(NULL, -// (vy), (vx), MB_OK | MB_ICONWARNING);*/ -// if(Count>0) -// { -// // MessageBox(NULL,"reached", "info", MB_OK | MB_ICONEXCLAMATION); -// for(j =0; j < Count; j++) -// { -// Value = (void*) NameId[Index].PinData.ImageId[j]; -// for(int k =0; k<ImagesDrawn; k++) -// { -// if(ImageStack[k].Properties == Value) -// { -// NameId[Index].PinData.Volt = VoltSet(Value, SimulationStarted, -// NameId[Index].PinData.ImageType[j], NameId[Index].PinData.Index[j], -// VoltReq, SOURCE_PROGRAM_MAIN, &ImageStack[k].Image->Images); -// NameId[Index].PinData.ProgVolt = NameId[Index].PinData.Volt; - -// } -// } -// } -// } - -// } - -void TranslateState(char *name, BOOL state) -{ - double VoltReq; - UINT i; - VoltReq = (double) (state ? VOLT_5 : GND); - for(i=0; i<NameCount; i++) - { - if((strcmp(NameId[i].Name, name)) == 0) - { - // CreateVoltRequest(i,VoltReq); - /*NameId[i].PinData.ProgVolt = RefreshVolt( - NameId[i].PinId, NULL, i, NULL, VoltReq);*/ - if((NameId[i].PinData.ProgVolt > VoltReq) || - (NameId[i].PinData.ProgComponent == &MainProgramComponent) || - (NameId[i].PinData.ProgComponent == NULL)) - { - NameId[i].PinData.ProgComponent = &MainProgramComponent; - if(VoltReq <= NameId[i].PinData.Volt) - { - NameId[i].PinData.ProgVolt = VoltReq; - /*char vx[3],vy[10]; - _gcvt(NameId[i].PinData.ProgVolt,10,vy); - _itoa(NameId[i].PinId,vx,10); - MessageBox(AdvancedDialog, - _(vy), _(NameId[i].Name), MB_OK | MB_ICONWARNING);*/ - /*sprintf_s(Debug, "Executing1: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - } - else - { - NameId[i].PinData.ProgVolt = NameId[i].PinData.Volt; - /*sprintf_s(Debug, "Executing2: \tVoltage:%f\n", - NameId[Id].PinData.Volt); - OutputDebugString(Debug);*/ - } - RefreshVolt(NameId[i].PinId, NULL, i, NULL, VoltReq); - /*sprintf_s(Debug, "Executing3: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - } - /*char Debug[256]; - sprintf_s(Debug, "TranslateState: %s: %f \n", name, VoltReq); - OutputDebugString(Debug);*/ - } - } -} - -void MCUPinState(char *name, BOOL state) -{ - double volt = (double) state?VOLT_5:GND; - for(UINT i=0; i<NameCount; i++) - { - if((strcmp(NameId[i].Name, name)) == 0) - { - NameId[i].PinData.ProgVolt = volt; - } - } -} - -int IsMCUPin(int PinId) -{ - UINT i; - for(i=0; i<MCUCount; i++) - { - if(McuPin[i].PinId == PinId) - { - return i; - } - } - return -1; -} - -/*double RequestVoltChange(int PinId, void *ComponentAddress, double volt) -{ - // Compare NameId.PinData.Imageid with component address, - and notify all other components of voltage change - char* Name; - int Pin; - // MessageBox(AdvancedDialog, "Test", "Pullup", MB_OK | MB_ICONWARNING); - for(unsigned int i =0;i<NameCount;i++) - { - if((NameId[i].PinId == PinId)) - { - /*char vx[3],vy[10]; - _gcvt(NameId[i].PinData.Volt,10,vy); - _itoa(PinId,vx,10); - MessageBox(AdvancedDialog, - _(vx), _(vy), MB_OK | MB_ICONWARNING); - if(NameId[i].PinData.Volt <= volt) - { - // MessageBox(NULL, "Returning", "Mouse Clicked", - MB_OK | MB_ICONWARNING); - return NameId[i].PinData.Volt; - } - Name = (char*)&NameId[i].Name; - int num = NameId[i].PinData.LinkCount; - Pin = i; - for(int j=0;j<num;j++) - { - if(!(ComponentAddress == NameId[i].PinData.ImageId[j])) - { - for(int k =0; k<ImagesDrawn; k++) - { - if(ImageStack[k].Properties == ComponentAddress) - { - if((NameId[i].PinData.ProgVolt > volt)) - { - NameId[i].PinData.ProgVolt = VoltRequest( - NameId[i].PinData.ImageId[j], - SimulationStarted, - NameId[i].PinData.ImageType[j], - NameId[i].PinData.Index[j], - volt, SOURCE_FORCE_MAIN, - ImageStack[k].Image->Images); - NameId[i].PinData.ProgComponent = - ComponentAddress; - char Debug[256]; - sprintf_s(Debug, "1Name:%s \t ProgVolt:%f \t Volt:%f \t RVolt: %f\n", Name, - NameId[i].PinData.ProgVolt,NameId[i].PinData.Volt,volt); - OutputDebugString(Debug); - } - else if((NameId[i].PinData.ProgVolt < volt)) - { - if( - (NameId[i].PinData.ProgComponent == - ComponentAddress) || - NameId[i].PinData.ProgComponent == NULL) - { - // MessageBox(AdvancedDialog, "Set", - "Mouse Clicked", - MB_OK | MB_ICONWARNING); - NameId[i].PinData.ProgVolt = VoltRequest( - NameId[i].PinData.ImageId[j], - SimulationStarted, - NameId[i].PinData.ImageType[j], - NameId[i].PinData.Index[j], volt, - SOURCE_FORCE_MAIN, - ImageStack[k].Image->Images); - char Debug[256]; - sprintf_s(Debug, "2Name:%s \t ProgVolt:%f \t Volt:%f \t RVolt: %f\n", Name, - NameId[i].PinData.ProgVolt,NameId[i].PinData.Volt,volt); - OutputDebugString(Debug); - } - } - } - } - } - else - { - if((NameId[i].PinData.ProgComponent == ComponentAddress)) - { - // MessageBox(AdvancedDialog, "Set", "Test", - MB_OK | MB_ICONWARNING); - for(int k =0; k<ImagesDrawn; k++) - { - if(ImageStack[k].Properties == ComponentAddress) - { - NameId[i].PinData.ProgVolt = VoltRequest( - NameId[i].PinData.ImageId[j], - SimulationStarted, - NameId[i].PinData.ImageType[j], - NameId[i].PinData.Index[j], - volt, SOURCE_FORCE_MAIN, - ImageStack[k].Image->Images); - NameId[i].PinData.ProgComponent = - ComponentAddress; - } - } - char Debug[256]; - sprintf_s(Debug, "3Name:%s \t ProgVolt:%f \t Volt:%f \t RVolt: %f\n", Name, - NameId[i].PinData.ProgVolt,NameId[i].PinData.Volt,volt); - OutputDebugString(Debug); - } - else if(NameId[i].PinData.ProgComponent == NULL) - { - NameId[i].PinData.ProgVolt = volt; - NameId[i].PinData.ProgComponent = ComponentAddress; - } - } - } - } - } - int Index; - Index = IsMCUPin(PinId); - if(Index >=0) - { - if(McuPin[Index].type == IO_TYPE_DIG_INPUT) - { - if(NameId[Pin].PinData.ProgVolt == VOLT_5) - { - SimulationSetContact(Name); - // MessageBox(AdvancedDialog, "Set", "Mouse Clicked", - MB_OK | MB_ICONWARNING); - } - else if(NameId[Pin].PinData.ProgVolt == GND) - { - SimulationResetContact(Name); - // MessageBox(AdvancedDialog, "Reset", "Mouse Clicked", - MB_OK | MB_ICONWARNING); - } - else if(NameId[Pin].PinData.ProgVolt == V_OPEN) - { - if(McuPin[Index].InternalPullup) - { - NameId[Pin].PinData.ProgVolt = VOLT_5; - SimulationSetContact(Name); - // MessageBox(AdvancedDialog, "Set", "Pullup", - MB_OK | MB_ICONWARNING); - } - else - { - SimulationResetContact(Name); - // MessageBox(AdvancedDialog, "Set", "Pullup", - MB_OK | MB_ICONWARNING); - } - } - } - // char Debug[256]; - // sprintf_s(Debug, "Name:%s \t ProgVolt:%f \t Volt:%f \n", Name, - NameId[Index].PinData.ProgVolt,NameId[Index].PinData.Volt); - // OutputDebugString(Debug); - } - if(NameId[Pin].PinData.ProgVolt > NameId[Pin].PinData.Volt) - { - NameId[Pin].PinData.ProgVolt = NameId[Pin].PinData.Volt; - char Debug[256]; - sprintf_s(Debug, "4Name:%s \t ProgVolt:%f \t Volt:%f \t RVolt: %f\n", Name, - NameId[Pin].PinData.ProgVolt,NameId[Pin].PinData.Volt,volt); - OutputDebugString(Debug); - } - else - { - char Debug[256]; - sprintf_s(Debug, "5Name:%s \t ProgVolt:%f \t Volt:%f \t RVolt: %f\n", Name, - NameId[Pin].PinData.ProgVolt,NameId[Pin].PinData.Volt,volt); - OutputDebugString(Debug); - } - char vx[10],vy[10]; - _gcvt(NameId[Pin].PinData.ProgVolt,8,vy); - _itoa(Pin,vx,2); - MessageBox(AdvancedDialog, - Name, _(vy), MB_OK | MB_ICONWARNING); - return NameId[Pin].PinData.ProgVolt; -}*/ - -double RequestVoltChange(int PinId, int Index, - void *ComponentAddress, double volt) -{ - UINT Id; - double temp; - // char Debug[1024]; - for(UINT i=0; i<NameCount; i++) - { - if(NameId[i].PinId == PinId) - { - Id = i; - break; - } - } - // if(Id >= NameCount) - // { - // sprintf_s(Debug, "PinId Not found %s: %d\n", - // NameId[Id].Name, PinId); - // OutputDebugString(Debug); - // } - temp = NameId[Id].PinData.ProgVolt; - - /*sprintf_s(Debug, "Changing Voltage %s: %f to %f \t ProgVolt:\ - %f \tChanger: %p\n", - NameId[Id].Name, temp, volt, NameId[Id].PinData.ProgVolt, - NameId[Id].PinData.ProgComponent); - OutputDebugString(Debug);*/ - if((NameId[Id].PinData.ProgVolt > volt) || - (NameId[Id].PinData.ProgComponent == ComponentAddress) || - (NameId[Id].PinData.ProgComponent == NULL)) - { - NameId[Id].PinData.ProgComponent = ComponentAddress; - if(volt <= NameId[Id].PinData.Volt) - { - NameId[Id].PinData.ProgVolt = volt; - /*sprintf_s(Debug, "Executing1: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - } - else - { - NameId[Id].PinData.ProgVolt = NameId[Id].PinData.Volt; - /*sprintf_s(Debug, "Executing2: \tVoltage:%f\n", - NameId[Id].PinData.Volt); - OutputDebugString(Debug);*/ - } - RefreshVolt(PinId, Index, Id, ComponentAddress, - NameId[Id].PinData.ProgVolt); - /*sprintf_s(Debug, "Executing3: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - } - RefreshProcessorStat(PinId, Id); - /*sprintf_s(Debug, "Final Voltage %s: %f to %f \t ProgVolt:\ - %f \tChanger: %p\n", - NameId[Id].Name, temp, volt, NameId[Id].PinData.ProgVolt, - NameId[Id].PinData.ProgComponent); - OutputDebugString(Debug);*/ - return NameId[Id].PinData.ProgVolt; -} - -double RefreshVolt(int PinId, int Index, UINT Id, - void* ComponentAddress, double volt) -{ - // char Debug[1024]; - double FinalVolt = volt; - /*sprintf_s(Debug, "Executing4: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - for(int i=0; i<NameId[Id].PinData.LinkCount;i++) - { - /*sprintf_s(Debug, "Currently processing: %s \tComponentAddress:%p\ - \tIndex:%d \tRequested by: %p,Index:%d\n", - NameId[Id].Name, NameId[Id].PinData.ImageId[i], - NameId[Id].PinData.Index[i],ComponentAddress, Index); - OutputDebugString(Debug);*/ - if(!(NameId[Id].PinData.ImageId[i] == ComponentAddress)) - { - /*sprintf_s(Debug, "Executing5: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - for(int k =0; k<ImagesDrawn; k++) - { - if((ImageStack[k].Properties == NameId[Id].PinData.ImageId[i])) - { - /*sprintf_s(Debug, "Requesting Voltage %s: %f to \ - %f \tProgVolt: %f \tComponentAddress:%p, Index: %d\n", - NameId[Id].Name, volt, FinalVolt, - NameId[Id].PinData.ProgVolt, - NameId[Id].PinData.ImageId[i], - NameId[Id].PinData.Index[i]); - OutputDebugString(Debug);*/ - /*if(ComponentAddress == NULL) - { - char vx[sizeof(int)*8+1],vy[10]; - _gcvt(NameId[Id].PinData.ProgVolt,10,vy); - // if(NameId[Id].PinData.Index) - _itoa(ImageStack[i].Image->ComponentId,vx,10); - MessageBox(AdvancedDialog, - (LPSTR)(vx), (LPSTR)(NameId[Id].Name), MB_OK | MB_ICONWARNING); - }*/ - - FinalVolt = VoltSet(NameId[Id].PinData.ImageId[i], - SimulationStarted, ImageStack[k].Image->ComponentId, - NameId[Id].PinData.Index[i], - NameId[Id].PinData.ProgVolt, - SOURCE_PROGRAM_MAIN, &ImageStack[k].Image->Images); - if(FinalVolt < NameId[Id].PinData.ProgVolt) - { - NameId[Id].PinData.ProgVolt = FinalVolt; - NameId[Id].PinData.ProgComponent = - ImageStack[k].Properties; - /*sprintf_s(Debug, "Executing7: \t \ - ProgVoltage:%f\n",NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - } - else - { - if(ImageStack[k].Properties == - NameId[Id].PinData.ProgComponent) - { - NameId[Id].PinData.ProgVolt = FinalVolt; - NameId[Id].PinData.ProgComponent = - ImageStack[k].Properties; - /*sprintf_s(Debug, "Executing8: \t ProgVoltage:\ - %f\n",NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - } - } - if(NameId[Id].PinData.ProgVolt > NameId[Id].PinData.Volt) - { - NameId[Id].PinData.ProgVolt = NameId[Id].PinData.Volt; - } - /*sprintf_s(Debug, "Updating Voltage %s: %f to \ - %f \tProgVolt: %f\n",NameId[Id].Name, - volt,FinalVolt,NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - } - } - } - } - /*sprintf_s(Debug, "Executing:10 \t ProgVoltage:\ - %f\n",NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - RefreshProcessorStat(PinId, Id); - /*if(ComponentAddress == NULL) - { - char vx[10],vy[10]; - _gcvt(NameId[Id].PinData.ProgVolt,10,vy); - _itoa(NameId[Id].PinId,vx,10); - MessageBox(AdvancedDialog, - (LPSTR)(vx), (LPSTR)(NameId[Id].Name), MB_OK | MB_ICONWARNING); - }*/ - /*sprintf_s(Debug, "Executing11: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - return NameId[Id].PinData.ProgVolt; -} -double RefreshProcessorStat(int PinId, UINT Id) -{ - char* Name; - // char Debug[256]; - int MCUPinId; - MCUPinId = IsMCUPin(PinId); - if(MCUPinId >=0) - { - Name = (char*)&NameId[Id].Name; - if(McuPin[MCUPinId].type == IO_TYPE_DIG_INPUT) - { - if(NameId[Id].PinData.ProgVolt == VOLT_5) - { - SimulationSetContact(Name); - // MessageBox(AdvancedDialog, "Set", - // "Mouse Clicked", MB_OK | MB_ICONWARNING); - } - else if(NameId[Id].PinData.ProgVolt == GND) - { - SimulationResetContact(Name); - // MessageBox(AdvancedDialog, "Reset", - // "Mouse Clicked", MB_OK | MB_ICONWARNING); - } - else if(NameId[Id].PinData.ProgVolt == V_OPEN) - { - if(McuPin[MCUPinId].InternalPullup) - { - /*sprintf_s(Debug, "Executing21: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - NameId[Id].PinData.ProgVolt = VOLT_5; - SimulationSetContact(Name); - // MessageBox(AdvancedDialog, "Set", "Pullup",\ - // MB_OK | MB_ICONWARNING); - } - else - { - SimulationResetContact(Name); - // MessageBox(AdvancedDialog, "Set", "Pullup", - // MB_OK | MB_ICONWARNING); - } - } - } - } - else - { - if(NameId[Id].PinData.ProgVolt > NameId[Id].PinData.Volt) - { - /*sprintf_s(Debug, "Executing22: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - NameId[Id].PinData.ProgVolt = NameId[Id].PinData.Volt; - } - } - /*sprintf_s(Debug, "Executing23: \t ProgVoltage:%f\n", - NameId[Id].PinData.ProgVolt); - OutputDebugString(Debug);*/ - return NameId[Id].PinData.ProgVolt; -} - -double GetGlobalVoltage(int PinId, void* ComponentAddress) -{ - int MCUPinId = IsMCUPin(PinId); - for(UINT i=0; i<NameCount; i++) - { - if(NameId[i].PinId == PinId) - { - /*char Debug[256]; - sprintf_s(Debug, "GetGlobalVoltage: %s\n", - NameId[i].Name); - OutputDebugString(Debug);*/ - if(MCUPinId >=0) - { - if(McuPin[MCUPinId].type == IO_TYPE_DIG_INPUT) - { - if(ComponentAddress == NameId[i].PinData.ProgComponent) - { - return VOLT_5; - } - } - } - return NameId[i].PinData.ProgVolt; - } - } - return GND - 1; -} -// int RegisterPinState(int Index, double Volt) -// { -// PinData[Index].McuPin = TRUE; -// return 0; -// } - -/*void RefreshDialogScrollbars(void) -{ - SCROLLINFO vert, horiz; - SetUpScrollbars(&NeedHoriz, &horiz, &vert); - SetScrollInfo(HorizScrollBar, SB_CTL, &horiz, TRUE); - SetScrollInfo(VertScrollBar, SB_CTL, &vert, TRUE); - - RECT main; - GetClientRect(AdvancedWorkspace, &main); - - if(NeedHoriz) { - MoveWindow(HorizScrollBar, 0, IoListTop - ScrollHeight - 2, - main.right - ScrollWidth - 2, ScrollHeight, TRUE); - ShowWindow(HorizScrollBar, SW_SHOW); - EnableWindow(HorizScrollBar, TRUE); - } else { - ShowWindow(HorizScrollBar, SW_HIDE); - } - MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth, - NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE); - - MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth, - NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE); - - InvalidateRect(AdvancedDialog, NULL, FALSE); -}*/
\ No newline at end of file diff --git a/ldmicro/componentimages.cpp b/ldmicro/componentimages.cpp deleted file mode 100644 index 063bdbb..0000000 --- a/ldmicro/componentimages.cpp +++ /dev/null @@ -1,253 +0,0 @@ - -#include <linuxUI.h> -//#include <commctrl.h> -#include <stdio.h> -#include <stdlib.h> -#include <wincodec.h> - -#include "ldmicro.h" -#include "componentlist.h" -#include "components/componentimages.h" - -static int temp = 1; - -void InitializeComponentImage(int Component, HIMAGELIST *il) -{ - int i; - // char a[4]; - // MessageBox(ComponentList, (LPCTSTR)itoa(rgCompData[Component], a, 10), - // "Info", MB_OK | MB_ICONEXCLAMATION); - // test=LoadComponentImage(rgCompData[Component].Images[0]); - // if(test ==NULL){ - // MessageBox(ComponentList, "Could not load Bitmap!", - // "Error", MB_OK | MB_ICONEXCLAMATION); - // } - // HDC hdc=GetDC(AdvancedWorkspace); - // HdcMem = CreateCompatibleDC(hdc); - // HBITMAP bm = (HBITMAP)SelectObject(HdcMem, test); - // BitBlt(hdc, 10 * temp, 10 * temp, COMPONENT_WIDTH, - // COMPONENT_HEIGHT, HdcMem, 0, 0, SRCCOPY); - // temp++; - // DeleteDC(hdc); - // if(ComponentDiagrams == NULL){ - // InitializeImageList(); - // } - HBITMAP bm = LoadComponentImage(Component); - // HBITMAP mask = CreateBitmapMask(bm, CLR_NONE); - // HDC hdc = GetDC(AdvancedWorkspace); - ImageList_RemoveAll(*il); - i = ImageList_AddMasked(*il, bm, CLR_NONE); - if(bm==NULL) - { - MessageBox(NULL,"Could not add image", - "Info", MB_OK | MB_ICONEXCLAMATION); - } - /*char vx[4],vy[4]; - _itoa(10,vy,10); - _itoa(ImageStack[i].Image->Images,vx,10); - MessageBox(NULL, - (vx), (vy), MB_OK | MB_ICONWARNING);*/ - // _itoa(Component, a, 10); - // MessageBox(ComponentList,a, - // "Info", MB_OK | MB_ICONEXCLAMATION); - - // ImageList_Draw(ComponentDiagrams, i, hdc, 100*temp, 100*temp, ILD_TRANSPARENT); - // temp ++; - // DeleteDC(hdc); -} - -//----------------------------------------------------------------------------- -// Creates a stream object initialized with the data from an executable resource. -//----------------------------------------------------------------------------- - -IStream * CreateStreamOnResource(LPCTSTR lpName, LPCTSTR lpType) -{ - - // initialize return value - IStream * ipStream = NULL; - - // find the resource - HRSRC hrsrc = FindResource(NULL, lpName, lpType); - if (hrsrc == NULL) - { - return ipStream; - } - - // load the resource - DWORD dwResourceSize = SizeofResource(NULL, hrsrc); - HGLOBAL hglbImage = LoadResource(NULL, hrsrc); - if (hglbImage == NULL) - { - return ipStream; - } - - // lock the resource, getting a pointer to its data - LPVOID pvSourceResourceData = LockResource(hglbImage); - if (pvSourceResourceData == NULL) - { - return ipStream; - } - - // allocate memory to hold the resource data - HGLOBAL hgblResourceData = GlobalAlloc(GMEM_MOVEABLE, dwResourceSize); - if (hgblResourceData == NULL) - { - return ipStream; - } - - // get a pointer to the allocated memory - LPVOID pvResourceData = GlobalLock(hgblResourceData); - if (pvResourceData == NULL) - { - // couldn't create stream; free the memory - GlobalFree(hgblResourceData); - return ipStream; - } - - // copy the data from the resource to the new memory block - CopyMemory(pvResourceData, pvSourceResourceData, dwResourceSize); - GlobalUnlock(hgblResourceData); - - // create a stream on the HGLOBAL containing the data - if (SUCCEEDED(CreateStreamOnHGlobal(hgblResourceData, TRUE, &ipStream))) - { - return ipStream; - } - GlobalFree(hgblResourceData); - return ipStream; -} - -//----------------------------------------------------------------------------- -// Loads a PNG image from the specified stream -// (using Windows Imaging Component) -//----------------------------------------------------------------------------- -IWICBitmapSource * LoadBitmapFromStream(IStream * ipImageStream) -{ - // initialize return value - IWICBitmapSource * ipBitmap = NULL; - - // load WIC's PNG decoder - IWICBitmapDecoder * ipDecoder = NULL; - if(CoInitialize(NULL) == RPC_E_CHANGED_MODE) - { - MessageBox(ComponentList, "Could not Initialize COM Library!", - "Error", MB_OK | MB_ICONEXCLAMATION); - } - if (FAILED(CoCreateInstance(CLSID_WICPngDecoder, NULL, CLSCTX_INPROC_SERVER, - __uuidof(ipDecoder), reinterpret_cast<void**>(&ipDecoder)))) - { - MessageBox(ComponentList, "Could not Create Object!", - "Error", MB_OK | MB_ICONEXCLAMATION); - goto Return; - } - - // load the PNG - if (FAILED(ipDecoder->Initialize(ipImageStream, WICDecodeMetadataCacheOnLoad))) - goto ReleaseDecoder; - - // check for the presence of the first frame in the bitmap - UINT nFrameCount = 0; - if (FAILED(ipDecoder->GetFrameCount(&nFrameCount)) || nFrameCount != 1) - goto ReleaseDecoder; - - // load the first frame (i.e., the image) - IWICBitmapFrameDecode * ipFrame = NULL; - if (FAILED(ipDecoder->GetFrame(0, &ipFrame))) - goto ReleaseDecoder; - - // convert the image to 32bpp BGRA format with pre-multiplied alpha - // (it may not be stored in that format natively in the PNG resource, - // but we need this format to create the DIB to use on-screen) - WICConvertBitmapSource(GUID_WICPixelFormat32bppPBGRA, ipFrame, &ipBitmap); - ipFrame->Release(); - -ReleaseDecoder: - ipDecoder->Release(); - -Return: - return ipBitmap; - -} - -//----------------------------------------------------------------------------- -// Creates a 32-bit DIB from the specified WIC bitmap. -//----------------------------------------------------------------------------- - -HBITMAP CreateHBITMAP(IWICBitmapSource * ipBitmap) -{ - // initialize return value - HBITMAP hbmp = NULL; - - // get image attributes and check for valid image - UINT width = 0; - UINT height = 0; - if (FAILED(ipBitmap->GetSize(&width, &height)) || width == 0 || height == 0) - { - return hbmp; - } - - // prepare structure giving bitmap information - // (negative height indicates a top-down DIB) - BITMAPINFO bminfo; - ZeroMemory(&bminfo, sizeof(bminfo)); - bminfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bminfo.bmiHeader.biWidth = width; - bminfo.bmiHeader.biHeight = -((LONG) height); - bminfo.bmiHeader.biPlanes = 1; - bminfo.bmiHeader.biBitCount = 32; - bminfo.bmiHeader.biCompression = BI_RGB; - - // create a DIB section that can hold the image - void * pvImageBits = NULL; - HDC hdcScreen = GetDC(NULL); - hbmp = CreateDIBSection(hdcScreen, &bminfo, DIB_RGB_COLORS, &pvImageBits, NULL, 0); - ReleaseDC(NULL, hdcScreen); - if (hbmp == NULL) - { - return hbmp; - } - - // extract the image into the HBITMAP - const UINT cbStride = width * 4; - const UINT cbImage = cbStride * height; - if (FAILED(ipBitmap->CopyPixels(NULL, cbStride, cbImage, static_cast<BYTE *>(pvImageBits)))) - { - // couldn't extract image; delete HBITMAP - DeleteObject(hbmp); - hbmp = NULL; - } - - return hbmp; -} - -//----------------------------------------------------------------------------- -// Loads the PNG containing the splash image into a HBITMAP. -//----------------------------------------------------------------------------- - -HBITMAP LoadComponentImage(int resource) -{ - HBITMAP hbmpSplash = NULL; - - // load the PNG image data into a stream - IStream * ipImageStream = CreateStreamOnResource( - MAKEINTRESOURCE(resource), _("PNG")); - if (ipImageStream == NULL) - { - return hbmpSplash; - } - - // load the bitmap with WIC - IWICBitmapSource * ipBitmap = LoadBitmapFromStream(ipImageStream); - if (ipBitmap == NULL) - { - ipImageStream->Release(); - return hbmpSplash; - } - - // create a HBITMAP containing the image - hbmpSplash = CreateHBITMAP(ipBitmap); - ipBitmap->Release(); - - ipImageStream->Release(); - return hbmpSplash; -}
\ No newline at end of file diff --git a/ldmicro/componentlist.cpp b/ldmicro/componentlist.cpp deleted file mode 100644 index 56a243e..0000000 --- a/ldmicro/componentlist.cpp +++ /dev/null @@ -1,208 +0,0 @@ -#include <linuxUI.h> -//#include <commctrl.h> -#include <stdio.h> -#include <stdlib.h> -#include <wincodec.h> - -#include "ldmicro.h" -#include "advanceddialog.h" -#include "componentlist.h" -#include "components\componentimages.h" -#include "components\components.h" - -// I/O that we have seen recently, so that we don't forget pin assignments -// when we re-extract the list - -// static HBITMAP testmask=NULL; - -// HIMAGELIST ComponentDiagrams; -// static int ComponentCount; -// ImageLocation ImageStack[MAX_SCREEN_ITEMS]; -// PinInfo PinStack[MAX_PINS]; -// int ImagesDrawn = 0; -// int DragIndex = 0; -// int DragOffsetX = 0; -// int DragOffsetY = 0; -// int DragX = 0; -// int DragY = 0; -// BOOL Dragging = FALSE; -// UINT UniqueImgId = 0; - -// Imagemap test; - -void ComponentListInitiate(void) -{ - // int i; - // LVITEM lvi; - // for(i = 0; i < TOTAL_COMPONENTS; i++) - // { - // lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; - // lvi.state = lvi.stateMask = 0; - // lvi.iItem = i; - // lvi.iSubItem = 0; - // lvi.pszText = rgCompData[i].ComponentName; - // lvi.lParam = rgCompData[i].Index; - // if(ListView_InsertItem(ComponentList, &lvi) < 0) oops(); - // } - // test.insert(make_pair(1, ComponentDiagrams, 100, 100, 6000)); -} - -void ComponentListProc(NMHDR *h) -{ - // switch(h->code) { - // case LVN_ITEMACTIVATE: - // { - // int Img, Index; - // NMITEMACTIVATE *i = (NMITEMACTIVATE *)h; - // LVITEM lvi; - // lvi.mask = LVIF_PARAM; - // lvi.iItem = ListView_GetNextItem(ComponentList, -1, LVNI_SELECTED); - // ListView_GetItem(ComponentList, &lvi); - // Index = (int) lvi.lParam; - // int CompId = rgCompData[Index].ComponentId; - // ImageStack[ImagesDrawn].Image = - // (ImageStruct *)AllocImageHeap(sizeof(ImageStruct)); - // ImageStack[ImagesDrawn].Image->ComponentId = CompId; - // ImageStack[ImagesDrawn].Properties = - // AllocImageHeap(GetStructSize(CompId)); - // ImageStack[ImagesDrawn].PinName = - // AllocImageHeap(GetNameSize(Index)); - // ImageStack[ImagesDrawn].Id = ++UniqueImgId; - // ImageStack[ImagesDrawn].Index = Index; - // Img = InitializeComponentProperties( - // ImageStack[ImagesDrawn].Properties, CompId); - // InitializeImageList(&ImageStack[ImagesDrawn].Image->Images); - // InitializeComponentImage(Img, - // &ImageStack[ImagesDrawn].Image->Images); - // ImageStack[ImagesDrawn].x = 100; - // ImageStack[ImagesDrawn].y = 100; - // // RECT TempRect; - // // GetWindowRect(AdvancedWorkspace, &TempRect); - // InvalidateRect(AdvancedWorkspace, NULL, TRUE); - - // ImagesDrawn++; - // // char a[4]; - // // MessageBox(ComponentList, (LPCTSTR)itoa(lvi.lParam, a, 10), "Info", MB_OK | MB_ICONEXCLAMATION); - // // InitializeComponentImage((int)lvi.lParam); - // // int *temp; - // // temp = (int *)i->lParam; - // // MessageBox(ComponentList, (LPCTSTR)itoa(*temp, a, 10), "Info", MB_OK | MB_ICONEXCLAMATION); - // //Selection Code Here - - // // test=LoadComponentImage(RELAY_NC); - // // if(test ==NULL){ - // // MessageBox(ComponentList, "Could not load Bitmap!", "Error", MB_OK | MB_ICONEXCLAMATION); - // // } - // } - // break; - // default: - // break; - // } -} - -void InitializeImageList(HIMAGELIST *il) -{ - // *il = ImageList_Create(COMPONENT_WIDTH, COMPONENT_HEIGHT, ILC_MASK | ILC_COLOR8, 0, MAX_SCREEN_ITEMS); - // if(*il == NULL){ - // MessageBox(ComponentList, "Could not Initialize ImageList", "Error", MB_OK | MB_ICONEXCLAMATION); - // return; - // } -} - -void RefreshImages() -{ - // InvalidateRect(AdvancedWorkspace, NULL, TRUE); -} - -void SetImage(int Component, void *il) -{ - // InitializeComponentImage(Component,(HIMAGELIST*) il); -} - -int BeginComponentDrag(int x, int y) -{ - // int i; - // for(i = 0; i < ImagesDrawn; i++) - // { - // if((((ImageStack[i].x + COMPONENT_WIDTH) > x) && (ImageStack[i].x < x) - // && (ImageStack[i].y < y) && ((ImageStack[i].y + COMPONENT_HEIGHT) > y))) - // { - // // RECT TempRect; - // // TempRect.left = ImageStack[i].x; - // // TempRect.top = ImageStack[i].y; - // // TempRect.right = ImageStack[i].x + 100; - // // TempRect.bottom = ImageStack[i].y + 100; - - // DragOffsetX = x - ImageStack[i].x; - // DragOffsetY = y - ImageStack[i].y; - // DragX = x; - // DragY = y; - - // // MessageBox(ComponentList, "Clicked Image", "Error", MB_OK | MB_ICONEXCLAMATION); - // ImageList_BeginDrag(ImageStack[i].Image->Images, 0, DragOffsetX, DragOffsetY); - // ImageList_SetDragCursorImage(ImageStack[i].Image->Images, 0, 0, 0); - // ImageList_DragEnter(AdvancedWorkspace, x, y); - - // // ImageStack[i].x = -200; - // // ImageStack[i].y = -200; - // // InvalidateRect(AdvancedWorkspace, &TempRect, TRUE); - // DragIndex = i; - // Dragging = TRUE; - // return 0; - // } - // } - // // HBITMAP temp=(HBITMAP)GetCurrentObject(GetDC(AdvancedWorkspace), OBJ_BITMAP); - // // if(temp == NULL) - // // { - // // MessageBox(ComponentList, "Bitmap Found", "Information", MB_OK | MB_ICONEXCLAMATION); - // // } - // return 0; -} -int ComponentDrag(int x, int y) -{ - // if(Dragging) - // { - // ImageList_DragMove(x, y); - // // ImageStack[DragIndex].x = x - DragOffsetX; - // // ImageStack[DragIndex].y = y - DragOffsetY; - // // InvalidateRect(AdvancedWorkspace, NULL, TRUE); - // } - // else - // { - // SetCursor(LoadCursor(NULL, IDC_ARROW)); - // } - // return 0; -} - -int EndComponentDrag(int x, int y) -{ - // if(Dragging) - // { - // // HBITMAP TempBM; - // // HDC HdcMem2 = GetDC(AdvancedWorkspace); - // // HDC HdcMem =GetDC(AdvancedWorkspace); - // // RECT TempRect; - // // GetWindowRect(AdvancedWorkspace, &TempRect); - // ImageList_DragLeave(AdvancedWorkspace); - // ImageList_EndDrag(); - // ImageStack[DragIndex].x = x - DragOffsetX; - // ImageStack[DragIndex].y = y - DragOffsetY; - // // InvalidateRect(AdvancedWorkspace, &TempRect, TRUE); - // InvalidateRect(AdvancedWorkspace, NULL, TRUE); - // // TempBM = CreateBitmap(COMPONENT_WIDTH, COMPONENT_HEIGHT, 1, 32, NULL); - - // // BitBlt(HdcMem2, x, y, COMPONENT_WIDTH, COMPONENT_HEIGHT, HdcMem, 100, 100, SRCERASE); - // Dragging =FALSE; - // return DragIndex; - // } - // // IMAGEINFO imginfo; - // // ImageList_GetImageInfo(ComponentDiagrams,0, &imginfo); - // // char vx[4],vy[4]; - // // itoa(imginfo.rcImage.right,vx,10); - // // itoa(imginfo.rcImage.bottom,vy,10); - // // MessageBox(ComponentList, _(vx), _(vy), MB_OK | MB_ICONEXCLAMATION); - // // imginfo.rcImage.left=x; - // // imginfo.rcImage.top=y; - // // ImageList_Draw(ComponentDiagrams, 0, GetDC(AdvancedWorkspace), x, y, ILD_TRANSPARENT); - // return NULL; -} 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 diff --git a/ldmicro/img/dpdt_1.png b/ldmicro/img/dpdt_1.png Binary files differdeleted file mode 100644 index 17ff18d..0000000 --- a/ldmicro/img/dpdt_1.png +++ /dev/null diff --git a/ldmicro/img/dpdt_2.png b/ldmicro/img/dpdt_2.png Binary files differdeleted file mode 100644 index 56c61a8..0000000 --- a/ldmicro/img/dpdt_2.png +++ /dev/null diff --git a/ldmicro/img/dpst_1.png b/ldmicro/img/dpst_1.png Binary files differdeleted file mode 100644 index 38a58ac..0000000 --- a/ldmicro/img/dpst_1.png +++ /dev/null diff --git a/ldmicro/img/dpst_2.png b/ldmicro/img/dpst_2.png Binary files differdeleted file mode 100644 index 6e254c8..0000000 --- a/ldmicro/img/dpst_2.png +++ /dev/null diff --git a/ldmicro/img/relay_nc.png b/ldmicro/img/relay_nc.png Binary files differdeleted file mode 100644 index 25c6f66..0000000 --- a/ldmicro/img/relay_nc.png +++ /dev/null diff --git a/ldmicro/img/relay_no.png b/ldmicro/img/relay_no.png Binary files differdeleted file mode 100644 index c1739d4..0000000 --- a/ldmicro/img/relay_no.png +++ /dev/null diff --git a/ldmicro/img/spdt_1.png b/ldmicro/img/spdt_1.png Binary files differdeleted file mode 100644 index 5141923..0000000 --- a/ldmicro/img/spdt_1.png +++ /dev/null diff --git a/ldmicro/img/spdt_2.png b/ldmicro/img/spdt_2.png Binary files differdeleted file mode 100644 index 9132841..0000000 --- a/ldmicro/img/spdt_2.png +++ /dev/null diff --git a/ldmicro/img/switch_connected.png b/ldmicro/img/switch_connected.png Binary files differdeleted file mode 100644 index 6aa84b4..0000000 --- a/ldmicro/img/switch_connected.png +++ /dev/null diff --git a/ldmicro/img/switch_disconnected.png b/ldmicro/img/switch_disconnected.png Binary files differdeleted file mode 100644 index 596c939..0000000 --- a/ldmicro/img/switch_disconnected.png +++ /dev/null diff --git a/ldmicro/includes/advanceddialog.h b/ldmicro/includes/advanceddialog.h deleted file mode 100644 index 5adadbc..0000000 --- a/ldmicro/includes/advanceddialog.h +++ /dev/null @@ -1,142 +0,0 @@ -// #ifndef _ADVANCED_DIALOG_H -// #define _ADVANCED_DIALOG_H - -// #define MAX_PIN_NAME 128 - -// /*Advanced Dialog Menus*/ -// #define MNU_ADV_NEW 0x01 -// #define MNU_ADV_OPEN 0x02 -// #define MNU_ADV_SAVE 0x03 -// #define MNU_ADV_SAVE_AS 0x04 -// #define MNU_ADV_EXIT 0x05 - -// #define MNU_ADV_UNDO 0x10 -// #define MNU_ADV_REDO 0x11 -// #define MNU_ADV_CUT 0x12 -// #define MNU_ADV_COPY 0x13 -// #define MNU_ADV_PASTE 0x14 -// #define MNU_ADV_DEL 0x15 - -// #define MNU_ADV_SIMULATION_MODE 0x20 -// #define MNU_ADV_START_SIMULATION 0x21 -// #define MNU_ADV_STOP_SIMULATION 0x22 -// #define MNU_ADV_SINGLE_CYCLE 0x23 - -// #define MNU_ADV_MANUAL 0x30 -// #define MNU_ADV_ABOUT 0x31 - -// #define MAX_NAME_LENGTH 128 -// #define MAX_SCREEN_ITEMS 512 -// #define MAX_PINS 4000 -// #define MCU_PIN_FLAG 4000 -// #define MAX_MCU_PINS 128 -// #define TIMER_ADV_SIMULATE 101 - - -// typedef struct ImageStructTag { -// int selectedState; -// HIMAGELIST Images; -// int ComponentId; -// } ImageStruct; - -// typedef struct ImageLocationTag{ -// int Id; -// ImageStruct* Image; -// int Index; -// int x; -// int y; -// void* Properties; -// void* PinId; -// void* PinName; -// }ImageLocation; - -// typedef struct PinInfoTag{ -// double Volt; -// double OperatingVolt; -// void** ImageId; -// int* Index; -// int* ImageType; //To compare with imagelocation array -// int LinkCount; //No of valid entries in array -// double ProgVolt; -// void* ProgComponent; -// }PinInfo; - -// typedef struct PinMcuTag{ -// UINT PinId; -// UINT state; -// int type; -// BOOL InternalPullup; -// }PinMcu; - -// typedef struct PinNameTag{ -// UINT PinId; //Need to generate unique pinid every time user saves a name -// TCHAR Name[MAX_NAME_LENGTH]; -// PinInfo PinData; -// }PinName; - -// typedef struct PinComponentTag{ -// UINT PinId; -// void** ComponentAddress; -// int Count; -// void* Next; -// }PinComponent; - -// extern HANDLE ImageHeap; -// extern HFONT AdvNiceFont; -// extern HFONT AdvFixedFont; -// extern UINT NameCount; -// extern ImageLocation ImageStack[MAX_SCREEN_ITEMS]; -// // extern PinInfo PinData[MAX_PINS]; -// extern PinMcu McuPin[MAX_MCU_PINS]; -// extern PinName NameId[MAX_PINS]; -// extern HWND AdvancedDialog; -// extern PinComponent ComponentPin; - -// /*Advanced Dialog Functions*/ -// void MakeAdvancedDialogControls(void); -// void AdvancedDialogResized(void); -// void MakeAdvancedWindowMenus(void); -// void ProcessEvent(int x, int y, int Event); -// void AdvancedWindowClosing(void); -// void ToggleAdvancedSimulationMode(void); -// void SimulateOneAdvCycle(BOOL ForceRefresh); -// int IsMCUPin(int PinId); -// // void CreateVoltRequest(int PinId, int Index, double VoltReq); - -// // Heap Functions -// void* AllocImageHeap(size_t n); -// void* ReallocImageHeap(LPVOID lpMem, size_t n); -// void FreeImageHeap(void *p); - -// // Component Functions - -// void InitComponents(void); - -// double GetGlobalVoltage(int PinId, void* ComponentAddress); -// double RefreshVolt(int PinId, int Index, UINT Id, void* ComponentAddress, double volt); -// double RefreshProcessorStat(int PinId, UINT Id); - - -// int RegisterPinName(LPCTSTR Name); -// int SetPinImage(int PinId,void* ImageId,int ImageType, int Index); -// int FlushPinNames(void); //Clear Pins which are deleted from MainWindow -// int DeRegisterPinName(LPCTSTR Name, void* ImageId); -// int DeletePinImage(LPCTSTR Name, void* ImageId, int Index); -// int DeletePinName(UINT Index); -// void SetMcu(int PinId, int Type); -// void RefreshNamingList(void); -// void PopulateNamingList(void); - -// double RequestVoltChange(int PinId, int Index, void *ComponentAddress, double volt); - -// int DeleteComponentPin(int PinId, void* ComponentAddress); -// int AddComponentPin(int PinId, void* ComponentAddress); -// // int RegisterPinState(int Index, double Volt); - -// //NamingList functions -// void ToggleInternalPullup(int PinId); - - -// extern BOOL SimulationStarted; - -// #endif diff --git a/ldmicro/includes/componentlist.h b/ldmicro/includes/componentlist.h deleted file mode 100644 index 20c095b..0000000 --- a/ldmicro/includes/componentlist.h +++ /dev/null @@ -1,71 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright 2007 Jonathan Westhues -// -// This file is part of LDmicro. -// -// LDmicro is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// LDmicro is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with LDmicro. If not, see <http://www.gnu.org/licenses/>. -//------ -// -// Constants, structures, declarations etc. for the PIC ladder logic compiler -// Jonathan Westhues, Oct 2004 -//----------------------------------------------------------------------------- - -#ifndef __COMPONENTLIST_H -#define __COMPONENTLIST_H - -#define MAX_COMPONENTS 999 -#define MAX_IMAGES 10 - -#define COMPONENT_WIDTH 100 -#define COMPONENT_HEIGHT 100 - -extern HDC HdcMem; -extern HWND ComponentList; -extern HBITMAP test; -extern HIMAGELIST ComponentDiagrams; -extern HWND AdvancedWorkspace; -extern BOOL Dragging; -extern int ImagesDrawn; -extern int DragX; -extern int DragY; -extern UINT UniquePinId; -extern UINT UniqueImgId; - - -/*map<int, HIMAGELIST, int, int, int> Imagemap; //To relate image with it's drawing area(Index,Images,x,y,maptype) -map<int, BOOL, BOOL, BOOL> Switchmap; //Add MCU pin later //(Index(same as Imagemap), Selected, Default Connected,Latch Action) -map<int, BOOL> Relaymap; //Add MCU pin later //(Index(same as Imagemap), Selected) - -extern Imagemap test;*/ - -void ComponentListProc(NMHDR *h); -void ComponentListInitiate(void); - -void InitializeImageList(HIMAGELIST *il); - -int BeginComponentDrag(int x, int y); -int ComponentDrag(int x, int y); -int EndComponentDrag(int x, int y); - -// Componentimages.cpp functions -//Function Definitions - -void InitializeComponentImage(int Component, HIMAGELIST *il); -IStream * CreateStreamOnResource(LPCTSTR lpName, LPCTSTR lpType); -IWICBitmapSource * LoadBitmapFromStream(IStream * ipImageStream); -HBITMAP CreateHBITMAP(IWICBitmapSource * ipBitmap); -HBITMAP LoadComponentImage(int resource); - - -#endif
\ No newline at end of file diff --git a/ldmicro/includes/components/componentfunctions.h b/ldmicro/includes/components/componentfunctions.h deleted file mode 100644 index 916bf00..0000000 --- a/ldmicro/includes/components/componentfunctions.h +++ /dev/null @@ -1,63 +0,0 @@ -#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/includes/components/componentimages.h b/ldmicro/includes/components/componentimages.h deleted file mode 100644 index 27ef6ce..0000000 --- a/ldmicro/includes/components/componentimages.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __COMPONENTIMAGES_H -#define __COMPONENTIMAGES_H - -#define SWITCH_CONNECTED 8000 -#define SWITCH_DISCONNECTED 8001 -#define RELAY_NC 8002 -#define RELAY_NO 8003 -#define SPDT_1 8004 -#define SPDT_2 8005 -#define DPST_1 8006 -#define DPST_2 8007 -#define DPDT_1 8008 -#define DPDT_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:", "Output11:", "Output12:", "Output21:", "Output22:"}} -}; - -#endif -#endif diff --git a/ldmicro/includes/components/components.h b/ldmicro/includes/components/components.h deleted file mode 100644 index 810c2d2..0000000 --- a/ldmicro/includes/components/components.h +++ /dev/null @@ -1,51 +0,0 @@ -#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/includes/components/componentstructs.h b/ldmicro/includes/components/componentstructs.h deleted file mode 100644 index 76dadda..0000000 --- a/ldmicro/includes/components/componentstructs.h +++ /dev/null @@ -1,62 +0,0 @@ -#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; //Voltage at NC pin - int PinId[5]; - -}RelayStruct; - -typedef struct SpdtStructTag -{ - int id; - int image; - BOOL latched; //Whether the swetch is in latch mode or not - BOOL NO1; //Whether Output 1 is connected - double Volt[3]; //Voltage at Input, Output1, Output2 respectively - int PinId[3]; -}SpdtStruct; - -typedef struct DpstStructTag -{ - int id; - int image; - BOOL latched; //Whether the swetch is in latch mode or not - BOOL NO; //Whether the inputs and outputs are disconnected (Open) - double Volt[4]; // Voltage at Input1, Input2, Output1, Output2 respectively - int PinId[4]; -}DpstStruct; - -typedef struct DpdtStructTag -{ - int id; - int image; - BOOL latched; //Whether the swetch is in latch mode or not - BOOL NS1; //Whether the inputs and outputs are connected in state 1 - double Volt[6]; // Voltage at Input1, Input2, Output11, Output12, Output21, Output22 respectively - int PinId[6]; -}DpdtStruct; - -#endif diff --git a/ldmicro/includes/simulate.h b/ldmicro/includes/simulate.h deleted file mode 100644 index 7b26ba3..0000000 --- a/ldmicro/includes/simulate.h +++ /dev/null @@ -1,8 +0,0 @@ -/*This file is created with an intention to share simulation functions -with advanced simulation dialog window*/ -#ifndef _SIMULATE_H -#define _SIMULATE_H - -static void SetSingleBit(char *name, BOOL state); -static BOOL SingleBitOn(char *name); -#endif diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index 67d9718..e803bba 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -31,7 +31,6 @@ #include "ldmicro.h" #include "freezeLD.h" #include "mcutable.h" -#include "advanceddialog.h" HINSTANCE Instance; @@ -279,11 +278,6 @@ static void CompileProgram(BOOL compileAs) // ProgramChangedNotSaved = TRUE; // GenerateIoListDontLoseSelection(); // RefreshScrollbars(); -// if(AdvancedWindowOpen) -// { -// FlushPinNames(); -// PopulateNamingList(); -// } // } // #define CHANGING_PROGRAM(x) { \ // UndoRemember(); \ @@ -556,17 +550,14 @@ static void CompileProgram(BOOL compileAs) // case MNU_SIMULATION_MODE: // ToggleSimulationMode(); -// ToggleAdvancedSimulationMode(); // break; // case MNU_START_SIMULATION: // StartSimulation(); -// StartAdvSimulation(); // break; // case MNU_STOP_SIMULATION: // StopSimulation(); -// StopAdvSimulation(); // break; // case MNU_SINGLE_CYCLE: @@ -588,9 +579,6 @@ static void CompileProgram(BOOL compileAs) // case MNU_ABOUT: // ShowHelpDialog(TRUE); // break; - -// case MNU_ADV_SIMULATION: -// ShowAdvancedDialog(); // } // } @@ -645,7 +633,6 @@ static void CompileProgram(BOOL compileAs) // if(wParam == 'M') { // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { // ToggleSimulationMode(); -// ToggleAdvancedSimulationMode(); // break; // } // } else if(wParam == VK_TAB) { @@ -657,13 +644,6 @@ static void CompileProgram(BOOL compileAs) // break; // } -// if(wParam == 'A') { -// if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { -// ShowAdvancedDialog(); -// break; -// } -// } - // if(InSimulationMode) { // switch(wParam) { // case ' ': @@ -673,13 +653,11 @@ static void CompileProgram(BOOL compileAs) // case 'R': // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) // StartSimulation(); -// StartAdvSimulation(); // break; // case 'H': // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) // StopSimulation(); -// StopAdvSimulation(); // break; // case VK_DOWN: @@ -719,6 +697,7 @@ static void CompileProgram(BOOL compileAs) // break; // } + // switch(wParam) { // case VK_F5: // CompileProgram(FALSE); @@ -1015,6 +994,7 @@ static void CompileProgram(BOOL compileAs) // PostQuitMessage(0); // return 1; + // default: // return DefWindowProc(hwnd, msg, wParam, lParam); // } @@ -1121,8 +1101,6 @@ int main(int argc, char** argv) // // MakeWindowClass(); // // MakeDialogBoxClass(); - // // MakeAdvancedDialogClass(); - // // MakeAdvancedWorkspaceClass(); // // MakeComponentListClass(); // // MakeSmplDialogClass(); // // MakeNamingListClass(); diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index 5e328cf..b390f8f 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -100,8 +100,6 @@ HMENU MNU_COMPILE_AS; HMENU MNU_MANUAL; HMENU MNU_ABOUT; -HMENU MNU_ADV_SIMULATION; - // scrollbars for the ladder logic area // static HWND HorizScrollBar; // static HWND VertScrollBar; @@ -569,7 +567,6 @@ HMENU MakeMainWindowMenus(void) MNU_START_SIMULATION = gtk_menu_item_new_with_label("Start Real-Time Simulation"); MNU_STOP_SIMULATION = gtk_menu_item_new_with_label("Halt Simulation"); MNU_SINGLE_CYCLE = gtk_menu_item_new_with_label("Single Cycle"); - MNU_ADV_SIMULATION = gtk_menu_item_new_with_label("Advanced Simulation"); // Appending menu items to Simulate menu and adding separators gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), MNU_SIMULATION_MODE); @@ -578,7 +575,6 @@ HMENU MakeMainWindowMenus(void) gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), MNU_SINGLE_CYCLE); SimulateMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(SimulateMenu), SimulateMenuSeparator); - gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), MNU_ADV_SIMULATION); // Creating submenus for each menu gtk_menu_item_set_submenu(GTK_MENU_ITEM(FileLabel), FileMenu); diff --git a/ldmicro/naminglist.cpp b/ldmicro/naminglist.cpp deleted file mode 100644 index d6a7159..0000000 --- a/ldmicro/naminglist.cpp +++ /dev/null @@ -1,338 +0,0 @@ -#include "linuxUI.h" -//#include <commctrl.h> -#include <stdio.h> -#include <stdlib.h> -#include <wincodec.h> -#include <Windowsx.h> - -#include "ldmicro.h" -#include "naminglist.h" -#include "components\components.h" -#include "advanceddialog.h" - -LVITEM lvi; - -void ShowNameListDialog(); -double SaveNameListDialog(int PinId, int Index); -static BOOL DlgDone, DlgCancel; -static LRESULT CALLBACK SmplDlgProc(HWND hwnd, UINT msg, WPARAM wParam, - LPARAM lParam); - -int NameList_AddName(LPCTSTR Name, int PinId, int Index) -{ - lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; - lvi.state = lvi.stateMask = 0; - lvi.iItem = Index; - lvi.iSubItem = 0; - lvi.pszText = (LPSTR)Name; - lvi.lParam = PinId; - return ListView_InsertItem(NamingList, &lvi); -} - -int NameList_AddVolt(LPCTSTR Name, int Index) -{ - ListView_SetItemText(NamingList, Index, 1 , (LPSTR)Name); - return 0; -} - -void PopulateNamingList() -{ - int ItmCount = Prog.io.count; - int i; - // ListView_DeleteAllItems(NamingList); - for(i=0; i<ItmCount; i++) - { - switch(Prog.io.assignment[i].type){ - - case IO_TYPE_DIG_INPUT: - case IO_TYPE_DIG_OUTPUT: - case IO_TYPE_READ_ADC: - case IO_TYPE_UART_TX: - case IO_TYPE_UART_RX: - case IO_TYPE_PWM_OUTPUT: - { - LPCTSTR Name = (LPCTSTR)Prog.io.assignment[i].name; - // MessageBox(NULL, - // Name, "Name", MB_OK | MB_ICONWARNING); - SetMcu(RegisterPinName(Name), Prog.io.assignment[i].type); - LVFINDINFO temp; - temp.psz = Name; - temp.flags = LVFI_STRING; - int index = ListView_FindItem(NamingList, -1, &temp); - /*char vx[3],vy[3]; - _itoa(10,vy,10); - _itoa(index,vx,10); - MessageBox(NULL, - _(vx), _(vy), MB_OK | MB_ICONWARNING);*/ - break; - } - default: - break; - } - } - /*char vx[3],vy[3]; - _itoa(NameCount,vy,10); - _itoa(ItmCount,vx,10); - MessageBox(NULL, - _(vx), _(vy), MB_OK | MB_ICONWARNING);*/ -} -void RefreshNamingList() -{ - UINT i=0; - ListView_DeleteAllItems(NamingList); - for(i=0; i<NameCount; i++) - { - /*char vx[3]; - _itoa(i,vx,10); - MessageBox(NULL, NameId[i].Name, (LPCTSTR)vx, MB_OK |MB_ICONWARNING);*/ - int NameIndex = NameList_AddName((LPCTSTR)NameId[i].Name, NameId[i].PinId, i); - int index = IsMCUPin(NameId[i].PinId); - if(index >=0) - { - if(McuPin[index].InternalPullup) - { - NameList_AddVolt((LPCTSTR)"Pullup", NameIndex); - NameId[i].PinData.Volt = VOLT_5; - } - else - { - NameList_AddVolt((LPCTSTR)"V_OPEN", NameIndex); - NameId[i].PinData.Volt = V_OPEN; - } - // MessageBox(NULL, (LPCTSTR)NameId[i].Name,"Test", MB_OK | MB_ICONWARNING); - } - else - { - char Voltage[15]; - sprintf((char*)Voltage,"%f", NameId[i].PinData.Volt); - NameList_AddVolt(LPCTSTR(Voltage), NameIndex); - /*char Debug[256]; - sprintf_s(Debug, "Nameid[%d].PinData.Volt = %f \t Index= %d\n", - i,NameId[i].PinData.Volt, NameIndex); - OutputDebugString(Debug);*/ - } - NameId[i].PinData.ProgVolt = NameId[i].PinData.Volt; - } -} - -void NamingListProc(NMHDR *h) -{ - switch(h->code) { - case LVN_ITEMACTIVATE: - { - if(!SimulationStarted) - { - int PinId; - // NMITEMACTIVATE *i = (NMITEMACTIVATE *)h; - LVITEM lvi; - lvi.mask = LVIF_PARAM; - lvi.iItem = ListView_GetNextItem(NamingList, -1, LVNI_SELECTED); - ListView_GetItem(NamingList, &lvi); - PinId = (int) lvi.lParam; - int index = IsMCUPin(PinId); - if(index >= 0) - { - ToggleInternalPullup(PinId); - McuPin[index].InternalPullup ? - NameList_AddVolt((LPCTSTR)"Pullup", lvi.iItem): - NameList_AddVolt((LPCTSTR)"V_OPEN", lvi.iItem); - // MessageBox(NULL, "Pullup","NamingListProc" , MB_OK | MB_ICONWARNING): - // MessageBox(NULL, "V_OPEN", "NamingListProc", MB_OK | MB_ICONWARNING); - /*char vx[3],vy[3]; - _itoa(PinId,vy,10); - _itoa(index,vx,10); - MessageBox(NULL, - "Selected", _(vx), MB_OK | MB_ICONWARNING);*/ - } - else - SaveNameListDialog(PinId,lvi.iItem); - // Set voltage for PinId if it is not mcupin - /*char vx[3],vy[3]; - _itoa(10,vy,10); - _itoa(PinId,vx,10); - MessageBox(NULL, - "Selected", _(vx), MB_OK | MB_ICONWARNING);*/ - } - break; - } - default: - break; - } -} - -void MakeSmplDialogClass(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)SmplDlgProc; - wc.hInstance = Instance; - wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW; - wc.lpszClassName = "SmplDialog"; - wc.lpszMenuName = NULL; - wc.hCursor = LoadCursor(NULL, IDC_SIZEWE); - wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), - IMAGE_ICON, 32, 32, 0); - wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), - IMAGE_ICON, 16, 16, 0); - - RegisterClassEx(&wc); - - AdvNiceFont = CreateFont(16, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - FF_DONTCARE, "Tahoma"); - if(!AdvNiceFont) - AdvNiceFont = (HFONT)GetStockObject(SYSTEM_FONT); - - AdvFixedFont = 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(!AdvFixedFont) - AdvFixedFont = (HFONT)GetStockObject(SYSTEM_FONT); -} - -static LRESULT CALLBACK SmplDlgProc(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; -} - -double SaveNameListDialog(int PinId, int Index) -{ - double volt; - for(UINT i=0;i<NameCount;i++) - { - if(NameId[i].PinId == PinId) - { - volt = NameId[i].PinData.Volt; - TCHAR Voltage[15]; - if(volt == (double)GND) - strcpy((char*)Voltage, "GND"); - else if(volt == (double)VOLT_5) - strcpy((char*)Voltage, "VOLT_5"); - else if(volt == (double)V_OPEN) - strcpy((char*)Voltage, "V_OPEN"); - else - sprintf((char*)Voltage,"%f",volt); - HWND NameVoltDialog = CreateWindowClient(0, "SmplDialog", - NameId[i].Name, WS_OVERLAPPED | WS_SYSMENU | WS_POPUP | WS_CAPTION, - 100, 100, 304, 15 + 30*2, NULL, NULL, Instance, NULL); - - HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Volt:"), - WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, - 10, 20, 50, 21, NameVoltDialog, NULL, Instance, NULL); - NiceFont(textLabel); - - HWND ValueTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 65, 20, 115, 21, NameVoltDialog, NULL, Instance, NULL); - FixedFont(ValueTextbox); - - OkButton = CreateWindowEx(0, WC_BUTTON, ("OK"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - 220, 10, 70, 23, NameVoltDialog, NULL, NULL, NULL); - NiceFont(OkButton); - - CancelButton = CreateWindowEx(0, WC_BUTTON, ("Cancel"), - WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - 220, 40, 70, 23, NameVoltDialog, NULL, NULL, NULL); - FixedFont(CancelButton); - - Edit_SetText(ValueTextbox,Voltage); - EnableWindow(AdvancedDialog, FALSE); - EnableWindow(MainWindow, FALSE); - ShowWindow(NameVoltDialog, TRUE); - SetFocus(ValueTextbox); - SendMessage(ValueTextbox, EM_SETSEL, 0, -1); - - 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(NameVoltDialog, &msg)) continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - if(!DlgCancel) { - // Set Voltage here - Edit_GetText(ValueTextbox, Voltage, 15); - volt = atof(Voltage); - if(strcmp((char*)Voltage, "GND") == 0) - { - volt = GND; - } - else if(strcmp((char*)Voltage, "VOLT_5") == 0) - { - volt = 5; - } - else if(strcmp((char*)Voltage, "V_OPEN") == 0) - { - volt = V_OPEN; - } - else if(volt == 0.0f) - { - EnableWindow(AdvancedDialog, TRUE); - EnableWindow(MainWindow, TRUE); - DestroyWindow(NameVoltDialog); - volt = V_OPEN; - } - NameList_AddVolt((LPCTSTR)Voltage, Index); - NameList_SetVolt(i, volt); - } - NameId[i].PinData.Volt = volt; - NameId[i].PinData.ProgVolt = volt; - //CreateVoltRequest(i,volt); - EnableWindow(AdvancedDialog, TRUE); - EnableWindow(MainWindow, TRUE); - DestroyWindow(NameVoltDialog); - } - } - return volt; -} - -double NameList_SetVolt(int Index, double volt) -{ - NameId[Index].PinData.Volt = volt; - return volt; -} |