Commit 53cd19a6 authored by unknown's avatar unknown Committed by jean-pierre charras

VRML export rewritten

parent bd174ebf
...@@ -140,7 +140,6 @@ set( PCBNEW_EXPORTERS ...@@ -140,7 +140,6 @@ set( PCBNEW_EXPORTERS
exporters/gen_drill_report_files.cpp exporters/gen_drill_report_files.cpp
exporters/gen_modules_placefile.cpp exporters/gen_modules_placefile.cpp
exporters/gendrill_Excellon_writer.cpp exporters/gendrill_Excellon_writer.cpp
exporters/vrml_board.cpp
) )
set( PCBNEW_AUTOROUTER_SRCS set( PCBNEW_AUTOROUTER_SRCS
......
...@@ -568,7 +568,7 @@ bool Export_IDF3( BOARD* aPcb, const wxString& aFullFileName, bool aUseThou ) ...@@ -568,7 +568,7 @@ bool Export_IDF3( BOARD* aPcb, const wxString& aFullFileName, bool aUseThou )
ok = false; ok = false;
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
wxString msg; wxString msg;
msg << _( "IDF Export Failed:\n" ) << FROM_UTF8( e.what() ); msg << _( "IDF Export Failed:\n" ) << FROM_UTF8( e.what() );
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -775,7 +775,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli ...@@ -775,7 +775,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli
aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5)
<< aOutline->front()->startPoint.x << " " << aOutline->front()->startPoint.x << " "
<< aOutline->front()->startPoint.y << " " << aOutline->front()->startPoint.y << " "
<< setprecision(5) << -aOutline->front()->angle << "\n"; << setprecision(2) << -aOutline->front()->angle << "\n";
} }
} }
else else
...@@ -799,7 +799,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli ...@@ -799,7 +799,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli
aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1)
<< (aOutline->front()->startPoint.x / IDF_THOU_TO_MM) << " " << (aOutline->front()->startPoint.x / IDF_THOU_TO_MM) << " "
<< (aOutline->front()->startPoint.y / IDF_THOU_TO_MM) << " " << (aOutline->front()->startPoint.y / IDF_THOU_TO_MM) << " "
<< setprecision(5) << -aOutline->front()->angle << "\n"; << setprecision(2) << -aOutline->front()->angle << "\n";
} }
} }
...@@ -819,7 +819,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli ...@@ -819,7 +819,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli
aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5)
<< (*bo)->startPoint.x << " " << (*bo)->startPoint.x << " "
<< (*bo)->startPoint.y << " " << (*bo)->startPoint.y << " "
<< setprecision(5) << -(*bo)->angle << "\n"; << setprecision(2) << -(*bo)->angle << "\n";
} }
} }
else else
...@@ -835,7 +835,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli ...@@ -835,7 +835,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli
aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1)
<< ((*bo)->startPoint.x / IDF_THOU_TO_MM) << " " << ((*bo)->startPoint.x / IDF_THOU_TO_MM) << " "
<< ((*bo)->startPoint.y / IDF_THOU_TO_MM) << " " << ((*bo)->startPoint.y / IDF_THOU_TO_MM) << " "
<< setprecision(5) << -(*bo)->angle << "\n"; << setprecision(2) << -(*bo)->angle << "\n";
} }
} }
...@@ -869,7 +869,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli ...@@ -869,7 +869,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli
aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5)
<< (*bo)->endPoint.x << " " << (*bo)->endPoint.x << " "
<< (*bo)->endPoint.y << " " << (*bo)->endPoint.y << " "
<< setprecision(5) << (*bo)->angle << "\n"; << setprecision(2) << (*bo)->angle << "\n";
} }
} }
else else
...@@ -893,7 +893,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli ...@@ -893,7 +893,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli
aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1)
<< ((*bo)->endPoint.x / IDF_THOU_TO_MM) << " " << ((*bo)->endPoint.x / IDF_THOU_TO_MM) << " "
<< ((*bo)->endPoint.y / IDF_THOU_TO_MM) << " " << ((*bo)->endPoint.y / IDF_THOU_TO_MM) << " "
<< setprecision(5) << (*bo)->angle << "\n"; << setprecision(2) << (*bo)->angle << "\n";
} }
} }
...@@ -915,7 +915,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli ...@@ -915,7 +915,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli
aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5)
<< (*bo)->endPoint.x << " " << (*bo)->endPoint.x << " "
<< (*bo)->endPoint.y << " " << (*bo)->endPoint.y << " "
<< setprecision(5) << (*bo)->angle << "\n"; << setprecision(2) << (*bo)->angle << "\n";
} }
} }
else else
...@@ -931,7 +931,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli ...@@ -931,7 +931,7 @@ void BOARD_OUTLINE::writeOutline( std::ofstream& aBoardFile, IDF_OUTLINE* aOutli
aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1)
<< ((*bo)->endPoint.x / IDF_THOU_TO_MM) << " " << ((*bo)->endPoint.x / IDF_THOU_TO_MM) << " "
<< ((*bo)->endPoint.y / IDF_THOU_TO_MM) << " " << ((*bo)->endPoint.y / IDF_THOU_TO_MM) << " "
<< setprecision(5) << (*bo)->angle << "\n"; << setprecision(2) << (*bo)->angle << "\n";
} }
} }
...@@ -1281,7 +1281,7 @@ bool BOARD_OUTLINE::addOutline( IDF_OUTLINE* aOutline ) ...@@ -1281,7 +1281,7 @@ bool BOARD_OUTLINE::addOutline( IDF_OUTLINE* aOutline )
outlines.push_back( aOutline ); outlines.push_back( aOutline );
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
errormsg = e.what(); errormsg = e.what();
......
...@@ -2382,7 +2382,7 @@ void IDF3_BOARD::readBoardFile( const std::string& aFileName, bool aNoSubstitute ...@@ -2382,7 +2382,7 @@ void IDF3_BOARD::readBoardFile( const std::string& aFileName, bool aNoSubstitute
} }
} }
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
brd.exceptions ( std::ios_base::goodbit ); brd.exceptions ( std::ios_base::goodbit );
...@@ -2689,7 +2689,7 @@ void IDF3_BOARD::readLibFile( const std::string& aFileName ) ...@@ -2689,7 +2689,7 @@ void IDF3_BOARD::readLibFile( const std::string& aFileName )
while( lib.good() ) readLibSection( lib, state, this ); while( lib.good() ) readLibSection( lib, state, this );
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
lib.exceptions ( std::ios_base::goodbit ); lib.exceptions ( std::ios_base::goodbit );
...@@ -2773,7 +2773,7 @@ bool IDF3_BOARD::ReadFile( const wxString& aFullFileName, bool aNoSubstituteOutl ...@@ -2773,7 +2773,7 @@ bool IDF3_BOARD::ReadFile( const wxString& aFullFileName, bool aNoSubstituteOutl
// read the board file // read the board file
readBoardFile( bfname, aNoSubstituteOutlines ); readBoardFile( bfname, aNoSubstituteOutlines );
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
Clear(); Clear();
errormsg = e.what(); errormsg = e.what();
...@@ -2821,7 +2821,7 @@ bool IDF3_BOARD::writeLibFile( const std::string& aFileName ) ...@@ -2821,7 +2821,7 @@ bool IDF3_BOARD::writeLibFile( const std::string& aFileName )
} }
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
lib.exceptions( std::ios_base::goodbit ); lib.exceptions( std::ios_base::goodbit );
...@@ -3065,7 +3065,7 @@ void IDF3_BOARD::writeBoardFile( const std::string& aFileName ) ...@@ -3065,7 +3065,7 @@ void IDF3_BOARD::writeBoardFile( const std::string& aFileName )
} }
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
brd.exceptions( std::ios_base::goodbit ); brd.exceptions( std::ios_base::goodbit );
...@@ -3137,7 +3137,7 @@ bool IDF3_BOARD::WriteFile( const wxString& aFullFileName, bool aUnitMM, bool aF ...@@ -3137,7 +3137,7 @@ bool IDF3_BOARD::WriteFile( const wxString& aFullFileName, bool aUnitMM, bool aF
writeBoardFile( bfname ); writeBoardFile( bfname );
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
errormsg = e.what(); errormsg = e.what();
...@@ -3901,7 +3901,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( wxString aFullFileName ) ...@@ -3901,7 +3901,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( wxString aFullFileName )
} }
} // while( true ) } // while( true )
} }
catch( std::exception& e ) catch( const std::exception& e )
{ {
delete cp; delete cp;
......
...@@ -230,8 +230,7 @@ void VRML_LAYER::Clear( void ) ...@@ -230,8 +230,7 @@ void VRML_LAYER::Clear( void )
contours.pop_back(); contours.pop_back();
} }
while( !areas.empty() ) areas.clear();
areas.pop_back();
for( i = vertices.size(); i > 0; --i ) for( i = vertices.size(); i > 0; --i )
{ {
...@@ -254,8 +253,7 @@ void VRML_LAYER::clearTmp( void ) ...@@ -254,8 +253,7 @@ void VRML_LAYER::clearTmp( void )
ord = 0; ord = 0;
glcmd = 0; glcmd = 0;
while( !triplets.empty() ) triplets.clear();
triplets.pop_back();
for( i = outline.size(); i > 0; --i ) for( i = outline.size(); i > 0; --i )
{ {
...@@ -263,8 +261,7 @@ void VRML_LAYER::clearTmp( void ) ...@@ -263,8 +261,7 @@ void VRML_LAYER::clearTmp( void )
outline.pop_back(); outline.pop_back();
} }
for( i = ordmap.size(); i > 0; --i ) ordmap.clear();
ordmap.pop_back();
for( i = extra_verts.size(); i > 0; --i ) for( i = extra_verts.size(); i > 0; --i )
{ {
...@@ -274,8 +271,7 @@ void VRML_LAYER::clearTmp( void ) ...@@ -274,8 +271,7 @@ void VRML_LAYER::clearTmp( void )
// note: unlike outline and extra_verts, // note: unlike outline and extra_verts,
// vlist is not responsible for memory management // vlist is not responsible for memory management
for( i = vlist.size(); i > 0; --i ) vlist.clear();
vlist.pop_back();
// go through the vertex list and reset ephemeral parameters // go through the vertex list and reset ephemeral parameters
for( i = 0; i < vertices.size(); ++i ) for( i = 0; i < vertices.size(); ++i )
...@@ -743,6 +739,7 @@ bool VRML_LAYER::Tesselate( VRML_LAYER* holes ) ...@@ -743,6 +739,7 @@ bool VRML_LAYER::Tesselate( VRML_LAYER* holes )
// open the polygon // open the polygon
gluTessBeginPolygon( tess, this ); gluTessBeginPolygon( tess, this );
// add solid outlines
pushVertices( false ); pushVertices( false );
// close the polygon // close the polygon
...@@ -751,8 +748,10 @@ bool VRML_LAYER::Tesselate( VRML_LAYER* holes ) ...@@ -751,8 +748,10 @@ bool VRML_LAYER::Tesselate( VRML_LAYER* holes )
if( Fault ) if( Fault )
return false; return false;
// push the (solid) outline to the tesselator // at this point we have a solid outline; add it to the tesselator
if( !pushOutline( holes ) ) gluTessBeginPolygon( tess, this );
if( !pushOutline( NULL ) )
return false; return false;
// add the holes contained by this object // add the holes contained by this object
...@@ -772,14 +771,14 @@ bool VRML_LAYER::Tesselate( VRML_LAYER* holes ) ...@@ -772,14 +771,14 @@ bool VRML_LAYER::Tesselate( VRML_LAYER* holes )
// erase the previous outline data and vertex order // erase the previous outline data and vertex order
// but preserve the extra vertices // but preserve the extra vertices
for( int i = outline.size(); i > 0; --i ) while( !outline.empty() )
{ {
delete outline.back(); delete outline.back();
outline.pop_back(); outline.pop_back();
} }
for( unsigned int i = ordmap.size(); i > 0; --i ) ordmap.clear();
ordmap.pop_back(); ord = 0;
// go through the vertex lists and reset ephemeral parameters // go through the vertex lists and reset ephemeral parameters
for( unsigned int i = 0; i < vertices.size(); ++i ) for( unsigned int i = 0; i < vertices.size(); ++i )
...@@ -792,14 +791,16 @@ bool VRML_LAYER::Tesselate( VRML_LAYER* holes ) ...@@ -792,14 +791,16 @@ bool VRML_LAYER::Tesselate( VRML_LAYER* holes )
extra_verts[i]->o = -1; extra_verts[i]->o = -1;
} }
ord = 0; // close the polygon; this creates the outline points
// and the point ordering list 'ordmap'
// close the polygon; we now have all the data necessary for the tesselation
gluTessEndPolygon( tess ); gluTessEndPolygon( tess );
// request a tesselated surface // repeat the last operation but request a tesselated surface
// rather than an outline; this creates the triangles list.
gluTessProperty( tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE ); gluTessProperty( tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE );
gluTessBeginPolygon( tess, this );
if( !pushOutline( holes ) ) if( !pushOutline( holes ) )
return false; return false;
...@@ -821,8 +822,6 @@ bool VRML_LAYER::pushOutline( VRML_LAYER* holes ) ...@@ -821,8 +822,6 @@ bool VRML_LAYER::pushOutline( VRML_LAYER* holes )
return false; return false;
} }
gluTessBeginPolygon( tess, this );
std::list<std::list<int>*>::const_iterator obeg = outline.begin(); std::list<std::list<int>*>::const_iterator obeg = outline.begin();
std::list<std::list<int>*>::const_iterator oend = outline.end(); std::list<std::list<int>*>::const_iterator oend = outline.end();
...@@ -851,6 +850,7 @@ bool VRML_LAYER::pushOutline( VRML_LAYER* holes ) ...@@ -851,6 +850,7 @@ bool VRML_LAYER::pushOutline( VRML_LAYER* holes )
if( pi < 0 || (unsigned int) pi > ordmap.size() ) if( pi < 0 || (unsigned int) pi > ordmap.size() )
{ {
gluTessEndContour( tess );
error = "pushOutline():BUG: *outline.begin() is not a valid index to ordmap"; error = "pushOutline():BUG: *outline.begin() is not a valid index to ordmap";
return false; return false;
} }
...@@ -862,6 +862,7 @@ bool VRML_LAYER::pushOutline( VRML_LAYER* holes ) ...@@ -862,6 +862,7 @@ bool VRML_LAYER::pushOutline( VRML_LAYER* holes )
if( !vp ) if( !vp )
{ {
gluTessEndContour( tess );
error = "pushOutline():: BUG: ordmap[n] is not a valid index to vertices[]"; error = "pushOutline():: BUG: ordmap[n] is not a valid index to vertices[]";
return false; return false;
} }
...@@ -1194,9 +1195,9 @@ bool VRML_LAYER::addTriplet( VERTEX_3D* p0, VERTEX_3D* p1, VERTEX_3D* p2 ) ...@@ -1194,9 +1195,9 @@ bool VRML_LAYER::addTriplet( VERTEX_3D* p0, VERTEX_3D* p1, VERTEX_3D* p2 )
double dy0 = p1->y - p0->y; double dy0 = p1->y - p0->y;
double dy1 = p2->y - p0->y; double dy1 = p2->y - p0->y;
// this number is chosen because we shall only write 6 decimal places // this number is chosen because we shall only write 9 decimal places
// on the VRML output // at most on the VRML output
double err = 0.000001; double err = 0.000000001;
// test if the triangles are degenerate (parallel sides) // test if the triangles are degenerate (parallel sides)
......
...@@ -96,6 +96,7 @@ private: ...@@ -96,6 +96,7 @@ private:
bool fix; // when true, no more vertices may be added by the user bool fix; // when true, no more vertices may be added by the user
int idx; // vertex index (number of contained vertices) int idx; // vertex index (number of contained vertices)
int ord; // vertex order (number of ordered vertices) int ord; // vertex order (number of ordered vertices)
unsigned int idxout; // outline index to first point in 3D outline
std::vector<VERTEX_3D*> vertices; // vertices of all contours std::vector<VERTEX_3D*> vertices; // vertices of all contours
std::vector<std::list<int>*> contours; // lists of vertices for each contour std::vector<std::list<int>*> contours; // lists of vertices for each contour
std::vector< double > areas; // area of the contours (positive if winding is CCW) std::vector< double > areas; // area of the contours (positive if winding is CCW)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment