Make use of referenced verifier for Renderables

Adapt HTML documentation generation
This commit is contained in:
Alexander Bock
2016-09-19 11:24:37 +02:00
parent 9b9f0ecce8
commit 85492405bd
5 changed files with 54 additions and 23 deletions
+21 -3
View File
@@ -125,16 +125,34 @@ std::string generateHtmlDocumentation(const Documentation& d) {
std::stringstream html;
html << "\t<tr>\n"
<< "\t\t<td colspan=6>" << d.name << "</td>\n";
<< "\t\t<td colspan=6>" << d.name << "<a name=\"" << d.id << "\"></a></td>\n";
for (const auto& p : d.entries) {
html << "\t<tr>\n"
<< "\t\t<td></td>\n"
<< "\t\t<td>" << p.key << "</td>\n"
<< "\t\t<td>" << (p.optional ? "true" : "false") << "</td>\n"
<< "\t\t<td>" << (p.optional ? "Optional" : "Required") << "</td>\n"
<< "\t\t<td>" << p.verifier->type() << "</td>\n";
TableVerifier* tv = dynamic_cast<TableVerifier*>(p.verifier.get());
if (tv) {
ReferencingVerifier* rv = dynamic_cast<ReferencingVerifier*>(p.verifier.get());
// We have to check ReferencingVerifier first as a ReferencingVerifier is also a
// TableVerifier
if (rv) {
std::vector<Documentation> documentations = DocEng.documentations();
auto it = std::find_if(
documentations.begin(),
documentations.end(),
[rv](const Documentation& doc) { return doc.id == rv->identifier; }
);
html << "\t\t<td>"
<< "\t\t\tReferencing: "
<< "<a href=\"#" << rv->identifier << "\">" << it->name << "</a>"
<< "\t\t</td>";
}
else if (tv) {
// We have a TableVerifier, so we need to recurse
html << "<td><table cellpadding=3 cellspacing=0 border=1>\n"
<< "\t<thead>\n"
+2
View File
@@ -165,6 +165,8 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
DocEng.addDocumentation(ConfigurationManager::Documentation());
DocEng.addDocumentation(Scene::Documentation());
DocEng.addDocumentation(SceneGraphNode::Documentation());
DocEng.addDocumentation(Renderable::Documentation());
}
OpenSpaceEngine::~OpenSpaceEngine() {
+26 -9
View File
@@ -28,6 +28,8 @@
#include <openspace/util/spicemanager.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/documentation/verifier.h>
#include <ghoul/misc/dictionary.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/opengl/programobject.h>
@@ -42,22 +44,37 @@ namespace {
namespace openspace {
Documentation Renderable::Documentation() {
using namespace openspace::documentation;
return {
"Renderable",
"renderable",
{
{
KeyType,
new StringAnnotationVerifier("A valid Renderable created by a factory"),
"This key specifies the type of Renderable that gets created. It has to be one"
"of the valid Renderables that are available for creation (see the "
"FactoryDocumentation for a list of possible Renderables), which depends on "
"the configration of the application",
Optional::No
}
}
};
}
Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary) {
// The name is passed down from the SceneGraphNode
std::string name;
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
assert(success);
ghoul_assert(success, "The SceneGraphNode did not set the 'name' key");
std::string renderableType;
success = dictionary.getValue(KeyType, renderableType);
documentation::testSpecificationAndThrow(Documentation(), dictionary, "Renderable");
if (!success) {
LERROR("Renderable '" << name << "' did not have key '" << KeyType << "'");
return nullptr;
}
std::string renderableType = dictionary.value<std::string>(KeyType);
ghoul::TemplateFactory<Renderable>* factory
= FactoryManager::ref().factory<Renderable>();
auto factory = FactoryManager::ref().factory<Renderable>();
Renderable* result = factory->create(renderableType, dictionary);
if (result == nullptr) {
LERROR("Failed to create a Renderable object of type '" << renderableType << "'");
+1 -11
View File
@@ -52,17 +52,7 @@ Documentation SceneGraphNode::Documentation() {
},
{
"Renderable",
new TableVerifier({
{
"Type",
new StringAnnotationVerifier(
"Must name a valid Renderable type."
),
"The type of the specific renderable. The list of available "
"renderables depends on the configuration of the application and can "
"be written to disk at startup."
}
}),
new ReferencingVerifier("renderable"),
"The renderable that is to be created for this scenegraph node. A renderable "
"is a component of a scenegraph node that will lead to some visual result on "
"the screen. The specifics heavily depend on the 'Type' of the renderable. "