Skip to content

Commit

Permalink
[UPDATE] actionGraph getStartFact, getEndFact and getFactsDuring
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthou committed Dec 15, 2020
1 parent 3e1520a commit c29f7ab
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tleaf*>(leaf_);
}

Tleaf* getNextLeaf()
{
if(leaf_ == nullptr)
Expand Down
3 changes: 3 additions & 0 deletions include/mementar/core/memGraphs/Graphs/ActionGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class ActionGraph : public Graph<Action>
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<std::string> getFactsDuring(const std::string& action_name);

std::vector<Action*> get()
{
Expand Down
14 changes: 14 additions & 0 deletions src/RosInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
60 changes: 59 additions & 1 deletion src/core/memGraphs/Graphs/ActionGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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<std::string> ActionGraph::getFactsDuring(const std::string& action_name)
{
std::unordered_set<std::string> 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<Action*> ActionGraph::getPendingPtr()
{
std::vector<Action*> res;
Expand Down
9 changes: 9 additions & 0 deletions src/graphical/mementarGUI/mementargui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ 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()));
QObject::connect(ui->action_isPending_button, SIGNAL(clicked()),this, SLOT(actionButtonClickedSlot()));
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()));
Expand Down
44 changes: 44 additions & 0 deletions ui/mementargui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,50 @@
</layout>
</item>

<item>
<layout class="QHBoxLayout" name="action_functions_layer3_layout">
<item>
<widget class="QPushButtonExtended" name="action_getStartFact_button">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; font-style:italic;&quot;&gt;getStartFact&lt;/span&gt; returns the identifier of the fact representing the start of the action provided as a parameter&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>getStartFact</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButtonExtended" name="action_getEndFact_button">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; font-style:italic;&quot;&gt;getEndFact&lt;/span&gt; returns the identifier of the fact representing the end of the action provided as a parameter&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>getEndFact</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButtonExtended" name="action_getFactsDuring_button">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; font-style:italic;&quot;&gt;getFactsDuring&lt;/span&gt; returns the identifiers of all the facts that took place during the execution of the action provided in parameter&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>getFactsDuring</string>
</property>
</widget>
</item>
</layout>
</item>

<item>
<widget class="QTextEdit" name="action_description_textedit">
<property name="verticalScrollBarPolicy">
Expand Down

0 comments on commit c29f7ab

Please sign in to comment.