예제 #1
0
void CMainFrame::AutoSave()

{
    // Tell all documents to autosave
    POSITION Pos = ((CWedApp*)AfxGetApp())->
                    pDocTemplate->GetFirstDocPosition();
    for(;;)
        {
        if(!Pos)
            break;

        CWedDoc* doc = (CWedDoc*)
            ((CWedApp*)AfxGetApp())->pDocTemplate->GetNextDoc(Pos);

        if(!doc)
            continue;

        ASSERT_VALID(doc);
        if(doc->IsModified())
            {
            P2N("Autosave %s\r\n", doc->GetPathName());
            doc->AutoSave();
            }
        }
}
예제 #2
0
int	 CWedDoc::GetComment(const char *fname)

{
	int loop = 0;
	CString name(fname), drive, dir, filename, ext;
	
	SplitPath(name,  drive, dir, filename, ext);
	ext.MakeUpper();

	comment = "//";

	while(TRUE)
		{
		if(!comms[loop])
			break;

		if(ext == comms[loop])
			{
			comment		= comms[loop+1];
			funcregex	= comms[loop+2]; 
			P2N("Got: '%s' '%s' '%s'\r\n", comms[loop], comms[loop+1], comms[loop+2]);
			break;
			}
		//P2N("Searching extension %s %s\r\n", str, comms[loop]);
		loop += 3;
	}
	return(0);
}
예제 #3
0
BOOL CWedDoc::OnNewDocument()

