Subversion Repositories spk

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#include "bob_dom_frame.h"
2
//---------------------------------------------------------------------------------
114 cycrow 3
bool bob_frame::Position::toFile(otextfilestream & os)
1 cycrow 4
{
5
	os << noSemicolons << x << ';' << y << ';' << z << "; ";
6
	return os.good();
7
}
8
//---------------------------------------------------------------------------------
114 cycrow 9
bool bob_frame::rgb::load(ibinaryfilestream& is)
1 cycrow 10
{
11
	if(!is.good()) return false;
12
	is >> r >> g >> b;
13
	return !is.fail();
14
}
15
//---------------------------------------------------------------------------------
114 cycrow 16
bool bob_frame::rgb::toFile(otextfilestream & os)
1 cycrow 17
{
18
	os << noSemicolons << r << ';' << g << ';' << b << "; ";
19
	return os.good();
20
}
21
//---------------------------------------------------------------------------------
114 cycrow 22
bool bob_frame::rgb::toFile(obinaryfilestream& os)
1 cycrow 23
{
24
	os << r << g << b;
25
	return os.good();
26
}
27
//---------------------------------------------------------------------------------
114 cycrow 28
bool bob_frame::AngleAxis::load(ibinaryfilestream& is)
1 cycrow 29
{
30
	if(!is.good()) return false;
31
	is >> angle >> x >> y >> z;
114 cycrow 32
 
1 cycrow 33
	return(!is.fail());
34
}
35
//---------------------------------------------------------------------------------
114 cycrow 36
bool bob_frame::AngleAxis::toFile(otextfilestream& os)
1 cycrow 37
{
38
	os << noSemicolons << angle << ';' << x << ';' << y << ';' << z << "; ";
39
	return os.good();
40
}
41
//---------------------------------------------------------------------------------
114 cycrow 42
bool bob_frame::AngleAxis::toFile(obinaryfilestream& os)
1 cycrow 43
{
44
	os << angle << x << y << z;
45
	return os.good();
46
}
47
//---------------------------------------------------------------------------------
114 cycrow 48
bool bob_frame::tcb_info::load(ibinaryfilestream& is)
1 cycrow 49
{
50
	if(!is.good()) return false;
51
	is >> tension >> continuity >> bias >> easeFrom >> easeTo;
52
	return !is.fail();
53
}
54
//---------------------------------------------------------------------------------
114 cycrow 55
bool bob_frame::tcb_info::toFile(otextfilestream & os)
1 cycrow 56
{
57
	os << noSemicolons;
58
	os << tension << ';' << continuity << ';' << bias << ';' << easeFrom << ';' << easeTo << "; ";
59
	return os.good();
60
}
61
//---------------------------------------------------------------------------------
114 cycrow 62
bool bob_frame::tcb_info::toFile(obinaryfilestream& os)
1 cycrow 63
{
64
	os << tension << continuity << bias << easeFrom << easeTo;
65
	return os.good();
66
}
67
//---------------------------------------------------------------------------------
114 cycrow 68
bool bob_frame::load(ibinaryfilestream& is)
1 cycrow 69
{
70
	is >> flags;
114 cycrow 71
 
1 cycrow 72
	// if we don't know some bits in the flags, the load will probably fail but not necessarily
73
	if((flags & ~flagMask) > 0)
74
		error(s_warning, e_unsupportedFrameFlags, "0x%X - unsupported bits set in frame flags", flags);
114 cycrow 75
 
1 cycrow 76
	// these flags are "known" but they were never found so I don't know how to treat them
77
	if(flags & CUT_F_POSBEZINFO)
78
		error(s_warning, e_unsupportedFrameFlags, "0x%X: CUT_F_POSBEZINFO encountered - don't know how to output", flags);
79
	if(flags & CUT_F_SAMESCALE)
80
		error(s_warning, e_unsupportedFrameFlags, "0x%X: CUT_F_SAMESCALE encountered", flags);
114 cycrow 81
 
1 cycrow 82
	if((flags & CUT_F_SAMEPOS)==0){
83
		if(position.load(is)==false) { error(e_notEnoughData, "Error loading position"); return false; }
84
		if((flags & CUT_F_POSTCBINFO) > 0) {
85
			pos_tcb_info=new tcb_info();
86
			if(pos_tcb_info->load(is)==false) { error(e_notEnoughData, "Error loading position TCB data"); return false; }
87
		}
88
	}
89
	if((flags & CUT_F_SAMEROT)==0 && (flags & CUT_F_ROT) > 0){
114 cycrow 90
		rotation=new AngleAxis();
1 cycrow 91
		if(rotation->load(is)==false) { error(e_notEnoughData, "Error loading rotation"); return false; }
92
		if((flags & CUT_F_ROTTCBINFO) > 0) {
93
			rot_tcb_info=new tcb_info();
94
			if(rot_tcb_info->load(is)==false) { error(e_notEnoughData, "Error loading rotation TCB data"); return false; }
95
		}
96
	}
97
	if((flags & CUT_F_TARGETPOS) > 0) {
98
		if((flags & CUT_F_SAMETARGET) == 0){
114 cycrow 99
			targetPos=new Position();
1 cycrow 100
			if(targetPos->load(is)==false) { error(e_notEnoughData, "Error loading target position data"); return false; }
101
		}
102
		if((flags & CUT_F_SAMEROT) == 0){
103
			is >> rollAngle;
104
			if(is.fail()) { error(e_notEnoughData, "Error loading roll angle"); return false; }
105
		}
106
		if((flags & CUT_F_TPOSTCBINFO) > 0) {
107
			tpos_tcb_info=new tcb_info();
108
			if(tpos_tcb_info->load(is)==false) { error(e_notEnoughData, "Error loading target position TCB data"); return false; }
109
		}
110
	}
111
	if((flags & CUT_F_SAMEFOV)==0 && (flags & CUT_F_FOV) > 0){
112
		is >> fov;
113
		if(is.fail()) { error(e_notEnoughData, "Error loading FOV"); return false; }
114
	}
115
	if((flags & CUT_F_SAMECOLOR)==0 && (flags & CUT_F_COLOR) > 0){
116
		color=new rgb();
117
		if(color->load(is)==false) { error(e_notEnoughData, "Error loading RGB"); return false; }
118
	}
114 cycrow 119
 
1 cycrow 120
	is >> length >> index;
121
	if(is.fail()) { error(e_notEnoughData, "Error loading length or index"); return false; }
114 cycrow 122
 
1 cycrow 123
	return !is.fail();
124
}
125
//---------------------------------------------------------------------------------
114 cycrow 126
bool bob_frame::toFile(obinaryfilestream& os)
1 cycrow 127
{
128
	os << flags;
114 cycrow 129
 
1 cycrow 130
	if((flags & CUT_F_SAMEPOS)==0){
131
		position.toFile(os);
132
		if(pos_tcb_info)
133
			pos_tcb_info->toFile(os);
134
	}
135
	if((flags & CUT_F_SAMEROT)==0 && rotation){
136
		rotation->toFile(os);
137
		if(rot_tcb_info)
138
			rot_tcb_info->toFile(os);
139
	}
140
	if(flags & CUT_F_TARGETPOS) {
141
		if(targetPos)
142
			targetPos->toFile(os);
114 cycrow 143
 
1 cycrow 144
		if((flags & CUT_F_SAMEROT) == 0)
145
			os << rollAngle;
114 cycrow 146
 
1 cycrow 147
		if(tpos_tcb_info)
148
			tpos_tcb_info->toFile(os);
149
	}
150
	if((flags & CUT_F_SAMEFOV)==0 && (flags & CUT_F_FOV) > 0)
151
		os << fov;
114 cycrow 152
 
1 cycrow 153
	if((flags & CUT_F_SAMECOLOR)==0 && (flags & CUT_F_COLOR) > 0)
154
		color->toFile(os);
114 cycrow 155
 
1 cycrow 156
	os << length << index;
157
	return os.good();
158
}
159
//---------------------------------------------------------------------------------
114 cycrow 160
bool bob_frame::toFile(otextfilestream& os)
1 cycrow 161
{
162
	os << noSemicolons << "{ " << hex << "0x" << flags << dec << "; ";
114 cycrow 163
 
1 cycrow 164
	if((flags & CUT_F_SAMEPOS)==0){
165
		position.toFile(os);
166
		if(pos_tcb_info)
167
			pos_tcb_info->toFile(os);
168
	}
169
	if((flags & CUT_F_SAMEROT)==0 && rotation){
170
		rotation->toFile(os);
171
		if(rot_tcb_info)
172
			rot_tcb_info->toFile(os);
173
	}
174
	if((flags & CUT_F_TARGETPOS) > 0) {
175
		if(targetPos)
176
			targetPos->toFile(os);
114 cycrow 177
 
1 cycrow 178
		if((flags & CUT_F_SAMEROT) == 0)
179
			os << rollAngle << "; ";
114 cycrow 180
 
1 cycrow 181
		if(tpos_tcb_info)
182
			tpos_tcb_info->toFile(os);
183
	}
184
	if((flags & CUT_F_SAMEFOV)==0 && (flags & CUT_F_FOV) > 0)
185
		os << fov << "; ";
114 cycrow 186
 
1 cycrow 187
	if((flags & CUT_F_SAMECOLOR)==0 && (flags & CUT_F_COLOR) > 0)
188
		color->toFile(os);
114 cycrow 189
 
1 cycrow 190
	os << autoSemicolons << length << index << noSemicolons << '}';
114 cycrow 191
 
1 cycrow 192
	return os.good();
193
}
194
//---------------------------------------------------------------------------------
114 cycrow 195
int bob_frame::valueCount()
1 cycrow 196
{
197
	int size=0;
114 cycrow 198
 
1 cycrow 199
	if((flags & CUT_F_SAMEPOS)==0){
200
		size+=3;
201
		if((flags & CUT_F_POSTCBINFO) > 0)
202
			size+=5;
203
	}
204
	if((flags & CUT_F_SAMEROT)==0 && (flags & CUT_F_ROT) > 0){
205
		size+=4;
206
		if((flags & CUT_F_ROTTCBINFO) > 0)
207
			size+=5;
208
	}
209
	if((flags & CUT_F_TARGETPOS) > 0) {
210
		if((flags & CUT_F_SAMETARGET) == 0)
211
			size+=3;
114 cycrow 212
 
1 cycrow 213
		if((flags & CUT_F_SAMEROT) == 0)
214
			size++;
114 cycrow 215
 
1 cycrow 216
		if((flags & CUT_F_TPOSTCBINFO) > 0)
217
			size+=5;
218
	}
219
	if((flags & CUT_F_SAMEFOV)==0 && (flags & CUT_F_FOV) > 0)
220
		size+=1;
221
	if((flags & CUT_F_SAMECOLOR)==0 && (flags & CUT_F_COLOR) > 0)
222
		size+=3;
223
	return size;
224
}
225
//---------------------------------------------------------------------------------