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/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
2015-02-06 14:20:33 +00:00
|
|
|
#include <Standard_Version.hxx>
|
|
|
|
|
|
2013-03-24 10:48:39 +00:00
|
|
|
#include "OpenCascadeBasedSerializer.h"
|
|
|
|
|
|
|
|
|
|
bool OpenCascadeBasedSerializer::ready() {
|
|
|
|
|
std::ofstream test_file(out_filename.c_str(), std::ios_base::binary);
|
|
|
|
|
bool succeeded = test_file.is_open();
|
|
|
|
|
test_file.close();
|
|
|
|
|
remove(out_filename.c_str());
|
|
|
|
|
return succeeded;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-10 17:00:06 +02:00
|
|
|
void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement<real_t>* o) {
|
2014-12-19 12:14:36 +00:00
|
|
|
for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
|
2013-05-05 08:49:25 +00:00
|
|
|
gp_GTrsf gtrsf = it->Placement();
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-10-13 11:15:45 +02:00
|
|
|
const gp_Trsf& o_trsf = o->transformation().data();
|
2013-05-11 10:03:20 +00:00
|
|
|
gtrsf.PreMultiply(o_trsf);
|
2015-12-01 11:14:50 +01:00
|
|
|
|
2016-03-07 22:37:36 +02:00
|
|
|
if (o->geometry().settings().get(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS)) {
|
2015-12-01 11:14:50 +01:00
|
|
|
gp_Trsf scale;
|
|
|
|
|
scale.SetScaleFactor(1.0 / o->geometry().settings().unit_magnitude());
|
|
|
|
|
gtrsf.PreMultiply(scale);
|
|
|
|
|
}
|
2014-11-04 12:36:59 +00:00
|
|
|
|
2016-05-03 11:01:47 +02:00
|
|
|
const TopoDS_Shape& s = it->Shape();
|
|
|
|
|
const TopoDS_Shape moved_shape = IfcGeom::Kernel::apply_transformation(s, gtrsf);
|
2013-03-24 10:48:39 +00:00
|
|
|
|
|
|
|
|
writeShape(moved_shape);
|
|
|
|
|
}
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|