LAPTOP-SNT8I5JK\Boounion
2025-03-21 980d4fc1690b4f8a81dc65e8573d2898f34a406f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// CPageGraph2.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "CPageGraph2.h"
#include "afxdialogex.h"
 
 
// CPageGraph2 对话框
 
IMPLEMENT_DYNAMIC(CPageGraph2, CDialogEx)
 
CPageGraph2::CPageGraph2(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_PAGE_GRAPH2, pParent)
{
    m_pEqsGraphWnd = nullptr;
    m_crBkgnd = PAGE_GRPAH2_BACKGROUND_COLOR;
    m_hbrBkgnd = nullptr;
}
 
CPageGraph2::~CPageGraph2()
{
}
 
void CPageGraph2::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
 
 
BEGIN_MESSAGE_MAP(CPageGraph2, CDialogEx)
    ON_WM_CTLCOLOR()
    ON_WM_DESTROY()
    ON_WM_SIZE()
    ON_WM_TIMER()
END_MESSAGE_MAP()
 
 
// CPageGraph2 消息处理程序
 
 
BOOL CPageGraph2::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    SetTimer(1, 2000, nullptr);
 
 
    // filter graph wnd
    EqsGraphListener listener;
    listener.onCheckConnectPin = [](PIN* pPin1, PIN* pPin2) -> bool {
        ASSERT(pPin1);
        ASSERT(pPin2);
        ASSERT(pPin1->pData);
        ASSERT(pPin2->pData);
 
        //int nRet = ((IPin*)pPin1->pData)->checkConnectPin((IPin*)pPin2->pData);
        //if (nRet >= 0) {
        //    return true;
        //}
 
        return false;
    };
    listener.onConnectPin = [](PIN* pPin1, PIN* pPin2) -> bool {
        ASSERT(pPin1);
        ASSERT(pPin2);
        ASSERT(pPin1->pData);
        ASSERT(pPin2->pData);
 
        //int nRet = ((IPin*)pPin1->pData)->connectPin((IPin*)pPin2->pData);
        //if (nRet >= 0) {
        //    return true;
        //}
 
        return false;
    };
    listener.onDisconnectPin = [](PIN* pPin) -> bool {
        ASSERT(pPin);
        ASSERT(pPin->pData);
 
        //int nRet = ((IPin*)pPin->pData)->disconnect();
        //if (nRet >= 0) {
        //    return true;
        //}
 
        return false;
    };
    listener.onDeleteEqItem = [&](EQITEM* pItem) -> bool {
        ASSERT(pItem);
        ASSERT(pItem->pData);
        return true;
        // return _filterManager.unload((CFilter*)pFilter->pData) >= 0;
    };
    listener.onEqItemPosChanged = [&](EQITEM* pItem, int x, int y) -> void {
        ASSERT(pItem);
    };
    listener.onDblckEqItem = [&](EQITEM* pItem) -> bool {
        ASSERT(pItem);
        return true;
    };
    listener.onRclickEqItem = [&](EQITEM* pItem) -> bool {
        ASSERT(pItem);
        return true;
    };
 
    m_pEqsGraphWnd = CEqsGraphWnd::FromHandle(GetDlgItem(IDC_EQSGRAPHWND1)->m_hWnd);
    m_pEqsGraphWnd->SetBkgndColor(m_crBkgnd);
    m_pEqsGraphWnd->SetOnListener(listener);
 
 
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}
 
 
HBRUSH CPageGraph2::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
 
    if (nCtlColor == CTLCOLOR_STATIC) {
        pDC->SetBkColor(m_crBkgnd);
        pDC->SetTextColor(RGB(0, 0, 0));
    }
 
    if (m_hbrBkgnd == nullptr) {
        m_hbrBkgnd = CreateSolidBrush(m_crBkgnd);
    }
 
    return m_hbrBkgnd;
}
 
 
void CPageGraph2::OnDestroy()
{
    CDialogEx::OnDestroy();
 
    if (m_hbrBkgnd != nullptr) {
        ::DeleteObject(m_hbrBkgnd);
    }
}
 
 
void CPageGraph2::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    if (GetDlgItem(IDC_EQSGRAPHWND1) == nullptr) return;
 
    CRect rcClient;
    GetClientRect(&rcClient);
    GetDlgItem(IDC_EQSGRAPHWND1)->MoveWindow(0, 0, rcClient.Width(), rcClient.Height());
}
 
#define INPIN        1
#define OUTPIN        2
void CPageGraph2::AddEqToGraphWnd(SERVO::CEquipment* pEquipment)
{
    EQITEM* pItem = m_pEqsGraphWnd->AddItem(0, pEquipment->getName().c_str(), (DWORD_PTR)pEquipment);
    m_pEqsGraphWnd->SetItemType(pItem, ITEM_SMALL);
    std::vector<SERVO::CPin*>& inPins = pEquipment->getInputPins();
    for (auto inPin : inPins) {
        m_pEqsGraphWnd->AddPin(pItem, INPIN, inPin->getName().c_str(), (DWORD_PTR)inPin);
    }
 
    std::vector<SERVO::CPin*>& outPins = pEquipment->getOutputPins();
    for (auto outPin : outPins) {
        m_pEqsGraphWnd->AddPin(pItem, OUTPIN, outPin->getName().c_str(), (DWORD_PTR)outPin);
    }
}
 
void CPageGraph2::OnTimer(UINT_PTR nIDEvent)
{
    if (1 == nIDEvent) {
        KillTimer(1);
        std::list<SERVO::CEquipment*>& eqs = theApp.m_model.m_master.getEquipmentList();
        for (auto item : eqs) {
            AddEqToGraphWnd(item);
        }
    }
 
    CDialogEx::OnTimer(nIDEvent);
}