⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win uwpflowview.cpp

📁 用于潮流计算的程序请让我下载我需要的吧感谢了啊
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Win UWPflowView.cpp : implementation of the CWinUWPflowView class
//

#include "stdafx.h"
#include "Win UWPflow.h"
#include "Win UWPflowDoc.h"
#include "MainFrm.h"
#include "Win UWPflowView.h"
#include "constant.h"
#include "pfwstdio.h"
#include "process.h"
#include "GraphDLG.h"
#include "SETJMP.H"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWinUWPflowView

IMPLEMENT_DYNCREATE(CWinUWPflowView, CScrollView)

BEGIN_MESSAGE_MAP(CWinUWPflowView, CScrollView)
	//{{AFX_MSG_MAP(CWinUWPflowView)
	ON_COMMAND(ID_HELP_HELP, OnHelpHelp)
	ON_COMMAND(ID_EXECUTE_BATCHSCRIPTFILE, OnExecuteBatchscriptfile)
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONDBLCLK()
	ON_COMMAND(ID_VIEW_SIZE_12, OnViewSize12)
	ON_COMMAND(ID_VIEW_SIZE_13, OnViewSize13)
	ON_COMMAND(ID_VIEW_SIZE_14, OnViewSize14)
	ON_COMMAND(ID_VIEW_SIZE_15, OnViewSize15)
	ON_COMMAND(ID_VIEW_SIZE_16, OnViewSize16)
	ON_COMMAND(ID_VIEW_SIZE_17, OnViewSize17)
	ON_COMMAND(ID_VIEW_SIZE_18, OnViewSize18)
	ON_COMMAND(ID_VIEW_SIZE_19, OnViewSize19)
	ON_COMMAND(ID_VIEW_SIZE_20, OnViewSize20)
	ON_COMMAND(ID_VIEW_SIZE_11, OnViewSize11)
	ON_COMMAND(ID_FILE_EDIT, OnFileEdit)
	ON_COMMAND(ID_FILE_CHANGEDIRECTORY, OnFileChangedirectory)
	ON_WM_KEYDOWN()
	ON_COMMAND(ID_OPTIONS_SHOWGRAPH, OnOptionsShowgraph)
	ON_COMMAND(ID_VIEW_SIZE_10, OnViewSize10)
	ON_COMMAND(ID_EXECUTE_RUNUWPFLOW, OnExecuteRunuwpflow)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//command line arguments
int Argc=0;
char **Argv;

//the previous commandline
char Options[400];

//definition of uwpflow main
int pfw_main(int argc, char **argv);

//the document to be updated and printed to screen
CWinUWPflowDoc *myDoc;

// Define exit label
jmp_buf exit_main;

//this
CWinUWPflowView *myWindow;

//the current directory
CString dir;

//graph dialog
GraphDLG* GraphDlg;	

/*--CWinUWPflowView construction/destruction--*/

CWinUWPflowView::CWinUWPflowView()
{
	myWindow = this;

	//initialize directory
	dir = __FILE__;
	dir.TrimRight("Win UWPflowView.cpp");

	//initialize graph dialog
	GraphDlg = new GraphDLG(this);
	GraphDlg->Create(IDD_GRAPH_DLG, this);

	wordHeight = 15; //default font
}


CWinUWPflowView::~CWinUWPflowView()
{

}

BOOL CWinUWPflowView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}


void CWinUWPflowView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	SetScrollSizes(MM_TEXT, CSize(0,0));

	//initialize myDoc
	myDoc = GetDocument();
	ASSERT_VALID(myDoc);

	//initialize font
	MyFont.CreateFont(wordHeight,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,0,
		OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
        FIXED_PITCH|FF_DONTCARE,0);

	//get the toolbar and statusbar
	TCHAR strClassName[255];
	CWnd* wndParent = GetParent();
	CWnd* wndChild = wndParent->GetWindow(GW_CHILD);
    while( wndChild != NULL )
    {
		// Get the class name of child control
		::GetClassName(wndChild->GetSafeHwnd(), strClassName, 255);

		if( _tcscmp(_T("ToolbarWindow32"), strClassName) == 0 )
		{	
			m_wndToolBar = (CMainToolBar*) wndChild;	
		}

		if( _tcscmp(_T("msctls_statusbar32"), strClassName) == 0 )
		{	
			m_wndStatusBar = (CStatusBar*) wndChild;
		}
		
		wndChild = wndChild->GetNextWindow();
	}
}

