Skip to content

Commit

Permalink
ScenarioManager: added displayStringTextFormat NED parameter for spec…
Browse files Browse the repository at this point in the history
…ify the text above the module
  • Loading branch information
ZoltanBojthe committed Apr 5, 2024
1 parent 1685db8 commit b44279d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/inet/common/scenario/ScenarioManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,28 @@ void ScenarioManager::processLifecycleCommand(const cXMLElement *node)

void ScenarioManager::refreshDisplay() const
{
char buf[80];
sprintf(buf, "total %d changes, %d left", numChanges, numChanges - numDone);
getDisplayString().setTagArg(ATTR_T, 0, buf);
auto text = StringFormat::formatString(par("displayStringTextFormat"), this);
getDisplayString().setTagArg("t", 0, text.c_str());
}

std::string ScenarioManager::resolveDirective(char directive) const
{
switch (directive) {
case 'c':
return std::to_string(numChanges);
case 'd':
return std::to_string(numDone);
case 'l':
return std::to_string(numChanges - numDone); // "numLeft"
case 't':
return scheduledEvents.empty() ? "n/a" : scheduledEvents.front()->getArrivalTime().str() + "s";
case 'n':
return scheduledEvents.empty() ? "n/a" : scheduledEvents.front()->getName();
default:
throw cRuntimeError("Unknown directive: %c", directive);
}
}


} // namespace inet

5 changes: 4 additions & 1 deletion src/inet/common/scenario/ScenarioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "inet/common/lifecycle/LifecycleController.h"
#include "inet/common/scenario/IScriptable.h"
#include "inet/common/scenario/ScenarioTimer_m.h"
#include "inet/common/StringFormat.h"

namespace inet {

Expand Down Expand Up @@ -41,7 +42,7 @@ class INET_API cPostModuleInitNotification : public cModelChangeNotification
*
* @see IScriptable
*/
class INET_API ScenarioManager : public cSimpleModule, public LifecycleController
class INET_API ScenarioManager : public cSimpleModule, public LifecycleController, public StringFormat::IDirectiveResolver
{
protected:
// total number of changes, and number of changes already done
Expand Down Expand Up @@ -75,6 +76,8 @@ class INET_API ScenarioManager : public cSimpleModule, public LifecycleControlle
virtual void processModuleSpecificCommand(const cXMLElement *node);
virtual void processLifecycleCommand(const cXMLElement *node);

virtual std::string resolveDirective(char directive) const override;

public:
ScenarioManager() {}

Expand Down
5 changes: 5 additions & 0 deletions src/inet/common/scenario/ScenarioManager.ned
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ simple ScenarioManager
{
parameters:
xml script = default(xml("<script></script>"));

// Format for the text displayed above the module icon.
// Directives: %c: numChanges, %d: numDone, %l: numLeft, %t: nextEventTime, %n: nextEventName
string displayStringTextFormat = default("total %c changes, %l left\nnext at: %t");

@display("i=block/control");
@labels(node,mpls-node);
}
Expand Down

0 comments on commit b44279d

Please sign in to comment.