Skip to content

Commit ffde865

Browse files
committed
ADD: Prefab states and error msgs updated on reInit
1 parent afe7c3d commit ffde865

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Plugin/src/SofaPython3/Prefab.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ using sofa::core::objectmodel::Event;
2121

2222
void Prefab::init()
2323
{
24-
std::cout << "prefab::init" << std::endl;
2524
reinit();
2625
Inherit1::init(sofa::core::ExecParams::defaultInstance());
26+
m_is_initialized = true;
2727
}
2828

2929
void PrefabFileEventListener::fileHasChanged(const std::string &filename)
@@ -44,21 +44,16 @@ void PrefabFileEventListener::fileHasChanged(const std::string &filename)
4444

4545
void Prefab::reinit()
4646
{
47-
std::cout << "prefab::reinit" << std::endl;
4847
clearLoggedMessages();
4948

5049
/// remove everything in the node.
5150
execute<sofa::simulation::DeleteVisitor>(sofa::core::ExecParams::defaultInstance());
52-
std::cout << "prefab::doReInit" << std::endl;
51+
5352
doReInit();
5453

55-
std::cout << "simulation->initNode" << std::endl;
5654
/// Beurk beurk beurk
5755
sofa::simulation::getSimulation()->initNode(this);
58-
std::cout << "VisualInitVisitor" << std::endl;
5956
execute<VisualInitVisitor>(nullptr);
60-
61-
d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
6257
}
6358

6459
void Prefab::doReInit()
@@ -83,19 +78,18 @@ void Prefab::addPrefabParameter(const std::string& name, const std::string& help
8378
if(!findData(name) && !findLink(name))
8479
{
8580
sofa::core::objectmodel::BaseData* data = sofapython3::addData(py::cast(this), name, py::none(), defaultValue, help, "Prefab's properties", type);
81+
data->setRequired(true);
8682
m_datacallback.addInputs({data});
8783
}
8884
}
8985

9086
void Prefab::setSourceTracking(const std::string& filename)
9187
{
92-
std::cout << "Activating source tracking to " << filename << std::endl;
9388
FileMonitor::addFile(filename, &m_filelistener);
9489
}
9590

9691
void Prefab::breakPrefab()
9792
{
98-
std::cout << "Breaking prefab" << std::endl;
9993
FileMonitor::removeListener(&m_filelistener);
10094
for (auto& data : this->getDataFields())
10195
if (data->getGroup() == "Prefab's properties")

Plugin/src/SofaPython3/Prefab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ class SOFAPYTHON3_API Prefab : public BasePrefab
4848

4949
PrefabFileEventListener m_filelistener;
5050
DataCallback m_datacallback;
51+
bool m_is_initialized {false};
5152
};
5253
} // namespace sofapython3

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Prefab.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,17 @@ class Prefab_Trampoline : public Prefab, public PythonTrampoline
6868

6969
void Prefab_Trampoline::doReInit()
7070
{
71+
if (!m_is_initialized) {
72+
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Loading);
73+
msg_warning(this) << "Prefab instantiated. Check for required prefab parameters to fully populate";
74+
return;
75+
}
7176
try{
77+
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
7278
PYBIND11_OVERLOAD(void, Prefab, doReInit, );
7379
} catch (std::exception& e)
7480
{
81+
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
7582
msg_error(this) << e.what();
7683
}
7784
}

0 commit comments

Comments
 (0)