2022-06-14 15:02:54 +02: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/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
#include "mapping.h"
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
#define mapping POSTFIX_SCHEMA(mapping)
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
using namespace ifcopenshell::geometry;
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
namespace {
|
|
|
|
|
taxonomy::boolean_result::operation_t boolean_op_type(IfcSchema::IfcBooleanOperator::Value op) {
|
|
|
|
|
if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_DIFFERENCE) {
|
|
|
|
|
return taxonomy::boolean_result::SUBTRACTION;
|
|
|
|
|
} else if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_INTERSECTION) {
|
|
|
|
|
return taxonomy::boolean_result::INTERSECTION;
|
|
|
|
|
} else if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_UNION) {
|
|
|
|
|
return taxonomy::boolean_result::UNION;
|
|
|
|
|
} else {
|
|
|
|
|
throw taxonomy::topology_error("Unknown boolean operation");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 16:42:06 +08:00
|
|
|
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcBooleanResult* inst) {
|
2023-03-21 20:15:01 +01:00
|
|
|
IfcSchema::IfcBooleanOperand* operand1 = inst->FirstOperand();
|
|
|
|
|
IfcSchema::IfcBooleanOperand* operand2 = inst->SecondOperand();
|
2022-06-14 15:02:54 +02:00
|
|
|
bool has_halfspace_operand = false;
|
|
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
std::vector<IfcSchema::IfcBooleanOperand*> operands;
|
|
|
|
|
operands.push_back(operand2);
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
auto op = boolean_op_type(inst->Operator());
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
if (op == taxonomy::boolean_result::SUBTRACTION) {
|
2022-06-14 15:02:54 +02:00
|
|
|
int n_half_space_operands = 0;
|
|
|
|
|
bool process_as_list = true;
|
|
|
|
|
while (true) {
|
|
|
|
|
auto res1 = operand1->as<IfcSchema::IfcBooleanResult>();
|
|
|
|
|
if (res1 && res1->SecondOperand()->as<IfcSchema::IfcHalfSpaceSolid>() && ++n_half_space_operands > 8) {
|
|
|
|
|
// There is something peculiar about many half space subtraction operands that OCCT does not like.
|
|
|
|
|
// Often these are used to create a semi-curved arch, as is the case in 693. Supplying all these
|
|
|
|
|
// operands at once apparently leads to too many edge-edge interference checks.
|
2023-03-21 20:15:01 +01:00
|
|
|
|
|
|
|
|
// @todo this should probably be moved to the opencascade kernel and not the mapping.
|
2022-06-14 15:02:54 +02:00
|
|
|
process_as_list = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (res1) {
|
2023-03-21 20:15:01 +01:00
|
|
|
if (boolean_op_type(res1->Operator()) == op) {
|
2022-06-14 15:02:54 +02:00
|
|
|
operand1 = res1->FirstOperand();
|
2023-03-21 20:15:01 +01:00
|
|
|
operands.push_back(res1->SecondOperand());
|
2022-06-14 15:02:54 +02:00
|
|
|
} else {
|
|
|
|
|
process_as_list = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!process_as_list) {
|
2023-03-21 20:15:01 +01:00
|
|
|
operand1 = inst->FirstOperand();
|
|
|
|
|
operands = { operand2 };
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
operands.insert(operands.begin(), operand1);
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
auto br = map_to_collection<taxonomy::boolean_result>(this, &operands);
|
|
|
|
|
if (br) {
|
|
|
|
|
br->operation = op;
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
2023-03-21 20:15:01 +01:00
|
|
|
return br;
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|