{
	P2N("CWedDoc::OnNewDocument()\r\n");

	if(GetNumOfDocs() > MAX_DOC_LIMIT)
		{
		AfxMessageBox("Too many open documents");
		return FALSE;
		}

	// Go get one
    if (!CDocument::OnNewDocument())
        return FALSE;

	CString num;
	// Find temporary name that is not an existing file
	while(TRUE)
		{
		num.Format("untitled%02d.txt", newcount++);
		if(access(num, 0))
			break;

		// Safety net
		if(newcount > 100)
			break;
		}
	SetPathName(num);
    SetModifiedFlag();
	return TRUE;
}
예제 #4
0
int widget_keypad_draw(WIDGET * Self)
{
    WIDGET_KEYPAD *keypad = Self->data;

    /* evaluate properties */
    property_eval(&keypad->expression);

    return P2N(&keypad->expression);
}
예제 #5
0
int drv_generic_graphic_icon_draw(WIDGET * W)
{
    WIDGET_ICON *Icon = W->data;
    RGBA fg, bg;
    unsigned char *bitmap = Icon->bitmap + YRES * Icon->curmap;
    int layer, row, col;
    int x, y;
    int visible;

    layer = W->layer;
    row = YRES * W->row;
    col = XRES * W->col;

    fg = W->fg_valid ? W->fg_color : FG_COL;
    bg = W->bg_valid ? W->bg_color : BG_COL;

    /* sanity check */
    if (layer < 0 || layer >= LAYERS) {
	error("%s: layer %d out of bounds (0..%d)", Driver, layer, LAYERS - 1);
	return -1;
    }

    /* maybe grow layout framebuffer */
    drv_generic_graphic_resizeFB(row + YRES, col + XRES);

    /* Icon visible? */
    visible = P2N(&Icon->visible) > 0;

    /* render icon */
    for (y = 0; y < YRES; y++) {
	int mask = 1 << XRES;
	for (x = 0; x < XRES; x++) {
	    int i = (row + y) * LCOLS + col + x;
	    mask >>= 1;
	    if (visible) {
		if (bitmap[y] & mask)
		    drv_generic_graphic_FB[layer][i] = fg;
		else
		    drv_generic_graphic_FB[layer][i] = bg;
	    } else {
		drv_generic_graphic_FB[layer][i] = BG_COL;
	    }
	}
    }

    /* flush area */
    drv_generic_graphic_blit(row, col, YRES, XRES);

    return 0;

}
예제 #6
0
void widget_timer_update(void *Self)
{
    WIDGET *W = (WIDGET *) Self;
    WIDGET_TIMER *Timer = W->data;
    int update, active;

    /* evaluate expressions */
    property_eval(&Timer->update);
    property_eval(&Timer->active);

    /* get new update interval */
    update = P2N(&Timer->update);
    if (update < 10)
	update = 10;

    /* finally, fire it! */
    active = P2N(&Timer->active);
    if (active > 0) {
	property_eval(&Timer->expression);
    }

    /* add a new one-shot timer */
    timer_add_widget(widget_timer_update, Self, update, 1);
}
예제 #7
0
int drv_generic_graphic_image_draw(WIDGET * W)
{
    WIDGET_IMAGE *Image = W->data;
    int layer, row, col, width, height;
    int x, y;
    int visible;

    layer = W->layer;
    row = W->row;
    col = W->col;
    width = Image->width;
    height = Image->height;

    /* sanity check */
    if (layer < 0 || layer >= LAYERS) {
	error("%s: layer %d out of bounds (0..%d)", Driver, layer, LAYERS - 1);
	return -1;
    }

    /* if no size or no image at all, do nothing */
    if (width <= 0 || height <= 0 || Image->bitmap == NULL) {
	return 0;
    }

    /* maybe grow layout framebuffer */
    drv_generic_graphic_resizeFB(row + height, col + width);

    /* render image */
    visible = P2N(&Image->visible);
    for (y = 0; y < height; y++) {
	for (x = 0; x < width; x++) {
	    int i = (row + y) * LCOLS + col + x;
	    if (visible) {
		drv_generic_graphic_FB[layer][i] = Image->bitmap[y * width + x];
	    } else {
		drv_generic_graphic_FB[layer][i] = BG_COL;
	    }
	}
    }

    /* flush area */
    drv_generic_graphic_blit(row, col, height, width);

    return 0;

}
예제 #8
0
int drv_generic_gpio_draw(WIDGET * W)
{
    WIDGET_GPO *gpo = W->data;
    int num, val;

    num = W->row;
    val = P2N(&gpo->expression);

    if (num < 0 || num >= GPOS) {
	error("%s: gpio_draw(%d): GPO out of range (0..%d)", Driver, num + 1, GPOS);
	return -1;
    }

    if (GPO[num] != val) {
	if (drv_generic_gpio_real_set)
	    GPO[num] = drv_generic_gpio_real_set(num, val);
    }

    return 0;
}
예제 #9
0
파일: wed.cpp 프로젝트: akavel/wed-editor
int 	CWedApp::ExitInstance()
{
#if 0
	if(!RemoveFontResource("sample.fnt"))
		MessageBox(NULL, "Cannot remove font", "Wed", 0);
#endif

	//P2N("Terminated Application: %s %s\r\n",
	//				m_pszAppName, approot);

	//if(wait_exit)
	//	{
	//	for(int loop = 0; loop < 10; loop++)
	//		{
	//		YieldToWin(); Sleep(20);
	//		}
	//	}

	P2N("Exited Wed\r\n");

 	return CWinApp::ExitInstance();
}
예제 #10
0
bool
ViewerQuery::UpdateLineFromSlice(PlaneAttributes *newPlaneAtts)
{
    // 
    // Only update the line if the slice-plane attributes have truly changed.
    // 
    if (*planeAtts == *newPlaneAtts)
        return false;

    int i, opId = -1;
    int lineId = resultsPlot->GetNOperators()-1;
    for (i = 0; i < lineId; i++)
    {
        ViewerOperator *oper = resultsPlot->GetOperator(i);
        if (strcmp(oper->GetName(), "Slice") == 0)
        {
            opId = i;
            break; 
        }
    }

    // 
    //  No need to update if no slice-operator has been applied.
    // 
    if (opId == -1) 
        return false;

    avtVector pt1(lineAtts->GetPoint1()); 
    avtVector pt2(lineAtts->GetPoint2()); 

    avtVector o1(planeAtts->GetOrigin());
    avtVector o2(newPlaneAtts->GetOrigin());
 
    // Define the frame for Plane 1.
    avtVector P1N(planeAtts->GetNormal());
    avtVector P1Up(planeAtts->GetUpAxis());
    avtVector u1, v1, w1;
    CreateBasis(P1N, P1Up, u1, v1, w1);

    // Define the frame for Plane 2.
    avtVector P2N(newPlaneAtts->GetNormal());
    avtVector P2Up(newPlaneAtts->GetUpAxis());
    avtVector u2, v2, w2;
    CreateBasis(P2N, P2Up, u2, v2, w2);

    avtMatrix M1, M2, M3, C;
    int spaceT = 0;
    if (planeAtts->GetThreeSpace() && !newPlaneAtts->GetThreeSpace())
    {
        // convert 3d to 2d
        avtVector zero(0., 0., 0.);
        avtMatrix C1, C2;
        C1.MakeFrameToCartesianConversion(u2, v2, w2, zero);

        C1.Inverse();
        C2.MakeScale(1, 1, 0);

        C = C2 * C1;
        spaceT = 1;
    }
    else if (!planeAtts->GetThreeSpace() && newPlaneAtts->GetThreeSpace())
    {
        // convert 2d to 3d
        avtVector zero(0., 0., 0.);
        avtMatrix C1, C2, C3;
        C1.MakeFrameToCartesianConversion(u1, v1, w1, zero);
        C2.MakeCartesianToFrameConversion(u1, v1, w1, zero);
        avtVector zdim = C1 * o1;
        zdim.x = 0; 
        zdim.y = 0; 
        zdim = C2 * zdim;
        C3.MakeTranslate(zdim.x, zdim.y, zdim.z);
        C = C3 * C1;
        spaceT = 2;
    }

    if ((!planeAtts->FieldsEqual(0, newPlaneAtts)) ||
        (!planeAtts->FieldsEqual(1, newPlaneAtts)) ||
        (!planeAtts->FieldsEqual(2, newPlaneAtts))) 
    {
        // Create conversion between Cartesian and plane1 frame.
        M1.MakeCartesianToFrameConversion(u1, v1, w1, o1);

        // Create conversion between plane2 and Cartesian frame.
        M2.MakeFrameToCartesianConversion(u2, v2, w2, o2);
        // Create composition matrix.
        switch (spaceT)
        {
            case 0 : M3 = M2 * M1;     break; // no dimensionality change
            case 1 : M3 = C * M2 * M1; break; // converted from 3d to 2d
            case 2 : M3 = M2 * M1 * C; break; // converted from 2d to 3d
        }
    }
    else
    {
        M3 = C;
    }

    // Convert points. 
    pt1 = M3 * pt1;
    pt2 = M3 * pt2;

    // Update necessary attributes.
    lineAtts->SetPoint1(pt1.x, pt1.y, pt1.z);
    lineAtts->SetPoint2(pt2.x, pt2.y, pt2.z);
    *planeAtts = *newPlaneAtts;

    // Ensure that both the slice and lineout operators have the correct atts. 
    resultsPlot->GetOperator(lineId)->SetOperatorAtts(lineAtts);
    resultsPlot->GetOperator(opId)->SetOperatorAtts(newPlaneAtts);

    // Update the refline. 
    originatingWindow->UpdateQuery(lineAtts);

    return true;
}
예제 #11
0
파일: wed.cpp 프로젝트: akavel/wed-editor
BOOL 	CWedApp::InitInstance()

