Skip to content

Commit

Permalink
Fixed the automatic setting of USED when adding new values for rotations
Browse files Browse the repository at this point in the history
  • Loading branch information
pariterre committed May 17, 2022
1 parent 70ea0c9 commit 0d7e36e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/ezc3d/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{

protected:
///
/// \brief Add all required parameter for a c3d to be valid
/// \brief Add all required parameters for a c3d to be valid
///
void setMandatoryParameters();

///
/// \brief Set the required parameters for some specific but non-mandatory groups
/// \param groupName The name of the group to add to the c3d
///
void setMandatoryParametersForSpecialGroup(
const std::string& groupName);

//---- STREAM ----//
public:
///
Expand Down
43 changes: 43 additions & 0 deletions src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,46 @@ void ezc3d::ParametersNS::Parameters::setMandatoryParameters() {
}
}

void ezc3d::ParametersNS::Parameters::setMandatoryParametersForSpecialGroup(
const std::string& groupName) {
// Mandatory groups
if (!groupName.compare("ROTATION"))
{
if (!isGroup("ROTATION")){
group(ezc3d::ParametersNS::GroupNS::Group ("ROTATION"));
}

ezc3d::ParametersNS::GroupNS::Group& grp(group("ROTATION"));
if (!grp.isParameter("USED")){
ezc3d::ParametersNS::GroupNS::Parameter p("USED", "");
p.set(0);
grp.parameter(p);
}
if (!grp.isParameter("DATA_START")){
ezc3d::ParametersNS::GroupNS::Parameter p("DATA_START", "");
p.set(std::vector<int>()={1});
grp.parameter(p);
}
if (!grp.isParameter("RATE")){
// Double is better as default than RATIO as RATIO is chosen in
// priority when writing.
ezc3d::ParametersNS::GroupNS::Parameter p("RATE", "");
p.set(std::vector<double>()=group("POINT").parameter("RATE").valuesAsDouble());
grp.parameter(p);
}
if (!grp.isParameter("LABELS")){
ezc3d::ParametersNS::GroupNS::Parameter p("LABELS", "");
p.set(std::vector<std::string>()={});
grp.parameter(p);
}
if (!grp.isParameter("DESCRIPTIONS")){
ezc3d::ParametersNS::GroupNS::Parameter p("DESCRIPTIONS", "");
p.set(std::vector<double>()={});
grp.parameter(p);
}
}
}

void ezc3d::ParametersNS::Parameters::print() const {
std::cout << "Parameters header" << "\n";
std::cout << "parametersStart = " << parametersStart() << "\n";
Expand Down Expand Up @@ -562,6 +602,9 @@ void ezc3d::ParametersNS::Parameters::group(
for (size_t i=0; i < g.nbParameters(); ++i)
_groups[alreadyExtIdx].parameter(g.parameter(i));
}

// Do a sanity check for some specific group
setMandatoryParametersForSpecialGroup(g.name());
}

void ezc3d::ParametersNS::Parameters::remove(
Expand Down
8 changes: 8 additions & 0 deletions src/ezc3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,5 +1011,13 @@ void ezc3d::c3d::updateParameters(
}
}
}

// Adjust some ROTATION parameters
if (_parameters->isGroup("ROTATION")){
ezc3d::ParametersNS::GroupNS::Group& grpRotation(
_parameters->group(parameters().groupIdx("ROTATION")));
grpRotation.parameter("USED").set(_data->frame(0).rotations().subframe(0).nbRotations());
}

updateHeader();
}

0 comments on commit 0d7e36e

Please sign in to comment.