mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-15 18:14:08 +00:00
Initial attempt at new python wrapper
This commit is contained in:
@@ -355,6 +355,10 @@ class Classdef:
|
||||
parent_relations[self.class_name] = self.parent_class
|
||||
argument_count[self.class_name] = len(self.arguments)
|
||||
entity_map[self.class_name] = self
|
||||
def get_attributes(self, get_parent=True):
|
||||
s = entity_map[self.parent_class].get_attributes() if get_parent and self.parent_class else []
|
||||
s += [(a.name,not not a.optional,a.type.type_enum()) for a in self.arguments.l]
|
||||
return s
|
||||
def get_constructor_args(self):
|
||||
s = entity_map[self.parent_class].get_constructor_args() if self.parent_class else []
|
||||
i = len(s) + 1
|
||||
@@ -476,8 +480,10 @@ schema_version = schema_version.capitalize()
|
||||
# Writing of the three generated files starts here
|
||||
#
|
||||
h_file = open("%s.h"%schema_version,'w')
|
||||
h2_file = open("%s-rt.h"%schema_version,'w')
|
||||
enumh_file = open("%senum.h"%schema_version,'w')
|
||||
cpp_file = open("%s.cpp"%schema_version,'w')
|
||||
cpp2_file = open("%s-rt.cpp"%schema_version,'w')
|
||||
|
||||
header += """
|
||||
|
||||
@@ -492,19 +498,23 @@ header += """
|
||||
generator_mode = 'HEADER'
|
||||
|
||||
print >>h_file, header
|
||||
print >>h2_file, header
|
||||
print >>enumh_file, header
|
||||
print >>cpp_file, header
|
||||
print >>cpp2_file, header
|
||||
print >>h_file, """#ifndef %(schema_upper)s_H
|
||||
#define %(schema_upper)s_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
#include "../ifcparse/%(schema)senum.h"
|
||||
|
||||
using namespace IfcUtil;
|
||||
@@ -540,6 +550,8 @@ all_enumerations = simple_enumerations + entity_enumerations
|
||||
print >>enumh_file, """#ifndef IFC2X3ENUM_H
|
||||
#define IFC2X3ENUM_H
|
||||
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
|
||||
namespace Ifc2x3 {
|
||||
|
||||
namespace Type {
|
||||
@@ -556,6 +568,22 @@ namespace Type {
|
||||
|
||||
#endif
|
||||
"""%{'schema_upper':schema_version.upper(),'schema':schema_version,'enum':", ".join(all_enumerations + ["ALL"])}
|
||||
print >>h2_file, """#ifndef IFC2X3RT_H
|
||||
#define IFC2X3RT_H
|
||||
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
|
||||
namespace Ifc2x3 {
|
||||
namespace Type {
|
||||
int GetAttributeCount(Enum t);
|
||||
int GetAttributeIndex(Enum t, const std::string& a);
|
||||
IfcUtil::ArgumentType GetAttributeType(Enum t, unsigned char a);
|
||||
const std::string& GetAttributeName(Enum t, unsigned char a);
|
||||
bool GetAttributeOptional(Enum t, unsigned char a);
|
||||
}}
|
||||
|
||||
#endif
|
||||
"""
|
||||
|
||||
defined_types = set(express_to_cpp.values())
|
||||
deferred_types = []
|
||||
@@ -585,16 +613,31 @@ while True:
|
||||
print >>h_file, c
|
||||
|
||||
print >>h_file, "void InitStringMap();"
|
||||
print >>h_file, "void InitAttributeCountMap();"
|
||||
print >>h_file, "void InitAttributeIndexMap();"
|
||||
print >>h_file, "void InitAttributeTypeMap();"
|
||||
print >>h_file, "void InitAttributeNameMap();"
|
||||
print >>h_file, "void InitAttributeOptionalMap();"
|
||||
print >>h_file, "IfcSchemaEntity SchemaEntity(IfcAbstractEntityPtr e = 0);"
|
||||
|
||||
print >>h_file, "}\n\n#endif"
|
||||
|
||||
generator_mode = 'SOURCE'
|
||||
print >>cpp2_file, """#include "../ifcparse/%(schema)s.h"
|
||||
#include "../ifcparse/%(schema)s-rt.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
|
||||
print >>cpp_file, """#include "%(schema)s.h"
|
||||
#include "IfcException.h"
|
||||
#include "IfcWrite.h"
|
||||
#include "IfcWritableEntity.h"
|
||||
using namespace %(schema)s;
|
||||
using namespace IfcParse;
|
||||
using namespace IfcWrite;"""%{'schema':schema_version}
|
||||
print >>cpp_file, """#include "../ifcparse/%(schema)s.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
|
||||
using namespace %(schema)s;
|
||||
using namespace IfcParse;
|
||||
@@ -616,20 +659,37 @@ print >>cpp_file, ' const char* names[] = { "%s" };'%'","'.join(all_enumerati
|
||||
print >>cpp_file, ' return names[v];'
|
||||
print >>cpp_file, "}"
|
||||
print >>cpp_file
|
||||
#print >>cpp_file, "Type::Enum Type::FromStringOld(const std::string& s){"
|
||||
#elseif = "if"
|
||||
#maxlen = max([len(e) for e in all_enumerations])
|
||||
#for e in all_enumerations:
|
||||
# print >>cpp_file, ' %s(s=="%s"%s) { return %s; }'%(elseif,e.upper()," "*(maxlen-len(e)),e)
|
||||
#print >>cpp_file, " throw;"
|
||||
#print >>cpp_file, "}"
|
||||
|
||||
print >>cpp_file, "std::map<std::string,Type::Enum> string_map;"
|
||||
print >>cpp_file, "void Ifc2x3::InitStringMap() {"
|
||||
print >>cpp2_file, "std::map<Type::Enum,IfcEntityDescriptor*> entity_descriptor_map;"
|
||||
maxlen = max([len(e) for e in all_enumerations])
|
||||
string_map,attribute_count_map,attribute_index_map,attribute_name_map,attribute_optional_map,attribute_type_map = [""]*6
|
||||
print >>cpp2_file, "void InitDescriptorMap() {"
|
||||
print >>cpp2_file, " IfcEntityDescriptor* current;"
|
||||
rt_entities = set()
|
||||
while True:
|
||||
todo = [e for e in entities if e.class_name not in rt_entities]
|
||||
if len(todo) == 0: break
|
||||
for e in todo:
|
||||
if e.parent_class and e.parent_class not in rt_entities: continue
|
||||
rt_entities.add(e.class_name)
|
||||
args = e.get_attributes(False)
|
||||
parent_descriptor = ("entity_descriptor_map.find(Type::%s)->second"%e.parent_class) if e.parent_class else "0"
|
||||
print >>cpp2_file, " current = entity_descriptor_map[Type::%s] = new IfcEntityDescriptor(Type::%s,%s);"%(e.class_name,e.class_name,parent_descriptor)
|
||||
for a,i in zip(args,range(len(args))):
|
||||
name,optional,type = a
|
||||
print >>cpp2_file, " current->add(\"%s\",%s,%s);"%(name,"true" if optional else "false",type)
|
||||
|
||||
print >>cpp2_file, "}"
|
||||
|
||||
for e in all_enumerations:
|
||||
print >>cpp_file, ' string_map["%s"%s] = Type::%s;'%(e.upper()," "*(maxlen-len(e)),e)
|
||||
print >>cpp_file, """}
|
||||
Type::Enum Type::FromString(const std::string& s) {
|
||||
string_map += ' string_map["%s"%s] = Type::%s;\n'%(e.upper()," "*(maxlen-len(e)),e)
|
||||
print >>cpp_file, """void Ifc2x3::InitStringMap() {
|
||||
%(string_map)s
|
||||
}"""%locals()
|
||||
|
||||
print >>cpp_file, """Type::Enum Type::FromString(const std::string& s) {
|
||||
if (string_map.empty()) ::Ifc2x3::InitStringMap();
|
||||
std::map<std::string,Type::Enum>::const_iterator it = string_map.find(s);
|
||||
if ( it == string_map.end() ) throw IfcException("Unable to find find keyword in schema");
|
||||
else return it->second;
|
||||
@@ -650,3 +710,40 @@ print >>cpp_file, "}"
|
||||
for t in [T for T in types if isinstance(T.type,EnumType)]:
|
||||
print >>cpp_file, t
|
||||
for e in entities: print >>cpp_file, e,
|
||||
print >>cpp_file, ""
|
||||
|
||||
print >>cpp2_file, """int Type::GetAttributeIndex(Enum t, const std::string& a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentIndex(a);
|
||||
}
|
||||
|
||||
int Type::GetAttributeCount(Enum t) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentCount();
|
||||
}
|
||||
|
||||
ArgumentType Type::GetAttributeType(Enum t, unsigned char a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentType(a);
|
||||
}
|
||||
|
||||
const std::string& Type::GetAttributeName(Enum t, unsigned char a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentName(a);
|
||||
}
|
||||
|
||||
bool Type::GetAttributeOptional(Enum t, unsigned char a) {
|
||||
if (entity_descriptor_map.empty()) ::InitDescriptorMap();
|
||||
std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t);
|
||||
if ( i == entity_descriptor_map.end() ) throw IfcException("Type not found");
|
||||
else return i->second->getArgumentOptional(a);
|
||||
}
|
||||
"""
|
||||
@@ -96,6 +96,7 @@ namespace IfcGeom {
|
||||
double face_area(const TopoDS_Face& f);
|
||||
void SetValue(GeomValue var, double value);
|
||||
double GetValue(GeomValue var);
|
||||
std::string create_brep_data(Ifc2x3::IfcProduct* s);
|
||||
|
||||
namespace Cache {
|
||||
void Purge();
|
||||
|
||||
@@ -86,6 +86,8 @@
|
||||
|
||||
#include <BRepGProp_Face.hxx>
|
||||
|
||||
#include <BRepTools.hxx>
|
||||
|
||||
#include "../ifcgeom/IfcGeom.h"
|
||||
|
||||
bool IfcGeom::create_solid_from_compound(const TopoDS_Shape& compound, TopoDS_Shape& shape) {
|
||||
@@ -489,4 +491,91 @@ double IfcGeom::GetValue(GeomValue var) {
|
||||
}
|
||||
assert(!"never reach here");
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string IfcGeom::create_brep_data(Ifc2x3::IfcProduct* ifc_product) {
|
||||
if (!ifc_product->hasRepresentation()) return "";
|
||||
|
||||
Ifc2x3::IfcProductRepresentation* prod_rep = ifc_product->Representation();
|
||||
Ifc2x3::IfcRepresentation::list li = prod_rep->Representations();
|
||||
Ifc2x3::IfcShapeRepresentation* shape_rep;
|
||||
for (Ifc2x3::IfcRepresentation::it i = li->begin(); i != li->end(); ++i) {
|
||||
const std::string representation_identifier = (*i)->RepresentationIdentifier();
|
||||
if ((*i)->is(Ifc2x3::Type::IfcShapeRepresentation) && (representation_identifier == "Body" || representation_identifier == "Facetation")) {
|
||||
shape_rep = (Ifc2x3::IfcShapeRepresentation*) *i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
IfcGeom::ShapeList shapes;
|
||||
if (!IfcGeom::convert_shapes(shape_rep,shapes)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
gp_Trsf trsf;
|
||||
try {
|
||||
IfcGeom::convert(ifc_product->ObjectPlacement(),trsf);
|
||||
} catch (...) {}
|
||||
|
||||
// Does the IfcElement have any IfcOpenings?
|
||||
// Note that openings for IfcOpeningElements are not processed
|
||||
Ifc2x3::IfcRelVoidsElement::list openings = Ifc2x3::IfcRelVoidsElement::list();
|
||||
if ( ifc_product->is(Ifc2x3::Type::IfcElement) && !ifc_product->is(Ifc2x3::Type::IfcOpeningElement) ) {
|
||||
Ifc2x3::IfcElement::ptr element = reinterpret_pointer_cast<Ifc2x3::IfcProduct,Ifc2x3::IfcElement>(ifc_product);
|
||||
openings = element->HasOpenings();
|
||||
}
|
||||
// Is the IfcElement a decomposition of an IfcElement with any IfcOpeningElements?
|
||||
if ( ifc_product->is(Ifc2x3::Type::IfcBuildingElementPart ) ) {
|
||||
Ifc2x3::IfcBuildingElementPart::ptr part = reinterpret_pointer_cast<Ifc2x3::IfcProduct,Ifc2x3::IfcBuildingElementPart>(ifc_product);
|
||||
Ifc2x3::IfcRelDecomposes::list decomposes = part->Decomposes();
|
||||
for ( Ifc2x3::IfcRelDecomposes::it it = decomposes->begin(); it != decomposes->end(); ++ it ) {
|
||||
Ifc2x3::IfcObjectDefinition::ptr obdef = (*it)->RelatingObject();
|
||||
if ( obdef->is(Ifc2x3::Type::IfcElement) ) {
|
||||
Ifc2x3::IfcElement::ptr element = reinterpret_pointer_cast<Ifc2x3::IfcObjectDefinition,Ifc2x3::IfcElement>(obdef);
|
||||
openings->push(element->HasOpenings());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( openings && openings->Size() ) {
|
||||
IfcGeom::ShapeList opened_shapes;
|
||||
try {
|
||||
IfcGeom::convert_openings(ifc_product,openings,shapes,trsf,opened_shapes);
|
||||
} catch(...) {
|
||||
Logger::Message(Logger::LOG_ERROR,"Error processing openings for:",ifc_product->entity);
|
||||
}
|
||||
for ( IfcGeom::ShapeList::const_iterator it = opened_shapes.begin(); it != opened_shapes.end(); ++ it ) {
|
||||
it->first->PreMultiply(trsf);
|
||||
}
|
||||
trsf = gp_Trsf();
|
||||
for ( IfcGeom::ShapeList::const_iterator it = opened_shapes.begin(); it != opened_shapes.end(); ++ it ) {
|
||||
delete it->first;
|
||||
delete it->second;
|
||||
}
|
||||
} else {
|
||||
for ( IfcGeom::ShapeList::const_iterator it = shapes.begin(); it != shapes.end(); ++ it ) {
|
||||
it->first->PreMultiply(trsf);
|
||||
}
|
||||
trsf = gp_Trsf();
|
||||
}
|
||||
|
||||
TopoDS_Compound compound;
|
||||
BRep_Builder builder;
|
||||
builder.MakeCompound(compound);
|
||||
for ( IfcGeom::ShapeList::const_iterator it = shapes.begin(); it != shapes.end(); ++ it ) {
|
||||
const TopoDS_Shape& s = *(*it).second;
|
||||
const gp_GTrsf& trsf = *(*it).first;
|
||||
bool trsf_valid = false;
|
||||
gp_Trsf _trsf;
|
||||
try {
|
||||
_trsf = trsf.Trsf();
|
||||
trsf_valid = true;
|
||||
} catch (...) {}
|
||||
const TopoDS_Shape moved_shape = trsf_valid ? s.Moved(_trsf) :
|
||||
BRepBuilderAPI_GTransform(s,trsf,true).Shape();
|
||||
builder.Add(compound,moved_shape);
|
||||
}
|
||||
std::stringstream sstream;
|
||||
BRepTools::Write(compound,sstream);
|
||||
return sstream.str();
|
||||
}
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <BRepBuilderAPI_GTransform.hxx>
|
||||
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcgeom/IfcGeomObjects.h"
|
||||
#include "../ifcgeom/IfcGeom.h"
|
||||
|
||||
|
||||
@@ -180,53 +180,73 @@ bool IfcGeom::convert(const Ifc2x3::IfcTrimmedCurve::ptr l, TopoDS_Wire& wire) {
|
||||
IfcUtil::IfcAbstractSelect::list trims2 = l->Trim2();
|
||||
bool trimmed1 = false;
|
||||
bool trimmed2 = false;
|
||||
bool sense_agreement = l->SenseAgreement();
|
||||
double flt1;
|
||||
gp_Pnt pnt1;
|
||||
unsigned sense_agreement = l->SenseAgreement() ? 0 : 1;
|
||||
double flts[2];
|
||||
gp_Pnt pnts[2];
|
||||
bool has_flts[2] = {false,false};
|
||||
bool has_pnts[2] = {false,false};
|
||||
BRepBuilderAPI_MakeWire w;
|
||||
for ( IfcUtil::IfcAbstractSelect::it it = trims1->begin(); it != trims1->end(); it ++ ) {
|
||||
const IfcUtil::IfcAbstractSelect::ptr i = *it;
|
||||
if ( i->is(Ifc2x3::Type::IfcCartesianPoint) && trim_cartesian ) {
|
||||
IfcGeom::convert(reinterpret_pointer_cast<IfcUtil::IfcAbstractSelect,Ifc2x3::IfcCartesianPoint>(i), pnt1 );
|
||||
trimmed1 = true;
|
||||
} else if ( i->is(Ifc2x3::Type::IfcParameterValue) && !trim_cartesian ) {
|
||||
if ( i->is(Ifc2x3::Type::IfcCartesianPoint) ) {
|
||||
IfcGeom::convert(reinterpret_pointer_cast<IfcUtil::IfcAbstractSelect,Ifc2x3::IfcCartesianPoint>(i), pnts[sense_agreement] );
|
||||
has_pnts[sense_agreement] = true;
|
||||
} else if ( i->is(Ifc2x3::Type::IfcParameterValue) ) {
|
||||
const double value = *reinterpret_pointer_cast<IfcUtil::IfcAbstractSelect,IfcUtil::IfcArgumentSelect>(i)->wrappedValue();
|
||||
flt1 = value * parameterFactor;
|
||||
trimmed1 = true;
|
||||
flts[sense_agreement] = value * parameterFactor;
|
||||
has_flts[sense_agreement] = true;
|
||||
}
|
||||
}
|
||||
for ( IfcUtil::IfcAbstractSelect::it it = trims2->begin(); it != trims2->end(); it ++ ) {
|
||||
const IfcUtil::IfcAbstractSelect::ptr i = *it;
|
||||
if ( i->is(Ifc2x3::Type::IfcCartesianPoint) && trim_cartesian && trimmed1 ) {
|
||||
gp_Pnt pnt2;
|
||||
IfcGeom::convert(reinterpret_pointer_cast<IfcUtil::IfcAbstractSelect,Ifc2x3::IfcCartesianPoint>(i), pnt2 );
|
||||
BRepBuilderAPI_MakeEdge e (curve,sense_agreement ? pnt1 : pnt2,sense_agreement ? pnt2 : pnt1);
|
||||
if ( ! e.IsDone() ) {
|
||||
BRepBuilderAPI_EdgeError err = e.Error();
|
||||
if ( err == BRepBuilderAPI_PointProjectionFailed ) {
|
||||
w.Add(BRepBuilderAPI_MakeEdge(sense_agreement ? pnt1 : pnt2,sense_agreement ? pnt2 : pnt1));
|
||||
Logger::Message(Logger::LOG_WARNING,"Point projection failed for:",l->entity);
|
||||
}
|
||||
} else {
|
||||
w.Add(e.Edge());
|
||||
}
|
||||
trimmed2 = true;
|
||||
break;
|
||||
} else if ( i->is(Ifc2x3::Type::IfcParameterValue) && !trim_cartesian && trimmed1 ) {
|
||||
if ( i->is(Ifc2x3::Type::IfcCartesianPoint) ) {
|
||||
IfcGeom::convert(reinterpret_pointer_cast<IfcUtil::IfcAbstractSelect,Ifc2x3::IfcCartesianPoint>(i), pnts[1-sense_agreement] );
|
||||
has_pnts[1-sense_agreement] = true;
|
||||
} else if ( i->is(Ifc2x3::Type::IfcParameterValue) ) {
|
||||
const double value = *reinterpret_pointer_cast<IfcUtil::IfcAbstractSelect,IfcUtil::IfcArgumentSelect>(i)->wrappedValue();
|
||||
double flt2 = value * parameterFactor;
|
||||
if ( isConic && ALMOST_THE_SAME(fmod(flt2-flt1,(double)(M_PI*2.0)),0.0f) ) {
|
||||
w.Add(BRepBuilderAPI_MakeEdge(curve));
|
||||
} else {
|
||||
BRepBuilderAPI_MakeEdge e (curve,sense_agreement ? flt1 : flt2,sense_agreement ? flt2 : flt1);
|
||||
w.Add(e.Edge());
|
||||
}
|
||||
trimmed2 = true;
|
||||
break;
|
||||
flts[1-sense_agreement] = value * parameterFactor;
|
||||
has_flts[1-sense_agreement] = true;
|
||||
}
|
||||
}
|
||||
if ( trimmed2 ) wire = w.Wire();
|
||||
return trimmed2;
|
||||
trim_cartesian &= has_pnts[0] && has_pnts[1];
|
||||
bool trim_cartesian_failed = !trim_cartesian;
|
||||
if ( trim_cartesian ) {
|
||||
if ( pnts[0].Distance(pnts[1]) < GetValue(GV_WIRE_CREATION_TOLERANCE) ) {
|
||||
Logger::Message(Logger::LOG_WARNING,"Skipping segment with length below tolerance level:",l->entity);
|
||||
return false;
|
||||
}
|
||||
ShapeFix_ShapeTolerance FTol;
|
||||
TopoDS_Vertex v1 = BRepBuilderAPI_MakeVertex(pnts[0]);
|
||||
TopoDS_Vertex v2 = BRepBuilderAPI_MakeVertex(pnts[1]);
|
||||
FTol.SetTolerance(v1, GetValue(GV_WIRE_CREATION_TOLERANCE), TopAbs_VERTEX);
|
||||
FTol.SetTolerance(v2, GetValue(GV_WIRE_CREATION_TOLERANCE), TopAbs_VERTEX);
|
||||
BRepBuilderAPI_MakeEdge e (curve,v1,v2);
|
||||
if ( ! e.IsDone() ) {
|
||||
BRepBuilderAPI_EdgeError err = e.Error();
|
||||
if ( err == BRepBuilderAPI_PointProjectionFailed ) {
|
||||
Logger::Message(Logger::LOG_WARNING,"Point projection failed for:",l->entity);
|
||||
trim_cartesian_failed = true;
|
||||
}
|
||||
} else {
|
||||
w.Add(e.Edge());
|
||||
}
|
||||
}
|
||||
if ( (!trim_cartesian || trim_cartesian_failed) && (has_flts[0] && has_flts[1]) ) {
|
||||
if ( isConic && ALMOST_THE_SAME(fmod(flts[1]-flts[0],(double)(M_PI*2.0)),0.0f) ) {
|
||||
w.Add(BRepBuilderAPI_MakeEdge(curve));
|
||||
} else {
|
||||
BRepBuilderAPI_MakeEdge e (curve,flts[0],flts[1]);
|
||||
w.Add(e.Edge());
|
||||
}
|
||||
} else if ( trim_cartesian_failed && (has_pnts[0] && has_pnts[1]) ) {
|
||||
w.Add(BRepBuilderAPI_MakeEdge(pnts[0],pnts[1]));
|
||||
}
|
||||
if ( w.IsDone() ) {
|
||||
wire = w.Wire();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool IfcGeom::convert(const Ifc2x3::IfcPolyline::ptr l, TopoDS_Wire& result) {
|
||||
Ifc2x3::IfcCartesianPoint::list points = l->Points();
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef ARGUMENTTYPE_H
|
||||
#define ARGUMENTTYPE_H
|
||||
|
||||
namespace IfcUtil {
|
||||
enum ArgumentType {
|
||||
Argument_INT, Argument_BOOL, Argument_DOUBLE, Argument_STRING, Argument_VECTOR_INT, Argument_VECTOR_DOUBLE, Argument_VECTOR_STRING, Argument_ENTITY, Argument_ENTITY_LIST, Argument_ENUMERATION, Argument_UNKNOWN
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This file has been generated from IFC2X3_TC1.exp. Do not make modifications *
|
||||
* but instead modify the python script that has been used to generate this. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFC2X3RT_H
|
||||
#define IFC2X3RT_H
|
||||
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
|
||||
namespace Ifc2x3 {
|
||||
namespace Type {
|
||||
int GetAttributeCount(Enum t);
|
||||
int GetAttributeIndex(Enum t, const std::string& a);
|
||||
IfcUtil::ArgumentType GetAttributeType(Enum t, unsigned char a);
|
||||
const std::string& GetAttributeName(Enum t, unsigned char a);
|
||||
bool GetAttributeOptional(Enum t, unsigned char a);
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,10 +24,11 @@
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include "Ifc2x3.h"
|
||||
#include "IfcException.h"
|
||||
#include "IfcWrite.h"
|
||||
#include "IfcWritableEntity.h"
|
||||
#include "../ifcparse/Ifc2x3.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
|
||||
using namespace Ifc2x3;
|
||||
using namespace IfcParse;
|
||||
@@ -805,7 +806,7 @@ std::string Type::ToString(Enum v) {
|
||||
|
||||
std::map<std::string,Type::Enum> string_map;
|
||||
void Ifc2x3::InitStringMap() {
|
||||
string_map["IFCABSORBEDDOSEMEASURE" ] = Type::IfcAbsorbedDoseMeasure;
|
||||
string_map["IFCABSORBEDDOSEMEASURE" ] = Type::IfcAbsorbedDoseMeasure;
|
||||
string_map["IFCACCELERATIONMEASURE" ] = Type::IfcAccelerationMeasure;
|
||||
string_map["IFCAMOUNTOFSUBSTANCEMEASURE" ] = Type::IfcAmountOfSubstanceMeasure;
|
||||
string_map["IFCANGULARVELOCITYMEASURE" ] = Type::IfcAngularVelocityMeasure;
|
||||
@@ -1563,8 +1564,10 @@ void Ifc2x3::InitStringMap() {
|
||||
string_map["IFCWORKSCHEDULE" ] = Type::IfcWorkSchedule;
|
||||
string_map["IFCZSHAPEPROFILEDEF" ] = Type::IfcZShapeProfileDef;
|
||||
string_map["IFCZONE" ] = Type::IfcZone;
|
||||
|
||||
}
|
||||
Type::Enum Type::FromString(const std::string& s) {
|
||||
if (string_map.empty()) ::Ifc2x3::InitStringMap();
|
||||
std::map<std::string,Type::Enum>::const_iterator it = string_map.find(s);
|
||||
if ( it == string_map.end() ) throw IfcException("Unable to find find keyword in schema");
|
||||
else return it->second;
|
||||
@@ -12008,4 +12011,4 @@ bool IfcZone::is(Type::Enum v) const { return v == Type::IfcZone || IfcGroup::is
|
||||
Type::Enum IfcZone::type() const { return Type::IfcZone; }
|
||||
Type::Enum IfcZone::Class() { return Type::IfcZone; }
|
||||
IfcZone::IfcZone(IfcAbstractEntityPtr e) { if (!is(Type::IfcZone)) throw IfcException("Unable to find find keyword in schema"); entity = e; }
|
||||
IfcZone::IfcZone(IfcGloballyUniqueId v1_GlobalId, IfcOwnerHistory* v2_OwnerHistory, optional< IfcLabel > v3_Name, optional< IfcText > v4_Description, optional< IfcLabel > v5_ObjectType) { IfcWritableEntity* e = new IfcWritableEntity(Class()); e->setArgument(0,(v1_GlobalId)); e->setArgument(1,(v2_OwnerHistory)); if (v3_Name) { e->setArgument(2,(*v3_Name)); } else { e->setArgument(2); } ; if (v4_Description) { e->setArgument(3,(*v4_Description)); } else { e->setArgument(3); } ; if (v5_ObjectType) { e->setArgument(4,(*v5_ObjectType)); } else { e->setArgument(4); } ; entity = e; EntityBuffer::Add(this); }
|
||||
IfcZone::IfcZone(IfcGloballyUniqueId v1_GlobalId, IfcOwnerHistory* v2_OwnerHistory, optional< IfcLabel > v3_Name, optional< IfcText > v4_Description, optional< IfcLabel > v5_ObjectType) { IfcWritableEntity* e = new IfcWritableEntity(Class()); e->setArgument(0,(v1_GlobalId)); e->setArgument(1,(v2_OwnerHistory)); if (v3_Name) { e->setArgument(2,(*v3_Name)); } else { e->setArgument(2); } ; if (v4_Description) { e->setArgument(3,(*v4_Description)); } else { e->setArgument(3); } ; if (v5_ObjectType) { e->setArgument(4,(*v5_ObjectType)); } else { e->setArgument(4); } ; entity = e; EntityBuffer::Add(this); }
|
||||
|
||||
@@ -30,11 +30,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
#include "../ifcparse/Ifc2x3enum.h"
|
||||
|
||||
using namespace IfcUtil;
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#ifndef IFC2X3ENUM_H
|
||||
#define IFC2X3ENUM_H
|
||||
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
|
||||
namespace Ifc2x3 {
|
||||
|
||||
namespace Type {
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "../ifcparse/IfcCharacterDecoder.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
|
||||
#define FIRST_SOLIDUS (1 << 1)
|
||||
#define PAGE (1 << 2)
|
||||
@@ -67,6 +67,7 @@
|
||||
#define CLEAR_HEX(C) (C &= ~(HEX(1)&HEX(2)&HEX(3)&HEX(4)&HEX(5)&HEX(6)&HEX(7)&HEX(8)))
|
||||
|
||||
using namespace IfcParse;
|
||||
using namespace IfcWrite;
|
||||
|
||||
void IfcCharacterDecoder::addChar(std::stringstream& s,const UChar32& ch) {
|
||||
#ifdef HAVE_ICU
|
||||
@@ -296,3 +297,71 @@ std::string IfcCharacterDecoder::compatibility_charset = "";
|
||||
#else
|
||||
char IfcCharacterDecoder::substitution_character = '_';
|
||||
#endif
|
||||
|
||||
|
||||
IfcCharacterEncoder::IfcCharacterEncoder(const std::string& input) {
|
||||
#ifdef HAVE_ICU
|
||||
if ( !converter) converter = ucnv_open("utf-8", &status);
|
||||
#endif
|
||||
str = input;
|
||||
}
|
||||
|
||||
IfcCharacterEncoder::~IfcCharacterEncoder() {
|
||||
#ifdef HAVE_ICU
|
||||
if ( !converter) ucnv_close(converter);
|
||||
converter = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
IfcCharacterEncoder::operator std::string() {
|
||||
std::ostringstream oss;
|
||||
oss.put('\'');
|
||||
#ifdef HAVE_ICU
|
||||
// Either 2 or 4 to uses \X2 or \X4 respectively.
|
||||
// Currently hardcoded to 4, but \X2 might be
|
||||
// sufficient for nearly all purposes.
|
||||
const int num_bytes = 4;
|
||||
const std::string num_bytes_str = std::string(1,num_bytes + 0x30);
|
||||
|
||||
|
||||
UChar32 ch;
|
||||
|
||||
const char* source = str.c_str();
|
||||
const char* limit = &*str.end();
|
||||
|
||||
bool in_extended = false;
|
||||
|
||||
while(source < limit) {
|
||||
ch = ucnv_getNextUChar(converter, &source, limit, &status);
|
||||
const bool within_spf_range = ch >= 0x20 && ch <= 0x7e;
|
||||
if ( in_extended && within_spf_range ) {
|
||||
oss << "\\X0\\";
|
||||
} else if ( !in_extended && !within_spf_range ) {
|
||||
oss << "\\X" << num_bytes_str << "\\";
|
||||
}
|
||||
if ( within_spf_range ) {
|
||||
oss.put(ch);
|
||||
if ( ch == '\\' || ch == '\'' ) oss.put(ch);
|
||||
} else {
|
||||
oss << std::hex << std::setw(num_bytes*2) << std::uppercase << std::setfill('0') << (int) ch;
|
||||
}
|
||||
in_extended = !within_spf_range;
|
||||
}
|
||||
|
||||
if ( in_extended ) oss << "\\X0\\";
|
||||
#else
|
||||
for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) {
|
||||
char ch = *i;
|
||||
if ( ch == '\\' || ch == '\'' ) oss.put(ch);
|
||||
oss.put(ch);
|
||||
}
|
||||
#endif
|
||||
oss.put('\'');
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_ICU
|
||||
UErrorCode IfcCharacterEncoder::status = U_ZERO_ERROR;
|
||||
UConverter* IfcCharacterEncoder::converter = 0;
|
||||
#endif
|
||||
@@ -36,7 +36,7 @@
|
||||
typedef unsigned int UChar32;
|
||||
#endif
|
||||
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
|
||||
namespace IfcParse {
|
||||
|
||||
@@ -73,4 +73,21 @@ namespace IfcParse {
|
||||
|
||||
}
|
||||
|
||||
namespace IfcWrite {
|
||||
|
||||
class IfcCharacterEncoder {
|
||||
private:
|
||||
std::string str;
|
||||
#ifdef HAVE_ICU
|
||||
static UErrorCode status;
|
||||
static UConverter* converter;
|
||||
#endif
|
||||
public:
|
||||
IfcCharacterEncoder(const std::string& input);
|
||||
~IfcCharacterEncoder();
|
||||
operator std::string();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+70
-73
@@ -1,81 +1,78 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* *
|
||||
* Reads a file in chunks of BUF_SIZE and provides functions to access its *
|
||||
* contents randomly and character by character *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFCFILE_H
|
||||
#define IFCFILE_H
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
// As of IfcOpenShell version 0.3.0 the paging functionality, which
|
||||
// loads a file on disk into multiple chunks, has been disabled.
|
||||
// It proved to be an inefficient way of working with large files,
|
||||
// as often these did not facilitate to be parsed in a sequential
|
||||
// manner efficiently, to enable the paging functionality uncomment
|
||||
// the following statement.
|
||||
//const int BUF_SIZE = (128 * 1024 * 1024);
|
||||
#include "IfcUtil.h"
|
||||
#include "IfcParse.h"
|
||||
|
||||
namespace IfcParse {
|
||||
/// The IfcSpfStream class represents a ISO 10303-21 IFC-SPF file in memory.
|
||||
/// The file is interpreted as a sequence of tokens which are lazily
|
||||
/// interpreted only when requested. If the size of the file is
|
||||
/// larger than BUF_SIZE, the file is split into seperate pages, of
|
||||
/// which only one is simultaneously kept in memory, for files
|
||||
/// that define their entities not in a sequential nature, this is
|
||||
/// detrimental for the performance of the parser.
|
||||
class IfcSpfStream {
|
||||
private:
|
||||
std::ifstream stream;
|
||||
char* buffer;
|
||||
unsigned int ptr;
|
||||
unsigned int len;
|
||||
void ReadBuffer(bool inc=true);
|
||||
#ifdef BUF_SIZE
|
||||
unsigned int offset;
|
||||
bool paging;
|
||||
#endif
|
||||
public:
|
||||
bool valid;
|
||||
bool eof;
|
||||
unsigned int size;
|
||||
IfcSpfStream(const std::string& fn);
|
||||
IfcSpfStream(std::istream& f, int len);
|
||||
IfcSpfStream(void* data, int len);
|
||||
/// Returns the character at the cursor
|
||||
char Peek();
|
||||
/// Returns the character at specified offset
|
||||
char Read(unsigned int offset);
|
||||
/// Increment the file cursor and reads new page if necessary
|
||||
void Inc();
|
||||
void Close();
|
||||
/// Moves the file cursor to an arbitrary offset in the file
|
||||
void Seek(unsigned int offset);
|
||||
/// Returns the cursor position
|
||||
unsigned int Tell();
|
||||
};
|
||||
|
||||
typedef IfcUtil::IfcSchemaEntity IfcEntity;
|
||||
//typedef IfcEntities IfcEntities;
|
||||
typedef std::map<Ifc2x3::Type::Enum,IfcEntities> MapEntitiesByType;
|
||||
typedef std::map<unsigned int,IfcEntity> MapEntityById;
|
||||
typedef std::map<std::string,Ifc2x3::IfcRoot::ptr> MapEntityByGuid;
|
||||
typedef std::map<unsigned int,IfcEntities> MapEntitiesByRef;
|
||||
typedef std::map<unsigned int,unsigned int> MapOffsetById;
|
||||
|
||||
/// This class provides several static convenience functions and variables
|
||||
/// and provide access to the entities in an IFC file
|
||||
class IfcFile {
|
||||
private:
|
||||
MapEntityById byid;
|
||||
MapEntitiesByType bytype;
|
||||
MapEntitiesByRef byref;
|
||||
MapEntityByGuid byguid;
|
||||
MapOffsetById offsets;
|
||||
unsigned int lastId;
|
||||
unsigned int MaxId;
|
||||
public:
|
||||
typedef MapEntityById::const_iterator const_iterator;
|
||||
IfcFile();
|
||||
~IfcFile();
|
||||
/// Returns the first entity in the file, this probably is the entity with the lowest id (EXPRESS ENTITY_INSTANCE_NAME)
|
||||
const_iterator begin() const;
|
||||
/// Returns the last entity in the file, this probably is the entity with the highes id (EXPRESS ENTITY_INSTANCE_NAME)
|
||||
const_iterator end() const;
|
||||
IfcParse::IfcSpfStream* file;
|
||||
IfcParse::Tokens* tokens;
|
||||
/// Returns all entities in the file that match the template argument.
|
||||
/// NOTE: This also returns subtypes of the requested type, for example:
|
||||
/// IfcWall will also return IfcWallStandardCase entities
|
||||
template <class T>
|
||||
typename T::list EntitiesByType() {
|
||||
IfcEntities e = EntitiesByType(T::Class());
|
||||
typename T::list l ( new IfcTemplatedEntityList<T>() );
|
||||
if ( e && e->Size() )
|
||||
for ( IfcEntityList::it it = e->begin(); it != e->end(); ++ it ) {
|
||||
l->push(reinterpret_pointer_cast<IfcUtil::IfcBaseClass,T>(*it));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
/// Returns all entities in the file that match the positional argument.
|
||||
/// NOTE: This also returns subtypes of the requested type, for example:
|
||||
/// IfcWall will also return IfcWallStandardCase entities
|
||||
IfcEntities EntitiesByType(Ifc2x3::Type::Enum t);
|
||||
/// Returns all entities in the file that match the positional argument.
|
||||
/// NOTE: This also returns subtypes of the requested type, for example:
|
||||
/// IfcWall will also return IfcWallStandardCase entities
|
||||
IfcEntities EntitiesByType(const std::string& t);
|
||||
/// Returns all entities in the file that reference the id
|
||||
IfcEntities EntitiesByReference(int id);
|
||||
/// Returns the entity with the specified id
|
||||
IfcEntity EntityById(int id);
|
||||
/// Returns the entity with the specified GlobalId
|
||||
Ifc2x3::IfcRoot::ptr EntityByGuid(const std::string& guid);
|
||||
bool Init(const std::string& fn);
|
||||
bool Init(std::istream& fn, int len);
|
||||
bool Init(void* data, int len);
|
||||
bool Init(IfcParse::IfcSpfStream* f);
|
||||
unsigned int FreshId() { MaxId ++; return MaxId; }
|
||||
void AddEntity(IfcUtil::IfcSchemaEntity e);
|
||||
void AddEntities(IfcEntities es);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -24,9 +24,10 @@
|
||||
|
||||
#include "../ifcparse/IfcCharacterDecoder.h"
|
||||
#include "../ifcparse/IfcParse.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
|
||||
using namespace IfcParse;
|
||||
@@ -468,7 +469,13 @@ TokenArgument::operator IfcUtil::IfcSchemaEntity() const { return token.first->f
|
||||
TokenArgument::operator IfcEntities() const { throw IfcException("Argument is not a list of entities"); }
|
||||
unsigned int TokenArgument::Size() const { return 1; }
|
||||
ArgumentPtr TokenArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of arguments"); }
|
||||
std::string TokenArgument::toString(bool upper) const { return TokenFunc::toString(token); }
|
||||
std::string TokenArgument::toString(bool upper) const {
|
||||
if ( upper && TokenFunc::isString(token) ) {
|
||||
return IfcWrite::IfcCharacterEncoder(TokenFunc::asString(token));
|
||||
} else {
|
||||
return TokenFunc::toString(token);
|
||||
}
|
||||
}
|
||||
bool TokenArgument::isNull() const { return TokenFunc::isOperator(token,'$'); }
|
||||
//
|
||||
// Functions for casting the EntityArgument to other types
|
||||
@@ -488,10 +495,18 @@ ArgumentPtr EntityArgument::operator [] (unsigned int i) const { throw IfcExcept
|
||||
std::string EntityArgument::toString(bool upper) const {
|
||||
ArgumentPtr arg = entity->wrappedValue();
|
||||
IfcParse::TokenArgument* token_arg = dynamic_cast<IfcParse::TokenArgument*>(arg);
|
||||
std::string token_string = ( token_arg ) ? TokenFunc::toString(token_arg->token) : "";
|
||||
const bool is_string = TokenFunc::isString(token_arg->token);
|
||||
std::string token_string = token_arg ? (is_string
|
||||
? TokenFunc::asString(token_arg->token)
|
||||
: TokenFunc::toString(token_arg->token))
|
||||
: std::string();
|
||||
std::string dt = Ifc2x3::Type::ToString(entity->type());
|
||||
if ( upper ) {
|
||||
for (std::string::iterator p = dt.begin(); p != dt.end(); ++p ) *p = toupper(*p);
|
||||
if (is_string) token_string = IfcWrite::IfcCharacterEncoder(token_string);
|
||||
} else {
|
||||
token_string.insert(token_string.begin(),'\'');
|
||||
token_string.push_back('\'');
|
||||
}
|
||||
return dt + "(" + token_string + ")";
|
||||
}
|
||||
@@ -662,7 +677,8 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
|
||||
if ( currentId ) {
|
||||
try {
|
||||
e = new Entity(currentId,this);
|
||||
entity = Ifc2x3::SchemaEntity(e);
|
||||
//entity = Ifc2x3::SchemaEntity(e);
|
||||
entity = new Ifc::IfcUntypedEntity(e);
|
||||
} catch (IfcException ex) {
|
||||
currentId = 0;
|
||||
Logger::Message(Logger::LOG_ERROR,ex.what());
|
||||
|
||||
+2
-66
@@ -41,7 +41,8 @@
|
||||
#include "../ifcparse/IfcCharacterDecoder.h"
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/Ifc2x3.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcSpfStream.h"
|
||||
#include "../ifcparse/IfcUntypedEntity.h"
|
||||
|
||||
namespace IfcParse {
|
||||
|
||||
@@ -210,71 +211,6 @@ namespace IfcParse {
|
||||
bool isWritable();
|
||||
};
|
||||
|
||||
typedef IfcUtil::IfcSchemaEntity IfcEntity;
|
||||
//typedef IfcEntities IfcEntities;
|
||||
typedef std::map<Ifc2x3::Type::Enum,IfcEntities> MapEntitiesByType;
|
||||
typedef std::map<unsigned int,IfcEntity> MapEntityById;
|
||||
typedef std::map<std::string,Ifc2x3::IfcRoot::ptr> MapEntityByGuid;
|
||||
typedef std::map<unsigned int,IfcEntities> MapEntitiesByRef;
|
||||
typedef std::map<unsigned int,unsigned int> MapOffsetById;
|
||||
|
||||
/// This class provides several static convenience functions and variables
|
||||
/// and provide access to the entities in an IFC file
|
||||
class IfcFile {
|
||||
private:
|
||||
MapEntityById byid;
|
||||
MapEntitiesByType bytype;
|
||||
MapEntitiesByRef byref;
|
||||
MapEntityByGuid byguid;
|
||||
MapOffsetById offsets;
|
||||
unsigned int lastId;
|
||||
unsigned int MaxId;
|
||||
public:
|
||||
typedef MapEntityById::const_iterator const_iterator;
|
||||
IfcFile();
|
||||
~IfcFile();
|
||||
/// Returns the first entity in the file, this probably is the entity with the lowest id (EXPRESS ENTITY_INSTANCE_NAME)
|
||||
const_iterator begin() const;
|
||||
/// Returns the last entity in the file, this probably is the entity with the highes id (EXPRESS ENTITY_INSTANCE_NAME)
|
||||
const_iterator end() const;
|
||||
IfcParse::IfcSpfStream* file;
|
||||
IfcParse::Tokens* tokens;
|
||||
/// Returns all entities in the file that match the template argument.
|
||||
/// NOTE: This also returns subtypes of the requested type, for example:
|
||||
/// IfcWall will also return IfcWallStandardCase entities
|
||||
template <class T>
|
||||
typename T::list EntitiesByType() {
|
||||
IfcEntities e = EntitiesByType(T::Class());
|
||||
typename T::list l ( new IfcTemplatedEntityList<T>() );
|
||||
if ( e && e->Size() )
|
||||
for ( IfcEntityList::it it = e->begin(); it != e->end(); ++ it ) {
|
||||
l->push(reinterpret_pointer_cast<IfcUtil::IfcBaseClass,T>(*it));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
/// Returns all entities in the file that match the positional argument.
|
||||
/// NOTE: This also returns subtypes of the requested type, for example:
|
||||
/// IfcWall will also return IfcWallStandardCase entities
|
||||
IfcEntities EntitiesByType(Ifc2x3::Type::Enum t);
|
||||
/// Returns all entities in the file that match the positional argument.
|
||||
/// NOTE: This also returns subtypes of the requested type, for example:
|
||||
/// IfcWall will also return IfcWallStandardCase entities
|
||||
IfcEntities EntitiesByType(const std::string& t);
|
||||
/// Returns all entities in the file that reference the id
|
||||
IfcEntities EntitiesByReference(int id);
|
||||
/// Returns the entity with the specified id
|
||||
IfcEntity EntityById(int id);
|
||||
/// Returns the entity with the specified GlobalId
|
||||
Ifc2x3::IfcRoot::ptr EntityByGuid(const std::string& guid);
|
||||
bool Init(const std::string& fn);
|
||||
bool Init(std::istream& fn, int len);
|
||||
bool Init(void* data, int len);
|
||||
bool Init(IfcParse::IfcSpfStream* f);
|
||||
unsigned int FreshId() { MaxId ++; return MaxId; }
|
||||
void AddEntity(IfcUtil::IfcSchemaEntity e);
|
||||
void AddEntities(IfcEntities es);
|
||||
};
|
||||
|
||||
double UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v );
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* *
|
||||
* Reads a file in chunks of BUF_SIZE and provides functions to access its *
|
||||
* contents randomly and character by character *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef IFCSPFSTREAM_H
|
||||
#define IFCSPFSTREAM_H
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
// As of IfcOpenShell version 0.3.0 the paging functionality, which
|
||||
// loads a file on disk into multiple chunks, has been disabled.
|
||||
// It proved to be an inefficient way of working with large files,
|
||||
// as often these did not facilitate to be parsed in a sequential
|
||||
// manner efficiently, to enable the paging functionality uncomment
|
||||
// the following statement.
|
||||
//const int BUF_SIZE = (128 * 1024 * 1024);
|
||||
|
||||
namespace IfcParse {
|
||||
/// The IfcSpfStream class represents a ISO 10303-21 IFC-SPF file in memory.
|
||||
/// The file is interpreted as a sequence of tokens which are lazily
|
||||
/// interpreted only when requested. If the size of the file is
|
||||
/// larger than BUF_SIZE, the file is split into seperate pages, of
|
||||
/// which only one is simultaneously kept in memory, for files
|
||||
/// that define their entities not in a sequential nature, this is
|
||||
/// detrimental for the performance of the parser.
|
||||
class IfcSpfStream {
|
||||
private:
|
||||
std::ifstream stream;
|
||||
char* buffer;
|
||||
unsigned int ptr;
|
||||
unsigned int len;
|
||||
void ReadBuffer(bool inc=true);
|
||||
#ifdef BUF_SIZE
|
||||
unsigned int offset;
|
||||
bool paging;
|
||||
#endif
|
||||
public:
|
||||
bool valid;
|
||||
bool eof;
|
||||
unsigned int size;
|
||||
IfcSpfStream(const std::string& fn);
|
||||
IfcSpfStream(std::istream& f, int len);
|
||||
IfcSpfStream(void* data, int len);
|
||||
/// Returns the character at the cursor
|
||||
char Peek();
|
||||
/// Returns the character at specified offset
|
||||
char Read(unsigned int offset);
|
||||
/// Increment the file cursor and reads new page if necessary
|
||||
void Inc();
|
||||
void Close();
|
||||
/// Moves the file cursor to an arbitrary offset in the file
|
||||
void Seek(unsigned int offset);
|
||||
/// Returns the cursor position
|
||||
unsigned int Tell();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,156 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "IfcWritableEntity.h"
|
||||
|
||||
#include "IfcUtil.h"
|
||||
#include "IfcWrite.h"
|
||||
#include "Ifc2x3-rt.h"
|
||||
|
||||
IfcWrite::IfcWritableEntity* Ifc::IfcUntypedEntity::writable_entity() {
|
||||
IfcWrite::IfcWritableEntity* e;
|
||||
if (entity->isWritable()) {
|
||||
e = (IfcWrite::IfcWritableEntity*) entity;
|
||||
} else {
|
||||
entity = e = new IfcWrite::IfcWritableEntity(entity);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
Ifc::IfcUntypedEntity::IfcUntypedEntity(const std::string& s) {
|
||||
std::string S = s;
|
||||
for (std::string::iterator i = S.begin(); i != S.end(); ++i ) *i = toupper(*i);
|
||||
_type = Ifc2x3::Type::FromString(S);
|
||||
entity = new IfcWrite::IfcWritableEntity(_type);
|
||||
}
|
||||
Ifc::IfcUntypedEntity::IfcUntypedEntity(IfcAbstractEntity* e) {
|
||||
entity = e;
|
||||
_type = e->type();
|
||||
}
|
||||
bool Ifc::IfcUntypedEntity::is(Ifc2x3::Type::Enum v) const {
|
||||
Ifc2x3::Type::Enum _ty = _type;
|
||||
if (v == _ty) return true;
|
||||
while (_ty != -1) {
|
||||
_ty = Ifc2x3::Type::Parent(_ty);
|
||||
if (v == _ty) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
std::string Ifc::IfcUntypedEntity::is_a() const {
|
||||
return Ifc2x3::Type::ToString(_type);
|
||||
}
|
||||
bool Ifc::IfcUntypedEntity::is_a(const std::string& s) const {
|
||||
std::string S = s;
|
||||
for (std::string::iterator i = S.begin(); i != S.end(); ++i ) *i = toupper(*i);
|
||||
return is(Ifc2x3::Type::FromString(S));
|
||||
}
|
||||
Ifc2x3::Type::Enum Ifc::IfcUntypedEntity::type() const {
|
||||
return _type;
|
||||
}
|
||||
unsigned int Ifc::IfcUntypedEntity::getArgumentCount() const {
|
||||
return Ifc2x3::Type::GetAttributeCount(_type);
|
||||
}
|
||||
IfcUtil::ArgumentType Ifc::IfcUntypedEntity::getArgumentType(unsigned int i) const {
|
||||
return Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
}
|
||||
ArgumentPtr Ifc::IfcUntypedEntity::getArgument(unsigned int i) const {
|
||||
return entity->getArgument(i);
|
||||
}
|
||||
const char* Ifc::IfcUntypedEntity::getArgumentName(unsigned int i) const {
|
||||
return Ifc2x3::Type::GetAttributeName(_type,i).c_str();
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::invalid_argument(unsigned int i, const std::string& t) {
|
||||
const std::string arg_name = Ifc2x3::Type::GetAttributeName(_type,i);
|
||||
throw IfcException(t + " is not a valid type for '" + arg_name + "'");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, int v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_INT) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"INT");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, bool v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_BOOL) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"BOOL");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, double v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_DOUBLE) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"DOUBLE");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, const std::string& a) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_STRING) {
|
||||
writable_entity()->setArgument(i,a);
|
||||
} else if (arg_type == Argument_ENUMERATION) {
|
||||
writable_entity()->setArgument(i,a);
|
||||
} else invalid_argument(i,"STRING");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, const std::vector<int>& v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_VECTOR_INT) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"LIST of INT");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, const std::vector<double>& v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_VECTOR_DOUBLE) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"LIST of DOUBLE");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, const std::vector<std::string>& v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_VECTOR_STRING) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"LIST of STRING");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, Ifc::IfcUntypedEntity* v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_ENTITY) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"ENTITY");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, IfcEntities v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_ENTITY_LIST) {
|
||||
writable_entity()->setArgument(i,v);
|
||||
} else invalid_argument(i,"LIST of ENTITY");
|
||||
}
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> Ifc::IfcUntypedEntity::get_argument(unsigned i) {
|
||||
return std::pair<IfcUtil::ArgumentType,ArgumentPtr>(getArgumentType(i),getArgument(i));
|
||||
}
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> Ifc::IfcUntypedEntity::get_argument(const std::string& a) {
|
||||
return get_argument(Ifc2x3::Type::GetAttributeIndex(_type,a));
|
||||
}
|
||||
unsigned Ifc::IfcUntypedEntity::getArgumentIndex(const std::string& a) const {
|
||||
return Ifc2x3::Type::GetAttributeIndex(_type,a);
|
||||
}
|
||||
std::string Ifc::IfcUntypedEntity::toString() {
|
||||
return entity->toString(false);
|
||||
}
|
||||
bool Ifc::IfcUntypedEntity::is_valid() {
|
||||
const unsigned arg_count = getArgumentCount();
|
||||
bool valid = true;
|
||||
std::ostringstream oss;
|
||||
oss << "Argument ";
|
||||
for (unsigned i = 0; i < arg_count; ++i) {
|
||||
bool is_null = true;
|
||||
try {
|
||||
const Argument& arg = *getArgument(i);
|
||||
is_null = arg.isNull();
|
||||
} catch(IfcException) {}
|
||||
if (!Ifc2x3::Type::GetAttributeOptional(_type,i) && is_null) {
|
||||
if (!valid) {
|
||||
oss << ", ";
|
||||
}
|
||||
oss << "\"" << getArgumentName(i) << "\"";
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
oss << " not optional";
|
||||
if (!valid) {
|
||||
throw IfcException(oss.str());
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef IFCUNTYPEDENTITY_H
|
||||
#define IFCUNTYPEDENTITY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "IfcUtil.h"
|
||||
#include "IfcWrite.h"
|
||||
#include "IfcWritableEntity.h"
|
||||
|
||||
namespace Ifc {
|
||||
|
||||
class IfcUntypedEntity : public IfcUtil::IfcBaseEntity {
|
||||
private:
|
||||
Ifc2x3::Type::Enum _type;
|
||||
IfcWrite::IfcWritableEntity* writable_entity();
|
||||
void invalid_argument(unsigned int i, const std::string& t);
|
||||
public:
|
||||
IfcUntypedEntity(const std::string& s);
|
||||
IfcUntypedEntity(IfcAbstractEntity* e);
|
||||
bool is(Ifc2x3::Type::Enum v) const;
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
bool is_a(const std::string& s) const;
|
||||
std::string is_a() const;
|
||||
unsigned int getArgumentCount() const;
|
||||
IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
|
||||
ArgumentPtr getArgument(unsigned int i) const;
|
||||
const char* getArgumentName(unsigned int i) const;
|
||||
unsigned getArgumentIndex(const std::string& a) const;
|
||||
|
||||
void setArgument(unsigned int i, int v);
|
||||
void setArgument(unsigned int i, bool v);
|
||||
void setArgument(unsigned int i, double v);
|
||||
void setArgument(unsigned int i, const std::string& v);
|
||||
void setArgument(unsigned int i, const std::vector<int>& v);
|
||||
void setArgument(unsigned int i, const std::vector<double>& v);
|
||||
void setArgument(unsigned int i, const std::vector<std::string>& v);
|
||||
void setArgument(unsigned int i, IfcUntypedEntity* v);
|
||||
void setArgument(unsigned int i, IfcEntities v);
|
||||
|
||||
std::string toString();
|
||||
|
||||
// TODO: Write as SWIG extension methods
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> get_argument(unsigned i);
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> get_argument(const std::string& a);
|
||||
|
||||
bool is_valid();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+63
-5
@@ -23,9 +23,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "../ifcparse/SharedPointer.h"
|
||||
#include "../ifcparse/Ifc2x3enum.h"
|
||||
#include "../ifcparse/ArgumentType.h"
|
||||
#include "../ifcparse/IfcException.h"
|
||||
|
||||
|
||||
class IfcAbstractEntity;
|
||||
//typedef SHARED_PTR<IfcAbstractEntity> IfcAbstractEntityPtr;
|
||||
@@ -47,12 +51,66 @@ inline T* reinterpret_pointer_cast(F* from) {
|
||||
}
|
||||
|
||||
namespace IfcUtil {
|
||||
enum ArgumentType {
|
||||
Argument_INT, Argument_BOOL, Argument_DOUBLE, Argument_STRING, Argument_VECTOR_INT, Argument_VECTOR_DOUBLE, Argument_VECTOR_STRING, Argument_ENTITY, Argument_ENTITY_LIST, Argument_ENUMERATION, Argument_UNKNOWN
|
||||
};
|
||||
}
|
||||
|
||||
namespace IfcUtil {
|
||||
class IfcEntityDescriptor {
|
||||
public:
|
||||
class IfcArgumentDescriptor
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
bool optional;
|
||||
ArgumentType type;
|
||||
IfcArgumentDescriptor(const std::string& name, bool optional, ArgumentType type)
|
||||
: name(name), optional(optional), type(type) {}
|
||||
};
|
||||
private:
|
||||
Ifc2x3::Type::Enum type;
|
||||
IfcEntityDescriptor* parent;
|
||||
std::vector<IfcArgumentDescriptor> arguments;
|
||||
unsigned argument_start() {
|
||||
return parent ? parent->getArgumentCount() : 0;
|
||||
}
|
||||
IfcArgumentDescriptor& get_argument(unsigned i) {
|
||||
if (i < arguments.size()) return arguments[i];
|
||||
else throw IfcParse::IfcException("Argument out of range");
|
||||
}
|
||||
public:
|
||||
IfcEntityDescriptor(Ifc2x3::Type::Enum type, IfcEntityDescriptor* parent)
|
||||
: type(type), parent(parent) {}
|
||||
void add(const std::string& name, bool optional, ArgumentType type) {
|
||||
arguments.push_back(IfcArgumentDescriptor(name, optional, type));
|
||||
}
|
||||
unsigned getArgumentCount() {
|
||||
return (parent ? parent->getArgumentCount() : 0) + arguments.size();
|
||||
}
|
||||
std::string& getArgumentName(unsigned i) {
|
||||
const unsigned a = argument_start();
|
||||
return i < a
|
||||
? parent->getArgumentName(i)
|
||||
: get_argument(i-a).name;
|
||||
}
|
||||
ArgumentType getArgumentType(unsigned i) {
|
||||
const unsigned a = argument_start();
|
||||
return i < a
|
||||
? parent->getArgumentType(i)
|
||||
: get_argument(i-a).type;
|
||||
}
|
||||
bool getArgumentOptional(unsigned i) {
|
||||
const unsigned a = argument_start();
|
||||
return i < a
|
||||
? parent->getArgumentOptional(i)
|
||||
: get_argument(i-a).optional;
|
||||
}
|
||||
unsigned getArgumentIndex(const std::string& s) {
|
||||
unsigned a = argument_start();
|
||||
for(std::vector<IfcArgumentDescriptor>::const_iterator i = arguments.begin(); i != arguments.end(); ++i) {
|
||||
if (i->name == s) return a;
|
||||
a++;
|
||||
}
|
||||
if (parent) return parent->getArgumentIndex(s);
|
||||
throw IfcParse::IfcException(std::string("Argument ") + s + " not found on " + Ifc2x3::Type::ToString(type));
|
||||
}
|
||||
};
|
||||
|
||||
class IfcBaseClass {
|
||||
public:
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#ifndef IFCWRITABLEENTITY_H
|
||||
#define IFCWRITABLEENTITY_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "IfcUtil.h"
|
||||
|
||||
namespace IfcWrite {
|
||||
|
||||
+60
-56
@@ -17,9 +17,11 @@
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include "IfcParse.h"
|
||||
#include "IfcWrite.h"
|
||||
#include "IfcWritableEntity.h"
|
||||
#include "../ifcparse/IfcParse.h"
|
||||
#include "../ifcparse/IfcFile.h"
|
||||
#include "../ifcparse/IfcWrite.h"
|
||||
#include "../ifcparse/IfcWritableEntity.h"
|
||||
#include "../ifcparse/IfcCharacterDecoder.h"
|
||||
|
||||
using namespace IfcWrite;
|
||||
|
||||
@@ -69,7 +71,7 @@ IfcEntities IfcWritableEntity::getInverse(Ifc2x3::Type::Enum c, int i, const std
|
||||
}
|
||||
|
||||
std::string IfcWritableEntity::datatype() { return Ifc2x3::Type::ToString(_type); }
|
||||
ArgumentPtr IfcWritableEntity::getArgument (unsigned int i) { if ( i >= getArgumentCount() ) throw; return args[i]; }
|
||||
ArgumentPtr IfcWritableEntity::getArgument (unsigned int i) { if ( i >= getArgumentCount() ) throw IfcParse::IfcException("Argument not set"); return args[i]; }
|
||||
unsigned int IfcWritableEntity::getArgumentCount() {return args.size(); }
|
||||
Ifc2x3::Type::Enum IfcWritableEntity::type() const { return _type; }
|
||||
bool IfcWritableEntity::is(Ifc2x3::Type::Enum v) const { return _type == v; }
|
||||
@@ -152,33 +154,33 @@ void IfcWritableEntity::setArgument(int i,const std::vector<int>& v){
|
||||
arg_writable(i,true);
|
||||
}
|
||||
|
||||
IfcWriteNullArgument::operator int() const { throw; }
|
||||
IfcWriteNullArgument::operator bool() const { throw; }
|
||||
IfcWriteNullArgument::operator double() const { throw; }
|
||||
IfcWriteNullArgument::operator std::string() const { throw; }
|
||||
IfcWriteNullArgument::operator std::vector<double>() const { throw; }
|
||||
IfcWriteNullArgument::operator std::vector<int>() const { throw; }
|
||||
IfcWriteNullArgument::operator std::vector<std::string>() const { throw; }
|
||||
IfcWriteNullArgument::operator IfcUtil::IfcSchemaEntity() const { throw; }
|
||||
IfcWriteNullArgument::operator IfcEntities() const { throw; }
|
||||
IfcWriteNullArgument::operator int() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator bool() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator double() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator std::string() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator std::vector<double>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator std::vector<int>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator std::vector<std::string>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator IfcUtil::IfcSchemaEntity() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteNullArgument::operator IfcEntities() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
bool IfcWriteNullArgument::isNull() const { return true; }
|
||||
ArgumentPtr IfcWriteNullArgument::operator [] (unsigned int i) const { throw; }
|
||||
ArgumentPtr IfcWriteNullArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteNullArgument::toString(bool upper) const { return "$"; }
|
||||
unsigned int IfcWriteNullArgument::Size() const { throw; }
|
||||
unsigned int IfcWriteNullArgument::Size() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
|
||||
IfcWriteEntityListArgument::IfcWriteEntityListArgument(const IfcEntities& v) { value = v; }
|
||||
IfcWriteEntityListArgument::operator int() const { throw; }
|
||||
IfcWriteEntityListArgument::operator bool() const { throw; }
|
||||
IfcWriteEntityListArgument::operator double() const { throw; }
|
||||
IfcWriteEntityListArgument::operator std::string() const { throw; }
|
||||
IfcWriteEntityListArgument::operator std::vector<double>() const { throw; }
|
||||
IfcWriteEntityListArgument::operator std::vector<int>() const { throw; }
|
||||
IfcWriteEntityListArgument::operator std::vector<std::string>() const { throw; }
|
||||
IfcWriteEntityListArgument::operator IfcUtil::IfcSchemaEntity() const { throw; }
|
||||
IfcWriteEntityListArgument::operator int() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator bool() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator double() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator std::string() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator std::vector<double>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator std::vector<int>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator std::vector<std::string>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator IfcUtil::IfcSchemaEntity() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEntityListArgument::operator IfcEntities() const { return value; }
|
||||
bool IfcWriteEntityListArgument::isNull() const { return false; }
|
||||
unsigned int IfcWriteEntityListArgument::Size() const { return value->Size(); }
|
||||
ArgumentPtr IfcWriteEntityListArgument::operator [] (unsigned int i) const { throw; }
|
||||
ArgumentPtr IfcWriteEntityListArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteEntityListArgument::toString(bool upper) const {
|
||||
std::ostringstream ss;
|
||||
ss << "(";
|
||||
@@ -196,19 +198,19 @@ std::string IfcWriteEntityListArgument::toString(bool upper) const {
|
||||
}
|
||||
|
||||
IfcWriteEnumerationArgument::IfcWriteEnumerationArgument(int v, const char* c) {data=v; enumeration_value = c;}
|
||||
IfcWriteEnumerationArgument::operator int() const { throw; }
|
||||
IfcWriteEnumerationArgument::operator bool() const { throw; }
|
||||
IfcWriteEnumerationArgument::operator double() const { throw; }
|
||||
IfcWriteEnumerationArgument::operator int() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator bool() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator double() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator std::string() const { return std::string(enumeration_value); }
|
||||
IfcWriteEnumerationArgument::operator std::vector<double>() const { throw; }
|
||||
IfcWriteEnumerationArgument::operator std::vector<int>() const { throw; }
|
||||
IfcWriteEnumerationArgument::operator std::vector<std::string>() const { throw; }
|
||||
IfcWriteEnumerationArgument::operator IfcUtil::IfcSchemaEntity() const { throw; }
|
||||
IfcWriteEnumerationArgument::operator IfcEntities() const { throw; }
|
||||
IfcWriteEnumerationArgument::operator std::vector<double>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator std::vector<int>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator std::vector<std::string>() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator IfcUtil::IfcSchemaEntity() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
IfcWriteEnumerationArgument::operator IfcEntities() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
bool IfcWriteEnumerationArgument::isNull() const { return false; }
|
||||
ArgumentPtr IfcWriteEnumerationArgument::operator [] (unsigned int i) const { throw; }
|
||||
ArgumentPtr IfcWriteEnumerationArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteEnumerationArgument::toString(bool upper) const { return std::string(".") + enumeration_value + '.';}
|
||||
unsigned int IfcWriteEnumerationArgument::Size() const { throw; }
|
||||
unsigned int IfcWriteEnumerationArgument::Size() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(int v) {data=new int(v); type = Argument_INT;}
|
||||
IfcWriteIntegralArgument::IfcWriteIntegralArgument(bool v) {data=new bool(v); type = Argument_BOOL;}
|
||||
@@ -245,15 +247,15 @@ IfcWriteIntegralArgument::~IfcWriteIntegralArgument() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
IfcWriteIntegralArgument::operator int() const { if ( type != Argument_INT ) throw; return *(int*)data; }
|
||||
IfcWriteIntegralArgument::operator bool() const { if ( type != Argument_BOOL ) throw; return *(bool*)data; }
|
||||
IfcWriteIntegralArgument::operator double() const { if ( type != Argument_DOUBLE ) throw; return *(double*)data; }
|
||||
IfcWriteIntegralArgument::operator std::string() const { if ( type != Argument_STRING ) throw; return *(std::string*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<double>() const { if ( type != Argument_VECTOR_DOUBLE ) throw; return *(std::vector<double>*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<int>() const { if ( type != Argument_VECTOR_INT ) throw; return *(std::vector<int>*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<std::string>() const { if ( type != Argument_VECTOR_STRING ) throw; return *(std::vector<std::string>*)data; }
|
||||
IfcWriteIntegralArgument::operator IfcUtil::IfcSchemaEntity() const { if ( type != Argument_ENTITY ) throw; return (IfcUtil::IfcSchemaEntity)data; }
|
||||
IfcWriteIntegralArgument::operator IfcEntities() const { throw; }
|
||||
IfcWriteIntegralArgument::operator int() const { if ( type != Argument_INT ) throw IfcParse::IfcException("Invalid cast"); return *(int*)data; }
|
||||
IfcWriteIntegralArgument::operator bool() const { if ( type != Argument_BOOL ) throw IfcParse::IfcException("Invalid cast"); return *(bool*)data; }
|
||||
IfcWriteIntegralArgument::operator double() const { if ( type != Argument_DOUBLE ) throw IfcParse::IfcException("Invalid cast"); return *(double*)data; }
|
||||
IfcWriteIntegralArgument::operator std::string() const { if ( type != Argument_STRING ) throw IfcParse::IfcException("Invalid cast"); return *(std::string*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<double>() const { if ( type != Argument_VECTOR_DOUBLE ) throw IfcParse::IfcException("Invalid cast"); return *(std::vector<double>*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<int>() const { if ( type != Argument_VECTOR_INT ) throw IfcParse::IfcException("Invalid cast"); return *(std::vector<int>*)data; }
|
||||
IfcWriteIntegralArgument::operator std::vector<std::string>() const { if ( type != Argument_VECTOR_STRING ) throw IfcParse::IfcException("Invalid cast"); return *(std::vector<std::string>*)data; }
|
||||
IfcWriteIntegralArgument::operator IfcUtil::IfcSchemaEntity() const { if ( type != Argument_ENTITY ) throw IfcParse::IfcException("Invalid cast"); return (IfcUtil::IfcSchemaEntity)data; }
|
||||
IfcWriteIntegralArgument::operator IfcEntities() const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
bool IfcWriteIntegralArgument::isNull() const { return false; }
|
||||
unsigned int IfcWriteIntegralArgument::Size() const {
|
||||
switch ( type ) {
|
||||
@@ -267,11 +269,11 @@ unsigned int IfcWriteIntegralArgument::Size() const {
|
||||
return ((std::vector<std::string>*) data)->size();
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
throw IfcParse::IfcException("Invalid cast");
|
||||
break;
|
||||
}
|
||||
}
|
||||
ArgumentPtr IfcWriteIntegralArgument::operator [] (unsigned int i) const { throw; }
|
||||
ArgumentPtr IfcWriteIntegralArgument::operator [] (unsigned int i) const { throw IfcParse::IfcException("Invalid cast"); }
|
||||
std::string IfcWriteIntegralArgument::toString(bool upper) const {
|
||||
std::ostringstream ss;
|
||||
switch ( type ) {
|
||||
@@ -284,10 +286,12 @@ std::string IfcWriteIntegralArgument::toString(bool upper) const {
|
||||
case Argument_DOUBLE:
|
||||
ss << *(double*) data;
|
||||
break;
|
||||
case Argument_STRING:
|
||||
ss << '\'' << *(std::string*) data << '\'';
|
||||
break;
|
||||
case Argument_VECTOR_INT:
|
||||
case Argument_STRING: {
|
||||
std::string d = *(std::string*) data;
|
||||
if ( upper ) d = IfcCharacterEncoder(d);
|
||||
ss << d;
|
||||
break;
|
||||
} case Argument_VECTOR_INT:
|
||||
ss << "(";
|
||||
{const std::vector<int>& v = *(std::vector<int>*) data;
|
||||
for ( std::vector<int>::const_iterator it = v.begin(); it != v.end(); ++ it ) {
|
||||
@@ -322,16 +326,16 @@ std::string IfcWriteIntegralArgument::toString(bool upper) const {
|
||||
ss << "#" << e->id();
|
||||
}}
|
||||
break;
|
||||
default: throw;
|
||||
default: throw IfcParse::IfcException("Invalid cast");
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
IfcEntities IfcSelectHelperEntity::getInverse(Ifc2x3::Type::Enum,int,const std::string &) {throw;}
|
||||
IfcEntities IfcSelectHelperEntity::getInverse(Ifc2x3::Type::Enum) {throw;}
|
||||
IfcEntities IfcSelectHelperEntity::getInverse(Ifc2x3::Type::Enum,int,const std::string &) {throw IfcParse::IfcException("Invalid cast");}
|
||||
IfcEntities IfcSelectHelperEntity::getInverse(Ifc2x3::Type::Enum) {throw IfcParse::IfcException("Invalid cast");}
|
||||
std::string IfcSelectHelperEntity::datatype() { return Ifc2x3::Type::ToString(_type); }
|
||||
ArgumentPtr IfcSelectHelperEntity::getArgument(unsigned int i) {
|
||||
if ( i != 0 ) throw;
|
||||
if ( i != 0 ) throw IfcParse::IfcException("Invalid cast");
|
||||
return arg;
|
||||
}
|
||||
unsigned int IfcSelectHelperEntity::getArgumentCount() { return 1; }
|
||||
@@ -346,8 +350,8 @@ std::string IfcSelectHelperEntity::toString(bool upper) {
|
||||
ss << dt << "(" << arg->toString(upper) << ")";
|
||||
return ss.str();
|
||||
}
|
||||
unsigned int IfcSelectHelperEntity::id() { throw; }
|
||||
bool IfcSelectHelperEntity::isWritable() { throw; }
|
||||
unsigned int IfcSelectHelperEntity::id() { throw IfcParse::IfcException("Invalid cast"); }
|
||||
bool IfcSelectHelperEntity::isWritable() { throw IfcParse::IfcException("Invalid cast"); }
|
||||
|
||||
IfcSelectHelper::IfcSelectHelper(const std::string& v, Ifc2x3::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteIntegralArgument(v);
|
||||
@@ -361,7 +365,7 @@ IfcSelectHelper::IfcSelectHelper(int v, Ifc2x3::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteIntegralArgument(v);
|
||||
this->entity = new IfcSelectHelperEntity(t,a);
|
||||
}
|
||||
IfcSelectHelper::IfcSelectHelper(float v, Ifc2x3::Type::Enum t) {
|
||||
IfcSelectHelper::IfcSelectHelper(double v, Ifc2x3::Type::Enum t) {
|
||||
IfcWriteArgument* a = new IfcWriteIntegralArgument(v);
|
||||
this->entity = new IfcSelectHelperEntity(t,a);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace IfcWrite {
|
||||
IfcSelectHelper(const std::string& v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcText);
|
||||
IfcSelectHelper(const char* const v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcText);
|
||||
IfcSelectHelper(int v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcInteger);
|
||||
IfcSelectHelper(float v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcReal);
|
||||
IfcSelectHelper(double v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcReal);
|
||||
IfcSelectHelper(bool v, Ifc2x3::Type::Enum t=Ifc2x3::Type::IfcBoolean);
|
||||
bool is(Ifc2x3::Type::Enum t) const;
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
|
||||
+130
-7
@@ -19,16 +19,139 @@
|
||||
|
||||
%include "std_vector.i"
|
||||
%include "std_string.i"
|
||||
%include "exception.i"
|
||||
|
||||
%ignore Ifc::IfcUntypedEntity::is;
|
||||
%ignore Ifc::IfcUntypedEntity::type;
|
||||
%ignore Ifc::IfcUntypedEntity::getArgument;
|
||||
%ignore Ifc::IfcUntypedEntity::IfcUntypedEntity(IfcAbstractEntity);
|
||||
|
||||
%ignore IfcParse::IfcFile::Init;
|
||||
%ignore IfcParse::IfcFile::EntityById;
|
||||
%ignore IfcParse::IfcFile::EntityByGuid;
|
||||
%ignore IfcParse::IfcFile::AddEntity;
|
||||
%ignore operator<<;
|
||||
|
||||
%rename("by_type") EntitiesByType;
|
||||
%rename("get_argument_count") getArgumentCount;
|
||||
%rename("get_argument_type") getArgumentType;
|
||||
%rename("get_argument_name") getArgumentName;
|
||||
%rename("get_argument_index") getArgumentIndex;
|
||||
%rename("set_argument") setArgument;
|
||||
%rename("__repr__") toString;
|
||||
%rename("Entity") IfcUntypedEntity;
|
||||
|
||||
%typemap(out) IfcEntities {
|
||||
const unsigned size = $1->Size();
|
||||
$result = PyList_New(size);
|
||||
for (unsigned i = 0; i < size; ++i) {
|
||||
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr((*$1)[i]), SWIGTYPE_p_Ifc__IfcUntypedEntity, 0);
|
||||
PyList_SetItem($result,i,o);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) std::pair<IfcUtil::ArgumentType,ArgumentPtr> {
|
||||
const Argument& arg = *($1.second);
|
||||
const ArgumentType type = $1.first;
|
||||
if (arg.isNull()) {
|
||||
$result = Py_None;
|
||||
} else {
|
||||
switch(type) {
|
||||
case Argument_INT:
|
||||
$result = PyInt_FromLong((int)arg);
|
||||
break;
|
||||
case Argument_BOOL:
|
||||
$result = PyBool_FromLong((bool)arg);
|
||||
break;
|
||||
case Argument_DOUBLE:
|
||||
$result = PyFloat_FromDouble(arg);
|
||||
break;
|
||||
case Argument_ENUMERATION:
|
||||
case Argument_STRING: {
|
||||
const std::string s = arg;
|
||||
$result = PyString_FromString(s.c_str());
|
||||
break; }
|
||||
case Argument_VECTOR_INT: {
|
||||
const std::vector<int> v = arg;
|
||||
const unsigned size = v.size();
|
||||
$result = PyList_New(size);
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
PyList_SetItem($result,i,PyInt_FromLong(v[i]));
|
||||
}
|
||||
break; }
|
||||
case Argument_VECTOR_DOUBLE: {
|
||||
const std::vector<double> v = arg;
|
||||
const unsigned size = v.size();
|
||||
$result = PyList_New(size);
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
PyList_SetItem($result,i,PyFloat_FromDouble(v[i]));
|
||||
}
|
||||
break; }
|
||||
case Argument_VECTOR_STRING: {
|
||||
const std::vector<std::string> v = arg;
|
||||
const unsigned size = v.size();
|
||||
$result = PyList_New(size);
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
PyList_SetItem($result,i,PyString_FromString(v[i].c_str()));
|
||||
}
|
||||
break; }
|
||||
case Argument_ENTITY: {
|
||||
IfcUtil::IfcSchemaEntity e = arg;
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr(e), SWIGTYPE_p_Ifc__IfcUntypedEntity, 0);
|
||||
break; }
|
||||
case Argument_ENTITY_LIST: {
|
||||
IfcEntities es = arg;
|
||||
const unsigned size = es->Size();
|
||||
$result = PyList_New(size);
|
||||
for (unsigned i = 0; i < size; ++i) {
|
||||
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr((*es)[i]), SWIGTYPE_p_Ifc__IfcUntypedEntity, 0);
|
||||
PyList_SetItem($result,i,o);
|
||||
}
|
||||
break; }
|
||||
case Argument_UNKNOWN:
|
||||
default:
|
||||
SWIG_exception(SWIG_RuntimeError,"Unknown argument type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch(::IfcParse::IfcException& e) {
|
||||
SWIG_exception(SWIG_RuntimeError,e.what());
|
||||
}
|
||||
}
|
||||
|
||||
%module IfcImport %{
|
||||
#include "../ifcparse/IfcException.h"
|
||||
#include "Interface.h"
|
||||
using namespace Ifc;
|
||||
using namespace IfcParse;
|
||||
%}
|
||||
|
||||
%include "Interface.h"
|
||||
|
||||
%module IfcImport %{
|
||||
#include "Interface.h"
|
||||
using namespace IfcGeomObjects;
|
||||
%}
|
||||
%extend IfcParse::IfcFile {
|
||||
Ifc::IfcUntypedEntity* by_id(unsigned id) {
|
||||
return (IfcUntypedEntity*) $self->EntityById(id);
|
||||
}
|
||||
Ifc::IfcUntypedEntity* by_guid(const std::string& guid) {
|
||||
return (IfcUntypedEntity*) $self->EntityByGuid(guid);
|
||||
}
|
||||
void add(Ifc::IfcUntypedEntity* e) {
|
||||
$self->AddEntity(e);
|
||||
}
|
||||
void write(const std::string& fn) {
|
||||
std::ofstream f(fn);
|
||||
f << (*$self);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace std {
|
||||
%template(IntVector) vector<int>;
|
||||
%template(FloatVector) vector<float>;
|
||||
%template(ObjVector) vector<IfcGeomObject>;
|
||||
%template(Ints) vector<int>;
|
||||
%template(Doubles) vector<double>;
|
||||
%template(Strings) vector<string>;
|
||||
};
|
||||
+85
-74
@@ -1,82 +1,93 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
#define IFCUNTYPEDENTITY_H
|
||||
|
||||
namespace IfcGeomObjects {
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
|
||||
const int WELD_VERTICES = 1;
|
||||
const int USE_WORLD_COORDS = 2;
|
||||
const int CONVERT_BACK_UNITS = 3;
|
||||
const int USE_BREP_DATA = 4;
|
||||
const int SEW_SHELLS = 5;
|
||||
const int FASTER_BOOLEANS = 6;
|
||||
const int FORCE_CCW_FACE_ORIENTATION = 7;
|
||||
#include "../ifcparse/IfcUtil.h"
|
||||
#include "../ifcparse/Ifc2x3.h"
|
||||
|
||||
class IfcMesh {
|
||||
#include "../ifcgeom/IfcGeom.h"
|
||||
|
||||
|
||||
namespace Ifc {
|
||||
class IfcUntypedEntity : public IfcUtil::IfcBaseEntity {
|
||||
private:
|
||||
Ifc2x3::Type::Enum _type;
|
||||
public:
|
||||
int id;
|
||||
std::vector<float> verts;
|
||||
std::vector<int> faces;
|
||||
std::vector<int> edges;
|
||||
std::vector<float> normals;
|
||||
std::string brep_data;
|
||||
IfcUntypedEntity(const std::string& s);
|
||||
bool is(Ifc2x3::Type::Enum v) const;
|
||||
Ifc2x3::Type::Enum type() const;
|
||||
bool is_a(const std::string& s) const;
|
||||
std::string is_a() const;
|
||||
unsigned int getArgumentCount() const;
|
||||
IfcUtil::ArgumentType getArgumentType(unsigned int i) const;
|
||||
ArgumentPtr getArgument(unsigned int i) const;
|
||||
ArgumentPtr getArgument(const std::string& a) const;
|
||||
const char* getArgumentName(unsigned int i) const;
|
||||
unsigned getArgumentIndex(const std::string& a) const;
|
||||
|
||||
void setArgument(unsigned int i, int v);
|
||||
void setArgument(unsigned int i, bool v);
|
||||
void setArgument(unsigned int i, double v);
|
||||
void setArgument(unsigned int i, const std::string& v);
|
||||
void setArgument(unsigned int i, const std::vector<int>& v);
|
||||
void setArgument(unsigned int i, const std::vector<double>& v);
|
||||
void setArgument(unsigned int i, const std::vector<std::string>& v);
|
||||
void setArgument(unsigned int i, IfcUntypedEntity* v);
|
||||
void setArgument(unsigned int i, IfcEntities v);
|
||||
|
||||
std::string toString();
|
||||
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> get_argument(unsigned i);
|
||||
std::pair<IfcUtil::ArgumentType,ArgumentPtr> get_argument(const std::string& a);
|
||||
|
||||
bool is_valid();
|
||||
};
|
||||
}
|
||||
|
||||
typedef IfcUtil::IfcSchemaEntity IfcEntity;
|
||||
typedef std::map<Ifc2x3::Type::Enum,IfcEntities> MapEntitiesByType;
|
||||
typedef std::map<unsigned int,IfcEntity> MapEntityById;
|
||||
typedef std::map<std::string,Ifc2x3::IfcRoot::ptr> MapEntityByGuid;
|
||||
typedef std::map<unsigned int,IfcEntities> MapEntitiesByRef;
|
||||
typedef std::map<unsigned int,unsigned int> MapOffsetById;
|
||||
|
||||
namespace IfcParse {
|
||||
class IfcSpfStream;
|
||||
class Tokens;
|
||||
|
||||
class IfcFile {
|
||||
private:
|
||||
MapEntityById byid;
|
||||
MapEntitiesByType bytype;
|
||||
MapEntitiesByRef byref;
|
||||
MapEntityByGuid byguid;
|
||||
MapOffsetById offsets;
|
||||
unsigned int lastId;
|
||||
unsigned int MaxId;
|
||||
IfcParse::IfcSpfStream* file;
|
||||
IfcParse::Tokens* tokens;
|
||||
public:
|
||||
bool Init(const std::string& fn);
|
||||
IfcEntities EntitiesByType(const std::string& t);
|
||||
IfcEntity EntityById(int id);
|
||||
Ifc2x3::IfcRoot::ptr EntityByGuid(const std::string& guid);
|
||||
void AddEntity(IfcUtil::IfcSchemaEntity e);
|
||||
IfcFile();
|
||||
~IfcFile();
|
||||
};
|
||||
|
||||
class IfcObject {
|
||||
public:
|
||||
int id;
|
||||
int parent_id;
|
||||
std::string name;
|
||||
std::string type;
|
||||
std::string guid;
|
||||
std::vector<float> matrix;
|
||||
const std::vector<int> name_as_intvector() {
|
||||
std::vector<int> r;
|
||||
for ( std::string::const_iterator it = name.begin(); it != name.end(); ++ it ) r.push_back(*it);
|
||||
return r;
|
||||
}
|
||||
const std::vector<int> type_as_intvector() {
|
||||
std::vector<int> r;
|
||||
for ( std::string::const_iterator it = type.begin(); it != type.end(); ++ it ) r.push_back(*it);
|
||||
return r;
|
||||
}
|
||||
const std::vector<int> guid_as_intvector() {
|
||||
std::vector<int> r;
|
||||
for ( std::string::const_iterator it = guid.begin(); it != guid.end(); ++ it ) r.push_back(*it);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
IfcParse::IfcFile* open(const std::string& s) {
|
||||
IfcParse::IfcFile* f = new IfcParse::IfcFile();
|
||||
f->Init(s);
|
||||
return f;
|
||||
}
|
||||
|
||||
class IfcGeomObject : public IfcObject {
|
||||
public:
|
||||
IfcMesh* mesh;
|
||||
};
|
||||
std::string create_shape(Ifc::IfcUntypedEntity* e) {
|
||||
if (!e->is(Ifc2x3::Type::IfcProduct)) throw IfcException("Entity is not an IfcProduct");
|
||||
Ifc2x3::IfcProduct* ifc_product = (Ifc2x3::IfcProduct*) e;
|
||||
return IfcGeom::create_brep_data(ifc_product);
|
||||
}
|
||||
}
|
||||
|
||||
bool Next();
|
||||
const IfcGeomObject* Get();
|
||||
bool Init(const std::string fn);
|
||||
bool InitUCS2(const char* fn) {
|
||||
return Init(std::string(fn+1));
|
||||
}
|
||||
void Settings(int setting, bool value);
|
||||
int Progress();
|
||||
const IfcObject* GetObject(int id);
|
||||
bool CleanUp();
|
||||
std::string GetLog();
|
||||
|
||||
};
|
||||
std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f);
|
||||
Reference in New Issue
Block a user