2013-03-27 18:34:23 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Tuomas Vaherkoski <tuomasvaherkoski@gmail.com>
|
2015-02-15 21:30:34 +00:00
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-03-27 18:34:23 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file modelparsers.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MODELPARSERS_H
|
|
|
|
#define MODELPARSERS_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/string.h>
|
2014-07-30 09:01:25 +00:00
|
|
|
#include <3d_mesh_model.h>
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
class S3D_MASTER;
|
|
|
|
class S3D_MODEL_PARSER;
|
|
|
|
class X3D_MODEL_PARSER;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* abstract class S3D_MODEL_PARSER
|
|
|
|
* Base class for 3D model parsers.
|
|
|
|
*/
|
|
|
|
class S3D_MODEL_PARSER
|
|
|
|
{
|
|
|
|
public:
|
2015-02-15 21:30:34 +00:00
|
|
|
S3D_MODEL_PARSER( S3D_MASTER* aMaster ) :
|
2013-03-28 16:51:22 +00:00
|
|
|
master( aMaster )
|
2013-03-27 18:34:23 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~S3D_MODEL_PARSER()
|
|
|
|
{}
|
|
|
|
|
|
|
|
S3D_MASTER* GetMaster()
|
|
|
|
{
|
|
|
|
return master;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Create
|
|
|
|
* Factory method for creating concrete 3D model parsers
|
2013-03-28 16:51:22 +00:00
|
|
|
* Notice that the caller is responsible to delete created parser.
|
2013-03-27 18:34:23 +00:00
|
|
|
*
|
|
|
|
* @param aMaster is master object that the parser will fill.
|
|
|
|
* @param aExtension is file extension of the file you are going to parse.
|
|
|
|
*/
|
2013-03-28 16:51:22 +00:00
|
|
|
static S3D_MODEL_PARSER* Create( S3D_MASTER* aMaster, const wxString aExtension );
|
2014-08-21 11:59:57 +00:00
|
|
|
|
2013-03-27 18:34:23 +00:00
|
|
|
/**
|
2014-08-21 11:59:57 +00:00
|
|
|
* pure virtual Function
|
2013-03-27 18:34:23 +00:00
|
|
|
* Concrete parsers should implement this function
|
2014-08-21 11:59:57 +00:00
|
|
|
* @param aFilename = the full file name of the file to load
|
|
|
|
* @param aVrmlunits_to_3Dunits = the scaling factor, i.e. the
|
|
|
|
* convertion from file unit to internal 3D units
|
2013-03-27 18:34:23 +00:00
|
|
|
*/
|
2014-08-21 11:59:57 +00:00
|
|
|
virtual void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits ) = 0;
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
S3D_MASTER* master;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class wxXmlNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class X3D_MODEL_PARSER
|
|
|
|
* Implements parser for X3D file format (VRML2.0 successor)
|
|
|
|
* X3D files can be exported from eg. Blender */
|
|
|
|
class X3D_MODEL_PARSER: public S3D_MODEL_PARSER
|
|
|
|
{
|
|
|
|
public:
|
2013-03-28 16:51:22 +00:00
|
|
|
X3D_MODEL_PARSER( S3D_MASTER* aMaster );
|
2013-03-27 18:34:23 +00:00
|
|
|
~X3D_MODEL_PARSER();
|
2014-08-21 11:59:57 +00:00
|
|
|
|
|
|
|
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
typedef std::map< wxString, wxString > PROPERTY_MAP;
|
2015-02-15 21:30:34 +00:00
|
|
|
typedef std::vector< wxXmlNode* > NODE_LIST;
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetChildsByName
|
|
|
|
* Searches all child nodes with aName.
|
|
|
|
*
|
|
|
|
* @param aParent is node to search from
|
|
|
|
* @param aName is the name of node you try to find
|
|
|
|
* @param aResult contains found nodes
|
|
|
|
*/
|
2013-03-28 16:51:22 +00:00
|
|
|
static void GetChildsByName( wxXmlNode* aParent, const wxString aName, NODE_LIST& aResult );
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetNodeProperties
|
|
|
|
* Collects all node properties to map.
|
|
|
|
*
|
2013-04-25 16:29:35 +00:00
|
|
|
* @param aNode is an XML node.
|
|
|
|
* @param aProps contains map of found properties.
|
2013-03-27 18:34:23 +00:00
|
|
|
*/
|
2013-03-28 16:51:22 +00:00
|
|
|
static void GetNodeProperties( wxXmlNode* aNode, PROPERTY_MAP& aProps );
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-30 09:01:25 +00:00
|
|
|
* Return string representing x3d file in vrml2 format
|
2013-03-27 18:34:23 +00:00
|
|
|
* Function Load must be called before this function, otherwise empty
|
|
|
|
* data set is returned.
|
|
|
|
*/
|
2014-07-30 09:01:25 +00:00
|
|
|
wxString VRML2_representation();
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
private:
|
2015-02-15 21:30:34 +00:00
|
|
|
wxString m_Filename;
|
|
|
|
S3D_MESH* m_model;
|
|
|
|
std::vector< S3D_MESH* > childs;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2013-03-28 16:51:22 +00:00
|
|
|
std::vector< wxString > vrml_materials;
|
|
|
|
std::vector< wxString > vrml_points;
|
|
|
|
std::vector< wxString > vrml_coord_indexes;
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
void readTransform( wxXmlNode* aTransformNode );
|
|
|
|
void readMaterial( wxXmlNode* aMatNode );
|
2013-03-28 16:51:22 +00:00
|
|
|
void readIndexedFaceSet( wxXmlNode* aFaceNode, PROPERTY_MAP& aTransfromProps );
|
2013-03-27 18:34:23 +00:00
|
|
|
bool parseDoubleTriplet( const wxString& aData, S3D_VERTEX& aResult );
|
|
|
|
|
2013-03-28 16:51:22 +00:00
|
|
|
void rotate( S3D_VERTEX& aCoordinate, S3D_VERTEX& aRotAxis, double angle );
|
2013-03-27 18:34:23 +00:00
|
|
|
};
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-02-15 21:30:34 +00:00
|
|
|
typedef std::map< std::string, std::vector< glm::vec3 > > VRML2_COORDINATE_MAP;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2013-03-27 18:34:23 +00:00
|
|
|
/**
|
2014-07-30 09:01:25 +00:00
|
|
|
* class VRML2_MODEL_PARSER
|
2013-03-27 18:34:23 +00:00
|
|
|
* Parses
|
|
|
|
*/
|
2014-07-30 09:01:25 +00:00
|
|
|
class VRML2_MODEL_PARSER: public S3D_MODEL_PARSER
|
2013-03-27 18:34:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-07-30 09:01:25 +00:00
|
|
|
VRML2_MODEL_PARSER( S3D_MASTER* aMaster );
|
|
|
|
~VRML2_MODEL_PARSER();
|
2014-08-21 11:59:57 +00:00
|
|
|
|
|
|
|
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
|
2013-03-27 18:34:23 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-30 09:01:25 +00:00
|
|
|
* Return string representing VRML2 file in vrml2 format
|
|
|
|
* Function Load must be called before this function, otherwise empty
|
|
|
|
* data set is returned.
|
2013-03-27 18:34:23 +00:00
|
|
|
*/
|
2014-07-30 09:01:25 +00:00
|
|
|
wxString VRML2_representation();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int read_Transform();
|
|
|
|
int read_DEF();
|
2015-02-15 21:30:34 +00:00
|
|
|
int read_DEF_Coordinate();
|
2014-07-30 09:01:25 +00:00
|
|
|
int read_Shape();
|
|
|
|
int read_Appearance();
|
|
|
|
int read_material();
|
|
|
|
int read_Material();
|
|
|
|
int read_IndexedFaceSet();
|
2015-02-15 21:30:34 +00:00
|
|
|
int read_IndexedLineSet();
|
2014-07-30 09:01:25 +00:00
|
|
|
int read_Coordinate();
|
2015-02-15 21:30:34 +00:00
|
|
|
int read_CoordinateDef();
|
2014-07-30 09:01:25 +00:00
|
|
|
int read_Normal();
|
2014-07-31 07:01:30 +00:00
|
|
|
int read_NormalIndex();
|
2014-07-30 09:01:25 +00:00
|
|
|
int read_Color();
|
|
|
|
int read_coordIndex();
|
|
|
|
int read_colorIndex();
|
2015-02-15 21:30:34 +00:00
|
|
|
int read_USE();
|
|
|
|
|
|
|
|
bool m_normalPerVertex;
|
|
|
|
bool colorPerVertex;
|
|
|
|
S3D_MESH* m_model;
|
|
|
|
std::vector< S3D_MESH* > childs;
|
|
|
|
FILE* m_file;
|
|
|
|
S3D_MATERIAL* m_Materials;
|
|
|
|
wxString m_Filename;
|
|
|
|
VRML2_COORDINATE_MAP m_defCoordinateMap;
|
2014-07-30 09:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class VRML1_MODEL_PARSER
|
|
|
|
* Parses
|
|
|
|
*/
|
|
|
|
class VRML1_MODEL_PARSER: public S3D_MODEL_PARSER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VRML1_MODEL_PARSER( S3D_MASTER* aMaster );
|
|
|
|
~VRML1_MODEL_PARSER();
|
2014-08-21 11:59:57 +00:00
|
|
|
|
|
|
|
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
|
2013-03-28 16:51:22 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-30 09:01:25 +00:00
|
|
|
* Return string representing VRML2 file in vrml2 format
|
|
|
|
* Function Load must be called before this function, otherwise empty
|
|
|
|
* data set is returned.
|
2013-03-28 16:51:22 +00:00
|
|
|
*/
|
2014-07-30 09:01:25 +00:00
|
|
|
wxString VRML2_representation();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int read_separator();
|
|
|
|
int readMaterial();
|
|
|
|
int readCoordinate3();
|
|
|
|
int readIndexedFaceSet();
|
|
|
|
|
|
|
|
int readMaterial_ambientColor();
|
|
|
|
int readMaterial_diffuseColor();
|
|
|
|
int readMaterial_emissiveColor();
|
|
|
|
int readMaterial_specularColor();
|
|
|
|
int readMaterial_shininess();
|
|
|
|
int readMaterial_transparency();
|
|
|
|
|
|
|
|
int readCoordinate3_point();
|
|
|
|
|
|
|
|
int readIndexedFaceSet_coordIndex();
|
|
|
|
int readIndexedFaceSet_materialIndex();
|
|
|
|
|
2015-02-15 21:30:34 +00:00
|
|
|
bool m_normalPerVertex;
|
|
|
|
bool colorPerVertex;
|
|
|
|
S3D_MESH* m_model;
|
|
|
|
std::vector< S3D_MESH* > childs;
|
|
|
|
S3D_MATERIAL* m_Materials;
|
|
|
|
FILE* m_file;
|
|
|
|
wxString m_Filename;
|
2013-03-27 18:34:23 +00:00
|
|
|
};
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
/**
|
|
|
|
* class VRML_MODEL_PARSER
|
|
|
|
* Parses
|
|
|
|
*/
|
|
|
|
class VRML_MODEL_PARSER: public S3D_MODEL_PARSER
|
|
|
|
{
|
|
|
|
public:
|
2015-03-05 19:46:38 +00:00
|
|
|
/**
|
|
|
|
* ctor: initialize a VRML file parser
|
|
|
|
* @param aMaster = a ref to a 3D footprint shape description to fill
|
|
|
|
* by the vrml file data
|
|
|
|
*/
|
2014-07-30 09:01:25 +00:00
|
|
|
VRML_MODEL_PARSER( S3D_MASTER* aMaster );
|
2015-03-05 19:46:38 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
~VRML_MODEL_PARSER();
|
2014-08-21 11:59:57 +00:00
|
|
|
|
2015-03-05 19:46:38 +00:00
|
|
|
/**
|
|
|
|
* Function load
|
|
|
|
* Load a 3D file and build a S3D_MASTER shape.
|
|
|
|
* file has .vrml ext and can be VRML 1 or VRML 2 format
|
|
|
|
* @param aFilename = the full filename to read
|
|
|
|
* @param aVrmlunits_to_3Dunits = the csaling factor to convert the 3D file unit
|
|
|
|
* to our internal units.
|
|
|
|
*/
|
2014-08-21 11:59:57 +00:00
|
|
|
void Load( const wxString& aFilename, double aVrmlunits_to_3Dunits );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
private:
|
2015-03-05 19:46:38 +00:00
|
|
|
S3D_MASTER* m_curr3DShape; ///< the current 3D shape to build from the file
|
2015-02-15 21:30:34 +00:00
|
|
|
VRML1_MODEL_PARSER* vrml1_parser;
|
|
|
|
VRML2_MODEL_PARSER* vrml2_parser;
|
2014-07-30 09:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-27 18:34:23 +00:00
|
|
|
#endif // MODELPARSERS_H
|