// pdnmeshDoc.cpp : implementation of the CPdnmeshDoc class // /* pdnmesh - a 2D finite element solver Copyright (C) 2001-2005 Sarod Yatawatta This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: pdnmeshDoc.cpp,v 1.9 2005/02/16 13:16:15 sarod Exp $ */ #include "stdafx.h" #include "winpdnmesh.h" #include "pdnmeshDoc.h" #include "SaveOptions.h" #include "SolveOptions.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPdnmeshDoc IMPLEMENT_DYNCREATE(CPdnmeshDoc, CDocument) BEGIN_MESSAGE_MAP(CPdnmeshDoc, CDocument) //{{AFX_MSG_MAP(CPdnmeshDoc) ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) ON_COMMAND(SID_SOLVE_OPTIONS, OnSolveOptions) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPdnmeshDoc construction/destruction CPdnmeshDoc::CPdnmeshDoc() { // TODO: add one-time construction code here model=NULL; } CPdnmeshDoc::~CPdnmeshDoc() { } BOOL CPdnmeshDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CPdnmeshDoc serialization void CPdnmeshDoc::Serialize(CArchive& ar) { CString filename; int flag; filename=ar.GetFile()->GetFileName(); if (ar.IsStoring()) { // TODO: add storing code here flag=model->SaveOutput((const char*)filename); if(!flag) { ::MessageBox(::GetFocus(),"File Save Error","Error",MB_OK); } } else { // TODO: add loading code here // if(model !=NULL) delete model; // model =new Model; // flag=model->LoadCoordFile(filename); // if (!flag) { // ::MessageBox(::GetFocus(),"File Open Error","Error",MB_OK); // } //model->Solve(); } } ///////////////////////////////////////////////////////////////////////////// // CPdnmeshDoc diagnostics #ifdef _DEBUG void CPdnmeshDoc::AssertValid() const { CDocument::AssertValid(); } void CPdnmeshDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CPdnmeshDoc commands void CPdnmeshDoc::draw() { if(model !=NULL) model->Render(); } void CPdnmeshDoc::OnFileSaveAs() { if (model!=NULL) { SaveOptions sv; if(sv.DoModal()==IDOK) { // TODO: Add your command handler code here CFileDialog fd(false); switch (output_file_option) { case OUT_CONT: fd.m_ofn.lpstrFilter="EPS Files(*.eps)\0*.eps\0\0"; fd.m_ofn.lpstrDefExt="eps"; fd.m_ofn.lpstrTitle ="Save as EPS"; break; case OUT_CONT_COLOR: fd.m_ofn.lpstrFilter="EPS Files(*.eps)\0*.eps\0\0"; fd.m_ofn.lpstrDefExt="eps"; fd.m_ofn.lpstrTitle ="Save as Color EPS"; break; case OUT_CONT_COLOR_LEGEND: fd.m_ofn.lpstrFilter="EPS Files(*.eps)\0*.eps\0\0"; fd.m_ofn.lpstrDefExt="eps"; fd.m_ofn.lpstrTitle ="Save as Color EPS with Legend"; break; case OUT_GRAD: fd.m_ofn.lpstrFilter="EPS Files(*.eps)\0*.eps\0\0"; fd.m_ofn.lpstrDefExt="eps"; fd.m_ofn.lpstrTitle ="Save as EPS (Gradient)"; break; case OUT_MESH_EPS: fd.m_ofn.lpstrFilter="EPS Files(*.eps)\0*.eps\0\0"; fd.m_ofn.lpstrDefExt="eps"; fd.m_ofn.lpstrTitle ="Save as EPS (Mesh)"; break; case OUT_MESH: fd.m_ofn.lpstrFilter="ASCII Files(*.*)\0*.*\0\0"; fd.m_ofn.lpstrDefExt="txt"; fd.m_ofn.lpstrTitle ="Save as ASCII(Mesh)"; break; case OUT_POTENTIAL: fd.m_ofn.lpstrFilter="ASCII Files(*.*)\0*.*\0\0"; fd.m_ofn.lpstrDefExt="txt"; fd.m_ofn.lpstrTitle ="Save as ASCII(Mesh)"; break; default: fd.m_ofn.lpstrFilter="EPS Files(*.eps)\0*.eps\0\0"; fd.m_ofn.lpstrDefExt="eps"; fd.m_ofn.lpstrTitle ="Save as EPS"; break; } if(fd.DoModal()==IDOK) model->SaveOutput(fd.GetPathName()); } } } void CPdnmeshDoc::OnSolveOptions() { // TODO: Add your command handler code here SolveOptions so; if(so.DoModal()==IDOK) { solve_equation=so.m_equtype; if(solve_equation==HELMHOLTZ) requested_degree_of_freedom=so.m_degree_of_freedom; } } BOOL CPdnmeshDoc::OnOpenDocument(LPCTSTR lpszPathName) { int flag; //if (!CDocument::OnOpenDocument(lpszPathName)) // return FALSE; // TODO: Add your specialized creation code here if(model !=NULL) delete model; model =new Model; flag=model->LoadCoordFile(lpszPathName); if (!flag) { ::MessageBox(::GetFocus(),"File Open Error","Error",MB_OK); } model->Solve(); AddToRecentFileList(lpszPathName); return TRUE; } void CPdnmeshDoc::AddToRecentFileList(LPCTSTR lpszPathName) { ((CPdnmeshApp *)AfxGetApp())->AddToRecentFileList(lpszPathName); }