Skip to content

Commit

Permalink
lib: add onLookAt and onLookAway
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlivio committed Apr 27, 2021
1 parent b055fc5 commit b993b0e
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 12 deletions.
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ endif()
# Ginga-related cmake's variables
include (GNUInstallDirs)
set (PACKAGE "ginga")
set (GINGA_BINARY_DIR ${CMAKE_BINARY_DIR}/bin)
set (GINGA_BINARY_TESTS_DIR ${CMAKE_BINARY_DIR}/tests)
set (GINGA_BINARY_DIR ${CMAKE_BINARY_DIR})
set (GINGA_BINARY_TESTS_DIR ${CMAKE_BINARY_DIR})
add_definitions (-DGINGADATADIR="${CMAKE_INSTALL_FULL_DATADIR}/${PACKAGE}")
add_definitions (-DGINGABINDIR="${CMAKE_INSTALL_FULL_BINDIR}")

Expand Down Expand Up @@ -116,7 +116,7 @@ if (WITH_CEF) # Download, link, build with CEF

# Logical target used to link the libcef library.
ADD_LOGICAL_TARGET("libcef_lib" "${CEF_LIB_DEBUG}" "${CEF_LIB_RELEASE}")
SET (CEF_TARGET_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/bin/")
SET (CEF_TARGET_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/")

else()
add_definitions (-DWITH_CEF=0)
Expand Down Expand Up @@ -365,13 +365,14 @@ enable_testing ()
add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND})
macro (add_ginga_test target)
add_executable (${target} EXCLUDE_FROM_ALL ${ARGN})
target_include_directories (${target} PRIVATE ${GTK3_INCLUDE_DIRS})
target_link_libraries (${target} PRIVATE libginga ${GTK3_LIBRARIES})
target_include_directories (${target} PUBLIC ${GTK3_INCLUDE_DIRS})
target_link_libraries (${target} PUBLIC libginga ${GTK3_LIBRARIES})

set_target_properties (${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${GINGA_BINARY_TESTS_DIR})
add_test (${target} tests/${target})
add_dependencies (${target} libginga)
add_dependencies (check ${target})
add_test (${target} ${target})
endmacro ()

file(GLOB GINGA_TESTS_SRC
Expand Down
6 changes: 5 additions & 1 deletion lib/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ Event::getFullId ()
return obj_id + "." + _id;
case Event::SELECTION:
return obj_id + "<" + _id + ">";
case Event::LOOKAT:
return obj_id + "<lookat>";
case Event::PREPARATION:
if (_id == "@lambda")
return obj_id + "$" + _id.substr (1, _id.length() - 1);
return obj_id + "$" + _id.substr (1, _id.length () - 1);
else
return obj_id + "$" + _id;
default:
Expand Down Expand Up @@ -254,6 +256,8 @@ Event::getEventTypeAsString (Event::Type type)
return "selection";
case Event::PREPARATION:
return "preparation";
case Event::LOOKAT:
return "lookAt";
default:
g_assert_not_reached ();
}
Expand Down
7 changes: 7 additions & 0 deletions lib/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class Event
* Stands for the preparation of a specific time interval of the object.
*/
PREPARATION,

/**
* @brief lookAt event.
*
* Stands for the user viewport is on the objet.
*/
LOOKAT,
};

/// @brief Event state.
Expand Down
16 changes: 16 additions & 0 deletions lib/Media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ Media::beforeTransition (Event *evt, Event::Transition transition)
case Event::PREPARATION:
break; // nothing to do

case Event::LOOKAT:
break; // nothing to do

default:
g_assert_not_reached ();
}
Expand Down Expand Up @@ -502,6 +505,19 @@ Media::afterTransition (Event *evt, Event::Transition transition)
}
break;
}
case Event::LOOKAT:
switch (transition)
{
case Event::START:
TRACE ("start %s", evt->getFullId ().c_str ());
break;
case Event::STOP:
TRACE ("stop %s", evt->getFullId ().c_str ());
break;
default:
g_assert_not_reached ();
}
break;
default:
g_assert_not_reached ();
}
Expand Down
17 changes: 17 additions & 0 deletions lib/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,23 @@ Object::addPreparationEvent (const string &id, Time begin, Time end)
_events.insert (evt);
}

