s045508Doc.cpp
资源名称:HeShi.rar [点击查看]
上传用户:bjzhifu888
上传日期:2013-01-22
资源大小:136k
文件大小:4k
源码类别:
STL
开发平台:
Visual C++
- // s045508Doc.cpp : implementation of the CS045508Doc class
- //
- #include "stdafx.h"
- #include "s045508.h"
- #include "s045508Doc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CS045508Doc
- IMPLEMENT_DYNCREATE(CS045508Doc, CDocument)
- BEGIN_MESSAGE_MAP(CS045508Doc, CDocument)
- //{{AFX_MSG_MAP(CS045508Doc)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CS045508Doc construction/destruction
- CS045508Doc::CS045508Doc()
- {
- // TODO: add one-time construction code here
- }
- CS045508Doc::~CS045508Doc()
- {
- }
- BOOL CS045508Doc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CS045508Doc serialization
- void CS045508Doc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CS045508Doc diagnostics
- #ifdef _DEBUG
- void CS045508Doc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CS045508Doc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CS045508Doc commands
- BOOL CS045508Doc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- if (!CDocument::OnOpenDocument(lpszPathName))
- return FALSE;
- // TODO: Add your specialized creation code here
- CVector temp;
- CString cstr, cstrtemp,checkstr;
- CStdioFile inFile;
- VertexArray.RemoveAll(); //empty array
- NormalArray.RemoveAll();
- inFile.Open(lpszPathName, CFile::modeRead); //open file
- inFile.ReadString(cstr); //read "solid ***"
- inFile.ReadString(cstr); //read the first normal vector line
- ncon=0; // normal vector counter
- pcon=0; // vetex vector counter
- checkstr=cstr[3]; // ensure the normal vector line exists
- while (checkstr==cstr[3]) // if exist, the third charecter must be "f" of " facet"
- {
- cstr.TrimLeft(" facet normal "); //in order to get the first vector number
- for (int i = 0; cstr[i] != ' '; i++) //the first number is end before a " "
- cstrtemp = cstrtemp + cstr[i]; //store all the numbers needed
- temp.x = (float)atof(cstrtemp); //translate string into float
- cstrtemp.Empty();
- for (i++; cstr[i] != ' '; i++) //the second number is also end before a " "
- cstrtemp = cstrtemp + cstr[i];
- temp.y = (float)atof(cstrtemp);
- cstrtemp.Empty();
- for (i++; i < cstr.GetLength(); i++) //the third number is end when the line ends
- cstrtemp = cstrtemp + cstr[i];
- temp.z = (float)atof(cstrtemp);
- cstrtemp.Empty();
- NormalArray.Add(temp); //add the vector to the array
- ncon++; //counter of normal vector +1
- inFile.ReadString(cstr); //read "outer loop"
- for (i = 0; i < 3; i++) //there are three vectors in a vertex
- {
- inFile.ReadString(cstr); //read the vertex line
- cstr.TrimLeft(" vertex "); //the following is similar to the method getting normal vector
- for (int j = 0; cstr[j] != ' '; j++)
- cstrtemp = cstrtemp + cstr[j];
- temp.x = (float)atof(cstrtemp);
- cstrtemp.Empty();
- for (j++; cstr[j] != ' '; j++)
- cstrtemp = cstrtemp + cstr[j];
- temp.y = (float)atof(cstrtemp);
- cstrtemp.Empty();
- for (j++; j < cstr.GetLength(); j++)
- cstrtemp = cstrtemp + cstr[j];
- temp.z = (float)atof(cstrtemp);
- cstrtemp.Empty();
- VertexArray.Add(temp); //store the vector in the array
- pcon++; //counter of vertex +1
- //note that pcon+3 when ncon+1
- }
- inFile.ReadString(cstr); //read "end loop"
- inFile.ReadString(cstr); //read "end facet"
- inFile.ReadString(cstr); //read the next normal vector
- }
- inFile.Close();
- return TRUE;
- }