Make stepfile schema validation more robust. (#5627)
* Make stepfile schema validation more robust. * Update STEPFile.hpull/5608/head^2
parent
0cef794abd
commit
5c2a33f230
|
@ -220,7 +220,7 @@ void IFCImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
std::unique_ptr<STEP::DB> db(STEP::ReadFileHeader(std::move(stream)));
|
std::unique_ptr<STEP::DB> db(STEP::ReadFileHeader(std::move(stream)));
|
||||||
const STEP::HeaderInfo &head = static_cast<const STEP::DB &>(*db).GetHeader();
|
const STEP::HeaderInfo &head = static_cast<const STEP::DB &>(*db).GetHeader();
|
||||||
|
|
||||||
if (!head.fileSchema.size() || head.fileSchema.substr(0, 3) != "IFC") {
|
if (!head.fileSchema.size() || head.fileSchema.substr(0, 4) != "IFC2") {
|
||||||
ThrowException("Unrecognized file schema: " + head.fileSchema);
|
ThrowException("Unrecognized file schema: " + head.fileSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +260,8 @@ void IFCImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
ThrowException("missing IfcProject entity");
|
ThrowException("missing IfcProject entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConversionData conv(*db, proj->To<Schema_2x3::IfcProject>(), pScene, settings);
|
ConversionData conv(*db, proj->To<Schema_2x3::IfcProject>(), pScene, settings);
|
||||||
SetUnits(conv);
|
SetUnits(conv);
|
||||||
SetCoordinateSpace(conv);
|
SetCoordinateSpace(conv);
|
||||||
|
@ -352,6 +354,11 @@ void ConvertUnit(const ::Assimp::STEP::EXPRESS::DataType &dt, ConversionData &co
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void SetUnits(ConversionData &conv) {
|
void SetUnits(ConversionData &conv) {
|
||||||
|
if (conv.proj.UnitsInContext == nullptr) {
|
||||||
|
IFCImporter::LogError("Skipping conversion data, nullptr.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// see if we can determine the coordinate space used to express.
|
// see if we can determine the coordinate space used to express.
|
||||||
for (size_t i = 0; i < conv.proj.UnitsInContext->Units.size(); ++i) {
|
for (size_t i = 0; i < conv.proj.UnitsInContext->Units.size(); ++i) {
|
||||||
ConvertUnit(*conv.proj.UnitsInContext->Units[i], conv);
|
ConvertUnit(*conv.proj.UnitsInContext->Units[i], conv);
|
||||||
|
|
|
@ -82,8 +82,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
// this is intended as stress test - by default, entities are evaluated
|
// this is intended as stress test - by default, entities are evaluated
|
||||||
// lazily and therefore not unless needed.
|
// lazily and therefore not unless needed.
|
||||||
|
|
||||||
//#define ASSIMP_IFC_TEST
|
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
// ********************************************************************************
|
// ********************************************************************************
|
||||||
|
@ -531,6 +529,7 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T &To() const {
|
const T &To() const {
|
||||||
|
|
||||||
return dynamic_cast<const T &>(**this);
|
return dynamic_cast<const T &>(**this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,12 +580,12 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator==(const std::shared_ptr<LazyObject> &lo, T whatever) {
|
inline bool operator == (const std::shared_ptr<LazyObject> &lo, T whatever) {
|
||||||
return *lo == whatever; // XXX use std::forward if we have 0x
|
return *lo == whatever; // XXX use std::forward if we have 0x
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator==(const std::pair<uint64_t, std::shared_ptr<LazyObject>> &lo, T whatever) {
|
inline bool operator == (const std::pair<uint64_t, std::shared_ptr<LazyObject>> &lo, T whatever) {
|
||||||
return *(lo.second) == whatever; // XXX use std::forward if we have 0x
|
return *(lo.second) == whatever; // XXX use std::forward if we have 0x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,18 +598,30 @@ struct Lazy {
|
||||||
Lazy(const LazyObject *obj = nullptr) : obj(obj) {}
|
Lazy(const LazyObject *obj = nullptr) : obj(obj) {}
|
||||||
|
|
||||||
operator const T *() const {
|
operator const T *() const {
|
||||||
|
if (obj == nullptr) {
|
||||||
|
throw TypeError("Obj type is nullptr.");
|
||||||
|
}
|
||||||
return obj->ToPtr<T>();
|
return obj->ToPtr<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
operator const T &() const {
|
operator const T &() const {
|
||||||
|
if (obj == nullptr) {
|
||||||
|
throw TypeError("Obj type is nullptr.");
|
||||||
|
}
|
||||||
return obj->To<T>();
|
return obj->To<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
const T &operator*() const {
|
const T &operator*() const {
|
||||||
|
if (obj == nullptr) {
|
||||||
|
throw TypeError("Obj type is nullptr.");
|
||||||
|
}
|
||||||
return obj->To<T>();
|
return obj->To<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
const T *operator->() const {
|
const T *operator->() const {
|
||||||
|
if (obj == nullptr) {
|
||||||
|
throw TypeError("Obj type is nullptr.");
|
||||||
|
}
|
||||||
return &obj->To<T>();
|
return &obj->To<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue