InteractionObserver.cpp
Go to the documentation of this file.
1 #include "InteractionObserver.h"
2 
3 #include <utility>
4 
7 {
8  contextMenuActions[index] = std::move(action);
9  return *this;
10 }
11 
14 {
15  transformEndAction = std::make_optional(std::move(action));
16  return *this;
17 }
18 
20 {
22  {
23  auto iterator = contextMenuActions.find(interaction.chosenContextMenuEntry());
24 
25  if (iterator != contextMenuActions.end())
26  {
27  auto [index, action] = *iterator;
28  action();
29  }
30  }
31 
32  if (interaction.type() == viz::InteractionFeedbackType::Transform && interaction.isTransformEnd())
33  {
34  if (transformEndAction.has_value())
35  {
36  transformEndAction.value()(interaction.transformation());
37  }
38  }
39 }
40 
42 {
43  layer.clear();
44  observedLayers.erase(layer.data_.name);
45 }
46 
48 {
49  for (auto& [name, observedLayer] : observedLayers)
50  {
51  stage.requestInteraction(observedLayer.layer);
52  }
53 }
54 
56 {
57  for (viz::InteractionFeedback const& interaction: interactions)
58  {
59  auto layerIterator = observedLayers.find(interaction.layer());
60 
61  if (layerIterator != observedLayers.end())
62  {
63  auto& [name, layer] = *layerIterator;
64 
65  auto observationIterator = layer.observations.find(interaction.element());
66 
67  if (observationIterator != layer.observations.end())
68  {
69  auto& [element, observation] = *observationIterator;
70  observation.process(interaction);
71  }
72  }
73  }
74 }
armarx::InteractionObserver::Observation::onTransformEnd
Observation & onTransformEnd(std::function< void(Eigen::Matrix4f const &)> action)
Definition: InteractionObserver.cpp:13
armarx::viz::InteractionFeedbackType::ContextMenuChosen
@ ContextMenuChosen
A context menu entry was chosen.
armarx::InteractionObserver::Observation::onContextMenu
Observation & onContextMenu(size_t index, std::function< void()> action)
Definition: InteractionObserver.cpp:6
armarx::viz::interaction
InteractionDescription interaction()
Definition: ElementOps.h:101
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::viz::Layer::clear
void clear()
Definition: Layer.h:23
armarx::InteractionObserver::process
void process(viz::InteractionFeedbackRange const &interactions)
Definition: InteractionObserver.cpp:55
armarx::viz::StagedCommit
A staged commit prepares multiple layers to be committed.
Definition: Client.h:31
armarx::InteractionObserver::Observation
Definition: InteractionObserver.h:10
InteractionObserver.h
armarx::viz::Layer::data_
data::LayerUpdate data_
Definition: Layer.h:53
armarx::viz::InteractionFeedbackType::Transform
@ Transform
The element was transformed (translated or rotated).
armarx::viz::StagedCommit::requestInteraction
void requestInteraction(Layer const &layer)
Request interaction feedback for a particular layer.
Definition: Client.h:55
armarx::viz::InteractionFeedbackRange
Definition: Interaction.h:135
armarx::viz::InteractionFeedback
Definition: Interaction.h:57
armarx::InteractionObserver::requestInteractions
void requestInteractions(viz::StagedCommit &stage)
Definition: InteractionObserver.cpp:47
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::InteractionObserver::clearObservedLayer
void clearObservedLayer(viz::Layer &layer)
Definition: InteractionObserver.cpp:41
armarx::viz::Layer
Definition: Layer.h:12
armarx::InteractionObserver::Observation::process
void process(viz::InteractionFeedback const &interaction)
Definition: InteractionObserver.cpp:19