implementing Element reading

This commit is contained in:
jriegel 2014-12-14 21:12:17 +01:00 committed by Stefan Tröger
parent 1ca23c33c7
commit ade02b5643
13 changed files with 351 additions and 4 deletions

View File

@ -0,0 +1,40 @@
/***************************************************************************
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2014 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include <Base/Console.h>
#include "FcLodHandler.h"
void FcLodHandler::startLod()
{
Base::Console().Log("FcLodHandler::startLod()");
}

View File

@ -0,0 +1,44 @@
/***************************************************************************
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2014 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef FcLodHandler_HEADER
#define FcLodHandler_HEADER
#include "JrJt/LodHandler.h"
class FcLodHandler: public LodHandler
{
public:
virtual void startLod();
};
#endif

View File

@ -0,0 +1,75 @@
/***************************************************************************
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2014 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef Element_Header_HEADER
#define Element_Header_HEADER
#include <istream>
#include <stdint.h>
#include <assert.h>
#include "Context.h"
#include "GUID.h"
#include "UChar.h"
#include "I32.h"
using namespace std;
struct Element_Header
{
Element_Header(){};
Element_Header(Context& cont, bool zLib=false)
{
read(cont, zLib);
};
inline void read(Context& cont ,bool zLib=false)
{
// only zip less implemented so far...
assert(zLib == false);
Element_Lenght.read(cont);
Object_Type_ID.read(cont);
Object_Base_Type.read(cont);
};
I32 Element_Lenght;
GUID Object_Type_ID;
UChar Object_Base_Type;
};
#endif

View File

@ -41,11 +41,34 @@ struct GUID
{ {
GUID(){}; GUID(){};
GUID(uint32_t a1, uint16_t b1, uint16_t b2, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5, uint8_t c6, uint8_t c7, uint8_t c8)
:_A1(a1), _B1(b1), _B2(b2), _C1(c1), _C2(c2), _C3(c3), _C4(c4), _C5(c5), _C6(c6), _C7(c7), _C8(c8)
{}
GUID(Context& cont) GUID(Context& cont)
{ {
read(cont); read(cont);
} }
bool operator!=(const GUID& other) const {
return !operator == (other);
}
bool operator==(const GUID& other) const {
return
_A1 == other._A1
&& _B1 == other._B1
&& _B2 == other._B2
&& _C1 == other._C1
&& _C2 == other._C2
&& _C3 == other._C3
&& _C4 == other._C4
&& _C5 == other._C5
&& _C6 == other._C6
&& _C7 == other._C7
&& _C8 == other._C8;
}
inline void read(Context& cont) inline void read(Context& cont)
{ {
_A1.read(cont); _A1.read(cont);

View File

@ -3,19 +3,25 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <assert.h>
#include <stdint.h> #include <stdint.h>
#include "TOC_Entry.h" #include "TOC_Entry.h"
#include "GUID.h" #include "GUID.h"
#include "UChar.h" #include "UChar.h"
#include "I32.h" #include "I32.h"
#include "TOC_Entry.h" #include "TOC_Entry.h"
#include "LodHandler.h"
#include "Segment_Header.h"
#include "Element_Header.h"
using namespace std; using namespace std;
const GUID JtReader::TriStripSetShapeLODElement_ID(0x10dd10ab, 0x2ac8, 0x11d1, 0x9b, 0x6b, 0x0, 0x80, 0xc7, 0xbb, 0x59, 0x97);
JtReader::JtReader() JtReader::JtReader()
{ {
} }
@ -63,4 +69,32 @@ const std::vector<TOC_Entry>& JtReader::readToc()
return TocEntries; return TocEntries;
}
void JtReader::readLodSegment(const TOC_Entry& toc, LodHandler& handler)
{
std::ifstream strm;
strm.open(_fileName, ios::binary);
if (!strm) throw "cannot open file";
strm.seekg((int32_t)toc.Segment_Offset);
Context cont(strm);
// check if called with the right Toc
assert(toc.getSegmentType() == 7);
// read the segment header
Segment_Header header(cont);
// read the non zip Element header
Element_Header eHeader(cont, false);
if ( eHeader.Object_Type_ID != TriStripSetShapeLODElement_ID)
return;
} }

View File

@ -4,6 +4,9 @@
#include <vector> #include <vector>
#include "TOC_Entry.h" #include "TOC_Entry.h"
class LodHandler;
class JtReader class JtReader
{ {
@ -17,7 +20,9 @@ public:
void readSegment(int tocIndex); void readSegment(int tocIndex);
void readLodSegment(const TOC_Entry&, LodHandler&);
static const GUID TriStripSetShapeLODElement_ID;
protected: protected:

View File

@ -0,0 +1,41 @@
/***************************************************************************
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2014 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef LodHandler_HEADER
#define LodHandler_HEADER
class LodHandler
{
public:
virtual void startLod(){};
};
#endif

View File

@ -0,0 +1,68 @@
/***************************************************************************
* Copyright (c) Juergen Riegel (juergen.riegel@web.de) 2014 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef Segment_Header_HEADER
#define Segment_Header_HEADER
#include <istream>
#include <stdint.h>
#include "Context.h"
#include "GUID.h"
#include "U16.h"
#include "U32.h"
#include "I32.h"
using namespace std;
struct Segment_Header
{
Segment_Header(){};
Segment_Header(Context& cont)
{
read(cont);
};
inline void read(Context& cont)
{
Segment_ID.read(cont);
Segment_Type.read(cont);
Segment_Length.read(cont);
};
GUID Segment_ID;
I32 Segment_Type;
I32 Segment_Length;
};
#endif

View File

@ -56,7 +56,7 @@ struct TOC_Entry
uint8_t getSegmentType()const uint8_t getSegmentType()const
{ {
return Segment_Attributes << 24; return Segment_Attributes >> 24;
} }
std::string toString()const{ std::string toString()const{

View File

@ -32,6 +32,8 @@ struct U16
{ {
U16(){}; U16(){};
U16(uint16_t ui) :_U16(ui){}
U16(Context& cont) U16(Context& cont)
{ {
read(cont); read(cont);

View File

@ -32,6 +32,8 @@ struct U32
{ {
U32(){}; U32(){};
U32(uint32_t ui) :_U32(ui){}
U32(Context& cont) U32(Context& cont)
{ {
read(cont); read(cont);

View File

@ -33,6 +33,8 @@ struct U8
{ {
U8(){}; U8(){};
U8(uint8_t ui) :_U8(ui){}
U8(Context& cont) U8(Context& cont)
{ {
read(cont); read(cont);

View File

@ -25,12 +25,14 @@
#endif #endif
#include <Python.h> #include <iostream>
#include <fstream>
#include <Base/Console.h> #include <Base/Console.h>
#include <Base/FileInfo.h> #include <Base/FileInfo.h>
#include "TestJtReader.h" #include "TestJtReader.h"
#include "FcLodHandler.h"
TestJtReader::TestJtReader() TestJtReader::TestJtReader()
@ -49,6 +51,15 @@ void TestJtReader::read(void)
for (std::vector<TOC_Entry>::const_iterator i = TocEntries.begin(); i != TocEntries.end(); ++i){ for (std::vector<TOC_Entry>::const_iterator i = TocEntries.begin(); i != TocEntries.end(); ++i){
int segType = i->getSegmentType(); int segType = i->getSegmentType();
if (segType == 7){
FcLodHandler handler;
readLodSegment(*i, handler);
}
Base::Console().Log(i->toString().c_str()); Base::Console().Log(i->toString().c_str());
} }