Fix X3D patch commit coding policy issues.

This commit is contained in:
Wayne Stambaugh 2013-03-28 12:51:22 -04:00
parent 3c037a3c31
commit cd18ff1762
7 changed files with 265 additions and 227 deletions

View File

@ -41,16 +41,17 @@
// Imported function: // Imported function:
extern void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits ); extern void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits );
S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster,
const wxString aExtension ) S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster,
const wxString aExtension )
{ {
if ( aExtension == wxT( "x3d" ) ) if ( aExtension == wxT( "x3d" ) )
{ {
return new X3D_MODEL_PARSER(aMaster); return new X3D_MODEL_PARSER( aMaster );
} }
else if ( aExtension == wxT( "wrl" ) ) else if ( aExtension == wxT( "wrl" ) )
{ {
return new VRML_MODEL_PARSER(aMaster); return new VRML_MODEL_PARSER( aMaster );
} }
else else
{ {
@ -58,6 +59,7 @@ S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster,
} }
} }
int S3D_MASTER::ReadData() int S3D_MASTER::ReadData()
{ {
wxFileName fn; wxFileName fn;
@ -69,16 +71,17 @@ int S3D_MASTER::ReadData()
} }
wxString shape3DNname = m_Shape3DName; wxString shape3DNname = m_Shape3DName;
#ifdef __WINDOWS__ #ifdef __WINDOWS__
shape3DNname.Replace( wxT("/"), wxT("\\") ); shape3DNname.Replace( wxT( "/" ), wxT( "\\" ) );
#else #else
shape3DNname.Replace( wxT("\\"), wxT("/") ); shape3DNname.Replace( wxT( "\\" ), wxT( "/" ) );
#endif #endif
if( wxFileName::FileExists( shape3DNname ) ) if( wxFileName::FileExists( shape3DNname ) )
{ {
FullFilename = shape3DNname; FullFilename = shape3DNname;
fn.Assign(FullFilename); fn.Assign( FullFilename );
} }
else else
{ {
@ -94,14 +97,15 @@ int S3D_MASTER::ReadData()
} }
wxString extension = fn.GetExt(); wxString extension = fn.GetExt();
S3D_MODEL_PARSER* parser = S3D_MODEL_PARSER::Create(this, extension); S3D_MODEL_PARSER* parser = S3D_MODEL_PARSER::Create( this, extension );
if(parser)
if( parser )
{ {
parser->Load(FullFilename); parser->Load( FullFilename );
delete parser; delete parser;
return 0; return 0;
} }
else else
{ {
wxLogDebug( wxT( "Unknown file type <%s>" ), GetChars( extension ) ); wxLogDebug( wxT( "Unknown file type <%s>" ), GetChars( extension ) );
} }
@ -109,6 +113,7 @@ int S3D_MASTER::ReadData()
return -1; return -1;
} }
int STRUCT_3D_SHAPE::ReadData( FILE* file, int* LineNum ) int STRUCT_3D_SHAPE::ReadData( FILE* file, int* LineNum )
{ {
char line[512]; char line[512];

View File

@ -49,8 +49,8 @@ class X3D_MODEL_PARSER;
class S3D_MODEL_PARSER class S3D_MODEL_PARSER
{ {
public: public:
S3D_MODEL_PARSER(S3D_MASTER* aMaster) S3D_MODEL_PARSER(S3D_MASTER* aMaster) :
:master(aMaster) master( aMaster )
{} {}
virtual ~S3D_MODEL_PARSER() virtual ~S3D_MODEL_PARSER()
@ -64,19 +64,18 @@ public:
/** /**
* Function Create * Function Create
* Factory method for creating concrete 3D model parsers * Factory method for creating concrete 3D model parsers
* Notice that the caller is responible to delete created parser. * Notice that the caller is responsible to delete created parser.
* *
* @param aMaster is master object that the parser will fill. * @param aMaster is master object that the parser will fill.
* @param aExtension is file extension of the file you are going to parse. * @param aExtension is file extension of the file you are going to parse.
*/ */
static S3D_MODEL_PARSER* Create( S3D_MASTER* aMaster, static S3D_MODEL_PARSER* Create( S3D_MASTER* aMaster, const wxString aExtension );
const wxString aExtension );
/** /**
* Function Load * Function Load
* *
* Concrete parsers should implement this function * Concrete parsers should implement this function
*/ */
virtual void Load(const wxString aFilename) = 0; virtual void Load( const wxString aFilename ) = 0;
private: private:
S3D_MASTER* master; S3D_MASTER* master;
@ -92,9 +91,9 @@ class wxXmlNode;
class X3D_MODEL_PARSER: public S3D_MODEL_PARSER class X3D_MODEL_PARSER: public S3D_MODEL_PARSER
{ {
public: public:
X3D_MODEL_PARSER(S3D_MASTER* aMaster); X3D_MODEL_PARSER( S3D_MASTER* aMaster );
~X3D_MODEL_PARSER(); ~X3D_MODEL_PARSER();
void Load(const wxString aFilename); void Load( const wxString aFilename );
typedef std::map< wxString, wxString > PROPERTY_MAP; typedef std::map< wxString, wxString > PROPERTY_MAP;
typedef std::vector< wxXmlNode* > NODE_LIST; typedef std::vector< wxXmlNode* > NODE_LIST;
@ -107,8 +106,7 @@ public:
* @param aName is the name of node you try to find * @param aName is the name of node you try to find
* @param aResult contains found nodes * @param aResult contains found nodes
*/ */
static void GetChildsByName(wxXmlNode* aParent, const wxString aName, static void GetChildsByName( wxXmlNode* aParent, const wxString aName, NODE_LIST& aResult );
NODE_LIST& aResult);
/** /**
* Function GetNodeProperties * Function GetNodeProperties
@ -116,7 +114,7 @@ public:
* *
* @param aProps contains map of found properties * @param aProps contains map of found properties
*/ */
static void GetNodeProperties(wxXmlNode* aNode, PROPERTY_MAP& aProps); static void GetNodeProperties( wxXmlNode* aNode, PROPERTY_MAP& aProps );
/** /**
* Return string representing x3d file in vrml format * Return string representing x3d file in vrml format
@ -126,17 +124,16 @@ public:
wxString VRML_representation(); wxString VRML_representation();
private: private:
std::vector<wxString> vrml_materials; std::vector< wxString > vrml_materials;
std::vector<wxString> vrml_points; std::vector< wxString > vrml_points;
std::vector<wxString> vrml_coord_indexes; std::vector< wxString > vrml_coord_indexes;
void readTransform( wxXmlNode* aTransformNode ); void readTransform( wxXmlNode* aTransformNode );
void readMaterial( wxXmlNode* aMatNode ); void readMaterial( wxXmlNode* aMatNode );
void readIndexedFaceSet( wxXmlNode* aFaceNode, void readIndexedFaceSet( wxXmlNode* aFaceNode, PROPERTY_MAP& aTransfromProps );
PROPERTY_MAP& aTransfromProps );
bool parseDoubleTriplet( const wxString& aData, S3D_VERTEX& aResult ); bool parseDoubleTriplet( const wxString& aData, S3D_VERTEX& aResult );
void rotate( S3D_VERTEX& aCoordinate, S3D_VERTEX& aRotAxis, double angle); void rotate( S3D_VERTEX& aCoordinate, S3D_VERTEX& aRotAxis, double angle );
}; };
/** /**
@ -146,9 +143,9 @@ private:
class VRML_MODEL_PARSER: public S3D_MODEL_PARSER class VRML_MODEL_PARSER: public S3D_MODEL_PARSER
{ {
public: public:
VRML_MODEL_PARSER(S3D_MASTER* aMaster); VRML_MODEL_PARSER( S3D_MASTER* aMaster );
~VRML_MODEL_PARSER(); ~VRML_MODEL_PARSER();
void Load(const wxString aFilename); void Load( const wxString aFilename );
private: private:
/** /**
@ -170,7 +167,26 @@ private:
int readShape( FILE* file, int* LineNum ); int readShape( FILE* file, int* LineNum );
int readAppearance( FILE* file, int* LineNum ); int readAppearance( FILE* file, int* LineNum );
int readGeometry( FILE* file, int* LineNum ); int readGeometry( FILE* file, int* LineNum );
void readCoordsList( FILE* file, char* text_buffer, std::vector< double >& aList, int* LineNum );
/**
* Function ReadCoordList
* reads 3D coordinate lists like:
* coord Coordinate { point [
* -5.24489 6.57640e-3 -9.42129e-2,
* -5.11821 6.57421e-3 0.542654,
* -3.45868 0.256565 1.32000 ] }
* or:
* normal Normal { vector [
* 0.995171 -6.08102e-6 9.81541e-2,
* 0.923880 -4.09802e-6 0.382683,
* 0.707107 -9.38186e-7 0.707107]
* }
*
* text_buffer contains the first line of this node :
* "coord Coordinate { point ["
*/
void readCoordsList( FILE* file, char* text_buffer, std::vector< double >& aList,
int* LineNum );
}; };
#endif // MODELPARSERS_H #endif // MODELPARSERS_H

View File

@ -36,19 +36,21 @@
#include "3d_struct.h" #include "3d_struct.h"
#include "modelparsers.h" #include "modelparsers.h"
// separator chars // separator chars
static const char* sep_chars = " \t\n\r"; static const char* sep_chars = " \t\n\r";
VRML_MODEL_PARSER::VRML_MODEL_PARSER(S3D_MASTER* aMaster) VRML_MODEL_PARSER::VRML_MODEL_PARSER( S3D_MASTER* aMaster ) :
:S3D_MODEL_PARSER(aMaster) S3D_MODEL_PARSER( aMaster )
{} {}
VRML_MODEL_PARSER::~VRML_MODEL_PARSER() VRML_MODEL_PARSER::~VRML_MODEL_PARSER()
{} {}
void VRML_MODEL_PARSER::Load(const wxString aFilename)
{ void VRML_MODEL_PARSER::Load( const wxString aFilename )
{
char line[1024], * text; char line[1024], * text;
FILE* file; FILE* file;
int LineNum = 0; int LineNum = 0;
@ -67,7 +69,7 @@ void VRML_MODEL_PARSER::Load(const wxString aFilename)
{ {
text = strtok( line, sep_chars ); text = strtok( line, sep_chars );
if( stricmp( text, "DEF" ) == 0 || stricmp( text, "Group" ) == 0) if( stricmp( text, "DEF" ) == 0 || stricmp( text, "Group" ) == 0 )
{ {
while( GetLine( file, line, &LineNum, 512 ) ) while( GetLine( file, line, &LineNum, 512 ) )
{ {
@ -91,6 +93,7 @@ void VRML_MODEL_PARSER::Load(const wxString aFilename)
SetLocaleTo_Default(); // revert to the current locale SetLocaleTo_Default(); // revert to the current locale
} }
int VRML_MODEL_PARSER::readMaterial( FILE* file, int* LineNum ) int VRML_MODEL_PARSER::readMaterial( FILE* file, int* LineNum )
{ {
char line[512], * text, * command; char line[512], * text, * command;
@ -258,7 +261,8 @@ int VRML_MODEL_PARSER::readAppearance( FILE* file, int* LineNum )
if( *text == '}' ) if( *text == '}' )
{ {
err = 0; break; err = 0;
break;
} }
if( stricmp( text, "material" ) == 0 ) if( stricmp( text, "material" ) == 0 )
@ -278,24 +282,8 @@ int VRML_MODEL_PARSER::readAppearance( FILE* file, int* LineNum )
#define BUFSIZE 2000 #define BUFSIZE 2000
/** void VRML_MODEL_PARSER::readCoordsList( FILE* file, char* text_buffer,
* Function ReadCoordList std::vector< double >& aList, int* LineNum )
* reads 3D coordinate lists like:
* coord Coordinate { point [
* -5.24489 6.57640e-3 -9.42129e-2,
* -5.11821 6.57421e-3 0.542654,
* -3.45868 0.256565 1.32000 ] }
* or:
* normal Normal { vector [
* 0.995171 -6.08102e-6 9.81541e-2,
* 0.923880 -4.09802e-6 0.382683,
* 0.707107 -9.38186e-7 0.707107]
* }
*
* text_buffer contains the first line of this node :
* "coord Coordinate { point ["
*/
void VRML_MODEL_PARSER::readCoordsList( FILE* file, char* text_buffer, std::vector< double >& aList, int* LineNum )
{ {
unsigned int ii = 0, jj = 0; unsigned int ii = 0, jj = 0;
char* text; char* text;
@ -399,6 +387,7 @@ int VRML_MODEL_PARSER::readGeometry( FILE* file, int* LineNum )
else else
{ {
} }
continue; continue;
} }

View File

@ -39,17 +39,20 @@
#include "3d_struct.h" #include "3d_struct.h"
#include "modelparsers.h" #include "modelparsers.h"
X3D_MODEL_PARSER::X3D_MODEL_PARSER( S3D_MASTER* aMaster ) X3D_MODEL_PARSER::X3D_MODEL_PARSER( S3D_MASTER* aMaster ) :
:S3D_MODEL_PARSER( aMaster ) S3D_MODEL_PARSER( aMaster )
{} {}
X3D_MODEL_PARSER::~X3D_MODEL_PARSER() X3D_MODEL_PARSER::~X3D_MODEL_PARSER()
{} {}
void X3D_MODEL_PARSER::Load( const wxString aFilename )
void X3D_MODEL_PARSER::Load( const wxString aFilename )
{ {
wxXmlDocument doc; wxXmlDocument doc;
if( !doc.Load( aFilename ) )
if( !doc.Load( aFilename ) )
{ {
wxLogError( wxT( "Error while parsing file <%s>" ), GetChars( aFilename ) ); wxLogError( wxT( "Error while parsing file <%s>" ), GetChars( aFilename ) );
return; return;
@ -62,74 +65,85 @@ void X3D_MODEL_PARSER::Load( const wxString aFilename )
} }
// Shapes are inside of Transform nodes // Shapes are inside of Transform nodes
// Transform node contains information about // Transform node contains information about
// transition, scale and rotation of the shape // transition, scale and rotation of the shape
NODE_LIST transforms; NODE_LIST transforms;
GetChildsByName( doc.GetRoot(), wxT( "Transform" ), transforms ); GetChildsByName( doc.GetRoot(), wxT( "Transform" ), transforms );
for( NODE_LIST::iterator node_it = transforms.begin(); for( NODE_LIST::iterator node_it = transforms.begin();
node_it != transforms.end(); node_it != transforms.end();
node_it++ ) node_it++ )
{ {
readTransform( *node_it ); readTransform( *node_it );
} }
} }
wxString X3D_MODEL_PARSER::VRML_representation()
wxString X3D_MODEL_PARSER::VRML_representation()
{ {
wxString output; wxString output;
for( unsigned i = 0; i < vrml_points.size(); i++ )
for( unsigned i = 0; i < vrml_points.size(); i++ )
{ {
output += wxT("Shape {\n" output += wxT( "Shape {\n"
" appearance Appearance {\n" " appearance Appearance {\n"
" material Material {\n" ) + " material Material {\n" ) +
vrml_materials[i] + vrml_materials[i] +
wxT(" }\n" wxT( " }\n"
" }\n" " }\n"
" geometry IndexedFaceSet {\n" " geometry IndexedFaceSet {\n"
" solid TRUE\n" " solid TRUE\n"
" coord Coordinate {\n" " coord Coordinate {\n"
" point [\n") + " point [\n") +
vrml_points[i] + vrml_points[i] +
wxT( " ]\n" wxT( " ]\n"
" }\n" " }\n"
" coordIndex [\n" ) + " coordIndex [\n" ) +
vrml_coord_indexes[i] + vrml_coord_indexes[i] +
wxT(" ]\n" wxT( " ]\n"
" }\n" " }\n"
"},\n"); "},\n" );
} }
return output; return output;
} }
void X3D_MODEL_PARSER::GetChildsByName( wxXmlNode* aParent,
const wxString aName, void X3D_MODEL_PARSER::GetChildsByName( wxXmlNode* aParent,
std::vector< wxXmlNode* >& aResult ) const wxString aName,
std::vector< wxXmlNode* >& aResult )
{ {
// Breadth-first search (BFS) // Breadth-first search (BFS)
std::queue< wxXmlNode* > found; std::queue< wxXmlNode* > found;
found.push( aParent ); found.push( aParent );
while( !found.empty() )
while( !found.empty() )
{ {
wxXmlNode *elem = found.front(); wxXmlNode *elem = found.front();
for( wxXmlNode *child = elem->GetChildren(); for( wxXmlNode *child = elem->GetChildren();
child != NULL; child != NULL;
child = child->GetNext() ) child = child->GetNext() )
{ {
if( child->GetName() == aName) if( child->GetName() == aName )
{ {
aResult.push_back( child ); aResult.push_back( child );
} }
found.push( child ); found.push( child );
} }
found.pop(); found.pop();
} }
} }
void X3D_MODEL_PARSER::GetNodeProperties( wxXmlNode* aNode, PROPERTY_MAP& aProps ) {
void X3D_MODEL_PARSER::GetNodeProperties( wxXmlNode* aNode, PROPERTY_MAP& aProps )
{
wxXmlProperty *prop; wxXmlProperty *prop;
for( prop = aNode->GetProperties();
prop != NULL; for( prop = aNode->GetAttributes();
prop != NULL;
prop = prop->GetNext() ) prop = prop->GetNext() )
{ {
aProps[ prop->GetName() ] = prop->GetValue(); aProps[ prop->GetName() ] = prop->GetValue();
@ -145,98 +159,110 @@ void X3D_MODEL_PARSER::readTransform( wxXmlNode* aTransformNode )
for( NODE_LIST::iterator node = childnodes.begin(); for( NODE_LIST::iterator node = childnodes.begin();
node != childnodes.end(); node != childnodes.end();
node++ ) node++ )
{ {
readMaterial( *node ); readMaterial( *node );
} }
childnodes.clear(); childnodes.clear();
PROPERTY_MAP properties; PROPERTY_MAP properties;
GetNodeProperties( aTransformNode, properties ); GetNodeProperties( aTransformNode, properties );
GetChildsByName( aTransformNode, wxT("IndexedFaceSet"), childnodes ); GetChildsByName( aTransformNode, wxT("IndexedFaceSet"), childnodes );
for( NODE_LIST::iterator node = childnodes.begin(); for( NODE_LIST::iterator node = childnodes.begin();
node != childnodes.end(); node != childnodes.end();
node++ ) node++ )
{ {
readIndexedFaceSet( *node, properties ); readIndexedFaceSet( *node, properties );
} }
childnodes.clear(); childnodes.clear();
} }
void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode ) void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
{ {
PROPERTY_MAP properties; PROPERTY_MAP properties;
GetNodeProperties( aMatNode, properties ); GetNodeProperties( aMatNode, properties );
// DEFine new Material named as value of DEF // DEFine new Material named as value of DEF
if( properties.find( wxT( "DEF" ) ) != properties.end() ) { if( properties.find( wxT( "DEF" ) ) != properties.end() )
{
double amb, shine, transp; double amb, shine, transp;
S3D_MATERIAL* material = new S3D_MATERIAL( GetMaster(), properties[ wxT( "DEF" ) ] ); S3D_MATERIAL* material = new S3D_MATERIAL( GetMaster(), properties[ wxT( "DEF" ) ] );
GetMaster()->Insert( material ); GetMaster()->Insert( material );
if( !parseDoubleTriplet( properties[ wxT( "diffuseColor" ) ], if( !parseDoubleTriplet( properties[ wxT( "diffuseColor" ) ],
material->m_DiffuseColor) ) material->m_DiffuseColor ) )
{ {
D( printf("diffuseColor parsing error") ); D( printf("diffuseColor parsing error") );
} }
if( !parseDoubleTriplet( properties[ wxT( "specularColor" ) ], if( !parseDoubleTriplet( properties[ wxT( "specularColor" ) ],
material->m_SpecularColor ) ) material->m_SpecularColor ) )
{ {
D( printf("specularColor parsing error") ); D( printf("specularColor parsing error") );
} }
if( !parseDoubleTriplet( properties[ wxT( "emissiveColor" ) ], if( !parseDoubleTriplet( properties[ wxT( "emissiveColor" ) ],
material->m_EmissiveColor ) ) material->m_EmissiveColor ) )
{ {
D( printf("emissiveColor parsing error") ); D( printf("emissiveColor parsing error") );
} }
wxStringTokenizer values; wxStringTokenizer values;
values.SetString( properties[ wxT( "ambientIntensity" ) ] ); values.SetString( properties[ wxT( "ambientIntensity" ) ] );
if( values.GetNextToken().ToDouble( &amb ) )
if( values.GetNextToken().ToDouble( &amb ) )
{ {
material->m_AmbientIntensity = amb; material->m_AmbientIntensity = amb;
} }
else else
{ {
D( printf("ambienterror") ); D( printf( "ambienterror" ) );
} }
values.SetString( properties[ wxT( "shininess" ) ] ); values.SetString( properties[ wxT( "shininess" ) ] );
if( values.GetNextToken().ToDouble(&shine) )
if( values.GetNextToken().ToDouble( &shine ) )
{ {
material->m_Shininess = shine; material->m_Shininess = shine;
} }
else { else
D( printf( "shininess error" ) ); {
D( printf( "shininess error" ) );
} }
values.SetString( properties[ wxT( "transparency" ) ] ); values.SetString( properties[ wxT( "transparency" ) ] );
if( values.GetNextToken().ToDouble(&transp) )
if( values.GetNextToken().ToDouble( &transp ) )
{ {
material->m_Transparency = transp; material->m_Transparency = transp;
} }
else else
{ {
D( printf( "trans error") ); D( printf( "trans error") );
} }
material->SetMaterial(); material->SetMaterial();
// VRML // VRML
wxString vrml_material; wxString vrml_material;
PROPERTY_MAP::const_iterator p = ++properties.begin(); // skip DEF PROPERTY_MAP::const_iterator p = ++properties.begin(); // skip DEF
for(;p != properties.end();p++) {
vrml_material.Append( p->first + wxT(" ") + p->second + wxT("\n") ); for(;p != properties.end();p++)
{
vrml_material.Append( p->first + wxT( " " ) + p->second + wxT( "\n" ) );
} }
vrml_materials.push_back(vrml_material); vrml_materials.push_back( vrml_material );
} }
// USE existing material named by value of USE // USE existing material named by value of USE
else if( properties.find( wxT( "USE" ) ) != properties.end() ) { else if( properties.find( wxT( "USE" ) ) != properties.end() )
{
S3D_MATERIAL* material = NULL; S3D_MATERIAL* material = NULL;
wxString mat_name = properties[ wxT( "USE" ) ]; wxString mat_name = properties[ wxT( "USE" ) ];
@ -244,34 +270,33 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
{ {
if( material->m_Name == mat_name ) if( material->m_Name == mat_name )
{ {
wxString vrml_material; wxString vrml_material;
vrml_material.Append( wxString::Format( wxT( "specularColor %f %f %f\n"), vrml_material.Append( wxString::Format( wxT( "specularColor %f %f %f\n" ),
material->m_SpecularColor.x, material->m_SpecularColor.x,
material->m_SpecularColor.y, material->m_SpecularColor.y,
material->m_SpecularColor.z) ); material->m_SpecularColor.z ) );
vrml_material.Append( wxString::Format( wxT( "diffuseColor %f %f %f\n"), vrml_material.Append( wxString::Format( wxT( "diffuseColor %f %f %f\n" ),
material->m_DiffuseColor.x, material->m_DiffuseColor.x,
material->m_DiffuseColor.y, material->m_DiffuseColor.y,
material->m_DiffuseColor.z) ); material->m_DiffuseColor.z ) );
vrml_material.Append( wxString::Format( wxT( "emissiveColor %f %f %f\n"), vrml_material.Append( wxString::Format( wxT( "emissiveColor %f %f %f\n" ),
material->m_EmissiveColor.x, material->m_EmissiveColor.x,
material->m_EmissiveColor.y, material->m_EmissiveColor.y,
material->m_EmissiveColor.z) ); material->m_EmissiveColor.z ) );
vrml_material.Append( wxString::Format( wxT( "ambientIntensity %f\n"), vrml_material.Append( wxString::Format( wxT( "ambientIntensity %f\n"),
material->m_AmbientIntensity) ); material->m_AmbientIntensity ) );
vrml_material.Append( wxString::Format( wxT( "shininess %f\n"), vrml_material.Append( wxString::Format( wxT( "shininess %f\n"),
material->m_Shininess) ); material->m_Shininess ) );
vrml_material.Append( wxString::Format( wxT( "transparency %f\n"),
material->m_Transparency) );
vrml_materials.push_back(vrml_material);
vrml_material.Append( wxString::Format( wxT( "transparency %f\n"),
material->m_Transparency ) );
vrml_materials.push_back( vrml_material );
material->SetMaterial(); material->SetMaterial();
return; return;
@ -279,39 +304,40 @@ void X3D_MODEL_PARSER::readMaterial( wxXmlNode* aMatNode )
} }
D( printf( "ReadMaterial error: material not found\n" ) ); D( printf( "ReadMaterial error: material not found\n" ) );
} }
} }
bool X3D_MODEL_PARSER::parseDoubleTriplet( const wxString& aData,
bool X3D_MODEL_PARSER::parseDoubleTriplet( const wxString& aData,
S3D_VERTEX& aResult ) S3D_VERTEX& aResult )
{ {
wxStringTokenizer tokens(aData); wxStringTokenizer tokens(aData);
return tokens.GetNextToken().ToDouble( &aResult.x ) && return tokens.GetNextToken().ToDouble( &aResult.x ) &&
tokens.GetNextToken().ToDouble( &aResult.y ) && tokens.GetNextToken().ToDouble( &aResult.y ) &&
tokens.GetNextToken().ToDouble( &aResult.z ); tokens.GetNextToken().ToDouble( &aResult.z );
} }
void X3D_MODEL_PARSER::rotate( S3D_VERTEX& aV, void X3D_MODEL_PARSER::rotate( S3D_VERTEX& aV,
S3D_VERTEX& aU, S3D_VERTEX& aU,
double angle) double angle )
{ {
S3D_VERTEX rotated; S3D_VERTEX rotated;
double C = cos(angle); double C = cos( angle );
double S = sin(angle); double S = sin( angle );
double t = 1.0 - C; double t = 1.0 - C;
rotated.x = ( t * aU.x * aU.x + C ) * aV.x + rotated.x = ( t * aU.x * aU.x + C ) * aV.x +
( t * aU.x * aU.y - S * aU.z ) * aV.y + ( t * aU.x * aU.y - S * aU.z ) * aV.y +
( t * aU.x * aU.z + S * aU.y ) * aV.z; ( t * aU.x * aU.z + S * aU.y ) * aV.z;
rotated.y = ( t * aU.x * aU.y + S * aU.z ) * aV.x + rotated.y = ( t * aU.x * aU.y + S * aU.z ) * aV.x +
( t * aU.y * aU.y + C ) * aV.y + ( t * aU.y * aU.y + C ) * aV.y +
( t * aU.y * aU.z - S * aU.x ) * aV.z; ( t * aU.y * aU.z - S * aU.x ) * aV.z;
rotated.z = ( t * aU.x * aU.z - S * aU.y ) * aV.x + rotated.z = ( t * aU.x * aU.z - S * aU.y ) * aV.x +
( t * aU.y * aU.z + S * aU.x ) * aV.y + ( t * aU.y * aU.z + S * aU.x ) * aV.y +
( t * aU.z * aU.z + C) * aV.z; ( t * aU.z * aU.z + C) * aV.z;
aV.x = rotated.x; aV.x = rotated.x;
@ -319,21 +345,21 @@ void X3D_MODEL_PARSER::rotate( S3D_VERTEX& aV,
aV.z = rotated.z; aV.z = rotated.z;
} }
/* Steps: /* Steps:
* 1. Read transform data * 1. Read transform data
* 2. Read vectex triplets * 2. Read vertex triplets
* 3. Read coordinate indexes * 3. Read coordinate indexes
* 4. Apply geometry to Master object * 4. Apply geometry to Master object
*/ */
void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode, void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
PROPERTY_MAP& aTransformProps) PROPERTY_MAP& aTransformProps)
{ {
/* Step 1: Read transform data /* Step 1: Read transform data
* --------------------------- */ * --------------------------- */
S3D_VERTEX translation; S3D_VERTEX translation;
parseDoubleTriplet( aTransformProps[ wxT( "translation" ) ], parseDoubleTriplet( aTransformProps[ wxT( "translation" ) ], translation );
translation );
S3D_VERTEX scale; S3D_VERTEX scale;
parseDoubleTriplet( aTransformProps[ wxT( "scale" ) ], scale ); parseDoubleTriplet( aTransformProps[ wxT( "scale" ) ], scale );
@ -341,6 +367,7 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
S3D_VERTEX rotation; S3D_VERTEX rotation;
double angle = 0.0; double angle = 0.0;
wxStringTokenizer tokens(aTransformProps[ wxT( "rotation" ) ]); wxStringTokenizer tokens(aTransformProps[ wxT( "rotation" ) ]);
if( !(tokens.GetNextToken().ToDouble( &rotation.x ) && if( !(tokens.GetNextToken().ToDouble( &rotation.x ) &&
tokens.GetNextToken().ToDouble( &rotation.y ) && tokens.GetNextToken().ToDouble( &rotation.y ) &&
tokens.GetNextToken().ToDouble( &rotation.z ) && tokens.GetNextToken().ToDouble( &rotation.z ) &&
@ -349,7 +376,7 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
D( printf("rotation read error") ); D( printf("rotation read error") );
} }
double vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * double vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits *
UNITS3D_TO_UNITSPCB; UNITS3D_TO_UNITSPCB;
/* Step 2: Read all coordinate points /* Step 2: Read all coordinate points
@ -365,7 +392,8 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
// Save points to vector as doubles // Save points to vector as doubles
wxStringTokenizer point_tokens( coordinate_properties[ wxT("point") ] ); wxStringTokenizer point_tokens( coordinate_properties[ wxT("point") ] );
double point = 0.0; double point = 0.0;
while( point_tokens.HasMoreTokens() )
while( point_tokens.HasMoreTokens() )
{ {
if( point_tokens.GetNextToken().ToDouble( &point ) ) if( point_tokens.GetNextToken().ToDouble( &point ) )
{ {
@ -377,28 +405,30 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
} }
} }
if(points.size() % 3 != 0) { if( points.size() % 3 != 0 )
D( printf("Number of points is incorrect") ); {
D( printf( "Number of points is incorrect" ) );
return; return;
} }
/* Create 3D vertex from 3 points and /* Create 3D vertex from 3 points and
* apply tansforms in order of SCALE, ROTATION, TRANSLATION * apply transforms in order of SCALE, ROTATION, TRANSLATION
*/ */
wxString vrml_pointlist; wxString vrml_pointlist;
std::vector< S3D_VERTEX > triplets; std::vector< S3D_VERTEX > triplets;
for( unsigned id = 0; id < points.size() / 3; id++ ) for( unsigned id = 0; id < points.size() / 3; id++ )
{ {
int triplet_indx = id * 3; int triplet_indx = id * 3;
S3D_VERTEX point( points[ triplet_indx ], S3D_VERTEX point( points[ triplet_indx ],
points[ triplet_indx + 1 ], points[ triplet_indx + 1 ],
points[ triplet_indx + 2 ] ); points[ triplet_indx + 2 ] );
point.x *= scale.x; point.x *= scale.x;
point.y *= scale.y; point.y *= scale.y;
point.z *= scale.z; point.z *= scale.z;
rotate(point, rotation, angle); rotate( point, rotation, angle );
point.x += translation.x; point.x += translation.x;
point.y += translation.y; point.y += translation.y;
@ -407,9 +437,10 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
triplets.push_back(point); triplets.push_back(point);
// VRML // VRML
vrml_pointlist.Append( wxString::Format(wxT("%f %f %f\n"), point.x, point.y, point.z) ); vrml_pointlist.Append( wxString::Format( wxT( "%f %f %f\n" ), point.x, point.y, point.z ) );
} }
vrml_points.push_back(vrml_pointlist);
vrml_points.push_back( vrml_pointlist );
/* -- Read coordinate indexes -- */ /* -- Read coordinate indexes -- */
PROPERTY_MAP faceset_properties; PROPERTY_MAP faceset_properties;
@ -422,10 +453,11 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
wxStringTokenizer index_tokens( coordIndex_str ); wxStringTokenizer index_tokens( coordIndex_str );
wxString vrml_coord_indx_list; wxString vrml_coord_indx_list;
while( index_tokens.HasMoreTokens() )
while( index_tokens.HasMoreTokens() )
{ {
long index = 0; long index = 0;
index_tokens.GetNextToken().ToLong(&index); index_tokens.GetNextToken().ToLong( &index );
// -1 marks the end of polygon // -1 marks the end of polygon
if( index < 0 ) if( index < 0 )
@ -433,11 +465,12 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
/* Step 4: Apply geometry to Master object /* Step 4: Apply geometry to Master object
* --------------------------------------- */ * --------------------------------------- */
std::vector<int>::const_iterator id; std::vector<int>::const_iterator id;
for( id = coordIndex.begin(); for( id = coordIndex.begin();
id != coordIndex.end(); id != coordIndex.end();
id++ ) id++ )
{ {
vertices.push_back( triplets.at(*id) ); vertices.push_back( triplets.at( *id ) );
} }
GetMaster()->Set_Object_Coords( vertices ); GetMaster()->Set_Object_Coords( vertices );
@ -445,14 +478,14 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
vertices.clear(); vertices.clear();
coordIndex.clear(); coordIndex.clear();
vrml_coord_indx_list.Append( wxT("-1\n") ); vrml_coord_indx_list.Append( wxT( "-1\n" ) );
} }
else else
{ {
coordIndex.push_back( index ); coordIndex.push_back( index );
vrml_coord_indx_list.Append( wxString::Format(wxT("%u "), index) ); vrml_coord_indx_list.Append( wxString::Format( wxT( "%u " ), index ) );
} }
} }
vrml_coord_indexes.push_back(vrml_coord_indx_list);
}
vrml_coord_indexes.push_back( vrml_coord_indx_list );
}

View File

@ -59,7 +59,7 @@ void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock,
int iusPerMil = plotter->GetIUsPerDecimil() * 10; int iusPerMil = plotter->GetIUsPerDecimil() * 10;
wxSize pageSize = aPageInfo.GetSizeMils(); // in mils wxSize pageSize = aPageInfo.GetSizeMils(); // in mils
int xg, yg; int xg, yg;
int refx, refy; // int refx, refy;
wxPoint pos, end, ref; wxPoint pos, end, ref;
wxString msg; wxString msg;
wxSize text_size; wxSize text_size;

View File

@ -905,6 +905,17 @@ public:
/** /**
* Function ExportVRML_File * Function ExportVRML_File
* Creates the file(s) exporting current BOARD to a VRML file. * Creates the file(s) exporting current BOARD to a VRML file.
*
* @note When copying 3D shapes files, the new filename is build from the full path
* name, changing the separators by underscore. This is needed because files
* with the same shortname can exist in different directories
* @note ExportVRML_File generates coordinates in board units (BIU) inside the file.
* @todo Use mm inside the file. A general scale transform is applied to the whole
* file (1.0 to have the actual WRML unit im mm, 0.001 to have the actual WRML
* unit in meters.
* @note For 3D models built by a 3D modeler, the unit is 0,1 inches. A specfic scale
* is applied to 3D models to convert them to internal units.
*
* @param aFullFileName = the full filename of the file to create * @param aFullFileName = the full filename of the file to create
* @param aMMtoWRMLunit = the VRML scaling factor: * @param aMMtoWRMLunit = the VRML scaling factor:
* 1.0 to export in mm. 0.001 for meters * 1.0 to export in mm. 0.001 for meters

View File

@ -257,6 +257,7 @@ static void write_triangle_bag( FILE* output_file, int color_index, //{{{
"}\n", "}\n",
0 // End marker 0 // End marker
}; };
int marker_found = 0, lineno = 0; int marker_found = 0, lineno = 0;
while( marker_found < 4 ) while( marker_found < 4 )
@ -554,6 +555,7 @@ static void export_vrml_arc( int layer, double centerx, double centery,
ring.bag( layer, false ); ring.bag( layer, false );
} }
static void export_vrml_varc( TRIANGLEBAG& triangles, static void export_vrml_varc( TRIANGLEBAG& triangles,
int top_layer, int bottom_layer, int top_layer, int bottom_layer,
double centerx, double centery, double centerx, double centery,
@ -958,28 +960,28 @@ static void export_vrml_pad( BOARD* pcb, D_PAD* aPad ) //{{{
pad_dy = 0; pad_dy = 0;
case PAD_TRAPEZOID: case PAD_TRAPEZOID:
{
int coord[8] =
{ {
int coord[8] = KiROUND( -pad_w - pad_dy ), KiROUND( +pad_h + pad_dx ),
{ KiROUND( -pad_w + pad_dy ), KiROUND( -pad_h - pad_dx ),
KiROUND(-pad_w - pad_dy), KiROUND(+pad_h + pad_dx), KiROUND( +pad_w - pad_dy ), KiROUND( +pad_h - pad_dx ),
KiROUND(-pad_w + pad_dy), KiROUND(-pad_h - pad_dx), KiROUND( +pad_w + pad_dy ), KiROUND( -pad_h + pad_dx ),
KiROUND(+pad_w - pad_dy), KiROUND(+pad_h - pad_dx), };
KiROUND(+pad_w + pad_dy), KiROUND(-pad_h + pad_dx),
};
for( int i = 0; i < 4; i++ ) for( int i = 0; i < 4; i++ )
{ {
RotatePoint( &coord[i * 2], &coord[i * 2 + 1], aPad->GetOrientation() ); RotatePoint( &coord[i * 2], &coord[i * 2 + 1], aPad->GetOrientation() );
coord[i * 2] += KiROUND( pad_x ); coord[i * 2] += KiROUND( pad_x );
coord[i * 2 + 1] += KiROUND( pad_y ); coord[i * 2 + 1] += KiROUND( pad_y );
}
bag_flat_quad( layer, coord[0], coord[1],
coord[2], coord[3],
coord[4], coord[5],
coord[6], coord[7] );
} }
break;
bag_flat_quad( layer, coord[0], coord[1],
coord[2], coord[3],
coord[4], coord[5],
coord[6], coord[7] );
}
break;
default: default:
; ;
@ -1043,11 +1045,11 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
switch( item->Type() ) switch( item->Type() )
{ {
case PCB_MODULE_TEXT_T: case PCB_MODULE_TEXT_T:
export_vrml_text_module( dynamic_cast<TEXTE_MODULE*>(item) ); export_vrml_text_module( dynamic_cast<TEXTE_MODULE*>( item ) );
break; break;
case PCB_MODULE_EDGE_T: case PCB_MODULE_EDGE_T:
export_vrml_edge_module( dynamic_cast<EDGE_MODULE*>(item) ); export_vrml_edge_module( dynamic_cast<EDGE_MODULE*>( item ) );
break; break;
default: default:
@ -1078,13 +1080,13 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
fname = vrmlm->m_Shape3DName; fname = vrmlm->m_Shape3DName;
} }
fname.Replace(wxT("\\"), wxT("/" ) ); fname.Replace( wxT( "\\" ), wxT( "/" ) );
wxString source_fname = fname; wxString source_fname = fname;
if( aExport3DFiles ) // Change illegal characters in short filename if( aExport3DFiles ) // Change illegal characters in short filename
{ {
ChangeIllegalCharacters( fname, true ); ChangeIllegalCharacters( fname, true );
fname = a3D_Subdir + wxT("/") + fname; fname = a3D_Subdir + wxT( "/" ) + fname;
if( !wxFileExists( fname ) ) if( !wxFileExists( fname ) )
wxCopyFile( source_fname, fname ); wxCopyFile( source_fname, fname );
@ -1153,12 +1155,12 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
if( fname.EndsWith( wxT( "x3d" ) ) ) if( fname.EndsWith( wxT( "x3d" ) ) )
{ {
X3D_MODEL_PARSER* parser = new X3D_MODEL_PARSER(vrmlm); X3D_MODEL_PARSER* parser = new X3D_MODEL_PARSER( vrmlm );
if(parser) if( parser )
{ {
// embed x3d model in vrml format // embed x3d model in vrml format
parser->Load(fname); parser->Load( fname );
fprintf( aOutputFile, fprintf( aOutputFile,
" children [\n %s ]\n", TO_UTF8( parser->VRML_representation() ) ); " children [\n %s ]\n", TO_UTF8( parser->VRML_representation() ) );
fprintf( aOutputFile, " }\n" ); fprintf( aOutputFile, " }\n" );
@ -1187,28 +1189,7 @@ static void write_and_empty_triangle_bag( FILE* output_file, TRIANGLEBAG& triang
} }
} }
/* ExportVRML_File
* Creates the file(s) exporting current BOARD to a VRML file.
* aFullFileName = the full filename of the file to create
* aMMtoWRMLunit = the general WRML scaling factor. 1.0 to export in mm
* @param aExport3DFiles = true to copy 3D shapes in the subdir a3D_Subdir
* a3D_Subdir = sub directory where 3D shapes files are copied
* used only when aExport3DFiles == true
*/
/* Note1:
* When copying 3D shapes files, the new filename is build from
* the full path name, changing the separators by underscore.
* this is needed because files with the same shortname can exist in different directories
* Note 2:
* ExportVRML_File generates coordinates in board units (BIU) inside the file.
* (TODO: use mm inside the file)
* A general scale transform is applied to the whole file
* (1.0 to have the actual WRML unit im mm, 0.001 to have the actual WRML unit im meter
* Note 3:
* For 3D models built by a 3D modeler, the unit is 0,1 inch
* A specfic scale is applied to 3D models to convert them to BIU
*
*/
bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName, bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName,
double aMMtoWRMLunit, bool aExport3DFiles, double aMMtoWRMLunit, bool aExport3DFiles,
const wxString & a3D_Subdir ) const wxString & a3D_Subdir )
@ -1218,6 +1199,7 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName,
BOARD* pcb = GetBoard(); BOARD* pcb = GetBoard();
output_file = wxFopen( aFullFileName, wxT( "wt" ) ); output_file = wxFopen( aFullFileName, wxT( "wt" ) );
if( output_file == NULL ) if( output_file == NULL )
return false; return false;
@ -1227,7 +1209,7 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName,
// Begin with the usual VRML boilerplate // Begin with the usual VRML boilerplate
wxString name = aFullFileName; wxString name = aFullFileName;
name.Replace(wxT("\\"), wxT("/" ) ); name.Replace( wxT( "\\" ), wxT( "/" ) );
ChangeIllegalCharacters( name, false ); ChangeIllegalCharacters( name, false );
fprintf( output_file, "#VRML V2.0 utf8\n" fprintf( output_file, "#VRML V2.0 utf8\n"
"WorldInfo {\n" "WorldInfo {\n"
@ -1275,6 +1257,7 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName,
* is 2.54 * aMMtoWRMLunit * is 2.54 * aMMtoWRMLunit
*/ */
double wrml_3D_models_scaling_factor = 2.54 * aMMtoWRMLunit; double wrml_3D_models_scaling_factor = 2.54 * aMMtoWRMLunit;
// Export footprints // Export footprints
for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() ) for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() )
export_vrml_module( pcb, module, output_file, export_vrml_module( pcb, module, output_file,
@ -1307,6 +1290,7 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName,
return true; return true;
} }
/* /*
* some characters cannot be used in filenames, * some characters cannot be used in filenames,
* this function change them to "_" * this function change them to "_"
@ -1314,8 +1298,8 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName,
static void ChangeIllegalCharacters( wxString & aFileName, bool aDirSepIsIllegal ) static void ChangeIllegalCharacters( wxString & aFileName, bool aDirSepIsIllegal )
{ {
if( aDirSepIsIllegal ) if( aDirSepIsIllegal )
aFileName.Replace(wxT("/"), wxT("_" ) ); aFileName.Replace( wxT( "/" ), wxT( "_" ) );
aFileName.Replace(wxT(" "), wxT("_" ) ); aFileName.Replace( wxT( " " ), wxT( "_" ) );
aFileName.Replace(wxT(":"), wxT("_" ) ); aFileName.Replace( wxT( ":" ), wxT( "_" ) );
} }