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>
|
|
|
|
|
|
|
|
|
|
#include <BRepBuilderAPI_GTransform.hxx>
|
|
|
|
|
#include <BRepBuilderAPI_Transform.hxx>
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
void OpenCascadeBasedSerializer::write(const IfcGeom::ShapeModelElement<double>* o) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
const std::vector<double>& matrix = o->transformation().matrix().data();
|
2013-05-11 10:03:20 +00:00
|
|
|
|
2014-11-04 12:36:59 +00:00
|
|
|
// Convert the matrix back into a transformation object. The tolerance values
|
|
|
|
|
// are taken into consideration to reconstruct the form of the transformation.
|
|
|
|
|
gp_Trsf o_trsf;
|
|
|
|
|
o_trsf.SetValues(
|
2014-12-19 12:14:36 +00:00
|
|
|
matrix[0], matrix[3], matrix[6], matrix[ 9],
|
|
|
|
|
matrix[1], matrix[4], matrix[7], matrix[10],
|
|
|
|
|
matrix[2], matrix[5], matrix[8], matrix[11],
|
2014-11-04 12:36:59 +00:00
|
|
|
1e-5, 1e-5
|
|
|
|
|
);
|
2013-05-11 10:03:20 +00:00
|
|
|
gtrsf.PreMultiply(o_trsf);
|
2014-11-04 12:36:59 +00:00
|
|
|
|
2013-05-05 08:49:25 +00:00
|
|
|
const TopoDS_Shape& s = it->Shape();
|
2013-03-24 10:48:39 +00:00
|
|
|
|
|
|
|
|
bool trsf_valid = false;
|
|
|
|
|
gp_Trsf trsf;
|
|
|
|
|
try {
|
|
|
|
|
trsf = gtrsf.Trsf();
|
|
|
|
|
trsf_valid = true;
|
|
|
|
|
} catch (...) {}
|
|
|
|
|
|
|
|
|
|
const TopoDS_Shape moved_shape = trsf_valid
|
|
|
|
|
? BRepBuilderAPI_Transform(s, trsf, true).Shape()
|
|
|
|
|
: BRepBuilderAPI_GTransform(s, gtrsf, true).Shape();
|
|
|
|
|
|
|
|
|
|
writeShape(moved_shape);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-31 14:10:38 +00:00
|
|
|
|
|
|
|
|
#define RATHER_SMALL (1e-3)
|
|
|
|
|
#define ALMOST_THE_SAME(a,b) (fabs(a-b) < RATHER_SMALL)
|
|
|
|
|
|
|
|
|
|
const char* OpenCascadeBasedSerializer::getSymbolForUnitMagnitude(float mag) {
|
|
|
|
|
if (ALMOST_THE_SAME(mag, 0.001f)) {
|
|
|
|
|
return "MM";
|
|
|
|
|
} else if (ALMOST_THE_SAME(mag, 0.01f)) {
|
|
|
|
|
return "CM";
|
|
|
|
|
} else if (ALMOST_THE_SAME(mag, 1.0f)) {
|
|
|
|
|
return "M";
|
|
|
|
|
} else if (ALMOST_THE_SAME(mag, 0.3048f)) {
|
|
|
|
|
return "FT";
|
|
|
|
|
} else if (ALMOST_THE_SAME(mag, 0.0254f)) {
|
|
|
|
|
return "INCH";
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|