//paints the screen
//automatically called (via OnPaint())
void CWinUWPflowView::OnDraw(CDC* pDC)
{
	CString currLine="";
	myDoc->height=0;
	int index=0; //current position of currLine 

	pDC->SelectObject(MyFont);

	for (int i=0; i<myDoc->text.GetLength(); i++)
	{
		if (myDoc->text[i]=='\n')
		{
			pDC->TextOut(0,myDoc->height, currLine);

			//start drawing on the next line
			myDoc->height += wordHeight;

			//reset currLine
			currLine ="";
			index = 0;
		}
		else 
		{
			currLine.Insert(index++,myDoc->text[i]);
		}
	}
	
	if(myDoc->height>=MAXHEIGHT)
	{
		//save contents in to file
		FILE *OutStream = new FILE;
		OutStream = fopen("tmp.log", "w");
		LPCTSTR text = myDoc->allText;
		fprintf(OutStream, text); 
		fclose( OutStream );
		this->m_wndStatusBar->SetPaneText(0,"Too much text, top half is cut off. All text dumped in to tmp.log", true);

		myDoc->text= myDoc->newText;
		myDoc->newText = "";
		OnDraw(pDC); //call this function again, with the updated text
	}

	pDC->TextOut(0,0, currLine);

	myDoc->unPrintedLines = 0;
}

//reset scrollbar
void CWinUWPflowView::ResetScroll()
{
	SetScrollSizes(MM_TEXT, CSize(0,myDoc->height+400));
	SetScrollPos(SB_VERT, myDoc->height+400, true);
}

/*--CWinUWPflowView diagnostics--*/

#ifdef _DEBUG
void CWinUWPflowView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CWinUWPflowView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CWinUWPflowDoc* CWinUWPflowView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWinUWPflowDoc)));
	return (CWinUWPflowDoc*)m_pDocument;
}
#endif //_DEBUG

/*--Tools--*/

// Define command line arguments Argc and Argv
void CWinUWPflowView::GetArguments(char *Line,char *Program)
{
  int i,j,k;
  char string[200];
  bool FirstBlank=true;

  //clean up
  if (Argc!=0) {
    for(i=0;i<Argc;i++) 
		delete[] Argv[i];
    delete[] Argv;
    Argc=0;
  }
  i=0;

  //count the number of arguments (fill in Argc)
  while(Line[i]!='\0') {
    if (Line[i]!=' ' && FirstBlank) {
      Argc++;
      FirstBlank=FALSE;
    }
    else if (Line[i]==' ') FirstBlank=TRUE;
    i++;
  }

  //fill in Argv
  if (Argc!=0) {
    Argc++;
    Argv = new char* [Argc+1];
    Argv[0]=new char [strlen(Program)+1];
    strcpy(Argv[0],Program);
    Argv[Argc]=NULL;
    FirstBlank=TRUE;
    for(i=k=0,j=1;;i++) {
     if (Line[i]!=' ' && Line[i]!='\0') {
       string[k]=Line[i];
       k++;
       FirstBlank=FALSE;
     } else {
       if (!FirstBlank) {
         string[k]='\0';
         k++;
		 if (strcmp(string, "uwpflow")==0)
			 Argc--;	//ignore "uwpflow"
		 else{
			 Argv[j]=new char [k];
			 if (string[0]=='<' || string[0]=='>') strcpy(Argv[j],&string[1]);
			 else strcpy(Argv[j],string);
			 j++;
		 }
         FirstBlank=TRUE;
       }
       k=0;
     }
     if (Line[i]=='\0') break;
    }
  }
}

/*--Events--*/

