34 NetworkNodeVisualizerBase::NetworkNodeVisualization(
networkNode)
37 osgText::Text *label =
nullptr;
38 if (displayModuleName) {
39 auto font = osgText::Font::getDefaultFont();
40 label =
new osgText::Text();
41 label->setCharacterSize(18);
42 label->setBoundingBoxColor(osg::Vec4(1.0, 1.0, 1.0, 1.0));
43 label->setBoundingBoxMargin(spacing);
44 label->setColor(osg::Vec4(0.0, 0.0, 0.0, 1.0));
45 label->setAlignment(osgText::Text::CENTER_BOTTOM);
47 label->setDrawMode(osgText::Text::FILLEDBOUNDINGBOX | osgText::Text::TEXT);
48 label->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
49 for (
auto texture : font->getGlyphTextureList()) {
50 texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
51 texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
54 osg::Node *osgNode =
nullptr;
55 cDisplayString& displayString =
networkNode->getDisplayString();
58 auto osgModel = osgDB::readNodeFile(osgModelPath.c_str());
59 if (osgModel ==
nullptr)
60 throw cRuntimeError(
"Visual representation osg model '%s' not found",
networkNode->par(
"osgModel").stringValue());
61 const char *osgModelColor =
networkNode->par(
"osgModelColor");
62 if (*osgModelColor !=
'\0') {
63 auto material =
new osg::Material();
65 osg::Vec4 colorVec((
double)color.red / 255.0, (
double)color.green / 255.0, (
double)color.blue / 255.0, 1.0);
66 material->setAmbient(osg::Material::FRONT_AND_BACK, colorVec);
67 material->setDiffuse(osg::Material::FRONT_AND_BACK, colorVec);
68 material->setAlpha(osg::Material::FRONT_AND_BACK, 1.0);
69 osgModel->getOrCreateStateSet()->setAttribute(material);
71 auto group =
new osg::Group();
72 group->addChild(osgModel);
73 if (displayModuleName) {
74 label->setPosition(osg::Vec3(0.0, spacing, 0.0));
75 auto geode =
new osg::Geode();
76 geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
77 geode->addDrawable(label);
78 auto boundingSphere = osgModel->getBound();
79 size = osg::Vec3d(0, 18, 0);
82 auto autoTransform =
new osg::AutoTransform();
84 autoTransform->setPivotPoint(osg::Vec3d(0.0, 0.0, 0.0));
86 autoTransform->setAutoScaleToScreen(
true);
87 autoTransform->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
88 autoTransform->setPosition(osg::Vec3d(0.0, 0.0, boundingSphere.radius()));
90 group->addChild(autoTransform);
95 const char *icon = displayString.getTagArg(
"i", 0);
96 std::string path(icon);
98 path =
networkNode->resolveResourcePath(path.c_str());
99 auto image = osgDB::readImageFile(path.c_str());
100 if (image ==
nullptr)
101 throw cRuntimeError(
"Cannot find icon '%s' at '%s'", icon, path.c_str());
102 auto texture =
new osg::Texture2D();
103 texture->setImage(image);
104 auto geometry = osg::createTexturedQuadGeometry(osg::Vec3(-image->s() / 2, 0.0, 0.0), osg::Vec3(image->s(), 0.0, 0.0), osg::Vec3(0.0, image->t(), 0.0), 0.0, 0.0, 1.0, 1.0);
105 geometry->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture);
106 geometry->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
107 geometry->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
108 geometry->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
109 auto geode =
new osg::Geode();
110 geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
111 geode->addDrawable(geometry);
112 if (displayModuleName) {
113 label->setPosition(osg::Vec3(0.0, image->t() + spacing, 0.0));
114 geode->addDrawable(label);
116 size = osg::Vec3d(image->s(), image->t() + spacing + 18, 0);
119 auto autoTransform =
new osg::AutoTransform();
121 autoTransform->setPivotPoint(osg::Vec3d(0.0, 0.0, 0.0));
123 autoTransform->setAutoScaleToScreen(
true);
124 autoTransform->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
125 autoTransform->setPosition(osg::Vec3d(0.0, 0.0, 1.0));
127 osgNode = autoTransform;
130 objectNode->addChild(osgNode);
131 addChild(objectNode);
132 double x = atol(displayString.getTagArg(
"p", 0));
133 double y = atol(displayString.getTagArg(
"p", 1));
134 setPosition(osg::Vec3d(x, y, 0.0));