Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

353 lines
9.7 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 31/07/2001
// PROJECT:
// SUBSYSTEM:
// FILE: PropDCLinkDlg.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of PropDCLinkDlg.cpp
//----------------------------------------------------------------------------
// PropDCLinkDlg.cpp : implementation file
//
#include "stdafx.h"
#include "setuplgs.h"
//#include "PropDCLinkDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPropDCLinkDlg dialog
CPropDCLinkDlg::CPropDCLinkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPropDCLinkDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPropDCLinkDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pDryContact = NULL;
m_pDevice = NULL;
}
void CPropDCLinkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPropDCLinkDlg)
DDX_Control(pDX, IDC_LIST_TEMPLATE, m_ListTemplate);
DDX_Control(pDX, IDC_LIST_LINK, m_ListLink);
DDX_Control(pDX, IDC_LIST_DEVICE, m_ListDevice);
DDX_Control(pDX, IDC_BUTTON_DELALL, m_ButtonDelAll);
DDX_Control(pDX, IDC_BUTTON_DEL, m_ButtonDel);
DDX_Control(pDX, IDC_BUTTON_ADDALL, m_ButtonAddAll);
DDX_Control(pDX, IDC_BUTTON_ADD, m_ButtonAdd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPropDCLinkDlg, CDialog)
//{{AFX_MSG_MAP(CPropDCLinkDlg)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_ADDALL, OnButtonAddall)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
ON_BN_CLICKED(IDC_BUTTON_DELALL, OnButtonDelall)
ON_LBN_SELCHANGE(IDC_LIST_DEVICE, OnSelchangeList)
ON_LBN_SELCHANGE(IDC_LIST_LINK, OnSelchangeList)
ON_LBN_SELCHANGE(IDC_LIST_TEMPLATE, OnSelchangeList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
typedef struct
{
PVOID dataD;
PVOID dataT;
}DATAPTR, *PDATAPTR;
void CPropDCLinkDlg::OnButtonAdd()
{
int nIndexD = m_ListDevice.GetCurSel();
int nIndexT = m_ListTemplate.GetCurSel();
if( nIndexD >= 0 && nIndexT >= 0 )
{
PDATAPTR pDataPtr = new DATAPTR;
CString dname;
m_ListDevice.GetText( nIndexD, dname );
pDataPtr->dataD = m_ListDevice.GetItemDataPtr( nIndexD );
CString tname;
m_ListTemplate.GetText( nIndexT, tname );
pDataPtr->dataT = m_ListTemplate.GetItemDataPtr( nIndexT );
CString linkname;
linkname.Format( _T("D(%s) <-> T(%s)"), dname, tname );
int nIndex = m_ListLink.AddString( linkname );
m_ListLink.SetItemDataPtr( nIndex, pDataPtr );
m_ListDevice.DeleteString( nIndexD );
m_ListTemplate.DeleteString( nIndexT );
}
OnSelchangeList();
}
void CPropDCLinkDlg::OnButtonAddall()
{
while( m_ListDevice.GetCount() && m_ListTemplate.GetCount() )
{
m_ListDevice.SetCurSel( 0 );
m_ListTemplate.SetCurSel( 0 );
OnButtonAdd();
}
}
void CPropDCLinkDlg::OnButtonDel()
{
int nIndex = m_ListLink.GetCurSel();
if( nIndex >= 0 )
{
PDATAPTR pDataPtr = (PDATAPTR)m_ListLink.GetItemData( nIndex );
CString dname;
dname.Format( _T("%02d"), (int)pDataPtr->dataD );
int nIndexD = m_ListDevice.AddString( dname );
m_ListDevice.SetItemDataPtr( nIndexD, pDataPtr->dataD );
CString tname;
tname.Format( _T("%s"), ((COFTemplateDCBit*)pDataPtr->dataT)->GetName() );
int nIndexT = m_ListTemplate.AddString( tname );
m_ListTemplate.SetItemDataPtr( nIndexT, pDataPtr->dataT );
m_ListLink.DeleteString( nIndex );
delete pDataPtr;
}
OnSelchangeList();
}
void CPropDCLinkDlg::OnButtonDelall()
{
while( m_ListLink.GetCount() )
{
m_ListLink.SetCurSel( 0 );
OnButtonDel();
}
}
void CPropDCLinkDlg::OnSelchangeList()
{
m_ButtonAdd.EnableWindow( m_ListDevice.GetCurSel() >= 0 &&
m_ListTemplate.GetCurSel() >= 0 );
m_ButtonAddAll.EnableWindow( m_ListDevice.GetCount() &&
m_ListTemplate.GetCount() );
m_ButtonDel.EnableWindow( m_ListLink.GetCurSel() >= 0 );
m_ButtonDelAll.EnableWindow( m_ListLink.GetCount() );
}
void CPropDCLinkDlg::FillControls()
{
CObjectFactory *pOF = m_pDevice->GetOF();
/*
for( int i = 0; i < pOF->TemplateGetCount(); i++ )
{
int nIndex = m_ComboTemplate.AddString( pOF->TemplateGet(i)->GetName() );
m_ComboTemplate.SetItemDataPtr( nIndex, (PVOID)pOF->TemplateGet(i) );
}
*/
/*
for( int i = 0; i < m_pDevice->m_nDryContact; i++ )
{
// if bit link to this dry contact or bit link free
if( ( m_pDevice->m_pDryContact[i].nIndex == m_pDryContact->GetIndex() &&
m_pDevice->m_pDryContact[i].nType == m_pDryContact->GetType() ) ||
m_pDevice->m_pDryContact[i].nBit == -1 )
{
CString pinname;
pinname.Format( _T("%02d"), i );
int nIndex = m_ListDevice.AddString( pinname );
m_ListDevice.SetItemDataPtr( nIndex, (PVOID)i );
}
}
*/
while( m_ListLink.GetCount() )
m_ListLink.DeleteString( 0 );
// draw image
if( m_pDryContact->m_nTemplate >= 0 )
{
COFTemplateDC *pTempl = (COFTemplateDC*)pOF->TemplateGet( m_pDryContact->m_nTemplate );
while( m_ListTemplate.GetCount() )
m_ListTemplate.DeleteString( 0 );
for( int i = 0; i < pTempl->BitGetCount(); i++ )
{
CString bitname;
bitname.Format( _T("%s"), pTempl->BitGet(i)->GetName() );
int nIndex = m_ListTemplate.AddString( bitname );
m_ListTemplate.SetItemDataPtr( nIndex, (PVOID)pTempl->BitGet(i) );
}
while( m_ListLink.GetCount() )
m_ListLink.DeleteString( 0 );
m_ImageWnd.GetBitList()->RemoveAll();
for( i = 0; i < pTempl->BitGetCount(); i++ )
m_ImageWnd.GetBitList()->AddTail( pTempl->BitGet( i ) );
HBITMAP hBitmap = pTempl->GetFileGroup()->LoadImage( pTempl->GetBG(), IMAGE_BITMAP, 0, 0, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE );
m_ImageWnd.SetImage( hBitmap );
// m_ImageWnd.SetImage( pTempl->FileGroupGetTemp( pTempl->GetBG() ) );
// m_ImageWnd.SetImage( pTempl->GetBG() );
}
// fill links
for( i = 0; i < m_pDevice->m_nDryContact; i++ )
{
// if bit link to this dry contact and bit link exist
if( m_pDevice->m_pDryContact[i].nIndex == m_pDryContact->GetIndex() &&
m_pDevice->m_pDryContact[i].nType == m_pDryContact->GetType() &&
m_pDevice->m_pDryContact[i].nBit != -1 )
{
int nIndex;
for( int j = 0; j < m_ListDevice.GetCount(); j++ )
{
if( (int)m_ListDevice.GetItemDataPtr( j ) == i )
{
nIndex = j;
break;
}
}
m_ListDevice.SetCurSel( nIndex );
COFTemplateDC *pTempl = (COFTemplateDC*)pOF->TemplateGet( m_pDryContact->m_nTemplate );
nIndex = m_ListTemplate.FindString( -1, pTempl->BitGet( m_pDevice->m_pDryContact[i].nBit )->GetName() );
m_ListTemplate.SetCurSel( nIndex );
OnButtonAdd();
}
}
OnSelchangeList();
}
BOOL CPropDCLinkDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rect;
GetDlgItem( IDC_STATIC_TEMPLATE )->GetWindowRect( &rect );
ScreenToClient( &rect );
m_ImageWnd.Create( this, &rect );
FillControls();
return TRUE;
}
BOOL CPropDCLinkDlg::DestroyWindow()
{
while( m_ListLink.GetCount() )
{
delete (PDATAPTR)m_ListLink.GetItemData( 0 );
m_ListLink.DeleteString( 0 );
}
return CDialog::DestroyWindow();
}
int CPropDCLinkDlg::DoModal(COFDevice *pSensor, COFDevice *pDryContact)
{
ASSERT( pDryContact );
ASSERT( pSensor );
m_pDevice = pSensor;
m_pDryContact = (COFDeviceDryContacts*)pDryContact;
return CDialog::DoModal();
}
void CPropDCLinkDlg::OnOK()
{
// m_pDryContact->m_nTemplate = m_ComboTemplate.GetCurSel();
for( int i = 0; i < m_pDevice->GetPinCount(); i++ )
{
// search for sensor (RABBIT) d/c pin
COFPin *pPin = m_pDevice->GetPin(i);
if( pPin->GetType() == PT_SENSOR_INPUT )
{
CObjectFactory *pOF = m_pDevice->GetOF();
// delete all links in pin belong this dry-contacts
for( int j = 0; j < pPin->m_nDeviceCount; )
{
COFDevice *pD2 = pOF->DeviceGet( pPin->m_pDevice[j].nIndex, pPin->m_pDevice[j].nType );
if( pD2 == m_pDryContact )
{
COFPin *pP2 = pD2->GetPin( pPin->m_pDevice[j].nPin );
pOF->ConnectionDisconnect( pPin, pP2 );
// pPin->Disconnect( pP2 );
// pP2->Disconnect( pPin );
j = 0; // after delete start again
}
else j++;
}
// clear all dry contacts links
for( j = 0; j < m_pDevice->m_nDryContact; j++ )
{
// if bit link to this dry contact
if( m_pDevice->m_pDryContact[i].nIndex == m_pDryContact->GetIndex() &&
m_pDevice->m_pDryContact[i].nType == m_pDryContact->GetType() )
{
m_pDevice->m_pDryContact[j].nBit = -1;
m_pDevice->m_pDryContact[j].nIndex = -1;
m_pDevice->m_pDryContact[j].nType = -1;
}
}
// add link to pin
if( m_ListLink.GetCount() )
{
// connect dry contact pin with sensor pin
pPin->Connect( m_pDryContact->GetPin(0) );
// connect d/c bits with template bits
for( int nIndex = 0; nIndex < m_ListLink.GetCount(); nIndex++ )
{
PDATAPTR pDataPtr = (PDATAPTR)m_ListLink.GetItemDataPtr( nIndex );
COFTemplateDCBit *pBit = (COFTemplateDCBit*)pDataPtr->dataT;
COFTemplateDC *pTempl = pOF->TemplateGet( m_pDryContact->m_nTemplate ); //(COFTemplateDC*)m_ComboTemplate.GetItemDataPtr( 0 );
for( j = 0; j < pTempl->BitGetCount(); j++ )
{
if( pTempl->BitGet( j ) == pDataPtr->dataT )
{
m_pDevice->m_pDryContact[ (int)pDataPtr->dataD ].nBit = j;
m_pDevice->m_pDryContact[ (int)pDataPtr->dataD ].nIndex = m_pDryContact->GetIndex();
m_pDevice->m_pDryContact[ (int)pDataPtr->dataD ].nType = m_pDryContact->GetType();
break;
}
}
}
}
break;
}
}
CDialog::OnOK();
}