//display help
void CWinUWPflowView::OnHelpHelp() 
{
	this->WinHelp(0, HELP_INDEX);
}


// Run UWPflow
void CWinUWPflowView::OnExecuteRunuwpflow() 
{
	m_wndToolBar->m_wndEdit.GetWindowText(Options, 400);

	//insert new commandline to the listbox
	m_wndToolBar->m_wndEdit.DeleteString(m_wndToolBar->m_wndEdit.FindStringExact(-1, Options));
	m_wndToolBar->m_wndEdit.InsertString (0, Options);
	m_wndToolBar->m_wndEdit.SetCurSel(0);

	GetArguments(Options,"uwpflow");

	int i;

	if(Argc!=0) {
		if (myDoc->CountRuns!=0) {
		  CustomPrint("\n");
		  for (i=1; i<BUFFER-1; i++) CustomPrint("%c",'-');
		  CustomPrint("\n");
		}
		CustomPrint("RUN #%d: ",++myDoc->CountRuns);
		for(i=0; i<Argc; i++) 
			CustomPrint("%s ",Argv[i]);

		CustomPrint("\n");

		//update screen
		Invalidate();
		UpdateWindow();


		m_wndStatusBar->SetPaneText(0,"Press [Esc] to stop processing", true);

		pfw_main(Argc, Argv);

		//reset streams
		fclose(stderr);
		stderr->_file=-1;
		fclose(stdout);
		stdout->_file=-1;

		myDoc->SetModifiedFlag(true);

		CustomPrint("\n END OF RUN #%d\n",myDoc->CountRuns);

		//update screen
		UpdateWindow();
		ResetScroll();
		Invalidate();	
	}	
}

//opens a batch/script file and execute uwpflow commands if there are any in it
void CWinUWPflowView::OnExecuteBatchscriptfile() 
{
	fclose(stdin);
	FILE *InputFile;
	char Buffer[BUFFER],*string;
	int i;
	bool end=false;
	CFileDialog OpenFileDlg (TRUE, "bat", "*.bat",
      OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, "Batch/Script Files (*.bat)|*.bat|All Files (*.*)|*.*||", this);

	//set it to the correct default directory
	OpenFileDlg.m_ofn.lpstrInitialDir=dir.GetBuffer(dir.GetLength());

	if(OpenFileDlg.DoModal() == IDOK)
	{
		
		CString filename = OpenFileDlg.GetPathName();

		//reset directory
		dir="";

		InputFile=fopen(filename,"r");		
		if (InputFile==NULL) MessageBox("Unable to open file", "File Error", MB_OK | MB_ICONEXCLAMATION);
		else {
			for (i=1; i<BUFFER-1; i++) CustomPrint("%c",'-');
			myDoc->SetModifiedFlag(true);
			CustomPrint("RUN batch/script file: %s\n",filename);
			while (fgets(Buffer,BUFFER,InputFile)!=NULL && !end) if (Buffer[0]!='@'){
				if((string=strstr(Buffer,"echo"))!=NULL) {
					if ((string=strchr(string,' '))!=NULL) 
						fCustomPrint(stdout, "%s",&string[1]);
				}
				else if(strstr(Buffer,"rem")!=NULL) 
				{ 
					continue;
				}
				else if(strstr(Buffer,"pause")!=NULL) {

					//update screen
					UpdateWindow();
					this->ResetScroll();
					Invalidate();

					switch(MessageBox("Do you want to continue?", "Pause", MB_YESNO | MB_ICONQUESTION)) {
					case IDYES:
						continue;

					case IDNO:
						end = true;
					}
					CustomPrint("\n");
				}
				else if((string=strstr(Buffer,"uwpflow"))!=NULL ||
					(string=strstr(Buffer,"UWPflow"))!=NULL ||
					(string=strstr(Buffer,"UWPFLOW"))!=NULL ) 
				{
					string=strchr(string,' ');

					if (string[strlen(string)-1]==' '||string[strlen(string)-1]=='\n')
						string[strlen(string)-1]='\0';
					else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -