StepFile: introduce generated parser code.

pull/2175/head
Kim Kulling 2018-10-05 19:41:52 +02:00
parent 26e9591cc9
commit aceaecaed7
13 changed files with 18251 additions and 29 deletions

View File

@ -724,6 +724,9 @@ SET( Step_SRCS
STEPFile.h STEPFile.h
Importer/StepFile/StepFileImporter.h Importer/StepFile/StepFileImporter.h
Importer/StepFile/StepFileImporter.cpp Importer/StepFile/StepFileImporter.cpp
Importer/StepFile/StepFileGen1.cpp
Importer/StepFile/StepFileGen2.cpp
Importer/StepFile/StepReaderGen.h
StepExporter.h StepExporter.h
StepExporter.cpp StepExporter.cpp
) )

View File

@ -49,7 +49,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/DefaultIOSystem.h> #include <assimp/DefaultIOSystem.h>
namespace Assimp { namespace Assimp {
namespace STEP { namespace StepFile {
using namespace STEP;
static const aiImporterDesc desc = { "StepFile Importer", static const aiImporterDesc desc = { "StepFile Importer",
"", "",
@ -105,7 +107,7 @@ void StepFileImporter::InternReadFile(const std::string &file, aiScene* pScene,
} }
} }
} // Namespace STEP } // Namespace StepFile
} // Namespace Assimp } // Namespace Assimp
#endif // ASSIMP_BUILD_NO_STEPFILE_IMPORTER #endif // ASSIMP_BUILD_NO_STEPFILE_IMPORTER

View File

@ -48,7 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/BaseImporter.h> #include <assimp/BaseImporter.h>
namespace Assimp { namespace Assimp {
namespace STEP { namespace StepFile {
class StepFileImporter : public BaseImporter { class StepFileImporter : public BaseImporter {
public: public:
@ -63,7 +63,7 @@ protected:
private: private:
}; };
} // Namespace STEP } // Namespace StepFile
} // Namespace Assimp } // Namespace Assimp
#endif // ASSIMP_BUILD_NO_STEPFILE_IMPORTER #endif // ASSIMP_BUILD_NO_STEPFILE_IMPORTER

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -356,7 +356,7 @@ void GetImporterInstanceList(std::vector< BaseImporter* >& out)
out.push_back( new MMDImporter() ); out.push_back( new MMDImporter() );
#endif #endif
#ifndef ASSIMP_BUILD_NO_STEPFILE_IMPORTER #ifndef ASSIMP_BUILD_NO_STEPFILE_IMPORTER
out.push_back(new STEP::StepFileImporter()); out.push_back(new StepFile::StepFileImporter());
#endif #endif
} }

View File

@ -164,7 +164,6 @@ namespace STEP {
class DataType class DataType
{ {
public: public:
typedef std::shared_ptr<const DataType> Out; typedef std::shared_ptr<const DataType> Out;
public: public:
@ -357,6 +356,18 @@ namespace STEP {
MemberList members; MemberList members;
}; };
class BINARY : public PrimitiveDataType<uint32_t> {
public:
BINARY(uint32_t val)
: PrimitiveDataType<uint32_t>(val) {
// empty
}
BINARY()
: PrimitiveDataType<uint32_t>(TypeError::ENTITY_NOT_SPECIFIED) {
// empty
}
};
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
/* Not exactly a full EXPRESS schema but rather a list of conversion functions /* Not exactly a full EXPRESS schema but rather a list of conversion functions

View File

@ -52,17 +52,23 @@ use_ifc_template = False
input_step_template_h = 'StepReaderGen.h.template' input_step_template_h = 'StepReaderGen.h.template'
input_step_template_cpp = 'StepReaderGen.cpp.template' input_step_template_cpp = 'StepReaderGen.cpp.template'
input_template_h = 'IFCReaderGen.h.template' input_ifc_template_h = 'IFCReaderGen.h.template'
input_template_cpp = 'IFCReaderGen.cpp.template' input_ifc_template_cpp = 'IFCReaderGen.cpp.template'
cpp_keywords = "class"
output_file_h = "" output_file_h = ""
output_file_cpp = "" output_file_cpp = ""
if (use_ifc_template ): if (use_ifc_template ):
input_template_h = input_ifc_template_h
input_template_cpp = input_ifc_template_cpp
output_file_h = os.path.join('..','..','code','IFCReaderGen.h') output_file_h = os.path.join('..','..','code','IFCReaderGen.h')
output_file_cpp = os.path.join('..','..','code','IFCReaderGen.cpp') output_file_cpp = os.path.join('..','..','code','IFCReaderGen.cpp')
else: else:
output_file_h = os.path.join('..','..','code','StepReaderGen.h') input_template_h = input_step_template_h
output_file_cpp = os.path.join('..','..','code','StepReaderGen.cpp') input_template_cpp = input_step_template_cpp
output_file_h = os.path.join('..','..','code/Importer/StepFile','StepReaderGen.h')
output_file_cpp = os.path.join('..','..','code/Importer/StepFile','StepReaderGen.cpp')
template_entity_predef = '\tstruct {entity};\n' template_entity_predef = '\tstruct {entity};\n'
template_entity_predef_ni = '\ttypedef NotImplemented {entity}; // (not currently used by Assimp)\n' template_entity_predef_ni = '\ttypedef NotImplemented {entity}; // (not currently used by Assimp)\n'
@ -109,7 +115,6 @@ template_converter_epilogue = '\treturn base;'
import ExpressReader import ExpressReader
def get_list_bounds(collection_spec): def get_list_bounds(collection_spec):
start,end = [(int(n) if n!='?' else 0) for n in re.findall(r'(\d+|\?)',collection_spec)] start,end = [(int(n) if n!='?' else 0) for n in re.findall(r'(\d+|\?)',collection_spec)]
return start,end return start,end
@ -254,12 +259,14 @@ def work(filename):
schema.blacklist_partial -= schema.whitelist schema.blacklist_partial -= schema.whitelist
schema.whitelist |= schema.blacklist_partial schema.whitelist |= schema.blacklist_partial
# Generate list with reserved keywords from c++
cpp_types = cpp_keywords.split(',')
# uncomment this to disable automatic code reduction based on whitelisting all used entities # uncomment this to disable automatic code reduction based on whitelisting all used entities
# (blacklisted entities are those who are in the whitelist and may be instanced, but will # (blacklisted entities are those who are in the whitelist and may be instanced, but will
# only be accessed through a pointer to a base-class. # only be accessed through a pointer to a base-class.
#schema.whitelist = set(schema.entities.keys()) #schema.whitelist = set(schema.entities.keys())
#schema.blacklist_partial = set() #schema.blacklist_partial = set()
for ntype in schema.types.values(): for ntype in schema.types.values():
typedefs += gen_type_struct(ntype,schema) typedefs += gen_type_struct(ntype,schema)
schema_table.append(template_schema_type.format(normalized_name=ntype.name.lower())) schema_table.append(template_schema_type.format(normalized_name=ntype.name.lower()))
@ -268,6 +275,9 @@ def work(filename):
for entity in sorted_entities: for entity in sorted_entities:
parent = entity.parent+',' if entity.parent else '' parent = entity.parent+',' if entity.parent else ''
if ( entity.name in cpp_types ):
entity.name = entity.name + "_t"
print( "renaming " + entity.name)
if entity.name in schema.whitelist: if entity.name in schema.whitelist:
converters += template_converter.format(type=entity.name,contents=gen_converter(entity,schema)) converters += template_converter.format(type=entity.name,contents=gen_converter(entity,schema))
schema_table.append(template_schema.format(type=entity.name,normalized_name=entity.name.lower(),argcnt=len(entity.members))) schema_table.append(template_schema.format(type=entity.name,normalized_name=entity.name.lower(),argcnt=len(entity.members)))

View File

@ -2,7 +2,7 @@
Open Asset Import Library (ASSIMP) Open Asset Import Library (ASSIMP)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2010, ASSIMP Development Team Copyright (c) 2006-2018, ASSIMP Development Team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** MACHINE-GENERATED by scripts/ICFImporter/CppGenerator.py */ /** MACHINE-GENERATED by scripts/ICFImporter/CppGenerator.py */
#include "AssimpPCH.h"
#ifndef ASSIMP_BUILD_NO_IFC_IMPORTER #ifndef ASSIMP_BUILD_NO_IFC_IMPORTER
#include "IFCReaderGen.h" #include "IFCReaderGen.h"

View File

@ -2,7 +2,7 @@
Open Asset Import Library (ASSIMP) Open Asset Import Library (ASSIMP)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2010, ASSIMP Development Team Copyright (c) 2006-2018, ASSIMP Development Team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -40,13 +40,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** MACHINE-GENERATED by scripts/ICFImporter/CppGenerator.py */ /** MACHINE-GENERATED by scripts/ICFImporter/CppGenerator.py */
#include "AssimpPCH.h" #ifndef ASSIMP_BUILD_NO_STEPFILE_IMPORTER
#ifndef ASSIMP_BUILD_NO_IFC_IMPORTER
#include "StepReaderGen.h" #include "code/Importer/StepFile/StepReaderGen.h"
namespace Assimp { namespace Assimp {
using namespace IFC; using namespace StepFile;
namespace { namespace {
@ -57,7 +56,7 @@ namespace {
} }
// ----------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------
void IFC::GetSchema(EXPRESS::ConversionSchema& out) void StepFile::GetSchema(EXPRESS::ConversionSchema& out)
{ {
out = EXPRESS::ConversionSchema(schema_raw); out = EXPRESS::ConversionSchema(schema_raw);
} }

View File

@ -2,7 +2,7 @@
Open Asset Import Library (ASSIMP) Open Asset Import Library (ASSIMP)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2010, ASSIMP Development Team Copyright (c) 2006-2018, ASSIMP Development Team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -40,13 +40,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** MACHINE-GENERATED by scripts/ICFImporter/CppGenerator.py */ /** MACHINE-GENERATED by scripts/ICFImporter/CppGenerator.py */
#ifndef INCLUDED_IFC_READER_GEN_H #ifndef INCLUDED_STEPFILE_READER_GEN_H
#define INCLUDED_IFC_READER_GEN_H #define INCLUDED_STEPFILE_READER_GEN_H
#include "STEPFile.h" #include "code/STEPFile.h"
namespace Assimp { namespace Assimp {
namespace IFC { namespace StepFile {
using namespace STEP; using namespace STEP;
using namespace STEP::EXPRESS; using namespace STEP::EXPRESS;
@ -57,14 +57,14 @@ namespace IFC {
// ****************************************************************************** // ******************************************************************************
// IFC Custom data types // StepFile Custom data types
// ****************************************************************************** // ******************************************************************************
{types} {types}
// ****************************************************************************** // ******************************************************************************
// IFC Entities // StepFile Entities
// ****************************************************************************** // ******************************************************************************
{predefs} {predefs}
@ -72,7 +72,7 @@ namespace IFC {
void GetSchema(EXPRESS::ConversionSchema& out); void GetSchema(EXPRESS::ConversionSchema& out);
} //! IFC } //! StepFile
namespace STEP { namespace STEP {
// ****************************************************************************** // ******************************************************************************
@ -88,4 +88,4 @@ namespace STEP {
} //! STEP } //! STEP
} //! Assimp } //! Assimp
#endif // INCLUDED_IFC_READER_GEN_H #endif // INCLUDED_STEPFILE_READER_GEN_H

View File

@ -43,6 +43,7 @@
import sys import sys
Entity_token = "ENTITY" Entity_token = "ENTITY"
Type_token = "TYPE"
token = [] token = []
file = open(sys.argv[1]) file = open(sys.argv[1])
output = open("step_entitylist.txt", "a") output = open("step_entitylist.txt", "a")
@ -55,6 +56,7 @@ for line in lines:
name = token[1] name = token[1]
print( "Writing entity " + name) print( "Writing entity " + name)
output.write(name) output.write(name)
output.close() output.close()
file.close() file.close()