Files
IfcOpenShell/src/ifcgeom/mapping/IfcIndexedPolyCurve.cpp
T
Petru Conduraru f23db9440f ifcparse: widen all integer attribute types to int64_t for consistency
Follow-up to the scalar-only fix in #8754, per aothms's direct request on
that PR ("Please do make all int types consistent") and his own original
2023 design intent on issue #3058 ("make all integers (incl. schema
namespaces) an int64_t"). Widens the remaining inconsistent spots now that
compatibility isn't a constraint on this v0.9 branch:

- Integer aggregates (IfcTriangulatedFaceSet.CoordIndex and similar
  List<int> attributes), including the SWIG to_vec_int/to_vec_vec_int
  helpers, which previously silently truncated via static_cast<int> on the
  Python-set path - the same bug class as the original scalar issue.
- The schema code generator (express/mapping.py's integer type mapping),
  and all 12 generated schema header/source pairs regenerated to match, so
  every schema-typed getter/setter (e.g. IfcOwnerHistory::CreationDate) is
  int64_t end to end, not just the dynamic attribute-value path.

Instance/reference identifiers (STEP #123 ids) are deliberately left at
32-bit: they're a file-local index into internal maps, not an EXPRESS
domain value an application chooses, and no realistic STEP file has
billions of entities. The lexer's Token_IDENTIFIER parsing still funnels
through a 32-bit int for this reason - flagged as a known, low-risk gap
rather than fixed, since fixing it would mean touching indexing/hashing
code for no realistic benefit.

Verified: original PR's round-trip tests extended with aggregate cases
(IfcTriangulatedFaceSet.CoordIndex, InnerCoordIndices) at 64-bit boundary
values, in memory and through STEP text, IFC2X3 and IFC4. A standalone C++
program exercising the generated schema API directly (Ifc4::IfcOwnerHistory
::setCreationDate/CreationDate, IfcTriangulatedFaceSet::setCoordIndex/
CoordIndex) confirms int64_t end to end, bypassing SWIG. Full build
(BUILD_IFCGEOM, WITH_OPENCASCADE, BUILD_IFCPYTHON, IFC2X3+IFC4) clean.
test/util/test_attribute.py and test_file.py pass unchanged.

This contribution was produced with the assistance of an AI coding tool.
2026-07-19 13:54:16 +02:00

108 lines
4.6 KiB
C++

/********************************************************************************
* *
* 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 "mapping.h"
#define mapping POSTFIX_SCHEMA(mapping)
using namespace ifcopenshell::geometry;
#ifdef SCHEMA_HAS_IfcIndexedPolyCurve
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcIndexedPolyCurve& inst) {
auto point_list = inst.Points();
std::vector< std::vector<double> > coordinates;
if (point_list.as<IfcSchema::IfcCartesianPointList2D>()) {
coordinates = point_list.as<IfcSchema::IfcCartesianPointList2D>().CoordList();
} else if (point_list.as<IfcSchema::IfcCartesianPointList3D>()) {
coordinates = point_list.as<IfcSchema::IfcCartesianPointList3D>().CoordList();
}
std::vector<taxonomy::point3::ptr> points;
if (coordinates.size() < 2) {
throw ifcopenshell::exception("IfcIndexedPolyCurve has less than 2 points.");
}
points.reserve(coordinates.size());
for (auto& coords : coordinates) {
points.push_back(taxonomy::make<taxonomy::point3>(
coords.size() < 1 ? 0. : coords[0] * length_unit_,
coords.size() < 2 ? 0. : coords[1] * length_unit_,
coords.size() < 3 ? 0. : coords[2] * length_unit_));
}
int max_index = (int) points.size();
auto loop = taxonomy::make<taxonomy::loop>();
if(inst.Segments()) {
auto segments = inst.Segments();
for (auto& segment : *segments) {
if (auto line = segment.as<IfcSchema::IfcLineIndex>()) {
std::vector<int64_t> indices = line;
taxonomy::point3::ptr previous;
for (std::vector<int64_t>::const_iterator jt = indices.begin(); jt != indices.end(); ++jt) {
if (*jt < 1 || *jt > max_index) {
throw ifcopenshell::exception("IfcIndexedPolyCurve index out of bounds for index " + boost::lexical_cast<std::string>(*jt));
}
auto current = points[*jt - 1];
if (jt != indices.begin()) {
loop->children.push_back(taxonomy::make<taxonomy::edge>(previous, current));
}
previous = current;
}
} else if (auto arc = segment.as<IfcSchema::IfcArcIndex>()) {
std::vector<int64_t> indices = arc;
if (indices.size() != 3) {
throw ifcopenshell::exception("Invalid IfcArcIndex encountered");
}
for (int i = 0; i < 3; ++i) {
const int64_t& idx = indices[i];
if (idx < 1 || idx > max_index) {
throw ifcopenshell::exception("IfcIndexedPolyCurve index out of bounds for index " + boost::lexical_cast<std::string>(idx));
}
}
const auto& a = points[indices[0] - 1];
const auto& b = points[indices[1] - 1];
const auto& c = points[indices[2] - 1];
auto circ = taxonomy::circle::from_3_points(a->ccomponents(), b->ccomponents(), c->ccomponents());
if (circ) {
auto e = taxonomy::make<taxonomy::edge>(a, c);
e->basis = circ;
loop->children.push_back(e);
} else {
logger_.warning("GEO", 263, "Ignoring segment on", inst);
}
} else {
throw ifcopenshell::exception("Unexpected IfcIndexedPolyCurve segment of type " + segment.concrete().declaration().name());
}
}
} else if (points.begin() < points.end()) {
auto previous = points.begin();
for (auto current = previous+1; current < points.end(); ++current){
loop->children.push_back(taxonomy::make<taxonomy::edge>(*previous, *current));
previous = current;
}
}
return loop;
}
#endif