ifcplusplus icon indicating copy to clipboard operation
ifcplusplus copied to clipboard

WriterStep export unreadable IFC

Open ghost opened this issue 7 years ago • 4 comments

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.

  1. 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";

  2. 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); } }

  3. 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

ghost avatar Oct 30 '18 11:10 ghost

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

ifcquery avatar Nov 01 '18 17:11 ifcquery

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

ghost avatar Nov 02 '18 08:11 ghost

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?

ifcquery avatar Nov 12 '18 21:11 ifcquery

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 

ghost avatar Nov 13 '18 08:11 ghost