-
Notifications
You must be signed in to change notification settings - Fork 239
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
Expansion of GoCAD interface #2586
Conversation
parseLine(in, nodes, elems, node_id_map, mesh_prop); | ||
return true; | ||
} | ||
else if (line == "END") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else after a return is not needed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
@@ -108,7 +160,21 @@ MeshLib::Mesh* GocadTSurfaceReader::readMesh(std::ifstream& in, | |||
return nullptr; | |||
} | |||
} | |||
else if (str[0] == "TFACE") | |||
else if (type == GOCAD_DATA_TYPE::PLINE && str[0] == "ILINE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copy of the following if for TSURF. Please avoid code duplications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplication is indeed resolved, but now the mesh creation logic is mixed up with the parsing of the cases. It is difficult to add new cases there.
It's up to you, but I'd have written something like
auto parse_mesh = [&](auto node_element_parser) {
std::vector<MeshLib::Node*> nodes;
std::vector<MeshLib::Element*> elems;
std::map<std::size_t, std::size_t> node_id_map;
if (!node_element_parser(in, nodes, elems, node_id_map, mesh_prop))
{
ERR(...);
return nullptr;
}
return std::make_unique<MeshLib::Mesh>(mesh_name, ...);
};
And in the conditions:
if (type == TFACE)
{
return parse_mesh(parseSurface);
}
if (type == PLINE)
{
return parse_mesh(parseLine);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I have no idea what happens there. And I know that it's difficult to add cases now, that's why it was written before such that cases were independent of each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more specific, I'd very much prefer the code the way it was originally written. That'd be six lines of duplicate code, which isn't a big issue in my opinion if it means the code is easier to read.
std::map<std::size_t, std::size_t> const& node_id_map, | ||
MeshLib::Properties& mesh_prop) | ||
{ | ||
std::string keyword; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please constrain variables to minimum possible scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for data
array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
clang-format |
WARN( | ||
"GocadTSurfaceReader::parseNodes() - Unknown keyword found: %s", | ||
line.c_str()); | ||
WARN("GocadTSurfaceReader::parseNodes() - Unknown keyword found: %s", line.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GocadTSurfaceReader -> GocadAsciiReader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
} | ||
if (line.substr(0, 13) == "GOCAD Model3d") | ||
else if (line.substr(0, 11) == "GOCAD PLine") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this string to enum conversion to the place where the enum is defined.
Also no else after return is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you suggest that I should implement a enum -> string conversion for this one use?
The return does not follow "else" but "while" and is required in case the end of the file is reached.
GocadAsciiReader::GocadAsciiReader() | ||
: _export_type(GocadDataType::ALL) {} | ||
|
||
GocadAsciiReader::GocadAsciiReader(GocadDataType const t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GocadAsciiReader::GocadAsciiReader(GocadDataType const t) | |
GocadAsciiReader::GocadAsciiReader(GocadDataType const t = GocadDataType::ALL) |
... then the default ctor is not needed.
(Sorry, wrong place, goes into the header file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
if (!skipToEND(in)) | ||
{ | ||
std::string const t = (type == GocadDataType::VSET) ? "VSet" : "Model3D"; | ||
ERR("Parsing of type %s is not implemented. Skipping section.", t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERR("Parsing of type %s is not implemented. Skipping section.", t); | |
ERR("Parsing of type %s is not implemented. Skipping section.", t.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
The file
|
}; | ||
|
||
/// Given a Gocad DataType this returns the appropriate string. | ||
std::string DataType2Str(DataType const t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string DataType2Str(DataType const t); | |
std::string dataType2String(DataType const t); |
{ | ||
return "model"; | ||
} | ||
return "[all data]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all data
vs. all types
above. Maybe wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomFischer when OK, merge.
a50fcd9
to
701de2c
Compare
OpenGeoSys development has been moved to GitLab. |
Can now also parse GoCAD PLine data.
Also added a check if multiple data sets in the same file have the same name and if so append a UID, so files don't get overwritten on export.