1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/*
* selftest.cpp
*
* Copyright (C) 1999 Stephen F. White, 2003 J. "MUFTI" Scheurich
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see the file "COPYING" for details); if
* not, write to the Free Software Foundation, Inc., 675 Mass Ave,
* Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include "stdafx.h"
#include "swt.h"
#include "DuneApp.h"
#include "MainWindow.h"
#include "MoveCommand.h"
#include "xerrorhandler.h"
#include "Field.h"
#include "Types.h"
bool cover = false;
bool kambi = false;
#define errorprintf fprintf
void printFirstPart()
{
printf("#include <stdio.h>\n");
printf("#include <time.h>\n");
printf("#include \"stdafx.h\"\n");
printf("\n");
printf("#include \"swt.h\"\n");
printf("\n");
printf("#include \"DuneApp.h\"\n");
printf("#include \"MainWindow.h\"\n");
printf("#include \"MoveCommand.h\"\n");
printf("#include \"xerrorhandler.h\"\n");
printf("#include \"Field.h\"\n");
printf("#include \"AllNodes.h\"\n");
printf("\n");
printf("#define errorprintf fprintf \n");
printf("\n");
printf("int main(int argc, char *argv[])\n");
printf("{\n");
printf(" TheApp = new DuneApp();\n");
if (cover)
printf(" TheApp->setCoverMode();;\n");
if (kambi)
printf(" TheApp->setKambiMode();;\n");
printf(" Scene* scene = new Scene();\n");
printf(" long seed;\n");
printf(" NodeComment* comment;\n");
printf(" char commentBuffer[256];\n");
}
void printLastPart()
{
printf(" delete TheApp;\n");
printf(" normalExit(0);\n");
printf(" return 0;\n");
printf("}\n");
}
int main(int argc, char *argv[])
{
bool x3d = false;
TheApp = new DuneApp();
int i;
bool fileflag = false;
Scene* scene = new Scene();
for (i=1;i<argc;i++) {
if (strcmp(argv[i], "-x3d") == 0)
x3d = true;
else if (strcmp(argv[i], "-cover") == 0)
cover = true;
else if (strcmp(argv[i], "-kambi") == 0)
kambi = true;
else if (!TheApp->ImportFile(argv[i], scene)) {
fileflag = true;
delete scene;
perror(argv[i]);
return(1);
}
}
if (fileflag == false) {
StringArray *names = scene->getAllNodeNames();
printFirstPart();
if (x3d)
scene->setX3dv();
if (cover)
TheApp->setCoverMode();
if (kambi)
TheApp->setKambiMode();
for (i=0; i < names->size(); i++) {
Node* node = scene->createNode(names->get(i));
const char *str = names->get(i);
// skip fake nodes
if (strcmp(str,"#") == 0)
continue;
if (strcmp(str,"IMPORT") == 0)
continue;
if (strcmp(str,"EXPORT") == 0)
continue;
if (!cover)
if (node->getProto()->isCoverProto() && !TheApp->getCoverMode())
continue;
// Geo nodes
if (stringncmp(str,"Geo") == 0)
continue;
if (stringncmp(str,"Text3D") == 0)
continue;
if (stringncmp(str, "LdrawDatExport") == 0)
continue;
if (stringncmp(str, "BooleanSequencer") == 0)
continue;
printf(" seed = time(0);\n");
printf(" srand48(seed);\n");
printf(" comment = (NodeComment *)scene->createNode(\"#\"); \n");
printf(" sprintf(commentBuffer, \"seed: \%d\", seed);\n");
printf(" comment->comment(new MFString(commentBuffer));\n");
printf(" scene->execute(new MoveCommand(comment, ");
printf(" NULL, -1, scene->getRoot(),\n");
printf(" scene->getRootField()));\n");
printf(" Node%s* node%s = (Node%s*)scene->createNode(\"%s\"); \n",
str,str,str,str);
for (int j = 0; j < node->getProto()->getNumFields(); j++) {
Field *field = node->getProto()->getField(j);
if (x3d) {
if (field->getFlags() & FF_VRML_ONLY)
continue;
} else if (field->getFlags() & FF_X3D_ONLY)
continue;
if (!cover && (field->getFlags() & FF_COVER_ONLY))
continue;
if (!kambi && (field->getFlags() & FF_KAMBI_ONLY))
continue;
const char *fieldName = field->getName(false);
if (strcmp(fieldName, "metadata") != 0)
if (((strcmp(str, "NurbsCurve") == 0) ||
(strcmp(str, "NurbsSurface") == 0) ||
(strcmp(str, "NurbsTrimmedSurface") == 0)) &&
((strcmp(fieldName, "controlPoint") == 0) ||
(strcmp(fieldName, "controlPointX3D") == 0)))
printf(" node%s->createControlPoints(new MFVec3f());\n",
str);
else {
printf(" node%s->%s((%s *)node%s->%s()%s%d%s",
str, fieldName,
typeEnumToString(field->getType()),
str, fieldName, "->getRandom(scene, ",
field->getNodeType(), "));");
printf("\n");
}
}
printf(" scene->execute(new MoveCommand(node%s, NULL, -1, scene->getRoot(), \n",
str);
printf(" scene->getRootField()));\n");
}
if (x3d)
printf(" scene->write(STDOUT_FILENO,\"\",X3DV);\n");
else
printf(" scene->write(STDOUT_FILENO,\"\",true);\n");
printLastPart();
}
delete TheApp;
normalExit(0);
return 0;
}
|