-
Notifications
You must be signed in to change notification settings - Fork 8
/
MANETDoc.cpp
executable file
·195 lines (173 loc) · 4.65 KB
/
MANETDoc.cpp
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// MANETDoc.cpp : implementation of the CMANETDoc class
//
#include "stdafx.h"
#include "MANET.h"
#include "MANETDoc.h"
/////////////////////////////
#include "MANETView.h"
/////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMANETDoc
IMPLEMENT_DYNCREATE(CMANETDoc, CDocument)
BEGIN_MESSAGE_MAP(CMANETDoc, CDocument)
//{{AFX_MSG_MAP(CMANETDoc)
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_SEND_MAIL, OnFileSendMail)
ON_UPDATE_COMMAND_UI(ID_FILE_SEND_MAIL, OnUpdateFileSendMail)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMANETDoc construction/destruction
CMANETDoc::CMANETDoc()
{
// TODO: add one-time construction code here
}
CMANETDoc::~CMANETDoc()
{
int test=0;
}
BOOL CMANETDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
int RouterSize=Routers.GetSize();
for(int i=0;i<RouterSize;i++)
delete ((CRouter*)(Routers[i]));
Routers.RemoveAll();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMANETDoc serialization
void CMANETDoc::Serialize(CArchive& ar)
{
CString NotMainRouter = "NMR";
if (ar.IsStoring())
{
// TODO: add storing code here
/* ar<<traffics.GetSize();
for(i=0;i<traffics.GetSize();i++)
((CTraffic*)(traffics[i]))->Serialize(ar);
ar<<links.GetSize();
for(i=0;i<links.GetSize();i++)
((CLink*)(links[i]))->Serialize(ar);
*/
int RouterSize=Routers.GetSize();
ar<<RouterSize;
for(int ir=0;ir<RouterSize;ir++)
((CRouter*)(Routers[ir]))->Serialize(ar);
// links.Serialize(ar);
// routers.Serialize(ar);
// traffics.Serialize(ar);
for(int ir=0;ir<RouterSize;ir++)
{
Router=(CRouter*)(Routers[ir]);
int LinkSize=Router->Links.GetSize();
ar<<LinkSize;
for(int il=0;il<LinkSize;il++)
{
//if( (((CLink*)(Router->Links[il]))->Router1) == Router )
((CLink*)(Router->Links[il]))->Serialize(ar);
//else
// ar<<NotMainRouter;
}
int TrafficSize=Router->Traffics.GetSize();
ar<<TrafficSize;
for(int it=0;it<TrafficSize;it++)
((CTraffic*)(Router->Traffics[it]))->Serialize(ar);
}
}
else
{
// TODO: add loading code here
POSITION pos=GetFirstViewPosition();
CView* pView=GetNextView(pos);
int RouterSize;
ar>>RouterSize;
for(int ir=0;ir<RouterSize;ir++)
{
Router=new CRouter;
Router->Serialize(ar);
Routers.Add((CRouter*)Router);
Router->Create(Router->Caption,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,Router->Rectangle,(CMANETView*)pView,1);
//pView->UpdateWindow();
}
for(int ir=0;ir<RouterSize;ir++)
{
Router=(CRouter*)(Routers[ir]);
//CLink TempLink;
int LinkSize;
int duplex;
int frequency; //No. of Pixels per Tick
ar>>LinkSize;
CString caption;
for(int il=0;il<LinkSize;il++)
{
//TempLink.Serialize(&ar);
ar>>caption;
//if(caption != NotMainRouter)
if(Router->Caption == caption)
{
ar>>caption;
int ir2=0;
while((ir2<RouterSize)&&(((CRouter*)(Routers[ir2]))->Caption!=caption))
ir2++;
if(ir2<RouterSize)
{
//if(ir2>ir)
//{
ar>>frequency;
ar>>duplex;
Link = new CLink(Router,(CRouter*)(Routers[ir2]),frequency,duplex);
Link->Serialize(ar);
//router->links.Add(link);
//}
}
else
AfxMessageBox("Error in CLink Object! There is no destination router!");
}
else
{
ar>>caption>>frequency>>duplex;
}
}
int TrafficSize;
ar>>TrafficSize;
for(int it=0;it<TrafficSize;it++)
{
ar>>caption;
int it2=0;
while((it2<RouterSize)&&(((CRouter*)(Routers[it2]))->Caption!=caption))
it2++;
if(it2<RouterSize)
{
Traffic=new CTraffic(Router,(CRouter*)(Routers[it2]));
Traffic->Serialize(ar);
//no need for "router->traffics.Add(traffic);"
}
else
AfxMessageBox("Error in CTraffic Object! There is no destination router!");
}
}
((CMANETView*)pView)->UpdateWindow();
}
}
/////////////////////////////////////////////////////////////////////////////
// CMANETDoc diagnostics
#ifdef _DEBUG
void CMANETDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMANETDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMANETDoc commands