2013-03-24 10:48:39 +00:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
2019-02-08 15:18:55 +01:00
|
|
|
#include "OpenCascadeBasedSerializer.h"
|
|
|
|
|
|
|
|
|
|
#include "../ifcparse/utils.h"
|
|
|
|
|
|
2013-03-24 10:48:39 +00:00
|
|
|
#include <string>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
2015-02-06 14:20:33 +00:00
|
|
|
#include <Standard_Version.hxx>
|
2017-12-20 12:40:15 +01:00
|
|
|
#include <BRepBuilderAPI_Transform.hxx>
|
2015-02-06 14:20:33 +00:00
|
|
|
|
2013-03-24 10:48:39 +00:00
|
|
|
bool OpenCascadeBasedSerializer::ready() {
|
2019-02-08 15:18:55 +01:00
|
|
|
std::ofstream test_file(IfcUtil::path::from_utf8(out_filename).c_str(), std::ios_base::binary);
|
2013-03-24 10:48:39 +00:00
|
|
|
bool succeeded = test_file.is_open();
|
|
|
|
|
test_file.close();
|
2019-02-08 15:18:55 +01:00
|
|
|
IfcUtil::path::delete_file(out_filename);
|
2013-03-24 10:48:39 +00:00
|
|
|
return succeeded;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 11:03:35 +02:00
|
|
|
void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement<double>* o) {
|
2017-12-20 12:40:15 +01:00
|
|
|
TopoDS_Shape compound = o->geometry().as_compound();
|
2020-01-07 15:37:22 +01:00
|
|
|
gp_Trsf trsf = o->transformation().data();
|
|
|
|
|
const IfcGeom::ElementSettings& settings = o->geometry().settings();
|
|
|
|
|
if (settings.get(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS) && settings.unit_magnitude() != 1.0) {
|
|
|
|
|
trsf.SetTranslationPart(trsf.TranslationPart() / settings.unit_magnitude());
|
2013-03-24 10:48:39 +00:00
|
|
|
}
|
2020-03-18 10:12:54 +01:00
|
|
|
writeShape(object_id(o), compound.Moved(trsf));
|
2013-03-24 10:48:39 +00:00
|
|
|
}
|
2013-12-31 14:10:38 +00:00
|
|
|
|
|
|
|
|
#define RATHER_SMALL (1e-3)
|
2015-02-06 15:56:07 +00:00
|
|
|
#define APPROXIMATELY_THE_SAME(a,b) (fabs(a-b) < RATHER_SMALL)
|
2013-12-31 14:10:38 +00:00
|
|
|
|
|
|
|
|
const char* OpenCascadeBasedSerializer::getSymbolForUnitMagnitude(float mag) {
|
2015-02-06 15:56:07 +00:00
|
|
|
if (APPROXIMATELY_THE_SAME(mag, 0.001f)) {
|
2013-12-31 14:10:38 +00:00
|
|
|
return "MM";
|
2015-02-06 15:56:07 +00:00
|
|
|
} else if (APPROXIMATELY_THE_SAME(mag, 0.01f)) {
|
2013-12-31 14:10:38 +00:00
|
|
|
return "CM";
|
2015-02-06 15:56:07 +00:00
|
|
|
} else if (APPROXIMATELY_THE_SAME(mag, 1.0f)) {
|
2013-12-31 14:10:38 +00:00
|
|
|
return "M";
|
2015-02-06 15:56:07 +00:00
|
|
|
} else if (APPROXIMATELY_THE_SAME(mag, 0.3048f)) {
|
2013-12-31 14:10:38 +00:00
|
|
|
return "FT";
|
2015-02-06 15:56:07 +00:00
|
|
|
} else if (APPROXIMATELY_THE_SAME(mag, 0.0254f)) {
|
2013-12-31 14:10:38 +00:00
|
|
|
return "INCH";
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|