Przeglądaj źródła

Merge pull request #1884 from assimp/isue_1621

closes https://github.com/assimp/assimp/issues/1621: add file check f…
Kim Kulling 7 lat temu
rodzic
commit
9fd6744f93
4 zmienionych plików z 209 dodań i 4 usunięć
  1. 12 3
      code/DXFLoader.cpp
  2. 0 1
      doc/dox.h
  3. 190 0
      test/models/DXF/lineTest
  4. 7 0
      test/unit/utDXFImporterExporter.cpp

+ 12 - 3
code/DXFLoader.cpp

@@ -119,9 +119,18 @@ DXFImporter::~DXFImporter()
 
 // ------------------------------------------------------------------------------------------------
 // Returns whether the class can handle the format of the given file.
-bool DXFImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const
-{
-    return SimpleExtensionCheck(pFile,"dxf");
+bool DXFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig ) const {
+    const std::string& extension = GetExtension( pFile );
+    if ( extension == "dxf" ) {
+        return true;
+    }
+
+    if ( extension.empty() || checkSig ) {
+        static const char *pTokens[] = { "SECTION", "HEADER", "ENDSEC", "BLOCKS" };
+        return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 4 );
+    }
+
+    return false;
 }
 
 // ------------------------------------------------------------------------------------------------

+ 0 - 1
doc/dox.h

@@ -173,7 +173,6 @@ cmake CMakeLists.txt
 A project-file of your default make-system ( like gnu-make on linux or Visual-Studio on Windows ) will be generated. 
 Run the build and you are done. You can find the libs at assimp/lib and the dll's / so's at bin.
 
-
 @section assimp_dll Windows DLL Build
 
 The Assimp-package can be built as DLL. You just need to run the default cmake run.

+ 190 - 0
test/models/DXF/lineTest

@@ -0,0 +1,190 @@
+999
+VISION3D DXF
+0
+SECTION
+2
+HEADER
+9
+$ACADVER
+1
+AC1006
+9
+$INSBASE
+10
+0.0
+20
+0.0
+30
+0.0
+9
+$EXTMIN
+10
+0.0
+20
+0.0
+9
+$EXTMAX
+10
+1000.0
+20
+1000.0
+9
+$LINMIN
+10
+0.0
+20
+0.0
+9
+$LINMAX
+10
+1000.0
+20
+1000.0
+0
+ENDSEC
+0
+SECTION
+2
+TABLES
+0
+TABLE
+2
+LTYPE
+70
+1
+0
+LTYPE
+2
+CONTINUOUS
+70
+64
+3
+Solid line
+72
+65
+73
+0
+40
+0.000000
+0
+ENDTAB
+0
+TABLE
+2
+LAYER
+70
+6
+0
+LAYER
+2
+1
+70
+64
+62
+7
+6
+CONTINUOUS
+0
+ENDTAB
+0
+TABLE
+2
+STYLE
+70
+0
+0
+ENDTAB
+0
+ENDSEC
+0
+SECTION
+2
+BLOCKS
+0
+ENDSEC
+0
+SECTION
+2
+ENTITIES
+0
+3DFACE
+8
+1
+62
+1
+10
+-0.5
+20
+-0.5
+30
+-0.5
+11
+-0.5
+21
+0.5
+31
+-0.5
+12
+0.5
+22
+0.5
+32
+-0.5
+13
+0.5
+23
+-0.5
+33
+-0.5
+0
+3DFACE
+8
+1
+62
+1
+10
+-0.5
+20
+-0.5
+30
+-0.5
+11
+0.5
+21
+-0.5
+31
+-0.5
+12
+0
+22
+-0.5
+32
+0.5
+13
+0
+23
+-0.5
+33
+0.5
+0
+LINE
+8
+1
+62
+1
+10
+0
+20
+-0.5
+30
+0.5
+11
+0
+21
+0.5
+31
+-0.5
+0
+ENDSEC
+0
+EOF

+ 7 - 0
test/unit/utDXFImporterExporter.cpp

@@ -62,3 +62,10 @@ public:
 TEST_F( utDXFImporterExporter, importDXFFromFileTest ) {
     EXPECT_TRUE( importerTest() );
 }
+
+TEST_F( utDXFImporterExporter, importerWithoutExtensionTest ) {
+    Assimp::Importer importer;
+    const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/DXF/lineTest", aiProcess_ValidateDataStructure );
+    EXPECT_NE( nullptr, scene );
+}
+