diff --git a/StoryPresent/StoryPresent.vcxproj.user b/StoryPresent/StoryPresent.vcxproj.user index 655e87c..104e794 100644 --- a/StoryPresent/StoryPresent.vcxproj.user +++ b/StoryPresent/StoryPresent.vcxproj.user @@ -1,7 +1,7 @@  - --test + --graph dag --path E:/storyline.xast WindowsLocalDebugger diff --git a/StoryPresent/dag_layout.cpp b/StoryPresent/dag_layout.cpp index f156de0..8d048b5 100644 --- a/StoryPresent/dag_layout.cpp +++ b/StoryPresent/dag_layout.cpp @@ -227,6 +227,7 @@ QList> DAGGraph::tidy_graph_nodes() { return temp_array; } +#include void DAGGraph::graph_layer_nodes_sort(int layer_index, QList> nodes) { QList> nodes_within_current_layer; for (auto n : nodes) @@ -253,18 +254,27 @@ void DAGGraph::graph_layer_nodes_sort(int layer_index, QListsetSortNumber(target_sum / prev_sorts.size()); + if (!target_node->isFakeNode() && std::shared_ptr(target_node)->layerNode()->bindPoint().name().contains(u8"Сʦ½ãÅÑÌÓ")) { + qDebug() << ""; + } } } - // µ±Ç°²ã´Î½ÚµãÅÅÐòÖµÐÞÕý - std::sort(nodes_within_current_layer.begin(), nodes_within_current_layer.end(), - [](std::shared_ptr a, std::shared_ptr b){ return a->sortNumber() < b->sortNumber(); }); + // ÌáÈ¡µ±Ç°²ã´Î½ÚµãÅÅÐòÖµ + QList sort_values; + std::transform(nodes_within_current_layer.begin(), nodes_within_current_layer.end(), + std::back_inserter(sort_values), [](std::shared_ptr n) { return n->sortNumber(); }); + sort_values = sort_values.toSet().toList(); - for (auto idx = 1; idx < nodes_within_current_layer.size(); ++idx) { - auto prev = nodes_within_current_layer[idx - 1]; - auto curr = nodes_within_current_layer[idx]; - if (prev->sortNumber() == curr->sortNumber()) - curr->setSortNumber(curr->sortNumber() + 0.000000000000001); + for (auto& sort_v : sort_values) { + decltype(nodes_within_current_layer) pick_items; + std::copy_if(nodes_within_current_layer.begin(), nodes_within_current_layer.end(), + std::back_inserter(pick_items), [=](std::shared_ptr ins) { return ins->sortNumber() == sort_v; }); + + for (int idx = 0; idx < pick_items.size(); ++idx) { + auto item = pick_items[idx]; + item->setSortNumber(item->sortNumber() + 0.000000001 * idx); + } } } diff --git a/StoryPresent/main.cpp b/StoryPresent/main.cpp index 6d9ac08..80b2b0b 100644 --- a/StoryPresent/main.cpp +++ b/StoryPresent/main.cpp @@ -4,6 +4,7 @@ #include "dag_present.h" #include "cmp_present.h" #include +#include "storypresent.h" #include #include #include @@ -24,7 +25,13 @@ int main(int argc, char* argv[]) { auto test_mode = std::make_shared(0x000bu, u8"¿ª·¢¹ý³ÌÄÚ²¿²âÊÔ"); cmdrec << test_mode; - (*test_mode) << std::make_shared(u8"StoryPresent", u8"³ÌÐòÃû") << make_shared(u8"test", u8"´òÓ¡°ïÖúÎĵµ"); + (*test_mode) << std::make_shared(u8"StoryPresent", u8"³ÌÐòÃû") << make_shared(u8"test", u8"ÄÚ²¿¿ª·¢²âÊÔÑ¡Ïî"); + + auto graph_mode = std::make_shared(0x000cu, u8"ͼÐλ¯Õ¹Ê¾¹ÊÊÂÄÚÈÝ"); + cmdrec << graph_mode; + (*graph_mode) << std::make_shared(u8"StoryPresent", u8"³ÌÐòÃû") + << make_shared(u8"graph", u8"ÄÚ²¿¿ª·¢²âÊÔÑ¡ÏÌîдdag»òudg") + << make_shared(u8"path", u8"Ö¸¶¨xastÎļþ·¾¶"); auto rst = cmdrec.parse(argc, argv); QTextEdit msg; @@ -44,26 +51,16 @@ int main(int argc, char* argv[]) { case 0x000bu: { - auto arrows = QList() << - graph_data::Arrow(u8"aÖÐÎIJâÊÔ", u8"bÖÐÎIJâÊÔ") << - graph_data::Arrow(u8"cÖÐÎIJâÊÔ", u8"bÖÐÎIJâÊÔ") << - graph_data::Arrow(u8"cÖÐÎIJâÊÔ", u8"dÖÐÎIJâÊÔ") << - graph_data::Arrow(u8"bÖÐÎIJâÊÔ", u8"eÖÐÎIJâÊÔ") << - graph_data::Arrow(u8"dÖÐÎIJâÊÔ", u8"eÖÐÎIJâÊÔ") << - graph_data::Arrow(u8"cÖÐÎIJâÊÔ", u8"eÖÐÎIJâÊÔ"); - auto view = new dags::DAGActiveView; - view->updateWithEdges(arrows); - view->show(); - - //dags::DAGGraph tools; - //tools.rebuildFromEdges(arrows); - //tools.graphLayout(); - - //for (auto n : tools.nodeWithLayout()) { - // msg.setWindowTitle("layout-message"); - // msg.append(QString("node:%3,layer:%1,sort:%2").arg(n->layerNumber()).arg(n->sortNumber()).arg(n->layerNode()->bindPoint().name())); - // msg.show(); - //} + }break; + case 0x000cu: + { + auto type = rst->getUnitViaKey(u8"graph"); + auto path = rst->getUnitViaKey(u8"path"); + if (type->value().toString() == "dag") { + auto view = new StoryPresent(); + view->loadXAST(path->value().toString()); + view->show(); + } }break; default: break; diff --git a/StoryPresent/storypresent.cpp b/StoryPresent/storypresent.cpp index 81bfc64..5601778 100644 --- a/StoryPresent/storypresent.cpp +++ b/StoryPresent/storypresent.cpp @@ -1,9 +1,55 @@ #include "storypresent.h" +#include +#include -StoryPresent::StoryPresent(QWidget *parent) - : QMainWindow(parent) +using namespace dags; +using namespace xast_parse; + +StoryPresent::StoryPresent(QWidget* parent) + : QMainWindow(parent), _story_present(new DAGActiveView(this)) { + setCentralWidget(_story_present); } StoryPresent::~StoryPresent() {} + +#include "xast_parse.h" +void StoryPresent::loadXAST(const QString& ast_path) +{ + QFileInfo finfo(ast_path); + if (!finfo.exists() || !finfo.isFile()) { + QMessageBox::critical(this, u8"Îļþ´íÎó", QString(u8"Ö¸¶¨Îļþ£¨%1£©·Ç·¨£¡").arg(ast_path)); + return; + } + + xast_parse::XAST_Parser t(ast_path); + this->_story_graph = t.storyGraph(); + + QList arrows; + for (auto& key : this->_story_graph.keys()) { + auto story_line = this->_story_graph[key]; + + auto arrow_start = story_line->name(); + auto frag_temp = story_line->firstChild(); + while (frag_temp) { + switch (frag_temp->type()) { + case SliceType::FragmentDefines: { + auto arrow_tail = std::dynamic_pointer_cast(frag_temp)->name() + u8"@" + story_line->name(); + arrows << graph_data::Arrow(arrow_start, arrow_tail); + arrow_start = arrow_tail; + }break; + case SliceType::FragmentRefers: { + auto conv_refer = std::dynamic_pointer_cast(frag_temp); + auto arrow_tail = conv_refer->fragmentRefer() + u8"@" + conv_refer->storyRefer(); + arrows << graph_data::Arrow(arrow_start, arrow_tail); + arrow_start = arrow_tail; + }break; + default: break; + } + frag_temp = frag_temp->nextSlice(); + } + } + + this->_story_present->updateWithEdges(arrows); +} diff --git a/StoryPresent/storypresent.h b/StoryPresent/storypresent.h index d23e4d4..3e93433 100644 --- a/StoryPresent/storypresent.h +++ b/StoryPresent/storypresent.h @@ -11,4 +11,9 @@ public: StoryPresent(QWidget* parent = nullptr); ~StoryPresent(); + void loadXAST(const QString &ast_path); + +private: + dags::DAGActiveView *const _story_present; + QHash> _story_graph; };