|
| 1 | +/****************************************************************************** |
| 2 | +* SOFA, Simulation Open-Framework Architecture * |
| 3 | +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * |
| 4 | +* * |
| 5 | +* This program is free software; you can redistribute it and/or modify it * |
| 6 | +* under the terms of the GNU Lesser General Public License as published by * |
| 7 | +* the Free Software Foundation; either version 2.1 of the License, or (at * |
| 8 | +* your option) any later version. * |
| 9 | +* * |
| 10 | +* This program is distributed in the hope that it will be useful, but WITHOUT * |
| 11 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * |
| 12 | +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * |
| 13 | +* for more details. * |
| 14 | +* * |
| 15 | +* You should have received a copy of the GNU Lesser General Public License * |
| 16 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | +******************************************************************************* |
| 18 | +* Authors: The SOFA Team and external contributors (see Authors.txt) * |
| 19 | +* * |
| 20 | +* Contact information: contact@sofa-framework.org * |
| 21 | +******************************************************************************/ |
| 22 | +#include "SceneCheckCollisionPipelineAndModels.h" |
| 23 | + |
| 24 | +#include <sofa/simulation/Node.h> |
| 25 | +#include <sofa/core/CollisionModel.h> |
| 26 | +#include <sofa/core/collision/Pipeline.h> |
| 27 | +#include <sofa/simulation/SceneCheckMainRegistry.h> |
| 28 | + |
| 29 | +namespace sofa::_scenechecking_ |
| 30 | +{ |
| 31 | + |
| 32 | +const bool SceneCheckCollisionPipelineAndModelsRegistered = sofa::simulation::SceneCheckMainRegistry::addToRegistry(SceneCheckCollisionPipelineAndModels::newSPtr()); |
| 33 | + |
| 34 | +using sofa::simulation::Node; |
| 35 | + |
| 36 | +const std::string SceneCheckCollisionPipelineAndModels::getName() |
| 37 | +{ |
| 38 | + return "SceneCheckCollisionPipelineAndModels"; |
| 39 | +} |
| 40 | + |
| 41 | +const std::string SceneCheckCollisionPipelineAndModels::getDesc() |
| 42 | +{ |
| 43 | + return "Ensure the consistency of the existence of a collision pipeline, and collision models in the scene."; |
| 44 | +} |
| 45 | + |
| 46 | +void SceneCheckCollisionPipelineAndModels::doInit(Node* node) |
| 47 | +{ |
| 48 | + SOFA_UNUSED(node); |
| 49 | +} |
| 50 | + |
| 51 | +void SceneCheckCollisionPipelineAndModels::doCheckOn(Node* node) |
| 52 | +{ |
| 53 | + const sofa::core::objectmodel::BaseContext* root = node->getContext()->getRootContext(); |
| 54 | + |
| 55 | + if(!root) |
| 56 | + { |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + sofa::core::collision::Pipeline::SPtr anyPipeline{}; |
| 61 | + root->get(anyPipeline, sofa::core::objectmodel::BaseContext::SearchDirection::SearchDown); |
| 62 | + sofa::core::CollisionModel::SPtr anyCollisionModel{}; |
| 63 | + root->get(anyCollisionModel, sofa::core::objectmodel::BaseContext::SearchDirection::SearchDown); |
| 64 | + |
| 65 | + if(anyPipeline) |
| 66 | + { |
| 67 | + if(anyCollisionModel) |
| 68 | + { |
| 69 | + // there is a collision pipeline and (at least one) collision model(s), carry on. |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + // there is a collision pipeline but no collision model. |
| 74 | + // Either the collision pipeline is superfluous; |
| 75 | + // or the collision model(s) has been forgotten. |
| 76 | + m_message = "There is no collision model in this scene, but there is a collision pipeline. Either add one collision model or remove the collision pipeline."; |
| 77 | + } |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + if(anyCollisionModel) |
| 82 | + { |
| 83 | + // At least one collision model has been detected but without any pipeline. |
| 84 | + // Either the collision pipeline has been forgotten; |
| 85 | + // or the collision model(s) is useless. |
| 86 | + m_message = "At least one collision model has been found, but there is no collision pipeline. You may add a collision pipeline (or remove the collision model if it is not used)."; |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + // there is no collision pipeline and no collision model, the scene certainly does not involve any collision feature. |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +void SceneCheckCollisionPipelineAndModels::doPrintSummary() |
| 96 | +{ |
| 97 | + if(!m_message.empty()) |
| 98 | + { |
| 99 | + msg_warning(this->getName()) << m_message; |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | + |
| 104 | +} // namespace sofa::_scenechecking_ |
0 commit comments