/*
================
rvGEWorkspace::SaveFile

Writes the contents of the open gui file to disk
================
*/
bool rvGEWorkspace::SaveFile( const char *filename ) {
	idFile		*file;
	idWindow	*window;
	SetCursor( LoadCursor( NULL, MAKEINTRESOURCE( IDC_WAIT ) ) );
	mFilename = filename;
	// Since quake can only write to its path we will write a temp file then copy it over
	idStr tempfile;
	idStr ospath;
	tempfile = "guis/temp.guied";
	ospath = fileSystem->RelativePathToOSPath( tempfile, "fs_basepath" );
	// Open the output file for write
	if( !( file = fileSystem->OpenFileWrite( tempfile ) ) ) {
		int error = GetLastError( );
		SetCursor( LoadCursor( NULL, MAKEINTRESOURCE( IDC_ARROW ) ) );
		return false;
	}
	window = mInterface->GetDesktop( );
	WriteWindow( file, 1, window );
	fileSystem->CloseFile( file );
	if( !CopyFile( ospath, filename, FALSE ) ) {
		DeleteFile( ospath );
		SetCursor( LoadCursor( NULL, MAKEINTRESOURCE( IDC_ARROW ) ) );
		return false;
	}
	DeleteFile( ospath );
	mFilename = filename;
	mModified = false;
	mNew      = false;
	UpdateTitle( );
	SetCursor( LoadCursor( NULL, MAKEINTRESOURCE( IDC_ARROW ) ) );
	return true;
}
/*
================
rvGEWorkspace::WriteWindow

Writes the contents of the given window to the file
================
*/
bool rvGEWorkspace::WriteWindow(idFile *file, int depth, idWindow *window)
{
	idStr				out;
	rvGEWindowWrapper	*wrapper;
	int					i;

	wrapper = rvGEWindowWrapper::GetWrapper(window);

	if (!wrapper) {
		return true;
	}

	if (wrapper->IsDeleted()) {
		return true;
	}

	// Window def header
	WriteTabs(file, depth - 1);

	out = wrapper->WindowTypeToString(wrapper->GetWindowType());
	out.Append(" ");
	file->Write(out, out.Length());

	out = window->GetName();
	file->Write(out, out.Length());
	file->Write("\r\n", 2);

	WriteTabs(file, depth - 1);

	out = "{\r\n";
	file->Write(out, out.Length());
	file->ForceFlush();

	for (i = 0; i < wrapper->GetStateDict().GetNumKeyVals(); i ++) {
		const idKeyValue *key = wrapper->GetStateDict().GetKeyVal(i);

		// Dont write name to the files
		if (!key->GetKey().Icmp("name")) {
			continue;
		}

		WriteTabs(file, depth);

		out = key->GetKey();
		out.Append("\t");
		file->Write(out, out.Length());

		const char *p;

		for (p = key->GetValue().c_str(); *p; p ++) {
			switch (*p) {
				case '\n':
					file->Write("\\n", 2);
					break;

				default:
					file->Write(p, 1);
					break;
			}
		}

		file->Write("\r\n", 2);
	}

	for (i = 0; i < wrapper->GetVariableDict().GetNumKeyVals(); i ++) {
		const idKeyValue *key = wrapper->GetVariableDict().GetKeyVal(i);

		WriteTabs(file, depth);

		out = key->GetKey();
		out.Append("\t");
		out.Append(key->GetValue());
		out.Append("\r\n");

		file->Write(out, out.Length());
	}

	if (wrapper->GetScriptDict().GetNumKeyVals()) {
		file->Write("\r\n", 2);
	}

	for (i = 0; i < wrapper->GetScriptDict().GetNumKeyVals(); i ++) {
		const idKeyValue *key = wrapper->GetScriptDict().GetKeyVal(i);

		WriteTabs(file, depth);

		file->Write(key->GetKey(), key->GetKey().Length());
		file->Write(" ", 1);

		idLexer src(key->GetValue(), key->GetValue().Length(), "", LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWBACKSLASHSTRINGCONCAT);
		src.ParseBracedSectionExact(out, depth + 1);

		file->Write(out, out.Length());
		file->Write("\r\n", 2);
		file->Write("\r\n", 2);
	}

	for (i = 0; i < wrapper->GetChildCount(); i ++) {
		idWindow *child = wrapper->GetChild(i);

		WriteWindow(file, depth + 1, child);
	}

	// Window def footer
	WriteTabs(file, depth - 1);

	out = "}\r\n";
	file->Write(out, out.Length());
	file->ForceFlush();

	return true;
}
Example #3
0
void TrackEncoder( void)
{
	const int MaxTries = 9;
	int count = 0;
	int step;
	double StepsPerSec;
	int rate;

	TE = (struct AZLong*) malloc( MsInWindings * sizeof( struct AZLong));
	if( TE == NULL)
		BadExit( "Problem with malloc of TE in TrackEncoder()");

	WriteWindow( MsgFrame);

	gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 1);
	printf( "moving motors to start position...");
	/* attempt to move both motors to microstep '0' on winding 'A' */
	do
	{
		Steps.A = (MsIx.A/MaxPWM) % MsInWindings;
		if( Steps.A && Dir.A == CW)
			Steps.A = MsInWindings - Steps.A;
		Steps.Z = (MsIx.Z/MaxPWM) % MsInWindings;
		if( Steps.Z && Dir.Z == CW)
			Steps.Z = MsInWindings - Steps.Z;
		MoveMs_f_ptr();
		count++;
	}while( count < MaxTries && (Steps.A || Steps.Z));

	/* get rate of motion */
	gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 2);
	printf( "Please enter speed in microsteps per second ");
	if( !GetDouble( &StepsPerSec))
		/* if user aborts, then set it up so that no more execution occurs */
		count = MaxTries;
	else
		/* split rate in half bec. encoders read halfway through */
		rate = (int) (.5 + ClockTicksSec / (2.*StepsPerSec));

	if( count < MaxTries)
	{
		/* move MsInWindings microsteps, taking encoder readings as we go */
		for( step = 0; step < MsInWindings; step++)
		{
			Steps.A = Steps.Z = 1;
			for( Ix = 0; Ix < rate; Ix++)
				MoveMs_f_ptr();
			QueryEncoders_f_ptr();
			for( Ix = 0; Ix < rate; Ix++)
				MoveMs_f_ptr();
			if( EncoderState == ReadReady)
				ReadEncoders_f_ptr();
			TE[step].A = EncoderCount.A;
			TE[step].Z = EncoderCount.Z;
			gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 3);
			printf( "microstep %d: encA %ld encZ %ld", step, TE[step].A, TE[step].Z);
		}
		gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 4);
		printf( "writing %s file", TrackEncodersFile);
		Output = fopen( TrackEncodersFile, "w");
		if( Input == NULL)
			BadExit( strcat( "Could not open ", TrackEncodersFile));
		for( step = 0; step < MsInWindings; step++)
			fprintf( Output, "%d %ld %ld\n", step, TE[step].A, TE[step].Z);
		fclose( Output);
		gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 5);
		ContMsgRoutine();
		RemoveWindow( MsgFrame);
	}
	else
	{
		RemoveWindow( MsgFrame);
		PressKeyToContMsg( "could not move motors to start position");
	}
	free( TE);
	PauseUntilNewSidTime();
	HPEventGetEquat();
}
Example #4
0
void DisplayInit( void)
{
	int StartX = InitFrame.Left + 5;
	int StartY = InitFrame.Top + 1;
	int AltX, AzX, RaX, DecX, SidTX;

	AltX = StartX + 3;
	AzX = AltX + SizeofDegX + 1;
	RaX = AzX + SizeofDegX + 1;
	DecX = RaX + SizeofHMSX + 1;
	SidTX = DecX + SizeofDMSX + 1;

	WriteWindow( InitFrame);

	TextAttr = DefaultText;
	VidMemXY.Y = StartY;
	VidMemXY.X = AltX;

	if( One.Init)
	{
		sprintf( StrBuf, "Alt");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = AzX;
		sprintf( StrBuf, "Az");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = RaX;
		sprintf( StrBuf, "Ra");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = DecX;
		sprintf( StrBuf, "Dec");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = SidTX;
		sprintf( StrBuf, "SidT");
		WriteStrBufToScreen_f_ptr();

		VidMemXY.Y++;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "1:");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = AltX;
		VidMemDeg( One.Alt);
		VidMemXY.X = AzX;
		VidMemDeg( One.Az);
		VidMemXY.X = RaX;
		VidMemRaHMS( &One);
		VidMemXY.X = DecX;
		VidMemDecDMS( &One);
		VidMemXY.X = SidTX;
		VidMemSidT( &One);
	}
	else
	{
		sprintf( StrBuf, "no inits to display");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.Y++;
	}

	if( Two.Init)
	{
		VidMemXY.Y++;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "2:");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = AltX;
		VidMemDeg( Two.Alt);
		VidMemXY.X = AzX;
		VidMemDeg( Two.Az);
		VidMemXY.X = RaX;
		VidMemRaHMS( &Two);
		VidMemXY.X = DecX;
		VidMemDecDMS( &Two);
		VidMemXY.X = SidTX;
		VidMemSidT( &Two);
	}
	if( Three.Init)
	{
		VidMemXY.Y++;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "3:");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = AltX;
		VidMemDeg( Three.Alt);
		VidMemXY.X = AzX;
		VidMemDeg( Three.Az);
		VidMemXY.X = RaX;
		VidMemRaHMS( &Three);
		VidMemXY.X = DecX;
		VidMemDecDMS( &Three);
		VidMemXY.X = SidTX;
		VidMemSidT( &Three);                 
	}
	if( Two.Init)
	{
		VidMemXY.Y += 2;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "Lat: ");
		WriteStrBufToScreen_f_ptr();
		VidMemDeg( Lat);
		sprintf( StrBuf, " (dif %3.3f)", Lat*RadToDeg - LatitudeDeg);
		WriteStrBufToScreen_f_ptr();

		sprintf( StrBuf, " Long: ");
		WriteStrBufToScreen_f_ptr();
		VidMemDeg( LongitudeRad);
		sprintf( StrBuf, " (dif %3.3f)", LongitudeRad*RadToDeg - LongitudeDeg);
		WriteStrBufToScreen_f_ptr();

		VidMemXY.Y++;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "AzOff: ");
		WriteStrBufToScreen_f_ptr();
		VidMemDeg( AzOff);

		sprintf( StrBuf, " HAOff: ");
		WriteStrBufToScreen_f_ptr();
		GetHMSH( RadToHundSec*HAOff + 0.5, &HAOffHMSH);
		StrBufSHMS( HAOffHMSH);
		WriteStrBufToScreen_f_ptr();
		sprintf( StrBuf, " or %3.3f deg", HAOff*RadToDeg);
		WriteStrBufToScreen_f_ptr();

		VidMemXY.Y+=2;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "To polar align, move %3.3f deg %s, %3.3f deg %s",
		fabs( PolarAlign.A*RadToDeg), PolarAlign.A<0.?"down":"up",
		fabs( PolarAlign.Z*RadToDeg), PolarAlign.Z<0.?"left":"right");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.Y++;
	}
	VidMemXY.Y++;
	VidMemXY.X = StartX;
	sprintf( StrBuf, "Z1: %3.3f   Z2: %3.3f   Z3: %3.3f", Z1*RadToDeg,
	Z2*RadToDeg, Z3*RadToDeg);
	WriteStrBufToScreen_f_ptr();

	gotoxy( StartX + 6, VidMemXY.Y += 3);
	ContMsgRoutine();
	RemoveWindow( InitFrame);
}