diff --git a/3d-viewer/3d_aux.cpp b/3d-viewer/3d_aux.cpp index c2407f2c8d..8ef9eed657 100644 --- a/3d-viewer/3d_aux.cpp +++ b/3d-viewer/3d_aux.cpp @@ -129,7 +129,7 @@ void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits /* draw polygon/triangle/quad */ for( ii = 0; ii < aVertices.size(); ii++ ) { - glVertex3f( aVertices[ii].x * aBiuTo3DUnits, + glVertex3d( aVertices[ii].x * aBiuTo3DUnits, aVertices[ii].y * aBiuTo3DUnits, aVertices[ii].z * aBiuTo3DUnits ); } diff --git a/3d-viewer/3d_canvas.cpp b/3d-viewer/3d_canvas.cpp index e3828a70bf..df8ad2e694 100644 --- a/3d-viewer/3d_canvas.cpp +++ b/3d-viewer/3d_canvas.cpp @@ -499,8 +499,9 @@ void EDA_3D_CANVAS::InitGL() /* speedups */ glEnable( GL_DITHER ); glShadeModel( GL_SMOOTH ); - glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST ); - glHint( GL_POLYGON_SMOOTH_HINT, GL_FASTEST ); + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE ); + glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); + glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); // can be GL_FASTEST /* blend */ glEnable( GL_BLEND ); diff --git a/3d-viewer/3d_draw.cpp b/3d-viewer/3d_draw.cpp index 4f102a4ffc..be405b1869 100644 --- a/3d-viewer/3d_draw.cpp +++ b/3d-viewer/3d_draw.cpp @@ -154,8 +154,6 @@ GLuint EDA_3D_CANVAS::CreateDrawGL_List() -g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BiuTo3Dunits, 0.0F ); - glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis - // draw tracks and vias : for( TRACK* track = pcb->m_Track; track != NULL; track = track->Next() ) { @@ -453,7 +451,7 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM ) void EDA_3D_CANVAS::Draw3D_Track( TRACK* aTrack ) { - int layer = aTrack->GetLayer(); + int layer = aTrack->GetLayer(); int color = g_ColorsSettings.GetLayerColor( layer ); int thickness = g_Parm_3D_Visu.GetCopperThicknessBIU(); @@ -463,7 +461,7 @@ void EDA_3D_CANVAS::Draw3D_Track( TRACK* aTrack ) int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); SetGLColor( color ); - glNormal3f( 0.0, 0.0, (layer == LAYER_N_BACK) ? -1.0 : 1.0 ); + glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); Draw3D_SolidSegment( aTrack->m_Start, aTrack->m_End, aTrack->m_Width, thickness, zpos, @@ -503,13 +501,11 @@ void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) } SetGLColor( color ); - - if( thickness == 0 ) - glNormal3f( 0.0, 0.0, layer == LAYER_N_BACK ? -1.0 : 1.0 ); + glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); Draw3D_ZaxisCylinder( via->m_Start, (outer_radius + inner_radius)/2, thickness, outer_radius - inner_radius, - zpos - (thickness/2), biu_to_3Dunits ); + zpos, biu_to_3Dunits ); if( layer >= top_layer ) break; } @@ -518,7 +514,7 @@ void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) color = g_ColorsSettings.GetItemColor( VIAS_VISIBLE + via->m_Shape ); SetGLColor( color ); int height = g_Parm_3D_Visu.GetLayerZcoordBIU(top_layer) - - g_Parm_3D_Visu.GetLayerZcoordBIU( bottom_layer ) - thickness; + g_Parm_3D_Visu.GetLayerZcoordBIU( bottom_layer ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU(bottom_layer) + thickness/2; Draw3D_ZaxisCylinder( via->m_Start, inner_radius + thickness/2, height, @@ -538,7 +534,7 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment ) { for( layer = 0; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) { - glNormal3f( 0.0, 0.0, (layer == LAYER_N_BACK) ? -1.0 : 1.0 ); + glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU(layer); switch( segment->GetShape() ) @@ -784,7 +780,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) { for( int layer = 0; layer < g_Parm_3D_Visu.m_CopperLayersCount; layer++ ) { - glNormal3f( 0.0, 0.0, (layer == LAYER_N_BACK) ? -1.0 : 1.0 ); + glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( m_Layer ); @@ -827,7 +823,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) else { int thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( m_Layer ); - glNormal3f( 0.0, 0.0, (m_Layer == LAYER_N_BACK) ? -1.0 : 1.0 ); + glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( m_Layer ) ); int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU(m_Layer); switch( m_Shape ) @@ -970,7 +966,7 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); int ring_radius = (m_Size.x + m_Drill.x) / 4; if( thickness == 0 ) - glNormal3f( 0.0, 0.0, layer == LAYER_N_BACK ? -1.0 : 1.0 ); + glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); Draw3D_ZaxisCylinder(shape_pos, ring_radius, thickness, ( m_Size.x - m_Drill.x) / 2, @@ -1047,7 +1043,7 @@ void D_PAD::Draw3D( EDA_3D_CANVAS* glcanvas ) SetGLColor( color ); if( thickness == 0 ) - glNormal3f( 0.0, 0.0, layer == LAYER_N_BACK ? -1.0 : 1.0 ); + glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( layer ) ); // If not hole: draw a single polygon int zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer ); diff --git a/3d-viewer/3d_draw_basic_functions.cpp b/3d-viewer/3d_draw_basic_functions.cpp index 7aa2831ce9..713fef2aa9 100644 --- a/3d-viewer/3d_draw_basic_functions.cpp +++ b/3d-viewer/3d_draw_basic_functions.cpp @@ -52,6 +52,18 @@ static void CALLBACK tessEndCB(); static void CALLBACK tessErrorCB( GLenum errorCode ); static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data ); +// 2 helper functions to set the current normal vector for gle items +static inline void SetNormalZpos() +{ + glNormal3f( 0.0, 0.0, 1.0 ); +} + +static inline void SetNormalZneg() +{ + glNormal3f( 0.0, 0.0, -1.0 ); +} + + /* Draw3D_VerticalPolygonalCylinder is a helper function. * * draws a "vertical cylinder" having a polygon shape @@ -147,7 +159,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const std::vector& aPolysList, // Set normal to toward positive Z axis, for a solid object only (to draw the top side) if( aThickness ) - glNormal3f( 0.0, 0.0, 1.0 ); + SetNormalZpos(); // gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); @@ -191,7 +203,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const std::vector& aPolysList, g_Parm_3D_Visu.m_CurrentZpos = zpos; v_data[2] = zpos; // Now;, set normal to toward negative Z axis, for the solid object bottom side - glNormal3f( 0.0, 0.0, -1.0 ); + SetNormalZneg(); } gluDeleteTess( tess ); @@ -201,8 +213,6 @@ void Draw3D_SolidHorizontalPolyPolygons( const std::vector& aPolysList, // Build the 3D data : vertical side Draw3D_VerticalPolygonalCylinder( polylist, aThickness, aZpos, false, aBiuTo3DUnits ); - - glNormal3f( 0.0, 0.0, 1.0 ); } @@ -258,7 +268,7 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius, if( aThickness ) { // draw top (front) and bottom (back) horizontal sides (rings) - glNormal3f( 0.0, 0.0, 1.0 ); + SetNormalZpos(); outer_cornerBuffer.insert( outer_cornerBuffer.end(), inner_cornerBuffer.begin(), inner_cornerBuffer.end() ); std::vector polygon; @@ -270,12 +280,12 @@ void Draw3D_ZaxisCylinder( wxPoint aCenterPos, int aRadius, if( aHeight ) { // draw bottom (back) horizontal ring - glNormal3f( 0.0, 0.0, -1.0 ); + SetNormalZneg(); Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits ); } } - glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis + SetNormalZpos(); } @@ -326,18 +336,18 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos, ConvertPolysListWithHolesToOnePolygon( outer_cornerBuffer, polygon ); // draw top (front) horizontal side (ring) - glNormal3f( 0.0, 0.0, 1.0 ); + SetNormalZpos(); Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos + aHeight, 0, aBiuTo3DUnits ); if( aHeight ) { // draw bottom (back) horizontal side (ring) - glNormal3f( 0.0, 0.0, -1.0 ); + SetNormalZneg(); Draw3D_SolidHorizontalPolyPolygons( polygon, aZpos, 0, aBiuTo3DUnits ); } } - glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis + SetNormalZpos(); } @@ -395,7 +405,7 @@ void CALLBACK tessCPolyPt2Vertex( const GLvoid* data ) // cast back to double type const CPolyPt* ptr = (const CPolyPt*) data; - glVertex3f( ptr->x * g_Parm_3D_Visu.m_BiuTo3Dunits, + glVertex3d( ptr->x * g_Parm_3D_Visu.m_BiuTo3Dunits, -ptr->y * g_Parm_3D_Visu.m_BiuTo3Dunits, g_Parm_3D_Visu.m_CurrentZpos ); } diff --git a/pcbnew/controle.cpp b/pcbnew/controle.cpp index a8da80bab7..5d984f12e3 100644 --- a/pcbnew/controle.cpp +++ b/pcbnew/controle.cpp @@ -45,8 +45,8 @@ #include //external functions used here: -extern bool Magnetize( BOARD* m_Pcb, PCB_EDIT_FRAME* frame, - int aCurrentTool, wxSize grid, wxPoint on_grid, wxPoint* curpos ); +extern bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, + wxSize aGridSize, wxPoint on_grid, wxPoint* curpos ); /** @@ -323,11 +323,11 @@ void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH wxPoint curs_pos = pos; - wxSize grid; - grid.x = KiROUND( GetScreen()->GetGridSize().x ); - grid.y = KiROUND( GetScreen()->GetGridSize().y ); + wxSize igridsize; + igridsize.x = KiROUND( gridSize.x ); + igridsize.y = KiROUND( gridSize.y ); - if( Magnetize( m_Pcb, this, GetToolId(), grid, curs_pos, &pos ) ) + if( Magnetize( this, GetToolId(), igridsize, curs_pos, &pos ) ) { GetScreen()->SetCrossHairPosition( pos, false ); } @@ -350,7 +350,7 @@ void PCB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH pos = GetScreen()->GetCrossHairPosition(); GetScreen()->SetCrossHairPosition( oldpos, false ); m_canvas->CrossHairOff( aDC ); - GetScreen()->SetCrossHairPosition( pos, snapToGrid ); + GetScreen()->SetCrossHairPosition( pos, false ); m_canvas->CrossHairOn( aDC ); if( m_canvas->IsMouseCaptured() ) diff --git a/pcbnew/magnetic_tracks_functions.cpp b/pcbnew/magnetic_tracks_functions.cpp index 7db072d242..21cbc0baf8 100644 --- a/pcbnew/magnetic_tracks_functions.cpp +++ b/pcbnew/magnetic_tracks_functions.cpp @@ -28,7 +28,7 @@ * Join returns the point in "res" and "true" if a suitable point was found, * "false" if both lines are parallel or if the length of either segment is zero. */ -static bool Join( wxPoint* res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 ) +static bool Join( wxPoint* aIntersectPoint, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 ) { /* References: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ @@ -61,8 +61,8 @@ static bool Join( wxPoint* res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 ) t = std::min( std::max( t, 0.0 ), 1.0 ); - res->x = KiROUND( a0.x + t * a1.x ); - res->y = KiROUND( a0.y + t * a1.y ); + aIntersectPoint->x = KiROUND( a0.x + t * a1.x ); + aIntersectPoint->y = KiROUND( a0.y + t * a1.y ); return true; } @@ -72,7 +72,7 @@ static bool Join( wxPoint* res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 ) * "Project" finds the projection of a grid point on a track. This is the point * from where we want to draw new orthogonal tracks when starting on a track. */ -bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track ) +bool Project( wxPoint* aNearPos, wxPoint on_grid, const TRACK* track ) { if( track->m_Start == track->m_End ) return false; @@ -85,8 +85,8 @@ bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track ) t /= (double) vec.x * vec.x + (double) vec.y * vec.y; t = std::min( std::max( t, 0.0 ), 1.0 ); - res->x = KiROUND( track->m_Start.x + t * vec.x ); - res->y = KiROUND( track->m_Start.y + t * vec.y ); + aNearPos->x = KiROUND( track->m_Start.x + t * vec.x ); + aNearPos->y = KiROUND( track->m_Start.y + t * vec.y ); return true; } @@ -97,15 +97,14 @@ bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track ) * tests to see if there are any magnetic items within near reach of the given * "curpos". If yes, then curpos is adjusted appropriately according to that * near magnetic item and true is returned. - * @param m_Pcb = the current board * @param frame = the current frame * @param aCurrentTool = the current tool id (from vertical right toolbar) - * @param grid = the grid size - * @param on_grid = TODO + * @param aGridSize = the current grid size + * @param on_grid = the on grid position near initial position ( often on_grid = curpos) * @param curpos The initial position, and what to adjust if a change is needed. * @return bool - true if the position was adjusted magnetically, else false. */ -bool Magnetize( BOARD* m_Pcb, PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize grid, +bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize, wxPoint on_grid, wxPoint* curpos ) { bool doCheckNet = g_MagneticPadOption != capture_always && Drc_On; @@ -113,6 +112,7 @@ bool Magnetize( BOARD* m_Pcb, PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize gr bool doPad = false; bool amMovingVia = false; + BOARD* m_Pcb = frame->GetBoard(); TRACK* currTrack = g_CurrentTrackSegment; BOARD_ITEM* currItem = frame->GetCurItem(); PCB_SCREEN* screen = frame->GetScreen(); @@ -188,10 +188,6 @@ bool Magnetize( BOARD* m_Pcb, PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize gr return true; } } - else - { - //D( printf( "skipping self\n" ); ) - } } if( !currTrack ) @@ -214,16 +210,16 @@ bool Magnetize( BOARD* m_Pcb, PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize gr * In two segment mode, ignore the final segment if it's inside a grid square. */ if( !amMovingVia && currTrack && g_TwoSegmentTrackBuild && currTrack->Back() - && currTrack->m_Start.x - grid.x < currTrack->m_End.x - && currTrack->m_Start.x + grid.x > currTrack->m_End.x - && currTrack->m_Start.y - grid.y < currTrack->m_End.y - && currTrack->m_Start.y + grid.y > currTrack->m_End.y ) + && currTrack->m_Start.x - aGridSize.x < currTrack->m_End.x + && currTrack->m_Start.x + aGridSize.x > currTrack->m_End.x + && currTrack->m_Start.y - aGridSize.y < currTrack->m_End.y + && currTrack->m_Start.y + aGridSize.y > currTrack->m_End.y ) { currTrack = currTrack->Back(); } - for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() ) + for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() ) { if( track->Type() != PCB_TRACE_T ) continue; @@ -241,7 +237,7 @@ bool Magnetize( BOARD* m_Pcb, PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize gr if( !track->HitTest( *curpos ) ) continue; - D(printf( "have track prospect\n");) + // D(printf( "have track prospect\n");) if( Join( curpos, track->m_Start, track->m_End, currTrack->m_Start, currTrack->m_End ) ) {