WriterStep export unreadable IFC
Hello,
I wrote a little peace of code to export an IFC file that was imported before without any changes. Something like :
std::shared_ptr<BuildingModel> model{ new BuildingModel };
ReaderSTEP reader;
reader.loadModelFromFile(infilename, model);
WriterSTEP writer;
std::stringstream fileout;
writer.writeModelToStream(fileout, model);
std::ofstream outFile;
outFile.open(outfilename);
outFile << fileout.rdbuf();
outFile.close();
The code works but I found several bugs in the exported file. Here is how I fixed the found problems.
-
in WriterSTEP.cpp method writeModelToStream I changed this :
stream << file_header_str.c_str(); stream << "DATA;\n";
to this :
stream << "ISO-10303-21;\n"; stream << "HEADER;\n"; stream << file_header_str.c_str(); stream << "ENDSEC;\nDATA;\n";
-
In WriterUtil.h & .cpp I changed method encodeStepString to have a new bool parameter :
std::string encodeStepString(const std::wstring& str,bool removeQuotes);
and at the end of the method, added this piece of code just before return :
// remove quotes if ((removeQuotes) && result_str.length()>1) { if ((result_str[0] == ''') && (result_str[result_str.length() - 1] == ''')) { result_str = result_str.substr(1, result_str.length() - 2); } }
-
And finally I replaced every line looking like this :
stream << "'" << encodeStepString( m_value) << "'";
by this one :
stream << "'" << encodeStepString( m_value, true) << "'";
I have tested on several IFC files and it seems to work.
Regards,
Stéphane
Hi, thanks for your suggestion.
Did you consider the function void BuildingModel::initFileHeader( std::wstring file_name )?
There is also something like strs << "ISO-10303-21;" << std::endl; ... etc
If there is something wrong with that, I would prefer to fix the method BuildingModel::initFileHeader instead of adding it to WriterSTEP.
Regards, Fabian
Thanks Fabian for your answer.
I didn't used BuildingModel::initFileHeader( std::wstring file_name ) method.
As there is this line :
stream << "ENDSEC;\nEND-ISO-10303-21;\n";
at the end of method void WriterSTEP::writeModelToStream( std::stringstream& stream, shared_ptr<BuildingModel> model )
It seemed logic to me, but I've just tried a quick fix, so all other better way to fix the problem is OK for me.
The main problem was the double quotes around some strings that I fixed with points 2) and 3). For those points I also tried a quick fix but other fixes are fine :-)
Stéphane
I don't quite understand what you mean about the line stream << "ENDSEC;\nEND-ISO-10303-21;\n"; There needs to be an ENDSEC, right?
Hello, I just mean that as this line (stream << "ENDSEC;\nEND-ISO-10303-21;\n";) was already set at the end of the method WriterSTEP::writeModelToStream, it seamed logic to me (for code symmetry) that "stream << "ISO-10303-21;\n";" was also set in this same method.
Stéphane