Loading 3d-viewer/3d_draw.cpp +37 −39 Original line number Diff line number Diff line Loading @@ -49,21 +49,21 @@ #include <3d_draw_basic_functions.h> // Imported function: extern void SetGLColor( int color ); extern void SetGLColor( EDA_COLOR_T color ); extern void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits ); extern void CheckGLError(); /* returns true if aLayer should be displayed, false otherwise */ static bool Is3DLayerEnabled( int aLayer ); static bool Is3DLayerEnabled( LAYER_NUM aLayer ); /* returns the Z orientation parameter 1.0 or -1.0 for aLayer * Z orientation is 1.0 for all layers but "back" layers: * LAYER_N_BACK , ADHESIVE_N_BACK, SOLDERPASTE_N_BACK ), SILKSCREEN_N_BACK * used to calculate the Z orientation parameter for glNormal3f */ static GLfloat Get3DLayer_Z_Orientation( int aLayer ); static GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer ); void EDA_3D_CANVAS::Redraw( bool finish ) { Loading Loading @@ -163,7 +163,7 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List() Draw3D_Via( (SEGVIA*) track ); else { int layer = track->GetLayer(); LAYER_NUM layer = track->GetLayer(); if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) ) Draw3D_Track( track ); Loading @@ -174,7 +174,7 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List() { for( int ii = 0; ii < pcb->GetAreaCount(); ii++ ) { int layer = pcb->GetArea( ii )->GetLayer(); LAYER_NUM layer = pcb->GetArea( ii )->GetLayer(); if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) ) Draw3D_Zone( pcb->GetArea( ii ) ); Loading Loading @@ -236,8 +236,8 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List() */ void EDA_3D_CANVAS::Draw3D_Zone( ZONE_CONTAINER* aZone ) { int layer = aZone->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); LAYER_NUM layer = aZone->GetLayer(); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer ); int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); if( layer == LAST_COPPER_LAYER ) Loading Loading @@ -326,8 +326,8 @@ void EDA_3D_CANVAS::Draw3D_Zone( ZONE_CONTAINER* aZone ) void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM ) { double zpos = 0.0; int gridcolor = DARKGRAY; // Color of grid lines int gridcolor_marker = LIGHTGRAY; // Color of grid lines every 5 lines EDA_COLOR_T gridcolor = DARKGRAY; // Color of grid lines EDA_COLOR_T gridcolor_marker = LIGHTGRAY; // Color of grid lines every 5 lines double scale = g_Parm_3D_Visu.m_BiuTo3Dunits; glNormal3f( 0.0, 0.0, 1.0 ); Loading Loading @@ -456,8 +456,8 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM ) void EDA_3D_CANVAS::Draw3D_Track( TRACK* aTrack ) { int layer = aTrack->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); LAYER_NUM layer = aTrack->GetLayer(); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer ); int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); if( layer == LAST_COPPER_LAYER ) Loading @@ -475,8 +475,8 @@ void EDA_3D_CANVAS::Draw3D_Track( TRACK* aTrack ) void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) { int layer, top_layer, bottom_layer; int color; LAYER_NUM layer, top_layer, bottom_layer; EDA_COLOR_T color; double biu_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits ; int outer_radius = via->GetWidth() / 2; Loading @@ -486,7 +486,7 @@ void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) via->ReturnLayerPair( &top_layer, &bottom_layer ); // Drawing horizontal thick rings: for( layer = bottom_layer; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) for( layer = bottom_layer; layer < g_Parm_3D_Visu.m_CopperLayersCount; ++layer ) { int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); Loading Loading @@ -530,15 +530,15 @@ void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment ) { int layer = segment->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); LAYER_NUM layer = segment->GetLayer(); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer ); int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); SetGLColor( color ); if( layer == EDGE_N ) { for( layer = 0; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) for( layer = FIRST_LAYER; layer < g_Parm_3D_Visu.m_CopperLayersCount; ++layer ) { glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU(layer); Loading Loading @@ -624,8 +624,8 @@ static void Draw3dTextSegm( int x0, int y0, int xf, int yf ) void EDA_3D_CANVAS::Draw3D_DrawText( TEXTE_PCB* text ) { int layer = text->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); LAYER_NUM layer = text->GetLayer(); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer ); SetGLColor( color ); s_Text3DZPos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); Loading Loading @@ -754,7 +754,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( m_Layer ) == false ) return; int color = g_ColorsSettings.GetLayerColor( m_Layer ); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( m_Layer ); SetGLColor( color ); // for outline shape = S_POLYGON: Loading Loading @@ -790,7 +790,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) if( m_Layer == EDGE_N ) { for( int layer = 0; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) for( LAYER_NUM layer = FIRST_LAYER; layer < g_Parm_3D_Visu.m_CopperLayersCount; ++layer ) { glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); Loading Loading @@ -948,7 +948,7 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) switch( GetShape() ) { case PAD_CIRCLE: for( int layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; layer++ ) for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) { if( layer && (layer == nlmax) ) layer = LAYER_N_FRONT; Loading Loading @@ -998,7 +998,6 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) polyPadShape.insert( polyPadShape.end(), holecornersBuffer.begin(), holecornersBuffer.end() ); } break; case PAD_RECT: Loading @@ -1007,7 +1006,6 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) wxPoint coord[5]; BuildPadPolygon( coord, wxSize(0,0), m_Orient ); for( int ii = 0; ii < 4; ii ++ ) { CPolyPt pt( coord[ii].x + shape_pos.x, coord[ii].y+ shape_pos.y ); polyPadShape.push_back( pt ); Loading @@ -1027,7 +1025,7 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) if( polyPadShape.size() ) { for( int layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; layer++ ) for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) { if( layer && (layer == nlmax) ) layer = LAYER_N_FRONT; Loading Loading @@ -1061,9 +1059,9 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) } bool Is3DLayerEnabled( int aLayer ) bool Is3DLayerEnabled( LAYER_NUM aLayer ) { int flg = -1; int flg; // see if layer needs to be shown // check the flags Loading @@ -1084,18 +1082,18 @@ bool Is3DLayerEnabled( int aLayer ) case ECO2_N: flg = g_Parm_3D_Visu.FL_ECO2; break; } default: // the layer was not a layer with a flag, so show it if( flg < 0 ) return true; } // if the layer has a flag, return the flag return g_Parm_3D_Visu.m_DrawFlags[flg]; } GLfloat Get3DLayer_Z_Orientation( int aLayer ) GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer ) { double nZ; Loading 3d-viewer/3d_draw_basic_functions.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -122,10 +122,10 @@ static void Draw3D_VerticalPolygonalCylinder( const std::vector<CPolyPt>& aPolys } void SetGLColor( int color ) void SetGLColor( EDA_COLOR_T color ) { double red, green, blue; StructColors colordata = ColorRefs[color & MASKCOLOR]; const StructColors &colordata = g_ColorRefs[ColorGetBase( color )]; red = colordata.m_Red / 255.0; blue = colordata.m_Blue / 255.0; Loading 3d-viewer/3d_read_mesh.cpp +31 −502 Original line number Diff line number Diff line Loading @@ -35,20 +35,35 @@ #include <3d_viewer.h> #include <info3d_visu.h> #include "3d_struct.h" #include "modelparsers.h" // Imported function: extern void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits ); // separator chars static const char* sep_chars = " \t\n\r"; S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster, const wxString aExtension ) { if ( aExtension == wxT( "x3d" ) ) { return new X3D_MODEL_PARSER( aMaster ); } else if ( aExtension == wxT( "wrl" ) ) { return new VRML_MODEL_PARSER( aMaster ); } else { return NULL; } } int S3D_MASTER::ReadData() { char line[1024], * text; wxFileName fn; wxString FullFilename; FILE* file; int LineNum = 0; if( m_Shape3DName.IsEmpty() ) { Loading @@ -56,6 +71,7 @@ int S3D_MASTER::ReadData() } wxString shape3DNname = m_Shape3DName; #ifdef __WINDOWS__ shape3DNname.Replace( wxT( "/" ), wxT( "\\" ) ); #else Loading @@ -65,6 +81,7 @@ int S3D_MASTER::ReadData() if( wxFileName::FileExists( shape3DNname ) ) { FullFilename = shape3DNname; fn.Assign( FullFilename ); } else { Loading @@ -79,509 +96,21 @@ int S3D_MASTER::ReadData() } } file = wxFopen( FullFilename, wxT( "rt" ) ); if( file == NULL ) { return -1; } // Switch the locale to standard C (needed to print floating point numbers like 1.3) SetLocaleTo_C_standard(); while( GetLine( file, line, &LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( stricmp( text, "DEF" ) == 0 || stricmp( text, "Group" ) == 0) { while( GetLine( file, line, &LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( text == NULL ) continue; if( *text == '}' ) break; if( stricmp( text, "children" ) == 0 ) { ReadChildren( file, &LineNum ); } } } } fclose( file ); SetLocaleTo_Default(); // revert to the current locale return 0; } int S3D_MASTER::ReadMaterial( FILE* file, int* LineNum ) { char line[512], * text, * command; wxString mat_name; S3D_MATERIAL* material = NULL; command = strtok( NULL, sep_chars ); text = strtok( NULL, sep_chars ); mat_name = FROM_UTF8( text ); if( stricmp( command, "USE" ) == 0 ) { for( material = m_Materials; material; material = material->Next() ) { if( material->m_Name == mat_name ) { material->SetMaterial(); return 1; } } D( printf( "ReadMaterial error: material not found\n" ) ); return 0; } if( stricmp( command, "DEF" ) == 0 || stricmp( command, "Material") == 0) { material = new S3D_MATERIAL( this, mat_name ); Insert( material ); while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( text == NULL ) continue; wxString extension = fn.GetExt(); S3D_MODEL_PARSER* parser = S3D_MODEL_PARSER::Create( this, extension ); if( text[0] == '}' ) if( parser ) { material->SetMaterial(); parser->Load( FullFilename ); delete parser; return 0; } if( stricmp( text, "diffuseColor" ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_DiffuseColor.x = atof( text ); text = strtok( NULL, sep_chars ); material->m_DiffuseColor.y = atof( text ); text = strtok( NULL, sep_chars ); material->m_DiffuseColor.z = atof( text ); } else if( stricmp( text, "emissiveColor" ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_EmissiveColor.x = atof( text ); text = strtok( NULL, sep_chars ); material->m_EmissiveColor.y = atof( text ); text = strtok( NULL, sep_chars ); material->m_EmissiveColor.z = atof( text ); } else if( strnicmp( text, "specularColor", 13 ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_SpecularColor.x = atof( text ); text = strtok( NULL, sep_chars ); material->m_SpecularColor.y = atof( text ); text = strtok( NULL, sep_chars ); material->m_SpecularColor.z = atof( text ); } else if( strnicmp( text, "ambientIntensity", 16 ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_AmbientIntensity = atof( text ); } else if( strnicmp( text, "transparency", 12 ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_Transparency = atof( text ); } else if( strnicmp( text, "shininess", 9 ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_Shininess = atof( text ); } } } return -1; } int S3D_MASTER::ReadChildren( FILE* file, int* LineNum ) { char line[1024], * text; while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( *text == ']' ) return 0; if( *text == ',' ) continue; if( stricmp( text, "Shape" ) == 0 ) { ReadShape( file, LineNum ); } else { D( printf( "ReadChildren error line %d <%s> \n", *LineNum, text ) ); break; } } return 1; } int S3D_MASTER::ReadShape( FILE* file, int* LineNum ) { char line[1024], * text; int err = 1; while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( *text == '}' ) { err = 0; break; } if( stricmp( text, "appearance" ) == 0 ) { ReadAppearance( file, LineNum ); } else if( stricmp( text, "geometry" ) == 0 ) { ReadGeometry( file, LineNum ); } else { D( printf( "ReadShape error line %d <%s> \n", *LineNum, text ) ); break; } } return err; } int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum ) { char line[1024], * text; int err = 1; while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( *text == '}' ) { err = 0; break; } if( stricmp( text, "material" ) == 0 ) { ReadMaterial( file, LineNum ); } else { D( printf( "ReadAppearance error line %d <%s> \n", *LineNum, text ) ); break; } } return err; } #define BUFSIZE 2000 /** * 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 ) { unsigned int ii = 0, jj = 0; char* text; bool HasData = false; bool StartData = false; bool EndNode = false; char string_num[512]; text = text_buffer; while( !EndNode ) { if( *text == 0 ) // Needs data ! { text = text_buffer; GetLine( file, text_buffer, LineNum, 512 ); } while( !EndNode && *text ) { switch( *text ) { case '[': StartData = true; jj = 0; string_num[jj] = 0; break; case '}': EndNode = true; break; case ']': case '\t': case ' ': case ',': jj = 0; if( !StartData || !HasData ) break; aList.push_back( atof( string_num ) ); string_num[jj] = 0; ii++; HasData = false; if( *text == ']' ) { StartData = false; } break; default: if( !StartData ) break; if( jj >= sizeof( string_num ) ) break; string_num[jj] = *text; jj++; string_num[jj] = 0; HasData = true; break; } text++; } } } int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) { char line[1024], buffer[1024], * text; int err = 1; std::vector< double > points; std::vector< double > list; double vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB; while( GetLine( file, line, LineNum, 512 ) ) { strcpy( buffer, line ); text = strtok( buffer, sep_chars ); if( *text == '}' ) { err = 0; break; } if( stricmp( text, "normalPerVertex" ) == 0 ) { text = strtok( NULL, " ,\t\n\r" ); if( stricmp( text, "true" ) == 0 ) { } else { } continue; } if( stricmp( text, "colorPerVertex" ) == 0 ) { text = strtok( NULL, " ,\t\n\r" ); if( stricmp( text, "true" ) == 0 ) { } else { } continue; } if( stricmp( text, "normal" ) == 0 ) { ReadCoordsList( file, line, list, LineNum ); list.clear(); continue; wxLogDebug( wxT( "Unknown file type <%s>" ), GetChars( extension ) ); } if( stricmp( text, "normalIndex" ) == 0 ) { while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " ,\t\n\r" ); while( text ) { if( *text == ']' ) break; text = strtok( NULL, " ,\t\n\r" ); } if( text && (*text == ']') ) break; } continue; } if( stricmp( text, "color" ) == 0 ) { ReadCoordsList( file, line, list, LineNum ); list.clear(); continue; } if( stricmp( text, "solid" ) == 0 ) { // ignore solid continue; } if( stricmp( text, "colorIndex" ) == 0 ) { while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " ,\t\n\r" ); while( text ) { if( *text == ']' ) break; text = strtok( NULL, " ,\t\n\r" ); } if( text && (*text == ']') ) break; } continue; } if( stricmp( text, "coord" ) == 0 ) { ReadCoordsList( file, line, points, LineNum ); } else if( stricmp( text, "coordIndex" ) == 0 ) { if( points.size() < 3 || points.size() % 3 != 0 ) { wxLogError( wxT( "3D geometry read error <%s> at line %d." ), GetChars( FROM_UTF8( text ) ), *LineNum ); err = 1; break; } std::vector< int > coordIndex; std::vector< S3D_VERTEX > vertices; while( GetLine( file, line, LineNum, 512 ) ) { int jj; text = strtok( line, " ,\t\n\r" ); while( text ) { if( *text == ']' ) break; jj = atoi( text ); if( jj < 0 ) { for( jj = 0; jj < (int) coordIndex.size(); jj++ ) { int kk = coordIndex[jj] * 3; if( (kk < 0) || ((kk + 3) > (int)points.size()) ) { wxLogError( wxT( "3D geometry index read error <%s> at line %d." ), GetChars( FROM_UTF8( text ) ), *LineNum ); err = 1; break; } S3D_VERTEX vertex; vertex.x = points[kk]; vertex.y = points[kk + 1]; vertex.z = points[kk + 2]; vertices.push_back( vertex ); } Set_Object_Coords( vertices ); Set_Object_Data( vertices, vrmlunits_to_3Dunits ); vertices.clear(); coordIndex.clear(); } else { coordIndex.push_back( jj ); } text = strtok( NULL, " ,\t\n\r" ); } if( text && (*text == ']') ) break; } } else { wxLogError( wxT( "3D geometry read error <%s> at line %d." ), GetChars( FROM_UTF8( text ) ), *LineNum ); err = 1; break; } } return err; return -1; } Loading 3d-viewer/3d_struct.h +0 −20 Original line number Diff line number Diff line Loading @@ -115,26 +115,6 @@ public: void Copy( S3D_MASTER* pattern ); int ReadData(); /** * Function ReadMaterial * read the description of a 3D material definition in the form: * DEF yellow material Material ( * DiffuseColor 1.00000 1.00000 0.00000e 0 * EmissiveColor 0.00000e 0 0.00000e 0 0.00000e 0 * SpecularColor 1.00000 1.00000 1.00000 * AmbientIntensity 1.00000 * Transparency 0.00000e 0 * Shininess 1.00000 *) * Or type: * USE yellow material */ int ReadMaterial( FILE* file, int* LineNum ); int ReadChildren( FILE* file, int* LineNum ); int ReadShape( FILE* file, int* LineNum ); int ReadAppearance( FILE* file, int* LineNum ); int ReadGeometry( FILE* file, int* LineNum ); void Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices ); #if defined(DEBUG) Loading 3d-viewer/3d_toolbar.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -105,16 +105,16 @@ void EDA_3D_FRAME::ReCreateHToolbar() m_HToolBar->AddSeparator(); m_HToolBar->AddTool( ID_MOVE3D_LEFT, wxEmptyString, KiBitmap( left_xpm ), _( "Move left <-" ) ); _( "Move left" ) ); m_HToolBar->AddTool( ID_MOVE3D_RIGHT, wxEmptyString, KiBitmap( right_xpm ), _( "Move right ->" ) ); _( "Move right" ) ); m_HToolBar->AddTool( ID_MOVE3D_UP, wxEmptyString, KiBitmap( up_xpm ), _( "Move up ^" ) ); _( "Move up" ) ); m_HToolBar->AddTool( ID_MOVE3D_DOWN, wxEmptyString, KiBitmap( down_xpm ), _( "Move down v" ) ); _( "Move down" ) ); m_HToolBar->AddSeparator(); m_HToolBar->AddTool( ID_ORTHO, wxEmptyString, KiBitmap( ortho_xpm ), Loading Loading
3d-viewer/3d_draw.cpp +37 −39 Original line number Diff line number Diff line Loading @@ -49,21 +49,21 @@ #include <3d_draw_basic_functions.h> // Imported function: extern void SetGLColor( int color ); extern void SetGLColor( EDA_COLOR_T color ); extern void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits ); extern void CheckGLError(); /* returns true if aLayer should be displayed, false otherwise */ static bool Is3DLayerEnabled( int aLayer ); static bool Is3DLayerEnabled( LAYER_NUM aLayer ); /* returns the Z orientation parameter 1.0 or -1.0 for aLayer * Z orientation is 1.0 for all layers but "back" layers: * LAYER_N_BACK , ADHESIVE_N_BACK, SOLDERPASTE_N_BACK ), SILKSCREEN_N_BACK * used to calculate the Z orientation parameter for glNormal3f */ static GLfloat Get3DLayer_Z_Orientation( int aLayer ); static GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer ); void EDA_3D_CANVAS::Redraw( bool finish ) { Loading Loading @@ -163,7 +163,7 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List() Draw3D_Via( (SEGVIA*) track ); else { int layer = track->GetLayer(); LAYER_NUM layer = track->GetLayer(); if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) ) Draw3D_Track( track ); Loading @@ -174,7 +174,7 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List() { for( int ii = 0; ii < pcb->GetAreaCount(); ii++ ) { int layer = pcb->GetArea( ii )->GetLayer(); LAYER_NUM layer = pcb->GetArea( ii )->GetLayer(); if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) ) Draw3D_Zone( pcb->GetArea( ii ) ); Loading Loading @@ -236,8 +236,8 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List() */ void EDA_3D_CANVAS::Draw3D_Zone( ZONE_CONTAINER* aZone ) { int layer = aZone->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); LAYER_NUM layer = aZone->GetLayer(); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer ); int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); if( layer == LAST_COPPER_LAYER ) Loading Loading @@ -326,8 +326,8 @@ void EDA_3D_CANVAS::Draw3D_Zone( ZONE_CONTAINER* aZone ) void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM ) { double zpos = 0.0; int gridcolor = DARKGRAY; // Color of grid lines int gridcolor_marker = LIGHTGRAY; // Color of grid lines every 5 lines EDA_COLOR_T gridcolor = DARKGRAY; // Color of grid lines EDA_COLOR_T gridcolor_marker = LIGHTGRAY; // Color of grid lines every 5 lines double scale = g_Parm_3D_Visu.m_BiuTo3Dunits; glNormal3f( 0.0, 0.0, 1.0 ); Loading Loading @@ -456,8 +456,8 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM ) void EDA_3D_CANVAS::Draw3D_Track( TRACK* aTrack ) { int layer = aTrack->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); LAYER_NUM layer = aTrack->GetLayer(); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer ); int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); if( layer == LAST_COPPER_LAYER ) Loading @@ -475,8 +475,8 @@ void EDA_3D_CANVAS::Draw3D_Track( TRACK* aTrack ) void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) { int layer, top_layer, bottom_layer; int color; LAYER_NUM layer, top_layer, bottom_layer; EDA_COLOR_T color; double biu_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits ; int outer_radius = via->GetWidth() / 2; Loading @@ -486,7 +486,7 @@ void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) via->ReturnLayerPair( &top_layer, &bottom_layer ); // Drawing horizontal thick rings: for( layer = bottom_layer; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) for( layer = bottom_layer; layer < g_Parm_3D_Visu.m_CopperLayersCount; ++layer ) { int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); Loading Loading @@ -530,15 +530,15 @@ void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment ) { int layer = segment->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); LAYER_NUM layer = segment->GetLayer(); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer ); int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer ); SetGLColor( color ); if( layer == EDGE_N ) { for( layer = 0; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) for( layer = FIRST_LAYER; layer < g_Parm_3D_Visu.m_CopperLayersCount; ++layer ) { glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU(layer); Loading Loading @@ -624,8 +624,8 @@ static void Draw3dTextSegm( int x0, int y0, int xf, int yf ) void EDA_3D_CANVAS::Draw3D_DrawText( TEXTE_PCB* text ) { int layer = text->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); LAYER_NUM layer = text->GetLayer(); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer ); SetGLColor( color ); s_Text3DZPos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); Loading Loading @@ -754,7 +754,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( m_Layer ) == false ) return; int color = g_ColorsSettings.GetLayerColor( m_Layer ); EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( m_Layer ); SetGLColor( color ); // for outline shape = S_POLYGON: Loading Loading @@ -790,7 +790,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) if( m_Layer == EDGE_N ) { for( int layer = 0; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) for( LAYER_NUM layer = FIRST_LAYER; layer < g_Parm_3D_Visu.m_CopperLayersCount; ++layer ) { glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); Loading Loading @@ -948,7 +948,7 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) switch( GetShape() ) { case PAD_CIRCLE: for( int layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; layer++ ) for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) { if( layer && (layer == nlmax) ) layer = LAYER_N_FRONT; Loading Loading @@ -998,7 +998,6 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) polyPadShape.insert( polyPadShape.end(), holecornersBuffer.begin(), holecornersBuffer.end() ); } break; case PAD_RECT: Loading @@ -1007,7 +1006,6 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) wxPoint coord[5]; BuildPadPolygon( coord, wxSize(0,0), m_Orient ); for( int ii = 0; ii < 4; ii ++ ) { CPolyPt pt( coord[ii].x + shape_pos.x, coord[ii].y+ shape_pos.y ); polyPadShape.push_back( pt ); Loading @@ -1027,7 +1025,7 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) if( polyPadShape.size() ) { for( int layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; layer++ ) for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) { if( layer && (layer == nlmax) ) layer = LAYER_N_FRONT; Loading Loading @@ -1061,9 +1059,9 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) } bool Is3DLayerEnabled( int aLayer ) bool Is3DLayerEnabled( LAYER_NUM aLayer ) { int flg = -1; int flg; // see if layer needs to be shown // check the flags Loading @@ -1084,18 +1082,18 @@ bool Is3DLayerEnabled( int aLayer ) case ECO2_N: flg = g_Parm_3D_Visu.FL_ECO2; break; } default: // the layer was not a layer with a flag, so show it if( flg < 0 ) return true; } // if the layer has a flag, return the flag return g_Parm_3D_Visu.m_DrawFlags[flg]; } GLfloat Get3DLayer_Z_Orientation( int aLayer ) GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer ) { double nZ; Loading
3d-viewer/3d_draw_basic_functions.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -122,10 +122,10 @@ static void Draw3D_VerticalPolygonalCylinder( const std::vector<CPolyPt>& aPolys } void SetGLColor( int color ) void SetGLColor( EDA_COLOR_T color ) { double red, green, blue; StructColors colordata = ColorRefs[color & MASKCOLOR]; const StructColors &colordata = g_ColorRefs[ColorGetBase( color )]; red = colordata.m_Red / 255.0; blue = colordata.m_Blue / 255.0; Loading
3d-viewer/3d_read_mesh.cpp +31 −502 Original line number Diff line number Diff line Loading @@ -35,20 +35,35 @@ #include <3d_viewer.h> #include <info3d_visu.h> #include "3d_struct.h" #include "modelparsers.h" // Imported function: extern void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits ); // separator chars static const char* sep_chars = " \t\n\r"; S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster, const wxString aExtension ) { if ( aExtension == wxT( "x3d" ) ) { return new X3D_MODEL_PARSER( aMaster ); } else if ( aExtension == wxT( "wrl" ) ) { return new VRML_MODEL_PARSER( aMaster ); } else { return NULL; } } int S3D_MASTER::ReadData() { char line[1024], * text; wxFileName fn; wxString FullFilename; FILE* file; int LineNum = 0; if( m_Shape3DName.IsEmpty() ) { Loading @@ -56,6 +71,7 @@ int S3D_MASTER::ReadData() } wxString shape3DNname = m_Shape3DName; #ifdef __WINDOWS__ shape3DNname.Replace( wxT( "/" ), wxT( "\\" ) ); #else Loading @@ -65,6 +81,7 @@ int S3D_MASTER::ReadData() if( wxFileName::FileExists( shape3DNname ) ) { FullFilename = shape3DNname; fn.Assign( FullFilename ); } else { Loading @@ -79,509 +96,21 @@ int S3D_MASTER::ReadData() } } file = wxFopen( FullFilename, wxT( "rt" ) ); if( file == NULL ) { return -1; } // Switch the locale to standard C (needed to print floating point numbers like 1.3) SetLocaleTo_C_standard(); while( GetLine( file, line, &LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( stricmp( text, "DEF" ) == 0 || stricmp( text, "Group" ) == 0) { while( GetLine( file, line, &LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( text == NULL ) continue; if( *text == '}' ) break; if( stricmp( text, "children" ) == 0 ) { ReadChildren( file, &LineNum ); } } } } fclose( file ); SetLocaleTo_Default(); // revert to the current locale return 0; } int S3D_MASTER::ReadMaterial( FILE* file, int* LineNum ) { char line[512], * text, * command; wxString mat_name; S3D_MATERIAL* material = NULL; command = strtok( NULL, sep_chars ); text = strtok( NULL, sep_chars ); mat_name = FROM_UTF8( text ); if( stricmp( command, "USE" ) == 0 ) { for( material = m_Materials; material; material = material->Next() ) { if( material->m_Name == mat_name ) { material->SetMaterial(); return 1; } } D( printf( "ReadMaterial error: material not found\n" ) ); return 0; } if( stricmp( command, "DEF" ) == 0 || stricmp( command, "Material") == 0) { material = new S3D_MATERIAL( this, mat_name ); Insert( material ); while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( text == NULL ) continue; wxString extension = fn.GetExt(); S3D_MODEL_PARSER* parser = S3D_MODEL_PARSER::Create( this, extension ); if( text[0] == '}' ) if( parser ) { material->SetMaterial(); parser->Load( FullFilename ); delete parser; return 0; } if( stricmp( text, "diffuseColor" ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_DiffuseColor.x = atof( text ); text = strtok( NULL, sep_chars ); material->m_DiffuseColor.y = atof( text ); text = strtok( NULL, sep_chars ); material->m_DiffuseColor.z = atof( text ); } else if( stricmp( text, "emissiveColor" ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_EmissiveColor.x = atof( text ); text = strtok( NULL, sep_chars ); material->m_EmissiveColor.y = atof( text ); text = strtok( NULL, sep_chars ); material->m_EmissiveColor.z = atof( text ); } else if( strnicmp( text, "specularColor", 13 ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_SpecularColor.x = atof( text ); text = strtok( NULL, sep_chars ); material->m_SpecularColor.y = atof( text ); text = strtok( NULL, sep_chars ); material->m_SpecularColor.z = atof( text ); } else if( strnicmp( text, "ambientIntensity", 16 ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_AmbientIntensity = atof( text ); } else if( strnicmp( text, "transparency", 12 ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_Transparency = atof( text ); } else if( strnicmp( text, "shininess", 9 ) == 0 ) { text = strtok( NULL, sep_chars ); material->m_Shininess = atof( text ); } } } return -1; } int S3D_MASTER::ReadChildren( FILE* file, int* LineNum ) { char line[1024], * text; while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( *text == ']' ) return 0; if( *text == ',' ) continue; if( stricmp( text, "Shape" ) == 0 ) { ReadShape( file, LineNum ); } else { D( printf( "ReadChildren error line %d <%s> \n", *LineNum, text ) ); break; } } return 1; } int S3D_MASTER::ReadShape( FILE* file, int* LineNum ) { char line[1024], * text; int err = 1; while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( *text == '}' ) { err = 0; break; } if( stricmp( text, "appearance" ) == 0 ) { ReadAppearance( file, LineNum ); } else if( stricmp( text, "geometry" ) == 0 ) { ReadGeometry( file, LineNum ); } else { D( printf( "ReadShape error line %d <%s> \n", *LineNum, text ) ); break; } } return err; } int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum ) { char line[1024], * text; int err = 1; while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, sep_chars ); if( *text == '}' ) { err = 0; break; } if( stricmp( text, "material" ) == 0 ) { ReadMaterial( file, LineNum ); } else { D( printf( "ReadAppearance error line %d <%s> \n", *LineNum, text ) ); break; } } return err; } #define BUFSIZE 2000 /** * 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 ) { unsigned int ii = 0, jj = 0; char* text; bool HasData = false; bool StartData = false; bool EndNode = false; char string_num[512]; text = text_buffer; while( !EndNode ) { if( *text == 0 ) // Needs data ! { text = text_buffer; GetLine( file, text_buffer, LineNum, 512 ); } while( !EndNode && *text ) { switch( *text ) { case '[': StartData = true; jj = 0; string_num[jj] = 0; break; case '}': EndNode = true; break; case ']': case '\t': case ' ': case ',': jj = 0; if( !StartData || !HasData ) break; aList.push_back( atof( string_num ) ); string_num[jj] = 0; ii++; HasData = false; if( *text == ']' ) { StartData = false; } break; default: if( !StartData ) break; if( jj >= sizeof( string_num ) ) break; string_num[jj] = *text; jj++; string_num[jj] = 0; HasData = true; break; } text++; } } } int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) { char line[1024], buffer[1024], * text; int err = 1; std::vector< double > points; std::vector< double > list; double vrmlunits_to_3Dunits = g_Parm_3D_Visu.m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB; while( GetLine( file, line, LineNum, 512 ) ) { strcpy( buffer, line ); text = strtok( buffer, sep_chars ); if( *text == '}' ) { err = 0; break; } if( stricmp( text, "normalPerVertex" ) == 0 ) { text = strtok( NULL, " ,\t\n\r" ); if( stricmp( text, "true" ) == 0 ) { } else { } continue; } if( stricmp( text, "colorPerVertex" ) == 0 ) { text = strtok( NULL, " ,\t\n\r" ); if( stricmp( text, "true" ) == 0 ) { } else { } continue; } if( stricmp( text, "normal" ) == 0 ) { ReadCoordsList( file, line, list, LineNum ); list.clear(); continue; wxLogDebug( wxT( "Unknown file type <%s>" ), GetChars( extension ) ); } if( stricmp( text, "normalIndex" ) == 0 ) { while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " ,\t\n\r" ); while( text ) { if( *text == ']' ) break; text = strtok( NULL, " ,\t\n\r" ); } if( text && (*text == ']') ) break; } continue; } if( stricmp( text, "color" ) == 0 ) { ReadCoordsList( file, line, list, LineNum ); list.clear(); continue; } if( stricmp( text, "solid" ) == 0 ) { // ignore solid continue; } if( stricmp( text, "colorIndex" ) == 0 ) { while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " ,\t\n\r" ); while( text ) { if( *text == ']' ) break; text = strtok( NULL, " ,\t\n\r" ); } if( text && (*text == ']') ) break; } continue; } if( stricmp( text, "coord" ) == 0 ) { ReadCoordsList( file, line, points, LineNum ); } else if( stricmp( text, "coordIndex" ) == 0 ) { if( points.size() < 3 || points.size() % 3 != 0 ) { wxLogError( wxT( "3D geometry read error <%s> at line %d." ), GetChars( FROM_UTF8( text ) ), *LineNum ); err = 1; break; } std::vector< int > coordIndex; std::vector< S3D_VERTEX > vertices; while( GetLine( file, line, LineNum, 512 ) ) { int jj; text = strtok( line, " ,\t\n\r" ); while( text ) { if( *text == ']' ) break; jj = atoi( text ); if( jj < 0 ) { for( jj = 0; jj < (int) coordIndex.size(); jj++ ) { int kk = coordIndex[jj] * 3; if( (kk < 0) || ((kk + 3) > (int)points.size()) ) { wxLogError( wxT( "3D geometry index read error <%s> at line %d." ), GetChars( FROM_UTF8( text ) ), *LineNum ); err = 1; break; } S3D_VERTEX vertex; vertex.x = points[kk]; vertex.y = points[kk + 1]; vertex.z = points[kk + 2]; vertices.push_back( vertex ); } Set_Object_Coords( vertices ); Set_Object_Data( vertices, vrmlunits_to_3Dunits ); vertices.clear(); coordIndex.clear(); } else { coordIndex.push_back( jj ); } text = strtok( NULL, " ,\t\n\r" ); } if( text && (*text == ']') ) break; } } else { wxLogError( wxT( "3D geometry read error <%s> at line %d." ), GetChars( FROM_UTF8( text ) ), *LineNum ); err = 1; break; } } return err; return -1; } Loading
3d-viewer/3d_struct.h +0 −20 Original line number Diff line number Diff line Loading @@ -115,26 +115,6 @@ public: void Copy( S3D_MASTER* pattern ); int ReadData(); /** * Function ReadMaterial * read the description of a 3D material definition in the form: * DEF yellow material Material ( * DiffuseColor 1.00000 1.00000 0.00000e 0 * EmissiveColor 0.00000e 0 0.00000e 0 0.00000e 0 * SpecularColor 1.00000 1.00000 1.00000 * AmbientIntensity 1.00000 * Transparency 0.00000e 0 * Shininess 1.00000 *) * Or type: * USE yellow material */ int ReadMaterial( FILE* file, int* LineNum ); int ReadChildren( FILE* file, int* LineNum ); int ReadShape( FILE* file, int* LineNum ); int ReadAppearance( FILE* file, int* LineNum ); int ReadGeometry( FILE* file, int* LineNum ); void Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices ); #if defined(DEBUG) Loading
3d-viewer/3d_toolbar.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -105,16 +105,16 @@ void EDA_3D_FRAME::ReCreateHToolbar() m_HToolBar->AddSeparator(); m_HToolBar->AddTool( ID_MOVE3D_LEFT, wxEmptyString, KiBitmap( left_xpm ), _( "Move left <-" ) ); _( "Move left" ) ); m_HToolBar->AddTool( ID_MOVE3D_RIGHT, wxEmptyString, KiBitmap( right_xpm ), _( "Move right ->" ) ); _( "Move right" ) ); m_HToolBar->AddTool( ID_MOVE3D_UP, wxEmptyString, KiBitmap( up_xpm ), _( "Move up ^" ) ); _( "Move up" ) ); m_HToolBar->AddTool( ID_MOVE3D_DOWN, wxEmptyString, KiBitmap( down_xpm ), _( "Move down v" ) ); _( "Move down" ) ); m_HToolBar->AddSeparator(); m_HToolBar->AddTool( ID_ORTHO, wxEmptyString, KiBitmap( ortho_xpm ), Loading