MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / box_from_compound

Function box_from_compound

src/serializers/SvgSerializer.cpp:436–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434 };
435
436 boost::optional<box_t> box_from_compound(TopoDS_Shape& compound) {
437 /*
438 // in v0.8 apparently we don't get a solid/shell anymore because
439 // we no longer use PrimAPI, but rather resolve the box to an
440 // explicit shell with 6 faces in the mapping, which - depending
441 // on settings - may remain solely a compound of 6.
442
443 TopExp_Explorer exp(compound, TopAbs_SHELL);
444 TopoDS_Shell shell;
445 if (exp.More()) {
446 shell = TopoDS::Shell(exp.Current());
447 exp.Next();
448 if (exp.More()) {
449 return boost::none;
450 }
451 }
452 else {
453 return boost::none;
454 }
455 */
456 auto& shell = compound;
457
458 if (IfcGeom::util::count(shell, TopAbs_FACE) != 6) {
459 return boost::none;
460 }
461
462 TopExp_Explorer it(shell, TopAbs_FACE);
463 for (; it.More(); it.Next()) {
464 const auto& face = TopoDS::Face(it.Current());
465 auto surf = BRep_Tool::Surface(face);
466 if (surf->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
467 return boost::none;
468 }
469 auto pln = Handle(Geom_Plane)::DownCast(surf);
470 auto dz = std::abs(pln->Position().Direction().Z());
471 if (almost(0.) != dz && almost(1.) != dz) {
472 return boost::none;
473 }
474 auto dy = std::abs(pln->Position().Direction().Y());
475 if (almost(0.) != dy && almost(1.) != dy) {
476 return boost::none;
477 }
478 }
479
480 Bnd_Box b;
481 BRepBndLib::Add(compound, b, false);
482
483 double x0, y0, z0, x1, y1, z1;
484 b.Get(x0, y0, z0, x1, y1, z1);
485
486 return box_t{ {{x0, y0, z0}}, {{x1, y1, z1}} };
487 }
488
489 struct string_property {
490 std::string pset_name, prop_name, value;

Callers 1

writeMethod · 0.85

Calls 5

HandleFunction · 0.85
almostClass · 0.85
MoreMethod · 0.80
GetMethod · 0.80
NextMethod · 0.45

Tested by

no test coverage detected