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
|
2018-01-28 18:42:05 +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.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2024-01-30 13:32:41 +00:00
|
|
|
/**
|
|
|
|
* @file STEPFileReader.cpp
|
2015-05-19 03:52:10 +00:00
|
|
|
* @brief Implementation of the STEP file parser, which fills a
|
2024-01-30 13:32:41 +00:00
|
|
|
* STEP::DB with data read from a file.
|
2015-05-19 03:48:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "STEPFileReader.h"
|
|
|
|
#include "STEPFileEncoding.h"
|
2018-01-16 03:14:44 +00:00
|
|
|
#include <assimp/TinyFormatter.h>
|
|
|
|
#include <assimp/fast_atof.h>
|
2020-03-01 12:15:45 +00:00
|
|
|
#include <functional>
|
2021-06-22 16:27:15 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
2020-03-01 12:15:45 +00:00
|
|
|
namespace EXPRESS = STEP::EXPRESS;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
std::string AddLineNumber(const std::string& s,uint64_t line /*= LINE_NOT_SPECIFIED*/, const std::string& prefix = std::string()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return line == STEP::SyntaxError::LINE_NOT_SPECIFIED ? prefix+s : static_cast<std::string>( (Formatter::format(),prefix,"(line ",line,") ",s) );
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
std::string AddEntityID(const std::string& s,uint64_t entity /*= ENTITY_NOT_SPECIFIED*/, const std::string& prefix = std::string()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return entity == STEP::TypeError::ENTITY_NOT_SPECIFIED ? prefix+s : static_cast<std::string>( (Formatter::format(),prefix,"(entity #",entity,") ",s));
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
STEP::SyntaxError::SyntaxError (const std::string& s,uint64_t line) : DeadlyImportError(AddLineNumber(s,line)) {
|
|
|
|
// empty
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
STEP::TypeError::TypeError (const std::string& s,uint64_t entity, uint64_t line) : DeadlyImportError(AddLineNumber(AddEntityID(s,entity),line)) {
|
|
|
|
// empty
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 13:32:41 +00:00
|
|
|
static constexpr char ISO_Token[] = "ISO-10303-21;";
|
|
|
|
static constexpr char FILE_SCHEMA_Token[] = "FILE_SCHEMA";
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-09-28 15:06:03 +00:00
|
|
|
STEP::DB* STEP::ReadFileHeader(std::shared_ptr<IOStream> stream) {
|
2021-06-22 16:27:15 +00:00
|
|
|
std::shared_ptr<StreamReaderLE> reader = std::shared_ptr<StreamReaderLE>(new StreamReaderLE(std::move(stream)));
|
2016-04-05 20:56:11 +00:00
|
|
|
std::unique_ptr<STEP::DB> db = std::unique_ptr<STEP::DB>(new STEP::DB(reader));
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2018-09-28 15:06:03 +00:00
|
|
|
LineSplitter &splitter = db->GetSplitter();
|
|
|
|
if (!splitter || *splitter != ISO_Token ) {
|
|
|
|
throw STEP::SyntaxError("expected magic token: " + std::string( ISO_Token ), 1);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HeaderInfo& head = db->GetHeader();
|
|
|
|
for(++splitter; splitter; ++splitter) {
|
|
|
|
const std::string& s = *splitter;
|
|
|
|
if (s == "DATA;") {
|
|
|
|
// here we go, header done, start of data section
|
|
|
|
++splitter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// want one-based line numbers for human readers, so +1
|
|
|
|
const uint64_t line = splitter.get_index()+1;
|
|
|
|
|
2018-09-28 15:06:03 +00:00
|
|
|
if (s.substr(0,11) == FILE_SCHEMA_Token) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* sz = s.c_str()+11;
|
2024-01-30 13:32:41 +00:00
|
|
|
const char *end = s.c_str() + s.size();
|
|
|
|
SkipSpaces(sz,&sz, end);
|
|
|
|
std::shared_ptr< const EXPRESS::DataType > schema = EXPRESS::DataType::Parse(sz, end);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// the file schema should be a regular list entity, although it usually contains exactly one entry
|
|
|
|
// since the list itself is contained in a regular parameter list, we actually have
|
|
|
|
// two nested lists.
|
|
|
|
const EXPRESS::LIST* list = dynamic_cast<const EXPRESS::LIST*>(schema.get());
|
|
|
|
if (list && list->GetSize()) {
|
|
|
|
list = dynamic_cast<const EXPRESS::LIST*>( (*list)[0].get() );
|
|
|
|
if (!list) {
|
|
|
|
throw STEP::SyntaxError("expected FILE_SCHEMA to be a list",line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX need support for multiple schemas?
|
|
|
|
if (list->GetSize() > 1) {
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_WARN(AddLineNumber("multiple schemas currently not supported",line));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-03-01 12:15:45 +00:00
|
|
|
const EXPRESS::STRING *string = dynamic_cast<const EXPRESS::STRING *>((*list)[0].get());
|
|
|
|
if (!list->GetSize() || nullptr == string ) {
|
2015-05-19 03:57:13 +00:00
|
|
|
throw STEP::SyntaxError("expected FILE_SCHEMA to contain a single string literal",line);
|
|
|
|
}
|
|
|
|
head.fileSchema = *string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX handle more header fields
|
|
|
|
}
|
|
|
|
|
|
|
|
return db.release();
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// check whether the given line contains an entity definition (i.e. starts with "#<number>=")
|
|
|
|
bool IsEntityDef(const std::string& snext)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
if (snext[0] == '#') {
|
|
|
|
// it is only a new entity if it has a '=' after the
|
|
|
|
// entity ID.
|
|
|
|
for(std::string::const_iterator it = snext.begin()+1; it != snext.end(); ++it) {
|
|
|
|
if (*it == '=') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((*it < '0' || *it > '9') && *it != ' ') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* const* types_to_track, size_t len,
|
|
|
|
const char* const* inverse_indices_to_track, size_t len2)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
db.SetSchema(scheme);
|
|
|
|
db.SetTypesToTrack(types_to_track,len);
|
|
|
|
db.SetInverseIndicesToTrack(inverse_indices_to_track,len2);
|
|
|
|
|
|
|
|
const DB::ObjectMap& map = db.GetObjects();
|
|
|
|
LineSplitter& splitter = db.GetSplitter();
|
|
|
|
|
|
|
|
while (splitter) {
|
|
|
|
bool has_next = false;
|
|
|
|
std::string s = *splitter;
|
|
|
|
if (s == "ENDSEC;") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
|
|
|
|
|
|
|
|
// want one-based line numbers for human readers, so +1
|
|
|
|
const uint64_t line = splitter.get_index()+1;
|
|
|
|
// LineSplitter already ignores empty lines
|
|
|
|
ai_assert(s.length());
|
|
|
|
if (s[0] != '#') {
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_WARN(AddLineNumber("expected token \'#\'",line));
|
2015-05-19 03:57:13 +00:00
|
|
|
++splitter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// ---
|
|
|
|
// extract id, entity class name and argument string,
|
|
|
|
// but don't create the actual object yet.
|
|
|
|
// ---
|
|
|
|
const std::string::size_type n0 = s.find_first_of('=');
|
|
|
|
if (n0 == std::string::npos) {
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_WARN(AddLineNumber("expected token \'=\'",line));
|
2015-05-19 03:57:13 +00:00
|
|
|
++splitter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t id = strtoul10_64(s.substr(1,n0-1).c_str());
|
|
|
|
if (!id) {
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_WARN(AddLineNumber("expected positive, numeric entity id",line));
|
2015-05-19 03:57:13 +00:00
|
|
|
++splitter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::string::size_type n1 = s.find_first_of('(',n0);
|
|
|
|
if (n1 == std::string::npos) {
|
|
|
|
has_next = true;
|
|
|
|
bool ok = false;
|
|
|
|
for( ++splitter; splitter; ++splitter) {
|
|
|
|
const std::string& snext = *splitter;
|
|
|
|
if (snext.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the next line doesn't start an entity, so maybe it is
|
|
|
|
// just a continuation for this line, keep going
|
|
|
|
if (!IsEntityDef(snext)) {
|
|
|
|
s.append(snext);
|
|
|
|
n1 = s.find_first_of('(',n0);
|
|
|
|
ok = (n1 != std::string::npos);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ok) {
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_WARN(AddLineNumber("expected token \'(\'",line));
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string::size_type n2 = s.find_last_of(')');
|
|
|
|
if (n2 == std::string::npos || n2 < n1 || n2 == s.length() - 1 || s[n2 + 1] != ';') {
|
|
|
|
has_next = true;
|
|
|
|
bool ok = false;
|
|
|
|
for( ++splitter; splitter; ++splitter) {
|
|
|
|
const std::string& snext = *splitter;
|
|
|
|
if (snext.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-01-30 08:41:39 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// the next line doesn't start an entity, so maybe it is
|
|
|
|
// just a continuation for this line, keep going
|
|
|
|
if (!IsEntityDef(snext)) {
|
|
|
|
s.append(snext);
|
|
|
|
n2 = s.find_last_of(')');
|
|
|
|
ok = !(n2 == std::string::npos || n2 < n1 || n2 == s.length() - 1 || s[n2 + 1] != ';');
|
2019-01-30 08:41:39 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!ok) {
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_WARN(AddLineNumber("expected token \')\'",line));
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map.find(id) != map.end()) {
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_WARN(AddLineNumber((Formatter::format(),"an object with the id #",id," already exists"),line));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string::size_type ns = n0;
|
2021-03-09 20:08:28 +00:00
|
|
|
do {
|
|
|
|
++ns;
|
|
|
|
} while (IsSpace(s.at(ns)));
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string::size_type ne = n1;
|
2021-03-09 20:08:28 +00:00
|
|
|
do {
|
|
|
|
--ne;
|
|
|
|
} while (IsSpace(s.at(ne)));
|
|
|
|
std::string type = s.substr(ns, ne - ns + 1);
|
2021-04-03 08:25:03 +00:00
|
|
|
type = ai_tolower(type);
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* sz = scheme.GetStaticStringForToken(type);
|
|
|
|
if(sz) {
|
2019-03-30 18:12:13 +00:00
|
|
|
const std::string::size_type szLen = n2-n1+1;
|
|
|
|
char* const copysz = new char[szLen+1];
|
2015-05-19 03:57:13 +00:00
|
|
|
std::copy(s.c_str()+n1,s.c_str()+n2+1,copysz);
|
2019-03-30 18:12:13 +00:00
|
|
|
copysz[szLen] = '\0';
|
2015-05-19 03:57:13 +00:00
|
|
|
db.InternInsert(new LazyObject(db,id,line,sz,copysz));
|
|
|
|
}
|
|
|
|
if(!has_next) {
|
|
|
|
++splitter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!splitter) {
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_WARN("STEP: ignoring unexpected EOF");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !DefaultLogger::isNullLogger()){
|
2021-05-13 09:25:27 +00:00
|
|
|
ASSIMP_LOG_DEBUG("STEP: got ",map.size()," object records with ",
|
2021-05-13 08:56:42 +00:00
|
|
|
db.GetRefs().size()," inverse index entries");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
std::shared_ptr<const EXPRESS::DataType> EXPRESS::DataType::Parse(const char*& inout, const char *end, uint64_t line, const EXPRESS::ConversionSchema* schema /*= nullptr*/)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* cur = inout;
|
2024-01-30 13:32:41 +00:00
|
|
|
SkipSpaces(&cur, end);
|
2015-05-19 03:57:13 +00:00
|
|
|
if (*cur == ',' || IsSpaceOrNewLine(*cur)) {
|
|
|
|
throw STEP::SyntaxError("unexpected token, expected parameter",line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// just skip over constructions such as IFCPLANEANGLEMEASURE(0.01) and read only the value
|
|
|
|
if (schema) {
|
|
|
|
bool ok = false;
|
|
|
|
for(const char* t = cur; *t && *t != ')' && *t != ','; ++t) {
|
|
|
|
if (*t=='(') {
|
|
|
|
if (!ok) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(--t;IsSpace(*t);--t);
|
|
|
|
std::string s(cur,static_cast<size_t>(t-cur+1));
|
2021-03-09 20:08:28 +00:00
|
|
|
std::transform(s.begin(),s.end(),s.begin(),&ai_tolower<char> );
|
2015-05-19 03:57:13 +00:00
|
|
|
if (schema->IsKnownToken(s)) {
|
|
|
|
for(cur = t+1;*cur++ != '(';);
|
2024-01-30 13:32:41 +00:00
|
|
|
std::shared_ptr<const EXPRESS::DataType> dt = Parse(cur, end);
|
2015-05-19 03:57:13 +00:00
|
|
|
inout = *cur ? cur+1 : cur;
|
|
|
|
return dt;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!IsSpace(*t)) {
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cur == '*' ) {
|
|
|
|
inout = cur+1;
|
2016-04-05 21:23:53 +00:00
|
|
|
return std::make_shared<EXPRESS::ISDERIVED>();
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '$' ) {
|
|
|
|
inout = cur+1;
|
2016-04-05 21:23:53 +00:00
|
|
|
return std::make_shared<EXPRESS::UNSET>();
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '(' ) {
|
|
|
|
// start of an aggregate, further parsing is done by the LIST factory constructor
|
|
|
|
inout = cur;
|
2024-01-30 13:32:41 +00:00
|
|
|
return EXPRESS::LIST::Parse(inout, end, line, schema);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '.' ) {
|
|
|
|
// enum (includes boolean)
|
|
|
|
const char* start = ++cur;
|
|
|
|
for(;*cur != '.';++cur) {
|
|
|
|
if (*cur == '\0') {
|
|
|
|
throw STEP::SyntaxError("enum not closed",line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inout = cur+1;
|
2016-04-05 21:23:53 +00:00
|
|
|
return std::make_shared<EXPRESS::ENUMERATION>(std::string(start, static_cast<size_t>(cur-start) ));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '#' ) {
|
|
|
|
// object reference
|
2016-04-05 21:23:53 +00:00
|
|
|
return std::make_shared<EXPRESS::ENTITY>(strtoul10_64(++cur,&inout));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '\'' ) {
|
|
|
|
// string literal
|
|
|
|
const char* start = ++cur;
|
|
|
|
|
|
|
|
for(;*cur != '\'';++cur) {
|
|
|
|
if (*cur == '\0') {
|
|
|
|
throw STEP::SyntaxError("string literal not closed",line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur[1] == '\'') {
|
|
|
|
// Vesanen: more than 2 escaped ' in one literal!
|
|
|
|
do {
|
|
|
|
for(cur += 2;*cur != '\'';++cur) {
|
|
|
|
if (*cur == '\0') {
|
|
|
|
throw STEP::SyntaxError("string literal not closed",line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(cur[1] == '\'');
|
|
|
|
}
|
|
|
|
|
|
|
|
inout = cur + 1;
|
|
|
|
|
|
|
|
// assimp is supposed to output UTF8 strings, so we have to deal
|
|
|
|
// with foreign encodings.
|
|
|
|
std::string stemp = std::string(start, static_cast<size_t>(cur - start));
|
|
|
|
if(!StringToUTF8(stemp)) {
|
|
|
|
// TODO: route this to a correct logger with line numbers etc., better error messages
|
2018-04-20 14:23:24 +00:00
|
|
|
ASSIMP_LOG_ERROR("an error occurred reading escape sequences in ASCII text");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2016-04-05 21:23:53 +00:00
|
|
|
return std::make_shared<EXPRESS::STRING>(stemp);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '\"' ) {
|
|
|
|
throw STEP::SyntaxError("binary data not supported yet",line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// else -- must be a number. if there is a decimal dot in it,
|
|
|
|
// parse it as real value, otherwise as integer.
|
|
|
|
const char* start = cur;
|
|
|
|
for(;*cur && *cur != ',' && *cur != ')' && !IsSpace(*cur);++cur) {
|
|
|
|
if (*cur == '.') {
|
|
|
|
double f;
|
|
|
|
inout = fast_atoreal_move<double>(start,f);
|
2016-04-05 21:23:53 +00:00
|
|
|
return std::make_shared<EXPRESS::REAL>(f);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool neg = false;
|
|
|
|
if (*start == '-') {
|
|
|
|
neg = true;
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
else if (*start == '+') {
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
int64_t num = static_cast<int64_t>( strtoul10_64(start,&inout) );
|
2016-04-05 21:23:53 +00:00
|
|
|
return std::make_shared<EXPRESS::INTEGER>(neg?-num:num);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2024-01-30 13:32:41 +00:00
|
|
|
std::shared_ptr<const EXPRESS::LIST> EXPRESS::LIST::Parse(const char*& inout, const char *end,
|
|
|
|
uint64_t line, const EXPRESS::ConversionSchema* schema) {
|
2016-04-05 21:23:53 +00:00
|
|
|
const std::shared_ptr<EXPRESS::LIST> list = std::make_shared<EXPRESS::LIST>();
|
2024-01-30 13:32:41 +00:00
|
|
|
EXPRESS::LIST::MemberList& cur_members = list->members;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
const char* cur = inout;
|
|
|
|
if (*cur++ != '(') {
|
|
|
|
throw STEP::SyntaxError("unexpected token, expected \'(\' token at beginning of list",line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// estimate the number of items upfront - lists can grow large
|
|
|
|
size_t count = 1;
|
|
|
|
for(const char* c=cur; *c && *c != ')'; ++c) {
|
|
|
|
count += (*c == ',' ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:32:41 +00:00
|
|
|
cur_members.reserve(count);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
for(;;++cur) {
|
|
|
|
if (!*cur) {
|
|
|
|
throw STEP::SyntaxError("unexpected end of line while reading list");
|
|
|
|
}
|
2024-01-30 13:32:41 +00:00
|
|
|
SkipSpaces(cur,&cur, end);
|
2015-05-19 03:57:13 +00:00
|
|
|
if (*cur == ')') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:32:41 +00:00
|
|
|
cur_members.push_back(EXPRESS::DataType::Parse(cur, end, line, schema));
|
|
|
|
SkipSpaces(cur, &cur, end);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
if (*cur != ',') {
|
|
|
|
if (*cur == ')') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
throw STEP::SyntaxError("unexpected token, expected \',\' or \')\' token after list element",line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:32:41 +00:00
|
|
|
inout = cur + 1;
|
2015-05-19 03:57:13 +00:00
|
|
|
return list;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 08:41:39 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void handleSkippedDepthFromToken(const char *a, int64_t &skip_depth ) {
|
|
|
|
if (*a == '(') {
|
|
|
|
++skip_depth;
|
|
|
|
} else if (*a == ')') {
|
|
|
|
--skip_depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static int64_t getIdFromToken(const char *a) {
|
|
|
|
const char *tmp;
|
|
|
|
const int64_t num = static_cast<int64_t>(strtoul10_64(a + 1, &tmp));
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
STEP::LazyObject::LazyObject(DB& db, uint64_t id,uint64_t /*line*/, const char* const type,const char* args)
|
2019-01-30 08:41:39 +00:00
|
|
|
: id(id)
|
|
|
|
, type(type)
|
|
|
|
, db(db)
|
|
|
|
, args(args)
|
|
|
|
, obj() {
|
2015-05-19 03:57:13 +00:00
|
|
|
// find any external references and store them in the database.
|
|
|
|
// this helps us emulate STEPs INVERSE fields.
|
2019-01-30 08:41:39 +00:00
|
|
|
if (!db.KeepInverseIndicesForType(type)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2019-01-30 08:41:39 +00:00
|
|
|
// do a quick scan through the argument tuple and watch out for entity references
|
|
|
|
const char *a( args );
|
|
|
|
int64_t skip_depth( 0 );
|
|
|
|
while ( *a ) {
|
|
|
|
handleSkippedDepthFromToken(a, skip_depth);
|
|
|
|
/*if (*a == '(') {
|
|
|
|
++skip_depth;
|
|
|
|
} else if (*a == ')') {
|
|
|
|
--skip_depth;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if (skip_depth >= 1 && *a=='#') {
|
|
|
|
if (*(a + 1) != '#') {
|
|
|
|
/*const char *tmp;
|
|
|
|
const int64_t num = static_cast<int64_t>(strtoul10_64(a + 1, &tmp));
|
|
|
|
db.MarkRef(num, id);*/
|
|
|
|
db.MarkRef(getIdFromToken(a), id);
|
|
|
|
} else {
|
|
|
|
++a;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2019-01-30 08:41:39 +00:00
|
|
|
++a;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-01-30 08:41:39 +00:00
|
|
|
STEP::LazyObject::~LazyObject() {
|
2015-05-19 03:57:13 +00:00
|
|
|
// make sure the right dtor/operator delete get called
|
|
|
|
if (obj) {
|
|
|
|
delete obj;
|
2019-01-30 08:41:39 +00:00
|
|
|
} else {
|
|
|
|
delete[] args;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2019-01-30 08:41:39 +00:00
|
|
|
void STEP::LazyObject::LazyInit() const {
|
2015-05-19 03:57:13 +00:00
|
|
|
const EXPRESS::ConversionSchema& schema = db.GetSchema();
|
|
|
|
STEP::ConvertObjectProc proc = schema.GetConverterProc(type);
|
|
|
|
|
|
|
|
if (!proc) {
|
|
|
|
throw STEP::TypeError("unknown object type: " + std::string(type),id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* acopy = args;
|
2024-01-30 13:32:41 +00:00
|
|
|
const char *end = acopy + std::strlen(args);
|
|
|
|
std::shared_ptr<const EXPRESS::LIST> conv_args = EXPRESS::LIST::Parse(acopy, end, (uint64_t)STEP::SyntaxError::LINE_NOT_SPECIFIED,&db.GetSchema());
|
2015-05-19 03:57:13 +00:00
|
|
|
delete[] args;
|
2020-06-23 19:05:42 +00:00
|
|
|
args = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
// if the converter fails, it should throw an exception, but it should never return nullptr
|
2015-05-19 03:57:13 +00:00
|
|
|
try {
|
|
|
|
obj = proc(db,*conv_args);
|
|
|
|
}
|
|
|
|
catch(const TypeError& t) {
|
|
|
|
// augment line and entity information
|
|
|
|
throw TypeError(t.what(),id);
|
|
|
|
}
|
|
|
|
++db.evaluated_count;
|
|
|
|
ai_assert(obj);
|
|
|
|
|
|
|
|
// store the original id in the object instance
|
|
|
|
obj->SetID(id);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|