Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaGraphComponent] FIX SceneChecker & RequiredPlugin #563

Merged
merged 2 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion modules/SofaGraphComponent/RequiredPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,17 @@ void RequiredPlugin::loadPlugin()
}
if (suffixVec.empty())
suffixVec.push_back(defaultSuffix);

/// In case the pluginName is not set we copy the provided name into the set to load.
if(!d_pluginName.isSet() && name.isSet())
{
helper::WriteOnlyAccessor<Data<helper::vector<std::string>>> pluginsName = d_pluginName ;
pluginsName.push_back(this->getName());
}

const helper::vector<std::string>& nameVec = d_pluginName.getValue();
helper::vector<std::string> nameVecCopy=nameVec;
if(nameVec.empty()) nameVecCopy.push_back(this->getName());

helper::vector< std::string > loaded;
helper::vector< std::string > failed;
std::ostringstream errmsg;
Expand Down
11 changes: 7 additions & 4 deletions modules/SofaGraphComponent/SceneCheckerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ void SceneCheckerVisitor::validate(Node* node)
std::stringstream tmp;
for(SceneCheck::SPtr& check : m_checkset)
{
tmp << "- " << check->getName() << msgendl ;
tmp << check->getName() << ", " ;
check->doInit(node) ;
}

msg_info("SceneChecker") << "Validating node '"<< node->getPathName() << "'. " << msgendl
<< "Activate checkers: " << msgendl
<< tmp.str() ;
msg_info("SceneChecker") << "Validating node '"<< node->getPathName() << " with: [" << tmp.str() << "]" ;

execute(node) ;

for(SceneCheck::SPtr& check : m_checkset)
{
check->doPrintSummary() ;
}
}


Expand Down
71 changes: 61 additions & 10 deletions modules/SofaGraphComponent/SceneChecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const std::string SceneCheckDuplicatedName::getDesc()
return "Check there is not duplicated name in the scenegraph";
}

void SceneCheckDuplicatedName::doInit(Node* node)
{
SOFA_UNUSED(node) ;
m_hasDuplicates = false ;
m_duplicatedMsg.str("") ;
m_duplicatedMsg.clear() ;
}

void SceneCheckDuplicatedName::doCheckOn(Node* node)
{
std::map<std::string, int> duplicated ;
Expand All @@ -77,15 +85,26 @@ void SceneCheckDuplicatedName::doCheckOn(Node* node)
{
if(p.second!=1)
{
tmp << "- duplicated '" << p.first << "'" << msgendl ;
tmp << "'" << p.first << "', " ;
}
}

if(!tmp.str().empty())
{
msg_warning("SceneCheckDuplicatedName") << "In '"<< node->getPathName() <<"'" << msgendl
<< tmp.str() ;
m_hasDuplicates = true ;
m_duplicatedMsg << "- Found duplicated names "<<"' [" << tmp.str() << "] in node '"<< node->getPathName() << "'" << msgendl ;
}
}

void SceneCheckDuplicatedName::doPrintSummary()
{
if(m_hasDuplicates)
{
msg_warning("SceneCheckDuplicatedName") << msgendl
<< m_duplicatedMsg.str()
<< "Nodes with similar names at the same leve of your scene can "
"crash certain operations, please them rename" ;
}
}

const std::string SceneCheckMissingRequiredPlugin::getName()
Expand All @@ -110,26 +129,58 @@ void SceneCheckMissingRequiredPlugin::doCheckOn(Node* node)
std::string pluginName = it->second->getTarget() ;
std::string path = PluginManager::getInstance().findPlugin(pluginName) ;
if( PluginManager::getInstance().pluginIsLoaded(path)
&& m_requiredPlugins.find(pluginName) == m_requiredPlugins.end() )
&& m_loadedPlugins.find(pluginName) == m_loadedPlugins.end() )
{
msg_warning("SceneChecker")
<< "This scene is using component '" << object->getClassName() << "'. " << msgendl
<< "This component is part of the '" << pluginName << "' plugin but there is no <RequiredPlugin name='" << pluginName << "' /> directive in your scene." << msgendl
<< "Your scene may not work on a sofa environment that does not have pre-loaded the plugin." << msgendl
<< "To fix your scene and remove this warning you need to add the RequiredPlugin directive at the beginning of your scene. ";
if( m_requiredPlugins.empty() ){
m_requiredPlugins[pluginName].push_back(object->getClassName()) ;
}else{
std::vector<std::string>& t = m_requiredPlugins[pluginName] ;
if( std::find(t.begin(), t.end(), object->getClassName()) ==t.end() )
t.push_back(object->getClassName()) ;
}
}
}
}
}
}

void SceneCheckMissingRequiredPlugin::doPrintSummary()
{
if(!m_requiredPlugins.empty())
{
std::stringstream tmp ;
for(auto& kv : m_requiredPlugins)
{
tmp << "<RequiredPlugin name='"<<kv.first<<"'> <!-- Needed to use components [" ;
for(auto& name : kv.second)
{
tmp << name << ", " ;
}
tmp <<"]-->" << msgendl ;
}
msg_warning("SceneChecker")
<< "This scene is using component defined in plugins but are not importing the requierd plugins." << msgendl
<< "Your scene may not work on a sofa environment with different pre-loaded plugins." << msgendl
<< "To fix your scene and remove this warning you just need to cut & paste the following lines at the begining of your scene (if it is a .scn): " << msgendl
<< tmp.str() ;
}
}

void SceneCheckMissingRequiredPlugin::doInit(Node* node)
{
helper::vector< RequiredPlugin* > plugins ;
node->getTreeObjects< RequiredPlugin >(&plugins) ;

m_requiredPlugins.clear() ;
m_loadedPlugins.clear() ;

for(auto& plugin : plugins)
m_requiredPlugins[plugin->getName()] = true ;
{
for(auto& pluginName : plugin->d_pluginName.getValue())
{
m_loadedPlugins[pluginName] = true ;
}
}
}


Expand Down
13 changes: 11 additions & 2 deletions modules/SofaGraphComponent/SceneChecks.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SOFA_GRAPH_COMPONENT_API SceneCheck
virtual const std::string getDesc() = 0 ;
virtual void doInit(Node* node) { SOFA_UNUSED(node); }
virtual void doCheckOn(Node* node) = 0 ;
virtual void doPrintSummary() {}
};

class SOFA_GRAPH_COMPONENT_API SceneCheckDuplicatedName : public SceneCheck
Expand All @@ -57,7 +58,13 @@ class SOFA_GRAPH_COMPONENT_API SceneCheckDuplicatedName : public SceneCheck
static SPtr newSPtr() { return SPtr(new SceneCheckDuplicatedName()); }
virtual const std::string getName() override ;
virtual const std::string getDesc() override ;
virtual void doInit(Node* node) override ;
virtual void doCheckOn(Node* node) override ;
virtual void doPrintSummary() override ;

private:
bool m_hasDuplicates ;
std::stringstream m_duplicatedMsg ;
};

class SOFA_GRAPH_COMPONENT_API SceneCheckMissingRequiredPlugin : public SceneCheck
Expand All @@ -69,9 +76,11 @@ class SOFA_GRAPH_COMPONENT_API SceneCheckMissingRequiredPlugin : public SceneChe
virtual const std::string getDesc() override ;
virtual void doInit(Node* node) override ;
virtual void doCheckOn(Node* node) override ;
virtual void doPrintSummary() override ;

private:
std::map<std::string,bool> m_requiredPlugins ;
private:
std::map<std::string, bool > m_loadedPlugins ;
std::map<std::string, std::vector<std::string> > m_requiredPlugins ;
};


Expand Down