diff --git a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h index 1005cc0..0d584d3 100644 --- a/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h +++ b/include/mementar/core/memGraphs/ExtendedBtree/EventLinkedLeaf.h @@ -25,6 +25,14 @@ class LinkedEvent SelfType* getNext() { return next_elem_; } SelfType* getPrevious() { return prev_elem_; } + Tleaf* getLeaf() + { + if(leaf_ == nullptr) + return nullptr; + else + return static_cast(leaf_); + } + Tleaf* getNextLeaf() { if(leaf_ == nullptr) diff --git a/include/mementar/core/memGraphs/Graphs/ActionGraph.h b/include/mementar/core/memGraphs/Graphs/ActionGraph.h index 12953fc..326f764 100644 --- a/include/mementar/core/memGraphs/Graphs/ActionGraph.h +++ b/include/mementar/core/memGraphs/Graphs/ActionGraph.h @@ -28,6 +28,9 @@ class ActionGraph : public Graph SoftPoint::Ttime getStartStamp(const std::string& action_name); SoftPoint::Ttime getEndStamp(const std::string& action_name); SoftPoint::Ttime getDuration(const std::string& action_name); + std::string getStartFact(const std::string& action_name); + std::string getEndFact(const std::string& action_name); + std::unordered_set getFactsDuring(const std::string& action_name); std::vector get() { diff --git a/src/RosInterface.cpp b/src/RosInterface.cpp index 2cfba2f..e2b9f54 100644 --- a/src/RosInterface.cpp +++ b/src/RosInterface.cpp @@ -204,6 +204,20 @@ bool RosInterface::actionHandle(mementar::MementarService::Request &req, res.time_value = ros::Time(timeline_->actions.getEndStamp(params())); else if(req.action == "getDuration") res.time_value = ros::Time(timeline_->actions.getDuration(params())); + else if(req.action == "getStartFact") + { + auto fact_name = timeline_->actions.getStartFact(params()); + if(fact_name != "") + res.values.push_back(fact_name); + } + else if(req.action == "getEndFact") + { + auto fact_name = timeline_->actions.getEndFact(params()); + if(fact_name != "") + res.values.push_back(fact_name); + } + else if(req.action == "getFactsDuring") + set_res = timeline_->actions.getFactsDuring(params()); else res.code = UNKNOW_ACTION; diff --git a/src/core/memGraphs/Graphs/ActionGraph.cpp b/src/core/memGraphs/Graphs/ActionGraph.cpp index 266ce39..f64eb10 100644 --- a/src/core/memGraphs/Graphs/ActionGraph.cpp +++ b/src/core/memGraphs/Graphs/ActionGraph.cpp @@ -80,7 +80,7 @@ namespace mementar { if(action_branch == nullptr) return SoftPoint::default_time; else if(action_branch->isPending()) - return false; + return SoftPoint::default_time; else return action_branch->getEndFact()->getTime(); } @@ -94,6 +94,64 @@ namespace mementar { return action_branch->getDuration(); } + std::string ActionGraph::getStartFact(const std::string& action_name) + { + auto action_branch = find(action_name); + if(action_branch == nullptr) + return ""; + else + return action_branch->getStartFact()->getValue(); + } + + std::string ActionGraph::getEndFact(const std::string& action_name) + { + auto action_branch = find(action_name); + if(action_branch == nullptr) + return ""; + else if(action_branch->isPending()) + return ""; + else + return action_branch->getEndFact()->getValue(); + } + + std::unordered_set ActionGraph::getFactsDuring(const std::string& action_name) + { + std::unordered_set res; + auto action_branch = find(action_name); + if(action_branch != nullptr) + { + auto start_fact = action_branch->getStartFact(); + auto leaf = start_fact->getLeaf()->getNextLeaf(); + if(action_branch->isPending()) + { + while(leaf != nullptr) + { + auto data = leaf->getData(); + for(auto& fact : data) + res.insert(fact->getValue()); + leaf = leaf->getNextLeaf(); + } + } + else + { + auto end_fact = action_branch->getEndFact(); + while(leaf != nullptr) + { + auto data = leaf->getData(); + if(data.size()) + if(data[0] >= end_fact) + break; + + for(auto& fact : data) + res.insert(fact->getValue()); + leaf = leaf->getNextLeaf(); + } + } + } + + return res; + } + std::vector ActionGraph::getPendingPtr() { std::vector res; diff --git a/src/graphical/mementarGUI/mementargui.cpp b/src/graphical/mementarGUI/mementargui.cpp index c669013..48f197a 100644 --- a/src/graphical/mementarGUI/mementargui.cpp +++ b/src/graphical/mementarGUI/mementargui.cpp @@ -33,6 +33,12 @@ mementarGUI::mementarGUI(QWidget *parent) : QObject::connect(ui->action_getEndStamp_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); QObject::connect(ui->action_getDuration_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); QObject::connect(ui->action_getDuration_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getStartFact_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getStartFact_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getEndFact_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getEndFact_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); + QObject::connect(ui->action_getFactsDuring_button, SIGNAL(hoverEnter()),this, SLOT(actionButtonHoverEnterSlot())); + QObject::connect(ui->action_getFactsDuring_button, SIGNAL(hoverLeave()),this, SLOT(actionButtonHoverLeaveSlot())); QObject::connect(ui->action_exist_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_getPending_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); @@ -40,6 +46,9 @@ mementarGUI::mementarGUI(QWidget *parent) : QObject::connect(ui->action_getStartStamp_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_getEndStamp_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->action_getDuration_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getStartFact_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getEndFact_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); + QObject::connect(ui->action_getFactsDuring_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot())); QObject::connect(ui->manager_refresh_button, SIGNAL(clicked()),this, SLOT(displayInstancesListSlot())); QObject::connect(ui->manager_add_instance_button, SIGNAL(clicked()),this, SLOT(addInstanceSlot())); diff --git a/ui/mementargui.ui b/ui/mementargui.ui index f5db25d..f4121be 100644 --- a/ui/mementargui.ui +++ b/ui/mementargui.ui @@ -137,6 +137,50 @@ + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getStartFact</span> returns the identifier of the fact representing the start of the action provided as a parameter</p></body></html> + + + getStartFact + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getEndFact</span> returns the identifier of the fact representing the end of the action provided as a parameter</p></body></html> + + + getEndFact + + + + + + + PointingHandCursor + + + <html><head/><body><p><span style=" font-weight:600; font-style:italic;">getFactsDuring</span> returns the identifiers of all the facts that took place during the execution of the action provided in parameter</p></body></html> + + + getFactsDuring + + + + + +