Commit 4fd3dbb5 authored by jean-pierre charras's avatar jean-pierre charras

Finishing work on a better 3D viewer. this also fix bugs like Bug #1129630 .

parent f24bc87a
...@@ -45,16 +45,11 @@ ...@@ -45,16 +45,11 @@
#include <info3d_visu.h> #include <info3d_visu.h>
#include <trackball.h> #include <trackball.h>
// Exported function:
void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits );
void S3D_MASTER::ObjectCoordsTo3DUnits( std::vector< S3D_VERTEX >& aVertices )
void S3D_MASTER::Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices )
{ {
unsigned ii;
/* adjust object scale, rotation and offset position */ /* adjust object scale, rotation and offset position */
for( ii = 0; ii < aVertices.size(); ii++ ) for( unsigned ii = 0; ii < aVertices.size(); ii++ )
{ {
aVertices[ii].x *= m_MatScale.x; aVertices[ii].x *= m_MatScale.x;
aVertices[ii].y *= m_MatScale.y; aVertices[ii].y *= m_MatScale.y;
...@@ -79,7 +74,7 @@ void S3D_MASTER::Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices ) ...@@ -79,7 +74,7 @@ void S3D_MASTER::Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices )
} }
void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits ) void TransfertToGLlist( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits )
{ {
unsigned ii; unsigned ii;
GLfloat ax, ay, az, bx, by, bz, nx, ny, nz, r; GLfloat ax, ay, az, bx, by, bz, nx, ny, nz, r;
...@@ -138,44 +133,6 @@ void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits ...@@ -138,44 +133,6 @@ void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits
glEnd(); glEnd();
} }
GLuint EDA_3D_CANVAS::DisplayCubeforTest()
{
GLuint gllist = glGenLists( 1 );
glNewList( gllist, GL_COMPILE_AND_EXECUTE );
/* draw six faces of a cube */
glBegin( GL_QUADS );
glNormal3f( 0.0F, 0.0F, 1.0F );
glVertex3f( 0.5F, 0.5F, 0.5F ); glVertex3f( -0.5F, 0.5F, 0.5F );
glVertex3f( -0.5F, -0.5F, 0.5F ); glVertex3f( 0.5F, -0.5F, 0.5F );
glNormal3f( 0.0F, 0.0F, -1.0F );
glVertex3f( -0.5F, -0.5F, -0.5F ); glVertex3f( -0.5F, 0.5F, -0.5F );
glVertex3f( 0.5F, 0.5F, -0.5F ); glVertex3f( 0.5F, -0.5F, -0.5F );
glNormal3f( 0.0F, 1.0F, 0.0F );
glVertex3f( 0.5F, 0.5F, 0.5F ); glVertex3f( 0.5F, 0.5F, -0.5F );
glVertex3f( -0.5F, 0.5F, -0.5F ); glVertex3f( -0.5F, 0.5F, 0.5F );
glNormal3f( 0.0F, -1.0F, 0.0F );
glVertex3f( -0.5F, -0.5F, -0.5F ); glVertex3f( 0.5F, -0.5F, -0.5F );
glVertex3f( 0.5F, -0.5F, 0.5F ); glVertex3f( -0.5F, -0.5F, 0.5F );
glNormal3f( 1.0F, 0.0F, 0.0F );
glVertex3f( 0.5F, 0.5F, 0.5F ); glVertex3f( 0.5F, -0.5F, 0.5F );
glVertex3f( 0.5F, -0.5F, -0.5F ); glVertex3f( 0.5F, 0.5F, -0.5F );
glNormal3f( -1.0F, 0.0F, 0.0F );
glVertex3f( -0.5F, -0.5F, -0.5F ); glVertex3f( -0.5F, -0.5F, 0.5F );
glVertex3f( -0.5F, 0.5F, 0.5F ); glVertex3f( -0.5F, 0.5F, -0.5F );
glEnd();
glEndList();
return gllist;
}
VERTEX_VALUE_CTRL::VERTEX_VALUE_CTRL( wxWindow* aParent, wxBoxSizer* aBoxSizer ) VERTEX_VALUE_CTRL::VERTEX_VALUE_CTRL( wxWindow* aParent, wxBoxSizer* aBoxSizer )
{ {
wxString text; wxString text;
......
...@@ -104,7 +104,6 @@ public: ...@@ -104,7 +104,6 @@ public:
void OnEnterWindow( wxMouseEvent& event ); void OnEnterWindow( wxMouseEvent& event );
// Display functions // Display functions
GLuint DisplayCubeforTest(); // Just a test function
void SetView3D( int keycode ); void SetView3D( int keycode );
void DisplayStatus(); void DisplayStatus();
void Redraw(); void Redraw();
......
...@@ -41,9 +41,14 @@ S3D_MATERIAL::S3D_MATERIAL( S3D_MASTER* father, const wxString& name ) : ...@@ -41,9 +41,14 @@ S3D_MATERIAL::S3D_MATERIAL( S3D_MASTER* father, const wxString& name ) :
m_Name = name; m_Name = name;
} }
void S3D_MATERIAL::SetMaterial() void S3D_MATERIAL::SetMaterial()
{ {
S3D_MASTER * s3dParent = (S3D_MASTER *) GetParent();
s3dParent->SetLastTransparency( m_Transparency );
if( ! s3dParent->IsOpenGlAllowed() )
return;
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
glColor4f( m_DiffuseColor.x * m_AmbientIntensity, glColor4f( m_DiffuseColor.x * m_AmbientIntensity,
m_DiffuseColor.y * m_AmbientIntensity, m_DiffuseColor.y * m_AmbientIntensity,
...@@ -56,6 +61,20 @@ void S3D_MATERIAL::SetMaterial() ...@@ -56,6 +61,20 @@ void S3D_MATERIAL::SetMaterial()
#endif #endif
} }
bool S3D_MASTER::IsOpenGlAllowed()
{
if( m_loadNonTransparentObjects ) // return true for non transparent objects only
{
if( m_lastTransparency == 0.0 )
return true;
}
if( m_loadTransparentObjects ) // return true for transparent objects only
if( m_lastTransparency != 0.0 )
return true;
return false;
}
void S3D_MASTER::Insert( S3D_MATERIAL* aMaterial ) void S3D_MASTER::Insert( S3D_MATERIAL* aMaterial )
{ {
...@@ -79,6 +98,7 @@ S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) : ...@@ -79,6 +98,7 @@ S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) :
EDA_ITEM( aParent, NOT_USED ) EDA_ITEM( aParent, NOT_USED )
{ {
m_MatScale.x = m_MatScale.y = m_MatScale.z = 1.0; m_MatScale.x = m_MatScale.y = m_MatScale.z = 1.0;
m_lastTransparency = 0.0;
m_3D_Drawings = NULL; m_3D_Drawings = NULL;
m_Materials = NULL; m_Materials = NULL;
m_ShapeType = FILE3D_NONE; m_ShapeType = FILE3D_NONE;
......
...@@ -356,7 +356,7 @@ void EDA_3D_CANVAS::BuildBoard3DView() ...@@ -356,7 +356,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
} }
} }
// draw graphic items // draw graphic items on copper layers (texts)
for( BOARD_ITEM* item = pcb->m_Drawings; item; item = item->Next() ) for( BOARD_ITEM* item = pcb->m_Drawings; item; item = item->Next() )
{ {
if( !item->IsOnLayer( layer ) ) if( !item->IsOnLayer( layer ) )
...@@ -364,11 +364,9 @@ void EDA_3D_CANVAS::BuildBoard3DView() ...@@ -364,11 +364,9 @@ void EDA_3D_CANVAS::BuildBoard3DView()
switch( item->Type() ) switch( item->Type() )
{ {
case PCB_LINE_T: case PCB_LINE_T: // should not exist on copper layers
( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon( ( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon(
bufferPolys, 0, bufferPolys, 0, segcountforcircle, correctionFactor );
segcountforcircle,
correctionFactor );
break; break;
case PCB_TEXT_T: case PCB_TEXT_T:
...@@ -505,8 +503,7 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() ...@@ -505,8 +503,7 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
// a fine representation // a fine representation
CPOLYGONS_LIST bufferPolys; CPOLYGONS_LIST bufferPolys;
bufferPolys.reserve( 200000 ); // Reserve for large board (tracks mainly) bufferPolys.reserve( 100000 ); // Reserve for large board
CPOLYGONS_LIST allLayerHoles; // Contains through holes, calculated only once CPOLYGONS_LIST allLayerHoles; // Contains through holes, calculated only once
allLayerHoles.reserve( 20000 ); allLayerHoles.reserve( 20000 );
...@@ -522,11 +519,6 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() ...@@ -522,11 +519,6 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
wxMessageBox( msg ); wxMessageBox( msg );
} }
CPOLYGONS_LIST bufferZonesPolys;
bufferZonesPolys.reserve( 500000 ); // Reserve for large board ( copper zones mainly )
CPOLYGONS_LIST currLayerHoles; // Contains holes for the current layer
int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU();
for( TRACK* track = pcb->m_Track; track != NULL; track = track->Next() ) for( TRACK* track = pcb->m_Track; track != NULL; track = track->Next() )
{ {
...@@ -544,6 +536,16 @@ void EDA_3D_CANVAS::BuildTechLayers3DView() ...@@ -544,6 +536,16 @@ void EDA_3D_CANVAS::BuildTechLayers3DView()
} }
} }
// draw pads holes
for( MODULE* module = pcb->m_Modules; module != NULL; module = module->Next() )
{
// Add pad hole, if any
D_PAD* pad = module->Pads();
for( ; pad != NULL; pad = pad->Next() )
pad->BuildPadDrillShapePolygon( allLayerHoles, 0,
segcountLowQuality );
}
// draw graphic items, on technical layers // draw graphic items, on technical layers
...@@ -852,6 +854,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List() ...@@ -852,6 +854,7 @@ void EDA_3D_CANVAS::CreateDrawGL_List()
#endif #endif
} }
void EDA_3D_CANVAS::BuildFootprintShape3DList( GLuint aOpaqueList, void EDA_3D_CANVAS::BuildFootprintShape3DList( GLuint aOpaqueList,
GLuint aTransparentList) GLuint aTransparentList)
{ {
...@@ -860,10 +863,21 @@ void EDA_3D_CANVAS::BuildFootprintShape3DList( GLuint aOpaqueList, ...@@ -860,10 +863,21 @@ void EDA_3D_CANVAS::BuildFootprintShape3DList( GLuint aOpaqueList,
// which need to be drawn after all other items // which need to be drawn after all other items
BOARD* pcb = GetBoard(); BOARD* pcb = GetBoard();
glNewList( m_glLists[GL_ID_3DSHAPES_SOLID], GL_COMPILE ); glNewList( aOpaqueList, GL_COMPILE );
bool loadTransparentObjects = false;
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
module->ReadAndInsert3DComponentShape( this, !loadTransparentObjects,
loadTransparentObjects );
glEndList();
glNewList( aTransparentList, GL_COMPILE );
loadTransparentObjects = true;
for( MODULE* module = pcb->m_Modules; module; module = module->Next() ) for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
module->ReadAndInsert3DComponentShape( this ); module->ReadAndInsert3DComponentShape( this, !loadTransparentObjects,
loadTransparentObjects );
glEndList(); glEndList();
} }
...@@ -1055,8 +1069,11 @@ void EDA_3D_CANVAS::Draw3DViaHole( SEGVIA* aVia ) ...@@ -1055,8 +1069,11 @@ void EDA_3D_CANVAS::Draw3DViaHole( SEGVIA* aVia )
} }
void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas ) void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas,
bool aAllowNonTransparentObjects,
bool aAllowTransparentObjects )
{ {
// Read from disk and draws the footprint 3D shapes if exists // Read from disk and draws the footprint 3D shapes if exists
S3D_MASTER* shape3D = m_3D_Drawings; S3D_MASTER* shape3D = m_3D_Drawings;
double zpos = g_Parm_3D_Visu.GetModulesZcoord3DIU( IsFlipped() ); double zpos = g_Parm_3D_Visu.GetModulesZcoord3DIU( IsFlipped() );
...@@ -1078,6 +1095,9 @@ void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas ) ...@@ -1078,6 +1095,9 @@ void MODULE::ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas )
for( ; shape3D != NULL; shape3D = shape3D->Next() ) for( ; shape3D != NULL; shape3D = shape3D->Next() )
{ {
shape3D->SetLoadNonTransparentObjects( aAllowNonTransparentObjects );
shape3D->SetLoadTransparentObjects( aAllowTransparentObjects );
if( shape3D->Is3DType( S3D_MASTER::FILE3D_VRML ) ) if( shape3D->Is3DType( S3D_MASTER::FILE3D_VRML ) )
shape3D->ReadData(); shape3D->ReadData();
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <3d_draw_basic_functions.h> #include <3d_draw_basic_functions.h>
// Imported function: // Imported function:
extern void Set_Object_Data( std::vector<S3D_VERTEX>& aVertices, double aBiuTo3DUnits ); extern void TransfertToGLlist( std::vector<S3D_VERTEX>& aVertices, double aBiuTo3DUnits );
extern void CheckGLError(); extern void CheckGLError();
// Number of segments to approximate a circle by segments // Number of segments to approximate a circle by segments
...@@ -116,7 +116,7 @@ static void Draw3D_VerticalPolygonalCylinder( const CPOLYGONS_LIST& aPolysList, ...@@ -116,7 +116,7 @@ static void Draw3D_VerticalPolygonalCylinder( const CPOLYGONS_LIST& aPolysList,
coords[3].y = coords[2].y; // only z change coords[3].y = coords[2].y; // only z change
// Creates the GL_QUAD // Creates the GL_QUAD
Set_Object_Data( coords, aBiuTo3DUnits ); TransfertToGLlist( coords, aBiuTo3DUnits );
} }
} }
......
...@@ -109,6 +109,10 @@ public: ...@@ -109,6 +109,10 @@ public:
private: private:
wxString m_Shape3DName; /* 3D shape name in 3D library */ wxString m_Shape3DName; /* 3D shape name in 3D library */
FILE3D_TYPE m_ShapeType; FILE3D_TYPE m_ShapeType;
double m_lastTransparency; // last transparency value from
// last material in use
bool m_loadTransparentObjects;
bool m_loadNonTransparentObjects;
public: public:
S3D_MASTER( EDA_ITEM* aParent ); S3D_MASTER( EDA_ITEM* aParent );
...@@ -117,11 +121,41 @@ public: ...@@ -117,11 +121,41 @@ public:
S3D_MASTER* Next() const { return (S3D_MASTER*) Pnext; } S3D_MASTER* Next() const { return (S3D_MASTER*) Pnext; }
S3D_MASTER* Back() const { return (S3D_MASTER*) Pback; } S3D_MASTER* Back() const { return (S3D_MASTER*) Pback; }
// Accessors
void SetLastTransparency( double aValue ) { m_lastTransparency = aValue; }
void SetLoadTransparentObjects( bool aLoad )
{ m_loadTransparentObjects = aLoad; }
void SetLoadNonTransparentObjects( bool aLoad )
{ m_loadNonTransparentObjects = aLoad; }
void Insert( S3D_MATERIAL* aMaterial ); void Insert( S3D_MATERIAL* aMaterial );
/**
* Function IsOpenGlAllowed
* @return true if opengl current list accepts a gl data
* used to filter transparent objects, which are drawn after
* non transparent objects
*/
bool IsOpenGlAllowed();
void Copy( S3D_MASTER* pattern ); void Copy( S3D_MASTER* pattern );
/**
* Function ReadData
* Select the parser to read the 3D data file (vrml, x3d ...)
* and build the description objects list
*/
int ReadData(); int ReadData();
void Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices );
/**
* Function ObjectCoordsTo3DUnits
* @param aVertices = a list of 3D coordinates in shape units
* to convert to 3D canvas units, according to the
* footprint 3Dshape rotation, offset and scale parameters
*/
void ObjectCoordsTo3DUnits( std::vector< S3D_VERTEX >& aVertices );
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
...@@ -147,6 +181,13 @@ public: ...@@ -147,6 +181,13 @@ public:
*/ */
const wxString GetShape3DFullFilename(); const wxString GetShape3DFullFilename();
/**
* Function SetShape3DName
* @param aShapeName = file name of the data file relative to the 3D shape
*
* Set the filename of the 3D shape, and depending on the file extention
* (vrl, x3d, idf ) the type of file.
*/
void SetShape3DName( const wxString& aShapeName ); void SetShape3DName( const wxString& aShapeName );
}; };
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
class S3D_MASTER; class S3D_MASTER;
class S3D_VERTEX; class S3D_VERTEX;
extern void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits ); extern void TransfertToGLlist( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits );
class S3D_MODEL_PARSER; class S3D_MODEL_PARSER;
class X3D_MODEL_PARSER; class X3D_MODEL_PARSER;
......
...@@ -519,8 +519,12 @@ int VRML_MODEL_PARSER::readGeometry( FILE* file, int* LineNum ) ...@@ -519,8 +519,12 @@ int VRML_MODEL_PARSER::readGeometry( FILE* file, int* LineNum )
vertices.push_back( vertex ); vertices.push_back( vertex );
} }
GetMaster()->Set_Object_Coords( vertices ); if( GetMaster()->IsOpenGlAllowed() )
Set_Object_Data( vertices, vrmlunits_to_3Dunits ); {
GetMaster()->ObjectCoordsTo3DUnits( vertices );
TransfertToGLlist( vertices, vrmlunits_to_3Dunits );
}
vertices.clear(); vertices.clear();
coordIndex.clear(); coordIndex.clear();
} }
......
...@@ -479,8 +479,11 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode, ...@@ -479,8 +479,11 @@ void X3D_MODEL_PARSER::readIndexedFaceSet( wxXmlNode* aFaceNode,
vertices.push_back( triplets.at( *id ) ); vertices.push_back( triplets.at( *id ) );
} }
GetMaster()->Set_Object_Coords( vertices ); if( GetMaster()->IsOpenGlAllowed() )
Set_Object_Data( vertices, vrmlunits_to_3Dunits ); {
GetMaster()->ObjectCoordsTo3DUnits( vertices );
TransfertToGLlist( vertices, vrmlunits_to_3Dunits );
}
vertices.clear(); vertices.clear();
coordIndex.clear(); coordIndex.clear();
......
...@@ -250,8 +250,14 @@ public: ...@@ -250,8 +250,14 @@ public:
* function ReadandInsert3DComponentShape * function ReadandInsert3DComponentShape
* read the 3D component shape(s) of the footprint (physical shape) * read the 3D component shape(s) of the footprint (physical shape)
* and insert mesh in gl list * and insert mesh in gl list
* @param glcanvas = the openGL canvas
* @param aAllowNonTransparentObjects = true to load non transparent objects
* @param aAllowTransparentObjects = true to load non transparent objects
* in openGL, transparent objects should be drawn *after* non transparent objects
*/ */
void ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas ); void ReadAndInsert3DComponentShape( EDA_3D_CANVAS* glcanvas,
bool aAllowNonTransparentObjects,
bool aAllowTransparentObjects );
/** /**
* function TransformPadsShapesWithClearanceToPolygon * function TransformPadsShapesWithClearanceToPolygon
......
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