diff --git a/3d-viewer/3d_aux.cpp b/3d-viewer/3d_aux.cpp index 4e7af2f5ac..b3b667f92a 100644 --- a/3d-viewer/3d_aux.cpp +++ b/3d-viewer/3d_aux.cpp @@ -26,16 +26,17 @@ void S3D_MASTER::Set_Object_Coords( S3D_Vertex* coord, int nbcoord ) coord[ii].x *= m_MatScale.x; coord[ii].y *= m_MatScale.y; coord[ii].z *= m_MatScale.z; + /* adjust rotation */ if( m_MatRotation.x ) - RotatePoint( &coord[ii].y, &coord[ii].z, - (int) (m_MatRotation.x * 10) ); + RotatePoint( &coord[ii].y, &coord[ii].z, (int) (m_MatRotation.x * 10) ); + if( m_MatRotation.y ) - RotatePoint( &coord[ii].z, &coord[ii].x, - (int) (m_MatRotation.y * 10) ); + RotatePoint( &coord[ii].z, &coord[ii].x, (int) (m_MatRotation.y * 10) ); + if( m_MatRotation.z ) - RotatePoint( &coord[ii].x, &coord[ii].y, - (int) (m_MatRotation.z * 10) ); + RotatePoint( &coord[ii].x, &coord[ii].y, (int) (m_MatRotation.z * 10) ); + /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ #define SCALE_3D_CONV (PCB_INTERNAL_UNIT / UNITS3D_TO_UNITSPCB) coord[ii].x += m_MatPosition.x * SCALE_3D_CONV; @@ -68,6 +69,7 @@ void Set_Object_Data( const S3D_Vertex* coord, int nbcoord ) nz = ax * by - ay * bx; r = sqrt( nx * nx + ny * ny + nz * nz ); + if( r >= 0.000001 ) /* avoid division by zero */ { nx /= r; ny /= r; nz /= r; @@ -102,7 +104,7 @@ void Set_Object_Data( const S3D_Vertex* coord, int nbcoord ) } -GLuint Pcb3D_GLCanvas::DisplayCubeforTest() +GLuint EDA_3D_CANVAS::DisplayCubeforTest() { GLuint gllist = glGenLists( 1 ); @@ -151,18 +153,19 @@ Info_3D_Visu::Info_3D_Visu() m_Beginx = m_Beginy = 0.0; /* position of mouse */ m_Zoom = 1.0; /* field of view in degrees */ trackball( m_Quat, 0.0, 0.0, 0.0, 0.0 ); + for( ii = 0; ii < 4; ii++ ) m_Rot[ii] = 0.0; m_Layers = 1; m_BoardSettings = NULL; - m_Draw3DAxis = TRUE; - m_Draw3DModule = TRUE; - m_Draw3DZone = TRUE; - m_Draw3DComments = TRUE; - m_Draw3DDrawings = TRUE; - m_Draw3DEco1 = TRUE; - m_Draw3DEco2 = TRUE; + m_Draw3DAxis = true; + m_Draw3DModule = true; + m_Draw3DZone = true; + m_Draw3DComments = true; + m_Draw3DDrawings = true; + m_Draw3DEco1 = true; + m_Draw3DEco2 = true; } @@ -187,15 +190,12 @@ WinEDA_VertexCtrl::WinEDA_VertexCtrl( wxWindow* parent, const wxString& title, text = _( "Vertex " ); else text = title; + text += ReturnUnitSymbol( units ); - msgtitle = new wxStaticText( parent, -1, text, wxDefaultPosition, - wxSize( -1, -1 ), 0 ); + msgtitle = new wxStaticText( parent, -1, text, wxDefaultPosition, wxSize( -1, -1 ), 0 ); - BoxSizer->Add( - msgtitle, - wxGROW | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM | - wxADJUST_MINSIZE ); + BoxSizer->Add( msgtitle, wxGROW | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM | wxADJUST_MINSIZE ); wxFlexGridSizer* GridSizer = new wxFlexGridSizer( 3, 2, 0, 0 ); diff --git a/3d-viewer/3d_canvas.cpp b/3d-viewer/3d_canvas.cpp index 81d596c22d..36a40b8c4b 100644 --- a/3d-viewer/3d_canvas.cpp +++ b/3d-viewer/3d_canvas.cpp @@ -50,27 +50,27 @@ void CheckGLError() /* - * Pcb3D_GLCanvas implementation + * EDA_3D_CANVAS implementation */ -BEGIN_EVENT_TABLE( Pcb3D_GLCanvas, wxGLCanvas ) - EVT_PAINT( Pcb3D_GLCanvas::OnPaint ) +BEGIN_EVENT_TABLE( EDA_3D_CANVAS, wxGLCanvas ) + EVT_PAINT( EDA_3D_CANVAS::OnPaint ) // key event: - EVT_CHAR( Pcb3D_GLCanvas::OnChar ) + EVT_CHAR( EDA_3D_CANVAS::OnChar ) // mouse events - EVT_RIGHT_DOWN( Pcb3D_GLCanvas::OnRightClick ) - EVT_MOUSEWHEEL( Pcb3D_GLCanvas::OnMouseWheel ) - EVT_MOTION( Pcb3D_GLCanvas::OnMouseMove ) + EVT_RIGHT_DOWN( EDA_3D_CANVAS::OnRightClick ) + EVT_MOUSEWHEEL( EDA_3D_CANVAS::OnMouseWheel ) + EVT_MOTION( EDA_3D_CANVAS::OnMouseMove ) // other events - EVT_ERASE_BACKGROUND( Pcb3D_GLCanvas::OnEraseBackground ) - EVT_MENU_RANGE( ID_POPUP_3D_VIEW_START, ID_POPUP_3D_VIEW_END, Pcb3D_GLCanvas::OnPopUpMenu ) + EVT_ERASE_BACKGROUND( EDA_3D_CANVAS::OnEraseBackground ) + EVT_MENU_RANGE( ID_POPUP_3D_VIEW_START, ID_POPUP_3D_VIEW_END, EDA_3D_CANVAS::OnPopUpMenu ) END_EVENT_TABLE() -Pcb3D_GLCanvas::Pcb3D_GLCanvas( EDA_3D_FRAME* parent, int* attribList ) : +EDA_3D_CANVAS::EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList ) : #if wxCHECK_VERSION( 2, 7, 0 ) wxGLCanvas( parent, -1, attribList, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE ) @@ -94,7 +94,7 @@ Pcb3D_GLCanvas::Pcb3D_GLCanvas( EDA_3D_FRAME* parent, int* attribList ) : } -Pcb3D_GLCanvas::~Pcb3D_GLCanvas() +EDA_3D_CANVAS::~EDA_3D_CANVAS() { ClearLists(); m_init = false; @@ -105,7 +105,7 @@ Pcb3D_GLCanvas::~Pcb3D_GLCanvas() } -void Pcb3D_GLCanvas::ClearLists() +void EDA_3D_CANVAS::ClearLists() { if( m_gllist > 0 ) glDeleteLists( m_gllist, 1 ); @@ -114,14 +114,14 @@ void Pcb3D_GLCanvas::ClearLists() } -void Pcb3D_GLCanvas::OnChar( wxKeyEvent& event ) +void EDA_3D_CANVAS::OnChar( wxKeyEvent& event ) { SetView3D( event.GetKeyCode() ); event.Skip(); } -void Pcb3D_GLCanvas::SetView3D( int keycode ) +void EDA_3D_CANVAS::SetView3D( int keycode ) { int ii; double delta_move = 0.7 * g_Parm_3D_Visu.m_Zoom; @@ -237,7 +237,7 @@ void Pcb3D_GLCanvas::SetView3D( int keycode ) } -void Pcb3D_GLCanvas::OnMouseWheel( wxMouseEvent& event ) +void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event ) { wxSize size( GetClientSize() ); @@ -288,7 +288,7 @@ void Pcb3D_GLCanvas::OnMouseWheel( wxMouseEvent& event ) } -void Pcb3D_GLCanvas::OnMouseMove( wxMouseEvent& event ) +void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event ) { wxSize size( GetClientSize() ); double spin_quat[4]; @@ -331,7 +331,7 @@ void Pcb3D_GLCanvas::OnMouseMove( wxMouseEvent& event ) /* Construct and display a popup menu when the right button is clicked. */ -void Pcb3D_GLCanvas::OnRightClick( wxMouseEvent& event ) +void EDA_3D_CANVAS::OnRightClick( wxMouseEvent& event ) { wxPoint pos; wxMenu PopUpMenu; @@ -406,7 +406,7 @@ void Pcb3D_GLCanvas::OnRightClick( wxMouseEvent& event ) } -void Pcb3D_GLCanvas::OnPopUpMenu( wxCommandEvent& event ) +void EDA_3D_CANVAS::OnPopUpMenu( wxCommandEvent& event ) { int key = 0; @@ -468,7 +468,7 @@ void Pcb3D_GLCanvas::OnPopUpMenu( wxCommandEvent& event ) } -void Pcb3D_GLCanvas::DisplayStatus() +void EDA_3D_CANVAS::DisplayStatus() { wxString msg; @@ -483,7 +483,7 @@ void Pcb3D_GLCanvas::DisplayStatus() } -void Pcb3D_GLCanvas::OnPaint( wxPaintEvent& event ) +void EDA_3D_CANVAS::OnPaint( wxPaintEvent& event ) { wxPaintDC dc( this ); @@ -492,14 +492,14 @@ void Pcb3D_GLCanvas::OnPaint( wxPaintEvent& event ) } -void Pcb3D_GLCanvas::OnEraseBackground( wxEraseEvent& event ) +void EDA_3D_CANVAS::OnEraseBackground( wxEraseEvent& event ) { // Do nothing, to avoid flashing. } /* Initialize broad parameters for OpenGL */ -void Pcb3D_GLCanvas::InitGL() +void EDA_3D_CANVAS::InitGL() { wxSize size = GetClientSize(); @@ -568,7 +568,7 @@ void Pcb3D_GLCanvas::InitGL() g_Parm_3D_Visu.m_BgColor.m_Blue, 1 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - // Setup light souces: + // Setup light sources: SetLights(); CheckGLError(); @@ -576,7 +576,7 @@ void Pcb3D_GLCanvas::InitGL() /* Initialize OpenGL light sources. */ -void Pcb3D_GLCanvas::SetLights() +void EDA_3D_CANVAS::SetLights() { double light; GLfloat light_color[4]; @@ -604,7 +604,7 @@ void Pcb3D_GLCanvas::SetLights() /* Create a Screenshot of the current 3D view. * Output file format is png or jpeg, or image is copied to the clipboard */ -void Pcb3D_GLCanvas::TakeScreenshot( wxCommandEvent& event ) +void EDA_3D_CANVAS::TakeScreenshot( wxCommandEvent& event ) { wxFileName fn( m_Parent->m_Parent->GetScreen()->GetFileName() ); wxString FullFileName; diff --git a/3d-viewer/3d_draw.cpp b/3d-viewer/3d_draw.cpp index df70f24b43..87c07cb7a8 100644 --- a/3d-viewer/3d_draw.cpp +++ b/3d-viewer/3d_draw.cpp @@ -52,7 +52,7 @@ static void CALLBACK tessErrorCB( GLenum errorCode ); static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data ); static void CALLBACK tesswxPoint2Vertex( const GLvoid* data ); -void Pcb3D_GLCanvas::Redraw( bool finish ) +void EDA_3D_CANVAS::Redraw( bool finish ) { /* SwapBuffer requires the window to be shown before calling */ if( !IsShown() ) @@ -110,7 +110,7 @@ void Pcb3D_GLCanvas::Redraw( bool finish ) /* Create the draw list items */ -GLuint Pcb3D_GLCanvas::CreateDrawGL_List() +GLuint EDA_3D_CANVAS::CreateDrawGL_List() { PCB_BASE_FRAME* pcbframe = m_Parent->m_Parent; BOARD* pcb = pcbframe->GetBoard(); @@ -219,8 +219,7 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() glEnd(); #endif - /* move the board in order to draw it with its center at 0,0 3D - * coordinates */ + /* move the board in order to draw it with its center at 0,0 3D coordinates */ glTranslatef( -g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BoardScale, -g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BoardScale, 0.0F ); @@ -248,6 +247,7 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() for( ii = 0; ii < pcb->GetAreaCount(); ii++ ) { ZONE_CONTAINER* curr_zone = pcb->GetArea( ii ); + if( curr_zone->m_FillMode == 0 ) { // solid polygons only are used to fill areas @@ -295,6 +295,7 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() for( int ic = 1; ic <= imax; ic++ ) { CPolyPt* endcorner = &zone->m_FilledPolysList[ic]; + if( begincorner->utility == 0 ) { // Draw only basic outlines, not extra segments @@ -304,6 +305,7 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() dummysegment.m_End.y = endcorner->y; Draw3D_Track( &dummysegment ); } + if( (endcorner->end_contour) || (ic == imax) ) { // the last corner of a filled area is found: draw it @@ -368,7 +370,7 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() } -void Pcb3D_GLCanvas::Draw3D_Track( TRACK* track ) +void EDA_3D_CANVAS::Draw3D_Track( TRACK* track ) { double zpos; int layer = track->GetLayer(); @@ -402,7 +404,7 @@ void Pcb3D_GLCanvas::Draw3D_Track( TRACK* track ) * draw all solid polygons used as filles areas in a zone * @param aZone = the zone to draw */ -void Pcb3D_GLCanvas::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone ) +void EDA_3D_CANVAS::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone ) { double zpos; int layer = aZone->GetLayer(); @@ -435,6 +437,7 @@ void Pcb3D_GLCanvas::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone ) // Draw solid areas contained in this zone int StartContour = 1; + for( unsigned ii = 0; ii < aZone->m_FilledPolysList.size(); ii++ ) { if( StartContour == 1 ) @@ -443,6 +446,7 @@ void Pcb3D_GLCanvas::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone ) gluTessBeginContour( tess ); StartContour = 0; } + v_data[0] = aZone->m_FilledPolysList[ii].x * g_Parm_3D_Visu.m_BoardScale; v_data[1] = -aZone->m_FilledPolysList[ii].y * g_Parm_3D_Visu.m_BoardScale; gluTessVertex( tess, v_data, &aZone->m_FilledPolysList[ii] ); @@ -461,7 +465,7 @@ void Pcb3D_GLCanvas::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone ) /* 3D drawing for a VIA (cylinder + filled circles) */ -void Pcb3D_GLCanvas::Draw3D_Via( SEGVIA* via ) +void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) { double x, y, r, hole; int layer, top_layer, bottom_layer; @@ -480,6 +484,7 @@ void Pcb3D_GLCanvas::Draw3D_Via( SEGVIA* via ) for( layer = bottom_layer; layer < g_Parm_3D_Visu.m_Layers; layer++ ) { zpos = g_Parm_3D_Visu.m_LayerZcoord[layer]; + if( layer < g_Parm_3D_Visu.m_Layers - 1 ) { if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) == false ) @@ -519,7 +524,7 @@ void Pcb3D_GLCanvas::Draw3D_Via( SEGVIA* via ) } -void Pcb3D_GLCanvas::Draw3D_DrawSegment( DRAWSEGMENT* segment ) +void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment ) { double x, y, xf, yf; double zpos, w; @@ -608,7 +613,7 @@ static void Draw3dTextSegm( int x0, int y0, int xf, int yf ) } -void Pcb3D_GLCanvas::Draw3D_DrawText( TEXTE_PCB* text ) +void EDA_3D_CANVAS::Draw3D_DrawText( TEXTE_PCB* text ) { int layer = text->GetLayer(); @@ -661,7 +666,7 @@ void Pcb3D_GLCanvas::Draw3D_DrawText( TEXTE_PCB* text ) } -void MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) +void MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) { D_PAD* pad = m_Pads; @@ -676,7 +681,7 @@ void MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) /* Draw module shape: 3D shape if exists (or module outlines if not exists) */ S3D_MASTER* Struct3D = m_3D_Drawings; - bool As3dShape = FALSE; + bool As3dShape = false; if( g_Parm_3D_Visu.m_Draw3DModule ) { @@ -703,7 +708,7 @@ void MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) { if( !Struct3D->m_Shape3DName.IsEmpty() ) { - As3dShape = TRUE; + As3dShape = true; Struct3D->ReadData(); } } @@ -739,7 +744,7 @@ void MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) } -void EDGE_MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) +void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) { wxString s; int dx, dy; @@ -862,7 +867,7 @@ void EDGE_MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) /* Draw 3D pads. */ -void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) +void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) { int ii, ll, layer, nlmax; int ux0, uy0, @@ -907,8 +912,8 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis nlmax = g_Parm_3D_Visu.m_Layers - 1; - Oncu = (m_layerMask & LAYER_BACK) ? TRUE : FALSE; - Oncmp = (m_layerMask & LAYER_FRONT) ? TRUE : FALSE; + Oncu = (m_layerMask & LAYER_BACK) ? true : false; + Oncmp = (m_layerMask & LAYER_FRONT) ? true : false; Both = Oncu && Oncmp; switch( m_PadShape & 0x7F ) @@ -1364,10 +1369,10 @@ static void Draw3D_CircleSegment( double startx, double starty, double endx, /** * Function Draw3D_Polygon * draw one solid polygon - * @param aCornersList = a std::vector liste of corners, in physical coordinates + * @param aCornersList = a std::vector list of corners, in physical coordinates * @param aZpos = the z position in 3D units */ -void Pcb3D_GLCanvas::Draw3D_Polygon( std::vector& aCornersList, double aZpos ) +void EDA_3D_CANVAS::Draw3D_Polygon( std::vector& aCornersList, double aZpos ) { g_Parm_3D_Visu.m_ActZpos = aZpos; @@ -1407,19 +1412,19 @@ static int Get3DLayerEnable( int act_layer ) { bool enablelayer; - enablelayer = TRUE; + enablelayer = true; if( act_layer == DRAW_N && !g_Parm_3D_Visu.m_Draw3DDrawings ) - enablelayer = FALSE; + enablelayer = false; if( act_layer == COMMENT_N && !g_Parm_3D_Visu.m_Draw3DComments ) - enablelayer = FALSE; + enablelayer = false; if( act_layer == ECO1_N && !g_Parm_3D_Visu.m_Draw3DEco1 ) - enablelayer = FALSE; + enablelayer = false; if( act_layer == ECO2_N && !g_Parm_3D_Visu.m_Draw3DEco2 ) - enablelayer = FALSE; + enablelayer = false; return enablelayer; } diff --git a/3d-viewer/3d_frame.cpp b/3d-viewer/3d_frame.cpp index a1abf7886a..40d091be3b 100644 --- a/3d-viewer/3d_frame.cpp +++ b/3d-viewer/3d_frame.cpp @@ -66,9 +66,9 @@ EDA_3D_FRAME::EDA_3D_FRAME( PCB_BASE_FRAME* parent, const wxString& title, long // ReCreateAuxiliaryToolbar(); ReCreateVToolbar(); - // Make a Pcb3D_GLCanvas + // Make a EDA_3D_CANVAS int attrs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, 0 }; - m_Canvas = new Pcb3D_GLCanvas( this, attrs ); + m_Canvas = new EDA_3D_CANVAS( this, attrs ); m_auimgr.SetManagedWindow( this ); diff --git a/3d-viewer/3d_read_mesh.cpp b/3d-viewer/3d_read_mesh.cpp index c04e9b20a6..cd3d6095e8 100644 --- a/3d-viewer/3d_read_mesh.cpp +++ b/3d-viewer/3d_read_mesh.cpp @@ -24,9 +24,10 @@ int S3D_MASTER::ReadData() return 1; } - if( wxFileName::FileExists( m_Shape3DName ) ) + { FullFilename = m_Shape3DName; + } else { fn = m_Shape3DName; @@ -50,18 +51,23 @@ int S3D_MASTER::ReadData() // 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, " \t\n\r" ); + if( stricmp( text, "DEF" ) == 0 ) { while( GetLine( file, line, &LineNum, 512 ) ) { text = strtok( line, " \t\n\r" ); + if( text == NULL ) continue; + if( *text == '}' ) break; + if( stricmp( text, "children" ) == 0 ) { ReadChildren( file, &LineNum ); @@ -98,6 +104,7 @@ int S3D_MASTER:: ReadMaterial( FILE* file, int* LineNum ) command = strtok( NULL, " \t\n\r" ); text = strtok( NULL, " \t\n\r" ); mat_name = FROM_UTF8( text ); + if( stricmp( command, "USE" ) == 0 ) { for( material = m_Materials; material; material = material->Next() ) @@ -122,13 +129,16 @@ int S3D_MASTER:: ReadMaterial( FILE* file, int* LineNum ) while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " \t\n\r" ); + if( text == NULL ) continue; + if( text[0] == '}' ) { material->SetMaterial(); return 0; } + if( stricmp( text, "diffuseColor" ) == 0 ) { text = strtok( NULL, " \t\n\r" ); @@ -173,6 +183,7 @@ int S3D_MASTER:: ReadMaterial( FILE* file, int* LineNum ) } } } + return -1; } @@ -184,8 +195,10 @@ int S3D_MASTER::ReadChildren( FILE* file, int* LineNum ) while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " \t\n\r" ); + if( *text == ']' ) return 0; + if( *text == ',' ) continue; @@ -212,6 +225,7 @@ int S3D_MASTER::ReadShape( FILE* file, int* LineNum ) while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " \t\n\r" ); + if( *text == '}' ) { err = 0; @@ -245,6 +259,7 @@ int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum ) while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " \t\n\r" ); + if( *text == '}' ) { err = 0; break; @@ -283,18 +298,18 @@ int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum ) * text_buffer contains the first line of this node : * "coord Coordinate { point [" */ -double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, - int* LineNum ) +double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNum ) { double* data_list = NULL; unsigned int ii = 0, jj = 0, nn = BUFSIZE; char* text; - bool HasData = FALSE; - bool StartData = FALSE; - bool EndNode = FALSE; + bool HasData = false; + bool StartData = false; + bool EndNode = false; char string_num[512]; text = text_buffer; + while( !EndNode ) { if( *text == 0 ) // Needs data ! @@ -308,13 +323,13 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, switch( *text ) { case '[': - StartData = TRUE; + StartData = true; jj = 0; string_num[jj] = 0; data_list = (double*) MyZMalloc( nn * sizeof(double) ); break; case '}': - EndNode = TRUE; + EndNode = true; break; case ']': @@ -322,32 +337,38 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, case ' ': case ',': jj = 0; + if( !StartData || !HasData ) break; + data_list[ii] = atof( string_num ); string_num[jj] = 0; ii++; + if( ii >= nn ) { nn *= 2; - data_list = - (double*) realloc( data_list, ( nn * sizeof(double) ) ); + data_list = (double*) realloc( data_list, ( nn * sizeof(double) ) ); } - HasData = FALSE; + + HasData = false; + if( *text == ']' ) { - StartData = FALSE; + StartData = false; } break; default: if( !StartData ) break; + if( jj >= sizeof(string_num) ) break; + string_num[jj] = *text; jj++; string_num[jj] = 0; - HasData = TRUE; + HasData = true; break; } @@ -357,8 +378,10 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, if( data_list ) data_list = (double*) realloc( data_list, ( ii * sizeof(double) ) ); + if( bufsize ) *bufsize = ii; + return data_list; } @@ -375,6 +398,7 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) { strcpy( buffer, line ); text = strtok( buffer, " \t\n\r" ); + if( *text == '}' ) { err = 0; break; @@ -383,7 +407,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) if( stricmp( text, "normalPerVertex" ) == 0 ) { text = strtok( NULL, " ,\t\n\r" ); - if( stricmp( text, "TRUE" ) == 0 ) + + if( stricmp( text, "true" ) == 0 ) { } else @@ -395,7 +420,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) if( stricmp( text, "colorPerVertex" ) == 0 ) { text = strtok( NULL, " ,\t\n\r" ); - if( stricmp( text, "TRUE" ) == 0 ) + + if( stricmp( text, "true" ) == 0 ) { } else @@ -407,8 +433,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) if( stricmp( text, "normal" ) == 0 ) { int coord_number; - double* buf_points = ReadCoordsList( file, line, &coord_number, - LineNum ); + double* buf_points = ReadCoordsList( file, line, &coord_number, LineNum ); + // Do something if needed free( buf_points ); continue; @@ -418,10 +444,12 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) while( GetLine( file, line, LineNum, 512 ) ) { text = strtok( line, " ,\t\n\r" ); + while( text ) { if( *text == ']' ) break; + text = strtok( NULL, " ,\t\n\r" ); } @@ -435,21 +463,24 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) if( stricmp( text, "color" ) == 0 ) { int coord_number; - double* buf_points = ReadCoordsList( file, line, &coord_number, - LineNum ); + double* buf_points = ReadCoordsList( file, line, &coord_number, LineNum ); + // Do something if needed free( buf_points ); 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" ); } @@ -468,20 +499,24 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) else if( stricmp( text, "coordIndex" ) == 0 ) { index = (int*) MyMalloc( nn * sizeof(int) ); - S3D_Vertex* coords = - (S3D_Vertex*) MyMalloc( nn * sizeof(S3D_Vertex) ); + S3D_Vertex* coords = (S3D_Vertex*) MyMalloc( nn * sizeof(S3D_Vertex) ); + while( GetLine( file, line, LineNum, 512 ) ) { int coord_count = 0, jj; text = strtok( line, " ,\t\n\r" ); + while( text ) { if( *text == ']' ) break; + jj = atoi( text ); + if( jj < 0 ) { S3D_Vertex* curr_coord = coords; + for( jj = 0; jj < coord_count; jj++ ) { int kk = index[jj] * 3; @@ -499,6 +534,7 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) { index[coord_count++] = jj; } + text = strtok( NULL, " ,\t\n\r" ); } @@ -523,7 +559,7 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) } -int Struct3D_Shape:: ReadData( FILE* file, int* LineNum ) +int Struct3D_Shape::ReadData( FILE* file, int* LineNum ) { char line[512]; diff --git a/3d-viewer/3d_toolbar.cpp b/3d-viewer/3d_toolbar.cpp index e34782ed6b..33edd260ba 100644 --- a/3d-viewer/3d_toolbar.cpp +++ b/3d-viewer/3d_toolbar.cpp @@ -16,13 +16,13 @@ void EDA_3D_FRAME::ReCreateHToolbar() return; } - - m_HToolBar = new EDA_TOOLBAR( TOOLBAR_MAIN, this, ID_H_TOOLBAR, TRUE ); + m_HToolBar = new EDA_TOOLBAR( TOOLBAR_MAIN, this, ID_H_TOOLBAR, true ); // Set up toolbar m_HToolBar->AddTool( ID_RELOAD3D_BOARD, wxEmptyString, KiBitmap( import3d_xpm ), _( "Reload board" ) ); + #if (defined(__WINDOWS__) || defined(__APPLE__ ) ) // Does not work properly under linux @@ -117,16 +117,13 @@ void EDA_3D_FRAME::ReCreateMenuBar() menuBar->Append( fileMenu, _( "&File" ) ); - fileMenu->Append( ID_MENU_SCREENCOPY_PNG, - _( "Create Image (png format)" ) ); - fileMenu->Append( ID_MENU_SCREENCOPY_JPEG, - _( "Create Image (jpeg format)" ) ); + fileMenu->Append( ID_MENU_SCREENCOPY_PNG, _( "Create Image (png format)" ) ); + fileMenu->Append( ID_MENU_SCREENCOPY_JPEG, _( "Create Image (jpeg format)" ) ); #if (defined(__WINDOWS__) || defined(__APPLE__ ) ) // Does not work properly under linux fileMenu->AppendSeparator(); - fileMenu->Append( ID_TOOL_SCREENCOPY_TOCLIBBOARD, - _( "Copy 3D Image to Clipboard" ) ); + fileMenu->Append( ID_TOOL_SCREENCOPY_TOCLIBBOARD, _( "Copy 3D Image to Clipboard" ) ); #endif fileMenu->AppendSeparator(); fileMenu->Append( wxID_EXIT, _( "&Exit" ) ); diff --git a/3d-viewer/3d_viewer.h b/3d-viewer/3d_viewer.h index d5d5897b64..14a3a9b9c8 100644 --- a/3d-viewer/3d_viewer.h +++ b/3d-viewer/3d_viewer.h @@ -1,7 +1,6 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: 3d_viewer.h -///////////////////////////////////////////////////////////////////////////// - +/** + * @file 3d_viewer.h + */ #ifndef __3D_VIEWER_H__ #define __3D_VIEWER_H__ @@ -86,7 +85,7 @@ enum id_3dview_frm }; -class Pcb3D_GLCanvas; +class EDA_3D_CANVAS; class EDA_3D_FRAME; class Info_3D_Visu; class S3D_Vertex; @@ -129,7 +128,7 @@ public: Info_3D_Visu(); }; -class Pcb3D_GLCanvas : public wxGLCanvas +class EDA_3D_CANVAS : public wxGLCanvas { public: EDA_3D_FRAME* m_Parent; @@ -146,8 +145,8 @@ private: #endif public: - Pcb3D_GLCanvas( EDA_3D_FRAME* parent, int* attribList = 0 ); - ~Pcb3D_GLCanvas(); + EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 ); + ~EDA_3D_CANVAS(); void ClearLists(); @@ -209,7 +208,7 @@ public: PCB_BASE_FRAME* m_Parent; private: wxString m_FrameName; // name used for writing and reading setup. It is "Frame3D" - Pcb3D_GLCanvas* m_Canvas; + EDA_3D_CANVAS* m_Canvas; EDA_TOOLBAR* m_HToolBar; EDA_TOOLBAR* m_VToolBar; int m_InternalUnits; @@ -238,7 +237,7 @@ public: /** * Function ReloadRequest * must be called when reloading data from Pcbnew is needed - * mainly after edition of the board or footprint beeing displayed. + * mainly after edition of the board or footprint being displayed. * mainly for the module editor. */ void ReloadRequest( ) diff --git a/pcbnew/class_edge_mod.h b/pcbnew/class_edge_mod.h index 6d005dd08e..fef1d26685 100644 --- a/pcbnew/class_edge_mod.h +++ b/pcbnew/class_edge_mod.h @@ -1,6 +1,7 @@ -/*******************************************************/ -/* class_edge_module.h : EDGE_MODULE class definition. */ -/*******************************************************/ +/** + * @file class_edge_module.h + * @brief EDGE_MODULE class definition. + */ #ifndef _CLASS_EDGE_MOD_H_ #define _CLASS_EDGE_MOD_H_ @@ -8,13 +9,13 @@ #include "class_drawsegment.h" #include "richio.h" -class Pcb3D_GLCanvas; +class EDA_3D_CANVAS; class EDGE_MODULE : public DRAWSEGMENT { public: - wxPoint m_Start0; // Start point or centre, relative to module origin, orient 0. + wxPoint m_Start0; // Start point or center, relative to module origin, orient 0. wxPoint m_End0; // End point, relative to module origin, orient 0. public: @@ -25,7 +26,7 @@ public: EDGE_MODULE* Next() const { return (EDGE_MODULE*) Pnext; } EDGE_MODULE* Back() const { return (EDGE_MODULE*) Pback; } - void Copy( EDGE_MODULE* source ); // copy structure + void Copy( EDGE_MODULE* source ); // copy structure /** * Function Save @@ -33,17 +34,17 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - bool Save( FILE* aFile ) const; + bool Save( FILE* aFile ) const; - int ReadDescr( LINE_READER* aReader ); + int ReadDescr( LINE_READER* aReader ); - void SetDrawCoord(); + void SetDrawCoord(); /* drawing functions */ - void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, - int aDrawMode, const wxPoint& offset = ZeroOffset ); + void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, + int aDrawMode, const wxPoint& offset = ZeroOffset ); - void Draw3D( Pcb3D_GLCanvas* glcanvas ); + void Draw3D( EDA_3D_CANVAS* glcanvas ); /** * Function DisplayInfo @@ -52,7 +53,7 @@ public: * Is virtual from EDA_ITEM. * @param frame A EDA_DRAW_FRAME in which to print status information. */ - void DisplayInfo( EDA_DRAW_FRAME* frame ); + void DisplayInfo( EDA_DRAW_FRAME* frame ); /** @@ -77,7 +78,7 @@ public: * Function Show * is used to output the object tree, currently for debugging only. * @param nestLevel An aid to prettier tree indenting, and is the level - * of nesting of this object within the overall tree. + * of nesting of this object within the overall tree. * @param os The ostream& to output to. */ virtual void Show( int nestLevel, std::ostream& os ); diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index ab64056c37..f415c87975 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -8,16 +8,11 @@ #define _MODULE_H_ -class Pcb3D_GLCanvas; -class S3D_MASTER; - #include "richio.h" -/************************************/ -/* Modules (footprints) description */ -/* pad are in class_pad.xx */ -/************************************/ +class EDA_3D_CANVAS; +class S3D_MASTER; enum Mod_Attribut /* Attributes used for modules */ @@ -41,13 +36,12 @@ public: wxPoint m_Pos; // Real coord on board DLIST m_Pads; /* Pad list (linked list) */ DLIST m_Drawings; /* Graphic items list (linked list) */ - DLIST m_3D_Drawings; /* First item of the 3D shapes (linked - * list)*/ + DLIST m_3D_Drawings; /* First item of the 3D shapes (linked list)*/ TEXTE_MODULE* m_Reference; // Component reference (U34, R18..) TEXTE_MODULE* m_Value; // Component value (74LS00, 22K..) wxString m_LibRef; /* Name of the module in library (and * the default value when loading a - *module from the library) */ + * module from the library) */ wxString m_AlternateReference; /* Used when m_Reference cannot * be used to identify the * footprint ( after a full @@ -55,28 +49,20 @@ public: int m_Attributs; /* Flag bits ( see Mod_Attribut ) */ int m_Orient; /* orientation in 0.1 degrees */ - int flag; /* Use to trace ratsnest and auto - * routing. */ - int m_ModuleStatus; /* For autoplace: flags (LOCKED, - * AUTOPLACED) */ - EDA_RECT m_BoundaryBox; /* Bounding box : coordinates on board, - * real orientation */ + int flag; /* Use to trace ratsnest and auto routing. */ + int m_ModuleStatus; /* For autoplace: flags (LOCKED, AUTOPLACED) */ + EDA_RECT m_BoundaryBox; // Bounding box : coordinates on board, real orientation. int m_PadNum; // Pad count - int m_AltPadNum; /* Pad with netcode > 0 (active pads) - * count */ + int m_AltPadNum; /* Pad with netcode > 0 (active pads) count */ int m_CntRot90; /* Automatic placement : cost ( 0..10 ) - * for 90 degrees rotation - * (Horiz<->Vertical) */ + * for 90 degrees rotation (Horiz<->Vertical) */ int m_CntRot180; /* Automatic placement : cost ( 0..10 ) - * for 180 degrees rotation - * (UP <->Down) */ - wxSize m_Ext; /* Automatic placement margin around - * the module */ - double m_Surface; // Bounding box area + * for 180 degrees rotation (UP <->Down) */ + wxSize m_Ext; /* Automatic placement margin around the module */ + double m_Surface; // Bounding box area - unsigned long m_Link; /* Temporary variable ( used in - * editions, ...) */ + unsigned long m_Link; /* Temporary variable ( used in editions, ...) */ long m_LastEdit_Time; wxString m_Path; @@ -240,7 +226,7 @@ public: int aDrawMode, const wxPoint& aOffset = ZeroOffset ); - void Draw3D( Pcb3D_GLCanvas* glcanvas ); + void Draw3D( EDA_3D_CANVAS* glcanvas ); void DrawEdgesOnly( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, int draw_mode ); diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index ef5d56d157..023c52c5fa 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -1,17 +1,20 @@ -/**********************************/ -/* class_pad.h : Pads description */ -/**********************************/ +/** + * @file class_pad.h + * @brief Pad object description + */ #ifndef _PAD_H_ #define _PAD_H_ -class Pcb3D_GLCanvas; - #include "pad_shapes.h" #include "PolyLine.h" #include "richio.h" + +class EDA_3D_CANVAS; + + /* Default layers used for pads, according to the pad type. * this is default values only, they can be changed for a given pad */ @@ -35,23 +38,25 @@ class Pcb3D_GLCanvas; class PAD_DRAWINFO { public: - EDA_DRAW_PANEL * m_DrawPanel; // the EDA_DRAW_PANEL used to draw a PAD ; can be null - int m_DrawMode; // the draw mode - int m_Color; // color used to draw the pad shape , from pad layers and - // visible layers - int m_HoleColor; // color used to draw the pad hole - int m_NPHoleColor; // color used to draw a pad Not Plated hole - int m_PadClearance; // clearance value, used to draw the pad area outlines - wxSize m_Mask_margin; // margin, used to draw solder paste when only one layer is shown - bool m_Display_padnum; // true to show pad number - bool m_Display_netname; // true to show net name - bool m_ShowPadFilled; // true to show pad as solid area, false to show pas in sketch mode - bool m_ShowNCMark; // true to show pad not connected mark - bool m_ShowNotPlatedHole; // true when the pad hole in not plated, to draw a specifib pad shape - bool m_IsPrinting; // true to print, false to display on screen. - wxPoint m_Offset; // general draw offset + EDA_DRAW_PANEL* m_DrawPanel; // the EDA_DRAW_PANEL used to draw a PAD ; can be null + int m_DrawMode; // the draw mode + int m_Color; // color used to draw the pad shape , from pad layers and + // visible layers + int m_HoleColor; // color used to draw the pad hole + int m_NPHoleColor; // color used to draw a pad Not Plated hole + int m_PadClearance; // clearance value, used to draw the pad area outlines + wxSize m_Mask_margin; // margin, used to draw solder paste when only one layer is shown + bool m_Display_padnum; // true to show pad number + bool m_Display_netname; // true to show net name + bool m_ShowPadFilled; // true to show pad as solid area, false to show pas in + // sketch mode + bool m_ShowNCMark; // true to show pad not connected mark + bool m_ShowNotPlatedHole; // true when the pad hole in not plated, to draw a specific + // pad shape + bool m_IsPrinting; // true to print, false to display on screen. + wxPoint m_Offset; // general draw offset - PAD_DRAWINFO( ); + PAD_DRAWINFO(); }; @@ -110,7 +115,7 @@ public: static int m_PadSketchModePenSize; // Pen size used to draw pads in sketch mode // (mode used to print pads on silkscreen layer) - int m_LengthDie; // Length net from pad to die on chip + int m_LengthDie; // Length net from pad to die on chip // Local clearance. When null, the module default value is used. // when the module default value is null, the netclass value is used @@ -121,11 +126,11 @@ public: int m_LocalSolderMaskMargin; // Local solder mask margin int m_LocalSolderPasteMargin; // Local solder paste margin absolute value double m_LocalSolderPasteMarginRatio; // Local solder mask margin ratio value of pad size - // The final margin is the sum of these 2 values + // The final margin is the sum of these 2 values private: int m_SubRatsnest; // variable used in rats nest computations - // handle subnet (block) number in ratsnet connection + // handle subnet (block) number in ratsnest connection public: D_PAD( MODULE* parent ); @@ -136,7 +141,6 @@ public: D_PAD* Next() { return (D_PAD*) Pnext; } - /** * Function GetNetname * @return const wxString * , a pointer to the full netname @@ -216,7 +220,7 @@ public: * 2 - if null, the parent footprint value * 1 - if null, the global value */ - int GetSolderMaskMargin(); + int GetSolderMaskMargin(); /** * Function GetSolderPasteMargin @@ -228,10 +232,10 @@ public: * 2 - if null, the parent footprint value * 1 - if null, the global value */ - wxSize GetSolderPasteMargin(); + wxSize GetSolderPasteMargin(); /* Reading and writing data on files */ - int ReadDescr( LINE_READER* aReader ); + int ReadDescr( LINE_READER* aReader ); /** * Function Save @@ -239,27 +243,28 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - bool Save( FILE* aFile ) const; + bool Save( FILE* aFile ) const; /* drawing functions */ - /** Draw a pad: + /** + * Draw a pad: * @param aPanel = the EDA_DRAW_PANEL panel * @param aDC = the current device context * @param aDraw_mode = mode: GR_OR, GR_XOR, GR_AND... * @param aOffset = draw offset */ - void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, - int aDrawMode, const wxPoint& aOffset = ZeroOffset ); + void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, + int aDrawMode, const wxPoint& aOffset = ZeroOffset ); - void Draw3D( Pcb3D_GLCanvas* glcanvas ); + void Draw3D( EDA_3D_CANVAS* glcanvas ); /** * Function DrawShape * basic function to draw a pad. * used by Draw after calculation of parameters (color, ) final orientation ... */ - void DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ); + void DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ); /** * Function BuildPadPolygon @@ -271,7 +276,7 @@ public: * inflate, < 0 deflate * @param aRotation = full rotation of the polygon */ - void BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation ) const; + void BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation ) const; /** * Function BuildSegmentFromOvalShape @@ -288,12 +293,15 @@ public: int BuildSegmentFromOvalShape( wxPoint& aSegStart, wxPoint& aSegEnd, int aRotation ) const; // others - void SetPadName( const wxString& name ); // Change pad name - wxString ReturnStringPadName() const; // Return pad name as string in a wxString - void ReturnStringPadName( wxString& text ) const; // Return pad name as string in a buffer - void ComputeShapeMaxRadius(); // compute radius + void SetPadName( const wxString& name ); // Change pad name - int GetMaxRadius() const; + wxString ReturnStringPadName() const; // Return pad name as string in a wxString + + void ReturnStringPadName( wxString& text ) const; // Return pad name as string in a buffer + + void ComputeShapeMaxRadius(); // compute radius + + int GetMaxRadius() const; const wxPoint ReturnShapePos(); @@ -302,6 +310,7 @@ public: * @return int - the netcode */ int GetSubRatsnest() const { return m_SubRatsnest; } + void SetSubRatsnest( int aSubRatsnest ) { m_SubRatsnest = aSubRatsnest; } @@ -347,7 +356,7 @@ public: * returns the bounding box of this pad * Mainly used to redraw the screen area occupied by the pad */ - EDA_RECT GetBoundingBox() const; + EDA_RECT GetBoundingBox() const; /** * Function Compare @@ -389,7 +398,7 @@ public: * Function Show * is used to output the object tree, currently for debugging only. * @param nestLevel An aid to prettier tree indenting, and is the level - * of nesting of this object within the overall tree. + * of nesting of this object within the overall tree. * @param os The ostream& to output to. */ virtual void Show( int nestLevel, std::ostream& os );