void TreeModel::InitModel() { wxStringTokenizer tkz(DisplayAs, " "); wxString token = tkz.GetNextToken(); int firstStrand = 0; if (zeroBased && ModelXml->GetAttribute("exportFirstStrand") != "") { firstStrand = wxAtoi(ModelXml->GetAttribute("exportFirstStrand")) - 1; } if (firstStrand < 0) { firstStrand = 0; } InitVMatrix(firstStrand); token = tkz.GetNextToken(); token.ToLong(°rees); treeType = 0; if (token == "Flat") { treeType = 1; degrees = 0; } else if (token == "Ribbon") { treeType = 2; degrees = -1; } rotation = wxAtof(ModelXml->GetAttribute("TreeRotation", "3")); spiralRotations = wxAtof(ModelXml->GetAttribute("TreeSpiralRotations", "0.0")); botTopRatio = wxAtof(ModelXml->GetAttribute("TreeBottomTopRatio", "6.0")); perspective = wxAtof(ModelXml->GetAttribute("TreePerspective", "0.2")); SetTreeCoord(degrees); DisplayAs = "Tree"; }
void ModelClass::SetFromXml(wxXmlNode* ModelNode, bool zeroBased) { wxString tempstr,channelstr; wxString customModel,RGBorder; long degrees, StartChannel, channel; size_t i; ModelXml=ModelNode; TreeDegrees=0; StrobeRate=0; Nodes.clear(); name=ModelNode->GetAttribute("name"); DisplayAs=ModelNode->GetAttribute("DisplayAs"); if (ModelNode->HasAttribute("StringType")) { // post 3.1.4 StringType=ModelNode->GetAttribute("StringType"); } else { // 3.1.4 and earlier StringType=ModelNode->GetAttribute("Order","RGB")+" Nodes"; } SingleNode=HasSingleNode(StringType); SingleChannel=HasSingleChannel(StringType); RGBorder=SingleNode ? "RGB" : RGBorder=StringType.Left(3); rgbidx[0]=std::max(RGBorder.Find('R'),0); rgbidx[1]=std::max(RGBorder.Find('G'),0); rgbidx[2]=std::max(RGBorder.Find('B'),0); tempstr=ModelNode->GetAttribute("parm1"); tempstr.ToLong(&parm1); tempstr=ModelNode->GetAttribute("parm2"); tempstr.ToLong(&parm2); tempstr=ModelNode->GetAttribute("parm3"); tempstr.ToLong(&parm3); tempstr=ModelNode->GetAttribute("StartChannel","1"); tempstr.ToLong(&StartChannel); tempstr=ModelNode->GetAttribute("Dir"); IsLtoR=tempstr != "R"; if (ModelNode->HasAttribute("StartSide")) { tempstr=ModelNode->GetAttribute("StartSide"); isBotToTop = (tempstr == "B"); } else { isBotToTop=true; } tempstr=ModelNode->GetAttribute("Antialias","0"); tempstr.ToLong(&Antialias); AliasFactor=1 << Antialias; MyDisplay=IsMyDisplay(ModelNode); tempstr=ModelNode->GetAttribute("offsetXpct","0"); tempstr.ToDouble(&offsetXpct); tempstr=ModelNode->GetAttribute("offsetYpct","0"); tempstr.ToDouble(&offsetYpct); tempstr=ModelNode->GetAttribute("PreviewScale","0.333"); tempstr.ToDouble(&PreviewScale); tempstr=ModelNode->GetAttribute("PreviewRotation","0"); tempstr.ToLong(°rees); PreviewRotation=degrees; // calculate starting channel numbers for each string size_t NumberOfStrings= HasOneString(DisplayAs) ? 1 : parm1; int ChannelsPerString=parm2*3; if (SingleChannel) ChannelsPerString=1; else if (SingleNode) ChannelsPerString=3; if (ModelNode->HasAttribute("CustomModel")) { customModel = ModelNode->GetAttribute("CustomModel"); int maxval=GetCustomMaxChannel(customModel); // fix NumberOfStrings if (SingleNode) { NumberOfStrings=maxval; } else { ChannelsPerString=maxval*3; } } tempstr=ModelNode->GetAttribute("Advanced","0"); bool HasIndividualStartChans=tempstr == "1"; stringStartChan.clear(); stringStartChan.resize(NumberOfStrings); for (i=0; i<NumberOfStrings; i++) { tempstr=StartChanAttrName(i); if (!zeroBased && HasIndividualStartChans && ModelNode->HasAttribute(tempstr)) { ModelNode->GetAttribute(tempstr, &channelstr); channelstr.ToLong(&channel); stringStartChan[i] = channel-1; } else { stringStartChan[i] = (zeroBased? 0 : StartChannel-1) + i*ChannelsPerString; } } // initialize model based on the DisplayAs value wxStringTokenizer tkz(DisplayAs, " "); wxString token = tkz.GetNextToken(); if (token == "Tree") { InitVMatrix(); token = tkz.GetNextToken(); token.ToLong(°rees); SetTreeCoord(degrees); } else if (DisplayAs == "Custom") { InitCustomMatrix(customModel); CopyBufCoord2ScreenCoord(); } else if (DisplayAs == "Vert Matrix") { InitVMatrix(); CopyBufCoord2ScreenCoord(); } else if (DisplayAs == "Horiz Matrix") { InitHMatrix(); CopyBufCoord2ScreenCoord(); } else if (DisplayAs == "Single Line") { InitLine(); SetLineCoord(); } else if (DisplayAs == "Arches") { InitHMatrix(); // Old call was InitLine(); SetArchCoord(); } else if (DisplayAs == "Window Frame") { InitFrame(); CopyBufCoord2ScreenCoord(); } else if (DisplayAs == "Star") { InitStar(); CopyBufCoord2ScreenCoord(); } else if (DisplayAs == "Wreath") { InitWreath(); CopyBufCoord2ScreenCoord(); } size_t NodeCount=GetNodeCount(); for(size_t i=0; i<NodeCount; i++) { Nodes[i]->sparkle = rand() % 10000; } }