2014-12-19 12:14:36 +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 <BRep_Tool.hxx>
|
|
|
|
|
#include <BRepTools.hxx>
|
|
|
|
|
#include <BRep_Builder.hxx>
|
|
|
|
|
|
|
|
|
|
#include <TopoDS_Compound.hxx>
|
|
|
|
|
|
|
|
|
|
#include "../ifcgeom/IfcGeom.h"
|
|
|
|
|
|
|
|
|
|
#include "IfcGeomRepresentation.h"
|
|
|
|
|
|
|
|
|
|
IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
|
|
|
|
|
: Representation(brep.settings())
|
2017-06-28 15:24:49 +02:00
|
|
|
, id_(brep.id())
|
2014-12-19 12:14:36 +00:00
|
|
|
{
|
2017-09-13 13:16:58 +02:00
|
|
|
TopoDS_Compound compound = brep.as_compound();
|
2015-02-20 18:06:52 +00:00
|
|
|
for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = brep.begin(); it != brep.end(); ++ it) {
|
2016-04-11 11:50:43 +02:00
|
|
|
if (it->hasStyle() && it->Style().Diffuse()) {
|
|
|
|
|
const IfcGeom::SurfaceStyle::ColorComponent& clr = *it->Style().Diffuse();
|
2017-06-28 15:24:49 +02:00
|
|
|
surface_styles_.push_back(clr.R());
|
|
|
|
|
surface_styles_.push_back(clr.G());
|
|
|
|
|
surface_styles_.push_back(clr.B());
|
2016-04-11 11:50:43 +02:00
|
|
|
} else {
|
2017-06-28 15:24:49 +02:00
|
|
|
surface_styles_.push_back(-1.);
|
|
|
|
|
surface_styles_.push_back(-1.);
|
|
|
|
|
surface_styles_.push_back(-1.);
|
2016-04-11 11:50:43 +02:00
|
|
|
}
|
|
|
|
|
if (it->hasStyle() && it->Style().Transparency()) {
|
2017-06-28 15:24:49 +02:00
|
|
|
surface_styles_.push_back(1. - *it->Style().Transparency());
|
2016-04-11 11:50:43 +02:00
|
|
|
} else {
|
2017-06-28 15:24:49 +02:00
|
|
|
surface_styles_.push_back(1.);
|
2016-04-11 11:50:43 +02:00
|
|
|
}
|
2017-09-13 13:16:58 +02:00
|
|
|
}
|
|
|
|
|
std::stringstream sstream;
|
|
|
|
|
BRepTools::Write(compound,sstream);
|
|
|
|
|
brep_data_ = sstream.str();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 16:38:55 +01:00
|
|
|
// todo copied from kernel
|
|
|
|
|
#include <BRepBuilderAPI_Transform.hxx>
|
|
|
|
|
#include <BRepBuilderAPI_GTransform.hxx>
|
|
|
|
|
|
|
|
|
|
TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const gp_Trsf& t) {
|
|
|
|
|
if (t.Form() == gp_Identity) {
|
|
|
|
|
return s;
|
|
|
|
|
} else {
|
|
|
|
|
/// @todo set to 1. and exactly 1. or use epsilon?
|
|
|
|
|
if (t.ScaleFactor() != 1.) {
|
|
|
|
|
return BRepBuilderAPI_Transform(s, t, true);
|
|
|
|
|
} else {
|
|
|
|
|
return s.Moved(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const gp_GTrsf& t) {
|
|
|
|
|
if (t.Form() == gp_Other) {
|
|
|
|
|
return BRepBuilderAPI_GTransform(s, t, true);
|
|
|
|
|
} else {
|
|
|
|
|
return apply_transformation(s, t.Trsf());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-13 13:16:58 +02:00
|
|
|
TopoDS_Compound IfcGeom::Representation::BRep::as_compound() const {
|
|
|
|
|
TopoDS_Compound compound;
|
|
|
|
|
BRep_Builder builder;
|
|
|
|
|
builder.MakeCompound(compound);
|
|
|
|
|
for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = begin(); it != end(); ++it) {
|
|
|
|
|
const TopoDS_Shape& s = it->Shape();
|
|
|
|
|
gp_GTrsf trsf = it->Placement();
|
|
|
|
|
|
2016-03-07 22:37:36 +02:00
|
|
|
if (settings().get(IteratorSettings::CONVERT_BACK_UNITS)) {
|
2014-12-19 12:14:36 +00:00
|
|
|
gp_Trsf scale;
|
|
|
|
|
scale.SetScaleFactor(1.0 / settings().unit_magnitude());
|
|
|
|
|
trsf.PreMultiply(scale);
|
|
|
|
|
}
|
2016-05-03 11:01:47 +02:00
|
|
|
|
2017-12-20 16:38:55 +01:00
|
|
|
const TopoDS_Shape moved_shape = apply_transformation(s, trsf);
|
2016-05-03 11:01:47 +02:00
|
|
|
builder.Add(compound, moved_shape);
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
2017-09-13 13:16:58 +02:00
|
|
|
return compound;
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|