Files
IfcOpenShell/src/serializers/open_cascade_based_serializer.cpp
T

70 lines
2.8 KiB
C++
Raw Normal View History

/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
2023-03-22 11:17:14 +01:00
#ifdef IFOPSH_WITH_OPENCASCADE
2026-08-08 14:19:57 +02:00
#include "open_cascade_based_serializer.h"
2019-02-08 15:18:55 +01:00
#include "../ifcparse/utils.h"
2026-08-08 14:19:57 +02:00
#include "../ifcgeom/kernels/opencascade/opencascade_conversion_result.h"
2019-02-08 15:18:55 +01:00
#include <string>
#include <fstream>
#include <cstdio>
#include <Standard_Version.hxx>
2017-12-20 12:40:15 +01:00
#include <BRepBuilderAPI_Transform.hxx>
2026-08-08 07:42:45 +02:00
bool open_cascade_based_serializer::ready() {
2026-03-31 15:32:36 +02:00
std::ofstream test_file(ifcopenshell::path::from_utf8(out_filename).c_str(), std::ios_base::binary);
bool succeeded = test_file.is_open();
test_file.close();
2026-03-31 15:32:36 +02:00
ifcopenshell::path::delete_file(out_filename);
return succeeded;
}
2026-08-08 07:42:45 +02:00
void open_cascade_based_serializer::write(const ifcopenshell::geom::brep_element* o) {
2023-03-21 20:15:01 +01:00
auto itm = o->geometry().as_compound();
2026-08-08 07:42:45 +02:00
TopoDS_Shape compound = ((ifcopenshell::geom::open_cascade_shape*)itm)->shape();
2023-03-21 20:15:01 +01:00
writeShape(object_id(o), compound);
delete itm;
}
#define RATHER_SMALL (1e-3)
2015-02-06 15:56:07 +00:00
#define APPROXIMATELY_THE_SAME(a,b) (fabs(a-b) < RATHER_SMALL)
2026-08-08 07:42:45 +02:00
const char* open_cascade_based_serializer::getSymbolForUnitMagnitude(float mag) {
2015-02-06 15:56:07 +00:00
if (APPROXIMATELY_THE_SAME(mag, 0.001f)) {
return "MM";
2015-02-06 15:56:07 +00:00
} else if (APPROXIMATELY_THE_SAME(mag, 0.01f)) {
return "CM";
2015-02-06 15:56:07 +00:00
} else if (APPROXIMATELY_THE_SAME(mag, 1.0f)) {
return "M";
2015-02-06 15:56:07 +00:00
} else if (APPROXIMATELY_THE_SAME(mag, 0.3048f)) {
return "FT";
2015-02-06 15:56:07 +00:00
} else if (APPROXIMATELY_THE_SAME(mag, 0.0254f)) {
return "INCH";
} else {
return 0;
}
}
2023-03-22 11:17:14 +01:00
#endif