38 static char THIS_FILE[] = __FILE__;
43 IMPLEMENT_DYNCREATE(
MagicDoc, CDocument)
45 BEGIN_MESSAGE_MAP(
MagicDoc, CDocument)
49 ON_UPDATE_COMMAND_UI(ID_SURFACE_OPTIMIZE, OnUpdateSurfaceOptimize)
50 ON_UPDATE_COMMAND_UI(ID_SURFACE_EXPLODE, OnUpdateSurfaceExplode)
57 : solid(0), selection(0)
151 if (!CDocument::OnNewDocument())
174 void MagicDoc::AssertValid()
const
176 CDocument::AssertValid();
179 void MagicDoc::Dump(CDumpContext& dc)
const
189 SetModifiedFlag(FALSE);
194 SetModifiedFlag(FALSE);
195 UpdateAllViews(NULL);
201 FILE* fp = fopen(path_name,
"rb");
203 ::MessageBox(0,
"Open Failed: could not open file",
"ERROR", MB_OK);
209 fread(file_id, 4, 1, fp);
213 if (strncmp(file_id,
"MAG", 3)) {
214 ::MessageBox(0,
"Open Failed: Invalid file type",
"ERROR", MB_OK);
218 switch (file_id[3]) {
219 case '6': version = 6;
break;
220 case '5': version = 5;
break;
221 default: version = 0;
break;
224 if (version < 5 || version > 6) {
225 ::MessageBox(0,
"Open Failed: Unsupported version",
"ERROR", MB_OK);
235 SetModifiedFlag(FALSE);
236 UpdateAllViews(NULL);
243 if (strstr(path_name,
".obj") || strstr(path_name,
".OBJ")) {
249 if (s->
Load(&obj_file)) {
261 SetModifiedFlag(FALSE);
262 UpdateAllViews(NULL);
271 SetModifiedFlag(FALSE);
272 UpdateAllViews(NULL);
280 if (strstr(path_name,
".3ds") || strstr(path_name,
".3DS")) {
286 if (s->
Load(&model_file)) {
298 SetModifiedFlag(FALSE);
299 UpdateAllViews(NULL);
308 SetModifiedFlag(FALSE);
309 UpdateAllViews(NULL);
317 FILE* fp = fopen(path_name,
"rb");
319 ::MessageBox(0,
"Import Failed: could not open file",
"ERROR", MB_OK);
325 fread(file_id, 4, 1, fp);
329 if (strncmp(file_id,
"MAG", 3)) {
330 ::MessageBox(0,
"Open Failed: Invalid file type",
"ERROR", MB_OK);
334 switch (file_id[3]) {
335 case '6': version = 6;
break;
336 case '5': version = 5;
break;
337 default: version = 0;
break;
340 if (version < 5 || version > 6) {
341 ::MessageBox(0,
"Open Failed: Unsupported version",
"ERROR", MB_OK);
349 if (s->
Load(&mag_file)) {
361 SetModifiedFlag(FALSE);
362 UpdateAllViews(NULL);
373 SetModifiedFlag(FALSE);
374 UpdateAllViews(NULL);
388 if (strstr(path_name,
".obj") || strstr(path_name,
".OBJ")) {
394 if (strstr(path_name,
".3ds") || strstr(path_name,
".3DS")) {
398 if (strstr(path_name,
".mag") || strstr(path_name,
".MAG")) {
409 int LoadBuffer(
const char* filename, BYTE*& buf,
bool null_terminate)
413 FILE* f = ::fopen(filename,
"rb");
416 ::fseek(f, 0, SEEK_END);
418 ::fseek(f, 0, SEEK_SET);
420 if (null_terminate) {
421 buf =
new BYTE[len+1];
431 ::fread(buf, len, 1, f);
463 if (!fname || !*fname)
469 bool pcx_file = strstr(fname,
".pcx") || strstr(fname,
".PCX");
488 int len = strlen(fname);
491 ZeroMemory(tmp,
sizeof(tmp));
493 for (
int i = 0; i < len && !found; i++) {
494 if (strstr(fname + i,
".pcx") == (fname+i)) {
503 strcat_s(tmp,
"+.pcx");
515 if (d3dx.
Load((
char*) fname)) {
539 bool pcx_file = strstr(name,
".pcx") || strstr(name,
".PCX");
540 bool bmp_file = strstr(name,
".bmp") || strstr(name,
".BMP");
541 bool jpg_file = strstr(name,
".jpg") || strstr(name,
".JPG");
542 bool png_file = strstr(name,
".png") || strstr(name,
".PNG");
543 bool tga_file = strstr(name,
".tga") || strstr(name,
".TGA");
547 strcpy_s(filename, name);
549 char* dot = strrchr(filename,
'.');
551 strcpy(dot,
"@.pcx");
552 else if (dot && bmp_file)
553 strcpy(dot,
"@.bmp");
554 else if (dot && jpg_file)
555 strcpy(dot,
"@.jpg");
556 else if (dot && png_file)
557 strcpy(dot,
"@.png");
558 else if (dot && tga_file)
559 strcpy(dot,
"@.tga");
570 loaded = d3dx.
Load(filename);
574 if (pcx_file && pcx.
bitmap) {
577 else if (pcx_file && pcx.
himap) {
580 else if (d3dx.
image) {