#include "Visitor.h" #include "Log.h" #include "Scene.h" #include "Primitives.h" #include "MediaPlayer.h" #include "GstToolkit.h" #include #include #include #include #include #define GLM_ENABLE_EXPERIMENTAL #include #include #include using namespace tinyxml2; #ifndef XMLCheckResult #define XMLCheckResult(a_eResult) if (a_eResult != XML_SUCCESS) { Log::Warning("XML error %i\n", a_eResult); return; } #endif SessionVisitor::SessionVisitor(std::string filename) : filename_(filename) { xmlDoc_ = new XMLDocument; xmlCurrent_ = nullptr; } void SessionVisitor::visit(Group &n) { std::cerr << "Group" << std::endl; XMLElement *xmlParent = xmlCurrent_; xmlCurrent_ = xmlDoc_->NewElement("Group"); visit( (Node&) n); for (int node = 0; node < n.numChildren(); ++node) { Node *child = n.getChild(node); Group *g = dynamic_cast(child); if (g != nullptr) { g->accept(*this); continue; } TexturedRectangle *tr = dynamic_cast(child); if (tr != nullptr) { tr->accept(*this); continue; } MediaRectangle *mr = dynamic_cast(child); if (mr != nullptr) { mr->accept(*this); continue; } LineStrip *ls = dynamic_cast(child); if (ls != nullptr) { ls->accept(*this); continue; } Primitive *p = dynamic_cast(child); if (p != nullptr) { p->accept(*this); continue; } } // recursive xmlParent->InsertEndChild(xmlCurrent_); xmlCurrent_ = xmlParent; } void SessionVisitor::visit(Node &n) { XMLElement *transform = xmlDoc_->NewElement("Transform"); XMLText *matrix = xmlDoc_->NewText( glm::to_string(n.transform_).c_str() ); transform->InsertEndChild(matrix); xmlCurrent_->InsertEndChild(transform); } void SessionVisitor::visit(Primitive &n) { std::cerr << "Primitive" << std::endl; visit( (Node&) n); } void SessionVisitor::visit(TexturedRectangle &n) { std::cerr << "TexturedRectangle" << std::endl; } void SessionVisitor::visit(MediaRectangle &n) { std::cerr << "MediaRectangle" << std::endl; // type specific XMLElement *xmlParent = xmlCurrent_; xmlCurrent_ = xmlDoc_->NewElement("MediaRectangle"); xmlCurrent_->SetAttribute("Filename", n.getMediaPath().c_str() ); // inherited from Primitive visit( (Primitive&) n); // recursive xmlParent->InsertEndChild(xmlCurrent_); xmlCurrent_ = xmlParent; } void SessionVisitor::visit(LineStrip &n) { std::cerr << "LineStrip" << std::endl; } void SessionVisitor::visit(Scene &n) { std::cerr << "root" << std::endl; XMLDeclaration *pDec = xmlDoc_->NewDeclaration(); xmlDoc_->InsertFirstChild(pDec); XMLElement *pRoot = xmlDoc_->NewElement("Session"); xmlDoc_->InsertEndChild(pRoot); std::string s = "Saved on " + GstToolkit::date_time_string(); XMLComment *pComment = xmlDoc_->NewComment(s.c_str()); pRoot->InsertEndChild(pComment); // save scene xmlCurrent_ = pRoot; n.getRoot()->accept(*this); XMLError eResult = xmlDoc_->SaveFile(filename_.c_str()); XMLCheckResult(eResult); }