2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2024-02-23 21:30:05 +00:00
|
|
|
Copyright (c) 2006-2024, assimp team
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2015-05-19 03:48:29 +00:00
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_AI_STEPFILE_H
|
|
|
|
#define INCLUDED_AI_STEPFILE_H
|
|
|
|
|
|
|
|
#include <bitset>
|
2020-03-01 12:15:45 +00:00
|
|
|
#include <map>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include <memory>
|
2020-03-01 12:15:45 +00:00
|
|
|
#include <set>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include <typeinfo>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
#include "AssetLib/FBX/FBXDocument.h" //ObjectMap::value_type
|
2019-06-10 21:26:00 +00:00
|
|
|
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-07-17 13:58:51 +00:00
|
|
|
#ifdef _MSC_VER
|
2020-03-15 17:22:49 +00:00
|
|
|
# pragma warning(push)
|
|
|
|
# pragma warning(disable : 4127 4456 4245 4512 )
|
2021-04-13 18:15:52 +00:00
|
|
|
#endif // _MSC_VER
|
2020-03-15 17:22:49 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
#if _MSC_VER > 1500 || (defined __GNUC___)
|
2020-03-15 17:22:49 +00:00
|
|
|
# define ASSIMP_STEP_USE_UNORDERED_MULTIMAP
|
2017-10-29 19:28:59 +00:00
|
|
|
#else
|
2020-03-15 17:22:49 +00:00
|
|
|
# define step_unordered_map map
|
|
|
|
# define step_unordered_multimap multimap
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ASSIMP_STEP_USE_UNORDERED_MULTIMAP
|
2020-03-15 17:22:49 +00:00
|
|
|
# include <unordered_map>
|
2021-04-13 18:15:52 +00:00
|
|
|
# if defined(_MSC_VER) && _MSC_VER <= 1600
|
2020-03-15 17:22:49 +00:00
|
|
|
# define step_unordered_map tr1::unordered_map
|
|
|
|
# define step_unordered_multimap tr1::unordered_multimap
|
2021-04-13 18:15:52 +00:00
|
|
|
# else
|
|
|
|
# define step_unordered_map unordered_map
|
|
|
|
# define step_unordered_multimap unordered_multimap
|
2020-03-15 17:22:49 +00:00
|
|
|
# endif
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/LineSplitter.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// uncomment this to have the loader evaluate all entities upon loading.
|
|
|
|
// this is intended as stress test - by default, entities are evaluated
|
|
|
|
// lazily and therefore not unless needed.
|
|
|
|
|
|
|
|
namespace Assimp {
|
|
|
|
|
|
|
|
// ********************************************************************************
|
|
|
|
// before things get complicated, this is the basic outline:
|
|
|
|
|
|
|
|
namespace STEP {
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
namespace EXPRESS {
|
|
|
|
|
|
|
|
// base data types known by EXPRESS schemata - any custom data types will derive one of those
|
|
|
|
class DataType;
|
|
|
|
class UNSET; /*: public DataType */
|
|
|
|
class ISDERIVED; /*: public DataType */
|
|
|
|
class ENUM; /*: public DataType */
|
|
|
|
class ENTITY; /*: public DataType */
|
|
|
|
class LIST; /*: public DataType */
|
|
|
|
|
|
|
|
// a conversion schema is not exactly an EXPRESS schema, rather it
|
|
|
|
// is a list of pointers to conversion functions to build up the
|
|
|
|
// object tree from an input file.
|
|
|
|
class ConversionSchema;
|
|
|
|
} // namespace EXPRESS
|
|
|
|
|
|
|
|
struct HeaderInfo;
|
|
|
|
class Object;
|
|
|
|
class LazyObject;
|
|
|
|
class DB;
|
|
|
|
|
|
|
|
typedef Object *(*ConvertObjectProc)(const DB &db, const EXPRESS::LIST ¶ms);
|
|
|
|
} // namespace STEP
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ********************************************************************************
|
|
|
|
|
|
|
|
namespace STEP {
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Exception class used by the STEP loading & parsing code. It is typically
|
2023-01-16 08:12:35 +00:00
|
|
|
* coupled with a line number.
|
2022-07-08 07:47:33 +00:00
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
struct SyntaxError : DeadlyImportError {
|
2020-07-20 15:04:11 +00:00
|
|
|
enum : uint64_t {
|
|
|
|
LINE_NOT_SPECIFIED = 0xfffffffffffffffLL
|
2015-05-19 03:57:13 +00:00
|
|
|
};
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
SyntaxError(const std::string &s, uint64_t line = LINE_NOT_SPECIFIED);
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Exception class used by the STEP loading & parsing code when a type
|
2022-07-08 07:47:33 +00:00
|
|
|
* error (i.e. an entity expects a string but receives a bool) occurs.
|
|
|
|
* It is typically coupled with both an entity id and a line number.
|
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
struct TypeError : DeadlyImportError {
|
2020-07-20 15:04:11 +00:00
|
|
|
enum : uint64_t {
|
|
|
|
ENTITY_NOT_SPECIFIED = 0xffffffffffffffffUL,
|
2020-03-01 12:15:45 +00:00
|
|
|
ENTITY_NOT_SPECIFIED_32 = 0x00000000ffffffff
|
2015-05-19 03:57:13 +00:00
|
|
|
};
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
TypeError(const std::string &s, uint64_t entity = ENTITY_NOT_SPECIFIED, uint64_t line = SyntaxError::LINE_NOT_SPECIFIED);
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// hack to make a given member template-dependent
|
|
|
|
template <typename T, typename T2>
|
|
|
|
T2 &Couple(T2 &in) {
|
|
|
|
return in;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
namespace EXPRESS {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
//** Base class for all STEP data types */
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
class DataType {
|
|
|
|
public:
|
|
|
|
typedef std::shared_ptr<const DataType> Out;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
public:
|
2022-07-08 07:50:04 +00:00
|
|
|
virtual ~DataType() = default;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
const T &To() const {
|
|
|
|
return dynamic_cast<const T &>(*this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
T &To() {
|
|
|
|
return dynamic_cast<T &>(*this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
const T *ToPtr() const {
|
|
|
|
return dynamic_cast<const T *>(this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
T *ToPtr() {
|
|
|
|
return dynamic_cast<T *>(this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// utilities to deal with SELECT entities, which currently lack automatic
|
|
|
|
// conversion support.
|
|
|
|
template <typename T>
|
|
|
|
const T &ResolveSelect(const DB &db) const {
|
|
|
|
return Couple<T>(db).MustGetObject(To<EXPRESS::ENTITY>())->template To<T>();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
const T *ResolveSelectPtr(const DB &db) const {
|
|
|
|
const EXPRESS::ENTITY *e = ToPtr<EXPRESS::ENTITY>();
|
2022-11-08 16:03:55 +00:00
|
|
|
return e ? Couple<T>(db).MustGetObject(*e)->template ToPtr<T>() : (const T *)nullptr;
|
2020-03-01 12:15:45 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
public:
|
2024-01-30 13:32:41 +00:00
|
|
|
/// @brief Parse a variable from a string and set 'inout' to the character behind the last consumed character.
|
|
|
|
///
|
|
|
|
/// An optional schema enables, if specified, automatic conversion of custom data types.
|
|
|
|
///
|
|
|
|
/// @throw SyntaxError
|
|
|
|
static std::shared_ptr<const EXPRESS::DataType> Parse(const char *&inout, const char *end,
|
|
|
|
uint64_t line = SyntaxError::LINE_NOT_SPECIFIED, const EXPRESS::ConversionSchema *schema = nullptr);
|
2020-03-01 12:15:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef DataType SELECT;
|
|
|
|
typedef DataType LOGICAL;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
/// Sentinel class to represent explicitly unset (optional) fields ($)
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
class UNSET : public DataType {};
|
2020-03-01 12:15:45 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
/// Sentinel class to represent explicitly derived fields (*)
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
class ISDERIVED : public DataType {};
|
2020-03-01 12:15:45 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2023-01-16 08:12:35 +00:00
|
|
|
/** Shared implementation for some of the primitive data type, i.e. int, float
|
2022-07-08 07:47:33 +00:00
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
class PrimitiveDataType : public DataType {
|
|
|
|
public:
|
|
|
|
// This is the type that will cd ultimatively be used to
|
|
|
|
// expose this data type to the user.
|
|
|
|
typedef T Out;
|
|
|
|
|
2022-07-08 07:47:33 +00:00
|
|
|
PrimitiveDataType() = default;
|
2020-03-01 12:15:45 +00:00
|
|
|
PrimitiveDataType(const T &val) :
|
|
|
|
val(val) {}
|
|
|
|
|
|
|
|
PrimitiveDataType(const PrimitiveDataType &o) {
|
|
|
|
(*this) = o;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
operator const T &() const {
|
|
|
|
return val;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
PrimitiveDataType &operator=(const PrimitiveDataType &o) {
|
|
|
|
val = o.val;
|
|
|
|
return *this;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
protected:
|
|
|
|
T val;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef PrimitiveDataType<int64_t> INTEGER;
|
|
|
|
typedef PrimitiveDataType<double> REAL;
|
|
|
|
typedef PrimitiveDataType<double> NUMBER;
|
|
|
|
typedef PrimitiveDataType<std::string> STRING;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Generic base class for all enumerated types */
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
class ENUMERATION : public STRING {
|
|
|
|
public:
|
|
|
|
ENUMERATION(const std::string &val) :
|
|
|
|
STRING(val) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ENUMERATION BOOLEAN;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2023-01-16 08:12:35 +00:00
|
|
|
/** This is just a reference to an entity/object somewhere else
|
2022-07-08 07:47:33 +00:00
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
class ENTITY : public PrimitiveDataType<uint64_t> {
|
|
|
|
public:
|
2022-07-08 07:47:33 +00:00
|
|
|
ENTITY(uint64_t val) : PrimitiveDataType<uint64_t>(val) {}
|
|
|
|
ENTITY() : PrimitiveDataType<uint64_t>(TypeError::ENTITY_NOT_SPECIFIED) {}
|
2020-03-01 12:15:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Wrap any STEP aggregate: LIST, SET, ... */
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
class LIST : public DataType {
|
|
|
|
public:
|
|
|
|
// access a particular list index, throw std::range_error for wrong indices
|
|
|
|
std::shared_ptr<const DataType> operator[](size_t index) const {
|
|
|
|
return members[index];
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
size_t GetSize() const {
|
|
|
|
return members.size();
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
public:
|
2023-01-16 08:12:35 +00:00
|
|
|
/** @see DaraType::Parse
|
2022-07-08 07:47:33 +00:00
|
|
|
*/
|
2024-01-30 13:32:41 +00:00
|
|
|
static std::shared_ptr<const EXPRESS::LIST> Parse(const char *&inout, const char *end,
|
2020-03-01 12:15:45 +00:00
|
|
|
uint64_t line = SyntaxError::LINE_NOT_SPECIFIED,
|
2022-11-08 16:03:55 +00:00
|
|
|
const EXPRESS::ConversionSchema *schema = nullptr);
|
2020-03-01 12:15:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::vector<std::shared_ptr<const DataType>> MemberList;
|
|
|
|
MemberList members;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BINARY : public PrimitiveDataType<uint32_t> {
|
|
|
|
public:
|
2022-07-08 07:47:33 +00:00
|
|
|
BINARY(uint32_t val) : PrimitiveDataType<uint32_t>(val) {}
|
|
|
|
BINARY() : PrimitiveDataType<uint32_t>(TypeError::ENTITY_NOT_SPECIFIED_32) {}
|
2020-03-01 12:15:45 +00:00
|
|
|
};
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/* Not exactly a full EXPRESS schema but rather a list of conversion functions
|
2022-07-08 07:47:33 +00:00
|
|
|
* to extract valid C++ objects out of a STEP file. Those conversion functions
|
2023-01-16 08:12:35 +00:00
|
|
|
* may, however, perform further schema validations.
|
2022-07-08 07:47:33 +00:00
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
class ConversionSchema {
|
|
|
|
public:
|
|
|
|
struct SchemaEntry {
|
2022-07-08 07:47:33 +00:00
|
|
|
SchemaEntry(const char *name, ConvertObjectProc func) : mName(name), mFunc(func) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const char *mName;
|
|
|
|
ConvertObjectProc mFunc;
|
|
|
|
};
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
typedef std::map<std::string, ConvertObjectProc> ConverterMap;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <size_t N>
|
|
|
|
explicit ConversionSchema(const SchemaEntry (&schemas)[N]) {
|
|
|
|
*this = schemas;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2022-07-08 07:50:04 +00:00
|
|
|
ConversionSchema() = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
ConvertObjectProc GetConverterProc(const std::string &name) const {
|
|
|
|
ConverterMap::const_iterator it = converters.find(name);
|
|
|
|
return it == converters.end() ? nullptr : (*it).second;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
bool IsKnownToken(const std::string &name) const {
|
|
|
|
return converters.find(name) != converters.end();
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const char *GetStaticStringForToken(const std::string &token) const {
|
|
|
|
ConverterMap::const_iterator it = converters.find(token);
|
|
|
|
return it == converters.end() ? nullptr : (*it).first.c_str();
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <size_t N>
|
|
|
|
const ConversionSchema &operator=(const SchemaEntry (&schemas)[N]) {
|
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
const SchemaEntry &schema = schemas[i];
|
|
|
|
converters[schema.mName] = schema.mFunc;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
private:
|
|
|
|
ConverterMap converters;
|
|
|
|
};
|
|
|
|
} // namespace EXPRESS
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
/** Bundle all the relevant info from a STEP header, parts of which may later
|
2022-07-08 07:47:33 +00:00
|
|
|
* be plainly dumped to the logfile, whereas others may help the caller pick an
|
|
|
|
* appropriate loading strategy.
|
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
struct HeaderInfo {
|
|
|
|
std::string timestamp;
|
|
|
|
std::string app;
|
|
|
|
std::string fileSchema;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
2023-01-16 08:12:35 +00:00
|
|
|
/** Base class for all concrete object instances
|
2022-07-08 07:47:33 +00:00
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
class Object {
|
|
|
|
public:
|
2022-07-08 07:47:33 +00:00
|
|
|
Object(const char *classname = "unknown") : id(0), classname(classname) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2022-07-08 07:47:33 +00:00
|
|
|
virtual ~Object() = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// utilities to simplify casting to concrete types
|
|
|
|
template <typename T>
|
|
|
|
const T &To() const {
|
|
|
|
return dynamic_cast<const T &>(*this);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
T &To() {
|
|
|
|
return dynamic_cast<T &>(*this);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
template <typename T>
|
2020-03-01 12:15:45 +00:00
|
|
|
const T *ToPtr() const {
|
|
|
|
return dynamic_cast<const T *>(this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
T *ToPtr() {
|
|
|
|
return dynamic_cast<T *>(this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
uint64_t GetID() const {
|
|
|
|
return id;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
std::string GetClassName() const {
|
|
|
|
return classname;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
void SetID(uint64_t newval) {
|
|
|
|
id = newval;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
private:
|
|
|
|
uint64_t id;
|
|
|
|
const char *const classname;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
size_t GenericFill(const STEP::DB &db, const EXPRESS::LIST ¶ms, T *in);
|
|
|
|
// (intentionally undefined)
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
/** CRTP shared base class for use by concrete entity implementation classes */
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
template <typename TDerived, size_t arg_count>
|
|
|
|
struct ObjectHelper : virtual Object {
|
2022-07-08 07:47:33 +00:00
|
|
|
ObjectHelper() : aux_is_derived(0) {}
|
2018-09-02 11:04:52 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
static Object *Construct(const STEP::DB &db, const EXPRESS::LIST ¶ms) {
|
|
|
|
// make sure we don't leak if Fill() throws an exception
|
|
|
|
std::unique_ptr<TDerived> impl(new TDerived());
|
|
|
|
|
|
|
|
// GenericFill<T> is undefined so we need to have a specialization
|
2022-07-08 07:47:33 +00:00
|
|
|
static_cast<void>(GenericFill<TDerived>(db, params, &*impl));
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
return impl.release();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// note that this member always exists multiple times within the hierarchy
|
|
|
|
// of an individual object, so any access to it must be disambiguated.
|
|
|
|
std::bitset<arg_count> aux_is_derived;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
/** Class template used to represent OPTIONAL data members in the converted schema */
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
struct Maybe {
|
2022-07-08 07:47:33 +00:00
|
|
|
Maybe() : have() {}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2022-07-08 07:47:33 +00:00
|
|
|
explicit Maybe(const T &ptr) : ptr(ptr), have(true) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
void flag_invalid() {
|
|
|
|
have = false;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
void flag_valid() {
|
|
|
|
have = true;
|
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
bool operator!() const {
|
|
|
|
return !have;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
operator bool() const {
|
|
|
|
return have;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
operator const T &() const {
|
|
|
|
return Get();
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const T &Get() const {
|
|
|
|
ai_assert(have);
|
|
|
|
return ptr;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
Maybe &operator=(const T &_ptr) {
|
|
|
|
ptr = _ptr;
|
|
|
|
have = true;
|
|
|
|
return *this;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
private:
|
|
|
|
template <typename T2>
|
|
|
|
friend struct InternGenericConvert;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
operator T &() {
|
|
|
|
return ptr;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
T ptr;
|
|
|
|
bool have;
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
/** A LazyObject is created when needed. Before this happens, we just keep
|
2023-01-16 08:12:35 +00:00
|
|
|
* the text line that contains the object definition.
|
2022-07-08 07:47:33 +00:00
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
class LazyObject {
|
|
|
|
friend class DB;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
public:
|
|
|
|
LazyObject(DB &db, uint64_t id, uint64_t line, const char *type, const char *args);
|
|
|
|
~LazyObject();
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
Object &operator*() {
|
|
|
|
if (!obj) {
|
|
|
|
LazyInit();
|
|
|
|
ai_assert(obj);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return *obj;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const Object &operator*() const {
|
|
|
|
if (!obj) {
|
|
|
|
LazyInit();
|
|
|
|
ai_assert(obj);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return *obj;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
const T &To() const {
|
2024-06-18 12:22:12 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
return dynamic_cast<const T &>(**this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
T &To() {
|
|
|
|
return dynamic_cast<T &>(**this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
const T *ToPtr() const {
|
|
|
|
return dynamic_cast<const T *>(&**this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
T *ToPtr() {
|
|
|
|
return dynamic_cast<T *>(&**this);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
Object *operator->() {
|
|
|
|
return &**this;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const Object *operator->() const {
|
|
|
|
return &**this;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
bool operator==(const std::string &atype) const {
|
|
|
|
return type == atype;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
bool operator!=(const std::string &atype) const {
|
|
|
|
return type != atype;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
uint64_t GetID() const {
|
|
|
|
return id;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
private:
|
|
|
|
void LazyInit() const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
private:
|
|
|
|
mutable uint64_t id;
|
|
|
|
const char *const type;
|
|
|
|
DB &db;
|
|
|
|
mutable const char *args;
|
|
|
|
mutable Object *obj;
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
2024-06-18 12:22:12 +00:00
|
|
|
inline bool operator == (const std::shared_ptr<LazyObject> &lo, T whatever) {
|
2020-03-01 12:15:45 +00:00
|
|
|
return *lo == whatever; // XXX use std::forward if we have 0x
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
2024-06-18 12:22:12 +00:00
|
|
|
inline bool operator == (const std::pair<uint64_t, std::shared_ptr<LazyObject>> &lo, T whatever) {
|
2020-03-01 12:15:45 +00:00
|
|
|
return *(lo.second) == whatever; // XXX use std::forward if we have 0x
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
/** Class template used to represent lazily evaluated object references in the converted schema */
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
struct Lazy {
|
|
|
|
typedef Lazy Out;
|
2022-07-08 07:47:33 +00:00
|
|
|
Lazy(const LazyObject *obj = nullptr) : obj(obj) {}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
operator const T *() const {
|
2024-06-18 12:22:12 +00:00
|
|
|
if (obj == nullptr) {
|
|
|
|
throw TypeError("Obj type is nullptr.");
|
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return obj->ToPtr<T>();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
operator const T &() const {
|
2024-06-18 12:22:12 +00:00
|
|
|
if (obj == nullptr) {
|
|
|
|
throw TypeError("Obj type is nullptr.");
|
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return obj->To<T>();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const T &operator*() const {
|
2024-06-18 12:22:12 +00:00
|
|
|
if (obj == nullptr) {
|
|
|
|
throw TypeError("Obj type is nullptr.");
|
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return obj->To<T>();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const T *operator->() const {
|
2024-06-18 12:22:12 +00:00
|
|
|
if (obj == nullptr) {
|
|
|
|
throw TypeError("Obj type is nullptr.");
|
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return &obj->To<T>();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const LazyObject *obj;
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
/** Class template used to represent LIST and SET data members in the converted schema */
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
template <typename T, uint64_t min_cnt, uint64_t max_cnt = 0uL>
|
|
|
|
struct ListOf : public std::vector<typename T::Out> {
|
|
|
|
typedef typename T::Out OutScalar;
|
|
|
|
typedef ListOf Out;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
ListOf() {
|
|
|
|
static_assert(min_cnt <= max_cnt || !max_cnt, "min_cnt <= max_cnt || !max_cnt");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
template <typename TOut>
|
|
|
|
struct PickBaseType {
|
|
|
|
typedef EXPRESS::PrimitiveDataType<TOut> Type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename TOut>
|
|
|
|
struct PickBaseType<Lazy<TOut>> {
|
|
|
|
typedef EXPRESS::ENTITY Type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct PickBaseType<std::shared_ptr<const EXPRESS::DataType>>;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
struct InternGenericConvert {
|
|
|
|
void operator()(T &out, const std::shared_ptr<const EXPRESS::DataType> &in, const STEP::DB & /*db*/) {
|
|
|
|
try {
|
|
|
|
out = dynamic_cast<const typename PickBaseType<T>::Type &>(*in);
|
|
|
|
} catch (std::bad_cast &) {
|
|
|
|
throw TypeError("type error reading literal field");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
}
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <>
|
|
|
|
struct InternGenericConvert<std::shared_ptr<const EXPRESS::DataType>> {
|
|
|
|
void operator()(std::shared_ptr<const EXPRESS::DataType> &out, const std::shared_ptr<const EXPRESS::DataType> &in, const STEP::DB & /*db*/) {
|
|
|
|
out = in;
|
|
|
|
}
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
struct InternGenericConvert<Maybe<T>> {
|
|
|
|
void operator()(Maybe<T> &out, const std::shared_ptr<const EXPRESS::DataType> &in, const STEP::DB &db) {
|
|
|
|
GenericConvert((T &)out, in, db);
|
|
|
|
out.flag_valid();
|
|
|
|
}
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-07-07 15:35:03 +00:00
|
|
|
#if _MSC_VER > 1920
|
2020-03-15 17:22:49 +00:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4127)
|
2020-03-21 07:56:49 +00:00
|
|
|
#endif // _WIN32
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T, uint64_t min_cnt, uint64_t max_cnt>
|
|
|
|
struct InternGenericConvertList {
|
|
|
|
void operator()(ListOf<T, min_cnt, max_cnt> &out, const std::shared_ptr<const EXPRESS::DataType> &inp_base, const STEP::DB &db) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const EXPRESS::LIST *inp = dynamic_cast<const EXPRESS::LIST *>(inp_base.get());
|
|
|
|
if (!inp) {
|
|
|
|
throw TypeError("type error reading aggregate");
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// XXX is this really how the EXPRESS notation ([?:3],[1:3]) is intended?
|
2020-03-08 20:24:01 +00:00
|
|
|
const size_t len = inp->GetSize();
|
|
|
|
if (0 != max_cnt && len > max_cnt) {
|
2020-03-01 12:15:45 +00:00
|
|
|
ASSIMP_LOG_WARN("too many aggregate elements");
|
2020-03-08 20:24:01 +00:00
|
|
|
} else if (len < min_cnt) {
|
2020-03-01 12:15:45 +00:00
|
|
|
ASSIMP_LOG_WARN("too few aggregate elements");
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
out.reserve(inp->GetSize());
|
|
|
|
for (size_t i = 0; i < inp->GetSize(); ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
out.push_back(typename ListOf<T, min_cnt, max_cnt>::OutScalar());
|
|
|
|
try {
|
|
|
|
GenericConvert(out.back(), (*inp)[i], db);
|
|
|
|
} catch (const TypeError &t) {
|
|
|
|
throw TypeError(t.what() + std::string(" of aggregate"));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
}
|
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T>
|
|
|
|
struct InternGenericConvert<Lazy<T>> {
|
|
|
|
void operator()(Lazy<T> &out, const std::shared_ptr<const EXPRESS::DataType> &in_base, const STEP::DB &db) {
|
|
|
|
const EXPRESS::ENTITY *in = dynamic_cast<const EXPRESS::ENTITY *>(in_base.get());
|
|
|
|
if (!in) {
|
|
|
|
throw TypeError("type error reading entity");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
out = Couple<T>(db).GetObject(*in);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
};
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T1>
|
|
|
|
inline void GenericConvert(T1 &a, const std::shared_ptr<const EXPRESS::DataType> &b, const STEP::DB &db) {
|
|
|
|
return InternGenericConvert<T1>()(a, b, db);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
template <typename T1, uint64_t N1, uint64_t N2>
|
|
|
|
inline void GenericConvert(ListOf<T1, N1, N2> &a, const std::shared_ptr<const EXPRESS::DataType> &b, const STEP::DB &db) {
|
|
|
|
return InternGenericConvertList<T1, N1, N2>()(a, b, db);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
/** Lightweight manager class that holds the map of all objects in a
|
2022-07-08 07:47:33 +00:00
|
|
|
* STEP file. DB's are exclusively maintained by the functions in
|
|
|
|
* STEPFileReader.h
|
|
|
|
*/
|
2020-03-01 12:15:45 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
class DB {
|
|
|
|
friend DB *ReadFileHeader(std::shared_ptr<IOStream> stream);
|
|
|
|
friend void ReadFile(DB &db, const EXPRESS::ConversionSchema &scheme,
|
|
|
|
const char *const *types_to_track, size_t len,
|
|
|
|
const char *const *inverse_indices_to_track, size_t len2);
|
|
|
|
|
|
|
|
friend class LazyObject;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// objects indexed by ID - this can grow pretty large (i.e some hundred million
|
|
|
|
// entries), so use raw pointers to avoid *any* overhead.
|
|
|
|
typedef std::map<uint64_t, const LazyObject *> ObjectMap;
|
|
|
|
|
|
|
|
// objects indexed by their declarative type, but only for those that we truly want
|
|
|
|
typedef std::set<const LazyObject *> ObjectSet;
|
|
|
|
typedef std::map<std::string, ObjectSet> ObjectMapByType;
|
|
|
|
|
|
|
|
// list of types for which to keep inverse indices for all references
|
|
|
|
// that the respective objects keep.
|
|
|
|
// the list keeps pointers to strings in static storage
|
|
|
|
typedef std::set<const char *> InverseWhitelist;
|
|
|
|
|
|
|
|
// references - for each object id the ids of all objects which reference it
|
|
|
|
// this is used to simulate STEP inverse indices for selected types.
|
|
|
|
typedef std::step_unordered_multimap<uint64_t, uint64_t> RefMap;
|
|
|
|
typedef std::pair<RefMap::const_iterator, RefMap::const_iterator> RefMapRange;
|
|
|
|
|
|
|
|
private:
|
2021-06-22 16:27:15 +00:00
|
|
|
DB(const std::shared_ptr<StreamReaderLE> &reader) :
|
2020-03-01 12:15:45 +00:00
|
|
|
reader(reader), splitter(*reader, true, true), evaluated_count(), schema(nullptr) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
~DB() {
|
|
|
|
for (ObjectMap::value_type &o : objects) {
|
|
|
|
delete o.second;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
uint64_t GetObjectCount() const {
|
|
|
|
return objects.size();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
uint64_t GetEvaluatedObjectCount() const {
|
|
|
|
return evaluated_count;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const HeaderInfo &GetHeader() const {
|
|
|
|
return header;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const EXPRESS::ConversionSchema &GetSchema() const {
|
|
|
|
return *schema;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const ObjectMap &GetObjects() const {
|
|
|
|
return objects;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const ObjectMapByType &GetObjectsByType() const {
|
|
|
|
return objects_bytype;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const RefMap &GetRefs() const {
|
|
|
|
return refs;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
bool KeepInverseIndicesForType(const char *const type) const {
|
|
|
|
return inv_whitelist.find(type) != inv_whitelist.end();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// get the yet unevaluated object record with a given id
|
|
|
|
const LazyObject *GetObject(uint64_t id) const {
|
|
|
|
const ObjectMap::const_iterator it = objects.find(id);
|
|
|
|
if (it != objects.end()) {
|
|
|
|
return (*it).second;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// get an arbitrary object out of the soup with the only restriction being its type.
|
|
|
|
const LazyObject *GetObject(const std::string &type) const {
|
|
|
|
const ObjectMapByType::const_iterator it = objects_bytype.find(type);
|
|
|
|
if (it != objects_bytype.end() && (*it).second.size()) {
|
|
|
|
return *(*it).second.begin();
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2022-07-08 07:47:33 +00:00
|
|
|
return nullptr;
|
2020-03-01 12:15:45 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// same, but raise an exception if the object doesn't exist and return a reference
|
|
|
|
const LazyObject &MustGetObject(uint64_t id) const {
|
|
|
|
const LazyObject *o = GetObject(id);
|
|
|
|
if (!o) {
|
|
|
|
throw TypeError("requested entity is not present", id);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return *o;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const LazyObject &MustGetObject(const std::string &type) const {
|
|
|
|
const LazyObject *o = GetObject(type);
|
|
|
|
if (!o) {
|
|
|
|
throw TypeError("requested entity of type " + type + "is not present");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
return *o;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
#ifdef ASSIMP_IFC_TEST
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
// evaluate *all* entities in the file. this is a power test for the loader
|
|
|
|
void EvaluateAll() {
|
|
|
|
for (ObjectMap::value_type &e : objects) {
|
|
|
|
**e.second;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
ai_assert(evaluated_count == objects.size());
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
private:
|
|
|
|
// full access only offered to close friends - they should
|
|
|
|
// use the provided getters rather than messing around with
|
|
|
|
// the members directly.
|
|
|
|
LineSplitter &GetSplitter() {
|
|
|
|
return splitter;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
void InternInsert(const LazyObject *lz) {
|
|
|
|
objects[lz->GetID()] = lz;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
const ObjectMapByType::iterator it = objects_bytype.find(lz->type);
|
|
|
|
if (it != objects_bytype.end()) {
|
|
|
|
(*it).second.insert(lz);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
void SetSchema(const EXPRESS::ConversionSchema &_schema) {
|
|
|
|
schema = &_schema;
|
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
void SetTypesToTrack(const char *const *types, size_t N) {
|
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
objects_bytype[types[i]] = ObjectSet();
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
void SetInverseIndicesToTrack(const char *const *types, size_t N) {
|
|
|
|
for (size_t i = 0; i < N; ++i) {
|
|
|
|
const char *const sz = schema->GetStaticStringForToken(types[i]);
|
|
|
|
ai_assert(sz);
|
|
|
|
inv_whitelist.insert(sz);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
HeaderInfo &GetHeader() {
|
|
|
|
return header;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
void MarkRef(uint64_t who, uint64_t by_whom) {
|
|
|
|
refs.insert(std::make_pair(who, by_whom));
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
private:
|
|
|
|
HeaderInfo header;
|
|
|
|
ObjectMap objects;
|
|
|
|
ObjectMapByType objects_bytype;
|
|
|
|
RefMap refs;
|
|
|
|
InverseWhitelist inv_whitelist;
|
|
|
|
std::shared_ptr<StreamReaderLE> reader;
|
|
|
|
LineSplitter splitter;
|
|
|
|
uint64_t evaluated_count;
|
|
|
|
const EXPRESS::ConversionSchema *schema;
|
|
|
|
};
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-07-17 13:58:51 +00:00
|
|
|
#ifdef _MSC_VER
|
2020-03-15 17:22:49 +00:00
|
|
|
#pragma warning(pop)
|
2020-07-17 13:58:51 +00:00
|
|
|
#endif // _MSC_VER
|
2020-03-01 12:15:45 +00:00
|
|
|
|
|
|
|
} // namespace STEP
|
|
|
|
} // namespace Assimp
|
2016-10-21 17:44:31 +00:00
|
|
|
|
|
|
|
#endif // INCLUDED_AI_STEPFILE_H
|