Event *
Object::getLookAtEvent (const string &id)
{
return this->getEvent (Event::LOOKAT, id);
}

void
Object::addLookAtEvent (const string &id)
{
Event *evt;
if (this->getLookAtEvent (id))
return;

evt = new Event (Event::LOOKAT, this, id);
_events.insert (evt);
}

Event *
Object::getLambda ()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Object
Event *getPreparationEvent (const string &);
void addPreparationEvent (const string &);
void addPreparationEvent (const string &, Time, Time);
Event *getLookAtEvent (const string &);
void addLookAtEvent (const string &);

Event *getLambda ();
bool isOccurring ();
Expand Down
12 changes: 11 additions & 1 deletion lib/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ static map<string, pair<Event::Type, Event::Transition> >
{ "onBeginAttribution", { Event::ATTRIBUTION, Event::START } },
{ "onEndAttribution", { Event::ATTRIBUTION, Event::STOP } },
{ "onSelection", { Event::SELECTION, Event::START } },
{ "onLookAt", { Event::LOOKAT, Event::START } },
{ "onLookAway", { Event::LOOKAT, Event::STOP } },
{ "onBeginSelection", { Event::SELECTION, Event::START } },
{ "onEndSelection", { Event::SELECTION, Event::STOP } },
{ "onBeginPreparation", { Event::PREPARATION, Event::START } },
Expand Down Expand Up @@ -931,6 +933,7 @@ static map<string, Event::Type> parser_syntax_event_type_table = {
{ "presentation", Event::PRESENTATION },
{ "attribution", Event::ATTRIBUTION },
{ "selection", Event::SELECTION },
{ "lookat", Event::LOOKAT },
{ "preparation", Event::PREPARATION },
};

Expand Down Expand Up @@ -2775,7 +2778,7 @@ borderColor='%s'}",
{
string eventId = evt->getId ();

if(evt->getId () == "@lambda")
if(eventId == "@lambda")
{
obj->addPreparationEvent(eventId);
}
Expand All @@ -2784,6 +2787,13 @@ borderColor='%s'}",
g_assert_nonnull (act.event);
break;
}
case Event::LOOKAT:
{
obj->addLookAtEvent ("@lambda");
act.event = obj->getLookAtEvent ("@lambda");
g_assert_nonnull (act.event);
break;
}
default:
g_assert_not_reached ();
}
Expand Down
10 changes: 6 additions & 4 deletions lib/WebServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ WebServices::machMediaThenSetPlayerRemote (PlayerRemoteData &data)

bool found = false;
auto mrts = _formatter->getDocument ()->getMediasRemote ();
if (mrts->empty())
if (mrts->empty ())
return false;

// match media deviceType then set remotePlayerBaseURL
Expand Down Expand Up @@ -92,7 +92,7 @@ ws_null_callback (SoupServer *server, SoupMessage *msg, const char *path,
{
soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
soup_message_set_response (msg, "text/plan", SOUP_MEMORY_COPY,
"route not implemented", 0);
"Route not implemented", 0);
}

static void
Expand Down Expand Up @@ -131,7 +131,6 @@ ws_remoteplayer_callback (SoupServer *server, SoupMessage *msg,
string errors;
WebServices *ws = (WebServices *) user_data;

soup_message_set_status (msg, SOUP_STATUS_OK);
WS_LOG_REQUEST (msg);

if (!reader->parse (msg->request_body->data,
Expand All @@ -148,7 +147,10 @@ ws_remoteplayer_callback (SoupServer *server, SoupMessage *msg,
list<string> recognizableEvents;
for (const auto &item : root["recognizableEvents"])
recognizableEvents.push_back (item.asString ());
ws->machMediaThenSetPlayerRemote (pdata);
if (ws->machMediaThenSetPlayerRemote (pdata))
soup_message_set_status (msg, SOUP_STATUS_OK);
else
soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
}

bool
Expand Down
66 changes: 66 additions & 0 deletions tests-ncl/test-ws-lookat.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<ncl>
<head>
<regionBase>
<region id='reg1' left='0' top='25%' width='50%' height='50%'/>
<region id='reg2' left='55%' top='40%' width='20%' height='20%'/>
<region id='reg3' left='75%' top='40%' width='20%' height='20%'/>
</regionBase>
<descriptorBase>
<descriptor id="desc1" region="reg1"/>
<descriptor id="desc2" region="reg2" focusIndex="1" moveRight="2"/>
<descriptor id="desc3" region="reg3" focusIndex="2" moveLeft="1"/>
</descriptorBase>
<connectorBase>
<causalConnector id="onLookAtStart">
<simpleCondition role="onLookAt"/>
<simpleAction role="set" value="$var"/>
</causalConnector>
<causalConnector id="onLookAwayStart">
<simpleCondition role="onLookAway"/>
<simpleAction role="set" value="$var"/>
</causalConnector>
<causalConnector id="onSelectionStartLookAt">
<simpleCondition role="onSelection"/>
<simpleAction role="startLookAt" eventType="lookat" actionType="start"/>
</causalConnector>
<causalConnector id="onSelectionStopLookAt">
<simpleCondition role="onSelection"/>
<simpleAction role="stopLookAt" eventType="lookat" actionType="stop"/>
</causalConnector>
</connectorBase>
</head>
<body>
<port id="entry1" component="m1"/>
<port id="entry2" component="m2"/>
<port id="entry3" component="m3"/>
<media id="m1" descriptor="desc1">
<property name="background" value="blue"/>
</media>
<media id="m2" descriptor="desc2">
<property name="background" value="green"/>
</media>
<media id="m3" descriptor="desc3">
<property name="background" value="red"/>
</media>
<link xconnector="onLookAtStart">
<bind role="onLookAt" component="m1"/>
<bind role="set" component="m1" interface="background">
<bindParam name="var" value="green"/>
</bind>
</link>
<link xconnector="onLookAwayStart">
<bind role="onLookAway" component="m1"/>
<bind role="set" component="m1" interface="background">
<bindParam name="var" value="red"/>
</bind>
</link>
<link xconnector="onSelectionStartLookAt">
<bind role="onSelection" component="m2"/>
<bind role="startLookAt" component="m1"/>
</link>
<link xconnector="onSelectionStopLookAt">
<bind role="onSelection" component="m3"/>
<bind role="stopLookAt" component="m1"/>
</link>
</body>
</ncl>
1 change: 1 addition & 0 deletions tests/test-Event-getEventTypeAsString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ main (void)
CHECK_TYPE (Event::SELECTION, "selection");
CHECK_TYPE (Event::PRESENTATION, "presentation");
CHECK_TYPE (Event::ATTRIBUTION, "attribution");
CHECK_TYPE (Event::LOOKAT, "lookAt");
exit (EXIT_SUCCESS);
}
14 changes: 14 additions & 0 deletions tests/test-Event-new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ main (void)
delete e;
}

// LookAt
{
Event *e = new Event (Event::LOOKAT, m, "@lambda");
g_assert_nonnull (e);
g_assert (e->getType () == Event::LOOKAT);
g_assert (e->getObject () == m);
g_assert (e->getId () == "@lambda");
g_assert (e->getFullId () == "m<lookat>");
g_assert (e->getState () == Event::SLEEPING);
g_assert_false (e->isLambda ());
g_assert (!e->toString ().empty ());
delete e;
}

// getStringAsTransition
{
g_assert (Event::getStringAsTransition ("start") == Event::START);
Expand Down
Loading

0 comments on commit b993b0e

Please sign in to comment.