| 1 |
/* --------------------------------------------------------------------- */ |
| 2 |
/* NeuroManager - A spike train analysis tool */ |
| 3 |
/* Copyright (c) 2005-2006 RIKEN, Japan. All rights reserved. */ |
| 4 |
/* http://satellite.sourceforge.jp/ */ |
| 5 |
/* --------------------------------------------------------------------- */ |
| 6 |
/* This program is free software; you can redistribute it and/or */ |
| 7 |
/* modify it under the terms of the GNU General Public License */ |
| 8 |
/* as published by the Free Software Foundation; either version 2 */ |
| 9 |
/* of the License, or (at your option) any later version. */ |
| 10 |
/* */ |
| 11 |
/* This program is distributed in the hope that it will be useful, */ |
| 12 |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 13 |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 14 |
/* GNU General Public License for more details. */ |
| 15 |
/* */ |
| 16 |
/* You should have received a copy of the GNU General Public License */ |
| 17 |
/* along with this program; see the file COPYING.txt. If not, write */ |
| 18 |
/* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth */ |
| 19 |
/* Floor, Boston, MA 02110-1301, USA. */ |
| 20 |
/* --------------------------------------------------------------------- */ |
| 21 |
|
| 22 |
/* $Id: NeuroManagerDoc.cpp,v 1.4 2006/03/20 09:09:43 orrisroot Exp $ */ |
| 23 |
|
| 24 |
// NeuroManagerDoc.cpp : implementation of the CNeuroManagerDoc class |
| 25 |
// |
| 26 |
|
| 27 |
#include "stdafx.h" |
| 28 |
#include "NeuroManager.h" |
| 29 |
#include "NeuroManagerDoc.h" |
| 30 |
|
| 31 |
#ifdef _DEBUG |
| 32 |
#define new DEBUG_NEW |
| 33 |
#endif |
| 34 |
|
| 35 |
|
| 36 |
// CNeuroManagerDoc |
| 37 |
|
| 38 |
IMPLEMENT_DYNCREATE( CNeuroManagerDoc, CDocument ) |
| 39 |
|
| 40 |
BEGIN_MESSAGE_MAP( CNeuroManagerDoc, CDocument ) |
| 41 |
END_MESSAGE_MAP() |
| 42 |
|
| 43 |
|
| 44 |
// CNeuroManagerDoc construction/destruction |
| 45 |
|
| 46 |
CNeuroManagerDoc::CNeuroManagerDoc() |
| 47 |
: m_strFileName( _T( "" ) ) |
| 48 |
{ |
| 49 |
// TODO: add one-time construction code here |
| 50 |
m_pData = NULL; |
| 51 |
//MessageBox(NULL, "CNeuroManagerDoc()", "Constractor", MB_OK); |
| 52 |
// set menu bar for plugins |
| 53 |
m_MCDataManager.Initialize(); |
| 54 |
} |
| 55 |
|
| 56 |
CNeuroManagerDoc::~CNeuroManagerDoc() |
| 57 |
{ |
| 58 |
if ( m_pData ) |
| 59 |
{ |
| 60 |
delete m_pData; |
| 61 |
m_pData = NULL; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
BOOL CNeuroManagerDoc::OnNewDocument() |
| 66 |
{ |
| 67 |
// confirmation |
| 68 |
if ( !m_strFileName.IsEmpty() || m_pData ) |
| 69 |
{ |
| 70 |
int stat = AfxMessageBox( _T( "Do you want to close current data file" ), |
| 71 |
MB_OKCANCEL ); |
| 72 |
if ( stat == IDCANCEL ) |
| 73 |
return FALSE; |
| 74 |
} |
| 75 |
|
| 76 |
if ( !CDocument::OnNewDocument() ) |
| 77 |
return FALSE; |
| 78 |
// TODO: add reinitialization code here |
| 79 |
// (SDI documents will reuse this document) |
| 80 |
m_strFileName = _T( "" ); |
| 81 |
if ( m_pData ) |
| 82 |
{ |
| 83 |
delete m_pData; |
| 84 |
m_pData = NULL; |
| 85 |
UpdateAllViews( NULL ); |
| 86 |
} |
| 87 |
|
| 88 |
return TRUE; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
// CNeuroManagerDoc serialization |
| 93 |
|
| 94 |
void CNeuroManagerDoc::Serialize( CArchive& ar ) |
| 95 |
{ |
| 96 |
if ( ar.IsStoring() ) |
| 97 |
{ |
| 98 |
// TODO: add storing code here |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
// TODO: add loading code here |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
// CNeuroManagerDoc diagnostics |
| 108 |
|
| 109 |
#ifdef _DEBUG |
| 110 |
void CNeuroManagerDoc::AssertValid() const |
| 111 |
{ |
| 112 |
CDocument::AssertValid(); |
| 113 |
} |
| 114 |
|
| 115 |
void CNeuroManagerDoc::Dump( CDumpContext& dc ) const |
| 116 |
{ |
| 117 |
CDocument::Dump( dc ); |
| 118 |
} |
| 119 |
#endif //_DEBUG |
| 120 |
|
| 121 |
|
| 122 |
// get data name |
| 123 |
CString CNeuroManagerDoc::getFileName() const |
| 124 |
{ |
| 125 |
return m_strFileName; |
| 126 |
} |
| 127 |
|
| 128 |
BOOL CNeuroManagerDoc::OnOpenDocument( LPCTSTR lpszPathName ) |
| 129 |
{ |
| 130 |
// confirmation |
| 131 |
if ( !m_strFileName.IsEmpty() || m_pData ) |
| 132 |
{ |
| 133 |
int stat = AfxMessageBox( _T( "Do you want to close current data file" ), |
| 134 |
MB_OKCANCEL ); |
| 135 |
if ( stat == IDCANCEL ) |
| 136 |
return FALSE; |
| 137 |
} |
| 138 |
|
| 139 |
if ( !CDocument::OnOpenDocument( lpszPathName ) ) |
| 140 |
return FALSE; |
| 141 |
// delete previous data object |
| 142 |
if ( m_pData ) |
| 143 |
{ |
| 144 |
delete m_pData; |
| 145 |
m_pData = NULL; |
| 146 |
} |
| 147 |
m_strFileName = lpszPathName; |
| 148 |
m_pData = CreateDataInstance(); |
| 149 |
BOOL b = m_pData->LoadDataFile( lpszPathName ); |
| 150 |
if ( b ) |
| 151 |
{ |
| 152 |
m_pData->PrintDataInfo(); |
| 153 |
} |
| 154 |
UpdateAllViews( NULL ); |
| 155 |
return b; |
| 156 |
} |
| 157 |
|
| 158 |
BOOL CNeuroManagerDoc::OnSaveDocument( LPCTSTR lpszPathName ) |
| 159 |
{ |
| 160 |
SetModifiedFlag( FALSE ); |
| 161 |
return TRUE; |
| 162 |
// disable to call Serialize() |
| 163 |
// return CDocument::OnSaveDocument(lpszPathName); |
| 164 |
} |
| 165 |
|
| 166 |
void CNeuroManagerDoc::AttachData( UINT ch ) const |
| 167 |
{ |
| 168 |
ASSERT( m_pData ); |
| 169 |
m_pData->AttachData( ch ); |
| 170 |
} |
| 171 |
|
| 172 |
void CNeuroManagerDoc::DetachData() const |
| 173 |
{ |
| 174 |
ASSERT( m_pData ); |
| 175 |
m_pData->DetachData(); |
| 176 |
} |
| 177 |
|
| 178 |
double CNeuroManagerDoc::GetData( QWORD pos ) const |
| 179 |
{ |
| 180 |
ASSERT( m_pData ); |
| 181 |
return m_pData->GetData( pos ); |
| 182 |
} |
| 183 |
|
| 184 |
double CNeuroManagerDoc::GetYAxisRange( UINT ch ) const |
| 185 |
{ |
| 186 |
ASSERT( m_pData ); |
| 187 |
return m_pData->GetYAxisRange( ch ); |
| 188 |
} |
| 189 |
|
| 190 |
BOOL CNeuroManagerDoc::IsMapped() const |
| 191 |
{ |
| 192 |
if ( m_pData ) |
| 193 |
return m_pData->IsMapped(); |
| 194 |
return FALSE; |
| 195 |
} |
| 196 |
|
| 197 |
double CNeuroManagerDoc::GetSamplingRate() const |
| 198 |
{ |
| 199 |
ASSERT( m_pData ); |
| 200 |
return m_pData->GetSamplingRate(); |
| 201 |
} |
| 202 |
|
| 203 |
double CNeuroManagerDoc::GetPosTime( QWORD pos ) const |
| 204 |
{ |
| 205 |
ASSERT( m_pData ); |
| 206 |
return m_pData->GetPosTime( pos ); |
| 207 |
} |
| 208 |
|
| 209 |
UINT CNeuroManagerDoc::GetChannelNumber() const |
| 210 |
{ |
| 211 |
ASSERT( m_pData ); |
| 212 |
return m_pData->GetChannelNumber(); |
| 213 |
} |
| 214 |
|
| 215 |
QWORD CNeuroManagerDoc::GetDataLength() const |
| 216 |
{ |
| 217 |
ASSERT( m_pData ); |
| 218 |
return m_pData->GetDataLength(); |
| 219 |
} |
| 220 |
|
| 221 |
UINT CNeuroManagerDoc::GetBitLength() const |
| 222 |
{ |
| 223 |
ASSERT( m_pData ); |
| 224 |
return m_pData->GetBitLength(); |
| 225 |
} |
| 226 |
|
| 227 |
BOOL CNeuroManagerDoc::GetByteSwap() const |
| 228 |
{ |
| 229 |
ASSERT( m_pData ); |
| 230 |
return m_pData->GetByteSwap(); |
| 231 |
} |
| 232 |
|
| 233 |
BOOL CNeuroManagerDoc::SetPlguinMenu( CMenu *ParentMenu ) |
| 234 |
{ |
| 235 |
BOOL bReturn; |
| 236 |
bReturn = m_MCDataManager.InstallFileOpenMenu( ParentMenu ); |
| 237 |
if ( bReturn ) |
| 238 |
AfxGetMainWnd() ->DrawMenuBar(); |
| 239 |
return bReturn; |
| 240 |
} |
| 241 |
|
| 242 |
CMultiChannelData * CNeuroManagerDoc::CreateDataInstance() |
| 243 |
{ |
| 244 |
return this->m_MCDataManager.CreateInstance( 0 ); |
| 245 |
} |
| 246 |
|
| 247 |
BOOL CNeuroManagerDoc::GetPluginTitle( size_t n, char *buf, size_t buflen ) |
| 248 |
{ |
| 249 |
return m_MCDataManager.GetPluginTitle( n, buf, buflen ); |
| 250 |
} |