home *** CD-ROM | disk | FTP | other *** search
- // TestChildWnd.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "TestChildWnd.h"
- #include "DvDsDll.h"
-
- #include "VOfundecl.h"
- #include "VPfundecl.h"
- #include "VGfundecl.h"
- #include "GRfundecl.h"
- #include "VUerfundecl.h"
-
- #include "Msparams.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- // Data Structure used to rebind/rename vdp's
- typedef struct {
- CDvDsDll* pDsDll; //
- int arrayIndex;
- BOOL renameVdp;
- float* rebindArray;
- } VDP_TRAVERSAL_DATA;
-
-
- #define TEXT_BUFFER_SIZE 80
- static char g_TextBuffer[TEXT_BUFFER_SIZE];
-
- extern "C" {
-
- GLOBALREF long M_runtype;
-
- /////////////////////////////////////////////////////////////////////////////
- //
- ADDRESS
- CountVdps(OBJECT vd, VARDESC vdp, ADDRESS args)
- {
- int* nVdps = (int*)args;
- (*nVdps)++;
- return V_CONTINUE_TRAVERSAL;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // DataViews traversal function that gets called for every vdp if the
- // data browser uses custom tag names. We ask the browser to supply a
- // human readable name for the vdp so that they appear as expected in
- // graph legends as expected...
- //
- ADDRESS
- RenameRebindVdp(OBJECT data_obj, VARDESC vdp, ADDRESS pData)
- {
- VDP_TRAVERSAL_DATA *vdpData = (VDP_TRAVERSAL_DATA*)pData;
-
- // Rename the vdp if necessary...
- if(vdpData->pDsDll && vdpData->renameVdp)
- {
- DV_DSDLLDATA data;
-
- data.m_Context = DV_DSDLL_GETNAMEBITS;
- data.m_Pvdp = vdp;
- data.m_pszVarname = 0;
- data.m_pszVartags = 0;
-
- vdpData->pDsDll->HandleRequest(&data, 0);
-
- if(data.m_pszVarname)
- VPvdvarname(vdp,data.m_pszVarname);
- }
-
- // ... now rebind it (special casing text variables)...
- if( VGvdtype( vdp ) != V_T_TYPE )
- {
- TvdPutBuffer(vdp, (ADDRESS)&(vdpData->rebindArray[vdpData->arrayIndex++]));
- }
- else
- {
- VPvddim( vdp, 1, 1, TEXT_BUFFER_SIZE );
- TvdPutBuffer( vdp, (ADDRESS)g_TextBuffer );
- }
-
- return V_CONTINUE_TRAVERSAL;
- }
-
- }
-
-
- UINT CTestChildWnd::m_Speed[] = { 10, 20, 50, 100, 125, 200, 250, 333, 500, 1000 };
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CALLBACK EXPORT TimerProc(
- HWND hWnd, //handle of CWnd that called SetTimer
- UINT nMsg, //WM_TIMER
- UINT nIDEvent, //timer identification
- DWORD dwTime //system time
- )
- {
- CTestChildWnd* runView = (CTestChildWnd*)nIDEvent;
- runView->UpdateView();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTestChildWnd dialog
-
-
- CTestChildWnd::CTestChildWnd(UINT aid, VIEW v, char* clut, CWnd* pParent /*=NULL*/)
- : CDialog(CTestChildWnd::IDD, pParent), m_areaID(aid), m_View(v),
- m_Screen(0), m_Drawport(0), m_Loc(0), m_pszClut(clut), m_pRebindArray(0),
- m_NumVdps(0),m_SpeedIndex(DEFAULT_UPD_RATE), m_TimerID(0), m_Running(FALSE),
- m_Paused(FALSE), m_DataCounter(0)
- {
- //{{AFX_DATA_INIT(CTestChildWnd)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
-
- CTestChildWnd::~CTestChildWnd()
- {
- if(m_pRebindArray)
- delete[] m_pRebindArray;
- }
-
-
- void CTestChildWnd::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTestChildWnd)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CTestChildWnd, CDialog)
- //{{AFX_MSG_MAP(CTestChildWnd)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_WM_PAINT()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_RBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_RBUTTONUP()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // Simulates reading default.dat. The file default.dat contains 78 numbers
- // repeated over and over. So does this, with the same numbers found in
- // in the standard default.dat file that gets shipped with DataViews.
- //
- #define NUM_DATA 78
- void CTestChildWnd::UpdateView()
- {
- static double DefaultData[NUM_DATA] = {
- 0.01, 0.1, 0.4, 0.35, 0.7,
- 0.8, 0.2, 0.24, 0.26, 0.43,
- 0.54, 0.6, 0.21, 0.32, 0.46,
- 0.73, 0.86, 0.92, 0.0, 0.3,
- 0.5, 0.73, 0.89, 0.58, 0.3,
- 0.5, 0.63, 0.79, 0.83, 0.67,
- 0.3, 0.42, 0.57, 0.74, 0.93,
- 0.57, 0.35, 0.63, 0.74, 0.87,
- 0.94, 0.81, 0.02, 0.4, 0.42,
- 0.53, 0.64, 0.40, 0.02, 0.5,
- 0.85, 0.87, 0.64, 0.3, 0.4,
- 0.6, 0.66, 0.83, 0.75, 0.36,
- 0.37, 0.44, 0.52, 0.75, 0.59,
- 0.43, 0.1, 0.73, 0.84, 0.81,
- 0.73, 0.69, 0.1, 0.58, 0.74,
- 0.79, 0.80, 0.79
- };
-
- if(m_DataCounter && !(m_DataCounter % NUM_DATA))
- {
- m_DataCounter = 0;
- TRACE0("Resetting data counter...\n");
- }
-
- if(m_pRebindArray)
- {
- for(int i=0;i<m_NumVdps;i++)
- m_pRebindArray[i] = (float)(DefaultData[m_DataCounter++]);
- }
-
- M_runtype = MRUNNING;
- TdpDrawNext(m_Drawport);
-
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- BOOL CTestChildWnd::SetupLoc(const MSG* msg)
- {
- if(m_Screen && m_Drawport)
- {
- WINEVENT we;
- GRwe_convert((ADDRESS)msg, &we);
- return (BOOL)TloWinEventSetup(m_Loc,&we,m_Screen,m_Drawport);
- }
- return FALSE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::HandleOnDraw(const MSG* msg)
- {
- if(m_Screen && m_Drawport)
- {
- TscSetCurrentScreen(m_Screen);
- if(TdpIsDrawn(m_Drawport ))
- {
- WINEVENT we;
- GRwe_convert((ADDRESS)msg, &we);
- TdpRedraw(m_Drawport, &we.region, YES);
- }
- else
- TdpDraw(m_Drawport);
- TscFlush(m_Screen);
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::SetUpdateRate(int rate)
- {
- if(rate >=0 && rate < NUM_UPD_RATES)
- {
- m_SpeedIndex = rate;
- InstallTimer();
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::InstallTimer()
- {
- if(m_TimerID)
- KillTimer(m_TimerID);
- m_TimerID = SetTimer((UINT)this,m_Speed[m_SpeedIndex],TimerProc );
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::HandleMousePointerMsg(const MSG* msg)
- {
- if(m_Screen && m_Running && !m_Paused)
- {
- SetupLoc(msg);
- VUerHandleLocEvent(m_Loc);
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::StartTest()
- {
- m_Running = TRUE;
- m_Paused = FALSE;
- m_DataCounter = 0;
- UpdateView();
- InstallTimer();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::StopTest()
- {
- KillTimer(m_TimerID);
- if (m_Drawport)
- {
- if(m_pRebindArray)
- {
- for(int i=0;i<m_NumVdps;i++)
- m_pRebindArray[i] = (float)0.0;
- }
- TscErase(m_Screen);
- TdpDraw(m_Drawport);
- }
- m_Running = FALSE;
- m_Paused = FALSE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::PauseTest()
- {
- if(m_Paused)
- {
- m_Paused = FALSE;
- InstallTimer();
- }
- else
- {
- m_Paused = TRUE;
- KillTimer(m_TimerID);
- m_TimerID = 0;
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTestChildWnd message handlers
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- int CTestChildWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CDialog::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // Parent dialog contains a static group box we'll use as a border for
- // our actual test area screen. Locate it, size it, and make our child
- // dialog fit inside it...
- m_pParent = GetParent();
- CWnd *testArea = m_pParent->GetDlgItem(m_areaID);
-
- CRect testAreaRect;
-
- testArea->GetWindowRect(&testAreaRect);
- m_pParent->ScreenToClient(&testAreaRect);
- MoveWindow(&testAreaRect, FALSE);
-
- // Done with static border...
- testArea->DestroyWindow();
-
- return 0;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::OnDestroy()
- {
- TdpDestroy(m_Drawport);
- TviDestroy(m_View);
- TscClose(m_Screen);
- VOloDereference(m_Loc);
- CDialog::OnDestroy();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CTestChildWnd::OnPaint()
- {
- HandleOnDraw(GetCurrentMessage());
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- BOOL CTestChildWnd::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Check to see if the current data browser uses custom vdp names, and if
- // so, we'll need to go through all of the vdp's used in graphs and rename
- // them to their 'human readable' form (which the data browser will supply)
- // so that they will make sense in graph legends...
- CDvDsDll* pDsDll = 0;
-
- VDP_TRAVERSAL_DATA args;
-
- DVIGetInterface(IID_Datasource, (void**)&pDsDll);
-
- if(pDsDll)
- {
- DV_DSDLLDATA data;
- data.m_Context = DV_DSDLL_QUERYDLL;
- pDsDll->HandleRequest(&data, this);
-
- args.renameVdp = (BOOL)(data.m_Context & DV_DSDLL_USESCUSTOMTAGS);
- args.pDsDll = pDsDll;
- }
- else
- {
- args.renameVdp = FALSE;
- args.pDsDll = 0;
- }
-
- OBJECT drawing = TviGetDrawing(m_View);
- TobForEachVdp(drawing,CountVdps,(ADDRESS)&m_NumVdps);
- if(m_NumVdps)
- m_pRebindArray = new float[m_NumVdps];
-
- args.arrayIndex = 0;
- args.rebindArray = m_pRebindArray;
- TobForEachVdp(drawing,RenameRebindVdp,(ADDRESS)&args);
-
- // Create a location object...used to make input objects respond...
- m_Loc = VOloCreate();
-
- // OK, now we can set up the DataViews screen and drawport. One noteworthy
- // point here is that the interface to DV-Draw, besides including a cloned
- // view of the view being currently edited, it also passed in a viewport
- // rectangle if the user happens to be zoomed in, allowing you to run the
- // view as the user currently sees it. If this is the desired behavior, then
- // this is where it would be done...
-
- m_Screen = TscOpenSet("W", m_pszClut,
- V_WIN32_WINDOW_HANDLE, GetSafeHwnd(),
- V_WIN32_DOUBLE_BUFFER,TRUE,
- V_ACTIVE_CURSOR,V_END_OF_LIST );
-
- m_Drawport = TdpCreateStretch(m_Screen,m_View,0,0);
-
- M_runtype = MRUNNING;
-
- TscErase(m_Screen);
- TdpDraw(m_Drawport);
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // Mouse and pointer message handlers...
- //
- void CTestChildWnd::OnMouseMove(UINT nFlags, CPoint point)
- { HandleMousePointerMsg(GetCurrentMessage()); }
-
- void CTestChildWnd::OnLButtonDown(UINT nFlags, CPoint point)
- { HandleMousePointerMsg(GetCurrentMessage()); }
-
- void CTestChildWnd::OnRButtonDown(UINT nFlags, CPoint point)
- { HandleMousePointerMsg(GetCurrentMessage()); }
-
- void CTestChildWnd::OnLButtonUp(UINT nFlags, CPoint point)
- { HandleMousePointerMsg(GetCurrentMessage()); }
-
- void CTestChildWnd::OnRButtonUp(UINT nFlags, CPoint point)
- { HandleMousePointerMsg(GetCurrentMessage()); }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
-