{
	CString str;
	char *ptr;

	//SetDialogBkColor(0x00ff0000, 0xffffff);

	WaitCursor = AfxGetApp()->LoadStandardCursor(IDC_WAIT);
	NormalCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);

	GetModuleFileName(AfxGetInstanceHandle(), approot, MAX_PATH);

	CTime ct = CTime::GetCurrentTime();
	CString datestr = ct.Format("%A, %B %d, %Y - %I:%M %p");

	C2N();
	P2N("\r\nStarted WED application at %s\r\n", datestr);
	//P2N("AppRoot=%s\r\n", approot);

	//CString desktop;
	//GetSpecialFolder(CSIDL_DESKTOPDIRECTORY, desktop);
	//desktop += "wed";

	//P2N("Desktop special: %s\r\n", desktop);

	// Create initial desktop xcpt folder
	//if(access(desktop, 0) == -1)
	//	{
	//	P2N("Making %s\r\n", desktop);
	//	//message("Created desktop folder.");
	//	_mkdir(desktop);
	//	}

	ptr = strrchr(approot, '\\');
	if(ptr)
		*(ptr+1) = '\0';

	//dataroot = (CString)approot + "wed\\";

	GetSpecialFolder(CSIDL_PERSONAL, dataroot);
	dataroot += "WedData\\";

	P2N("Wed user data directory: %s\r\n", dataroot);

	if(access(dataroot, 0))
		{
		if(mkdir(dataroot))
			{
			//P2N("Cannot create data root dir\r\n");
			}
		}

	//////////////////////////////////////////////////////////////////////
	// Create data dirs

	str = dataroot; str += "data";

	// Check if data dir is in order
	if(access(str, 0))
		{
		if(mkdir(str))
			{
			//P2N("Cannot create data dir\r\n");
			}
		}
	str = dataroot; str += "macros";
	// Check if data dir is in order
	if(access(str, 0))
		{
		if(mkdir(str))
			{
			//P2N("Cannot create macro dir\r\n");
			}
		}
	str = dataroot; str += "holdings";
	// Check if data dir is in order
	if(access(str, 0))
		{
		if(mkdir(str))
			{
			//P2N("Cannot create holders dir\r\n");
			}
		}
	str = dataroot; str += "coco";
	// Check if coco dir is in order
	if(access(str, 0))
		{
		if(mkdir(str))
			{
			//P2N("Cannot create coco dir\r\n");
			}
		}
	str = dataroot; str += "backup";
	// Check if state dir is in order
	if(access(str, 0))
		{
		if(mkdir(str))
			{
			//P2N("Cannot create state dir\r\n");
			}
		}
	str = dataroot; str += "template";
	// Check if state dir is in order
	if(access(str, 0))
		{
		if(mkdir(str))
			{
			//P2N("Cannot create template dir\r\n");
			}
		}

	//P2N("Started Application: %s %s\r\n",
	//		m_pszAppName, approot);

	getcwd(str.GetBuffer(MAX_PATH), MAX_PATH);
	str.ReleaseBuffer();

	//P2N("Initial dir: %s\r\n", str);

	if (!AfxSocketInit())
		{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
		}

	// Initialize OLE 2.0 libraries
	if (!AfxOleInit())
		{
		AfxMessageBox("Failed OLE library init, OLE functions will not be available");
		}
	AfxEnableControlContainer();

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// You should modify this string to be something appropriate
	// such as the name of your company or organization.

	SetRegistryKey(_T("RobotMonkeySoftware"));

	LoadStdProfileSettings(6);  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	pDocTemplate = new CMultiDocTemplate(
			IDR_WEDTYPE,
				RUNTIME_CLASS(CWedDoc),
					RUNTIME_CLASS(CChildFrame), // custom MDI child frame
						RUNTIME_CLASS(CWedView));
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	pMainFrame = new CMainFrame;

	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;

	// Global
	m_pMainWnd = pMainFrame;

	// Get resources we need:
	// 1. Fonts

	CString fontname = 	GetProfileString(strConfig, strFontName, "Courier");
	int size    =  		GetProfileInt(strConfig,  strFontSize, 10);
	int weight  =  		GetProfileInt(strConfig, strFontWeight, 0);
	int italic  =  		GetProfileInt(strConfig, strFontItalic, 0);

	if(!ff.CreateFont(size, 0, 0, 0, weight, italic, 0, 0,
				0, 0, 0, 0, FIXED_PITCH, fontname))
		{
		AfxMessageBox("Cannot set font");
		}
	if(!ff.GetLogFont(&fflf))
		{
		AfxMessageBox("Cannot get font parameters");
		}

	// 2. Printer fonts
	if(!pp.CreateFont(80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                FF_MODERN, "system"))
		{
		MessageBox(NULL, "Cannot set font", "Wed", 0);
		}
	if(!pp.GetLogFont(&pplf))
		{
		MessageBox(NULL, "Cannot get font parameters", "Wed", 0);
		}

	// Get colors
	bgcol 	=  GetProfileInt(strConfig,  strColorBg, 	bgcol);
	fgcol 	=  GetProfileInt(strConfig,  strColorFg, 	fgcol);
	selcol 	=  GetProfileInt(strConfig,  strColorSel , 	selcol );
    cselcol =  GetProfileInt(strConfig,  strColorCSel, 	cselcol);
    cadd    =  GetProfileInt(strConfig,  strColorAdd , 	cadd   );
    cdel    =  GetProfileInt(strConfig,  strColorDel , 	cdel   );
    cchg    =  GetProfileInt(strConfig,  strColorChg , 	cchg   );
    comm    =  GetProfileInt(strConfig,  strColorComm, 	comm   );
    srcc    =  GetProfileInt(strConfig,  strColorSrc , 	srcc   );
    clng    =  GetProfileInt(strConfig,  strColorLong, 	clng   );

	// Bimaps
	caret.LoadBitmap(IDB_BITMAP1);
    backwrap  =  GetProfileInt(strConfig,  strBackWrap , 0);
    Tab2Space =  GetProfileInt(strConfig,  strTab2Space, 0);
    tabstop   =  GetProfileInt(strConfig,  strTabStop, 4);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	if(cmdInfo.m_strFileName != "")
		{
		comline = TRUE;
		OpenDocumentFile(cmdInfo.m_strFileName);
		}
	else
		{
   		// DON'T display a new MDI child window during startup!!!
		cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
		}

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// Key settings

	// Figure out last usage time ...
	int last = GetProfileInt(strConfig, "strLastUsage", 0);
	use = GetProfileInt(strConfig, "strUsage", 	0);
	//P2N("Usage count %d \r\n", use);

	// First time ever, display initial file
	if(!use)
		{
		OpenDocumentFile("Welcome.txt");
		comline  = TRUE;
		if(currentedit)
			{
			}
		}

	use++;
	CTime tt = CTime::GetCurrentTime();
	CTimeSpan t(tt.GetTime() - (time_t)last);

	//P2N("Time diff of last fire %d -- %d \r\n",
	//	t.GetTotalSeconds(), (int)tt.GetTime());

	YieldToWin() ;

	// Show sign banner only if more then 60 seconds passed
	//if(t.GetTotalSeconds() > 60)
		{
		spp.Create(IDD_DIALOG5, NULL);
 		spp.Show();
		}

	YieldToWin() ;

	//if(GetKeyState(VK_SHIFT))
	//	{
	//	AfxMessageBox("SHIFT HELD on startup\r\n");
	//	return(TRUE);
	//	}

	// The main window has been initialized ...
	// Show and update it.
	m_nCmdShow = GetProfileInt(strConfig, "WindowState", 1);
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	int num = GetProfileInt(strSection, strIntItem, 0);

	// De-serialize hash map
	CMap < int, int&, CString, CString& > HashMap;
	CFile cf;
	CString fname;
	fname.Format("%s%s", dataroot, "macros\\hashes.000");
	if( cf.Open( fname, CFile::modeRead))
		{
		CArchive ar( &cf, CArchive::load);
		HashMap.Serialize(ar);
		}
	else
		{
		//P2N("Cannot open hash map file: %s\r\n", fname);
		}
	POSITION rpos;
	rpos = HashMap.GetStartPosition();
	while(rpos)
		{
		int key;
		CString val;
		HashMap.GetNextAssoc(rpos, key, val);
		//P2N("In Hashlist: %x %s\r\n", key, val);
		}

	if(!comline)
		{
		// Reopen old documents:
		CString buf2, file;
		for(int count1 = 1; count1 <= num; count1++)
			{
			CWedDoc *doc = NULL;
			buf2.Format("%d", count1);
			file = GetProfileString(strSection, strStringItem + buf2);
			//P2N("Reloading file: '%s' at %s\r\n", file, buf2);

			// Empty file, no action
			if(file == "")
				continue;

			doc = (CWedDoc*)OpenDocumentFile(file);

			if(YieldToWinEx())
				break;

			//P2N("After Reloading file: %s at %s\r\n", file, buf2);

			if(doc)
				{
				ASSERT_VALID(doc);

				// Document had an error
				if(doc->ssel.m_err)
					break;

				int lrow, lcol;

				lrow = GetProfileInt(strSection,
					strStringItem + buf2 + "row", 0);

				lcol = GetProfileInt(strSection,
					strStringItem + buf2 + "col", 0);

				// Update cursor positions ...
				POSITION pos = doc->GetFirstViewPosition();
				for(;;)
					{
					if(!pos)
						break;
					CWedView *cv = (CWedView*)doc->GetNextView(pos);
					if(cv)
						{
						ASSERT_VALID(cv);
						cv->row = lrow;  cv->col = lcol;
						cv->SyncCaret();
						YieldToWin() ;
						}
					}
				// This happens after load, set it again
				doc->UpdateAllViews(NULL);
				}
			}

	// Try figure out last current directory
	int idx;
	if( (idx = file.ReverseFind('\\')) != -1)
		{
		file = file.Left(idx + 1);
		}
	P2N("CWedApp::InitInstance Chdir: '%s'\r\n", file);
	_chdir(file);
	targdir = srcdir = file;
    }

	message ("Loading macros ...");
	LoadMacros();

	message ("Loading holdings ...");
	LoadHoldings();

	message("");

	return TRUE;
}