Merge branch 'MusicalProgrammer'
Expect bugs
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
|
#include <string>
|
||||||
#include "DataModelInstance.h"
|
#include "DataModelInstance.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <commdlg.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace rapidxml;
|
||||||
|
|
||||||
|
|
||||||
DataModelInstance::DataModelInstance(void)
|
DataModelInstance::DataModelInstance(void)
|
||||||
@@ -18,9 +23,10 @@ DataModelInstance::DataModelInstance(void)
|
|||||||
mouseButton1Down = false;
|
mouseButton1Down = false;
|
||||||
showMessage = false;
|
showMessage = false;
|
||||||
canDelete = false;
|
canDelete = false;
|
||||||
|
_modY=0;
|
||||||
workspace->setParent(this);
|
workspace->setParent(this);
|
||||||
level->setParent(this);
|
level->setParent(this);
|
||||||
|
_loadedFileName="..//skooter.rbxm";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +34,429 @@ DataModelInstance::~DataModelInstance(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
void DataModelInstance::modXMLLevel(float modY)
|
||||||
|
{
|
||||||
|
_modY += modY;
|
||||||
|
clearLevel();
|
||||||
|
debugGetOpen();
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void DataModelInstance::clearLevel()
|
||||||
|
{
|
||||||
|
workspace->clearChildren();
|
||||||
|
}
|
||||||
|
PartInstance* DataModelInstance::makePart()
|
||||||
|
{
|
||||||
|
PartInstance* part = new PartInstance();
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
|
rapidxml::xml_node<>* DataModelInstance::getNode(xml_node<> * node,const char* name)
|
||||||
|
{
|
||||||
|
xml_node<> * tempNode = node->first_node(name);
|
||||||
|
if (!tempNode)
|
||||||
|
{
|
||||||
|
_errMsg = "Expected <";
|
||||||
|
_errMsg += name;
|
||||||
|
_errMsg+="> tag.";
|
||||||
|
_successfulLoad=true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tempNode;
|
||||||
|
}
|
||||||
|
float DataModelInstance::getFloatValue(xml_node<> * node,const char* name)
|
||||||
|
{
|
||||||
|
xml_node<> * tempNode = node->first_node(name);
|
||||||
|
if (!tempNode)
|
||||||
|
{
|
||||||
|
_errMsg = "Expected <";
|
||||||
|
_errMsg += name;
|
||||||
|
_errMsg+="> tag.";
|
||||||
|
_successfulLoad=true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
float newFloat;
|
||||||
|
stringstream converter;
|
||||||
|
converter << tempNode->value();
|
||||||
|
converter >> newFloat;
|
||||||
|
return newFloat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Color3 bcToRGB(short bc)
|
||||||
|
{
|
||||||
|
switch(bc)
|
||||||
|
{
|
||||||
|
case 1: return Color3(0.94901967048645,0.95294123888016,0.95294123888016);
|
||||||
|
case 2: return Color3(0.63137257099152,0.64705884456635,0.63529413938522);
|
||||||
|
case 3: return Color3(0.9764706492424,0.91372555494308,0.60000002384186);
|
||||||
|
case 5: return Color3(0.84313732385635,0.77254909276962,0.60392159223557);
|
||||||
|
case 6: return Color3(0.7607843875885,0.85490202903748,0.72156864404678);
|
||||||
|
case 9: return Color3(0.90980398654938,0.7294117808342,0.78431379795074);
|
||||||
|
case 11: return Color3(0.50196081399918,0.73333334922791,0.85882359743118);
|
||||||
|
case 12: return Color3(0.79607850313187,0.51764708757401,0.258823543787);
|
||||||
|
case 18: return Color3(0.80000007152557,0.55686277151108,0.41176474094391);
|
||||||
|
case 21: return Color3(0.76862752437592,0.15686275064945,0.10980392992496);
|
||||||
|
case 22: return Color3(0.76862752437592,0.43921571969986,0.62745100259781);
|
||||||
|
case 23: return Color3(0.050980396568775,0.41176474094391,0.6745098233223);
|
||||||
|
case 24: return Color3(0.96078437566757,0.80392163991928,0.18823531270027);
|
||||||
|
case 25: return Color3(0.38431376218796,0.27843138575554,0.19607844948769);
|
||||||
|
case 26: return Color3(0.10588236153126,0.16470588743687,0.20784315466881);
|
||||||
|
case 27: return Color3(0.42745101451874,0.43137258291245,0.42352944612503);
|
||||||
|
case 28: return Color3(0.15686275064945,0.49803924560547,0.27843138575554);
|
||||||
|
case 29: return Color3(0.63137257099152,0.76862752437592,0.54901963472366);
|
||||||
|
case 36: return Color3(0.95294123888016,0.8117647767067,0.60784316062927);
|
||||||
|
case 37: return Color3(0.29411765933037,0.59215688705444,0.29411765933037);
|
||||||
|
case 38: return Color3(0.62745100259781,0.37254902720451,0.20784315466881);
|
||||||
|
case 39: return Color3(0.75686281919479,0.79215693473816,0.8705883026123);
|
||||||
|
case 40: return Color3(0.92549026012421,0.92549026012421,0.92549026012421);
|
||||||
|
case 41: return Color3(0.80392163991928,0.32941177487373,0.29411765933037);
|
||||||
|
case 42: return Color3(0.75686281919479,0.87450987100601,0.94117653369904);
|
||||||
|
case 43: return Color3(0.48235297203064,0.71372550725937,0.90980398654938);
|
||||||
|
case 44: return Color3(0.96862751245499,0.94509810209274,0.55294120311737);
|
||||||
|
case 45: return Color3(0.70588237047195,0.82352948188782,0.89411771297455);
|
||||||
|
case 47: return Color3(0.85098046064377,0.52156865596771,0.42352944612503);
|
||||||
|
case 48: return Color3(0.51764708757401,0.71372550725937,0.55294120311737);
|
||||||
|
case 49: return Color3(0.97254908084869,0.94509810209274,0.51764708757401);
|
||||||
|
case 50: return Color3(0.92549026012421,0.90980398654938,0.8705883026123);
|
||||||
|
case 100: return Color3(0.93333339691162,0.76862752437592,0.71372550725937);
|
||||||
|
case 101: return Color3(0.85490202903748,0.52549022436142,0.47843140363693);
|
||||||
|
case 102: return Color3(0.43137258291245,0.60000002384186,0.79215693473816);
|
||||||
|
case 103: return Color3(0.78039222955704,0.75686281919479,0.71764707565308);
|
||||||
|
case 104: return Color3(0.41960787773132,0.19607844948769,0.48627454042435);
|
||||||
|
case 105: return Color3(0.88627457618713,0.60784316062927,0.25098040699959);
|
||||||
|
case 106: return Color3(0.85490202903748,0.52156865596771,0.2549019753933);
|
||||||
|
case 107: return Color3(0,0.56078433990479,0.61176472902298);
|
||||||
|
case 108: return Color3(0.4078431725502,0.36078432202339,0.26274511218071);
|
||||||
|
case 110: return Color3(0.26274511218071,0.32941177487373,0.57647061347961);
|
||||||
|
case 111: return Color3(0.74901962280273,0.71764707565308,0.69411766529083);
|
||||||
|
case 112: return Color3(0.4078431725502,0.45490199327469,0.6745098233223);
|
||||||
|
case 113: return Color3(0.89411771297455,0.678431391716,0.78431379795074);
|
||||||
|
case 115: return Color3(0.78039222955704,0.82352948188782,0.23529413342476);
|
||||||
|
case 116: return Color3(0.33333334326744,0.64705884456635,0.68627452850342);
|
||||||
|
case 118: return Color3(0.71764707565308,0.84313732385635,0.83529418706894);
|
||||||
|
case 119: return Color3(0.64313727617264,0.74117648601532,0.27843138575554);
|
||||||
|
case 120: return Color3(0.85098046064377,0.89411771297455,0.65490198135376);
|
||||||
|
case 121: return Color3(0.90588241815567,0.6745098233223,0.34509804844856);
|
||||||
|
case 123: return Color3(0.82745105028152,0.43529415130615,0.29803922772408);
|
||||||
|
case 124: return Color3(0.57254904508591,0.22352942824364,0.47058826684952);
|
||||||
|
case 125: return Color3(0.91764712333679,0.72156864404678,0.57254904508591);
|
||||||
|
case 126: return Color3(0.64705884456635,0.64705884456635,0.79607850313187);
|
||||||
|
case 127: return Color3(0.86274516582489,0.73725491762161,0.50588238239288);
|
||||||
|
case 128: return Color3(0.68235296010971,0.47843140363693,0.34901961684227);
|
||||||
|
case 131: return Color3(0.61176472902298,0.63921570777893,0.65882354974747);
|
||||||
|
case 133: return Color3(0.83529418706894,0.45098042488098,0.23921570181847);
|
||||||
|
case 134: return Color3(0.84705889225006,0.8666667342186,0.33725491166115);
|
||||||
|
case 135: return Color3(0.45490199327469,0.52549022436142,0.61568629741669);
|
||||||
|
case 136: return Color3(0.52941179275513,0.48627454042435,0.56470590829849);
|
||||||
|
case 137: return Color3(0.87843143939972,0.59607845544815,0.39215689897537);
|
||||||
|
case 138: return Color3(0.58431375026703,0.54117649793625,0.45098042488098);
|
||||||
|
case 140: return Color3(0.12549020349979,0.22745099663734,0.33725491166115);
|
||||||
|
case 141: return Color3(0.15294118225574,0.27450981736183,0.17647059261799);
|
||||||
|
case 143: return Color3(0.8117647767067,0.88627457618713,0.96862751245499);
|
||||||
|
case 145: return Color3(0.47450983524323,0.53333336114883,0.63137257099152);
|
||||||
|
case 146: return Color3(0.58431375026703,0.55686277151108,0.63921570777893);
|
||||||
|
case 147: return Color3(0.57647061347961,0.52941179275513,0.40392160415649);
|
||||||
|
case 148: return Color3(0.34117648005486,0.34509804844856,0.34117648005486);
|
||||||
|
case 149: return Color3(0.086274512112141,0.11372549831867,0.19607844948769);
|
||||||
|
case 150: return Color3(0.67058825492859,0.678431391716,0.6745098233223);
|
||||||
|
case 151: return Color3(0.47058826684952,0.56470590829849,0.50980395078659);
|
||||||
|
case 153: return Color3(0.58431375026703,0.47450983524323,0.46666669845581);
|
||||||
|
case 154: return Color3(0.48235297203064,0.1803921610117,0.1843137294054);
|
||||||
|
case 157: return Color3(1,0.96470594406128,0.48235297203064);
|
||||||
|
case 158: return Color3(0.88235300779343,0.64313727617264,0.7607843875885);
|
||||||
|
case 168: return Color3(0.4588235616684,0.42352944612503,0.38431376218796);
|
||||||
|
case 176: return Color3(0.59215688705444,0.41176474094391,0.35686275362968);
|
||||||
|
case 178: return Color3(0.70588237047195,0.51764708757401,0.33333334326744);
|
||||||
|
case 179: return Color3(0.53725492954254,0.52941179275513,0.53333336114883);
|
||||||
|
case 180: return Color3(0.84313732385635,0.66274511814117,0.29411765933037);
|
||||||
|
case 190: return Color3(0.9764706492424,0.83921575546265,0.1803921610117);
|
||||||
|
case 191: return Color3(0.90980398654938,0.67058825492859,0.17647059261799);
|
||||||
|
case 192: return Color3(0.41176474094391,0.25098040699959,0.15686275064945);
|
||||||
|
case 193: return Color3(0.8117647767067,0.37647062540054,0.14117647707462);
|
||||||
|
case 195: return Color3(0.27450981736183,0.40392160415649,0.64313727617264);
|
||||||
|
case 196: return Color3(0.13725490868092,0.27843138575554,0.54509806632996);
|
||||||
|
case 198: return Color3(0.55686277151108,0.258823543787,0.52156865596771);
|
||||||
|
case 199: return Color3(0.38823533058167,0.37254902720451,0.38431376218796);
|
||||||
|
case 200: return Color3(0.50980395078659,0.54117649793625,0.3647058904171);
|
||||||
|
case 208: return Color3(0.89803928136826,0.89411771297455,0.87450987100601);
|
||||||
|
case 209: return Color3(0.69019609689713,0.55686277151108,0.26666668057442);
|
||||||
|
case 210: return Color3(0.43921571969986,0.58431375026703,0.47058826684952);
|
||||||
|
case 211: return Color3(0.47450983524323,0.70980393886566,0.70980393886566);
|
||||||
|
case 212: return Color3(0.6235294342041,0.76470595598221,0.91372555494308);
|
||||||
|
case 213: return Color3(0.42352944612503,0.50588238239288,0.71764707565308);
|
||||||
|
case 216: return Color3(0.56078433990479,0.29803922772408,0.16470588743687);
|
||||||
|
case 217: return Color3(0.48627454042435,0.36078432202339,0.27450981736183);
|
||||||
|
case 218: return Color3(0.58823531866074,0.43921571969986,0.6235294342041);
|
||||||
|
case 219: return Color3(0.41960787773132,0.38431376218796,0.60784316062927);
|
||||||
|
case 220: return Color3(0.65490198135376,0.66274511814117,0.80784320831299);
|
||||||
|
case 221: return Color3(0.80392163991928,0.38431376218796,0.59607845544815);
|
||||||
|
case 222: return Color3(0.89411771297455,0.678431391716,0.78431379795074);
|
||||||
|
case 223: return Color3(0.86274516582489,0.56470590829849,0.58431375026703);
|
||||||
|
case 224: return Color3(0.94117653369904,0.83529418706894,0.62745100259781);
|
||||||
|
case 225: return Color3(0.9215686917305,0.72156864404678,0.49803924560547);
|
||||||
|
case 226: return Color3(0.99215692281723,0.91764712333679,0.55294120311737);
|
||||||
|
case 232: return Color3(0.49019610881805,0.73333334922791,0.8666667342186);
|
||||||
|
case 268: return Color3(0.2039215862751,0.16862745583057,0.4588235616684);
|
||||||
|
case 1001: return Color3(0.97254908084869,0.97254908084869,0.97254908084869);
|
||||||
|
case 1002: return Color3(0.80392163991928,0.80392163991928,0.80392163991928);
|
||||||
|
case 1003: return Color3(0.066666670143604,0.066666670143604,0.066666670143604);
|
||||||
|
case 1004: return Color3(1,0,0);
|
||||||
|
case 1005: return Color3(1,0.68627452850342,0);
|
||||||
|
case 1006: return Color3(0.70588237047195,0.50196081399918,1);
|
||||||
|
case 1007: return Color3(0.63921570777893,0.29411765933037,0.29411765933037);
|
||||||
|
case 1008: return Color3(0.75686281919479,0.74509805440903,0.258823543787);
|
||||||
|
case 1009: return Color3(1,1,0);
|
||||||
|
case 1010: return Color3(0,0,1);
|
||||||
|
case 1011: return Color3(0,0.12549020349979,0.37647062540054);
|
||||||
|
case 1012: return Color3(0.1294117718935,0.32941177487373,0.72549021244049);
|
||||||
|
case 1013: return Color3(0.015686275437474,0.68627452850342,0.92549026012421);
|
||||||
|
case 1014: return Color3(0.66666668653488,0.33333334326744,0);
|
||||||
|
case 1015: return Color3(0.66666668653488,0,0.66666668653488);
|
||||||
|
case 1016: return Color3(1,0.40000003576279,0.80000007152557);
|
||||||
|
case 1017: return Color3(1,0.68627452850342,0);
|
||||||
|
case 1018: return Color3(0.070588238537312,0.93333339691162,0.83137261867523);
|
||||||
|
case 1019: return Color3(0,1,1);
|
||||||
|
case 1020: return Color3(0,1,0);
|
||||||
|
case 1021: return Color3(0.22745099663734,0.49019610881805,0.082352943718433);
|
||||||
|
case 1022: return Color3(0.49803924560547,0.55686277151108,0.39215689897537);
|
||||||
|
case 1023: return Color3(0.54901963472366,0.35686275362968,0.6235294342041);
|
||||||
|
case 1024: return Color3(0.68627452850342,0.8666667342186,1);
|
||||||
|
case 1025: return Color3(1,0.78823536634445,0.78823536634445);
|
||||||
|
case 1026: return Color3(0.69411766529083,0.65490198135376,1);
|
||||||
|
case 1027: return Color3(0.6235294342041,0.95294123888016,0.91372555494308);
|
||||||
|
case 1028: return Color3(0.80000007152557,1,0.80000007152557);
|
||||||
|
case 1029: return Color3(1,1,0.80000007152557);
|
||||||
|
case 1030: return Color3(1,0.80000007152557,0.60000002384186);
|
||||||
|
case 1031: return Color3(0.38431376218796,0.14509804546833,0.81960791349411);
|
||||||
|
case 1032: return Color3(1,0,0.74901962280273);
|
||||||
|
default: return Color3::gray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool DataModelInstance::scanXMLObject(xml_node<> * scanNode)
|
||||||
|
{
|
||||||
|
xml_node<> * watchFirstNode = scanNode->first_node();
|
||||||
|
|
||||||
|
for (xml_node<> *node = scanNode->first_node();node; node = node->next_sibling())
|
||||||
|
{
|
||||||
|
|
||||||
|
if (strncmp(node->name(),"Item",4)==0)
|
||||||
|
{
|
||||||
|
xml_attribute<> *classAttr = node->first_attribute("class");
|
||||||
|
std::string className = classAttr->value();
|
||||||
|
if (className=="Part") {
|
||||||
|
xml_node<> *propNode = node->first_node();
|
||||||
|
xml_node<> *cFrameNode=0;
|
||||||
|
xml_node<> *sizeNode=0;
|
||||||
|
xml_node<> *colorNode=0;
|
||||||
|
xml_node<> *brickColorNode=0;
|
||||||
|
xml_node<> *nameNode=0;
|
||||||
|
|
||||||
|
for (xml_node<> *partPropNode = propNode->first_node();partPropNode; partPropNode = partPropNode->next_sibling())
|
||||||
|
{
|
||||||
|
for (xml_attribute<> *attr = partPropNode->first_attribute();attr; attr = attr->next_attribute())
|
||||||
|
{
|
||||||
|
std::string xmlName = attr->name();
|
||||||
|
std::string xmlValue = attr->value();
|
||||||
|
|
||||||
|
if (xmlValue=="CFrame" | xmlValue=="CoordinateFrame")
|
||||||
|
{
|
||||||
|
cFrameNode = partPropNode;
|
||||||
|
}
|
||||||
|
if (xmlValue=="Name")
|
||||||
|
{
|
||||||
|
nameNode = partPropNode;
|
||||||
|
}
|
||||||
|
if (xmlValue=="Color")
|
||||||
|
{
|
||||||
|
colorNode=partPropNode;
|
||||||
|
}
|
||||||
|
if (xmlValue=="BrickColor")
|
||||||
|
{
|
||||||
|
brickColorNode=partPropNode;
|
||||||
|
}
|
||||||
|
if (xmlValue=="size")
|
||||||
|
{
|
||||||
|
sizeNode = partPropNode;
|
||||||
|
_legacyLoad=false;
|
||||||
|
}
|
||||||
|
if (xmlValue=="Part")
|
||||||
|
{
|
||||||
|
for (xml_node<> *featureNode = partPropNode->first_node();featureNode; featureNode = featureNode->next_sibling())
|
||||||
|
{
|
||||||
|
for (xml_attribute<> *attr = featureNode->first_attribute();attr; attr = attr->next_attribute())
|
||||||
|
{
|
||||||
|
std::string xmlName = attr->name();
|
||||||
|
std::string xmlValue = attr->value();
|
||||||
|
if (xmlValue=="size")
|
||||||
|
{
|
||||||
|
sizeNode=featureNode;
|
||||||
|
_legacyLoad=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cFrameNode) {
|
||||||
|
_errMsg="CFrame is missing in Part";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!sizeNode) {
|
||||||
|
_errMsg="Size is missing in Part";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float R=1;
|
||||||
|
float G=1;
|
||||||
|
float B=1;
|
||||||
|
|
||||||
|
if (colorNode)
|
||||||
|
{
|
||||||
|
R = getFloatValue(colorNode,"R");
|
||||||
|
G = getFloatValue(colorNode,"G");
|
||||||
|
B = getFloatValue(colorNode,"B");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string newName = nameNode->value();
|
||||||
|
float X = getFloatValue(cFrameNode,"X");
|
||||||
|
float Y = getFloatValue(cFrameNode,"Y");
|
||||||
|
float Z = getFloatValue(cFrameNode,"Z");
|
||||||
|
float R00 = getFloatValue(cFrameNode,"R00");
|
||||||
|
float R01 = getFloatValue(cFrameNode,"R01");
|
||||||
|
float R02 = getFloatValue(cFrameNode,"R02");
|
||||||
|
float R10 = getFloatValue(cFrameNode,"R10");
|
||||||
|
float R11 = getFloatValue(cFrameNode,"R11");
|
||||||
|
float R12 = getFloatValue(cFrameNode,"R12");
|
||||||
|
float R20 = getFloatValue(cFrameNode,"R20");
|
||||||
|
float R21 = getFloatValue(cFrameNode,"R21");
|
||||||
|
float R22 = getFloatValue(cFrameNode,"R22");
|
||||||
|
|
||||||
|
float sizeX = getFloatValue(sizeNode,"X");
|
||||||
|
float sizeY = getFloatValue(sizeNode,"Y");
|
||||||
|
float sizeZ = getFloatValue(sizeNode,"Z");
|
||||||
|
//sizeX=1;
|
||||||
|
//sizeY=1;
|
||||||
|
//sizeZ=1;
|
||||||
|
if (_successfulLoad) {
|
||||||
|
PartInstance* test = makePart();
|
||||||
|
test->setParent(getWorkspace());
|
||||||
|
test->color = Color3(R,G,B);
|
||||||
|
if(brickColorNode)
|
||||||
|
{
|
||||||
|
test->color = bcToRGB(atoi(brickColorNode->value()));
|
||||||
|
}
|
||||||
|
test->setSize(Vector3(sizeX,sizeY+_modY,sizeZ));
|
||||||
|
test->setName(newName);
|
||||||
|
CoordinateFrame cf;
|
||||||
|
|
||||||
|
if (_legacyLoad)
|
||||||
|
{
|
||||||
|
|
||||||
|
cf = CoordinateFrame(Vector3(-X,Y,Z))*CoordinateFrame(Vector3(-sizeX/2,(sizeY+_modY)/2,sizeZ/2)*Matrix3(R00,R01,R02,R10,R11,R12,R20,R21,R22));
|
||||||
|
cf.rotation = Matrix3(R00,R01,R02,R10,R11,R12,R20,R21,R22);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cf.translation = Vector3(X,Y,Z);
|
||||||
|
cf.rotation = Matrix3(R00,R01,R02,R10,R11,R12,R20,R21,R22);
|
||||||
|
}
|
||||||
|
|
||||||
|
test->setCFrame(cf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
for (xml_attribute<> *attr = node->first_attribute();attr; attr = attr->next_attribute())
|
||||||
|
{
|
||||||
|
std::string xmlName = attr->name();
|
||||||
|
std::string xmlValue = attr->value();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
scanXMLObject(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DataModelInstance::load(const char* filename, bool clearObjects)
|
||||||
|
{
|
||||||
|
ifstream levelFile(filename,ios::binary);
|
||||||
|
if (levelFile)
|
||||||
|
{
|
||||||
|
if (clearObjects)
|
||||||
|
clearLevel();
|
||||||
|
readXMLFileStream(&levelFile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DataModelInstance::readXMLFileStream(std::ifstream* file)
|
||||||
|
{
|
||||||
|
file->seekg(0,file->end);
|
||||||
|
int length = file->tellg();
|
||||||
|
file->seekg(0,file->beg);
|
||||||
|
char * buffer = new char[length+1];
|
||||||
|
buffer[length]=0;
|
||||||
|
file->read(buffer,length);
|
||||||
|
file->close();
|
||||||
|
xml_document<> doc;
|
||||||
|
doc.parse<0>(buffer);
|
||||||
|
xml_node<> *mainNode = doc.first_node();
|
||||||
|
_legacyLoad=false;
|
||||||
|
//std::string xmlName = mainNode->name();
|
||||||
|
//node = node->first_node();
|
||||||
|
//xmlName = node->name();
|
||||||
|
scanXMLObject(mainNode);
|
||||||
|
delete[] buffer;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DataModelInstance::debugGetOpen()
|
||||||
|
{
|
||||||
|
ifstream levelFile(_loadedFileName.c_str(),ios::binary);
|
||||||
|
if (levelFile)
|
||||||
|
readXMLFileStream(&levelFile);
|
||||||
|
else
|
||||||
|
getOpen();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DataModelInstance::getOpen()
|
||||||
|
{
|
||||||
|
_modY=0;
|
||||||
|
OPENFILENAME of;
|
||||||
|
ZeroMemory( &of , sizeof( of));
|
||||||
|
of.lStructSize = sizeof(OPENFILENAME);
|
||||||
|
of.lpstrFilter = "Roblox Files\0*.rbxm;*.rbxl\0\0";
|
||||||
|
char szFile[512];
|
||||||
|
of.lpstrFile = szFile ;
|
||||||
|
of.lpstrFile[0]='\0';
|
||||||
|
of.nMaxFile=500;
|
||||||
|
of.lpstrTitle="Hello";
|
||||||
|
of.Flags = OFN_FILEMUSTEXIST;
|
||||||
|
ShowCursor(TRUE);
|
||||||
|
BOOL file = GetOpenFileName(&of);
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
_loadedFileName = of.lpstrFile;
|
||||||
|
load(of.lpstrFile,true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
void DataModelInstance::setMessage(std::string msg)
|
void DataModelInstance::setMessage(std::string msg)
|
||||||
{
|
{
|
||||||
message = msg;
|
message = msg;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "WorkspaceInstance.h"
|
#include "WorkspaceInstance.h"
|
||||||
#include "LevelInstance.h"
|
#include "LevelInstance.h"
|
||||||
#include "PartInstance.h"
|
#include "PartInstance.h"
|
||||||
|
#include "rapidxml/rapidxml.hpp"
|
||||||
|
|
||||||
class DataModelInstance :
|
class DataModelInstance :
|
||||||
public Instance
|
public Instance
|
||||||
@@ -9,26 +10,42 @@ class DataModelInstance :
|
|||||||
public:
|
public:
|
||||||
DataModelInstance(void);
|
DataModelInstance(void);
|
||||||
~DataModelInstance(void);
|
~DataModelInstance(void);
|
||||||
void setMessage(std::string);
|
void setMessage(std::string);
|
||||||
void setMessageBrickCount();
|
void setMessageBrickCount();
|
||||||
void clearMessage();
|
void clearMessage();
|
||||||
void drawMessage(RenderDevice*);
|
bool debugGetOpen();
|
||||||
WorkspaceInstance* getWorkspace();
|
bool getOpen();
|
||||||
WorkspaceInstance* workspace;
|
bool load(const char* filename,bool clearObjects);
|
||||||
LevelInstance * level;
|
bool readXMLFileStream(std::ifstream* file);
|
||||||
LevelInstance * getLevel();
|
void drawMessage(RenderDevice*);
|
||||||
Instance* guiRoot;
|
WorkspaceInstance* getWorkspace();
|
||||||
std::string message;
|
WorkspaceInstance* workspace;
|
||||||
bool showMessage;
|
LevelInstance * level;
|
||||||
G3D::GFontRef font;
|
LevelInstance * getLevel();
|
||||||
Instance* getGuiRoot();
|
Instance* guiRoot;
|
||||||
float mousex;
|
std::string message;
|
||||||
float mousey;
|
std::string _loadedFileName;
|
||||||
Vector2 getMousePos();
|
bool showMessage;
|
||||||
void setMousePos(int x,int y);
|
G3D::GFontRef font;
|
||||||
void setMousePos(Vector2 pos);
|
Instance* getGuiRoot();
|
||||||
bool mouseButton1Down;
|
float mousex;
|
||||||
|
float mousey;
|
||||||
|
Vector2 getMousePos();
|
||||||
|
void setMousePos(int x,int y);
|
||||||
|
void setMousePos(Vector2 pos);
|
||||||
|
bool mouseButton1Down;
|
||||||
|
PartInstance* makePart();
|
||||||
|
void clearLevel();
|
||||||
|
#if _DEBUG
|
||||||
|
void modXMLLevel(float modY);
|
||||||
|
#endif
|
||||||
private:
|
private:
|
||||||
bool isBrickCount;
|
bool isBrickCount;
|
||||||
|
bool scanXMLObject(rapidxml::xml_node<>* node);
|
||||||
|
rapidxml::xml_node<>* getNode(rapidxml::xml_node<> * node,const char* name );
|
||||||
|
float getFloatValue(rapidxml::xml_node<> * node,const char* name);
|
||||||
|
bool _successfulLoad;
|
||||||
|
std::string _errMsg;
|
||||||
|
bool _legacyLoad;
|
||||||
|
float _modY;
|
||||||
};
|
};
|
||||||
|
|||||||
2
Enum.h
2
Enum.h
@@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
namespace Enum
|
namespace Enum
|
||||||
{
|
{
|
||||||
namespace SurfaceType
|
namespace SurfaceType
|
||||||
|
|||||||
2
Enums.h
2
Enums.h
@@ -7,7 +7,7 @@ static enum ActionType {Nothing, Pause, Lose, Draw, Win};
|
|||||||
static enum AffectType {NoChange, Increase, Decrease};
|
static enum AffectType {NoChange, Increase, Decrease};
|
||||||
static enum InputType {NoInput, LeftTread, RightTread, Steer, Throtle, UpDown, Action1, Action2, Action3, Action4, Action5, Constant, Sin};
|
static enum InputType {NoInput, LeftTread, RightTread, Steer, Throtle, UpDown, Action1, Action2, Action3, Action4, Action5, Constant, Sin};
|
||||||
//static enum SurfaceConstraint {None, Hinge, SteppingMotor, Motor};
|
//static enum SurfaceConstraint {None, Hinge, SteppingMotor, Motor};
|
||||||
static enum SurfaceType{Smooth, Snaps, Inlets, Glue, Weld, Hinge, Motor, Bumps};
|
static enum SurfaceType{Smooth, Snaps, Inlets, Glue, Weld, Spawn, Hinge, Motor, Bumps};
|
||||||
static enum SoundType {NoSound, Boing, Bomb, Break, Click, Clock, Slingshot, Page, Ping, Snap, Splat, Step, StepOn, Swoosh, Victory};
|
static enum SoundType {NoSound, Boing, Bomb, Break, Click, Clock, Slingshot, Page, Ping, Snap, Splat, Step, StepOn, Swoosh, Victory};
|
||||||
static enum PartType {Ball, Block, Cylinder};
|
static enum PartType {Ball, Block, Cylinder};
|
||||||
static enum KeywordFilterType {Include, Exclude};
|
static enum KeywordFilterType {Include, Exclude};
|
||||||
|
|||||||
@@ -258,6 +258,10 @@
|
|||||||
RelativePath=".\Globals.cpp"
|
RelativePath=".\Globals.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\GroupInstance.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\IEBrowser.cpp"
|
RelativePath=".\IEBrowser.cpp"
|
||||||
>
|
>
|
||||||
@@ -270,6 +274,10 @@
|
|||||||
RelativePath=".\IEDispatcher.cpp"
|
RelativePath=".\IEDispatcher.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\LevelInstance.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="main.cpp"
|
RelativePath="main.cpp"
|
||||||
>
|
>
|
||||||
@@ -290,6 +298,10 @@
|
|||||||
/>
|
/>
|
||||||
</FileConfiguration>
|
</FileConfiguration>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\PartInstance.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\propertyGrid.cpp"
|
RelativePath=".\propertyGrid.cpp"
|
||||||
>
|
>
|
||||||
@@ -298,6 +310,10 @@
|
|||||||
RelativePath=".\PropertyWindow.cpp"
|
RelativePath=".\PropertyWindow.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\PVInstance.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\WindowFunctions.cpp"
|
RelativePath=".\WindowFunctions.cpp"
|
||||||
>
|
>
|
||||||
@@ -313,10 +329,6 @@
|
|||||||
RelativePath=".\DataModelInstance.cpp"
|
RelativePath=".\DataModelInstance.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\GroupInstance.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\ImageButtonInstance.cpp"
|
RelativePath=".\ImageButtonInstance.cpp"
|
||||||
>
|
>
|
||||||
@@ -325,18 +337,6 @@
|
|||||||
RelativePath=".\Instance.cpp"
|
RelativePath=".\Instance.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\LevelInstance.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\PartInstance.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\PVInstance.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\TextButtonInstance.cpp"
|
RelativePath=".\TextButtonInstance.cpp"
|
||||||
>
|
>
|
||||||
@@ -387,10 +387,22 @@
|
|||||||
RelativePath=".\Globals.h"
|
RelativePath=".\Globals.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\GroupInstance.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\IEDispatcher.h"
|
RelativePath=".\IEDispatcher.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\LevelInstance.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\PartInstance.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\propertyGrid.h"
|
RelativePath=".\propertyGrid.h"
|
||||||
>
|
>
|
||||||
@@ -399,6 +411,26 @@
|
|||||||
RelativePath=".\PropertyWindow.h"
|
RelativePath=".\PropertyWindow.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\PVInstance.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\rapidxml\rapidxml.hpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\rapidxml\rapidxml_iterators.hpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\rapidxml\rapidxml_print.hpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\rapidxml\rapidxml_utils.hpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\resource.h"
|
RelativePath=".\resource.h"
|
||||||
>
|
>
|
||||||
@@ -422,10 +454,6 @@
|
|||||||
RelativePath=".\DataModelInstance.h"
|
RelativePath=".\DataModelInstance.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\GroupInstance.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\ImageButtonInstance.h"
|
RelativePath=".\ImageButtonInstance.h"
|
||||||
>
|
>
|
||||||
@@ -434,18 +462,6 @@
|
|||||||
RelativePath=".\Instance.h"
|
RelativePath=".\Instance.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\LevelInstance.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\PartInstance.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\PVInstance.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\TextButtonInstance.h"
|
RelativePath=".\TextButtonInstance.h"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -85,6 +85,11 @@ Instance::~Instance(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Instance::setName(std::string newName)
|
||||||
|
{
|
||||||
|
name = newName;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Instance::getClassName()
|
std::string Instance::getClassName()
|
||||||
{
|
{
|
||||||
return className;
|
return className;
|
||||||
@@ -134,6 +139,10 @@ void Instance::addChild(Instance* newChild)
|
|||||||
children.push_back(newChild);
|
children.push_back(newChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Instance::clearChildren()
|
||||||
|
{
|
||||||
|
children.clear();
|
||||||
|
}
|
||||||
void Instance::removeChild(Instance* oldChild)
|
void Instance::removeChild(Instance* oldChild)
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < children.size(); i++)
|
for(size_t i = 0; i < children.size(); i++)
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ public:
|
|||||||
std::vector<Instance* > getChildren();
|
std::vector<Instance* > getChildren();
|
||||||
std::vector<Instance* > getAllChildren();
|
std::vector<Instance* > getAllChildren();
|
||||||
void setParent(Instance*);
|
void setParent(Instance*);
|
||||||
|
void setName(std::string newName);
|
||||||
void addChild(Instance*);
|
void addChild(Instance*);
|
||||||
void removeChild(Instance*);
|
void removeChild(Instance*);
|
||||||
|
void clearChildren();
|
||||||
Instance* getParent();
|
Instance* getParent();
|
||||||
virtual Instance* clone() const { return new Instance(*this); }
|
virtual Instance* clone() const { return new Instance(*this); }
|
||||||
virtual std::vector<PROPGRIDITEM> getProperties();
|
virtual std::vector<PROPGRIDITEM> getProperties();
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0)
|
PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0)
|
||||||
{
|
{
|
||||||
PVInstance::PVInstance();
|
PVInstance::PVInstance();
|
||||||
name = "Unnamed PVItem";
|
glList = glGenLists(1);
|
||||||
|
name = "Unnamed PVItem";
|
||||||
className = "Part";
|
className = "Part";
|
||||||
canCollide = true;
|
canCollide = true;
|
||||||
anchored = true;
|
anchored = true;
|
||||||
@@ -59,6 +60,7 @@ void PartInstance::postRender(RenderDevice *rd)
|
|||||||
PartInstance::PartInstance(const PartInstance &oinst) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0)
|
PartInstance::PartInstance(const PartInstance &oinst) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0)
|
||||||
{
|
{
|
||||||
PVInstance::PVInstance(oinst);
|
PVInstance::PVInstance(oinst);
|
||||||
|
glList = glGenLists(1);
|
||||||
//name = oinst.name;
|
//name = oinst.name;
|
||||||
//className = "Part";
|
//className = "Part";
|
||||||
name = oinst.name;
|
name = oinst.name;
|
||||||
@@ -129,7 +131,7 @@ Vector3 PartInstance::getPosition()
|
|||||||
void PartInstance::setPosition(Vector3 pos)
|
void PartInstance::setPosition(Vector3 pos)
|
||||||
{
|
{
|
||||||
position = pos;
|
position = pos;
|
||||||
cFrame = CoordinateFrame(cFrame.rotation,pos);
|
cFrame = CoordinateFrame(pos);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
CoordinateFrame PartInstance::getCFrame()
|
CoordinateFrame PartInstance::getCFrame()
|
||||||
@@ -209,13 +211,22 @@ void PartInstance::addVertex(Vector3 vertexPos,Color3 color)
|
|||||||
_normals.push_back(normal.y);
|
_normals.push_back(normal.y);
|
||||||
_normals.push_back(normal.z);
|
_normals.push_back(normal.z);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
void PartInstance::addSingularNormal(Vector3 normal)
|
||||||
|
{
|
||||||
|
_normals.push_back(normal.x);
|
||||||
|
_normals.push_back(normal.y);
|
||||||
|
_normals.push_back(normal.z);
|
||||||
}
|
}
|
||||||
void PartInstance::addTriangle(Vector3 v1,Vector3 v2,Vector3 v3)
|
void PartInstance::addTriangle(Vector3 v1,Vector3 v2,Vector3 v3)
|
||||||
{
|
{
|
||||||
addVertex(v1,color);
|
addVertex(v1,color);
|
||||||
addVertex(v2,color);
|
addVertex(v2,color);
|
||||||
addVertex(v3,color);
|
addVertex(v3,color);
|
||||||
addNormals(cross(v2-v1,v3-v1).direction());
|
//addNormals(cross(v2-v1,v3-v1).direction());
|
||||||
|
addSingularNormal(cross(v2-v1,v3-v1).direction());
|
||||||
|
addSingularNormal(cross(v3-v2,v1-v2).direction());
|
||||||
|
addSingularNormal(cross(v1-v3,v2-v3).direction());
|
||||||
}
|
}
|
||||||
void PartInstance::debugPrintVertexIDs(RenderDevice* rd,GFontRef font,Matrix3 rot)
|
void PartInstance::debugPrintVertexIDs(RenderDevice* rd,GFontRef font,Matrix3 rot)
|
||||||
{
|
{
|
||||||
@@ -379,18 +390,21 @@ void PartInstance::render(RenderDevice* rd) {
|
|||||||
_indices.push_back(i);
|
_indices.push_back(i);
|
||||||
}
|
}
|
||||||
changed=false;
|
changed=false;
|
||||||
|
|
||||||
|
glNewList(glList, GL_COMPILE);
|
||||||
|
glVertexPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[0]);
|
||||||
|
glColorPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[3]);
|
||||||
|
glNormalPointer(GL_FLOAT,3 * sizeof(GLfloat), &_normals[0]);
|
||||||
|
glPushMatrix();
|
||||||
|
//glTranslatef(2,7,0);
|
||||||
|
glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]);
|
||||||
|
glPopMatrix();
|
||||||
|
glEndList();
|
||||||
}
|
}
|
||||||
//rd->setObjectToWorldMatrix(cFrame);
|
|
||||||
CoordinateFrame forDraw = rd->getObjectToWorldMatrix();
|
|
||||||
rd->setObjectToWorldMatrix(cFrame);
|
rd->setObjectToWorldMatrix(cFrame);
|
||||||
glVertexPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[0]);
|
glCallList(glList);
|
||||||
glColorPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[3]);
|
//rd->setObjectToWorldMatrix(cFrame);
|
||||||
glNormalPointer(GL_FLOAT,3 * sizeof(GLfloat), &_normals[0]);
|
|
||||||
glPushMatrix();
|
|
||||||
//glTranslatef(2,7,0);
|
|
||||||
glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]);
|
|
||||||
glPopMatrix();
|
|
||||||
rd->setObjectToWorldMatrix(forDraw);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void PartInstance::render(RenderDevice* rd)
|
void PartInstance::render(RenderDevice* rd)
|
||||||
@@ -471,6 +485,7 @@ void PartInstance::render(RenderDevice* rd)
|
|||||||
|
|
||||||
PartInstance::~PartInstance(void)
|
PartInstance::~PartInstance(void)
|
||||||
{
|
{
|
||||||
|
glDeleteLists(glList, 1);
|
||||||
}
|
}
|
||||||
char pto[512];
|
char pto[512];
|
||||||
char pto2[512];
|
char pto2[512];
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public:
|
|||||||
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
|
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
|
||||||
void addVertex(Vector3 vertexPos,Color3 color);
|
void addVertex(Vector3 vertexPos,Color3 color);
|
||||||
void addNormals(Vector3 normal);
|
void addNormals(Vector3 normal);
|
||||||
|
void addSingularNormal(Vector3 normal);
|
||||||
void addTriangle(Vector3 vertexPos,Vector3 vertexPos2, Vector3 vertexPos3);
|
void addTriangle(Vector3 vertexPos,Vector3 vertexPos2, Vector3 vertexPos3);
|
||||||
void debugPrintVertexIDs(RenderDevice* rd, GFontRef font, Matrix3 camRot);
|
void debugPrintVertexIDs(RenderDevice* rd, GFontRef font, Matrix3 camRot);
|
||||||
void makeFace(int vertex1, int vertex2, int vertex3);
|
void makeFace(int vertex1, int vertex2, int vertex3);
|
||||||
@@ -60,4 +61,5 @@ private:
|
|||||||
std::vector<GLushort> _indices;
|
std::vector<GLushort> _indices;
|
||||||
bool changed;
|
bool changed;
|
||||||
Box itemBox;
|
Box itemBox;
|
||||||
|
GLuint glList;
|
||||||
};
|
};
|
||||||
|
|||||||
27
main.cpp
27
main.cpp
@@ -724,7 +724,7 @@ void Demo::onInit() {
|
|||||||
|
|
||||||
initGUI();
|
initGUI();
|
||||||
|
|
||||||
|
#ifdef LEGACY_LOAD_G3DFUN_LEVEL
|
||||||
PartInstance* test = makePart();
|
PartInstance* test = makePart();
|
||||||
test->setParent(dataModel->getWorkspace());
|
test->setParent(dataModel->getWorkspace());
|
||||||
test->color = Color3(0.2F,0.3F,1);
|
test->color = Color3(0.2F,0.3F,1);
|
||||||
@@ -801,7 +801,9 @@ void Demo::onInit() {
|
|||||||
test->color = Color3::gray();
|
test->color = Color3::gray();
|
||||||
test->setSize(Vector3(4,1,2));
|
test->setSize(Vector3(4,1,2));
|
||||||
test->setPosition(Vector3(2,7,0));
|
test->setPosition(Vector3(2,7,0));
|
||||||
|
#else
|
||||||
|
dataModel->debugGetOpen();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1195,7 +1197,9 @@ void Demo::onGraphics(RenderDevice* rd) {
|
|||||||
renderDevice->setAmbientLightColor(lighting.ambient);
|
renderDevice->setAmbientLightColor(lighting.ambient);
|
||||||
|
|
||||||
rd->beforePrimitive();
|
rd->beforePrimitive();
|
||||||
|
CoordinateFrame forDraw = rd->getObjectToWorldMatrix();
|
||||||
dataModel->getWorkspace()->render(rd);
|
dataModel->getWorkspace()->render(rd);
|
||||||
|
rd->setObjectToWorldMatrix(forDraw);
|
||||||
rd->afterPrimitive();
|
rd->afterPrimitive();
|
||||||
|
|
||||||
if(g_selectedInstances.size() > 0)
|
if(g_selectedInstances.size() > 0)
|
||||||
@@ -1206,7 +1210,7 @@ void Demo::onGraphics(RenderDevice* rd) {
|
|||||||
{
|
{
|
||||||
Vector3 size = part->getSize();
|
Vector3 size = part->getSize();
|
||||||
Vector3 pos = part->getPosition();
|
Vector3 pos = part->getPosition();
|
||||||
drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased());
|
drawOutline(Vector3(0+size.x/2, 0+size.y/2, 0+size.z/2) ,Vector3(0-size.x/2,0-size.y/2,0-size.z/2), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1310,6 +1314,23 @@ void Demo::onKeyPressed(int key)
|
|||||||
{
|
{
|
||||||
deleteInstance();
|
deleteInstance();
|
||||||
}
|
}
|
||||||
|
if (GetHoldKeyState(VK_RCONTROL))
|
||||||
|
{
|
||||||
|
if (key=='O')
|
||||||
|
{
|
||||||
|
dataModel->getOpen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef _DEBUG
|
||||||
|
if (key==VK_ADD)
|
||||||
|
{
|
||||||
|
dataModel->modXMLLevel(1);
|
||||||
|
}
|
||||||
|
if (key==VK_SUBTRACT)
|
||||||
|
{
|
||||||
|
dataModel->modXMLLevel(-1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
void Demo::onKeyUp(int key)
|
void Demo::onKeyUp(int key)
|
||||||
{
|
{
|
||||||
|
|||||||
52
rapidxml/license.txt
Normal file
52
rapidxml/license.txt
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
Use of this software is granted under one of the following two licenses,
|
||||||
|
to be chosen freely by the user.
|
||||||
|
|
||||||
|
1. Boost Software License - Version 1.0 - August 17th, 2003
|
||||||
|
===============================================================================
|
||||||
|
|
||||||
|
Copyright (c) 2006, 2007 Marcin Kalicinski
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
2. The MIT License
|
||||||
|
===============================================================================
|
||||||
|
|
||||||
|
Copyright (c) 2006, 2007 Marcin Kalicinski
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
IN THE SOFTWARE.
|
||||||
406
rapidxml/manual.html
Normal file
406
rapidxml/manual.html
Normal file
File diff suppressed because one or more lines are too long
2596
rapidxml/rapidxml.hpp
Normal file
2596
rapidxml/rapidxml.hpp
Normal file
File diff suppressed because it is too large
Load Diff
174
rapidxml/rapidxml_iterators.hpp
Normal file
174
rapidxml/rapidxml_iterators.hpp
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
#ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
|
||||||
|
#define RAPIDXML_ITERATORS_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||||
|
// Version 1.13
|
||||||
|
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||||
|
//! \file rapidxml_iterators.hpp This file contains rapidxml iterators
|
||||||
|
|
||||||
|
#include "rapidxml.hpp"
|
||||||
|
|
||||||
|
namespace rapidxml
|
||||||
|
{
|
||||||
|
|
||||||
|
//! Iterator of child nodes of xml_node
|
||||||
|
template<class Ch>
|
||||||
|
class node_iterator
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef typename xml_node<Ch> value_type;
|
||||||
|
typedef typename xml_node<Ch> &reference;
|
||||||
|
typedef typename xml_node<Ch> *pointer;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
|
||||||
|
node_iterator()
|
||||||
|
: m_node(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator(xml_node<Ch> *node)
|
||||||
|
: m_node(node->first_node())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
reference operator *() const
|
||||||
|
{
|
||||||
|
assert(m_node);
|
||||||
|
return *m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer operator->() const
|
||||||
|
{
|
||||||
|
assert(m_node);
|
||||||
|
return m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator& operator++()
|
||||||
|
{
|
||||||
|
assert(m_node);
|
||||||
|
m_node = m_node->next_sibling();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator operator++(int)
|
||||||
|
{
|
||||||
|
node_iterator tmp = *this;
|
||||||
|
++this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator& operator--()
|
||||||
|
{
|
||||||
|
assert(m_node && m_node->previous_sibling());
|
||||||
|
m_node = m_node->previous_sibling();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
node_iterator operator--(int)
|
||||||
|
{
|
||||||
|
node_iterator tmp = *this;
|
||||||
|
++this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator ==(const node_iterator<Ch> &rhs)
|
||||||
|
{
|
||||||
|
return m_node == rhs.m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator !=(const node_iterator<Ch> &rhs)
|
||||||
|
{
|
||||||
|
return m_node != rhs.m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
xml_node<Ch> *m_node;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Iterator of child attributes of xml_node
|
||||||
|
template<class Ch>
|
||||||
|
class attribute_iterator
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef typename xml_attribute<Ch> value_type;
|
||||||
|
typedef typename xml_attribute<Ch> &reference;
|
||||||
|
typedef typename xml_attribute<Ch> *pointer;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
|
||||||
|
attribute_iterator()
|
||||||
|
: m_attribute(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator(xml_node<Ch> *node)
|
||||||
|
: m_attribute(node->first_attribute())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
reference operator *() const
|
||||||
|
{
|
||||||
|
assert(m_attribute);
|
||||||
|
return *m_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer operator->() const
|
||||||
|
{
|
||||||
|
assert(m_attribute);
|
||||||
|
return m_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator& operator++()
|
||||||
|
{
|
||||||
|
assert(m_attribute);
|
||||||
|
m_attribute = m_attribute->next_attribute();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator operator++(int)
|
||||||
|
{
|
||||||
|
attribute_iterator tmp = *this;
|
||||||
|
++this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator& operator--()
|
||||||
|
{
|
||||||
|
assert(m_attribute && m_attribute->previous_attribute());
|
||||||
|
m_attribute = m_attribute->previous_attribute();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_iterator operator--(int)
|
||||||
|
{
|
||||||
|
attribute_iterator tmp = *this;
|
||||||
|
++this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator ==(const attribute_iterator<Ch> &rhs)
|
||||||
|
{
|
||||||
|
return m_attribute == rhs.m_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator !=(const attribute_iterator<Ch> &rhs)
|
||||||
|
{
|
||||||
|
return m_attribute != rhs.m_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
xml_attribute<Ch> *m_attribute;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
421
rapidxml/rapidxml_print.hpp
Normal file
421
rapidxml/rapidxml_print.hpp
Normal file
@@ -0,0 +1,421 @@
|
|||||||
|
#ifndef RAPIDXML_PRINT_HPP_INCLUDED
|
||||||
|
#define RAPIDXML_PRINT_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||||
|
// Version 1.13
|
||||||
|
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||||
|
//! \file rapidxml_print.hpp This file contains rapidxml printer implementation
|
||||||
|
|
||||||
|
#include "rapidxml.hpp"
|
||||||
|
|
||||||
|
// Only include streams if not disabled
|
||||||
|
#ifndef RAPIDXML_NO_STREAMS
|
||||||
|
#include <ostream>
|
||||||
|
#include <iterator>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace rapidxml
|
||||||
|
{
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// Printing flags
|
||||||
|
|
||||||
|
const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function.
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// Internal
|
||||||
|
|
||||||
|
//! \cond internal
|
||||||
|
namespace internal
|
||||||
|
{
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Internal character operations
|
||||||
|
|
||||||
|
// Copy characters from given range to given output iterator
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out)
|
||||||
|
{
|
||||||
|
while (begin != end)
|
||||||
|
*out++ = *begin++;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy characters from given range to given output iterator and expand
|
||||||
|
// characters into references (< > ' " &)
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand, OutIt out)
|
||||||
|
{
|
||||||
|
while (begin != end)
|
||||||
|
{
|
||||||
|
if (*begin == noexpand)
|
||||||
|
{
|
||||||
|
*out++ = *begin; // No expansion, copy character
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (*begin)
|
||||||
|
{
|
||||||
|
case Ch('<'):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('l'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
case Ch('>'):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('g'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
case Ch('\''):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('p'); *out++ = Ch('o'); *out++ = Ch('s'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
case Ch('"'):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('q'); *out++ = Ch('u'); *out++ = Ch('o'); *out++ = Ch('t'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
case Ch('&'):
|
||||||
|
*out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('m'); *out++ = Ch('p'); *out++ = Ch(';');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*out++ = *begin; // No expansion, copy character
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++begin; // Step to next character
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill given output iterator with repetitions of the same character
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt fill_chars(OutIt out, int n, Ch ch)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
*out++ = ch;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find character
|
||||||
|
template<class Ch, Ch ch>
|
||||||
|
inline bool find_char(const Ch *begin, const Ch *end)
|
||||||
|
{
|
||||||
|
while (begin != end)
|
||||||
|
if (*begin++ == ch)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Internal printing operations
|
||||||
|
|
||||||
|
// Print node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
// Print proper node type
|
||||||
|
switch (node->type())
|
||||||
|
{
|
||||||
|
|
||||||
|
// Document
|
||||||
|
case node_document:
|
||||||
|
out = print_children(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Element
|
||||||
|
case node_element:
|
||||||
|
out = print_element_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Data
|
||||||
|
case node_data:
|
||||||
|
out = print_data_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// CDATA
|
||||||
|
case node_cdata:
|
||||||
|
out = print_cdata_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Declaration
|
||||||
|
case node_declaration:
|
||||||
|
out = print_declaration_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Comment
|
||||||
|
case node_comment:
|
||||||
|
out = print_comment_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Doctype
|
||||||
|
case node_doctype:
|
||||||
|
out = print_doctype_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Pi
|
||||||
|
case node_pi:
|
||||||
|
out = print_pi_node(out, node, flags, indent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Unknown
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If indenting not disabled, add line break after node
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
*out = Ch('\n'), ++out;
|
||||||
|
|
||||||
|
// Return modified iterator
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print children of the node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
for (xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling())
|
||||||
|
out = print_node(out, child, flags, indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print attributes of the node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags)
|
||||||
|
{
|
||||||
|
for (xml_attribute<Ch> *attribute = node->first_attribute(); attribute; attribute = attribute->next_attribute())
|
||||||
|
{
|
||||||
|
if (attribute->name() && attribute->value())
|
||||||
|
{
|
||||||
|
// Print attribute name
|
||||||
|
*out = Ch(' '), ++out;
|
||||||
|
out = copy_chars(attribute->name(), attribute->name() + attribute->name_size(), out);
|
||||||
|
*out = Ch('='), ++out;
|
||||||
|
// Print attribute value using appropriate quote type
|
||||||
|
if (find_char<Ch, Ch('"')>(attribute->value(), attribute->value() + attribute->value_size()))
|
||||||
|
{
|
||||||
|
*out = Ch('\''), ++out;
|
||||||
|
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('"'), out);
|
||||||
|
*out = Ch('\''), ++out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*out = Ch('"'), ++out;
|
||||||
|
out = copy_and_expand_chars(attribute->value(), attribute->value() + attribute->value_size(), Ch('\''), out);
|
||||||
|
*out = Ch('"'), ++out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print data node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_data);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print data node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_cdata);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'); ++out;
|
||||||
|
*out = Ch('!'); ++out;
|
||||||
|
*out = Ch('['); ++out;
|
||||||
|
*out = Ch('C'); ++out;
|
||||||
|
*out = Ch('D'); ++out;
|
||||||
|
*out = Ch('A'); ++out;
|
||||||
|
*out = Ch('T'); ++out;
|
||||||
|
*out = Ch('A'); ++out;
|
||||||
|
*out = Ch('['); ++out;
|
||||||
|
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||||
|
*out = Ch(']'); ++out;
|
||||||
|
*out = Ch(']'); ++out;
|
||||||
|
*out = Ch('>'); ++out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print element node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_element);
|
||||||
|
|
||||||
|
// Print element name and attributes, if any
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||||
|
out = print_attributes(out, node, flags);
|
||||||
|
|
||||||
|
// If node is childless
|
||||||
|
if (node->value_size() == 0 && !node->first_node())
|
||||||
|
{
|
||||||
|
// Print childless node tag ending
|
||||||
|
*out = Ch('/'), ++out;
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Print normal node tag ending
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
|
||||||
|
// Test if node contains a single data node only (and no other nodes)
|
||||||
|
xml_node<Ch> *child = node->first_node();
|
||||||
|
if (!child)
|
||||||
|
{
|
||||||
|
// If node has no children, only print its value without indenting
|
||||||
|
out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
|
||||||
|
}
|
||||||
|
else if (child->next_sibling() == 0 && child->type() == node_data)
|
||||||
|
{
|
||||||
|
// If node has a sole data child, only print its value without indenting
|
||||||
|
out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Print all children with full indenting
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
*out = Ch('\n'), ++out;
|
||||||
|
out = print_children(out, node, flags, indent + 1);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print node end
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('/'), ++out;
|
||||||
|
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print declaration node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
// Print declaration start
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('?'), ++out;
|
||||||
|
*out = Ch('x'), ++out;
|
||||||
|
*out = Ch('m'), ++out;
|
||||||
|
*out = Ch('l'), ++out;
|
||||||
|
|
||||||
|
// Print attributes
|
||||||
|
out = print_attributes(out, node, flags);
|
||||||
|
|
||||||
|
// Print declaration end
|
||||||
|
*out = Ch('?'), ++out;
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print comment node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_comment);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('!'), ++out;
|
||||||
|
*out = Ch('-'), ++out;
|
||||||
|
*out = Ch('-'), ++out;
|
||||||
|
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||||
|
*out = Ch('-'), ++out;
|
||||||
|
*out = Ch('-'), ++out;
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print doctype node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_doctype);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('!'), ++out;
|
||||||
|
*out = Ch('D'), ++out;
|
||||||
|
*out = Ch('O'), ++out;
|
||||||
|
*out = Ch('C'), ++out;
|
||||||
|
*out = Ch('T'), ++out;
|
||||||
|
*out = Ch('Y'), ++out;
|
||||||
|
*out = Ch('P'), ++out;
|
||||||
|
*out = Ch('E'), ++out;
|
||||||
|
*out = Ch(' '), ++out;
|
||||||
|
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print pi node
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
|
||||||
|
{
|
||||||
|
assert(node->type() == node_pi);
|
||||||
|
if (!(flags & print_no_indenting))
|
||||||
|
out = fill_chars(out, indent, Ch('\t'));
|
||||||
|
*out = Ch('<'), ++out;
|
||||||
|
*out = Ch('?'), ++out;
|
||||||
|
out = copy_chars(node->name(), node->name() + node->name_size(), out);
|
||||||
|
*out = Ch(' '), ++out;
|
||||||
|
out = copy_chars(node->value(), node->value() + node->value_size(), out);
|
||||||
|
*out = Ch('?'), ++out;
|
||||||
|
*out = Ch('>'), ++out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//! \endcond
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Printing
|
||||||
|
|
||||||
|
//! Prints XML to given output iterator.
|
||||||
|
//! \param out Output iterator to print to.
|
||||||
|
//! \param node Node to be printed. Pass xml_document to print entire document.
|
||||||
|
//! \param flags Flags controlling how XML is printed.
|
||||||
|
//! \return Output iterator pointing to position immediately after last character of printed text.
|
||||||
|
template<class OutIt, class Ch>
|
||||||
|
inline OutIt print(OutIt out, const xml_node<Ch> &node, int flags = 0)
|
||||||
|
{
|
||||||
|
return internal::print_node(out, &node, flags, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef RAPIDXML_NO_STREAMS
|
||||||
|
|
||||||
|
//! Prints XML to given output stream.
|
||||||
|
//! \param out Output stream to print to.
|
||||||
|
//! \param node Node to be printed. Pass xml_document to print entire document.
|
||||||
|
//! \param flags Flags controlling how XML is printed.
|
||||||
|
//! \return Output stream.
|
||||||
|
template<class Ch>
|
||||||
|
inline std::basic_ostream<Ch> &print(std::basic_ostream<Ch> &out, const xml_node<Ch> &node, int flags = 0)
|
||||||
|
{
|
||||||
|
print(std::ostream_iterator<Ch>(out), node, flags);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Prints formatted XML to given output stream. Uses default printing flags. Use print() function to customize printing process.
|
||||||
|
//! \param out Output stream to print to.
|
||||||
|
//! \param node Node to be printed.
|
||||||
|
//! \return Output stream.
|
||||||
|
template<class Ch>
|
||||||
|
inline std::basic_ostream<Ch> &operator <<(std::basic_ostream<Ch> &out, const xml_node<Ch> &node)
|
||||||
|
{
|
||||||
|
return print(out, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
122
rapidxml/rapidxml_utils.hpp
Normal file
122
rapidxml/rapidxml_utils.hpp
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
#ifndef RAPIDXML_UTILS_HPP_INCLUDED
|
||||||
|
#define RAPIDXML_UTILS_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||||
|
// Version 1.13
|
||||||
|
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||||
|
//! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful
|
||||||
|
//! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective.
|
||||||
|
|
||||||
|
#include "rapidxml.hpp"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace rapidxml
|
||||||
|
{
|
||||||
|
|
||||||
|
//! Represents data loaded from a file
|
||||||
|
template<class Ch = char>
|
||||||
|
class file
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Loads file into the memory. Data will be automatically destroyed by the destructor.
|
||||||
|
//! \param filename Filename to load.
|
||||||
|
file(const char *filename)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// Open stream
|
||||||
|
basic_ifstream<Ch> stream(filename, ios::binary);
|
||||||
|
if (!stream)
|
||||||
|
throw runtime_error(string("cannot open file ") + filename);
|
||||||
|
stream.unsetf(ios::skipws);
|
||||||
|
|
||||||
|
// Determine stream size
|
||||||
|
stream.seekg(0, ios::end);
|
||||||
|
size_t size = stream.tellg();
|
||||||
|
stream.seekg(0);
|
||||||
|
|
||||||
|
// Load data and add terminating 0
|
||||||
|
m_data.resize(size + 1);
|
||||||
|
stream.read(&m_data.front(), static_cast<streamsize>(size));
|
||||||
|
m_data[size] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Loads file into the memory. Data will be automatically destroyed by the destructor
|
||||||
|
//! \param stream Stream to load from
|
||||||
|
file(std::basic_istream<Ch> &stream)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// Load data and add terminating 0
|
||||||
|
stream.unsetf(ios::skipws);
|
||||||
|
m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
|
||||||
|
if (stream.fail() || stream.bad())
|
||||||
|
throw runtime_error("error reading stream");
|
||||||
|
m_data.push_back(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Gets file data.
|
||||||
|
//! \return Pointer to data of file.
|
||||||
|
Ch *data()
|
||||||
|
{
|
||||||
|
return &m_data.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Gets file data.
|
||||||
|
//! \return Pointer to data of file.
|
||||||
|
const Ch *data() const
|
||||||
|
{
|
||||||
|
return &m_data.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Gets file data size.
|
||||||
|
//! \return Size of file data, in characters.
|
||||||
|
std::size_t size() const
|
||||||
|
{
|
||||||
|
return m_data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector<Ch> m_data; // File data
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Counts children of node. Time complexity is O(n).
|
||||||
|
//! \return Number of children of node
|
||||||
|
template<class Ch>
|
||||||
|
inline std::size_t count_children(xml_node<Ch> *node)
|
||||||
|
{
|
||||||
|
xml_node<Ch> *child = node->first_node();
|
||||||
|
std::size_t count = 0;
|
||||||
|
while (child)
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
child = child->next_sibling();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Counts attributes of node. Time complexity is O(n).
|
||||||
|
//! \return Number of attributes of node
|
||||||
|
template<class Ch>
|
||||||
|
inline std::size_t count_attributes(xml_node<Ch> *node)
|
||||||
|
{
|
||||||
|
xml_attribute<Ch> *attr = node->first_attribute();
|
||||||
|
std::size_t count = 0;
|
||||||
|
while (attr)
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
attr = attr->next_attribute();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user